gpu_mode_manager.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 3// found in the LICENSE file. 4 5#include "chrome/browser/gpu/gpu_mode_manager.h" 6 7#include "base/bind.h" 8#include "base/prefs/pref_registry_simple.h" 9#include "base/prefs/pref_service.h" 10#include "chrome/browser/browser_process.h" 11#include "chrome/common/pref_names.h" 12#include "content/public/browser/gpu_data_manager.h" 13 14// static 15void GpuModeManager::RegisterPrefs(PrefRegistrySimple* registry) { 16 registry->RegisterBooleanPref( 17 prefs::kHardwareAccelerationModeEnabled, true); 18} 19 20GpuModeManager::GpuModeManager() 21 : initial_gpu_mode_pref_(true) { 22 if (g_browser_process->local_state()) { // Skip for unit tests 23 pref_registrar_.Init(g_browser_process->local_state()); 24 // Do nothing when the pref changes. It takes effect after 25 // chrome restarts. 26 pref_registrar_.Add( 27 prefs::kHardwareAccelerationModeEnabled, 28 base::Bind(&base::DoNothing)); 29 30 initial_gpu_mode_pref_ = IsGpuModePrefEnabled(); 31 32 if (!initial_gpu_mode_pref_) { 33 content::GpuDataManager* gpu_data_manager = 34 content::GpuDataManager::GetInstance(); 35 DCHECK(gpu_data_manager); 36 gpu_data_manager->DisableHardwareAcceleration(); 37 } 38 } 39} 40 41GpuModeManager::~GpuModeManager() { 42} 43 44bool GpuModeManager::initial_gpu_mode_pref() const { 45 return initial_gpu_mode_pref_; 46} 47 48// static 49bool GpuModeManager::IsGpuModePrefEnabled() { 50 PrefService* service = g_browser_process->local_state(); 51 DCHECK(service); 52 return service->GetBoolean( 53 prefs::kHardwareAccelerationModeEnabled); 54} 55 56