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

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

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
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 #include "content/browser/gpu/gpu_data_manager_impl.h" 5 #include "content/browser/gpu/gpu_data_manager_impl_private.h"
6 6
7 #if defined(OS_MACOSX) 7 #if defined(OS_MACOSX)
8 #include <ApplicationServices/ApplicationServices.h> 8 #include <ApplicationServices/ApplicationServices.h>
9 #endif // OS_MACOSX 9 #endif // OS_MACOSX
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/debug/trace_event.h" 14 #include "base/debug/trace_event.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_piece.h" 20 #include "base/strings/string_piece.h"
21 #include "base/sys_info.h" 21 #include "base/sys_info.h"
22 #include "base/values.h"
23 #include "base/version.h" 22 #include "base/version.h"
24 #include "content/browser/gpu/gpu_process_host.h" 23 #include "content/browser/gpu/gpu_process_host.h"
25 #include "content/browser/gpu/gpu_util.h" 24 #include "content/browser/gpu/gpu_util.h"
26 #include "content/common/gpu/gpu_messages.h" 25 #include "content/common/gpu/gpu_messages.h"
27 #include "content/gpu/gpu_info_collector.h" 26 #include "content/gpu/gpu_info_collector.h"
28 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/gpu_data_manager_observer.h" 28 #include "content/public/browser/gpu_data_manager_observer.h"
30 #include "content/public/common/content_client.h" 29 #include "content/public/common/content_client.h"
31 #include "content/public/common/content_constants.h" 30 #include "content/public/common/content_constants.h"
32 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // Enums for UMA histograms. 94 // Enums for UMA histograms.
96 enum BlockStatusHistogram { 95 enum BlockStatusHistogram {
97 BLOCK_STATUS_NOT_BLOCKED, 96 BLOCK_STATUS_NOT_BLOCKED,
98 BLOCK_STATUS_SPECIFIC_DOMAIN_BLOCKED, 97 BLOCK_STATUS_SPECIFIC_DOMAIN_BLOCKED,
99 BLOCK_STATUS_ALL_DOMAINS_BLOCKED, 98 BLOCK_STATUS_ALL_DOMAINS_BLOCKED,
100 BLOCK_STATUS_MAX 99 BLOCK_STATUS_MAX
101 }; 100 };
102 101
103 } // namespace anonymous 102 } // namespace anonymous
104 103
105 // static 104 void GpuDataManagerImplPrivate::InitializeForTesting(
106 GpuDataManager* GpuDataManager::GetInstance() {
107 return GpuDataManagerImpl::GetInstance();
108 }
109
110 // static
111 GpuDataManagerImpl* GpuDataManagerImpl::GetInstance() {
112 return Singleton<GpuDataManagerImpl>::get();
113 }
114
115 void GpuDataManagerImpl::InitializeForTesting(
116 const std::string& gpu_blacklist_json, 105 const std::string& gpu_blacklist_json,
117 const GPUInfo& gpu_info) { 106 const GPUInfo& gpu_info) {
118 // This function is for testing only, so disable histograms. 107 // This function is for testing only, so disable histograms.
119 update_histograms_ = false; 108 update_histograms_ = false;
120 109
121 InitializeImpl(gpu_blacklist_json, std::string(), std::string(), gpu_info); 110 InitializeImpl(gpu_blacklist_json, std::string(), std::string(), gpu_info);
122 } 111 }
123 112
124 bool GpuDataManagerImpl::IsFeatureBlacklisted(int feature) const { 113 bool GpuDataManagerImplPrivate::IsFeatureBlacklisted(int feature) const {
125 if (use_swiftshader_) { 114 if (use_swiftshader_) {
126 // Skia's software rendering is probably more efficient than going through 115 // Skia's software rendering is probably more efficient than going through
127 // software emulation of the GPU, so use that. 116 // software emulation of the GPU, so use that.
128 if (feature == GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) 117 if (feature == GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
129 return true; 118 return true;
130 return false; 119 return false;
131 } 120 }
132 121
133 return (blacklisted_features_.count(feature) == 1); 122 return (blacklisted_features_.count(feature) == 1);
134 } 123 }
135 124
136 size_t GpuDataManagerImpl::GetBlacklistedFeatureCount() const { 125 size_t GpuDataManagerImplPrivate::GetBlacklistedFeatureCount() const {
137 if (use_swiftshader_) 126 if (use_swiftshader_)
138 return 1; 127 return 1;
139 return blacklisted_features_.size(); 128 return blacklisted_features_.size();
140 } 129 }
141 130
142 void GpuDataManagerImpl::AddGpuSwitchCallback( 131 GPUInfo GpuDataManagerImplPrivate::GetGPUInfo() const {
143 const GpuSwitchCallback& callback) { 132 return gpu_info_;
144 gpu_switch_callbacks_.push_back(callback);
145 } 133 }
146 134
147 void GpuDataManagerImpl::RemoveGpuSwitchCallback( 135 void GpuDataManagerImplPrivate::GetGpuProcessHandles(
148 const GpuSwitchCallback& callback) { 136 const GpuDataManager::GetGpuProcessHandlesCallback& callback) const {
149 for (size_t i = 0; i < gpu_switch_callbacks_.size(); i++) {
150 if (gpu_switch_callbacks_[i].Equals(callback)) {
151 gpu_switch_callbacks_.erase(gpu_switch_callbacks_.begin() + i);
152 return;
153 }
154 }
155 }
156
157 GPUInfo GpuDataManagerImpl::GetGPUInfo() const {
158 GPUInfo gpu_info;
159 {
160 base::AutoLock auto_lock(gpu_info_lock_);
161 gpu_info = gpu_info_;
162 }
163 return gpu_info;
164 }
165
166 void GpuDataManagerImpl::GetGpuProcessHandles(
167 const GetGpuProcessHandlesCallback& callback) const {
168 GpuProcessHost::GetProcessHandles(callback); 137 GpuProcessHost::GetProcessHandles(callback);
169 } 138 }
170 139
171 bool GpuDataManagerImpl::GpuAccessAllowed(std::string* reason) const { 140 bool GpuDataManagerImplPrivate::GpuAccessAllowed(
141 std::string* reason) const {
172 if (use_swiftshader_) 142 if (use_swiftshader_)
173 return true; 143 return true;
174 144
175 if (!gpu_info_.gpu_accessible) { 145 if (!gpu_info_.gpu_accessible) {
176 if (reason) { 146 if (reason) {
177 *reason = "GPU process launch failed."; 147 *reason = "GPU process launch failed.";
178 } 148 }
179 return false; 149 return false;
180 } 150 }
181 151
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 if (reason) { 183 if (reason) {
214 *reason = "All GPU features are blacklisted."; 184 *reason = "All GPU features are blacklisted.";
215 } 185 }
216 return false; 186 return false;
217 #endif 187 #endif
218 } 188 }
219 189
220 return true; 190 return true;
221 } 191 }
222 192
223 void GpuDataManagerImpl::RequestCompleteGpuInfoIfNeeded() { 193 void GpuDataManagerImplPrivate::RequestCompleteGpuInfoIfNeeded() {
224 if (complete_gpu_info_already_requested_ || gpu_info_.finalized) 194 if (complete_gpu_info_already_requested_ || gpu_info_.finalized)
225 return; 195 return;
226 complete_gpu_info_already_requested_ = true; 196 complete_gpu_info_already_requested_ = true;
227 197
228 GpuProcessHost::SendOnIO( 198 GpuProcessHost::SendOnIO(
229 #if defined(OS_WIN) 199 #if defined(OS_WIN)
230 GpuProcessHost::GPU_PROCESS_KIND_UNSANDBOXED, 200 GpuProcessHost::GPU_PROCESS_KIND_UNSANDBOXED,
231 #else 201 #else
232 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, 202 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
233 #endif 203 #endif
234 CAUSE_FOR_GPU_LAUNCH_GPUDATAMANAGER_REQUESTCOMPLETEGPUINFOIFNEEDED, 204 CAUSE_FOR_GPU_LAUNCH_GPUDATAMANAGER_REQUESTCOMPLETEGPUINFOIFNEEDED,
235 new GpuMsg_CollectGraphicsInfo()); 205 new GpuMsg_CollectGraphicsInfo());
236 } 206 }
237 207
238 bool GpuDataManagerImpl::IsCompleteGpuInfoAvailable() const { 208 bool GpuDataManagerImplPrivate::IsCompleteGpuInfoAvailable() const {
239 return gpu_info_.finalized; 209 return gpu_info_.finalized;
240 } 210 }
241 211
242 void GpuDataManagerImpl::RequestVideoMemoryUsageStatsUpdate() const { 212 void GpuDataManagerImplPrivate::RequestVideoMemoryUsageStatsUpdate() const {
243 GpuProcessHost::SendOnIO( 213 GpuProcessHost::SendOnIO(
244 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, 214 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
245 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, 215 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH,
246 new GpuMsg_GetVideoMemoryUsageStats()); 216 new GpuMsg_GetVideoMemoryUsageStats());
247 } 217 }
248 218
249 bool GpuDataManagerImpl::ShouldUseSwiftShader() const { 219 bool GpuDataManagerImplPrivate::ShouldUseSwiftShader() const {
250 return use_swiftshader_; 220 return use_swiftshader_;
251 } 221 }
252 222
253 void GpuDataManagerImpl::RegisterSwiftShaderPath(const base::FilePath& path) { 223 void GpuDataManagerImplPrivate::RegisterSwiftShaderPath(
224 const base::FilePath& path) {
254 swiftshader_path_ = path; 225 swiftshader_path_ = path;
255 EnableSwiftShaderIfNecessary(); 226 EnableSwiftShaderIfNecessary();
256 } 227 }
257 228
258 void GpuDataManagerImpl::AddObserver(GpuDataManagerObserver* observer) { 229 void GpuDataManagerImplPrivate::AddObserver(GpuDataManagerObserver* observer) {
230 GpuDataManagerImpl::UnlockedSession session(owner_);
259 observer_list_->AddObserver(observer); 231 observer_list_->AddObserver(observer);
260 } 232 }
261 233
262 void GpuDataManagerImpl::RemoveObserver(GpuDataManagerObserver* observer) { 234 void GpuDataManagerImplPrivate::RemoveObserver(
235 GpuDataManagerObserver* observer) {
236 GpuDataManagerImpl::UnlockedSession session(owner_);
263 observer_list_->RemoveObserver(observer); 237 observer_list_->RemoveObserver(observer);
264 } 238 }
265 239
266 void GpuDataManagerImpl::UnblockDomainFrom3DAPIs(const GURL& url) { 240 void GpuDataManagerImplPrivate::UnblockDomainFrom3DAPIs(const GURL& url) {
267 // This method must do two things: 241 // This method must do two things:
268 // 242 //
269 // 1. If the specific domain is blocked, then unblock it. 243 // 1. If the specific domain is blocked, then unblock it.
270 // 244 //
271 // 2. Reset our notion of how many GPU resets have occurred recently. 245 // 2. Reset our notion of how many GPU resets have occurred recently.
272 // This is necessary even if the specific domain was blocked. 246 // This is necessary even if the specific domain was blocked.
273 // Otherwise, if we call Are3DAPIsBlocked with the same domain right 247 // Otherwise, if we call Are3DAPIsBlocked with the same domain right
274 // after unblocking it, it will probably still be blocked because of 248 // after unblocking it, it will probably still be blocked because of
275 // the recent GPU reset caused by that domain. 249 // the recent GPU reset caused by that domain.
276 // 250 //
277 // These policies could be refined, but at a certain point the behavior 251 // These policies could be refined, but at a certain point the behavior
278 // will become difficult to explain. 252 // will become difficult to explain.
279 std::string domain = GetDomainFromURL(url); 253 std::string domain = GetDomainFromURL(url);
280 254
281 base::AutoLock auto_lock(gpu_info_lock_);
282 blocked_domains_.erase(domain); 255 blocked_domains_.erase(domain);
283 timestamps_of_gpu_resets_.clear(); 256 timestamps_of_gpu_resets_.clear();
284 } 257 }
285 258
286 void GpuDataManagerImpl::DisableGpuWatchdog() { 259 void GpuDataManagerImplPrivate::DisableGpuWatchdog() {
287 GpuProcessHost::SendOnIO( 260 GpuProcessHost::SendOnIO(
288 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, 261 GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
289 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, 262 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH,
290 new GpuMsg_DisableWatchdog); 263 new GpuMsg_DisableWatchdog);
291 } 264 }
292 265
293 void GpuDataManagerImpl::SetGLStrings(const std::string& gl_vendor, 266 void GpuDataManagerImplPrivate::SetGLStrings(const std::string& gl_vendor,
294 const std::string& gl_renderer, 267 const std::string& gl_renderer,
295 const std::string& gl_version) { 268 const std::string& gl_version) {
296 if (gl_vendor.empty() && gl_renderer.empty() && gl_version.empty()) 269 if (gl_vendor.empty() && gl_renderer.empty() && gl_version.empty())
297 return; 270 return;
298 271
299 GPUInfo gpu_info; 272 // If GPUInfo already got GL strings, do nothing. This is for the rare
300 { 273 // situation where GPU process collected GL strings before this call.
301 base::AutoLock auto_lock(gpu_info_lock_); 274 if (!gpu_info_.gl_vendor.empty() ||
302 // If GPUInfo already got GL strings, do nothing. This is for the rare 275 !gpu_info_.gl_renderer.empty() ||
303 // situation where GPU process collected GL strings before this call. 276 !gpu_info_.gl_version_string.empty())
304 if (!gpu_info_.gl_vendor.empty() || 277 return;
305 !gpu_info_.gl_renderer.empty() || 278
306 !gpu_info_.gl_version_string.empty()) 279 GPUInfo gpu_info = gpu_info_;
307 return;
308 gpu_info = gpu_info_;
309 }
310 280
311 gpu_info.gl_vendor = gl_vendor; 281 gpu_info.gl_vendor = gl_vendor;
312 gpu_info.gl_renderer = gl_renderer; 282 gpu_info.gl_renderer = gl_renderer;
313 gpu_info.gl_version_string = gl_version; 283 gpu_info.gl_version_string = gl_version;
314 284
315 gpu_info_collector::CollectDriverInfoGL(&gpu_info); 285 gpu_info_collector::CollectDriverInfoGL(&gpu_info);
316 286
317 UpdateGpuInfo(gpu_info); 287 UpdateGpuInfo(gpu_info);
318 UpdateGpuSwitchingManager(gpu_info); 288 UpdateGpuSwitchingManager(gpu_info);
319 UpdatePreliminaryBlacklistedFeatures(); 289 UpdatePreliminaryBlacklistedFeatures();
320 } 290 }
321 291
322 void GpuDataManagerImpl::GetGLStrings(std::string* gl_vendor, 292 void GpuDataManagerImplPrivate::GetGLStrings(std::string* gl_vendor,
323 std::string* gl_renderer, 293 std::string* gl_renderer,
324 std::string* gl_version) { 294 std::string* gl_version) {
325 DCHECK(gl_vendor && gl_renderer && gl_version); 295 DCHECK(gl_vendor && gl_renderer && gl_version);
326 296
327 base::AutoLock auto_lock(gpu_info_lock_);
328 *gl_vendor = gpu_info_.gl_vendor; 297 *gl_vendor = gpu_info_.gl_vendor;
329 *gl_renderer = gpu_info_.gl_renderer; 298 *gl_renderer = gpu_info_.gl_renderer;
330 *gl_version = gpu_info_.gl_version_string; 299 *gl_version = gpu_info_.gl_version_string;
331 } 300 }
332 301
333 302 void GpuDataManagerImplPrivate::Initialize() {
334 void GpuDataManagerImpl::Initialize() {
335 TRACE_EVENT0("startup", "GpuDataManagerImpl::Initialize"); 303 TRACE_EVENT0("startup", "GpuDataManagerImpl::Initialize");
336 CommandLine* command_line = CommandLine::ForCurrentProcess(); 304 CommandLine* command_line = CommandLine::ForCurrentProcess();
337 if (command_line->HasSwitch(switches::kSkipGpuDataLoading)) 305 if (command_line->HasSwitch(switches::kSkipGpuDataLoading))
338 return; 306 return;
339 307
340 GPUInfo gpu_info; 308 GPUInfo gpu_info;
341 { 309 {
342 TRACE_EVENT0("startup", 310 TRACE_EVENT0("startup",
343 "GpuDataManagerImpl::Initialize:CollectBasicGraphicsInfo"); 311 "GpuDataManagerImpl::Initialize:CollectBasicGraphicsInfo");
344 gpu_info_collector::CollectBasicGraphicsInfo(&gpu_info); 312 gpu_info_collector::CollectBasicGraphicsInfo(&gpu_info);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // have a GPU process, we append the browser process commandline. 344 // have a GPU process, we append the browser process commandline.
377 if (command_line->HasSwitch(switches::kSingleProcess) || 345 if (command_line->HasSwitch(switches::kSingleProcess) ||
378 command_line->HasSwitch(switches::kInProcessGPU)) { 346 command_line->HasSwitch(switches::kInProcessGPU)) {
379 if (!gpu_driver_bugs_.empty()) { 347 if (!gpu_driver_bugs_.empty()) {
380 command_line->AppendSwitchASCII(switches::kGpuDriverBugWorkarounds, 348 command_line->AppendSwitchASCII(switches::kGpuDriverBugWorkarounds,
381 IntSetToString(gpu_driver_bugs_)); 349 IntSetToString(gpu_driver_bugs_));
382 } 350 }
383 } 351 }
384 } 352 }
385 353
386 void GpuDataManagerImpl::UpdateGpuInfo(const GPUInfo& gpu_info) { 354 void GpuDataManagerImplPrivate::UpdateGpuInfo(const GPUInfo& gpu_info) {
387 // No further update of gpu_info if falling back to SwiftShader. 355 // No further update of gpu_info if falling back to SwiftShader.
388 if (use_swiftshader_) 356 if (use_swiftshader_)
389 return; 357 return;
390 358
391 GPUInfo my_gpu_info; 359 gpu_info_collector::MergeGPUInfo(&gpu_info_, gpu_info);
392 { 360 complete_gpu_info_already_requested_ =
393 base::AutoLock auto_lock(gpu_info_lock_); 361 complete_gpu_info_already_requested_ || gpu_info_.finalized;
394 gpu_info_collector::MergeGPUInfo(&gpu_info_, gpu_info);
395 complete_gpu_info_already_requested_ =
396 complete_gpu_info_already_requested_ || gpu_info_.finalized;
397 my_gpu_info = gpu_info_;
398 }
399 362
400 GetContentClient()->SetGpuInfo(my_gpu_info); 363 GetContentClient()->SetGpuInfo(gpu_info_);
401 364
402 if (gpu_blacklist_) { 365 if (gpu_blacklist_) {
403 std::set<int> features = gpu_blacklist_->MakeDecision( 366 std::set<int> features = gpu_blacklist_->MakeDecision(
404 GpuControlList::kOsAny, std::string(), my_gpu_info); 367 GpuControlList::kOsAny, std::string(), gpu_info_);
405 if (update_histograms_) 368 if (update_histograms_)
406 UpdateStats(gpu_blacklist_.get(), features); 369 UpdateStats(gpu_blacklist_.get(), features);
407 370
408 UpdateBlacklistedFeatures(features); 371 UpdateBlacklistedFeatures(features);
409 } 372 }
410 if (gpu_switching_list_) { 373 if (gpu_switching_list_) {
411 std::set<int> option = gpu_switching_list_->MakeDecision( 374 std::set<int> option = gpu_switching_list_->MakeDecision(
412 GpuControlList::kOsAny, std::string(), my_gpu_info); 375 GpuControlList::kOsAny, std::string(), gpu_info_);
413 if (option.size() == 1) { 376 if (option.size() == 1) {
414 // Blacklist decision should not overwrite commandline switch from users. 377 // Blacklist decision should not overwrite commandline switch from users.
415 CommandLine* command_line = CommandLine::ForCurrentProcess(); 378 CommandLine* command_line = CommandLine::ForCurrentProcess();
416 if (!command_line->HasSwitch(switches::kGpuSwitching)) 379 if (!command_line->HasSwitch(switches::kGpuSwitching))
417 gpu_switching_ = static_cast<GpuSwitchingOption>(*(option.begin())); 380 gpu_switching_ = static_cast<GpuSwitchingOption>(*(option.begin()));
418 } 381 }
419 } 382 }
420 if (gpu_driver_bug_list_) 383 if (gpu_driver_bug_list_)
421 gpu_driver_bugs_ = gpu_driver_bug_list_->MakeDecision( 384 gpu_driver_bugs_ = gpu_driver_bug_list_->MakeDecision(
422 GpuControlList::kOsAny, std::string(), my_gpu_info); 385 GpuControlList::kOsAny, std::string(), gpu_info_);
423 386
424 // We have to update GpuFeatureType before notify all the observers. 387 // We have to update GpuFeatureType before notify all the observers.
425 NotifyGpuInfoUpdate(); 388 NotifyGpuInfoUpdate();
426 } 389 }
427 390
428 void GpuDataManagerImpl::UpdateVideoMemoryUsageStats( 391 void GpuDataManagerImplPrivate::UpdateVideoMemoryUsageStats(
429 const GPUVideoMemoryUsageStats& video_memory_usage_stats) { 392 const GPUVideoMemoryUsageStats& video_memory_usage_stats) {
393 GpuDataManagerImpl::UnlockedSession session(owner_);
430 observer_list_->Notify(&GpuDataManagerObserver::OnVideoMemoryUsageStatsUpdate, 394 observer_list_->Notify(&GpuDataManagerObserver::OnVideoMemoryUsageStatsUpdate,
431 video_memory_usage_stats); 395 video_memory_usage_stats);
432 } 396 }
433 397
434 void GpuDataManagerImpl::AppendRendererCommandLine( 398 void GpuDataManagerImplPrivate::AppendRendererCommandLine(
435 CommandLine* command_line) const { 399 CommandLine* command_line) const {
436 DCHECK(command_line); 400 DCHECK(command_line);
437 401
438 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)) { 402 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)) {
439 #if !defined(OS_ANDROID) 403 #if !defined(OS_ANDROID)
440 if (!command_line->HasSwitch(switches::kDisableExperimentalWebGL)) 404 if (!command_line->HasSwitch(switches::kDisableExperimentalWebGL))
441 command_line->AppendSwitch(switches::kDisableExperimentalWebGL); 405 command_line->AppendSwitch(switches::kDisableExperimentalWebGL);
442 #endif 406 #endif
443 if (!command_line->HasSwitch(switches::kDisablePepper3d)) 407 if (!command_line->HasSwitch(switches::kDisablePepper3d))
444 command_line->AppendSwitch(switches::kDisablePepper3d); 408 command_line->AppendSwitch(switches::kDisablePepper3d);
445 } 409 }
446 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_MULTISAMPLING) && 410 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_MULTISAMPLING) &&
447 !command_line->HasSwitch(switches::kDisableGLMultisampling)) 411 !command_line->HasSwitch(switches::kDisableGLMultisampling))
448 command_line->AppendSwitch(switches::kDisableGLMultisampling); 412 command_line->AppendSwitch(switches::kDisableGLMultisampling);
449 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) && 413 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) &&
450 !command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) 414 !command_line->HasSwitch(switches::kDisableAcceleratedCompositing))
451 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); 415 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing);
452 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) && 416 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) &&
453 !command_line->HasSwitch(switches::kDisableAccelerated2dCanvas)) 417 !command_line->HasSwitch(switches::kDisableAccelerated2dCanvas))
454 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); 418 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas);
455 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE) && 419 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE) &&
456 !command_line->HasSwitch(switches::kDisableAcceleratedVideoDecode)) 420 !command_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
457 command_line->AppendSwitch(switches::kDisableAcceleratedVideoDecode); 421 command_line->AppendSwitch(switches::kDisableAcceleratedVideoDecode);
458 if (ShouldUseSwiftShader()) 422 if (ShouldUseSwiftShader())
459 command_line->AppendSwitch(switches::kDisableFlashFullscreen3d); 423 command_line->AppendSwitch(switches::kDisableFlashFullscreen3d);
460 } 424 }
461 425
462 void GpuDataManagerImpl::AppendGpuCommandLine( 426 void GpuDataManagerImplPrivate::AppendGpuCommandLine(
463 CommandLine* command_line) const { 427 CommandLine* command_line) const {
464 DCHECK(command_line); 428 DCHECK(command_line);
465 429
466 std::string use_gl = 430 std::string use_gl =
467 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); 431 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
468 base::FilePath swiftshader_path = 432 base::FilePath swiftshader_path =
469 CommandLine::ForCurrentProcess()->GetSwitchValuePath( 433 CommandLine::ForCurrentProcess()->GetSwitchValuePath(
470 switches::kSwiftShaderPath); 434 switches::kSwiftShaderPath);
471 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_MULTISAMPLING) && 435 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_MULTISAMPLING) &&
472 !command_line->HasSwitch(switches::kDisableGLMultisampling)) 436 !command_line->HasSwitch(switches::kDisableGLMultisampling))
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 // http://crbug.com/177611 484 // http://crbug.com/177611
521 // Thinkpad USB Port Replicator driver causes GPU process to crash when the 485 // Thinkpad USB Port Replicator driver causes GPU process to crash when the
522 // sandbox is enabled. http://crbug.com/181665. 486 // sandbox is enabled. http://crbug.com/181665.
523 if ((gpu_info_.display_link_version.IsValid() 487 if ((gpu_info_.display_link_version.IsValid()
524 && gpu_info_.display_link_version.IsOlderThan("7.2")) || 488 && gpu_info_.display_link_version.IsOlderThan("7.2")) ||
525 gpu_info_.lenovo_dcute) { 489 gpu_info_.lenovo_dcute) {
526 command_line->AppendSwitch(switches::kReduceGpuSandbox); 490 command_line->AppendSwitch(switches::kReduceGpuSandbox);
527 } 491 }
528 #endif 492 #endif
529 493
530 { 494 if (gpu_info_.optimus)
531 base::AutoLock auto_lock(gpu_info_lock_); 495 command_line->AppendSwitch(switches::kReduceGpuSandbox);
532 if (gpu_info_.optimus) 496 if (gpu_info_.amd_switchable) {
533 command_line->AppendSwitch(switches::kReduceGpuSandbox); 497 // The image transport surface currently doesn't work with AMD Dynamic
534 if (gpu_info_.amd_switchable) { 498 // Switchable graphics.
535 // The image transport surface currently doesn't work with AMD Dynamic 499 command_line->AppendSwitch(switches::kReduceGpuSandbox);
536 // Switchable graphics. 500 command_line->AppendSwitch(switches::kDisableImageTransportSurface);
537 command_line->AppendSwitch(switches::kReduceGpuSandbox);
538 command_line->AppendSwitch(switches::kDisableImageTransportSurface);
539 }
540 // Pass GPU and driver information to GPU process. We try to avoid full GPU
541 // info collection at GPU process startup, but we need gpu vendor_id,
542 // device_id, driver_vendor, driver_version for deciding whether we need to
543 // collect full info (on Linux) and for crash reporting purpose.
544 command_line->AppendSwitchASCII(switches::kGpuVendorID,
545 base::StringPrintf("0x%04x", gpu_info_.gpu.vendor_id));
546 command_line->AppendSwitchASCII(switches::kGpuDeviceID,
547 base::StringPrintf("0x%04x", gpu_info_.gpu.device_id));
548 command_line->AppendSwitchASCII(switches::kGpuDriverVendor,
549 gpu_info_.driver_vendor);
550 command_line->AppendSwitchASCII(switches::kGpuDriverVersion,
551 gpu_info_.driver_version);
552 } 501 }
502 // Pass GPU and driver information to GPU process. We try to avoid full GPU
503 // info collection at GPU process startup, but we need gpu vendor_id,
504 // device_id, driver_vendor, driver_version for deciding whether we need to
505 // collect full info (on Linux) and for crash reporting purpose.
506 command_line->AppendSwitchASCII(switches::kGpuVendorID,
507 base::StringPrintf("0x%04x", gpu_info_.gpu.vendor_id));
508 command_line->AppendSwitchASCII(switches::kGpuDeviceID,
509 base::StringPrintf("0x%04x", gpu_info_.gpu.device_id));
510 command_line->AppendSwitchASCII(switches::kGpuDriverVendor,
511 gpu_info_.driver_vendor);
512 command_line->AppendSwitchASCII(switches::kGpuDriverVersion,
513 gpu_info_.driver_version);
553 } 514 }
554 515
555 void GpuDataManagerImpl::AppendPluginCommandLine( 516 void GpuDataManagerImplPrivate::AppendPluginCommandLine(
556 CommandLine* command_line) const { 517 CommandLine* command_line) const {
557 DCHECK(command_line); 518 DCHECK(command_line);
558 519
559 #if defined(OS_MACOSX) 520 #if defined(OS_MACOSX)
560 // TODO(jbauman): Add proper blacklist support for core animation plugins so 521 // TODO(jbauman): Add proper blacklist support for core animation plugins so
561 // special-casing this video card won't be necessary. See 522 // special-casing this video card won't be necessary. See
562 // http://crbug.com/134015 523 // http://crbug.com/134015
563 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) || 524 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) ||
564 CommandLine::ForCurrentProcess()->HasSwitch( 525 CommandLine::ForCurrentProcess()->HasSwitch(
565 switches::kDisableAcceleratedCompositing)) { 526 switches::kDisableAcceleratedCompositing)) {
566 if (!command_line->HasSwitch( 527 if (!command_line->HasSwitch(
567 switches::kDisableCoreAnimationPlugins)) 528 switches::kDisableCoreAnimationPlugins))
568 command_line->AppendSwitch( 529 command_line->AppendSwitch(
569 switches::kDisableCoreAnimationPlugins); 530 switches::kDisableCoreAnimationPlugins);
570 } 531 }
571 #endif 532 #endif
572 } 533 }
573 534
574 void GpuDataManagerImpl::UpdateRendererWebPrefs(WebPreferences* prefs) const { 535 void GpuDataManagerImplPrivate::UpdateRendererWebPrefs(
536 WebPreferences* prefs) const {
575 DCHECK(prefs); 537 DCHECK(prefs);
576 538
577 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)) 539 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING))
578 prefs->accelerated_compositing_enabled = false; 540 prefs->accelerated_compositing_enabled = false;
579 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)) 541 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL))
580 prefs->experimental_webgl_enabled = false; 542 prefs->experimental_webgl_enabled = false;
581 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_FLASH3D)) 543 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_FLASH3D))
582 prefs->flash_3d_enabled = false; 544 prefs->flash_3d_enabled = false;
583 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_FLASH_STAGE3D)) { 545 if (IsFeatureBlacklisted(GPU_FEATURE_TYPE_FLASH_STAGE3D)) {
584 prefs->flash_stage3d_enabled = false; 546 prefs->flash_stage3d_enabled = false;
(...skipping 15 matching lines...) Expand all
600 // Accelerated video and animation are slower than regular when using 562 // Accelerated video and animation are slower than regular when using
601 // SwiftShader. 3D CSS may also be too slow to be worthwhile. 563 // SwiftShader. 3D CSS may also be too slow to be worthwhile.
602 if (ShouldUseSwiftShader()) { 564 if (ShouldUseSwiftShader()) {
603 prefs->accelerated_compositing_for_video_enabled = false; 565 prefs->accelerated_compositing_for_video_enabled = false;
604 prefs->accelerated_compositing_for_animation_enabled = false; 566 prefs->accelerated_compositing_for_animation_enabled = false;
605 prefs->accelerated_compositing_for_3d_transforms_enabled = false; 567 prefs->accelerated_compositing_for_3d_transforms_enabled = false;
606 prefs->accelerated_compositing_for_plugins_enabled = false; 568 prefs->accelerated_compositing_for_plugins_enabled = false;
607 } 569 }
608 } 570 }
609 571
610 GpuSwitchingOption GpuDataManagerImpl::GetGpuSwitchingOption() const { 572 GpuSwitchingOption GpuDataManagerImplPrivate::GetGpuSwitchingOption() const {
611 if (!ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) 573 if (!ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus())
612 return GPU_SWITCHING_OPTION_UNKNOWN; 574 return GPU_SWITCHING_OPTION_UNKNOWN;
613 return gpu_switching_; 575 return gpu_switching_;
614 } 576 }
615 577
616 void GpuDataManagerImpl::DisableHardwareAcceleration() { 578 void GpuDataManagerImplPrivate::DisableHardwareAcceleration() {
617 card_blacklisted_ = true; 579 card_blacklisted_ = true;
618 580
619 for (int i = 0; i < NUMBER_OF_GPU_FEATURE_TYPES; ++i) 581 for (int i = 0; i < NUMBER_OF_GPU_FEATURE_TYPES; ++i)
620 blacklisted_features_.insert(i); 582 blacklisted_features_.insert(i);
621 583
622 EnableSwiftShaderIfNecessary(); 584 EnableSwiftShaderIfNecessary();
623 NotifyGpuInfoUpdate(); 585 NotifyGpuInfoUpdate();
624 } 586 }
625 587
626 std::string GpuDataManagerImpl::GetBlacklistVersion() const { 588 std::string GpuDataManagerImplPrivate::GetBlacklistVersion() const {
627 if (gpu_blacklist_) 589 if (gpu_blacklist_)
628 return gpu_blacklist_->version(); 590 return gpu_blacklist_->version();
629 return "0"; 591 return "0";
630 } 592 }
631 593
632 base::ListValue* GpuDataManagerImpl::GetBlacklistReasons() const { 594 base::ListValue* GpuDataManagerImplPrivate::GetBlacklistReasons() const {
633 ListValue* reasons = new ListValue(); 595 ListValue* reasons = new ListValue();
634 if (gpu_blacklist_) 596 if (gpu_blacklist_)
635 gpu_blacklist_->GetReasons(reasons); 597 gpu_blacklist_->GetReasons(reasons);
636 return reasons; 598 return reasons;
637 } 599 }
638 600
639 void GpuDataManagerImpl::AddLogMessage( 601 void GpuDataManagerImplPrivate::AddLogMessage(
640 int level, const std::string& header, const std::string& message) { 602 int level, const std::string& header, const std::string& message) {
641 base::AutoLock auto_lock(log_messages_lock_);
642 DictionaryValue* dict = new DictionaryValue(); 603 DictionaryValue* dict = new DictionaryValue();
643 dict->SetInteger("level", level); 604 dict->SetInteger("level", level);
644 dict->SetString("header", header); 605 dict->SetString("header", header);
645 dict->SetString("message", message); 606 dict->SetString("message", message);
646 log_messages_.Append(dict); 607 log_messages_.Append(dict);
647 } 608 }
648 609
649 void GpuDataManagerImpl::ProcessCrashed(base::TerminationStatus exit_code) { 610 void GpuDataManagerImplPrivate::ProcessCrashed(
611 base::TerminationStatus exit_code) {
650 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 612 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
651 BrowserThread::PostTask(BrowserThread::UI, 613 if (owner_) {
652 FROM_HERE, 614 // Unretained is ok, because it's posted to UI thread, the thread
653 base::Bind(&GpuDataManagerImpl::ProcessCrashed, 615 // where the singleton GpuDataManagerImpl lives until the end.
654 base::Unretained(this), 616 BrowserThread::PostTask(
655 exit_code)); 617 BrowserThread::UI,
618 FROM_HERE,
619 base::Bind(&GpuDataManagerImpl::ProcessCrashed,
620 base::Unretained(owner_),
621 exit_code));
622 }
656 return; 623 return;
657 } 624 }
658 observer_list_->Notify(&GpuDataManagerObserver::OnGpuProcessCrashed, 625 {
Ken Russell (switch to Gerrit) 2013/05/10 23:59:19 This is a little hard to read. Instead of the expl
659 exit_code); 626 GpuDataManagerImpl::UnlockedSession session(owner_);
627 observer_list_->Notify(
628 &GpuDataManagerObserver::OnGpuProcessCrashed, exit_code);
629 }
660 } 630 }
661 631
662 base::ListValue* GpuDataManagerImpl::GetLogMessages() const { 632 base::ListValue* GpuDataManagerImplPrivate::GetLogMessages() const {
663 base::ListValue* value; 633 base::ListValue* value;
664 { 634 value = log_messages_.DeepCopy();
665 base::AutoLock auto_lock(log_messages_lock_);
666 value = log_messages_.DeepCopy();
667 }
668 return value; 635 return value;
669 } 636 }
670 637
671 void GpuDataManagerImpl::HandleGpuSwitch() { 638 void GpuDataManagerImplPrivate::HandleGpuSwitch() {
672 complete_gpu_info_already_requested_ = false; 639 GpuDataManagerImpl::UnlockedSession session(owner_);
673 gpu_info_.finalized = false; 640 observer_list_->Notify(&GpuDataManagerObserver::OnGpuSwitching);
674 for (size_t i = 0; i < gpu_switch_callbacks_.size(); ++i)
675 gpu_switch_callbacks_[i].Run();
676 } 641 }
677 642
678 #if defined(OS_WIN) 643 #if defined(OS_WIN)
679 bool GpuDataManagerImpl::IsUsingAcceleratedSurface() const { 644 bool GpuDataManagerImplPrivate::IsUsingAcceleratedSurface() const {
680 if (base::win::GetVersion() < base::win::VERSION_VISTA) 645 if (base::win::GetVersion() < base::win::VERSION_VISTA)
681 return false; 646 return false;
682 647
683 if (gpu_info_.amd_switchable) 648 if (gpu_info_.amd_switchable)
684 return false; 649 return false;
685 if (use_swiftshader_) 650 if (use_swiftshader_)
686 return false; 651 return false;
687 CommandLine* command_line = CommandLine::ForCurrentProcess(); 652 CommandLine* command_line = CommandLine::ForCurrentProcess();
688 if (command_line->HasSwitch(switches::kDisableImageTransportSurface)) 653 if (command_line->HasSwitch(switches::kDisableImageTransportSurface))
689 return false; 654 return false;
690 return !IsFeatureBlacklisted(GPU_FEATURE_TYPE_TEXTURE_SHARING); 655 return !IsFeatureBlacklisted(GPU_FEATURE_TYPE_TEXTURE_SHARING);
691 } 656 }
692 #endif 657 #endif
693 658
694 void GpuDataManagerImpl::BlockDomainFrom3DAPIs( 659 void GpuDataManagerImplPrivate::BlockDomainFrom3DAPIs(
695 const GURL& url, DomainGuilt guilt) { 660 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt) {
696 BlockDomainFrom3DAPIsAtTime(url, guilt, base::Time::Now()); 661 BlockDomainFrom3DAPIsAtTime(url, guilt, base::Time::Now());
697 } 662 }
698 663
699 bool GpuDataManagerImpl::Are3DAPIsBlocked(const GURL& url, 664 bool GpuDataManagerImplPrivate::Are3DAPIsBlocked(const GURL& url,
700 int render_process_id, 665 int render_process_id,
701 int render_view_id, 666 int render_view_id,
702 ThreeDAPIType requester) { 667 ThreeDAPIType requester) {
703 bool blocked = Are3DAPIsBlockedAtTime(url, base::Time::Now()) != 668 bool blocked = Are3DAPIsBlockedAtTime(url, base::Time::Now()) !=
704 GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED; 669 GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED;
705 if (blocked) { 670 if (blocked && owner_) {
671 // Unretained is ok, because it's posted to UI thread, the thread
672 // where the singleton GpuDataManagerImpl lives until the end.
706 BrowserThread::PostTask( 673 BrowserThread::PostTask(
707 BrowserThread::UI, FROM_HERE, 674 BrowserThread::UI, FROM_HERE,
708 base::Bind(&GpuDataManagerImpl::Notify3DAPIBlocked, 675 base::Bind(&GpuDataManagerImpl::Notify3DAPIBlocked,
709 base::Unretained(this), url, render_process_id, 676 base::Unretained(owner_), url, render_process_id,
710 render_view_id, requester)); 677 render_view_id, requester));
711 } 678 }
712 679
713 return blocked; 680 return blocked;
714 } 681 }
715 682
716 void GpuDataManagerImpl::DisableDomainBlockingFor3DAPIsForTesting() { 683 void GpuDataManagerImplPrivate::DisableDomainBlockingFor3DAPIsForTesting() {
717 domain_blocking_enabled_ = false; 684 domain_blocking_enabled_ = false;
718 } 685 }
719 686
720 GpuDataManagerImpl::GpuDataManagerImpl() 687 // static
688 GpuDataManagerImplPrivate* GpuDataManagerImplPrivate::Create(
689 GpuDataManagerImpl* owner) {
690 GpuDataManagerImplPrivate* rt = new GpuDataManagerImplPrivate();
691 rt->owner_ = owner;
692 return rt;
693 }
694
695 GpuDataManagerImplPrivate::GpuDataManagerImplPrivate()
721 : complete_gpu_info_already_requested_(false), 696 : complete_gpu_info_already_requested_(false),
722 gpu_switching_(GPU_SWITCHING_OPTION_AUTOMATIC), 697 gpu_switching_(GPU_SWITCHING_OPTION_AUTOMATIC),
723 observer_list_(new GpuDataManagerObserverList), 698 observer_list_(new GpuDataManagerObserverList),
724 use_swiftshader_(false), 699 use_swiftshader_(false),
725 card_blacklisted_(false), 700 card_blacklisted_(false),
726 update_histograms_(true), 701 update_histograms_(true),
727 window_count_(0), 702 window_count_(0),
728 domain_blocking_enabled_(true) { 703 domain_blocking_enabled_(true),
704 owner_(NULL) {
729 CommandLine* command_line = CommandLine::ForCurrentProcess(); 705 CommandLine* command_line = CommandLine::ForCurrentProcess();
730 if (command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) { 706 if (command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
731 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); 707 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas);
732 command_line->AppendSwitch(switches::kDisableAcceleratedLayers); 708 command_line->AppendSwitch(switches::kDisableAcceleratedLayers);
733 } 709 }
734 if (command_line->HasSwitch(switches::kDisableGpu)) 710 if (command_line->HasSwitch(switches::kDisableGpu))
735 DisableHardwareAcceleration(); 711 DisableHardwareAcceleration();
736 if (command_line->HasSwitch(switches::kGpuSwitching)) { 712 if (command_line->HasSwitch(switches::kGpuSwitching)) {
737 std::string option_string = command_line->GetSwitchValueASCII( 713 std::string option_string = command_line->GetSwitchValueASCII(
738 switches::kGpuSwitching); 714 switches::kGpuSwitching);
739 GpuSwitchingOption option = StringToGpuSwitchingOption(option_string); 715 GpuSwitchingOption option = StringToGpuSwitchingOption(option_string);
740 if (option != GPU_SWITCHING_OPTION_UNKNOWN) 716 if (option != GPU_SWITCHING_OPTION_UNKNOWN)
741 gpu_switching_ = option; 717 gpu_switching_ = option;
742 } 718 }
743 719
744 #if defined(OS_MACOSX) 720 #if defined(OS_MACOSX)
745 CGDisplayRegisterReconfigurationCallback(DisplayReconfigCallback, this); 721 CGDisplayRegisterReconfigurationCallback(DisplayReconfigCallback, this);
746 #endif // OS_MACOSX 722 #endif // OS_MACOSX
747 } 723 }
748 724
749 GpuDataManagerImpl::~GpuDataManagerImpl() { 725 GpuDataManagerImplPrivate::~GpuDataManagerImplPrivate() {
750 #if defined(OS_MACOSX) 726 #if defined(OS_MACOSX)
751 CGDisplayRemoveReconfigurationCallback(DisplayReconfigCallback, this); 727 CGDisplayRemoveReconfigurationCallback(DisplayReconfigCallback, this);
752 #endif 728 #endif
753 } 729 }
754 730
755 void GpuDataManagerImpl::InitializeImpl( 731 void GpuDataManagerImplPrivate::InitializeImpl(
756 const std::string& gpu_blacklist_json, 732 const std::string& gpu_blacklist_json,
757 const std::string& gpu_switching_list_json, 733 const std::string& gpu_switching_list_json,
758 const std::string& gpu_driver_bug_list_json, 734 const std::string& gpu_driver_bug_list_json,
759 const GPUInfo& gpu_info) { 735 const GPUInfo& gpu_info) {
760 std::string browser_version_string = ProcessVersionString( 736 std::string browser_version_string = ProcessVersionString(
761 GetContentClient()->GetProduct()); 737 GetContentClient()->GetProduct());
762 CHECK(!browser_version_string.empty()); 738 CHECK(!browser_version_string.empty());
763 739
764 if (!gpu_blacklist_json.empty()) { 740 if (!gpu_blacklist_json.empty()) {
765 gpu_blacklist_.reset(GpuBlacklist::Create()); 741 gpu_blacklist_.reset(GpuBlacklist::Create());
766 gpu_blacklist_->LoadList( 742 gpu_blacklist_->LoadList(
767 browser_version_string, gpu_blacklist_json, 743 browser_version_string, gpu_blacklist_json,
768 GpuControlList::kCurrentOsOnly); 744 GpuControlList::kCurrentOsOnly);
769 } 745 }
770 if (!gpu_switching_list_json.empty()) { 746 if (!gpu_switching_list_json.empty()) {
771 gpu_switching_list_.reset(GpuSwitchingList::Create()); 747 gpu_switching_list_.reset(GpuSwitchingList::Create());
772 gpu_switching_list_->LoadList( 748 gpu_switching_list_->LoadList(
773 browser_version_string, gpu_switching_list_json, 749 browser_version_string, gpu_switching_list_json,
774 GpuControlList::kCurrentOsOnly); 750 GpuControlList::kCurrentOsOnly);
775 } 751 }
776 if (!gpu_driver_bug_list_json.empty()) { 752 if (!gpu_driver_bug_list_json.empty()) {
777 gpu_driver_bug_list_.reset(GpuDriverBugList::Create()); 753 gpu_driver_bug_list_.reset(GpuDriverBugList::Create());
778 gpu_driver_bug_list_->LoadList( 754 gpu_driver_bug_list_->LoadList(
779 browser_version_string, gpu_driver_bug_list_json, 755 browser_version_string, gpu_driver_bug_list_json,
780 GpuControlList::kCurrentOsOnly); 756 GpuControlList::kCurrentOsOnly);
781 } 757 }
782 758
783 { 759 gpu_info_ = gpu_info;
784 base::AutoLock auto_lock(gpu_info_lock_);
785 gpu_info_ = gpu_info;
786 }
787 UpdateGpuInfo(gpu_info); 760 UpdateGpuInfo(gpu_info);
788 UpdateGpuSwitchingManager(gpu_info); 761 UpdateGpuSwitchingManager(gpu_info);
789 UpdatePreliminaryBlacklistedFeatures(); 762 UpdatePreliminaryBlacklistedFeatures();
790 } 763 }
791 764
792 void GpuDataManagerImpl::UpdateBlacklistedFeatures( 765 void GpuDataManagerImplPrivate::UpdateBlacklistedFeatures(
793 const std::set<int>& features) { 766 const std::set<int>& features) {
794 CommandLine* command_line = CommandLine::ForCurrentProcess(); 767 CommandLine* command_line = CommandLine::ForCurrentProcess();
795 blacklisted_features_ = features; 768 blacklisted_features_ = features;
796 769
797 // Force disable using the GPU for these features, even if they would 770 // Force disable using the GPU for these features, even if they would
798 // otherwise be allowed. 771 // otherwise be allowed.
799 if (card_blacklisted_ || 772 if (card_blacklisted_ ||
800 command_line->HasSwitch(switches::kBlacklistAcceleratedCompositing)) { 773 command_line->HasSwitch(switches::kBlacklistAcceleratedCompositing)) {
801 blacklisted_features_.insert(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING); 774 blacklisted_features_.insert(GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING);
802 } 775 }
803 if (card_blacklisted_ || 776 if (card_blacklisted_ ||
804 command_line->HasSwitch(switches::kBlacklistWebGL)) { 777 command_line->HasSwitch(switches::kBlacklistWebGL)) {
805 blacklisted_features_.insert(GPU_FEATURE_TYPE_WEBGL); 778 blacklisted_features_.insert(GPU_FEATURE_TYPE_WEBGL);
806 } 779 }
807 780
808 EnableSwiftShaderIfNecessary(); 781 EnableSwiftShaderIfNecessary();
809 } 782 }
810 783
811 void GpuDataManagerImpl::UpdatePreliminaryBlacklistedFeatures() { 784 void GpuDataManagerImplPrivate::UpdatePreliminaryBlacklistedFeatures() {
812 preliminary_blacklisted_features_ = blacklisted_features_; 785 preliminary_blacklisted_features_ = blacklisted_features_;
813 } 786 }
814 787
815 void GpuDataManagerImpl::UpdateGpuSwitchingManager(const GPUInfo& gpu_info) { 788 void GpuDataManagerImplPrivate::UpdateGpuSwitchingManager(
789 const GPUInfo& gpu_info) {
816 ui::GpuSwitchingManager::GetInstance()->SetGpuCount( 790 ui::GpuSwitchingManager::GetInstance()->SetGpuCount(
817 gpu_info.secondary_gpus.size() + 1); 791 gpu_info.secondary_gpus.size() + 1);
818 792
819 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { 793 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) {
820 switch (gpu_switching_) { 794 switch (gpu_switching_) {
821 case GPU_SWITCHING_OPTION_FORCE_DISCRETE: 795 case GPU_SWITCHING_OPTION_FORCE_DISCRETE:
822 ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu(); 796 ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu();
823 break; 797 break;
824 case GPU_SWITCHING_OPTION_FORCE_INTEGRATED: 798 case GPU_SWITCHING_OPTION_FORCE_INTEGRATED:
825 ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu(); 799 ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu();
826 break; 800 break;
827 case GPU_SWITCHING_OPTION_AUTOMATIC: 801 case GPU_SWITCHING_OPTION_AUTOMATIC:
828 case GPU_SWITCHING_OPTION_UNKNOWN: 802 case GPU_SWITCHING_OPTION_UNKNOWN:
829 break; 803 break;
830 } 804 }
831 } 805 }
832 } 806 }
833 807
834 void GpuDataManagerImpl::NotifyGpuInfoUpdate() { 808 void GpuDataManagerImplPrivate::NotifyGpuInfoUpdate() {
835 observer_list_->Notify(&GpuDataManagerObserver::OnGpuInfoUpdate); 809 observer_list_->Notify(&GpuDataManagerObserver::OnGpuInfoUpdate);
836 } 810 }
837 811
838 void GpuDataManagerImpl::EnableSwiftShaderIfNecessary() { 812 void GpuDataManagerImplPrivate::EnableSwiftShaderIfNecessary() {
839 if (!GpuAccessAllowed(NULL) || 813 if (!GpuAccessAllowed(NULL) ||
840 blacklisted_features_.count(GPU_FEATURE_TYPE_WEBGL)) { 814 blacklisted_features_.count(GPU_FEATURE_TYPE_WEBGL)) {
841 if (!swiftshader_path_.empty() && 815 if (!swiftshader_path_.empty() &&
842 !CommandLine::ForCurrentProcess()->HasSwitch( 816 !CommandLine::ForCurrentProcess()->HasSwitch(
843 switches::kDisableSoftwareRasterizer)) 817 switches::kDisableSoftwareRasterizer))
844 use_swiftshader_ = true; 818 use_swiftshader_ = true;
845 } 819 }
846 } 820 }
847 821
848 std::string GpuDataManagerImpl::GetDomainFromURL(const GURL& url) const { 822 std::string GpuDataManagerImplPrivate::GetDomainFromURL(
823 const GURL& url) const {
849 // For the moment, we just use the host, or its IP address, as the 824 // For the moment, we just use the host, or its IP address, as the
850 // entry in the set, rather than trying to figure out the top-level 825 // entry in the set, rather than trying to figure out the top-level
851 // domain. This does mean that a.foo.com and b.foo.com will be 826 // domain. This does mean that a.foo.com and b.foo.com will be
852 // treated independently in the blocking of a given domain, but it 827 // treated independently in the blocking of a given domain, but it
853 // would require a third-party library to reliably figure out the 828 // would require a third-party library to reliably figure out the
854 // top-level domain from a URL. 829 // top-level domain from a URL.
855 if (!url.has_host()) { 830 if (!url.has_host()) {
856 return std::string(); 831 return std::string();
857 } 832 }
858 833
859 return url.host(); 834 return url.host();
860 } 835 }
861 836
862 void GpuDataManagerImpl::BlockDomainFrom3DAPIsAtTime( 837 void GpuDataManagerImplPrivate::BlockDomainFrom3DAPIsAtTime(
863 const GURL& url, DomainGuilt guilt, base::Time at_time) { 838 const GURL& url,
839 GpuDataManagerImpl::DomainGuilt guilt,
840 base::Time at_time) {
864 if (!domain_blocking_enabled_) 841 if (!domain_blocking_enabled_)
865 return; 842 return;
866 843
867 std::string domain = GetDomainFromURL(url); 844 std::string domain = GetDomainFromURL(url);
868 845
869 base::AutoLock auto_lock(gpu_info_lock_);
870 DomainBlockEntry& entry = blocked_domains_[domain]; 846 DomainBlockEntry& entry = blocked_domains_[domain];
871 entry.last_guilt = guilt; 847 entry.last_guilt = guilt;
872 timestamps_of_gpu_resets_.push_back(at_time); 848 timestamps_of_gpu_resets_.push_back(at_time);
873 } 849 }
874 850
875 GpuDataManagerImpl::DomainBlockStatus 851 GpuDataManagerImpl::DomainBlockStatus
876 GpuDataManagerImpl::Are3DAPIsBlockedAtTime( 852 GpuDataManagerImplPrivate::Are3DAPIsBlockedAtTime(
877 const GURL& url, base::Time at_time) const { 853 const GURL& url, base::Time at_time) const {
878 if (!domain_blocking_enabled_) 854 if (!domain_blocking_enabled_)
879 return DOMAIN_BLOCK_STATUS_NOT_BLOCKED; 855 return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED;
880 856
881 // Note: adjusting the policies in this code will almost certainly 857 // Note: adjusting the policies in this code will almost certainly
882 // require adjusting the associated unit tests. 858 // require adjusting the associated unit tests.
883 std::string domain = GetDomainFromURL(url); 859 std::string domain = GetDomainFromURL(url);
884 860
885 base::AutoLock auto_lock(gpu_info_lock_); 861 DomainBlockMap::const_iterator iter = blocked_domains_.find(domain);
886 { 862 if (iter != blocked_domains_.end()) {
887 DomainBlockMap::const_iterator iter = blocked_domains_.find(domain); 863 // Err on the side of caution, and assume that if a particular
888 if (iter != blocked_domains_.end()) { 864 // domain shows up in the block map, it's there for a good
889 // Err on the side of caution, and assume that if a particular 865 // reason and don't let its presence there automatically expire.
890 // domain shows up in the block map, it's there for a good
891 // reason and don't let its presence there automatically expire.
892 866
893 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs", 867 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs",
894 BLOCK_STATUS_SPECIFIC_DOMAIN_BLOCKED, 868 BLOCK_STATUS_SPECIFIC_DOMAIN_BLOCKED,
895 BLOCK_STATUS_MAX); 869 BLOCK_STATUS_MAX);
896 870
897 return DOMAIN_BLOCK_STATUS_BLOCKED; 871 return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED;
898 }
899 } 872 }
900 873
901 // Look at the timestamps of the recent GPU resets to see if there are 874 // Look at the timestamps of the recent GPU resets to see if there are
902 // enough within the threshold which would cause us to blacklist all 875 // enough within the threshold which would cause us to blacklist all
903 // domains. This doesn't need to be overly precise -- if time goes 876 // domains. This doesn't need to be overly precise -- if time goes
904 // backward due to a system clock adjustment, that's fine. 877 // backward due to a system clock adjustment, that's fine.
905 // 878 //
906 // TODO(kbr): make this pay attention to the TDR thresholds in the 879 // TODO(kbr): make this pay attention to the TDR thresholds in the
907 // Windows registry, but make sure it continues to be testable. 880 // Windows registry, but make sure it continues to be testable.
908 std::list<base::Time>::iterator iter = timestamps_of_gpu_resets_.begin(); 881 {
Ken Russell (switch to Gerrit) 2013/05/10 23:59:19 This block doesn't seem necessary.
909 int num_resets_within_timeframe = 0; 882 std::list<base::Time>::iterator iter = timestamps_of_gpu_resets_.begin();
910 while (iter != timestamps_of_gpu_resets_.end()) { 883 int num_resets_within_timeframe = 0;
911 base::Time time = *iter; 884 while (iter != timestamps_of_gpu_resets_.end()) {
912 base::TimeDelta delta_t = at_time - time; 885 base::Time time = *iter;
886 base::TimeDelta delta_t = at_time - time;
913 887
914 // If this entry has "expired", just remove it. 888 // If this entry has "expired", just remove it.
915 if (delta_t.InMilliseconds() > kBlockAllDomainsMs) { 889 if (delta_t.InMilliseconds() > kBlockAllDomainsMs) {
916 iter = timestamps_of_gpu_resets_.erase(iter); 890 iter = timestamps_of_gpu_resets_.erase(iter);
917 continue; 891 continue;
892 }
893
894 ++num_resets_within_timeframe;
895 ++iter;
918 } 896 }
919 897
920 ++num_resets_within_timeframe; 898 if (num_resets_within_timeframe >= kNumResetsWithinDuration) {
921 ++iter; 899 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs",
922 } 900 BLOCK_STATUS_ALL_DOMAINS_BLOCKED,
901 BLOCK_STATUS_MAX);
923 902
924 if (num_resets_within_timeframe >= kNumResetsWithinDuration) { 903 return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED;
925 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs", 904 }
926 BLOCK_STATUS_ALL_DOMAINS_BLOCKED,
927 BLOCK_STATUS_MAX);
928
929 return DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED;
930 } 905 }
931 906
932 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs", 907 UMA_HISTOGRAM_ENUMERATION("GPU.BlockStatusForClient3DAPIs",
933 BLOCK_STATUS_NOT_BLOCKED, 908 BLOCK_STATUS_NOT_BLOCKED,
934 BLOCK_STATUS_MAX); 909 BLOCK_STATUS_MAX);
935 910
936 return DOMAIN_BLOCK_STATUS_NOT_BLOCKED; 911 return GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED;
937 } 912 }
938 913
939 int64 GpuDataManagerImpl::GetBlockAllDomainsDurationInMs() const { 914 int64 GpuDataManagerImplPrivate::GetBlockAllDomainsDurationInMs() const {
940 return kBlockAllDomainsMs; 915 return kBlockAllDomainsMs;
941 } 916 }
942 917
943 void GpuDataManagerImpl::Notify3DAPIBlocked(const GURL& url, 918 void GpuDataManagerImplPrivate::Notify3DAPIBlocked(const GURL& url,
944 int render_process_id, 919 int render_process_id,
945 int render_view_id, 920 int render_view_id,
946 ThreeDAPIType requester) { 921 ThreeDAPIType requester) {
922 GpuDataManagerImpl::UnlockedSession session(owner_);
947 observer_list_->Notify(&GpuDataManagerObserver::DidBlock3DAPIs, 923 observer_list_->Notify(&GpuDataManagerObserver::DidBlock3DAPIs,
948 url, render_process_id, render_view_id, requester); 924 url, render_process_id, render_view_id, requester);
949 } 925 }
950 926
951 } // namespace content 927 } // namespace content
928
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_data_manager_impl_private.h ('k') | content/browser/gpu/gpu_data_manager_impl_private_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698