Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / gpu / gpu_data_manager_impl.h
blob44a91fd1e943273bcf7c1a853002e276feec7804
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_
6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/files/file_path.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h"
16 #include "base/process/kill.h"
17 #include "base/synchronization/lock.h"
18 #include "base/time/time.h"
19 #include "base/values.h"
20 #include "content/public/browser/gpu_data_manager.h"
21 #include "content/public/common/gpu_memory_stats.h"
22 #include "content/public/common/three_d_api_types.h"
23 #include "gpu/config/gpu_info.h"
25 class GURL;
27 namespace base {
28 class CommandLine;
31 namespace content {
33 class GpuDataManagerImplPrivate;
34 struct WebPreferences;
36 class CONTENT_EXPORT GpuDataManagerImpl
37 : public NON_EXPORTED_BASE(GpuDataManager) {
38 public:
39 // Indicates the guilt level of a domain which caused a GPU reset.
40 // If a domain is 100% known to be guilty of resetting the GPU, then
41 // it will generally not cause other domains' use of 3D APIs to be
42 // blocked, unless system stability would be compromised.
43 enum DomainGuilt {
44 DOMAIN_GUILT_KNOWN,
45 DOMAIN_GUILT_UNKNOWN
48 // Indicates the reason that access to a given client API (like
49 // WebGL or Pepper 3D) was blocked or not. This state is distinct
50 // from blacklisting of an entire feature.
51 enum DomainBlockStatus {
52 DOMAIN_BLOCK_STATUS_BLOCKED,
53 DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED,
54 DOMAIN_BLOCK_STATUS_NOT_BLOCKED
57 // Getter for the singleton. This will return NULL on failure.
58 static GpuDataManagerImpl* GetInstance();
60 // GpuDataManager implementation.
61 void InitializeForTesting(const std::string& gpu_blacklist_json,
62 const gpu::GPUInfo& gpu_info) override;
63 bool IsFeatureBlacklisted(int feature) const override;
64 gpu::GPUInfo GetGPUInfo() const override;
65 void GetGpuProcessHandles(
66 const GetGpuProcessHandlesCallback& callback) const override;
67 bool GpuAccessAllowed(std::string* reason) const override;
68 void RequestCompleteGpuInfoIfNeeded() override;
69 bool IsEssentialGpuInfoAvailable() const override;
70 bool IsCompleteGpuInfoAvailable() const override;
71 void RequestVideoMemoryUsageStatsUpdate() const override;
72 bool ShouldUseSwiftShader() const override;
73 void RegisterSwiftShaderPath(const base::FilePath& path) override;
74 bool ShouldUseWarp() const override;
75 // TODO(kbr): the threading model for the GpuDataManagerObservers is
76 // not well defined, and it's impossible for callers to correctly
77 // delete observers from anywhere except in one of the observer's
78 // notification methods. Observer addition and removal, and their
79 // callbacks, should probably be required to occur on the UI thread.
80 void AddObserver(GpuDataManagerObserver* observer) override;
81 void RemoveObserver(GpuDataManagerObserver* observer) override;
82 void UnblockDomainFrom3DAPIs(const GURL& url) override;
83 void DisableGpuWatchdog() override;
84 void SetGLStrings(const std::string& gl_vendor,
85 const std::string& gl_renderer,
86 const std::string& gl_version) override;
87 void GetGLStrings(std::string* gl_vendor,
88 std::string* gl_renderer,
89 std::string* gl_version) override;
90 void DisableHardwareAcceleration() override;
91 bool CanUseGpuBrowserCompositor() const override;
93 // This collects preliminary GPU info, load GpuBlacklist, and compute the
94 // preliminary blacklisted features; it should only be called at browser
95 // startup time in UI thread before the IO restriction is turned on.
96 void Initialize();
98 // Only update if the current GPUInfo is not finalized. If blacklist is
99 // loaded, run through blacklist and update blacklisted features.
100 void UpdateGpuInfo(const gpu::GPUInfo& gpu_info);
102 void UpdateVideoMemoryUsageStats(
103 const GPUVideoMemoryUsageStats& video_memory_usage_stats);
105 // Insert disable-feature switches corresponding to preliminary gpu feature
106 // flags into the renderer process command line.
107 void AppendRendererCommandLine(base::CommandLine* command_line) const;
109 // Insert switches into gpu process command line: kUseGL, etc.
110 void AppendGpuCommandLine(base::CommandLine* command_line) const;
112 // Insert switches into plugin process command line:
113 // kDisableCoreAnimationPlugins.
114 void AppendPluginCommandLine(base::CommandLine* command_line) const;
116 // Update WebPreferences for renderer based on blacklisting decisions.
117 void UpdateRendererWebPrefs(WebPreferences* prefs) const;
119 std::string GetBlacklistVersion() const;
120 std::string GetDriverBugListVersion() const;
122 // Returns the reasons for the latest run of blacklisting decisions.
123 // For the structure of returned value, see documentation for
124 // GpuBlacklist::GetBlacklistedReasons().
125 void GetBlacklistReasons(base::ListValue* reasons) const;
127 // Returns the workarounds that are applied to the current system as
128 // a vector of strings.
129 std::vector<std::string> GetDriverBugWorkarounds() const;
131 void AddLogMessage(int level,
132 const std::string& header,
133 const std::string& message);
135 void ProcessCrashed(base::TerminationStatus exit_code);
137 // Returns a new copy of the ListValue. Caller is responsible to release
138 // the returned value.
139 base::ListValue* GetLogMessages() const;
141 // Called when switching gpu.
142 void HandleGpuSwitch();
144 // Maintenance of domains requiring explicit user permission before
145 // using client-facing 3D APIs (WebGL, Pepper 3D), either because
146 // the domain has caused the GPU to reset, or because too many GPU
147 // resets have been observed globally recently, and system stability
148 // might be compromised.
150 // The given URL may be a partial URL (including at least the host)
151 // or a full URL to a page.
153 // Note that the unblocking API must be part of the content API
154 // because it is called from Chrome side code.
155 void BlockDomainFrom3DAPIs(const GURL& url, DomainGuilt guilt);
156 bool Are3DAPIsBlocked(const GURL& url,
157 int render_process_id,
158 int render_view_id,
159 ThreeDAPIType requester);
161 // Disables domain blocking for 3D APIs. For use only in tests.
162 void DisableDomainBlockingFor3DAPIsForTesting();
164 void Notify3DAPIBlocked(const GURL& url,
165 int render_process_id,
166 int render_view_id,
167 ThreeDAPIType requester);
169 // Get number of features being blacklisted.
170 size_t GetBlacklistedFeatureCount() const;
172 void SetDisplayCount(unsigned int display_count);
173 unsigned int GetDisplayCount() const;
175 // Set the active gpu.
176 // Return true if it's a different GPU from the previous active one.
177 bool UpdateActiveGpu(uint32 vendor_id, uint32 device_id);
179 // Called when GPU process initialization failed.
180 void OnGpuProcessInitFailure();
182 bool IsDriverBugWorkaroundActive(int feature) const;
184 private:
185 friend class GpuDataManagerImplPrivate;
186 friend class GpuDataManagerImplPrivateTest;
187 friend struct DefaultSingletonTraits<GpuDataManagerImpl>;
189 // It's similar to AutoUnlock, but we want to make it a no-op
190 // if the owner GpuDataManagerImpl is null.
191 // This should only be used by GpuDataManagerImplPrivate where
192 // callbacks are called, during which re-entering
193 // GpuDataManagerImpl is possible.
194 class UnlockedSession {
195 public:
196 explicit UnlockedSession(GpuDataManagerImpl* owner)
197 : owner_(owner) {
198 DCHECK(owner_);
199 owner_->lock_.AssertAcquired();
200 owner_->lock_.Release();
203 ~UnlockedSession() {
204 DCHECK(owner_);
205 owner_->lock_.Acquire();
208 private:
209 GpuDataManagerImpl* owner_;
210 DISALLOW_COPY_AND_ASSIGN(UnlockedSession);
213 GpuDataManagerImpl();
214 ~GpuDataManagerImpl() override;
216 mutable base::Lock lock_;
217 scoped_ptr<GpuDataManagerImplPrivate> private_;
219 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl);
222 } // namespace content
224 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_