Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / gpu / gpu_data_manager_impl_private.h
blob8a1c9ebec71f5a9a35362464477aac4719c8b355
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 IsEssentialGpuInfoAvailable() const;
42 bool IsCompleteGpuInfoAvailable() const;
43 void RequestVideoMemoryUsageStatsUpdate() const;
44 bool ShouldUseSwiftShader() const;
45 void RegisterSwiftShaderPath(const base::FilePath& path);
46 bool ShouldUseWarp() const;
47 void AddObserver(GpuDataManagerObserver* observer);
48 void RemoveObserver(GpuDataManagerObserver* observer);
49 void UnblockDomainFrom3DAPIs(const GURL& url);
50 void DisableGpuWatchdog();
51 void SetGLStrings(const std::string& gl_vendor,
52 const std::string& gl_renderer,
53 const std::string& gl_version);
54 void GetGLStrings(std::string* gl_vendor,
55 std::string* gl_renderer,
56 std::string* gl_version);
57 void DisableHardwareAcceleration();
59 void Initialize();
61 void UpdateGpuInfo(const gpu::GPUInfo& gpu_info);
63 void UpdateVideoMemoryUsageStats(
64 const GPUVideoMemoryUsageStats& video_memory_usage_stats);
66 void AppendRendererCommandLine(base::CommandLine* command_line) const;
68 void AppendGpuCommandLine(base::CommandLine* command_line) const;
70 void AppendPluginCommandLine(base::CommandLine* command_line) const;
72 void UpdateRendererWebPrefs(WebPreferences* prefs) const;
74 std::string GetBlacklistVersion() const;
75 std::string GetDriverBugListVersion() const;
77 void GetBlacklistReasons(base::ListValue* reasons) const;
79 std::vector<std::string> GetDriverBugWorkarounds() const;
81 void AddLogMessage(int level,
82 const std::string& header,
83 const std::string& message);
85 void ProcessCrashed(base::TerminationStatus exit_code);
87 base::ListValue* GetLogMessages() const;
89 void HandleGpuSwitch();
91 bool CanUseGpuBrowserCompositor() const;
93 void BlockDomainFrom3DAPIs(
94 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt);
95 bool Are3DAPIsBlocked(const GURL& url,
96 int render_process_id,
97 int render_view_id,
98 ThreeDAPIType requester);
100 void DisableDomainBlockingFor3DAPIsForTesting();
102 void Notify3DAPIBlocked(const GURL& url,
103 int render_process_id,
104 int render_view_id,
105 ThreeDAPIType requester);
107 size_t GetBlacklistedFeatureCount() const;
109 void SetDisplayCount(unsigned int display_count);
110 unsigned int GetDisplayCount() const;
112 bool UpdateActiveGpu(uint32 vendor_id, uint32 device_id);
114 void OnGpuProcessInitFailure();
116 virtual ~GpuDataManagerImplPrivate();
118 private:
119 friend class GpuDataManagerImplPrivateTest;
121 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
122 GpuSideBlacklisting);
123 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
124 GpuSideExceptions);
125 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
126 DisableHardwareAcceleration);
127 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
128 SwiftShaderRendering);
129 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
130 SwiftShaderRendering2);
131 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
132 WarpEnabledOverridesSwiftShader);
133 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
134 GpuInfoUpdate);
135 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
136 NoGpuInfoUpdateWithSwiftShader);
137 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
138 GPUVideoMemoryUsageStatsUpdate);
139 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
140 BlockAllDomainsFrom3DAPIs);
141 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
142 UnblockGuiltyDomainFrom3DAPIs);
143 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
144 UnblockDomainOfUnknownGuiltFrom3DAPIs);
145 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
146 UnblockOtherDomainFrom3DAPIs);
147 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
148 UnblockThisDomainFrom3DAPIs);
149 #if defined(OS_LINUX)
150 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
151 SetGLStrings);
152 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
153 SetGLStringsNoEffects);
154 #endif
155 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
156 GpuDriverBugListSingle);
157 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
158 GpuDriverBugListMultiple);
159 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
160 BlacklistAllFeatures);
162 struct DomainBlockEntry {
163 GpuDataManagerImpl::DomainGuilt last_guilt;
166 typedef std::map<std::string, DomainBlockEntry> DomainBlockMap;
168 typedef ObserverListThreadSafe<GpuDataManagerObserver>
169 GpuDataManagerObserverList;
171 struct LogMessage {
172 int level;
173 std::string header;
174 std::string message;
176 LogMessage(int _level,
177 const std::string& _header,
178 const std::string& _message)
179 : level(_level),
180 header(_header),
181 message(_message) { }
184 explicit GpuDataManagerImplPrivate(GpuDataManagerImpl* owner);
186 void InitializeImpl(const std::string& gpu_blacklist_json,
187 const std::string& gpu_driver_bug_list_json,
188 const gpu::GPUInfo& gpu_info);
190 void UpdateGpuInfoHelper();
192 void UpdateBlacklistedFeatures(const std::set<int>& features);
194 // This should only be called once at initialization time, when preliminary
195 // gpu info is collected.
196 void UpdatePreliminaryBlacklistedFeatures();
198 // Update the GPU switching status.
199 // This should only be called once at initialization time.
200 void UpdateGpuSwitchingManager(const gpu::GPUInfo& gpu_info);
202 // Notify all observers whenever there is a GPU info update.
203 void NotifyGpuInfoUpdate();
205 // Try to switch to SwiftShader rendering, if possible and necessary.
206 void EnableSwiftShaderIfNecessary();
208 // Try to switch to WARP rendering if the GPU hardware is not supported or
209 // absent, and if we are trying to run in Windows Metro mode.
210 void EnableWarpIfNecessary();
212 // Use only for testing, forces |use_warp_| to true.
213 void ForceWarpModeForTesting();
215 // Helper to extract the domain from a given URL.
216 std::string GetDomainFromURL(const GURL& url) const;
218 // Implementation functions for blocking of 3D graphics APIs, used
219 // for unit testing.
220 void BlockDomainFrom3DAPIsAtTime(const GURL& url,
221 GpuDataManagerImpl::DomainGuilt guilt,
222 base::Time at_time);
223 GpuDataManagerImpl::DomainBlockStatus Are3DAPIsBlockedAtTime(
224 const GURL& url, base::Time at_time) const;
225 int64 GetBlockAllDomainsDurationInMs() const;
227 bool complete_gpu_info_already_requested_;
229 std::set<int> blacklisted_features_;
230 std::set<int> preliminary_blacklisted_features_;
232 std::set<int> gpu_driver_bugs_;
234 gpu::GPUInfo gpu_info_;
236 scoped_ptr<gpu::GpuBlacklist> gpu_blacklist_;
237 scoped_ptr<gpu::GpuDriverBugList> gpu_driver_bug_list_;
239 const scoped_refptr<GpuDataManagerObserverList> observer_list_;
241 std::vector<LogMessage> log_messages_;
243 bool use_swiftshader_;
245 bool use_warp_;
247 base::FilePath swiftshader_path_;
249 // Current card force-blacklisted due to GPU crashes, or disabled through
250 // the --disable-gpu commandline switch.
251 bool card_blacklisted_;
253 // We disable histogram stuff in testing, especially in unit tests because
254 // they cause random failures.
255 bool update_histograms_;
257 // Number of currently open windows, to be used in gpu memory allocation.
258 int window_count_;
260 DomainBlockMap blocked_domains_;
261 mutable std::list<base::Time> timestamps_of_gpu_resets_;
262 bool domain_blocking_enabled_;
264 GpuDataManagerImpl* owner_;
266 unsigned int display_count_;
268 bool gpu_process_accessible_;
270 // True if all future Initialize calls should be ignored.
271 bool finalized_;
273 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImplPrivate);
276 } // namespace content
278 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_