Commit 441e25cd authored by ccameron@chromium.org's avatar ccameron@chromium.org

Ensure that CAOpenGLLayer uses the dGPU when appropriate.

It is necessary that the context created by copyCGLContextForPixelFormat
have a pixel format compatible with the one created by
copyCGLPixelFormatForDisplayMask. In particular, make
copyCGLPixelFormatForDisplayMask create the CGL equivalent of the pixel
format created in CompositingIOSurfaceContext.

BUG=338925

Review URL: https://codereview.chromium.org/142413008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247925 0039d316-1c4b-4281-b951-d872f2087c98
parent 695d99e1
......@@ -14,6 +14,7 @@
#include "content/browser/renderer_host/compositing_iosurface_mac.h"
#include "ui/base/cocoa/animation_utils.h"
#include "ui/gfx/size_conversions.h"
#include "ui/gl/gpu_switching_manager.h"
@implementation CompositingIOSurfaceLayer
......@@ -62,13 +63,42 @@
// The remaining methods implement the CAOpenGLLayer interface.
- (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask {
std::vector<CGLPixelFormatAttribute> attribs;
attribs.push_back(kCGLPFADepthSize);
attribs.push_back(static_cast<CGLPixelFormatAttribute>(0));
if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) {
attribs.push_back(kCGLPFAAllowOfflineRenderers);
attribs.push_back(static_cast<CGLPixelFormatAttribute>(1));
}
attribs.push_back(static_cast<CGLPixelFormatAttribute>(0));
GLint number_virtual_screens = 0;
CGLPixelFormatObj pixel_format = NULL;
CGLError error = CGLChoosePixelFormat(
&attribs.front(), &pixel_format, &number_virtual_screens);
if (error != kCGLNoError) {
LOG(ERROR) << "Failed to create pixel format for layer.";
return nil;
}
return pixel_format;
}
- (void)releaseCGLPixelFormat:(CGLPixelFormatObj)pixelFormat {
CGLReleasePixelFormat(pixelFormat);
}
- (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
if (!renderWidgetHostView_)
if (!renderWidgetHostView_) {
LOG(ERROR) << "Cannot create layer context because there is no host.";
return nil;
}
context_ = renderWidgetHostView_->compositing_iosurface_context_;
if (!context_)
if (!context_) {
LOG(ERROR) << "Cannot create layer context because host has no context.";
return nil;
}
return context_->cgl_context();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment