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

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

Issue 2737983002: WebGL feature will only enabled when accelerated (Closed)
Patch Set: WebGL and WebGL2 features will only enabled when accelerated Created 3 years, 9 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
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 <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 blacklist->GetDecisionEntries(&flag_disabled_entries, disabled); 160 blacklist->GetDecisionEntries(&flag_disabled_entries, disabled);
161 for (uint32_t disabled_entry : flag_disabled_entries) { 161 for (uint32_t disabled_entry : flag_disabled_entries) {
162 UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerDisabledEntry", 162 UMA_HISTOGRAM_ENUMERATION("GPU.BlacklistTestResultsPerDisabledEntry",
163 disabled_entry, max_entry_id + 1); 163 disabled_entry, max_entry_id + 1);
164 } 164 }
165 165
166 const gpu::GpuFeatureType kGpuFeatures[] = { 166 const gpu::GpuFeatureType kGpuFeatures[] = {
167 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS, 167 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS,
168 gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING, 168 gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING,
169 gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION, 169 gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION,
170 gpu::GPU_FEATURE_TYPE_WEBGL, 170 gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL,
171 gpu::GPU_FEATURE_TYPE_WEBGL2}; 171 gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL2};
172 const std::string kGpuBlacklistFeatureHistogramNames[] = { 172 const std::string kGpuBlacklistFeatureHistogramNames[] = {
173 "GPU.BlacklistFeatureTestResults.Accelerated2dCanvas", 173 "GPU.BlacklistFeatureTestResults.Accelerated2dCanvas",
174 "GPU.BlacklistFeatureTestResults.GpuCompositing", 174 "GPU.BlacklistFeatureTestResults.GpuCompositing",
175 "GPU.BlacklistFeatureTestResults.GpuRasterization", 175 "GPU.BlacklistFeatureTestResults.GpuRasterization",
176 "GPU.BlacklistFeatureTestResults.Webgl", 176 "GPU.BlacklistFeatureTestResults.Webgl",
177 "GPU.BlacklistFeatureTestResults.Webgl2"}; 177 "GPU.BlacklistFeatureTestResults.Webgl2"};
178 const bool kGpuFeatureUserFlags[] = { 178 const bool kGpuFeatureUserFlags[] = {
179 command_line.HasSwitch(switches::kDisableAccelerated2dCanvas), 179 command_line.HasSwitch(switches::kDisableAccelerated2dCanvas),
180 command_line.HasSwitch(switches::kDisableGpu), 180 command_line.HasSwitch(switches::kDisableGpu),
181 command_line.HasSwitch(switches::kDisableGpuRasterization), 181 command_line.HasSwitch(switches::kDisableGpuRasterization),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 295 }
296 296
297 bool GpuDataManagerImplPrivate::IsFeatureBlacklisted(int feature) const { 297 bool GpuDataManagerImplPrivate::IsFeatureBlacklisted(int feature) const {
298 #if defined(OS_CHROMEOS) 298 #if defined(OS_CHROMEOS)
299 if (feature == gpu::GPU_FEATURE_TYPE_PANEL_FITTING && 299 if (feature == gpu::GPU_FEATURE_TYPE_PANEL_FITTING &&
300 base::CommandLine::ForCurrentProcess()->HasSwitch( 300 base::CommandLine::ForCurrentProcess()->HasSwitch(
301 switches::kDisablePanelFitting)) { 301 switches::kDisablePanelFitting)) {
302 return true; 302 return true;
303 } 303 }
304 #endif // OS_CHROMEOS 304 #endif // OS_CHROMEOS
305 if (use_swiftshader_) {
306 // Skia's software rendering is probably more efficient than going through
307 // software emulation of the GPU, so use that.
308 if (feature == gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
309 return true;
310 return false;
311 }
312 305
313 return (blacklisted_features_.count(feature) == 1); 306 // SwiftShader blacklists all features
307 return use_swiftshader_ || (blacklisted_features_.count(feature) == 1);
314 } 308 }
315 309
316 bool GpuDataManagerImplPrivate::IsFeatureEnabled(int feature) const { 310 bool GpuDataManagerImplPrivate::IsFeatureEnabled(int feature) const {
317 DCHECK_EQ(feature, gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION); 311 DCHECK_EQ(feature, gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION);
318 return gpu_feature_info_ 312 return gpu_feature_info_
319 .status_values[gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION] == 313 .status_values[gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION] ==
320 gpu::kGpuFeatureStatusEnabled; 314 gpu::kGpuFeatureStatusEnabled;
321 } 315 }
322 316
317 bool GpuDataManagerImplPrivate::IsWebGLEnabled() const {
318 return use_swiftshader_ ||
319 !blacklisted_features_.count(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL);
320 }
321
323 bool GpuDataManagerImplPrivate::IsDriverBugWorkaroundActive(int feature) const { 322 bool GpuDataManagerImplPrivate::IsDriverBugWorkaroundActive(int feature) const {
324 return (gpu_driver_bugs_.count(feature) == 1); 323 return (gpu_driver_bugs_.count(feature) == 1);
325 } 324 }
326 325
327 size_t GpuDataManagerImplPrivate::GetBlacklistedFeatureCount() const { 326 size_t GpuDataManagerImplPrivate::GetBlacklistedFeatureCount() const {
328 if (use_swiftshader_) 327 // SwiftShader blacklists all features
329 return 1; 328 return use_swiftshader_ ? gpu::NUMBER_OF_GPU_FEATURE_TYPES
330 return blacklisted_features_.size(); 329 : blacklisted_features_.size();
331 } 330 }
332 331
333 gpu::GPUInfo GpuDataManagerImplPrivate::GetGPUInfo() const { 332 gpu::GPUInfo GpuDataManagerImplPrivate::GetGPUInfo() const {
334 return gpu_info_; 333 return gpu_info_;
335 } 334 }
336 335
337 void GpuDataManagerImplPrivate::GetGpuProcessHandles( 336 void GpuDataManagerImplPrivate::GetGpuProcessHandles(
338 const GpuDataManager::GetGpuProcessHandlesCallback& callback) const { 337 const GpuDataManager::GetGpuProcessHandlesCallback& callback) const {
339 GpuProcessHost::GetProcessHandles(callback); 338 GpuProcessHost::GetProcessHandles(callback);
340 } 339 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 // because their context creation can always be rejected on the GPU process 372 // because their context creation can always be rejected on the GPU process
374 // side. 373 // side.
375 std::set<int> feature_diffs; 374 std::set<int> feature_diffs;
376 std::set_difference(blacklisted_features_.begin(), 375 std::set_difference(blacklisted_features_.begin(),
377 blacklisted_features_.end(), 376 blacklisted_features_.end(),
378 preliminary_blacklisted_features_.begin(), 377 preliminary_blacklisted_features_.begin(),
379 preliminary_blacklisted_features_.end(), 378 preliminary_blacklisted_features_.end(),
380 std::inserter(feature_diffs, feature_diffs.begin())); 379 std::inserter(feature_diffs, feature_diffs.begin()));
381 if (feature_diffs.size()) { 380 if (feature_diffs.size()) {
382 // TODO(zmo): Other features might also be OK to ignore here. 381 // TODO(zmo): Other features might also be OK to ignore here.
383 feature_diffs.erase(gpu::GPU_FEATURE_TYPE_WEBGL); 382 feature_diffs.erase(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL);
384 feature_diffs.erase(gpu::GPU_FEATURE_TYPE_WEBGL2); 383 feature_diffs.erase(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL2);
385 } 384 }
386 if (feature_diffs.size()) { 385 if (feature_diffs.size()) {
387 if (reason) { 386 if (reason) {
388 *reason = "Features are disabled on full but not preliminary GPU info."; 387 *reason = "Features are disabled on full but not preliminary GPU info.";
389 } 388 }
390 return false; 389 return false;
391 } 390 }
392 } 391 }
393 392
394 if (blacklisted_features_.size() == gpu::NUMBER_OF_GPU_FEATURE_TYPES) { 393 if (blacklisted_features_.size() == gpu::NUMBER_OF_GPU_FEATURE_TYPES) {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 gpu_driver_bugs_.end()) { 742 gpu_driver_bugs_.end()) {
744 command_line->AppendSwitch(switches::kDisableES3GLContext); 743 command_line->AppendSwitch(switches::kDisableES3GLContext);
745 } 744 }
746 if (gpu_driver_bugs_.find(gpu::DISABLE_DIRECT_COMPOSITION) != 745 if (gpu_driver_bugs_.find(gpu::DISABLE_DIRECT_COMPOSITION) !=
747 gpu_driver_bugs_.end()) { 746 gpu_driver_bugs_.end()) {
748 command_line->AppendSwitch(switches::kDisableDirectComposition); 747 command_line->AppendSwitch(switches::kDisableDirectComposition);
749 } 748 }
750 if (use_swiftshader_) { 749 if (use_swiftshader_) {
751 command_line->AppendSwitchASCII( 750 command_line->AppendSwitchASCII(
752 switches::kUseGL, gl::kGLImplementationSwiftShaderForWebGLName); 751 switches::kUseGL, gl::kGLImplementationSwiftShaderForWebGLName);
753 } else if ((IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL) || 752 } else if ((IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL) ||
754 IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING) || 753 IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING) ||
755 IsFeatureBlacklisted( 754 IsFeatureBlacklisted(
756 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)) && 755 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)) &&
757 (use_gl == "any")) { 756 (use_gl == "any")) {
758 command_line->AppendSwitchASCII( 757 command_line->AppendSwitchASCII(
759 switches::kUseGL, 758 switches::kUseGL,
760 gl::GetGLImplementationName(gl::GetSoftwareGLImplementation())); 759 gl::GetGLImplementationName(gl::GetSoftwareGLImplementation()));
761 } else if (!use_gl.empty()) { 760 } else if (!use_gl.empty()) {
762 command_line->AppendSwitchASCII(switches::kUseGL, use_gl); 761 command_line->AppendSwitchASCII(switches::kUseGL, use_gl);
763 } 762 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 command_line->AppendSwitch(switches::kDisableWebRtcHWEncoding); 820 command_line->AppendSwitch(switches::kDisableWebRtcHWEncoding);
822 if (gpu_preferences) 821 if (gpu_preferences)
823 gpu_preferences->disable_web_rtc_hw_encoding = true; 822 gpu_preferences->disable_web_rtc_hw_encoding = true;
824 #if defined (OS_ANDROID) 823 #if defined (OS_ANDROID)
825 } 824 }
826 #endif 825 #endif
827 } 826 }
828 #endif 827 #endif
829 828
830 if (gpu_preferences) { // enable_es3_apis 829 if (gpu_preferences) { // enable_es3_apis
831 bool blacklisted = IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL2); 830 bool blacklisted =
831 IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL2);
832 bool enabled = base::CommandLine::ForCurrentProcess()->HasSwitch( 832 bool enabled = base::CommandLine::ForCurrentProcess()->HasSwitch(
833 switches::kEnableES3APIs); 833 switches::kEnableES3APIs);
834 bool disabled = base::CommandLine::ForCurrentProcess()->HasSwitch( 834 bool disabled = base::CommandLine::ForCurrentProcess()->HasSwitch(
835 switches::kDisableES3APIs); 835 switches::kDisableES3APIs);
836 gpu_preferences->enable_es3_apis = (enabled || !blacklisted) && !disabled; 836 gpu_preferences->enable_es3_apis = (enabled || !blacklisted) && !disabled;
piman 2017/03/10 20:31:40 Mmh, I think we still want to be precise about web
sugoi1 2017/03/10 20:42:38 Ok, I can revert the WebGL2 change. For now, Swift
837 } 837 }
838 838
839 // Pass GPU and driver information to GPU process. We try to avoid full GPU 839 // Pass GPU and driver information to GPU process. We try to avoid full GPU
840 // info collection at GPU process startup, but we need gpu vendor_id, 840 // info collection at GPU process startup, but we need gpu vendor_id,
841 // device_id, driver_vendor, driver_version for deciding whether we need to 841 // device_id, driver_vendor, driver_version for deciding whether we need to
842 // collect full info (on Linux) and for crash reporting purpose. 842 // collect full info (on Linux) and for crash reporting purpose.
843 command_line->AppendSwitchASCII(switches::kGpuVendorID, 843 command_line->AppendSwitchASCII(switches::kGpuVendorID,
844 base::StringPrintf("0x%04x", gpu_info_.gpu.vendor_id)); 844 base::StringPrintf("0x%04x", gpu_info_.gpu.vendor_id));
845 command_line->AppendSwitchASCII(switches::kGpuDeviceID, 845 command_line->AppendSwitchASCII(switches::kGpuDeviceID,
846 base::StringPrintf("0x%04x", gpu_info_.gpu.device_id)); 846 base::StringPrintf("0x%04x", gpu_info_.gpu.device_id));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 command_line->AppendSwitchASCII( 883 command_line->AppendSwitchASCII(
884 switches::kGpuActiveDeviceID, 884 switches::kGpuActiveDeviceID,
885 base::StringPrintf("0x%04x", maybe_active_gpu_device.device_id)); 885 base::StringPrintf("0x%04x", maybe_active_gpu_device.device_id));
886 } 886 }
887 } 887 }
888 888
889 void GpuDataManagerImplPrivate::UpdateRendererWebPrefs( 889 void GpuDataManagerImplPrivate::UpdateRendererWebPrefs(
890 WebPreferences* prefs) const { 890 WebPreferences* prefs) const {
891 DCHECK(prefs); 891 DCHECK(prefs);
892 892
893 if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL)) { 893 if (!IsWebGLEnabled()) {
894 prefs->experimental_webgl_enabled = false; 894 prefs->experimental_webgl_enabled = false;
895 prefs->pepper_3d_enabled = false; 895 prefs->pepper_3d_enabled = false;
896 } 896 }
897 if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH3D)) 897 if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH3D))
898 prefs->flash_3d_enabled = false; 898 prefs->flash_3d_enabled = false;
899 if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D)) { 899 if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D)) {
900 prefs->flash_stage3d_enabled = false; 900 prefs->flash_stage3d_enabled = false;
901 prefs->flash_stage3d_baseline_enabled = false; 901 prefs->flash_stage3d_baseline_enabled = false;
902 } 902 }
903 if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D_BASELINE)) 903 if (IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_FLASH_STAGE3D_BASELINE))
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 } 1221 }
1222 1222
1223 void GpuDataManagerImplPrivate::UpdateBlacklistedFeatures( 1223 void GpuDataManagerImplPrivate::UpdateBlacklistedFeatures(
1224 const std::set<int>& features) { 1224 const std::set<int>& features) {
1225 blacklisted_features_ = features; 1225 blacklisted_features_ = features;
1226 1226
1227 // Force disable using the GPU for these features, even if they would 1227 // Force disable using the GPU for these features, even if they would
1228 // otherwise be allowed. 1228 // otherwise be allowed.
1229 if (card_blacklisted_) { 1229 if (card_blacklisted_) {
1230 blacklisted_features_.insert(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING); 1230 blacklisted_features_.insert(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING);
1231 blacklisted_features_.insert(gpu::GPU_FEATURE_TYPE_WEBGL); 1231 blacklisted_features_.insert(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL);
1232 blacklisted_features_.insert(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL2);
1232 } 1233 }
1233 1234
1234 EnableSwiftShaderIfNecessary(); 1235 EnableSwiftShaderIfNecessary();
1235 } 1236 }
1236 1237
1237 void GpuDataManagerImplPrivate::UpdatePreliminaryBlacklistedFeatures() { 1238 void GpuDataManagerImplPrivate::UpdatePreliminaryBlacklistedFeatures() {
1238 preliminary_blacklisted_features_ = blacklisted_features_; 1239 preliminary_blacklisted_features_ = blacklisted_features_;
1239 preliminary_blacklisted_features_initialized_ = true; 1240 preliminary_blacklisted_features_initialized_ = true;
1240 } 1241 }
1241 1242
1242 void GpuDataManagerImplPrivate::UpdateGpuSwitchingManager( 1243 void GpuDataManagerImplPrivate::UpdateGpuSwitchingManager(
1243 const gpu::GPUInfo& gpu_info) { 1244 const gpu::GPUInfo& gpu_info) {
1244 // The vendor IDs might be 0 on non-PCI devices (like Android), but 1245 // The vendor IDs might be 0 on non-PCI devices (like Android), but
1245 // the length of the vector is all we care about in most cases. 1246 // the length of the vector is all we care about in most cases.
1246 std::vector<uint32_t> vendor_ids; 1247 std::vector<uint32_t> vendor_ids;
1247 vendor_ids.push_back(gpu_info.gpu.vendor_id); 1248 vendor_ids.push_back(gpu_info.gpu.vendor_id);
1248 for (const auto& device : gpu_info.secondary_gpus) { 1249 for (const auto& device : gpu_info.secondary_gpus) {
1249 vendor_ids.push_back(device.vendor_id); 1250 vendor_ids.push_back(device.vendor_id);
1250 } 1251 }
1251 ui::GpuSwitchingManager::GetInstance()->SetGpuVendorIds(vendor_ids); 1252 ui::GpuSwitchingManager::GetInstance()->SetGpuVendorIds(vendor_ids);
1252 gpu::InitializeDualGpusIfSupported(gpu_driver_bugs_); 1253 gpu::InitializeDualGpusIfSupported(gpu_driver_bugs_);
1253 } 1254 }
1254 1255
1255 void GpuDataManagerImplPrivate::NotifyGpuInfoUpdate() { 1256 void GpuDataManagerImplPrivate::NotifyGpuInfoUpdate() {
1256 observer_list_->Notify(FROM_HERE, &GpuDataManagerObserver::OnGpuInfoUpdate); 1257 observer_list_->Notify(FROM_HERE, &GpuDataManagerObserver::OnGpuInfoUpdate);
1257 } 1258 }
1258 1259
1259 void GpuDataManagerImplPrivate::EnableSwiftShaderIfNecessary() { 1260 void GpuDataManagerImplPrivate::EnableSwiftShaderIfNecessary() {
1260 if (!GpuAccessAllowed(NULL) || 1261 if (!GpuAccessAllowed(NULL) ||
1261 blacklisted_features_.count(gpu::GPU_FEATURE_TYPE_WEBGL)) { 1262 blacklisted_features_.count(gpu::GPU_FEATURE_TYPE_ACCELERATED_WEBGL)) {
1262 if (!swiftshader_path_.empty() && 1263 if (!swiftshader_path_.empty() &&
1263 !base::CommandLine::ForCurrentProcess()->HasSwitch( 1264 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1264 switches::kDisableSoftwareRasterizer)) 1265 switches::kDisableSoftwareRasterizer))
1265 use_swiftshader_ = true; 1266 use_swiftshader_ = true;
1266 } 1267 }
1267 } 1268 }
1268 1269
1269 std::string GpuDataManagerImplPrivate::GetDomainFromURL( 1270 std::string GpuDataManagerImplPrivate::GetDomainFromURL(
1270 const GURL& url) const { 1271 const GURL& url) const {
1271 // For the moment, we just use the host, or its IP address, as the 1272 // For the moment, we just use the host, or its IP address, as the
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 gpu_info_.context_info_state = gpu::kCollectInfoFatalFailure; 1373 gpu_info_.context_info_state = gpu::kCollectInfoFatalFailure;
1373 #if defined(OS_WIN) 1374 #if defined(OS_WIN)
1374 gpu_info_.dx_diagnostics_info_state = gpu::kCollectInfoFatalFailure; 1375 gpu_info_.dx_diagnostics_info_state = gpu::kCollectInfoFatalFailure;
1375 #endif 1376 #endif
1376 complete_gpu_info_already_requested_ = true; 1377 complete_gpu_info_already_requested_ = true;
1377 // Some observers might be waiting. 1378 // Some observers might be waiting.
1378 NotifyGpuInfoUpdate(); 1379 NotifyGpuInfoUpdate();
1379 } 1380 }
1380 1381
1381 } // namespace content 1382 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698