Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / gpu / gpu_data_manager_impl_private.h
blob8e5514fad318236925412283a590aeb13884e9ef
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_
8 #include <list>
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
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"
21 namespace base {
22 class CommandLine;
25 namespace content {
27 class CONTENT_EXPORT GpuDataManagerImplPrivate {
28 public:
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();
57 void Initialize();
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,
95 int render_view_id,
96 ThreeDAPIType requester);
98 void DisableDomainBlockingFor3DAPIsForTesting();
100 void Notify3DAPIBlocked(const GURL& url,
101 int render_process_id,
102 int render_view_id,
103 ThreeDAPIType requester);
105 size_t GetBlacklistedFeatureCount() const;
107 void SetDisplayCount(unsigned int display_count);
108 unsigned int GetDisplayCount() const;
110 bool UpdateActiveGpu(uint32 vendor_id, uint32 device_id);
112 void OnGpuProcessInitFailure();
114 virtual ~GpuDataManagerImplPrivate();
116 private:
117 friend class GpuDataManagerImplPrivateTest;
119 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
120 GpuSideBlacklisting);
121 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
122 GpuSideExceptions);
123 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
124 DisableHardwareAcceleration);
125 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
126 SwiftShaderRendering);
127 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
128 SwiftShaderRendering2);
129 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
130 GpuInfoUpdate);
131 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
132 NoGpuInfoUpdateWithSwiftShader);
133 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
134 GPUVideoMemoryUsageStatsUpdate);
135 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
136 BlockAllDomainsFrom3DAPIs);
137 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
138 UnblockGuiltyDomainFrom3DAPIs);
139 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
140 UnblockDomainOfUnknownGuiltFrom3DAPIs);
141 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
142 UnblockOtherDomainFrom3DAPIs);
143 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
144 UnblockThisDomainFrom3DAPIs);
145 #if defined(OS_LINUX)
146 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
147 SetGLStrings);
148 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
149 SetGLStringsNoEffects);
150 #endif
151 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
152 GpuDriverBugListSingle);
153 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
154 GpuDriverBugListMultiple);
155 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
156 BlacklistAllFeatures);
158 struct DomainBlockEntry {
159 GpuDataManagerImpl::DomainGuilt last_guilt;
162 typedef std::map<std::string, DomainBlockEntry> DomainBlockMap;
164 typedef ObserverListThreadSafe<GpuDataManagerObserver>
165 GpuDataManagerObserverList;
167 struct LogMessage {
168 int level;
169 std::string header;
170 std::string message;
172 LogMessage(int _level,
173 const std::string& _header,
174 const std::string& _message)
175 : level(_level),
176 header(_header),
177 message(_message) { }
180 explicit GpuDataManagerImplPrivate(GpuDataManagerImpl* owner);
182 void InitializeImpl(const std::string& gpu_blacklist_json,
183 const std::string& gpu_driver_bug_list_json,
184 const gpu::GPUInfo& gpu_info);
186 void UpdateGpuInfoHelper();
188 void UpdateBlacklistedFeatures(const std::set<int>& features);
190 // This should only be called once at initialization time, when preliminary
191 // gpu info is collected.
192 void UpdatePreliminaryBlacklistedFeatures();
194 // Update the GPU switching status.
195 // This should only be called once at initialization time.
196 void UpdateGpuSwitchingManager(const gpu::GPUInfo& gpu_info);
198 // Notify all observers whenever there is a GPU info update.
199 void NotifyGpuInfoUpdate();
201 // Try to switch to SwiftShader rendering, if possible and necessary.
202 void EnableSwiftShaderIfNecessary();
204 // Helper to extract the domain from a given URL.
205 std::string GetDomainFromURL(const GURL& url) const;
207 // Implementation functions for blocking of 3D graphics APIs, used
208 // for unit testing.
209 void BlockDomainFrom3DAPIsAtTime(const GURL& url,
210 GpuDataManagerImpl::DomainGuilt guilt,
211 base::Time at_time);
212 GpuDataManagerImpl::DomainBlockStatus Are3DAPIsBlockedAtTime(
213 const GURL& url, base::Time at_time) const;
214 int64 GetBlockAllDomainsDurationInMs() const;
216 bool complete_gpu_info_already_requested_;
218 std::set<int> blacklisted_features_;
219 std::set<int> preliminary_blacklisted_features_;
221 std::set<int> gpu_driver_bugs_;
223 gpu::GPUInfo gpu_info_;
225 scoped_ptr<gpu::GpuBlacklist> gpu_blacklist_;
226 scoped_ptr<gpu::GpuDriverBugList> gpu_driver_bug_list_;
228 const scoped_refptr<GpuDataManagerObserverList> observer_list_;
230 std::vector<LogMessage> log_messages_;
232 bool use_swiftshader_;
234 base::FilePath swiftshader_path_;
236 // Current card force-blacklisted due to GPU crashes, or disabled through
237 // the --disable-gpu commandline switch.
238 bool card_blacklisted_;
240 // We disable histogram stuff in testing, especially in unit tests because
241 // they cause random failures.
242 bool update_histograms_;
244 // Number of currently open windows, to be used in gpu memory allocation.
245 int window_count_;
247 DomainBlockMap blocked_domains_;
248 mutable std::list<base::Time> timestamps_of_gpu_resets_;
249 bool domain_blocking_enabled_;
251 GpuDataManagerImpl* owner_;
253 unsigned int display_count_;
255 bool gpu_process_accessible_;
257 // True if all future Initialize calls should be ignored.
258 bool finalized_;
260 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImplPrivate);
263 } // namespace content
265 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_