summaryrefslogtreecommitdiffstats
path: root/content/browser/gpu/gpu_data_manager_impl.h
blob: 32d8301dd7451ad2189ce17c7e78513c1bd4716f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_
#define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_
#pragma once

#include <set>
#include <string>

#include "base/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/observer_list_threadsafe.h"
#include "base/synchronization/lock.h"
#include "base/values.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/common/gpu_info.h"

class CommandLine;

class CONTENT_EXPORT GpuDataManagerImpl
    : public NON_EXPORTED_BASE(content::GpuDataManager) {
 public:
  // Getter for the singleton. This will return NULL on failure.
  static GpuDataManagerImpl* GetInstance();

  // GpuDataManager implementation.
  virtual content::GpuFeatureType GetGpuFeatureType() OVERRIDE;
  virtual void SetGpuFeatureType(content::GpuFeatureType feature_type) OVERRIDE;
  virtual content::GPUInfo GetGPUInfo() const OVERRIDE;
  virtual bool GpuAccessAllowed() OVERRIDE;
  virtual void RequestCompleteGpuInfoIfNeeded() OVERRIDE;
  virtual bool IsCompleteGPUInfoAvailable() const OVERRIDE;
  virtual bool ShouldUseSoftwareRendering() OVERRIDE;
  virtual void RegisterSwiftShaderPath(const FilePath& path) OVERRIDE;
  virtual const base::ListValue& GetLogMessages() const OVERRIDE;
  virtual void AddObserver(content::GpuDataManagerObserver* observer) OVERRIDE;
  virtual void RemoveObserver(
      content::GpuDataManagerObserver* observer) OVERRIDE;

  // Only update if the current GPUInfo is not finalized.
  void UpdateGpuInfo(const content::GPUInfo& gpu_info);

  void AddLogMessage(Value* msg);

  // Inserting disable-feature switches into renderer process command-line
  // in correspondence to preliminary gpu feature flags.
  void AppendRendererCommandLine(CommandLine* command_line);

  // Inserting switches into gpu process command-line: kUseGL,
  // kDisableGLMultisampling.
  void AppendGpuCommandLine(CommandLine* command_line);

  // This gets called when switching GPU might have happened.
  void HandleGpuSwitch();

  // Force the current card to be blacklisted (usually due to GPU process
  // crashes).
  void BlacklistCard();

 private:
  typedef ObserverListThreadSafe<content::GpuDataManagerObserver>
      GpuDataManagerObserverList;

  friend struct DefaultSingletonTraits<GpuDataManagerImpl>;

  GpuDataManagerImpl();
  virtual ~GpuDataManagerImpl();

  void Initialize();

  // If flags hasn't been set and GPUInfo is available, run through blacklist
  // and compute the flags.
  void UpdateGpuFeatureType(content::GpuFeatureType embedder_feature_type);

  // Notify all observers whenever there is a GPU info update.
  void NotifyGpuInfoUpdate();

  // If use-gl switch is osmesa or any, return true.
  bool UseGLIsOSMesaOrAny();

  // Merges the second GPUInfo object with the first.
  // If it's the same GPU, i.e., device id and vendor id are the same, then
  // copy over the fields that are not set yet and ignore the rest.
  // If it's a different GPU, then reset and copy over everything.
  // Return true if something changes that may affect blacklisting; currently
  // they are device_id, vendor_id, driver_vendor, driver_version, driver_date,
  // and gl_renderer.
  static bool Merge(content::GPUInfo* object, const content::GPUInfo& other);

  // Try to switch to software rendering, if possible and necessary.
  void EnableSoftwareRenderingIfNecessary();

  bool complete_gpu_info_already_requested_;
  bool complete_gpu_info_available_;

  content::GpuFeatureType gpu_feature_type_;
  content::GpuFeatureType preliminary_gpu_feature_type_;

  content::GPUInfo gpu_info_;
  mutable base::Lock gpu_info_lock_;

  // Observers.
  const scoped_refptr<GpuDataManagerObserverList> observer_list_;

  ListValue log_messages_;
  bool software_rendering_;

  FilePath swiftshader_path_;

  // Current card force-blacklisted due to GPU crashes.
  bool card_blacklisted_;

  DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl);
};

#endif  // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_