summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/compositing_iosurface_layer_mac.mm
diff options
context:
space:
mode:
authorccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-06 13:47:49 +0000
committerccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-06 13:47:49 +0000
commit33c7c434d70e198db9185dc64a7510f3b9b77f78 (patch)
treed10912f2ea739b1e346c82ba85094c3f1029ad96 /content/browser/renderer_host/compositing_iosurface_layer_mac.mm
parente95b717f6d7ebfd44ab20c2caea205cc95e0a74e (diff)
downloadchromium_src-33c7c434d70e198db9185dc64a7510f3b9b77f78.zip
chromium_src-33c7c434d70e198db9185dc64a7510f3b9b77f78.tar.gz
chromium_src-33c7c434d70e198db9185dc64a7510f3b9b77f78.tar.bz2
Back CAOpenGLLayers by CGL contexts instead of NSGL contexts
Change CompositingIOSurfaceContext to have a separate path for creating a CGLContextObj directly, rather than creating a NSOpenGLContext and using its CGLContextObj. Add asserts to prevent trying to grab the NSOpenGLContext when using CoreAnimation. Change the CAOpenGLLayer to create the CGLContextObj at creation, and pass a retained pointer to it and its pixel format when requested, and allow the superclass to handle the release of the pixel format and context. This matches the behavior in WebKit. Change DisplayLinkMac to call CVDisplayLinkRelease instead of CFRelease because here is no documentation that CFRelease may be used with a CVDisplayLink. BUG=245900 Review URL: https://codereview.chromium.org/131453012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249398 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/renderer_host/compositing_iosurface_layer_mac.mm')
-rw-r--r--content/browser/renderer_host/compositing_iosurface_layer_mac.mm68
1 files changed, 13 insertions, 55 deletions
diff --git a/content/browser/renderer_host/compositing_iosurface_layer_mac.mm b/content/browser/renderer_host/compositing_iosurface_layer_mac.mm
index 7417e29..b05ffe2 100644
--- a/content/browser/renderer_host/compositing_iosurface_layer_mac.mm
+++ b/content/browser/renderer_host/compositing_iosurface_layer_mac.mm
@@ -23,6 +23,9 @@
- (id)initWithRenderWidgetHostViewMac:(content::RenderWidgetHostViewMac*)r {
if (self = [super init]) {
renderWidgetHostView_ = r;
+ context_ = content::CompositingIOSurfaceContext::Get(
+ content::CompositingIOSurfaceContext::kOffscreenContextWindowNumber);
+ DCHECK(context_);
ScopedCAActionDisabler disabler;
[self setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
@@ -64,60 +67,15 @@
// 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.";
- CHECK(0);
- return nil;
- }
- return pixel_format;
-}
-
-- (void)releaseCGLPixelFormat:(CGLPixelFormatObj)pixelFormat {
- if (!pixelFormat) {
- CHECK(0);
- }
-
- CGLReleasePixelFormat(pixelFormat);
+ if (!context_)
+ return [super copyCGLPixelFormatForDisplayMask:mask];
+ return CGLRetainPixelFormat(CGLGetPixelFormat(context_->cgl_context()));
}
- (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat {
- if (!renderWidgetHostView_) {
- CHECK(0);
- LOG(ERROR) << "Cannot create layer context because there is no host.";
- return nil;
- }
-
- context_ = renderWidgetHostView_->compositing_iosurface_context_;
- if (!context_) {
- CHECK(0);
- LOG(ERROR) << "Cannot create layer context because host has no context.";
- return nil;
- }
-
- return context_->cgl_context();
-}
-
-- (void)releaseCGLContext:(CGLContextObj)glContext {
- if (!context_) {
- CHECK(0);
- return;
- }
-
- DCHECK(glContext == context_->cgl_context());
- context_ = nil;
+ if (!context_)
+ return [super copyCGLContextForPixelFormat:pixelFormat];
+ return CGLRetainContext(context_->cgl_context());
}
- (void)drawInCGLContext:(CGLContextObj)glContext
@@ -126,15 +84,15 @@
displayTime:(const CVTimeStamp*)timeStamp {
TRACE_EVENT0("browser", "CompositingIOSurfaceLayer::drawInCGLContext");
- if (!context_.get() || !renderWidgetHostView_ ||
+ if (!context_ ||
+ (context_ && context_->cgl_context() != glContext) ||
+ !renderWidgetHostView_ ||
!renderWidgetHostView_->compositing_iosurface_) {
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
return;
}
- DCHECK(glContext == context_->cgl_context());
-
// Cache a copy of renderWidgetHostView_ because it may be reset if
// a software frame is received in GetBackingStore.
content::RenderWidgetHostViewMac* cached_view = renderWidgetHostView_;
@@ -147,6 +105,7 @@
cached_view->about_to_validate_and_paint_ = true;
(void)cached_view->render_widget_host_->GetBackingStore(true);
cached_view->about_to_validate_and_paint_ = false;
+ CGLSetCurrentContext(glContext);
}
// If a transition to software mode has occurred, this layer should be
@@ -159,7 +118,6 @@
if ([self respondsToSelector:(@selector(contentsScale))])
window_scale_factor = [self contentsScale];
- CGLSetCurrentContext(glContext);
if (!renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(
context_,
window_rect,