Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: content/browser/gpu/gpu_data_manager_impl_private.h

Issue 14794006: Refactor GpuDataManagerImpl to make it thread-safe, now and forever. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
dmichael (off chromium) 2013/05/09 15:53:51 drive-by suggestion: To make kbr's review easier,
Zhenyao Mo 2013/05/09 18:07:26 is there a way to do this through svn/gcl?
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
7
8 #include <list>
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
13
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_blacklist.h"
18 #include "content/browser/gpu/gpu_data_manager_impl.h"
19 #include "content/browser/gpu/gpu_driver_bug_list.h"
20 #include "content/browser/gpu/gpu_switching_list.h"
21
22 namespace content {
23
24 class CONTENT_EXPORT GpuDataManagerImplPrivate {
25 public:
26 void InitializeForTesting(
27 const std::string& gpu_blacklist_json,
28 const GPUInfo& gpu_info);
29 bool IsFeatureBlacklisted(int feature) const;
30 GPUInfo GetGPUInfo() const;
31 void GetGpuProcessHandles(
32 const GpuDataManager::GetGpuProcessHandlesCallback& callback) const;
33 bool GpuAccessAllowed(std::string* reason) const;
34 void RequestCompleteGpuInfoIfNeeded();
35 bool IsCompleteGpuInfoAvailable() const;
36 void RequestVideoMemoryUsageStatsUpdate() const;
37 bool ShouldUseSwiftShader() const;
38 void RegisterSwiftShaderPath(const base::FilePath& path);
39 void AddObserver(GpuDataManagerObserver* observer);
40 void RemoveObserver(GpuDataManagerObserver* observer);
41 void UnblockDomainFrom3DAPIs(const GURL& url);
42 void DisableGpuWatchdog();
43 void SetGLStrings(const std::string& gl_vendor,
44 const std::string& gl_renderer,
45 const std::string& gl_version);
46 void GetGLStrings(std::string* gl_vendor,
47 std::string* gl_renderer,
48 std::string* gl_version);
49 void DisableHardwareAcceleration();
50
51 void Initialize();
52
53 void UpdateGpuInfo(const GPUInfo& gpu_info);
54
55 void UpdateVideoMemoryUsageStats(
56 const GPUVideoMemoryUsageStats& video_memory_usage_stats);
57
58 void AppendRendererCommandLine(CommandLine* command_line) const;
59
60 void AppendGpuCommandLine(CommandLine* command_line) const;
61
62 void AppendPluginCommandLine(CommandLine* command_line) const;
63
64 void UpdateRendererWebPrefs(WebPreferences* prefs) const;
65
66 GpuSwitchingOption GetGpuSwitchingOption() const;
67
68 std::string GetBlacklistVersion() const;
69
70 base::ListValue* GetBlacklistReasons() const;
71
72 void AddLogMessage(int level,
73 const std::string& header,
74 const std::string& message);
75
76 void ProcessCrashed(base::TerminationStatus exit_code);
77
78 base::ListValue* GetLogMessages() const;
79
80 void HandleGpuSwitch();
81
82 #if defined(OS_WIN)
83 // Is the GPU process using the accelerated surface to present, instead of
84 // presenting by itself.
85 bool IsUsingAcceleratedSurface() const;
86 #endif
87
88 void BlockDomainFrom3DAPIs(
89 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt);
90 bool Are3DAPIsBlocked(const GURL& url,
91 int render_process_id,
92 int render_view_id,
93 ThreeDAPIType requester);
94
95 void DisableDomainBlockingFor3DAPIsForTesting();
96
97 size_t GetBlacklistedFeatureCount() const;
98
99 typedef base::Callback<void()> GpuSwitchCallback;
100
101 void AddGpuSwitchCallback(const GpuSwitchCallback& callback);
102 void RemoveGpuSwitchCallback(const GpuSwitchCallback& callback);
103
104 GpuDataManagerImplPrivate();
105 virtual ~GpuDataManagerImplPrivate();
106
107 private:
108 friend class GpuDataManagerImplTest;
109
110 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideBlacklisting);
111 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideExceptions);
112 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
113 DisableHardwareAcceleration);
114 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SwiftShaderRendering);
115 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SwiftShaderRendering2);
116 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuInfoUpdate);
117 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
118 NoGpuInfoUpdateWithSwiftShader);
119 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
120 GPUVideoMemoryUsageStatsUpdate);
121 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
122 BlockAllDomainsFrom3DAPIs);
123 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
124 UnblockGuiltyDomainFrom3DAPIs);
125 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
126 UnblockDomainOfUnknownGuiltFrom3DAPIs);
127 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
128 UnblockOtherDomainFrom3DAPIs);
129 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
130 UnblockThisDomainFrom3DAPIs);
131 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuDriverBugListSingle);
132 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuDriverBugListMultiple);
133
134 struct DomainBlockEntry {
135 GpuDataManagerImpl::DomainGuilt last_guilt;
136 };
137
138 typedef std::map<std::string, DomainBlockEntry> DomainBlockMap;
139
140 typedef ObserverListThreadSafe<GpuDataManagerObserver>
141 GpuDataManagerObserverList;
142
143 void InitializeImpl(const std::string& gpu_blacklist_json,
144 const std::string& gpu_switching_list_json,
145 const std::string& gpu_driver_bug_list_json,
146 const GPUInfo& gpu_info);
147
148 void UpdateBlacklistedFeatures(const std::set<int>& features);
149
150 // This should only be called once at initialization time, when preliminary
151 // gpu info is collected.
152 void UpdatePreliminaryBlacklistedFeatures();
153
154 // Update the GPU switching status.
155 // This should only be called once at initialization time.
156 void UpdateGpuSwitchingManager(const GPUInfo& gpu_info);
157
158 // Notify all observers whenever there is a GPU info update.
159 void NotifyGpuInfoUpdate();
160
161 // Try to switch to SwiftShader rendering, if possible and necessary.
162 void EnableSwiftShaderIfNecessary();
163
164 // Helper to extract the domain from a given URL.
165 std::string GetDomainFromURL(const GURL& url) const;
166
167 // Implementation functions for blocking of 3D graphics APIs, used
168 // for unit testing.
169 void BlockDomainFrom3DAPIsAtTime(const GURL& url,
170 GpuDataManagerImpl::DomainGuilt guilt,
171 base::Time at_time);
172 GpuDataManagerImpl::DomainBlockStatus Are3DAPIsBlockedAtTime(
173 const GURL& url, base::Time at_time) const;
174 int64 GetBlockAllDomainsDurationInMs() const;
175
176 void Notify3DAPIBlocked(const GURL& url,
177 int render_process_id,
178 int render_view_id,
179 ThreeDAPIType requester);
180
181 bool complete_gpu_info_already_requested_;
182
183 std::set<int> blacklisted_features_;
184 std::set<int> preliminary_blacklisted_features_;
185
186 GpuSwitchingOption gpu_switching_;
187
188 std::set<int> gpu_driver_bugs_;
189
190 GPUInfo gpu_info_;
191
192 scoped_ptr<GpuBlacklist> gpu_blacklist_;
193 scoped_ptr<GpuSwitchingList> gpu_switching_list_;
194 scoped_ptr<GpuDriverBugList> gpu_driver_bug_list_;
195
196 const scoped_refptr<GpuDataManagerObserverList> observer_list_;
197
198 ListValue log_messages_;
199
200 bool use_swiftshader_;
201
202 base::FilePath swiftshader_path_;
203
204 // Current card force-blacklisted due to GPU crashes, or disabled through
205 // the --disable-gpu commandline switch.
206 bool card_blacklisted_;
207
208 // We disable histogram stuff in testing, especially in unit tests because
209 // they cause random failures.
210 bool update_histograms_;
211
212 // Number of currently open windows, to be used in gpu memory allocation.
213 int window_count_;
214
215 DomainBlockMap blocked_domains_;
216 mutable std::list<base::Time> timestamps_of_gpu_resets_;
217 bool domain_blocking_enabled_;
218
219 std::vector<GpuSwitchCallback> gpu_switch_callbacks_;
220
221 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImplPrivate);
222 };
223
224 } // namespace content
225
226 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_PRIVATE_H_
227
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698