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

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

Issue 14981007: Refactor GpuDataManagerImpl to make it thread-safe. (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
« no previous file with comments | « no previous file | content/browser/gpu/gpu_data_manager_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ 5 #ifndef CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_
6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ 6 #define CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_
7 7
8 #include <list>
9 #include <map>
10 #include <set>
11 #include <string> 8 #include <string>
12 #include <vector>
13 9
14 #include "base/callback.h"
15 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
16 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
17 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
18 #include "base/memory/ref_counted.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
20 #include "base/observer_list_threadsafe.h"
21 #include "base/process_util.h" 16 #include "base/process_util.h"
22 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
23 #include "base/time.h" 18 #include "base/time.h"
24 #include "base/values.h" 19 #include "base/values.h"
25 #include "content/browser/gpu/gpu_blacklist.h"
26 #include "content/browser/gpu/gpu_driver_bug_list.h"
27 #include "content/browser/gpu/gpu_switching_list.h"
28 #include "content/public/browser/gpu_data_manager.h" 20 #include "content/public/browser/gpu_data_manager.h"
29 #include "content/public/common/gpu_info.h" 21 #include "content/public/common/gpu_info.h"
30 #include "content/public/common/gpu_memory_stats.h" 22 #include "content/public/common/gpu_memory_stats.h"
31 #include "content/public/common/gpu_switching_option.h" 23 #include "content/public/common/gpu_switching_option.h"
32 #include "content/public/common/three_d_api_types.h" 24 #include "content/public/common/three_d_api_types.h"
33 25
34 class CommandLine; 26 class CommandLine;
35 class GURL; 27 class GURL;
36 struct WebPreferences; 28 struct WebPreferences;
37 29
38 namespace content { 30 namespace content {
39 31
32 class GpuDataManagerImplPrivate;
33
40 class CONTENT_EXPORT GpuDataManagerImpl 34 class CONTENT_EXPORT GpuDataManagerImpl
41 : public NON_EXPORTED_BASE(GpuDataManager) { 35 : public NON_EXPORTED_BASE(GpuDataManager) {
42 public: 36 public:
43 // Indicates the guilt level of a domain which caused a GPU reset. 37 // Indicates the guilt level of a domain which caused a GPU reset.
44 // If a domain is 100% known to be guilty of resetting the GPU, then 38 // If a domain is 100% known to be guilty of resetting the GPU, then
45 // it will generally not cause other domains' use of 3D APIs to be 39 // it will generally not cause other domains' use of 3D APIs to be
46 // blocked, unless system stability would be compromised. 40 // blocked, unless system stability would be compromised.
47 enum DomainGuilt { 41 enum DomainGuilt {
48 DOMAIN_GUILT_KNOWN, 42 DOMAIN_GUILT_KNOWN,
49 DOMAIN_GUILT_UNKNOWN 43 DOMAIN_GUILT_UNKNOWN
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // because it is called from Chrome side code. 150 // because it is called from Chrome side code.
157 void BlockDomainFrom3DAPIs(const GURL& url, DomainGuilt guilt); 151 void BlockDomainFrom3DAPIs(const GURL& url, DomainGuilt guilt);
158 bool Are3DAPIsBlocked(const GURL& url, 152 bool Are3DAPIsBlocked(const GURL& url,
159 int render_process_id, 153 int render_process_id,
160 int render_view_id, 154 int render_view_id,
161 ThreeDAPIType requester); 155 ThreeDAPIType requester);
162 156
163 // Disables domain blocking for 3D APIs. For use only in tests. 157 // Disables domain blocking for 3D APIs. For use only in tests.
164 void DisableDomainBlockingFor3DAPIsForTesting(); 158 void DisableDomainBlockingFor3DAPIsForTesting();
165 159
166 // Get number of features being blacklisted.
167 size_t GetBlacklistedFeatureCount() const;
168
169 typedef base::Callback<void()> GpuSwitchCallback;
170
171 // Add and remove gpu switch callback.
172 void AddGpuSwitchCallback(const GpuSwitchCallback& callback);
173 void RemoveGpuSwitchCallback(const GpuSwitchCallback& callback);
174
175 private:
176 struct DomainBlockEntry {
177 DomainGuilt last_guilt;
178 };
179
180 typedef std::map<std::string, DomainBlockEntry> DomainBlockMap;
181
182 typedef ObserverListThreadSafe<GpuDataManagerObserver>
183 GpuDataManagerObserverList;
184
185 friend class GpuDataManagerImplTest;
186 friend struct DefaultSingletonTraits<GpuDataManagerImpl>;
187
188 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideBlacklisting);
189 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuSideExceptions);
190 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
191 DisableHardwareAcceleration);
192 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SwiftShaderRendering);
193 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, SwiftShaderRendering2);
194 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuInfoUpdate);
195 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
196 NoGpuInfoUpdateWithSwiftShader);
197 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
198 GPUVideoMemoryUsageStatsUpdate);
199 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
200 BlockAllDomainsFrom3DAPIs);
201 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
202 UnblockGuiltyDomainFrom3DAPIs);
203 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
204 UnblockDomainOfUnknownGuiltFrom3DAPIs);
205 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
206 UnblockOtherDomainFrom3DAPIs);
207 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest,
208 UnblockThisDomainFrom3DAPIs);
209 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuDriverBugListSingle);
210 FRIEND_TEST_ALL_PREFIXES(GpuDataManagerImplTest, GpuDriverBugListMultiple);
211
212 GpuDataManagerImpl();
213 virtual ~GpuDataManagerImpl();
214
215 void InitializeImpl(const std::string& gpu_blacklist_json,
216 const std::string& gpu_switching_list_json,
217 const std::string& gpu_driver_bug_list_json,
218 const GPUInfo& gpu_info);
219
220 void UpdateBlacklistedFeatures(const std::set<int>& features);
221
222 // This should only be called once at initialization time, when preliminary
223 // gpu info is collected.
224 void UpdatePreliminaryBlacklistedFeatures();
225
226 // Update the GPU switching status.
227 // This should only be called once at initialization time.
228 void UpdateGpuSwitchingManager(const GPUInfo& gpu_info);
229
230 // Notify all observers whenever there is a GPU info update.
231 void NotifyGpuInfoUpdate();
232
233 // Try to switch to SwiftShader rendering, if possible and necessary.
234 void EnableSwiftShaderIfNecessary();
235
236 // Helper to extract the domain from a given URL.
237 std::string GetDomainFromURL(const GURL& url) const;
238
239 // Implementation functions for blocking of 3D graphics APIs, used
240 // for unit testing.
241 void BlockDomainFrom3DAPIsAtTime(
242 const GURL& url, DomainGuilt guilt, base::Time at_time);
243 DomainBlockStatus Are3DAPIsBlockedAtTime(
244 const GURL& url, base::Time at_time) const;
245 int64 GetBlockAllDomainsDurationInMs() const;
246
247 void Notify3DAPIBlocked(const GURL& url, 160 void Notify3DAPIBlocked(const GURL& url,
248 int render_process_id, 161 int render_process_id,
249 int render_view_id, 162 int render_view_id,
250 ThreeDAPIType requester); 163 ThreeDAPIType requester);
251 164
252 bool complete_gpu_info_already_requested_; 165 // Get number of features being blacklisted.
166 size_t GetBlacklistedFeatureCount() const;
253 167
254 std::set<int> blacklisted_features_; 168 private:
255 std::set<int> preliminary_blacklisted_features_; 169 friend class GpuDataManagerImplPrivate;
170 friend class GpuDataManagerImplPrivateTest;
171 friend struct DefaultSingletonTraits<GpuDataManagerImpl>;
256 172
257 GpuSwitchingOption gpu_switching_; 173 // It's similar to AutoUnlock, but we want to make it a no-op
174 // if the owner GpuDataManagerImpl is null.
175 // This should only be used by GpuDataManagerImplPrivate where
176 // callbacks are called, during which re-entering
177 // GpuDataManagerImpl is possible.
178 class UnlockedSession {
179 public:
180 explicit UnlockedSession(GpuDataManagerImpl* owner)
181 : owner_(owner) {
182 DCHECK(owner_);
183 owner_->lock_.AssertAcquired();
184 owner_->lock_.Release();
185 }
258 186
259 std::set<int> gpu_driver_bugs_; 187 ~UnlockedSession() {
188 DCHECK(owner_);
189 owner_->lock_.Acquire();
190 }
260 191
261 GPUInfo gpu_info_; 192 private:
262 mutable base::Lock gpu_info_lock_; 193 GpuDataManagerImpl* owner_;
194 DISALLOW_COPY_AND_ASSIGN(UnlockedSession);
195 };
263 196
264 scoped_ptr<GpuBlacklist> gpu_blacklist_; 197 GpuDataManagerImpl();
265 scoped_ptr<GpuSwitchingList> gpu_switching_list_; 198 virtual ~GpuDataManagerImpl();
266 scoped_ptr<GpuDriverBugList> gpu_driver_bug_list_;
267 199
268 const scoped_refptr<GpuDataManagerObserverList> observer_list_; 200 mutable base::Lock lock_;
269 201 scoped_ptr<GpuDataManagerImplPrivate> private_;
270 ListValue log_messages_;
271 mutable base::Lock log_messages_lock_;
272
273 bool use_swiftshader_;
274
275 base::FilePath swiftshader_path_;
276
277 // Current card force-blacklisted due to GPU crashes, or disabled through
278 // the --disable-gpu commandline switch.
279 bool card_blacklisted_;
280
281 // We disable histogram stuff in testing, especially in unit tests because
282 // they cause random failures.
283 bool update_histograms_;
284
285 // Number of currently open windows, to be used in gpu memory allocation.
286 int window_count_;
287
288 DomainBlockMap blocked_domains_;
289 mutable std::list<base::Time> timestamps_of_gpu_resets_;
290 bool domain_blocking_enabled_;
291
292 std::vector<GpuSwitchCallback> gpu_switch_callbacks_;
293 202
294 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl); 203 DISALLOW_COPY_AND_ASSIGN(GpuDataManagerImpl);
295 }; 204 };
296 205
297 } // namespace content 206 } // namespace content
298 207
299 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_ 208 #endif // CONTENT_BROWSER_GPU_GPU_DATA_MANAGER_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/gpu/gpu_data_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698