Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / gpu / gpu_data_manager_impl_private.h
blob0cd004cb83b38804d0e2f82ead92fd009746e8c7
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>
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/singleton.h"
15 #include "base/observer_list_threadsafe.h"
16 #include "content/browser/gpu/gpu_data_manager_impl.h"
17 #include "gpu/config/gpu_blacklist.h"
18 #include "gpu/config/gpu_driver_bug_list.h"
19 #include "gpu/config/gpu_switching_list.h"
21 namespace content {
23 class CONTENT_EXPORT GpuDataManagerImplPrivate {
24 public:
25 static GpuDataManagerImplPrivate* Create(GpuDataManagerImpl* owner);
27 void InitializeForTesting(
28 const std::string& gpu_blacklist_json,
29 const gpu::GPUInfo& gpu_info);
30 bool IsFeatureBlacklisted(int feature) const;
31 gpu::GPUInfo GetGPUInfo() const;
32 void GetGpuProcessHandles(
33 const GpuDataManager::GetGpuProcessHandlesCallback& callback) const;
34 bool GpuAccessAllowed(std::string* reason) const;
35 void RequestCompleteGpuInfoIfNeeded();
36 bool IsCompleteGpuInfoAvailable() const;
37 void RequestVideoMemoryUsageStatsUpdate() const;
38 bool ShouldUseSwiftShader() const;
39 void RegisterSwiftShaderPath(const base::FilePath& path);
40 void AddObserver(GpuDataManagerObserver* observer);
41 void RemoveObserver(GpuDataManagerObserver* observer);
42 void UnblockDomainFrom3DAPIs(const GURL& url);
43 void DisableGpuWatchdog();
44 void SetGLStrings(const std::string& gl_vendor,
45 const std::string& gl_renderer,
46 const std::string& gl_version);
47 void GetGLStrings(std::string* gl_vendor,
48 std::string* gl_renderer,
49 std::string* gl_version);
50 void DisableHardwareAcceleration();
52 void Initialize();
54 void UpdateGpuInfo(const gpu::GPUInfo& gpu_info);
56 void UpdateVideoMemoryUsageStats(
57 const GPUVideoMemoryUsageStats& video_memory_usage_stats);
59 void AppendRendererCommandLine(CommandLine* command_line) const;
61 void AppendGpuCommandLine(CommandLine* command_line) const;
63 void AppendPluginCommandLine(CommandLine* command_line) const;
65 void UpdateRendererWebPrefs(WebPreferences* prefs) const;
67 gpu::GpuSwitchingOption GetGpuSwitchingOption() const;
69 std::string GetBlacklistVersion() const;
70 std::string GetDriverBugListVersion() const;
72 void GetBlacklistReasons(base::ListValue* reasons) const;
74 void GetDriverBugWorkarounds(base::ListValue* workarounds) const;
76 void AddLogMessage(int level,
77 const std::string& header,
78 const std::string& message);
80 void ProcessCrashed(base::TerminationStatus exit_code);
82 base::ListValue* GetLogMessages() const;
84 void HandleGpuSwitch();
86 #if defined(OS_WIN)
87 // Is the GPU process using the accelerated surface to present, instead of
88 // presenting by itself.
89 bool IsUsingAcceleratedSurface() const;
90 #endif
92 void BlockDomainFrom3DAPIs(
93 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt);
94 bool Are3DAPIsBlocked(const GURL& url,
95 int render_process_id,
96 int render_view_id,
97 ThreeDAPIType requester);
99 void DisableDomainBlockingFor3DAPIsForTesting();
101 void Notify3DAPIBlocked(const GURL& url,
102 int render_process_id,
103 int render_view_id,
104 ThreeDAPIType requester);
106 size_t GetBlacklistedFeatureCount() const;
108 void SetDisplayCount(unsigned int display_count);
109 unsigned int GetDisplayCount() const;
111 void OnGpuProcessInitFailure();
113 virtual ~GpuDataManagerImplPrivate();
115 private:
116 friend class GpuDataManagerImplPrivateTest;
118 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
119 GpuSideBlacklisting);
120 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
121 GpuSideExceptions);
122 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
123 DisableHardwareAcceleration);
124 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
125 SwiftShaderRendering);
126 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
127 SwiftShaderRendering2);
128 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
129 GpuInfoUpdate);
130 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
131 NoGpuInfoUpdateWithSwiftShader);
132 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
133 GPUVideoMemoryUsageStatsUpdate);
134 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
135 BlockAllDomainsFrom3DAPIs);
136 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
137 UnblockGuiltyDomainFrom3DAPIs);
138 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
139 UnblockDomainOfUnknownGuiltFrom3DAPIs);
140 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
141 UnblockOtherDomainFrom3DAPIs);
142 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
143 UnblockThisDomainFrom3DAPIs);
144 #if defined(OS_LINUX)
145 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
146 SetGLStrings);
147 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
148 SetGLStringsNoEffects);
149 #endif
150 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
151 GpuDriverBugListSingle);
152 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
153 GpuDriverBugListMultiple);
154 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplPrivateTest,
155 BlacklistAllFeatures);
157 struct DomainBlockEntry {
158 GpuDataManagerImpl::DomainGuilt last_guilt;
161 typedef std::map<std::string, DomainBlockEntry> DomainBlockMap;
163 typedef ObserverListThreadSafe<GpuDataManagerObserver>
164 GpuDataManagerObserverList;
166 explicit GpuDataManagerImplPrivate(GpuDataManagerImpl* owner);
168 void InitializeImpl(const std::string& gpu_blacklist_json,
169 const std::string& gpu_switching_list_json,
170 const std::string& gpu_driver_bug_list_json,
171 const gpu::GPUInfo& gpu_info);
173 void UpdateBlacklistedFeatures(const std::set<int>& features);
175 // This should only be called once at initialization time, when preliminary
176 // gpu info is collected.
177 void UpdatePreliminaryBlacklistedFeatures();
179 // Update the GPU switching status.
180 // This should only be called once at initialization time.
181 void UpdateGpuSwitchingManager(const gpu::GPUInfo& gpu_info);
183 // Notify all observers whenever there is a GPU info update.
184 void NotifyGpuInfoUpdate();
186 // Try to switch to SwiftShader rendering, if possible and necessary.
187 void EnableSwiftShaderIfNecessary();
189 // Helper to extract the domain from a given URL.
190 std::string GetDomainFromURL(const GURL& url) const;
192 // Implementation functions for blocking of 3D graphics APIs, used
193 // for unit testing.
194 void BlockDomainFrom3DAPIsAtTime(const GURL& url,
195 GpuDataManagerImpl::DomainGuilt guilt,
196 base::Time at_time);
197 GpuDataManagerImpl::DomainBlockStatus Are3DAPIsBlockedAtTime(
198 const GURL& url, base::Time at_time) const;
199 int64 GetBlockAllDomainsDurationInMs() const;
201 bool complete_gpu_info_already_requested_;
203 std::set<int> blacklisted_features_;
204 std::set<int> preliminary_blacklisted_features_;
206 gpu::GpuSwitchingOption gpu_switching_;
208 std::set<int> gpu_driver_bugs_;
210 gpu::GPUInfo gpu_info_;
212 scoped_ptr<gpu::GpuBlacklist> gpu_blacklist_;
213 scoped_ptr<gpu::GpuSwitchingList> gpu_switching_list_;
214 scoped_ptr<gpu::GpuDriverBugList> gpu_driver_bug_list_;
216 const scoped_refptr<GpuDataManagerObserverList> observer_list_;
218 base::ListValue log_messages_;
220 bool use_swiftshader_;
222 base::FilePath swiftshader_path_;
224 // Current card force-blacklisted due to GPU crashes, or disabled through
225 // the --disable-gpu commandline switch.
226 bool card_blacklisted_;
228 // We disable histogram stuff in testing, especially in unit tests because
229 // they cause random failures.
230 bool update_histograms_;
232 // Number of currently open windows, to be used in gpu memory allocation.
233 int window_count_;
235 DomainBlockMap blocked_domains_;
236 mutable std::list<base::Time> timestamps_of_gpu_resets_;
237 bool domain_blocking_enabled_;
239 GpuDataManagerImpl* owner_;
241 unsigned int display_count_;
243 bool gpu_process_accessible_;
245 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImplPrivate);
248 } // namespace content
250 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_