Index: ui/gl/gl_context_cgl.cc |
diff --git a/ui/gl/gl_context_cgl.cc b/ui/gl/gl_context_cgl.cc |
index 2a105c4983d0fb1ee86e2e75ccf5336afbde3b44..4b05c552a17d92bdb6962406c05308f216e7b764 100644 |
--- a/ui/gl/gl_context_cgl.cc |
+++ b/ui/gl/gl_context_cgl.cc |
@@ -114,17 +114,8 @@ bool GLContextCGL::Initialize(GLSurface* compatible_surface, |
// create the context. |
if (!ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus() || |
gpu_preference == PreferDiscreteGpu) { |
- std::vector<CGLPixelFormatAttribute> discrete_attribs; |
- discrete_attribs.push_back((CGLPixelFormatAttribute) 0); |
- GLint num_pixel_formats; |
- if (CGLChoosePixelFormat(&discrete_attribs.front(), |
- &discrete_pixelformat_, |
- &num_pixel_formats) != kCGLNoError) { |
- LOG(ERROR) << "Error choosing pixel format."; |
+ if (!AllocateDiscretePixelFormat()) |
return false; |
- } |
- // The renderer might be switched after this, so ignore the saved ID. |
- share_group()->SetRendererID(-1); |
} |
CGLError res = CGLCreateContext( |
@@ -147,6 +138,26 @@ bool GLContextCGL::Initialize(GLSurface* compatible_surface, |
return true; |
} |
+bool GLContextCGL::AllocateDiscretePixelFormat() { |
+ std::vector<CGLPixelFormatAttribute> discrete_attribs; |
+ discrete_attribs.push_back((CGLPixelFormatAttribute) 0); |
+ GLint num_pixel_formats; |
+ if (CGLChoosePixelFormat(&discrete_attribs.front(), |
+ &discrete_pixelformat_, |
+ &num_pixel_formats) != kCGLNoError) { |
+ LOG(ERROR) << "Error choosing discrete pixel format."; |
+ return false; |
+ } |
+ // The renderer might be switched after this, so ignore the saved ID. |
+ share_group()->SetRendererID(-1); |
+ return true; |
+} |
+ |
+void GLContextCGL::ReleaseDiscretePixelFormat() { |
+ CGLReleasePixelFormat(discrete_pixelformat_); |
+ discrete_pixelformat_ = nullptr; |
+} |
+ |
void GLContextCGL::Destroy() { |
if (yuv_to_rgb_converter_) { |
ScopedCGLSetCurrentContext(static_cast<CGLContextObj>(context_)); |
@@ -293,4 +304,14 @@ GpuPreference GLContextCGL::GetGpuPreference() { |
return gpu_preference_; |
} |
+void GLContextCGL::SetPerformancePreference(GpuPerformancePreference pref) { |
+ if (pref == PreferLowPower) { |
+ if (discrete_pixelformat_) |
+ ReleaseDiscretePixelFormat(); |
+ } else { |
+ if (gpu_preference_ == PreferDiscreteGpu && !discrete_pixelformat_) |
+ AllocateDiscretePixelFormat(); |
jbauman
2017/01/19 01:13:14
I'm not sure this would actually switch the contex
Ken Russell (switch to Gerrit)
2017/01/20 04:34:52
Thanks for tracking down that change. I'd remember
|
+ } |
+} |
+ |
} // namespace gl |