Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / gpu / gpu_data_manager_impl_private.h
blobc83ca9332708f28271217f10fbb368a616982fca
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 void OnGpuProcessInitFailure();
112 virtual ~GpuDataManagerImplPrivate();
114 private:
115 friend class GpuDataManagerImplPrivateTest;
117 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
118 GpuSideBlacklisting);
119 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
120 GpuSideExceptions);
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,
128 GpuInfoUpdate);
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,
145 SetGLStrings);
146 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
147 SetGLStringsNoEffects);
148 #endif
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;
165 struct LogMessage {
166 int level;
167 std::string header;
168 std::string message;
170 LogMessage(int _level,
171 const std::string& _header,
172 const std::string& _message)
173 : level(_level),
174 header(_header),
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 UpdateBlacklistedFeatures(const std::set<int>& features);
186 // This should only be called once at initialization time, when preliminary
187 // gpu info is collected.
188 void UpdatePreliminaryBlacklistedFeatures();
190 // Update the GPU switching status.
191 // This should only be called once at initialization time.
192 void UpdateGpuSwitchingManager(const gpu::GPUInfo& gpu_info);
194 // Notify all observers whenever there is a GPU info update.
195 void NotifyGpuInfoUpdate();
197 // Try to switch to SwiftShader rendering, if possible and necessary.
198 void EnableSwiftShaderIfNecessary();
200 // Helper to extract the domain from a given URL.
201 std::string GetDomainFromURL(const GURL& url) const;
203 // Implementation functions for blocking of 3D graphics APIs, used
204 // for unit testing.
205 void BlockDomainFrom3DAPIsAtTime(const GURL& url,
206 GpuDataManagerImpl::DomainGuilt guilt,
207 base::Time at_time);
208 GpuDataManagerImpl::DomainBlockStatus Are3DAPIsBlockedAtTime(
209 const GURL& url, base::Time at_time) const;
210 int64 GetBlockAllDomainsDurationInMs() const;
212 bool complete_gpu_info_already_requested_;
214 std::set<int> blacklisted_features_;
215 std::set<int> preliminary_blacklisted_features_;
217 std::set<int> gpu_driver_bugs_;
219 gpu::GPUInfo gpu_info_;
221 scoped_ptr<gpu::GpuBlacklist> gpu_blacklist_;
222 scoped_ptr<gpu::GpuDriverBugList> gpu_driver_bug_list_;
224 const scoped_refptr<GpuDataManagerObserverList> observer_list_;
226 std::vector<LogMessage> log_messages_;
228 bool use_swiftshader_;
230 base::FilePath swiftshader_path_;
232 // Current card force-blacklisted due to GPU crashes, or disabled through
233 // the --disable-gpu commandline switch.
234 bool card_blacklisted_;
236 // We disable histogram stuff in testing, especially in unit tests because
237 // they cause random failures.
238 bool update_histograms_;
240 // Number of currently open windows, to be used in gpu memory allocation.
241 int window_count_;
243 DomainBlockMap blocked_domains_;
244 mutable std::list<base::Time> timestamps_of_gpu_resets_;
245 bool domain_blocking_enabled_;
247 GpuDataManagerImpl* owner_;
249 unsigned int display_count_;
251 bool gpu_process_accessible_;
253 bool use_software_compositor_;
255 // True if all future Initialize calls should be ignored.
256 bool finalized_;
258 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImplPrivate);
261 } // namespace content
263 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_