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

Unified Diff: ui/gl/gl_context_cgl.cc

Issue 2627323007: Migrate WebGL contexts on backgrounded tabs to the integrated GPU.
Patch Set: Created 3 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gl/gl_context_cgl.h ('k') | ui/gl/gpu_preference.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ui/gl/gl_context_cgl.h ('k') | ui/gl/gpu_preference.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698