• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/gl_string_manager.h"
6  
7  #include "base/prefs/pref_registry_simple.h"
8  #include "base/prefs/pref_service.h"
9  #include "chrome/browser/browser_process.h"
10  #include "chrome/common/pref_names.h"
11  #include "content/public/browser/gpu_data_manager.h"
12  
13  // static
RegisterPrefs(PrefRegistrySimple * registry)14  void GLStringManager::RegisterPrefs(PrefRegistrySimple* registry) {
15    registry->RegisterStringPref(prefs::kGLVendorString, std::string());
16    registry->RegisterStringPref(prefs::kGLRendererString, std::string());
17    registry->RegisterStringPref(prefs::kGLVersionString, std::string());
18  }
19  
GLStringManager()20  GLStringManager::GLStringManager() {
21  }
22  
~GLStringManager()23  GLStringManager::~GLStringManager() {
24  }
25  
Initialize()26  void GLStringManager::Initialize() {
27    // On MacOSX or Windows, preliminary GPUInfo is enough.
28  #if defined(OS_LINUX)
29    // We never remove this observer from GpuDataManager.
30    content::GpuDataManager::GetInstance()->AddObserver(this);
31  
32    PrefService* local_state = g_browser_process->local_state();
33    if (!local_state)
34      return;
35  
36    gl_vendor_ = local_state->GetString(prefs::kGLVendorString);
37    gl_renderer_ = local_state->GetString(prefs::kGLRendererString);
38    gl_version_ = local_state->GetString(prefs::kGLVersionString);
39  
40    if (!gl_vendor_.empty() || !gl_renderer_.empty() || !gl_version_.empty()) {
41      content::GpuDataManager::GetInstance()->SetGLStrings(
42          gl_vendor_, gl_renderer_, gl_version_);
43    }
44  #endif
45  }
46  
OnGpuInfoUpdate()47  void GLStringManager::OnGpuInfoUpdate() {
48    std::string gl_vendor, gl_renderer, gl_version;
49    content::GpuDataManager::GetInstance()->GetGLStrings(
50        &gl_vendor, &gl_renderer, &gl_version);
51  
52    PrefService* local_state = g_browser_process->local_state();
53    if (!local_state)
54      return;
55  
56    if (!gl_vendor.empty() && gl_vendor != gl_vendor_) {
57      gl_vendor_ = gl_vendor;
58      local_state->SetString(prefs::kGLVendorString, gl_vendor_);
59    }
60    if (!gl_renderer.empty() && gl_renderer != gl_renderer_) {
61      gl_renderer_ = gl_renderer;
62      local_state->SetString(prefs::kGLRendererString, gl_renderer_);
63    }
64    if (!gl_version.empty() && gl_version != gl_version_) {
65      gl_version_ = gl_version;
66      local_state->SetString(prefs::kGLVersionString, gl_version_);
67    }
68  }
69  
70