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

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

Issue 435383002: adds WARP support to Chromium, for Metro mode only, on Windows 8 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 3 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) 2013 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_private.h" 5 #include "content/browser/gpu/gpu_data_manager_impl_private.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 264 }
265 265
266 bool GpuDataManagerImplPrivate::IsFeatureBlacklisted(int feature) const { 266 bool GpuDataManagerImplPrivate::IsFeatureBlacklisted(int feature) const {
267 #if defined(OS_CHROMEOS) 267 #if defined(OS_CHROMEOS)
268 if (feature == gpu::GPU_FEATURE_TYPE_PANEL_FITTING && 268 if (feature == gpu::GPU_FEATURE_TYPE_PANEL_FITTING &&
269 base::CommandLine::ForCurrentProcess()->HasSwitch( 269 base::CommandLine::ForCurrentProcess()->HasSwitch(
270 switches::kDisablePanelFitting)) { 270 switches::kDisablePanelFitting)) {
271 return true; 271 return true;
272 } 272 }
273 #endif // OS_CHROMEOS 273 #endif // OS_CHROMEOS
274 if (use_swiftshader_) { 274 if (use_swiftshader_ || ShouldUseWarp()) {
275 // Skia's software rendering is probably more efficient than going through 275 // Skia's software rendering is probably more efficient than going through
276 // software emulation of the GPU, so use that. 276 // software emulation of the GPU, so use that.
277 if (feature == gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) 277 if (feature == gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
278 return true; 278 return true;
279 return false; 279 return false;
280 } 280 }
281 281
282 return (blacklisted_features_.count(feature) == 1); 282 return (blacklisted_features_.count(feature) == 1);
283 } 283 }
284 284
285 bool GpuDataManagerImplPrivate::IsDriverBugWorkaroundActive(int feature) const { 285 bool GpuDataManagerImplPrivate::IsDriverBugWorkaroundActive(int feature) const {
286 return (gpu_driver_bugs_.count(feature) == 1); 286 return (gpu_driver_bugs_.count(feature) == 1);
287 } 287 }
288 288
289 size_t GpuDataManagerImplPrivate::GetBlacklistedFeatureCount() const { 289 size_t GpuDataManagerImplPrivate::GetBlacklistedFeatureCount() const {
290 if (use_swiftshader_) 290 if (use_swiftshader_ || ShouldUseWarp())
291 return 1; 291 return 1;
292 return blacklisted_features_.size(); 292 return blacklisted_features_.size();
293 } 293 }
294 294
295 void GpuDataManagerImplPrivate::SetDisplayCount(unsigned int display_count) { 295 void GpuDataManagerImplPrivate::SetDisplayCount(unsigned int display_count) {
296 display_count_ = display_count; 296 display_count_ = display_count;
297 } 297 }
298 298
299 unsigned int GpuDataManagerImplPrivate::GetDisplayCount() const { 299 unsigned int GpuDataManagerImplPrivate::GetDisplayCount() const {
300 return display_count_; 300 return display_count_;
301 } 301 }
302 302
303 gpu::GPUInfo GpuDataManagerImplPrivate::GetGPUInfo() const { 303 gpu::GPUInfo GpuDataManagerImplPrivate::GetGPUInfo() const {
304 return gpu_info_; 304 return gpu_info_;
305 } 305 }
306 306
307 void GpuDataManagerImplPrivate::GetGpuProcessHandles( 307 void GpuDataManagerImplPrivate::GetGpuProcessHandles(
308 const GpuDataManager::GetGpuProcessHandlesCallback& callback) const { 308 const GpuDataManager::GetGpuProcessHandlesCallback& callback) const {
309 GpuProcessHost::GetProcessHandles(callback); 309 GpuProcessHost::GetProcessHandles(callback);
310 } 310 }
311 311
312 bool GpuDataManagerImplPrivate::GpuAccessAllowed( 312 bool GpuDataManagerImplPrivate::GpuAccessAllowed(
313 std::string* reason) const { 313 std::string* reason) const {
314 if (use_swiftshader_) 314 if (use_swiftshader_ || ShouldUseWarp())
315 return true; 315 return true;
316 316
317 if (!gpu_process_accessible_) { 317 if (!gpu_process_accessible_) {
318 if (reason) { 318 if (reason) {
319 *reason = "GPU process launch failed."; 319 *reason = "GPU process launch failed.";
320 } 320 }
321 return false; 321 return false;
322 } 322 }
323 323
324 if (card_blacklisted_) { 324 if (card_blacklisted_) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 bool GpuDataManagerImplPrivate::ShouldUseSwiftShader() const { 391 bool GpuDataManagerImplPrivate::ShouldUseSwiftShader() const {
392 return use_swiftshader_; 392 return use_swiftshader_;
393 } 393 }
394 394
395 void GpuDataManagerImplPrivate::RegisterSwiftShaderPath( 395 void GpuDataManagerImplPrivate::RegisterSwiftShaderPath(
396 const base::FilePath& path) { 396 const base::FilePath& path) {
397 swiftshader_path_ = path; 397 swiftshader_path_ = path;
398 EnableSwiftShaderIfNecessary(); 398 EnableSwiftShaderIfNecessary();
399 } 399 }
400 400
401 bool GpuDataManagerImplPrivate::ShouldUseWarp() const {
402 return use_warp_ ||
403 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseWarp);
404 }
405
401 void GpuDataManagerImplPrivate::AddObserver(GpuDataManagerObserver* observer) { 406 void GpuDataManagerImplPrivate::AddObserver(GpuDataManagerObserver* observer) {
402 GpuDataManagerImpl::UnlockedSession session(owner_); 407 GpuDataManagerImpl::UnlockedSession session(owner_);
403 observer_list_->AddObserver(observer); 408 observer_list_->AddObserver(observer);
404 } 409 }
405 410
406 void GpuDataManagerImplPrivate::RemoveObserver( 411 void GpuDataManagerImplPrivate::RemoveObserver(
407 GpuDataManagerObserver* observer) { 412 GpuDataManagerObserver* observer) {
408 GpuDataManagerImpl::UnlockedSession session(owner_); 413 GpuDataManagerImpl::UnlockedSession session(owner_);
409 observer_list_->RemoveObserver(observer); 414 observer_list_->RemoveObserver(observer);
410 } 415 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 } 543 }
539 gpu::GpuDriverBugList::AppendWorkaroundsFromCommandLine( 544 gpu::GpuDriverBugList::AppendWorkaroundsFromCommandLine(
540 &gpu_driver_bugs_, *base::CommandLine::ForCurrentProcess()); 545 &gpu_driver_bugs_, *base::CommandLine::ForCurrentProcess());
541 546
542 // We have to update GpuFeatureType before notify all the observers. 547 // We have to update GpuFeatureType before notify all the observers.
543 NotifyGpuInfoUpdate(); 548 NotifyGpuInfoUpdate();
544 } 549 }
545 550
546 void GpuDataManagerImplPrivate::UpdateGpuInfo(const gpu::GPUInfo& gpu_info) { 551 void GpuDataManagerImplPrivate::UpdateGpuInfo(const gpu::GPUInfo& gpu_info) {
547 // No further update of gpu_info if falling back to SwiftShader. 552 // No further update of gpu_info if falling back to SwiftShader.
548 if (use_swiftshader_) 553 if (use_swiftshader_ || ShouldUseWarp())
549 return; 554 return;
550 555
551 gpu::MergeGPUInfo(&gpu_info_, gpu_info); 556 gpu::MergeGPUInfo(&gpu_info_, gpu_info);
552 complete_gpu_info_already_requested_ = 557 complete_gpu_info_already_requested_ =
553 complete_gpu_info_already_requested_ || gpu_info_.finalized; 558 complete_gpu_info_already_requested_ || gpu_info_.finalized;
554 559
555 UpdateGpuInfoHelper(); 560 UpdateGpuInfoHelper();
556 } 561 }
557 562
558 void GpuDataManagerImplPrivate::UpdateVideoMemoryUsageStats( 563 void GpuDataManagerImplPrivate::UpdateVideoMemoryUsageStats(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 // device_id, driver_vendor, driver_version for deciding whether we need to 643 // device_id, driver_vendor, driver_version for deciding whether we need to
639 // collect full info (on Linux) and for crash reporting purpose. 644 // collect full info (on Linux) and for crash reporting purpose.
640 command_line->AppendSwitchASCII(switches::kGpuVendorID, 645 command_line->AppendSwitchASCII(switches::kGpuVendorID,
641 base::StringPrintf("0x%04x", gpu_info_.gpu.vendor_id)); 646 base::StringPrintf("0x%04x", gpu_info_.gpu.vendor_id));
642 command_line->AppendSwitchASCII(switches::kGpuDeviceID, 647 command_line->AppendSwitchASCII(switches::kGpuDeviceID,
643 base::StringPrintf("0x%04x", gpu_info_.gpu.device_id)); 648 base::StringPrintf("0x%04x", gpu_info_.gpu.device_id));
644 command_line->AppendSwitchASCII(switches::kGpuDriverVendor, 649 command_line->AppendSwitchASCII(switches::kGpuDriverVendor,
645 gpu_info_.driver_vendor); 650 gpu_info_.driver_vendor);
646 command_line->AppendSwitchASCII(switches::kGpuDriverVersion, 651 command_line->AppendSwitchASCII(switches::kGpuDriverVersion,
647 gpu_info_.driver_version); 652 gpu_info_.driver_version);
653
654 if (ShouldUseWarp())
655 command_line->AppendSwitch(switches::kUseWarp);
648 } 656 }
649 657
650 void GpuDataManagerImplPrivate::AppendPluginCommandLine( 658 void GpuDataManagerImplPrivate::AppendPluginCommandLine(
651 base::CommandLine* command_line) const { 659 base::CommandLine* command_line) const {
652 DCHECK(command_line); 660 DCHECK(command_line);
653 661
654 #if defined(OS_MACOSX) 662 #if defined(OS_MACOSX)
655 // TODO(jbauman): Add proper blacklist support for core animation plugins so 663 // TODO(jbauman): Add proper blacklist support for core animation plugins so
656 // special-casing this video card won't be necessary. See 664 // special-casing this video card won't be necessary. See
657 // http://crbug.com/134015 665 // http://crbug.com/134015
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 prefs->pepper_accelerated_video_decode_enabled = true; 708 prefs->pepper_accelerated_video_decode_enabled = true;
701 } 709 }
702 } 710 }
703 711
704 void GpuDataManagerImplPrivate::DisableHardwareAcceleration() { 712 void GpuDataManagerImplPrivate::DisableHardwareAcceleration() {
705 card_blacklisted_ = true; 713 card_blacklisted_ = true;
706 714
707 for (int i = 0; i < gpu::NUMBER_OF_GPU_FEATURE_TYPES; ++i) 715 for (int i = 0; i < gpu::NUMBER_OF_GPU_FEATURE_TYPES; ++i)
708 blacklisted_features_.insert(i); 716 blacklisted_features_.insert(i);
709 717
718 EnableWarpIfNecessary();
710 EnableSwiftShaderIfNecessary(); 719 EnableSwiftShaderIfNecessary();
711 NotifyGpuInfoUpdate(); 720 NotifyGpuInfoUpdate();
712 } 721 }
713 722
714 std::string GpuDataManagerImplPrivate::GetBlacklistVersion() const { 723 std::string GpuDataManagerImplPrivate::GetBlacklistVersion() const {
715 if (gpu_blacklist_) 724 if (gpu_blacklist_)
716 return gpu_blacklist_->version(); 725 return gpu_blacklist_->version();
717 return "0"; 726 return "0";
718 } 727 }
719 728
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 gpu_info_.secondary_gpus[ii].active = false; 815 gpu_info_.secondary_gpus[ii].active = false;
807 } 816 }
808 } 817 }
809 gpu_info_.gpu.active = false; 818 gpu_info_.gpu.active = false;
810 } 819 }
811 UpdateGpuInfoHelper(); 820 UpdateGpuInfoHelper();
812 return true; 821 return true;
813 } 822 }
814 823
815 bool GpuDataManagerImplPrivate::CanUseGpuBrowserCompositor() const { 824 bool GpuDataManagerImplPrivate::CanUseGpuBrowserCompositor() const {
825 if (ShouldUseWarp())
826 return true;
816 if (ShouldUseSwiftShader()) 827 if (ShouldUseSwiftShader())
817 return false; 828 return false;
818 if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING)) 829 if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING))
819 return false; 830 return false;
820 return true; 831 return true;
821 } 832 }
822 833
823 void GpuDataManagerImplPrivate::BlockDomainFrom3DAPIs( 834 void GpuDataManagerImplPrivate::BlockDomainFrom3DAPIs(
824 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt) { 835 const GURL& url, GpuDataManagerImpl::DomainGuilt guilt) {
825 BlockDomainFrom3DAPIsAtTime(url, guilt, base::Time::Now()); 836 BlockDomainFrom3DAPIsAtTime(url, guilt, base::Time::Now());
(...skipping 26 matching lines...) Expand all
852 GpuDataManagerImplPrivate* GpuDataManagerImplPrivate::Create( 863 GpuDataManagerImplPrivate* GpuDataManagerImplPrivate::Create(
853 GpuDataManagerImpl* owner) { 864 GpuDataManagerImpl* owner) {
854 return new GpuDataManagerImplPrivate(owner); 865 return new GpuDataManagerImplPrivate(owner);
855 } 866 }
856 867
857 GpuDataManagerImplPrivate::GpuDataManagerImplPrivate( 868 GpuDataManagerImplPrivate::GpuDataManagerImplPrivate(
858 GpuDataManagerImpl* owner) 869 GpuDataManagerImpl* owner)
859 : complete_gpu_info_already_requested_(false), 870 : complete_gpu_info_already_requested_(false),
860 observer_list_(new GpuDataManagerObserverList), 871 observer_list_(new GpuDataManagerObserverList),
861 use_swiftshader_(false), 872 use_swiftshader_(false),
873 use_warp_(false),
862 card_blacklisted_(false), 874 card_blacklisted_(false),
863 update_histograms_(true), 875 update_histograms_(true),
864 window_count_(0), 876 window_count_(0),
865 domain_blocking_enabled_(true), 877 domain_blocking_enabled_(true),
866 owner_(owner), 878 owner_(owner),
867 display_count_(0), 879 display_count_(0),
868 gpu_process_accessible_(true), 880 gpu_process_accessible_(true),
869 finalized_(false) { 881 finalized_(false) {
870 DCHECK(owner_); 882 DCHECK(owner_);
871 const base::CommandLine* command_line = 883 const base::CommandLine* command_line =
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 const std::set<int>& features) { 937 const std::set<int>& features) {
926 blacklisted_features_ = features; 938 blacklisted_features_ = features;
927 939
928 // Force disable using the GPU for these features, even if they would 940 // Force disable using the GPU for these features, even if they would
929 // otherwise be allowed. 941 // otherwise be allowed.
930 if (card_blacklisted_) { 942 if (card_blacklisted_) {
931 blacklisted_features_.insert(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING); 943 blacklisted_features_.insert(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING);
932 blacklisted_features_.insert(gpu::GPU_FEATURE_TYPE_WEBGL); 944 blacklisted_features_.insert(gpu::GPU_FEATURE_TYPE_WEBGL);
933 } 945 }
934 946
947 EnableWarpIfNecessary();
935 EnableSwiftShaderIfNecessary(); 948 EnableSwiftShaderIfNecessary();
936 } 949 }
937 950
938 void GpuDataManagerImplPrivate::UpdatePreliminaryBlacklistedFeatures() { 951 void GpuDataManagerImplPrivate::UpdatePreliminaryBlacklistedFeatures() {
939 preliminary_blacklisted_features_ = blacklisted_features_; 952 preliminary_blacklisted_features_ = blacklisted_features_;
940 } 953 }
941 954
942 void GpuDataManagerImplPrivate::UpdateGpuSwitchingManager( 955 void GpuDataManagerImplPrivate::UpdateGpuSwitchingManager(
943 const gpu::GPUInfo& gpu_info) { 956 const gpu::GPUInfo& gpu_info) {
944 ui::GpuSwitchingManager::GetInstance()->SetGpuCount( 957 ui::GpuSwitchingManager::GetInstance()->SetGpuCount(
945 gpu_info.secondary_gpus.size() + 1); 958 gpu_info.secondary_gpus.size() + 1);
946 959
947 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { 960 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) {
948 if (gpu_driver_bugs_.count(gpu::FORCE_DISCRETE_GPU) == 1) 961 if (gpu_driver_bugs_.count(gpu::FORCE_DISCRETE_GPU) == 1)
949 ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu(); 962 ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu();
950 else if (gpu_driver_bugs_.count(gpu::FORCE_INTEGRATED_GPU) == 1) 963 else if (gpu_driver_bugs_.count(gpu::FORCE_INTEGRATED_GPU) == 1)
951 ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu(); 964 ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu();
952 } 965 }
953 } 966 }
954 967
955 void GpuDataManagerImplPrivate::NotifyGpuInfoUpdate() { 968 void GpuDataManagerImplPrivate::NotifyGpuInfoUpdate() {
956 observer_list_->Notify(&GpuDataManagerObserver::OnGpuInfoUpdate); 969 observer_list_->Notify(&GpuDataManagerObserver::OnGpuInfoUpdate);
957 } 970 }
958 971
959 void GpuDataManagerImplPrivate::EnableSwiftShaderIfNecessary() { 972 void GpuDataManagerImplPrivate::EnableSwiftShaderIfNecessary() {
973 if (ShouldUseWarp())
974 return;
Zhenyao Mo 2014/08/29 18:28:50 Please add an unit test to make sure if Warp is us
luken 2014/08/29 23:34:03 Done.
975
960 if (!GpuAccessAllowed(NULL) || 976 if (!GpuAccessAllowed(NULL) ||
961 blacklisted_features_.count(gpu::GPU_FEATURE_TYPE_WEBGL)) { 977 blacklisted_features_.count(gpu::GPU_FEATURE_TYPE_WEBGL)) {
962 if (!swiftshader_path_.empty() && 978 if (!swiftshader_path_.empty() &&
963 !base::CommandLine::ForCurrentProcess()->HasSwitch( 979 !base::CommandLine::ForCurrentProcess()->HasSwitch(
964 switches::kDisableSoftwareRasterizer)) 980 switches::kDisableSoftwareRasterizer))
965 use_swiftshader_ = true; 981 use_swiftshader_ = true;
966 } 982 }
967 } 983 }
968 984
985 void GpuDataManagerImplPrivate::EnableWarpIfNecessary() {
986 #if defined(OS_WIN)
987 // We should only use WARP if we are unable to use the regular GPU for
988 // compositing, and if we should fall back.
989 use_warp_ = !CanUseGpuBrowserCompositor() &&
990 gpu::ShouldFallbackToWarp();
991 #endif
992 }
993
969 std::string GpuDataManagerImplPrivate::GetDomainFromURL( 994 std::string GpuDataManagerImplPrivate::GetDomainFromURL(
970 const GURL& url) const { 995 const GURL& url) const {
971 // For the moment, we just use the host, or its IP address, as the 996 // For the moment, we just use the host, or its IP address, as the
972 // entry in the set, rather than trying to figure out the top-level 997 // entry in the set, rather than trying to figure out the top-level
973 // domain. This does mean that a.foo.com and b.foo.com will be 998 // domain. This does mean that a.foo.com and b.foo.com will be
974 // treated independently in the blocking of a given domain, but it 999 // treated independently in the blocking of a given domain, but it
975 // would require a third-party library to reliably figure out the 1000 // would require a third-party library to reliably figure out the
976 // top-level domain from a URL. 1001 // top-level domain from a URL.
977 if (!url.has_host()) { 1002 if (!url.has_host()) {
978 return std::string(); 1003 return std::string();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 1098
1074 void GpuDataManagerImplPrivate::OnGpuProcessInitFailure() { 1099 void GpuDataManagerImplPrivate::OnGpuProcessInitFailure() {
1075 gpu_process_accessible_ = false; 1100 gpu_process_accessible_ = false;
1076 gpu_info_.finalized = true; 1101 gpu_info_.finalized = true;
1077 complete_gpu_info_already_requested_ = true; 1102 complete_gpu_info_already_requested_ = true;
1078 // Some observers might be waiting. 1103 // Some observers might be waiting.
1079 NotifyGpuInfoUpdate(); 1104 NotifyGpuInfoUpdate();
1080 } 1105 }
1081 1106
1082 } // namespace content 1107 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698