| 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/compositor_util.h" | 5 #include "content/browser/gpu/compositor_util.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "cc/base/math_util.h" | |
| 14 #include "cc/base/switches.h" | 13 #include "cc/base/switches.h" |
| 15 #include "content/browser/gpu/gpu_data_manager_impl.h" | 14 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 16 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 17 #include "gpu/config/gpu_feature_type.h" | 16 #include "gpu/config/gpu_feature_type.h" |
| 18 | 17 |
| 19 namespace content { | 18 namespace content { |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 static bool IsGpuRasterizationBlacklisted() { | 22 static bool IsGpuRasterizationBlacklisted() { |
| 24 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance(); | 23 GpuDataManagerImpl* manager = GpuDataManagerImpl::GetInstance(); |
| 25 return manager->IsFeatureBlacklisted( | 24 return manager->IsFeatureBlacklisted( |
| 26 gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION); | 25 gpu::GPU_FEATURE_TYPE_GPU_RASTERIZATION); |
| 27 } | 26 } |
| 28 | 27 |
| 29 const char* kGpuCompositingFeatureName = "gpu_compositing"; | 28 const char* kGpuCompositingFeatureName = "gpu_compositing"; |
| 30 const char* kWebGLFeatureName = "webgl"; | 29 const char* kWebGLFeatureName = "webgl"; |
| 31 const char* kRasterizationFeatureName = "rasterization"; | 30 const char* kRasterizationFeatureName = "rasterization"; |
| 32 const char* kThreadedRasterizationFeatureName = "threaded_rasterization"; | 31 const char* kThreadedRasterizationFeatureName = "threaded_rasterization"; |
| 33 const char* kMultipleRasterThreadsFeatureName = "multiple_raster_threads"; | 32 const char* kMultipleRasterThreadsFeatureName = "multiple_raster_threads"; |
| 34 | 33 |
| 35 const int kMinRasterThreads = 1; | 34 const int kMinRasterThreads = 1; |
| 36 const int kMaxRasterThreads = 16; | 35 const int kMaxRasterThreads = 64; |
| 37 | 36 |
| 38 const int kMinMSAASampleCount = 0; | 37 const int kMinMSAASampleCount = 0; |
| 39 | 38 |
| 40 struct GpuFeatureInfo { | 39 struct GpuFeatureInfo { |
| 41 std::string name; | 40 std::string name; |
| 42 bool blocked; | 41 bool blocked; |
| 43 bool disabled; | 42 bool disabled; |
| 44 std::string disabled_description; | 43 std::string disabled_description; |
| 45 bool fallback_to_software; | 44 bool fallback_to_software; |
| 46 }; | 45 }; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 203 |
| 205 bool IsImplSidePaintingEnabled() { | 204 bool IsImplSidePaintingEnabled() { |
| 206 const base::CommandLine& command_line = | 205 const base::CommandLine& command_line = |
| 207 *base::CommandLine::ForCurrentProcess(); | 206 *base::CommandLine::ForCurrentProcess(); |
| 208 if (command_line.HasSwitch(switches::kDisableImplSidePainting)) | 207 if (command_line.HasSwitch(switches::kDisableImplSidePainting)) |
| 209 return false; | 208 return false; |
| 210 return true; | 209 return true; |
| 211 } | 210 } |
| 212 | 211 |
| 213 int NumberOfRendererRasterThreads() { | 212 int NumberOfRendererRasterThreads() { |
| 214 int num_raster_threads = base::SysInfo::NumberOfProcessors() / 2; | 213 int num_raster_threads = 1; |
| 215 | 214 |
| 216 // Async uploads is used when neither zero-copy nor one-copy is enabled and | 215 // Async uploads uses its own thread, so allow an extra thread when async |
| 217 // it uses its own thread, so reduce the number of raster threads when async | 216 // uploads is not in use. |
| 218 // uploads is in use. | 217 bool allow_extra_thread = |
| 219 bool async_uploads_is_used = | |
| 220 IsZeroCopyUploadEnabled() || IsOneCopyUploadEnabled(); | 218 IsZeroCopyUploadEnabled() || IsOneCopyUploadEnabled(); |
| 221 if (async_uploads_is_used) | 219 if (base::SysInfo::NumberOfProcessors() >= 4 && allow_extra_thread) |
| 222 --num_raster_threads; | 220 num_raster_threads = 2; |
| 223 | 221 |
| 224 const base::CommandLine& command_line = | 222 int force_num_raster_threads = ForceNumberOfRendererRasterThreads(); |
| 225 *base::CommandLine::ForCurrentProcess(); | 223 if (force_num_raster_threads) |
| 224 num_raster_threads = force_num_raster_threads; |
| 226 | 225 |
| 227 if (command_line.HasSwitch(switches::kNumRasterThreads)) { | 226 return num_raster_threads; |
| 228 std::string string_value = command_line.GetSwitchValueASCII( | |
| 229 switches::kNumRasterThreads); | |
| 230 if (!base::StringToInt(string_value, &num_raster_threads)) { | |
| 231 DLOG(WARNING) << "Failed to parse switch " << | |
| 232 switches::kNumRasterThreads << ": " << string_value; | |
| 233 } | |
| 234 } | |
| 235 | |
| 236 return cc::MathUtil::ClampToRange(num_raster_threads, kMinRasterThreads, | |
| 237 kMaxRasterThreads); | |
| 238 } | 227 } |
| 239 | 228 |
| 240 bool IsOneCopyUploadEnabled() { | 229 bool IsOneCopyUploadEnabled() { |
| 241 if (IsZeroCopyUploadEnabled()) | 230 if (IsZeroCopyUploadEnabled()) |
| 242 return false; | 231 return false; |
| 243 | 232 |
| 244 const base::CommandLine& command_line = | 233 const base::CommandLine& command_line = |
| 245 *base::CommandLine::ForCurrentProcess(); | 234 *base::CommandLine::ForCurrentProcess(); |
| 246 if (command_line.HasSwitch(switches::kEnableOneCopy)) | 235 if (command_line.HasSwitch(switches::kEnableOneCopy)) |
| 247 return true; | 236 return true; |
| 248 if (command_line.HasSwitch(switches::kDisableOneCopy)) | 237 if (command_line.HasSwitch(switches::kDisableOneCopy)) |
| 249 return false; | 238 return false; |
| 250 | 239 |
| 251 #if defined(OS_ANDROID) | 240 #if defined(OS_ANDROID) |
| 252 return false; | 241 return false; |
| 253 #endif | 242 #endif |
| 254 return true; | 243 return true; |
| 255 } | 244 } |
| 256 | 245 |
| 257 bool IsZeroCopyUploadEnabled() { | 246 bool IsZeroCopyUploadEnabled() { |
| 258 const base::CommandLine& command_line = | 247 const base::CommandLine& command_line = |
| 259 *base::CommandLine::ForCurrentProcess(); | 248 *base::CommandLine::ForCurrentProcess(); |
| 260 return command_line.HasSwitch(switches::kEnableZeroCopy); | 249 return command_line.HasSwitch(switches::kEnableZeroCopy); |
| 261 } | 250 } |
| 262 | 251 |
| 252 int ForceNumberOfRendererRasterThreads() { |
| 253 const base::CommandLine& command_line = |
| 254 *base::CommandLine::ForCurrentProcess(); |
| 255 |
| 256 if (!command_line.HasSwitch(switches::kNumRasterThreads)) |
| 257 return 0; |
| 258 std::string string_value = |
| 259 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
| 260 int force_num_raster_threads = 0; |
| 261 if (base::StringToInt(string_value, &force_num_raster_threads) && |
| 262 force_num_raster_threads >= kMinRasterThreads && |
| 263 force_num_raster_threads <= kMaxRasterThreads) { |
| 264 return force_num_raster_threads; |
| 265 } else { |
| 266 DLOG(WARNING) << "Failed to parse switch " << |
| 267 switches::kNumRasterThreads << ": " << string_value; |
| 268 return 0; |
| 269 } |
| 270 } |
| 271 |
| 263 bool IsGpuRasterizationEnabled() { | 272 bool IsGpuRasterizationEnabled() { |
| 264 const base::CommandLine& command_line = | 273 const base::CommandLine& command_line = |
| 265 *base::CommandLine::ForCurrentProcess(); | 274 *base::CommandLine::ForCurrentProcess(); |
| 266 | 275 |
| 267 if (!IsImplSidePaintingEnabled()) | 276 if (!IsImplSidePaintingEnabled()) |
| 268 return false; | 277 return false; |
| 269 | 278 |
| 270 if (command_line.HasSwitch(switches::kDisableGpuRasterization)) | 279 if (command_line.HasSwitch(switches::kDisableGpuRasterization)) |
| 271 return false; | 280 return false; |
| 272 else if (command_line.HasSwitch(switches::kEnableGpuRasterization)) | 281 else if (command_line.HasSwitch(switches::kEnableGpuRasterization)) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } else { | 376 } else { |
| 368 status = "enabled"; | 377 status = "enabled"; |
| 369 if (gpu_feature_info.name == kWebGLFeatureName && | 378 if (gpu_feature_info.name == kWebGLFeatureName && |
| 370 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING)) | 379 manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_GPU_COMPOSITING)) |
| 371 status += "_readback"; | 380 status += "_readback"; |
| 372 if (gpu_feature_info.name == kRasterizationFeatureName) { | 381 if (gpu_feature_info.name == kRasterizationFeatureName) { |
| 373 if (IsForceGpuRasterizationEnabled()) | 382 if (IsForceGpuRasterizationEnabled()) |
| 374 status += "_force"; | 383 status += "_force"; |
| 375 } | 384 } |
| 376 if (gpu_feature_info.name == kMultipleRasterThreadsFeatureName) { | 385 if (gpu_feature_info.name == kMultipleRasterThreadsFeatureName) { |
| 377 const base::CommandLine& command_line = | 386 if (ForceNumberOfRendererRasterThreads() > 0) |
| 378 *base::CommandLine::ForCurrentProcess(); | |
| 379 if (command_line.HasSwitch(switches::kNumRasterThreads)) | |
| 380 status += "_force"; | 387 status += "_force"; |
| 381 } | 388 } |
| 382 if (gpu_feature_info.name == kThreadedRasterizationFeatureName || | 389 if (gpu_feature_info.name == kThreadedRasterizationFeatureName || |
| 383 gpu_feature_info.name == kMultipleRasterThreadsFeatureName) | 390 gpu_feature_info.name == kMultipleRasterThreadsFeatureName) |
| 384 status += "_on"; | 391 status += "_on"; |
| 385 } | 392 } |
| 386 if (gpu_feature_info.name == kWebGLFeatureName && | 393 if (gpu_feature_info.name == kWebGLFeatureName && |
| 387 (gpu_feature_info.blocked || gpu_access_blocked) && | 394 (gpu_feature_info.blocked || gpu_access_blocked) && |
| 388 manager->ShouldUseSwiftShader()) { | 395 manager->ShouldUseSwiftShader()) { |
| 389 status = "unavailable_software"; | 396 status = "unavailable_software"; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 441 } |
| 435 } | 442 } |
| 436 return problem_list; | 443 return problem_list; |
| 437 } | 444 } |
| 438 | 445 |
| 439 std::vector<std::string> GetDriverBugWorkarounds() { | 446 std::vector<std::string> GetDriverBugWorkarounds() { |
| 440 return GpuDataManagerImpl::GetInstance()->GetDriverBugWorkarounds(); | 447 return GpuDataManagerImpl::GetInstance()->GetDriverBugWorkarounds(); |
| 441 } | 448 } |
| 442 | 449 |
| 443 } // namespace content | 450 } // namespace content |
| OLD | NEW |