Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: ui/gl/gpu_switching_manager.cc

Issue 786123002: Update from https://crrev.com/307330 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gl/gpu_switching_manager.h ('k') | url/gurl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/gl/gl_switches.h" 9 #include "ui/gl/gl_switches.h"
10 10
11 #if defined(OS_MACOSX) 11 #if defined(OS_MACOSX)
12 #include <OpenGL/OpenGL.h>
12 #include "base/mac/mac_util.h" 13 #include "base/mac/mac_util.h"
13 #include "ui/gl/gl_context_cgl.h" 14 #include "ui/gl/gl_context_cgl.h"
14 #endif // OS_MACOSX 15 #endif // OS_MACOSX
15 16
16 namespace ui { 17 namespace ui {
17 18
19 struct GpuSwitchingManager::PlatformSpecific {
20 #if defined(OS_MACOSX)
21 CGLPixelFormatObj discrete_pixel_format;
22 #endif // OS_MACOSX
23 };
24
18 // static 25 // static
19 GpuSwitchingManager* GpuSwitchingManager::GetInstance() { 26 GpuSwitchingManager* GpuSwitchingManager::GetInstance() {
20 return Singleton<GpuSwitchingManager>::get(); 27 return Singleton<GpuSwitchingManager>::get();
21 } 28 }
22 29
23 GpuSwitchingManager::GpuSwitchingManager() 30 GpuSwitchingManager::GpuSwitchingManager()
24 : gpu_switching_option_(gfx::PreferIntegratedGpu), 31 : gpu_switching_option_(gfx::PreferIntegratedGpu),
25 gpu_switching_option_set_(false), 32 gpu_switching_option_set_(false),
26 supports_dual_gpus_(false), 33 supports_dual_gpus_(false),
27 supports_dual_gpus_set_(false), 34 supports_dual_gpus_set_(false),
28 gpu_count_(0) { 35 gpu_count_(0),
36 platform_specific_(new PlatformSpecific) {
29 #if defined(OS_MACOSX) 37 #if defined(OS_MACOSX)
30 discrete_pixel_format_ = NULL; 38 platform_specific_->discrete_pixel_format = nullptr;
31 #endif // OS_MACOSX 39 #endif // OS_MACOSX
32 } 40 }
33 41
34 GpuSwitchingManager::~GpuSwitchingManager() { 42 GpuSwitchingManager::~GpuSwitchingManager() {
35 #if defined(OS_MACOSX) 43 #if defined(OS_MACOSX)
36 if (discrete_pixel_format_) 44 if (platform_specific_->discrete_pixel_format)
37 CGLReleasePixelFormat(discrete_pixel_format_); 45 CGLReleasePixelFormat(platform_specific_->discrete_pixel_format);
38 #endif // OS_MACOSX 46 #endif // OS_MACOSX
39 } 47 }
40 48
41 void GpuSwitchingManager::ForceUseOfIntegratedGpu() { 49 void GpuSwitchingManager::ForceUseOfIntegratedGpu() {
42 DCHECK(SupportsDualGpus()); 50 DCHECK(SupportsDualGpus());
43 if (gpu_switching_option_set_) { 51 if (gpu_switching_option_set_) {
44 DCHECK_EQ(gpu_switching_option_, gfx::PreferIntegratedGpu); 52 DCHECK_EQ(gpu_switching_option_, gfx::PreferIntegratedGpu);
45 } else { 53 } else {
46 gpu_switching_option_ = gfx::PreferIntegratedGpu; 54 gpu_switching_option_ = gfx::PreferIntegratedGpu;
47 gpu_switching_option_set_ = true; 55 gpu_switching_option_set_ = true;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 124
117 gfx::GpuPreference GpuSwitchingManager::AdjustGpuPreference( 125 gfx::GpuPreference GpuSwitchingManager::AdjustGpuPreference(
118 gfx::GpuPreference gpu_preference) { 126 gfx::GpuPreference gpu_preference) {
119 if (!gpu_switching_option_set_) 127 if (!gpu_switching_option_set_)
120 return gpu_preference; 128 return gpu_preference;
121 return gpu_switching_option_; 129 return gpu_switching_option_;
122 } 130 }
123 131
124 #if defined(OS_MACOSX) 132 #if defined(OS_MACOSX)
125 void GpuSwitchingManager::SwitchToDiscreteGpuMac() { 133 void GpuSwitchingManager::SwitchToDiscreteGpuMac() {
126 if (discrete_pixel_format_) 134 if (platform_specific_->discrete_pixel_format)
127 return; 135 return;
128 CGLPixelFormatAttribute attribs[1]; 136 CGLPixelFormatAttribute attribs[1];
129 attribs[0] = static_cast<CGLPixelFormatAttribute>(0); 137 attribs[0] = static_cast<CGLPixelFormatAttribute>(0);
130 GLint num_pixel_formats = 0; 138 GLint num_pixel_formats = 0;
131 CGLChoosePixelFormat(attribs, &discrete_pixel_format_, &num_pixel_formats); 139 CGLChoosePixelFormat(attribs, &platform_specific_->discrete_pixel_format,
140 &num_pixel_formats);
132 } 141 }
133 #endif // OS_MACOSX 142 #endif // OS_MACOSX
134 143
135 } // namespace ui 144 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gl/gpu_switching_manager.h ('k') | url/gurl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698