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 "chrome/browser/gpu/chrome_gpu_util.h" | 5 #include "chrome/browser/gpu/chrome_gpu_util.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/version.h" | 10 #include "base/version.h" |
11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
12 #include "base/win/windows_version.h" | 12 #include "base/win/windows_version.h" |
13 #endif | 13 #endif |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
16 #include "chrome/browser/ui/browser_list_observer.h" | 16 #include "chrome/browser/ui/browser_list_observer.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/chrome_version_info.h" | 18 #include "chrome/common/chrome_version_info.h" |
19 #include "content/public/browser/gpu_data_manager.h" | 19 #include "content/public/browser/gpu_data_manager.h" |
20 #include "content/public/common/content_constants.h" | 20 #include "content/public/common/content_constants.h" |
21 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
22 | 22 |
23 using content::GpuDataManager; | 23 using content::GpuDataManager; |
24 | 24 |
25 namespace gpu_util { | 25 namespace gpu_util { |
26 | 26 |
27 // The BrowserMonitor class is used to track the number of currently open | |
28 // browser windows, so that the gpu can be notified when they are created or | |
29 // destroyed. We only count tabbed windows for this purpose. | |
30 | |
31 // There's no BrowserList on Android/ | |
32 #if !defined(OS_ANDROID) | |
33 class BrowserMonitor : public chrome::BrowserListObserver { | |
34 public: | |
35 static BrowserMonitor* GetInstance() { | |
36 static BrowserMonitor* instance = NULL; | |
37 if (!instance) | |
38 instance = new BrowserMonitor; | |
39 return instance; | |
40 } | |
41 | |
42 void Install() { | |
43 if (!installed_) { | |
44 BrowserList::AddObserver(this); | |
45 installed_ = true; | |
46 } | |
47 } | |
48 | |
49 void Uninstall() { | |
50 if (installed_) { | |
51 BrowserList::RemoveObserver(this); | |
52 installed_ = false; | |
53 } | |
54 } | |
55 | |
56 private: | |
57 BrowserMonitor() : num_browsers_(0), installed_(false) { | |
58 } | |
59 | |
60 virtual ~BrowserMonitor() { | |
61 } | |
62 | |
63 // BrowserListObserver implementation. | |
64 virtual void OnBrowserAdded(Browser* browser) OVERRIDE { | |
65 if (browser->type() == Browser::TYPE_TABBED) | |
66 content::GpuDataManager::GetInstance()->SetWindowCount(++num_browsers_); | |
67 } | |
68 | |
69 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE { | |
70 if (browser->type() == Browser::TYPE_TABBED) | |
71 content::GpuDataManager::GetInstance()->SetWindowCount(--num_browsers_); | |
72 } | |
73 | |
74 uint32 num_browsers_; | |
75 bool installed_; | |
76 }; | |
77 | |
78 void InstallBrowserMonitor() { | |
79 BrowserMonitor::GetInstance()->Install(); | |
80 } | |
81 | |
82 void UninstallBrowserMonitor() { | |
83 BrowserMonitor::GetInstance()->Uninstall(); | |
84 } | |
85 | |
86 #endif // !defined(OS_ANDROID) | |
87 | |
88 void DisableCompositingFieldTrial() { | 27 void DisableCompositingFieldTrial() { |
89 base::FieldTrial* trial = | 28 base::FieldTrial* trial = |
90 base::FieldTrialList::Find(content::kGpuCompositingFieldTrialName); | 29 base::FieldTrialList::Find(content::kGpuCompositingFieldTrialName); |
91 if (trial) | 30 if (trial) |
92 trial->Disable(); | 31 trial->Disable(); |
93 } | 32 } |
94 | 33 |
95 bool ShouldRunCompositingFieldTrial() { | 34 bool ShouldRunCompositingFieldTrial() { |
96 // Enable the field trial only on desktop OS's. | 35 // Enable the field trial only on desktop OS's. |
97 #if !(defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)) | 36 #if !(defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 116 |
178 bool force_compositing = (trial->group() == force_compositing_group); | 117 bool force_compositing = (trial->group() == force_compositing_group); |
179 bool thread = (trial->group() == thread_group); | 118 bool thread = (trial->group() == thread_group); |
180 UMA_HISTOGRAM_BOOLEAN("GPU.InForceCompositingModeFieldTrial", | 119 UMA_HISTOGRAM_BOOLEAN("GPU.InForceCompositingModeFieldTrial", |
181 force_compositing); | 120 force_compositing); |
182 UMA_HISTOGRAM_BOOLEAN("GPU.InCompositorThreadFieldTrial", thread); | 121 UMA_HISTOGRAM_BOOLEAN("GPU.InCompositorThreadFieldTrial", thread); |
183 } | 122 } |
184 | 123 |
185 } // namespace gpu_util; | 124 } // namespace gpu_util; |
186 | 125 |
OLD | NEW |