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

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

Issue 8480015: Allow switching to SwiftShader when GPU is blacklisted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename functions Created 9 years, 1 month 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 | « content/browser/gpu/gpu_data_manager.h ('k') | content/browser/gpu/gpu_process_host.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "content/browser/gpu/gpu_data_manager.h"
6 6
7 #if defined(OS_MACOSX) 7 #if defined(OS_MACOSX)
8 #include <CoreGraphics/CGDisplayConfiguration.h> 8 #include <CoreGraphics/CGDisplayConfiguration.h>
9 #endif 9 #endif
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/file_util.h"
14 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
15 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
16 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
17 #include "base/sys_info.h" 18 #include "base/sys_info.h"
18 #include "base/values.h" 19 #include "base/values.h"
19 #include "base/version.h" 20 #include "base/version.h"
20 #include "content/browser/gpu/gpu_blacklist.h" 21 #include "content/browser/gpu/gpu_blacklist.h"
21 #include "content/browser/gpu/gpu_process_host.h" 22 #include "content/browser/gpu/gpu_process_host.h"
22 #include "content/common/gpu/gpu_messages.h" 23 #include "content/common/gpu/gpu_messages.h"
23 #include "content/gpu/gpu_info_collector.h" 24 #include "content/gpu/gpu_info_collector.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 189
189 void GpuDataManager::UserFlags::ApplyPolicies() { 190 void GpuDataManager::UserFlags::ApplyPolicies() {
190 if (disable_accelerated_compositing_) { 191 if (disable_accelerated_compositing_) {
191 disable_accelerated_2d_canvas_ = true; 192 disable_accelerated_2d_canvas_ = true;
192 disable_accelerated_layers_ = true; 193 disable_accelerated_layers_ = true;
193 } 194 }
194 } 195 }
195 196
196 GpuDataManager::GpuDataManager() 197 GpuDataManager::GpuDataManager()
197 : complete_gpu_info_already_requested_(false), 198 : complete_gpu_info_already_requested_(false),
198 observer_list_(new GpuDataManagerObserverList) { 199 observer_list_(new GpuDataManagerObserverList),
200 software_rendering_(false) {
199 Initialize(); 201 Initialize();
200 } 202 }
201 203
202 void GpuDataManager::Initialize() { 204 void GpuDataManager::Initialize() {
203 // User flags need to be collected before any further initialization. 205 // User flags need to be collected before any further initialization.
204 user_flags_.Initialize(); 206 user_flags_.Initialize();
205 207
206 // Certain tests doesn't go through the browser startup path that 208 // Certain tests doesn't go through the browser startup path that
207 // initializes GpuDataManager on FILE thread; therefore, it is initialized 209 // initializes GpuDataManager on FILE thread; therefore, it is initialized
208 // on UI thread later, and we skip the preliminary gpu info collection 210 // on UI thread later, and we skip the preliminary gpu info collection
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 ListValue* feature_status_list = new ListValue(); 321 ListValue* feature_status_list = new ListValue();
320 322
321 for (size_t i = 0; i < kNumFeatures; ++i) { 323 for (size_t i = 0; i < kNumFeatures; ++i) {
322 std::string status; 324 std::string status;
323 if (kGpuFeatureInfo[i].disabled) { 325 if (kGpuFeatureInfo[i].disabled) {
324 status = "disabled"; 326 status = "disabled";
325 if (kGpuFeatureInfo[i].fallback_to_software) 327 if (kGpuFeatureInfo[i].fallback_to_software)
326 status += "_software"; 328 status += "_software";
327 else 329 else
328 status += "_off"; 330 status += "_off";
329 } else if (kGpuFeatureInfo[i].blocked || gpu_access_blocked) { 331 } else if (software_rendering()) {
332 status = "unavailable_software";
333 } else if (kGpuFeatureInfo[i].blocked ||
334 gpu_access_blocked) {
330 status = "unavailable"; 335 status = "unavailable";
331 if (kGpuFeatureInfo[i].fallback_to_software) 336 if (kGpuFeatureInfo[i].fallback_to_software)
332 status += "_software"; 337 status += "_software";
333 else 338 else
334 status += "_off"; 339 status += "_off";
335 } else { 340 } else {
336 status = "enabled"; 341 status = "enabled";
337 if (kGpuFeatureInfo[i].name == "webgl" && 342 if (kGpuFeatureInfo[i].name == "webgl" &&
338 (user_flags_.disable_accelerated_compositing() || 343 (user_flags_.disable_accelerated_compositing() ||
339 (flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing))) 344 (flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)))
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
400 log_messages_.Append(msg); 405 log_messages_.Append(msg);
401 } 406 }
402 407
403 const ListValue& GpuDataManager::log_messages() const { 408 const ListValue& GpuDataManager::log_messages() const {
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
405 return log_messages_; 410 return log_messages_;
406 } 411 }
407 412
408 GpuFeatureFlags GpuDataManager::GetGpuFeatureFlags() { 413 GpuFeatureFlags GpuDataManager::GetGpuFeatureFlags() {
414 if (software_rendering_) {
415 GpuFeatureFlags flags;
416
417 // Skia's software rendering is probably more efficient than going through
418 // software emulation of the GPU, so use that.
419 flags.set_flags(GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas);
420 return flags;
421 }
422
409 return gpu_feature_flags_; 423 return gpu_feature_flags_;
410 } 424 }
411 425
412 bool GpuDataManager::GpuAccessAllowed() { 426 bool GpuDataManager::GpuAccessAllowed() {
427 if (software_rendering())
428 return true;
429
413 // We only need to block GPU process if more features are disallowed other 430 // We only need to block GPU process if more features are disallowed other
414 // than those in the preliminary gpu feature flags because the latter work 431 // than those in the preliminary gpu feature flags because the latter work
415 // through renderer commandline switches. 432 // through renderer commandline switches.
416 uint32 mask = (~(preliminary_gpu_feature_flags_.flags())); 433 uint32 mask = (~(preliminary_gpu_feature_flags_.flags()));
417 return (gpu_feature_flags_.flags() & mask) == 0; 434 return (gpu_feature_flags_.flags() & mask) == 0;
418 } 435 }
419 436
420 void GpuDataManager::AddObserver(Observer* observer) { 437 void GpuDataManager::AddObserver(Observer* observer) {
421 observer_list_->AddObserver(observer); 438 observer_list_->AddObserver(observer);
422 } 439 }
423 440
424 void GpuDataManager::RemoveObserver(Observer* observer) { 441 void GpuDataManager::RemoveObserver(Observer* observer) {
425 observer_list_->RemoveObserver(observer); 442 observer_list_->RemoveObserver(observer);
426 } 443 }
427 444
428 void GpuDataManager::AppendRendererCommandLine( 445 void GpuDataManager::AppendRendererCommandLine(
429 CommandLine* command_line) { 446 CommandLine* command_line) {
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
431 DCHECK(command_line); 448 DCHECK(command_line);
432 449
433 uint32 flags = gpu_feature_flags_.flags(); 450 uint32 flags = GpuFeatureFlags().flags();
434 if ((flags & GpuFeatureFlags::kGpuFeatureWebgl)) { 451 if ((flags & GpuFeatureFlags::kGpuFeatureWebgl)) {
435 if (!command_line->HasSwitch(switches::kDisableExperimentalWebGL)) 452 if (!command_line->HasSwitch(switches::kDisableExperimentalWebGL))
436 command_line->AppendSwitch(switches::kDisableExperimentalWebGL); 453 command_line->AppendSwitch(switches::kDisableExperimentalWebGL);
437 if (!command_line->HasSwitch(switches::kDisablePepper3dForUntrustedUse)) 454 if (!command_line->HasSwitch(switches::kDisablePepper3dForUntrustedUse))
438 command_line->AppendSwitch(switches::kDisablePepper3dForUntrustedUse); 455 command_line->AppendSwitch(switches::kDisablePepper3dForUntrustedUse);
439 } 456 }
440 if ((flags & GpuFeatureFlags::kGpuFeatureMultisampling) && 457 if ((flags & GpuFeatureFlags::kGpuFeatureMultisampling) &&
441 !command_line->HasSwitch(switches::kDisableGLMultisampling)) 458 !command_line->HasSwitch(switches::kDisableGLMultisampling))
442 command_line->AppendSwitch(switches::kDisableGLMultisampling); 459 command_line->AppendSwitch(switches::kDisableGLMultisampling);
443 if ((flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing) && 460 if ((flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing) &&
444 !command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) 461 !command_line->HasSwitch(switches::kDisableAcceleratedCompositing))
445 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); 462 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing);
446 if ((flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas) && 463 if ((flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas) &&
447 !command_line->HasSwitch(switches::kDisableAccelerated2dCanvas)) 464 !command_line->HasSwitch(switches::kDisableAccelerated2dCanvas))
448 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); 465 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas);
449 } 466 }
450 467
451 void GpuDataManager::AppendGpuCommandLine( 468 void GpuDataManager::AppendGpuCommandLine(
452 CommandLine* command_line) { 469 CommandLine* command_line) {
453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
454 DCHECK(command_line); 471 DCHECK(command_line);
455 472
456 uint32 flags = gpu_feature_flags_.flags(); 473 uint32 flags = GpuFeatureFlags().flags();
457 if ((flags & GpuFeatureFlags::kGpuFeatureMultisampling) && 474 if ((flags & GpuFeatureFlags::kGpuFeatureMultisampling) &&
458 !command_line->HasSwitch(switches::kDisableGLMultisampling)) 475 !command_line->HasSwitch(switches::kDisableGLMultisampling))
459 command_line->AppendSwitch(switches::kDisableGLMultisampling); 476 command_line->AppendSwitch(switches::kDisableGLMultisampling);
460 477
461 if ((flags & (GpuFeatureFlags::kGpuFeatureWebgl | 478 if (software_rendering_) {
479 command_line->AppendSwitchASCII(switches::kUseGL, "swiftshader");
480 command_line->AppendSwitchPath(switches::kSwiftShaderPath,
481 swiftshader_path_);
482 } else if ((flags & (GpuFeatureFlags::kGpuFeatureWebgl |
462 GpuFeatureFlags::kGpuFeatureAcceleratedCompositing | 483 GpuFeatureFlags::kGpuFeatureAcceleratedCompositing |
463 GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)) && 484 GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)) &&
464 (user_flags_.use_gl() == "any")) { 485 (user_flags_.use_gl() == "any")) {
465 command_line->AppendSwitchASCII( 486 command_line->AppendSwitchASCII(
466 switches::kUseGL, gfx::kGLImplementationOSMesaName); 487 switches::kUseGL, gfx::kGLImplementationOSMesaName);
467 } else if (!user_flags_.use_gl().empty()) { 488 } else if (!user_flags_.use_gl().empty()) {
468 command_line->AppendSwitchASCII(switches::kUseGL, user_flags_.use_gl()); 489 command_line->AppendSwitchASCII(switches::kUseGL, user_flags_.use_gl());
469 } 490 }
470 } 491 }
471 492
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 histogram_pointer->Add(value); 687 histogram_pointer->Add(value);
667 #if defined(OS_WIN) 688 #if defined(OS_WIN)
668 histogram_pointer = base::LinearHistogram::FactoryGet( 689 histogram_pointer = base::LinearHistogram::FactoryGet(
669 kGpuBlacklistFeatureHistogramNamesWin[i], 690 kGpuBlacklistFeatureHistogramNamesWin[i],
670 1, kNumWinSubVersions * kGpuFeatureNumStatus, 691 1, kNumWinSubVersions * kGpuFeatureNumStatus,
671 kNumWinSubVersions * kGpuFeatureNumStatus + 1, 692 kNumWinSubVersions * kGpuFeatureNumStatus + 1,
672 base::Histogram::kUmaTargetedHistogramFlag); 693 base::Histogram::kUmaTargetedHistogramFlag);
673 histogram_pointer->Add(GetGpuBlacklistHistogramValueWin(value)); 694 histogram_pointer->Add(GetGpuBlacklistHistogramValueWin(value));
674 #endif 695 #endif
675 } 696 }
697
698 EnableSoftwareRenderingIfNecessary();
699 }
700
701 void GpuDataManager::RegisterSwiftShaderPath(FilePath path) {
702 swiftshader_path_ = path;
703 EnableSoftwareRenderingIfNecessary();
704 }
705
706 void GpuDataManager::EnableSoftwareRenderingIfNecessary() {
707 if (!GpuAccessAllowed() ||
708 (gpu_feature_flags_.flags() & GpuFeatureFlags::kGpuFeatureWebgl)) {
709 #if defined(ENABLE_SWIFTSHADER)
710 if (!swiftshader_path_.empty())
711 software_rendering_ = true;
712 #endif
713 }
676 } 714 }
677 715
716 bool GpuDataManager::software_rendering() {
717 return software_rendering_;
718 }
719
678 GpuBlacklist* GpuDataManager::GetGpuBlacklist() const { 720 GpuBlacklist* GpuDataManager::GetGpuBlacklist() const {
679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 721 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
680 if (user_flags_.ignore_gpu_blacklist()) 722 if (user_flags_.ignore_gpu_blacklist())
681 return NULL; 723 return NULL;
682 // No need to return an empty blacklist. 724 // No need to return an empty blacklist.
683 if (gpu_blacklist_.get() != NULL && gpu_blacklist_->max_entry_id() == 0) 725 if (gpu_blacklist_.get() != NULL && gpu_blacklist_->max_entry_id() == 0)
684 return NULL; 726 return NULL;
685 return gpu_blacklist_.get(); 727 return gpu_blacklist_.get();
686 } 728 }
687 729
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 bool GpuDataManager::supportsAccelerated2dCanvas() const { 795 bool GpuDataManager::supportsAccelerated2dCanvas() const {
754 if (gpu_info_.can_lose_context) 796 if (gpu_info_.can_lose_context)
755 return false; 797 return false;
756 #if defined(USE_SKIA) 798 #if defined(USE_SKIA)
757 return true; 799 return true;
758 #else 800 #else
759 return false; 801 return false;
760 #endif 802 #endif
761 } 803 }
762 804
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_data_manager.h ('k') | content/browser/gpu/gpu_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698