From 3d089001af1749a46325423854bff82937cb76aa Mon Sep 17 00:00:00 2001 From: "ccameron@chromium.org" Date: Tue, 23 Apr 2013 10:47:00 +0000 Subject: Never bind two NSOpenGLContexts to an NSView Binding two NSOpenGLContexts to an NSView will cause corruption and crashes when one of the contexts is destroyed. Call clearDrawable before changing the underlying context of a CompositingIOSurface. Note that the NSView owns the CompositingIOSurface, so there is no risk of "some other" NSOpenGLContext being bound to the NSView. BUG=230883 Review URL: https://chromiumcodereview.appspot.com/14092005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195772 0039d316-1c4b-4281-b951-d872f2087c98 --- content/browser/renderer_host/compositing_iosurface_mac.h | 2 +- content/browser/renderer_host/compositing_iosurface_mac.mm | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/content/browser/renderer_host/compositing_iosurface_mac.h b/content/browser/renderer_host/compositing_iosurface_mac.h index f5bf62e..b6f734b 100644 --- a/content/browser/renderer_host/compositing_iosurface_mac.h +++ b/content/browser/renderer_host/compositing_iosurface_mac.h @@ -228,7 +228,7 @@ class CompositingIOSurfaceMac { // If this IOSurface has moved to a different window, use that window's // GL context (if multiple visible windows are using the same GL context // then call to setView call can stall and prevent reaching 60fps). - void SwitchToContextOnNewWindow(int window_number); + void SwitchToContextOnNewWindow(NSView* view, int window_number); bool IsVendorIntel(); diff --git a/content/browser/renderer_host/compositing_iosurface_mac.mm b/content/browser/renderer_host/compositing_iosurface_mac.mm index f000456..915868d 100644 --- a/content/browser/renderer_host/compositing_iosurface_mac.mm +++ b/content/browser/renderer_host/compositing_iosurface_mac.mm @@ -292,7 +292,8 @@ CompositingIOSurfaceMac::CompositingIOSurfaceMac( StopDisplayLink(); } -void CompositingIOSurfaceMac::SwitchToContextOnNewWindow(int window_number) { +void CompositingIOSurfaceMac::SwitchToContextOnNewWindow( + NSView* view, int window_number) { if (window_number == context_->window_number()) return; @@ -313,6 +314,13 @@ void CompositingIOSurfaceMac::SwitchToContextOnNewWindow(int window_number) { if (!new_context) return; + // Having two NSOpenGLContexts bound to an NSView concurrently will cause + // artifacts and crashes. If |context_| is bound to |view|, then unbind + // |context_| before |new_context| gets bound to |view|. + // http://crbug.com/230883 + if ([context_->nsgl_context() view] == view) + [context_->nsgl_context() clearDrawable]; + context_ = new_context; } @@ -361,7 +369,7 @@ void CompositingIOSurfaceMac::DrawIOSurface( float scale_factor, int window_number, RenderWidgetHostViewFrameSubscriber* frame_subscriber) { - SwitchToContextOnNewWindow(window_number); + SwitchToContextOnNewWindow(view, window_number); CGLSetCurrentContext(context_->cgl_context()); -- cgit v1.1