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_PRIVATE_H_
6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/singleton.h"
16 #include "base/observer_list_threadsafe.h"
17 #include "content/browser/gpu/gpu_data_manager_impl.h"
18 #include "gpu/config/gpu_blacklist.h"
19 #include "gpu/config/gpu_driver_bug_list.h"
27 class CONTENT_EXPORT GpuDataManagerImplPrivate {
29 static GpuDataManagerImplPrivate* Create(GpuDataManagerImpl* owner);
31 void InitializeForTesting(
32 const std::string& gpu_blacklist_json,
33 const gpu::GPUInfo& gpu_info);
34 bool IsFeatureBlacklisted(int feature) const;
35 bool IsDriverBugWorkaroundActive(int feature) const;
36 gpu::GPUInfo GetGPUInfo() const;
37 void GetGpuProcessHandles(
38 const GpuDataManager::GetGpuProcessHandlesCallback& callback) const;
39 bool GpuAccessAllowed(std::string* reason) const;
40 void RequestCompleteGpuInfoIfNeeded();
41 bool IsCompleteGpuInfoAvailable() const;
42 void RequestVideoMemoryUsageStatsUpdate() const;
43 bool ShouldUseSwiftShader() const;
44 void RegisterSwiftShaderPath(const base::FilePath& path);
45 void AddObserver(GpuDataManagerObserver* observer);
46 void RemoveObserver(GpuDataManagerObserver* observer);
47 void UnblockDomainFrom3DAPIs(const GURL& url);
48 void DisableGpuWatchdog();
49 void SetGLStrings(const std::string& gl_vendor,
50 const std::string& gl_renderer,
51 const std::string& gl_version);
52 void GetGLStrings(std::string* gl_vendor,
53 std::string* gl_renderer,
54 std::string* gl_version);
55 void DisableHardwareAcceleration();
59 void UpdateGpuInfo(const gpu::GPUInfo& gpu_info);
61 void UpdateVideoMemoryUsageStats(
62 const GPUVideoMemoryUsageStats& video_memory_usage_stats);
64 void AppendRendererCommandLine(base::CommandLine* command_line) const;
66 void AppendGpuCommandLine(base::CommandLine* command_line) const;
68 void AppendPluginCommandLine(base::CommandLine* command_line) const;
70 void UpdateRendererWebPrefs(WebPreferences* prefs) const;
72 std::string GetBlacklistVersion() const;
73 std::string GetDriverBugListVersion() const;
75 void GetBlacklistReasons(base::ListValue* reasons) const;
77 void GetDriverBugWorkarounds(base::ListValue* workarounds) const;
79 void AddLogMessage(int level,
80 const std::string& header,
81 const std::string& message);
83 void ProcessCrashed(base::TerminationStatus exit_code);
85 base::ListValue* GetLogMessages() const;
87 void HandleGpuSwitch();
89 bool CanUseGpuBrowserCompositor() const;
91 void BlockDomainFrom3DAPIs(
92 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt);
93 bool Are3DAPIsBlocked(const GURL& url,
94 int render_process_id,
96 ThreeDAPIType requester);
98 void DisableDomainBlockingFor3DAPIsForTesting();
100 void Notify3DAPIBlocked(const GURL& url,
101 int render_process_id,
103 ThreeDAPIType requester);
105 size_t GetBlacklistedFeatureCount() const;
107 void SetDisplayCount(unsigned int display_count);
108 unsigned int GetDisplayCount() const;
110 void OnGpuProcessInitFailure();
112 virtual ~GpuDataManagerImplPrivate();
115 friend class GpuDataManagerImplPrivateTest;
117 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
118 GpuSideBlacklisting);
119 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
121 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
122 DisableHardwareAcceleration);
123 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
124 SwiftShaderRendering);
125 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
126 SwiftShaderRendering2);
127 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
129 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
130 NoGpuInfoUpdateWithSwiftShader);
131 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
132 GPUVideoMemoryUsageStatsUpdate);
133 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
134 BlockAllDomainsFrom3DAPIs);
135 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
136 UnblockGuiltyDomainFrom3DAPIs);
137 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
138 UnblockDomainOfUnknownGuiltFrom3DAPIs);
139 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
140 UnblockOtherDomainFrom3DAPIs);
141 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
142 UnblockThisDomainFrom3DAPIs);
143 #if defined(OS_LINUX)
144 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
146 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
147 SetGLStringsNoEffects);
149 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
150 GpuDriverBugListSingle);
151 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
152 GpuDriverBugListMultiple);
153 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
154 BlacklistAllFeatures);
156 struct DomainBlockEntry {
157 GpuDataManagerImpl::DomainGuilt last_guilt;
160 typedef std::map<std::string, DomainBlockEntry> DomainBlockMap;
162 typedef ObserverListThreadSafe<GpuDataManagerObserver>
163 GpuDataManagerObserverList;
170 LogMessage(int _level,
171 const std::string& _header,
172 const std::string& _message)
175 message(_message) { }
178 explicit GpuDataManagerImplPrivate(GpuDataManagerImpl* owner);
180 void InitializeImpl(const std::string& gpu_blacklist_json,
181 const std::string& gpu_driver_bug_list_json,
182 const gpu::GPUInfo& gpu_info);
184 void UpdateGpuInfoHelper();
186 void UpdateBlacklistedFeatures(const std::set<int>& features);
188 // This should only be called once at initialization time, when preliminary
189 // gpu info is collected.
190 void UpdatePreliminaryBlacklistedFeatures();
192 // Update the GPU switching status.
193 // This should only be called once at initialization time.
194 void UpdateGpuSwitchingManager(const gpu::GPUInfo& gpu_info);
196 // Notify all observers whenever there is a GPU info update.
197 void NotifyGpuInfoUpdate();
199 // Try to switch to SwiftShader rendering, if possible and necessary.
200 void EnableSwiftShaderIfNecessary();
202 // Helper to extract the domain from a given URL.
203 std::string GetDomainFromURL(const GURL& url) const;
205 // Implementation functions for blocking of 3D graphics APIs, used
207 void BlockDomainFrom3DAPIsAtTime(const GURL& url,
208 GpuDataManagerImpl::DomainGuilt guilt,
210 GpuDataManagerImpl::DomainBlockStatus Are3DAPIsBlockedAtTime(
211 const GURL& url, base::Time at_time) const;
212 int64 GetBlockAllDomainsDurationInMs() const;
214 bool complete_gpu_info_already_requested_;
216 std::set<int> blacklisted_features_;
217 std::set<int> preliminary_blacklisted_features_;
219 std::set<int> gpu_driver_bugs_;
221 gpu::GPUInfo gpu_info_;
223 scoped_ptr<gpu::GpuBlacklist> gpu_blacklist_;
224 scoped_ptr<gpu::GpuDriverBugList> gpu_driver_bug_list_;
226 const scoped_refptr<GpuDataManagerObserverList> observer_list_;
228 std::vector<LogMessage> log_messages_;
230 bool use_swiftshader_;
232 base::FilePath swiftshader_path_;
234 // Current card force-blacklisted due to GPU crashes, or disabled through
235 // the --disable-gpu commandline switch.
236 bool card_blacklisted_;
238 // We disable histogram stuff in testing, especially in unit tests because
239 // they cause random failures.
240 bool update_histograms_;
242 // Number of currently open windows, to be used in gpu memory allocation.
245 DomainBlockMap blocked_domains_;
246 mutable std::list<base::Time> timestamps_of_gpu_resets_;
247 bool domain_blocking_enabled_;
249 GpuDataManagerImpl* owner_;
251 unsigned int display_count_;
253 bool gpu_process_accessible_;
255 bool use_software_compositor_;
257 // True if all future Initialize calls should be ignored.
260 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImplPrivate);
263 } // namespace content
265 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_