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 3 // found in the LICENSE file. 4 5 #include "content/public/browser/compositor_util.h" 6 7 #include "base/command_line.h" 8 #include "base/metrics/field_trial.h" 9 #include "content/public/browser/gpu_data_manager.h" 10 #include "content/public/common/content_constants.h" 11 #include "content/public/common/content_switches.h" 12 #include "gpu/config/gpu_feature_type.h" 13 14 namespace content { 15 16 namespace { 17 18 bool CanDoAcceleratedCompositing() { 19 const GpuDataManager* manager = GpuDataManager::GetInstance(); 20 21 // Don't run the field trial if gpu access has been blocked or 22 // accelerated compositing is blacklisted. 23 if (!manager->GpuAccessAllowed(NULL) || 24 manager->IsFeatureBlacklisted( 25 gpu::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)) 26 return false; 27 28 // Check for SwiftShader. 29 if (manager->ShouldUseSwiftShader()) 30 return false; 31 32 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 33 if (command_line.HasSwitch(switches::kDisableAcceleratedCompositing)) 34 return false; 35 36 return true; 37 } 38 39 bool IsForceCompositingModeBlacklisted() { 40 return GpuDataManager::GetInstance()->IsFeatureBlacklisted( 41 gpu::GPU_FEATURE_TYPE_FORCE_COMPOSITING_MODE); 42 } 43 44 } // namespace 45 46 bool IsThreadedCompositingEnabled() { 47 #if defined(OS_WIN) && defined(USE_AURA) 48 // We always want compositing on Aura Windows. 49 return true; 50 #endif 51 52 if (!CanDoAcceleratedCompositing()) 53 return false; 54 55 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 56 57 // Command line switches take precedence over blacklist and field trials. 58 if (command_line.HasSwitch(switches::kDisableForceCompositingMode) || 59 command_line.HasSwitch(switches::kDisableThreadedCompositing)) 60 return false; 61 62 #if defined(OS_CHROMEOS) 63 // We always want threaded compositing on ChromeOS unless it's explicitly 64 // disabled above. 65 return true; 66 #endif 67 68 if (command_line.HasSwitch(switches::kEnableThreadedCompositing)) 69 return true; 70 71 if (IsForceCompositingModeBlacklisted()) 72 return false; 73 74 base::FieldTrial* trial = 75 base::FieldTrialList::Find(kGpuCompositingFieldTrialName); 76 return trial && 77 trial->group_name() == kGpuCompositingFieldTrialThreadEnabledName; 78 } 79 80 bool IsForceCompositingModeEnabled() { 81 #if defined(OS_WIN) && defined(USE_AURA) 82 // We always want compositing on Aura Windows. 83 return true; 84 #endif 85 86 if (!CanDoAcceleratedCompositing()) 87 return false; 88 89 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 90 91 // Command line switches take precedence over blacklisting and field trials. 92 if (command_line.HasSwitch(switches::kDisableForceCompositingMode)) 93 return false; 94 95 #if defined(OS_CHROMEOS) 96 // We always want compositing ChromeOS unless it's explicitly disabled above. 97 return true; 98 #endif 99 100 if (command_line.HasSwitch(switches::kForceCompositingMode)) 101 return true; 102 103 if (IsForceCompositingModeBlacklisted()) 104 return false; 105 106 base::FieldTrial* trial = 107 base::FieldTrialList::Find(kGpuCompositingFieldTrialName); 108 109 // Force compositing is enabled in both the force compositing 110 // and threaded compositing mode field trials. 111 return trial && 112 (trial->group_name() == 113 kGpuCompositingFieldTrialForceCompositingEnabledName || 114 trial->group_name() == kGpuCompositingFieldTrialThreadEnabledName); 115 } 116 117 } // namespace content 118