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 "ui/gl/gpu_switching_manager.h" | 5 #include "ui/gl/gpu_switching_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "ui/gl/gl_switches.h" | 10 #include "ui/gl/gl_switches.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 CGLPixelFormatObj discrete_pixel_format; | 21 CGLPixelFormatObj discrete_pixel_format; |
22 #endif // OS_MACOSX | 22 #endif // OS_MACOSX |
23 }; | 23 }; |
24 | 24 |
25 // static | 25 // static |
26 GpuSwitchingManager* GpuSwitchingManager::GetInstance() { | 26 GpuSwitchingManager* GpuSwitchingManager::GetInstance() { |
27 return base::Singleton<GpuSwitchingManager>::get(); | 27 return base::Singleton<GpuSwitchingManager>::get(); |
28 } | 28 } |
29 | 29 |
30 GpuSwitchingManager::GpuSwitchingManager() | 30 GpuSwitchingManager::GpuSwitchingManager() |
31 : gpu_switching_option_(gfx::PreferIntegratedGpu), | 31 : gpu_switching_option_(gl::PreferIntegratedGpu), |
32 gpu_switching_option_set_(false), | 32 gpu_switching_option_set_(false), |
33 supports_dual_gpus_(false), | 33 supports_dual_gpus_(false), |
34 supports_dual_gpus_set_(false), | 34 supports_dual_gpus_set_(false), |
35 platform_specific_(new PlatformSpecific) { | 35 platform_specific_(new PlatformSpecific) { |
36 #if defined(OS_MACOSX) | 36 #if defined(OS_MACOSX) |
37 platform_specific_->discrete_pixel_format = nullptr; | 37 platform_specific_->discrete_pixel_format = nullptr; |
38 #endif // OS_MACOSX | 38 #endif // OS_MACOSX |
39 } | 39 } |
40 | 40 |
41 GpuSwitchingManager::~GpuSwitchingManager() { | 41 GpuSwitchingManager::~GpuSwitchingManager() { |
42 #if defined(OS_MACOSX) | 42 #if defined(OS_MACOSX) |
43 if (platform_specific_->discrete_pixel_format) | 43 if (platform_specific_->discrete_pixel_format) |
44 CGLReleasePixelFormat(platform_specific_->discrete_pixel_format); | 44 CGLReleasePixelFormat(platform_specific_->discrete_pixel_format); |
45 #endif // OS_MACOSX | 45 #endif // OS_MACOSX |
46 } | 46 } |
47 | 47 |
48 void GpuSwitchingManager::ForceUseOfIntegratedGpu() { | 48 void GpuSwitchingManager::ForceUseOfIntegratedGpu() { |
49 DCHECK(SupportsDualGpus()); | 49 DCHECK(SupportsDualGpus()); |
50 if (gpu_switching_option_set_) { | 50 if (gpu_switching_option_set_) { |
51 DCHECK_EQ(gpu_switching_option_, gfx::PreferIntegratedGpu); | 51 DCHECK_EQ(gpu_switching_option_, gl::PreferIntegratedGpu); |
52 } else { | 52 } else { |
53 gpu_switching_option_ = gfx::PreferIntegratedGpu; | 53 gpu_switching_option_ = gl::PreferIntegratedGpu; |
54 gpu_switching_option_set_ = true; | 54 gpu_switching_option_set_ = true; |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 void GpuSwitchingManager::ForceUseOfDiscreteGpu() { | 58 void GpuSwitchingManager::ForceUseOfDiscreteGpu() { |
59 DCHECK(SupportsDualGpus()); | 59 DCHECK(SupportsDualGpus()); |
60 if (gpu_switching_option_set_) { | 60 if (gpu_switching_option_set_) { |
61 DCHECK_EQ(gpu_switching_option_, gfx::PreferDiscreteGpu); | 61 DCHECK_EQ(gpu_switching_option_, gl::PreferDiscreteGpu); |
62 } else { | 62 } else { |
63 gpu_switching_option_ = gfx::PreferDiscreteGpu; | 63 gpu_switching_option_ = gl::PreferDiscreteGpu; |
64 gpu_switching_option_set_ = true; | 64 gpu_switching_option_set_ = true; |
65 #if defined(OS_MACOSX) | 65 #if defined(OS_MACOSX) |
66 // Create a pixel format that lasts the lifespan of Chrome, so Chrome | 66 // Create a pixel format that lasts the lifespan of Chrome, so Chrome |
67 // stays on the discrete GPU. | 67 // stays on the discrete GPU. |
68 SwitchToDiscreteGpuMac(); | 68 SwitchToDiscreteGpuMac(); |
69 #endif // OS_MACOSX | 69 #endif // OS_MACOSX |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 bool GpuSwitchingManager::SupportsDualGpus() { | 73 bool GpuSwitchingManager::SupportsDualGpus() { |
(...skipping 12 matching lines...) Expand all Loading... |
86 } else { | 86 } else { |
87 NOTIMPLEMENTED(); | 87 NOTIMPLEMENTED(); |
88 } | 88 } |
89 } else { | 89 } else { |
90 // Browser process. | 90 // Browser process. |
91 // We only compute this flag in the browser process. | 91 // We only compute this flag in the browser process. |
92 #if defined(OS_MACOSX) | 92 #if defined(OS_MACOSX) |
93 flag = (vendor_ids_.size() == 2); | 93 flag = (vendor_ids_.size() == 2); |
94 if (flag && command_line.HasSwitch(switches::kUseGL) && | 94 if (flag && command_line.HasSwitch(switches::kUseGL) && |
95 command_line.GetSwitchValueASCII(switches::kUseGL) != | 95 command_line.GetSwitchValueASCII(switches::kUseGL) != |
96 gfx::kGLImplementationDesktopName) | 96 gl::kGLImplementationDesktopName) |
97 flag = false; | 97 flag = false; |
98 | 98 |
99 if (flag) { | 99 if (flag) { |
100 // Only advertise that we have two GPUs to the rest of | 100 // Only advertise that we have two GPUs to the rest of |
101 // Chrome's code if we find an Intel GPU and some other | 101 // Chrome's code if we find an Intel GPU and some other |
102 // vendor's GPU. Otherwise we don't understand the | 102 // vendor's GPU. Otherwise we don't understand the |
103 // configuration and don't deal well with it (an example being | 103 // configuration and don't deal well with it (an example being |
104 // the dual AMD GPUs in recent Mac Pros). | 104 // the dual AMD GPUs in recent Mac Pros). |
105 const uint32_t intel = 0x8086; | 105 const uint32_t intel = 0x8086; |
106 flag = ((vendor_ids_[0] == intel && vendor_ids_[1] != intel) || | 106 flag = ((vendor_ids_[0] == intel && vendor_ids_[1] != intel) || |
(...skipping 17 matching lines...) Expand all Loading... |
124 } | 124 } |
125 | 125 |
126 void GpuSwitchingManager::RemoveObserver(GpuSwitchingObserver* observer) { | 126 void GpuSwitchingManager::RemoveObserver(GpuSwitchingObserver* observer) { |
127 observer_list_.RemoveObserver(observer); | 127 observer_list_.RemoveObserver(observer); |
128 } | 128 } |
129 | 129 |
130 void GpuSwitchingManager::NotifyGpuSwitched() { | 130 void GpuSwitchingManager::NotifyGpuSwitched() { |
131 FOR_EACH_OBSERVER(GpuSwitchingObserver, observer_list_, OnGpuSwitched()); | 131 FOR_EACH_OBSERVER(GpuSwitchingObserver, observer_list_, OnGpuSwitched()); |
132 } | 132 } |
133 | 133 |
134 gfx::GpuPreference GpuSwitchingManager::AdjustGpuPreference( | 134 gl::GpuPreference GpuSwitchingManager::AdjustGpuPreference( |
135 gfx::GpuPreference gpu_preference) { | 135 gl::GpuPreference gpu_preference) { |
136 if (!gpu_switching_option_set_) | 136 if (!gpu_switching_option_set_) |
137 return gpu_preference; | 137 return gpu_preference; |
138 return gpu_switching_option_; | 138 return gpu_switching_option_; |
139 } | 139 } |
140 | 140 |
141 #if defined(OS_MACOSX) | 141 #if defined(OS_MACOSX) |
142 void GpuSwitchingManager::SwitchToDiscreteGpuMac() { | 142 void GpuSwitchingManager::SwitchToDiscreteGpuMac() { |
143 if (platform_specific_->discrete_pixel_format) | 143 if (platform_specific_->discrete_pixel_format) |
144 return; | 144 return; |
145 CGLPixelFormatAttribute attribs[1]; | 145 CGLPixelFormatAttribute attribs[1]; |
146 attribs[0] = static_cast<CGLPixelFormatAttribute>(0); | 146 attribs[0] = static_cast<CGLPixelFormatAttribute>(0); |
147 GLint num_pixel_formats = 0; | 147 GLint num_pixel_formats = 0; |
148 CGLChoosePixelFormat(attribs, &platform_specific_->discrete_pixel_format, | 148 CGLChoosePixelFormat(attribs, &platform_specific_->discrete_pixel_format, |
149 &num_pixel_formats); | 149 &num_pixel_formats); |
150 } | 150 } |
151 #endif // OS_MACOSX | 151 #endif // OS_MACOSX |
152 | 152 |
153 } // namespace ui | 153 } // namespace ui |
OLD | NEW |