OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.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/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/string_piece.h" |
11 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
12 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "base/version.h" | 15 #include "base/version.h" |
15 #include "content/browser/gpu/gpu_process_host.h" | 16 #include "content/browser/gpu/gpu_process_host.h" |
16 #include "content/browser/gpu/gpu_util.h" | 17 #include "content/browser/gpu/gpu_util.h" |
17 #include "content/common/gpu/gpu_messages.h" | 18 #include "content/common/gpu/gpu_messages.h" |
18 #include "content/gpu/gpu_info_collector.h" | 19 #include "content/gpu/gpu_info_collector.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/gpu_data_manager_observer.h" | 21 #include "content/public/browser/gpu_data_manager_observer.h" |
21 #include "content/public/common/content_client.h" | 22 #include "content/public/common/content_client.h" |
22 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 24 #include "grit/content_resources.h" |
23 #include "ui/base/ui_base_switches.h" | 25 #include "ui/base/ui_base_switches.h" |
24 #include "ui/gl/gl_implementation.h" | 26 #include "ui/gl/gl_implementation.h" |
25 #include "ui/gl/gl_switches.h" | 27 #include "ui/gl/gl_switches.h" |
26 #include "webkit/plugins/plugin_switches.h" | 28 #include "webkit/plugins/plugin_switches.h" |
27 | 29 |
28 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
29 #include "base/win/windows_version.h" | 31 #include "base/win/windows_version.h" |
30 #endif | 32 #endif |
31 | 33 |
32 using content::BrowserThread; | 34 using content::BrowserThread; |
33 using content::GpuDataManagerObserver; | 35 using content::GpuDataManagerObserver; |
34 using content::GpuFeatureType; | 36 using content::GpuFeatureType; |
35 using content::GpuSwitchingOption; | 37 using content::GpuSwitchingOption; |
36 | 38 |
| 39 namespace { |
| 40 |
| 41 // Strip out the non-digital info; if after that, we get an empty string, |
| 42 // return "0". |
| 43 std::string ProcessVersionString(const std::string& raw_string) { |
| 44 const std::string valid_set = "0123456789."; |
| 45 size_t start_pos = raw_string.find_first_of(valid_set); |
| 46 if (start_pos == std::string::npos) |
| 47 return "0"; |
| 48 size_t end_pos = raw_string.find_first_not_of(raw_string, start_pos); |
| 49 std::string version_string = raw_string.substr( |
| 50 start_pos, end_pos - start_pos); |
| 51 if (version_string.empty()) |
| 52 return "0"; |
| 53 return version_string; |
| 54 } |
| 55 |
| 56 } // namespace anonymous |
| 57 |
37 // static | 58 // static |
38 content::GpuDataManager* content::GpuDataManager::GetInstance() { | 59 content::GpuDataManager* content::GpuDataManager::GetInstance() { |
39 return GpuDataManagerImpl::GetInstance(); | 60 return GpuDataManagerImpl::GetInstance(); |
40 } | 61 } |
41 | 62 |
42 // static | 63 // static |
43 GpuDataManagerImpl* GpuDataManagerImpl::GetInstance() { | 64 GpuDataManagerImpl* GpuDataManagerImpl::GetInstance() { |
44 return Singleton<GpuDataManagerImpl>::get(); | 65 return Singleton<GpuDataManagerImpl>::get(); |
45 } | 66 } |
46 | 67 |
47 GpuDataManagerImpl::GpuDataManagerImpl() | 68 GpuDataManagerImpl::GpuDataManagerImpl() |
48 : complete_gpu_info_already_requested_(false), | 69 : complete_gpu_info_already_requested_(false), |
49 gpu_feature_type_(content::GPU_FEATURE_TYPE_UNKNOWN), | 70 gpu_feature_type_(content::GPU_FEATURE_TYPE_UNKNOWN), |
50 preliminary_gpu_feature_type_(content::GPU_FEATURE_TYPE_UNKNOWN), | 71 preliminary_gpu_feature_type_(content::GPU_FEATURE_TYPE_UNKNOWN), |
51 gpu_switching_(content::GPU_SWITCHING_AUTOMATIC), | 72 gpu_switching_(content::GPU_SWITCHING_AUTOMATIC), |
52 observer_list_(new GpuDataManagerObserverList), | 73 observer_list_(new GpuDataManagerObserverList), |
53 software_rendering_(false), | 74 software_rendering_(false), |
54 card_blacklisted_(false), | 75 card_blacklisted_(false), |
55 update_histograms_(true) { | 76 update_histograms_(true) { |
56 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 77 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
57 if (command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) { | 78 if (command_line->HasSwitch(switches::kDisableAcceleratedCompositing)) { |
58 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); | 79 command_line->AppendSwitch(switches::kDisableAccelerated2dCanvas); |
59 command_line->AppendSwitch(switches::kDisableAcceleratedLayers); | 80 command_line->AppendSwitch(switches::kDisableAcceleratedLayers); |
60 } | 81 } |
61 if (command_line->HasSwitch(switches::kDisableGpu)) | 82 if (command_line->HasSwitch(switches::kDisableGpu)) |
62 BlacklistCard(); | 83 BlacklistCard(); |
63 } | 84 } |
64 | 85 |
65 void GpuDataManagerImpl::Initialize( | 86 void GpuDataManagerImpl::Initialize() { |
66 const std::string& browser_version_string, | 87 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
67 const std::string& gpu_blacklist_json) { | 88 if (command_line->HasSwitch(switches::kSkipGpuDataLoading)) |
| 89 return; |
| 90 |
68 content::GPUInfo gpu_info; | 91 content::GPUInfo gpu_info; |
69 gpu_info_collector::CollectPreliminaryGraphicsInfo(&gpu_info); | 92 gpu_info_collector::CollectPreliminaryGraphicsInfo(&gpu_info); |
70 #if defined(ARCH_CPU_X86_FAMILY) | 93 #if defined(ARCH_CPU_X86_FAMILY) |
71 if (!gpu_info.gpu.vendor_id || !gpu_info.gpu.device_id) | 94 if (!gpu_info.gpu.vendor_id || !gpu_info.gpu.device_id) |
72 gpu_info.finalized = true; | 95 gpu_info.finalized = true; |
73 #endif | 96 #endif |
74 | 97 |
75 Initialize(browser_version_string, gpu_blacklist_json, gpu_info); | 98 std::string gpu_blacklist_string; |
| 99 if (!command_line->HasSwitch(switches::kIgnoreGpuBlacklist)) { |
| 100 const base::StringPiece gpu_blacklist_json = |
| 101 content::GetContentClient()->GetDataResource( |
| 102 IDR_GPU_BLACKLIST, ui::SCALE_FACTOR_NONE); |
| 103 gpu_blacklist_string = gpu_blacklist_json.as_string(); |
| 104 } |
| 105 |
| 106 InitializeImpl(gpu_blacklist_string, gpu_info); |
76 } | 107 } |
77 | 108 |
78 void GpuDataManagerImpl::Initialize( | 109 void GpuDataManagerImpl::InitializeForTesting( |
79 const std::string& browser_version_string, | 110 const std::string& gpu_blacklist_json, |
| 111 const content::GPUInfo& gpu_info) { |
| 112 // This function is for testing only, so disable histograms. |
| 113 update_histograms_ = false; |
| 114 |
| 115 InitializeImpl(gpu_blacklist_json, gpu_info); |
| 116 } |
| 117 |
| 118 void GpuDataManagerImpl::InitializeImpl( |
80 const std::string& gpu_blacklist_json, | 119 const std::string& gpu_blacklist_json, |
81 const content::GPUInfo& gpu_info) { | 120 const content::GPUInfo& gpu_info) { |
82 { | 121 { |
83 // This function should only be called in testing. | 122 // This function should only be called in testing. |
84 // We need clean up the gpu_info_ for a clean initialization. | 123 // We need clean up the gpu_info_ for a clean initialization. |
85 const content::GPUInfo empty_gpu_info; | 124 const content::GPUInfo empty_gpu_info; |
86 base::AutoLock auto_lock(gpu_info_lock_); | 125 base::AutoLock auto_lock(gpu_info_lock_); |
87 gpu_info_ = empty_gpu_info; | 126 gpu_info_ = empty_gpu_info; |
88 } | 127 } |
89 | 128 |
90 // This function is for testing only, so disable histograms. | |
91 update_histograms_ = false; | |
92 | |
93 if (!gpu_blacklist_json.empty()) { | 129 if (!gpu_blacklist_json.empty()) { |
| 130 std::string browser_version_string = ProcessVersionString( |
| 131 content::GetContentClient()->GetProduct()); |
94 CHECK(!browser_version_string.empty()); | 132 CHECK(!browser_version_string.empty()); |
95 gpu_blacklist_.reset(new GpuBlacklist()); | 133 gpu_blacklist_.reset(new GpuBlacklist()); |
96 bool succeed = gpu_blacklist_->LoadGpuBlacklist( | 134 bool succeed = gpu_blacklist_->LoadGpuBlacklist( |
97 browser_version_string, | 135 browser_version_string, |
98 gpu_blacklist_json, | 136 gpu_blacklist_json, |
99 GpuBlacklist::kCurrentOsOnly); | 137 GpuBlacklist::kCurrentOsOnly); |
100 CHECK(succeed); | 138 CHECK(succeed); |
101 } | 139 } |
102 | 140 |
103 UpdateGpuInfo(gpu_info); | 141 UpdateGpuInfo(gpu_info); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 464 |
427 void GpuDataManagerImpl::BlacklistCard() { | 465 void GpuDataManagerImpl::BlacklistCard() { |
428 card_blacklisted_ = true; | 466 card_blacklisted_ = true; |
429 | 467 |
430 gpu_feature_type_ = content::GPU_FEATURE_TYPE_ALL; | 468 gpu_feature_type_ = content::GPU_FEATURE_TYPE_ALL; |
431 | 469 |
432 EnableSoftwareRenderingIfNecessary(); | 470 EnableSoftwareRenderingIfNecessary(); |
433 NotifyGpuInfoUpdate(); | 471 NotifyGpuInfoUpdate(); |
434 } | 472 } |
435 | 473 |
OLD | NEW |