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 "chrome/browser/gpu/chrome_gpu_util.h" 6 7 #include "base/command_line.h" 8 #if defined(OS_MACOSX) 9 #include "base/mac/mac_util.h" 10 #endif 11 #include "base/metrics/field_trial.h" 12 #include "base/metrics/histogram.h" 13 #include "base/version.h" 14 #if defined(OS_WIN) 15 #include "base/win/windows_version.h" 16 #endif 17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list_observer.h" 20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_version_info.h" 22 #include "content/public/browser/gpu_data_manager.h" 23 #include "content/public/common/content_constants.h" 24 #include "content/public/common/content_switches.h" 25 26 using content::GpuDataManager; 27 28 namespace gpu_util { 29 30 void DisableCompositingFieldTrial() { 31 base::FieldTrial* trial = 32 base::FieldTrialList::Find(content::kGpuCompositingFieldTrialName); 33 if (trial) 34 trial->Disable(); 35 } 36 37 bool ShouldRunCompositingFieldTrial() { 38 // Enable the field trial only on desktop OS's. 39 #if !(defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)) 40 return false; 41 #endif 42 43 // Necessary for linux_chromeos build since it defines both OS_LINUX 44 // and OS_CHROMEOS. 45 #if defined(OS_CHROMEOS) 46 return false; 47 #endif 48 49 #if defined(OS_WIN) 50 // Don't run the trial on Windows XP. 51 if (base::win::GetVersion() < base::win::VERSION_VISTA) 52 return false; 53 #endif 54 55 #if defined(OS_MACOSX) 56 // Browser and content shell tests hang on 10.7 when the Apple software 57 // renderer is used. These tests ignore the blacklist (which disables 58 // compositing both on 10.7 and when the Apple software renderer is used) 59 // by specifying the kSkipGpuDataLoading switch, so disable forced 60 // compositing here based on the switch and OS version. 61 // http://crbug.com/230931 62 if (base::mac::IsOSLion() && 63 CommandLine::ForCurrentProcess()->HasSwitch( 64 switches::kSkipGpuDataLoading)) { 65 return false; 66 } 67 #endif 68 69 // Don't activate the field trial if force-compositing-mode has been 70 // explicitly disabled from the command line. 71 if (CommandLine::ForCurrentProcess()->HasSwitch( 72 switches::kDisableForceCompositingMode) || 73 CommandLine::ForCurrentProcess()->HasSwitch( 74 switches::kDisableAcceleratedCompositing)) 75 return false; 76 77 return true; 78 } 79 80 // Note 1: The compositing field trial may be created at startup time via the 81 // Finch framework. In that case, all the Groups and probability values are 82 // set before this function is called and any Field Trial setup calls 83 // made here are simply ignored. 84 // Note 2: Compositing field trials will be overwritten if accelerated 85 // compositing is blacklisted. That check takes place in 86 // IsThreadedCompositingEnabled() and IsForceCompositingModeEnabled() as 87 // the blacklist information isn't available at the time the field trials 88 // are initialized. 89 // Early outs from this function intended to bypass activation of the field 90 // trial must call DisableCompositingFieldTrial() before returning. 91 void InitializeCompositingFieldTrial() { 92 // Early out in configurations that should not run the compositing 93 // field trial. 94 if (!ShouldRunCompositingFieldTrial()) { 95 DisableCompositingFieldTrial(); 96 return; 97 } 98 99 const base::FieldTrial::Probability kDivisor = 3; 100 scoped_refptr<base::FieldTrial> trial( 101 base::FieldTrialList::FactoryGetFieldTrial( 102 content::kGpuCompositingFieldTrialName, kDivisor, "disable", 103 2013, 12, 31, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL)); 104 105 base::FieldTrial::Probability force_compositing_mode_probability = 0; 106 base::FieldTrial::Probability threaded_compositing_probability = 0; 107 108 // Note: Threaded compositing mode isn't feature complete on mac or linux yet: 109 // http://crbug.com/133602 for mac 110 // http://crbug.com/140866 for linux 111 112 #if defined(OS_WIN) || defined(OS_MACOSX) 113 // Enable threaded compositing on Windows and Mac. 114 threaded_compositing_probability = kDivisor; 115 #endif 116 117 int force_compositing_group = trial->AppendGroup( 118 content::kGpuCompositingFieldTrialForceCompositingEnabledName, 119 force_compositing_mode_probability); 120 int thread_group = trial->AppendGroup( 121 content::kGpuCompositingFieldTrialThreadEnabledName, 122 threaded_compositing_probability); 123 124 bool force_compositing = (trial->group() == force_compositing_group); 125 bool thread = (trial->group() == thread_group); 126 UMA_HISTOGRAM_BOOLEAN("GPU.InForceCompositingModeFieldTrial", 127 force_compositing); 128 UMA_HISTOGRAM_BOOLEAN("GPU.InCompositorThreadFieldTrial", thread); 129 } 130 131 } // namespace gpu_util 132 133