Bug 886999 - Lock the GL context before compositing on the compositor thread or before calling setView or update on the main thread. r=mattwoodrow

--HG--
extra : rebase_source : 60930a858a5d52205703d14317312540387f269f
This commit is contained in:
Markus Stange 2013-10-09 10:39:23 -04:00
parent aa364be07d
commit cc60fe7720
5 changed files with 43 additions and 2 deletions

View File

@ -346,6 +346,7 @@ LayerManagerComposite::Render()
}
if (actualBounds.IsEmpty()) {
mCompositor->GetWidget()->PostRender(this);
return;
}
@ -375,6 +376,8 @@ LayerManagerComposite::Render()
PROFILER_LABEL("LayerManagerComposite", "EndFrame");
mCompositor->EndFrame();
}
mCompositor->GetWidget()->PostRender(this);
}
void

View File

@ -333,6 +333,7 @@ typedef NSInteger NSEventGestureAxis;
- (void)setGLContext:(NSOpenGLContext *)aGLContext;
- (bool)preRender:(NSOpenGLContext *)aGLContext;
- (void)postRender:(NSOpenGLContext *)aGLContext;
- (BOOL)isCoveringTitlebar;
@ -537,6 +538,7 @@ public:
virtual void PrepareWindowEffects() MOZ_OVERRIDE;
virtual void CleanupWindowEffects() MOZ_OVERRIDE;
virtual bool PreRender(LayerManager* aManager) MOZ_OVERRIDE;
virtual void PostRender(LayerManager* aManager) MOZ_OVERRIDE;
virtual void DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect) MOZ_OVERRIDE;
virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries);

View File

@ -2033,6 +2033,17 @@ nsChildView::PreRender(LayerManager* aManager)
return [(ChildView*)mView preRender:glContext];
}
void
nsChildView::PostRender(LayerManager* aManager)
{
nsAutoPtr<GLManager> manager(GLManager::CreateGLManager(aManager));
if (!manager) {
return;
}
NSOpenGLContext *glContext = (NSOpenGLContext *)manager->gl()->GetNativeData(GLContext::NativeGLContext);
[(ChildView*)mView postRender:glContext];
}
void
nsChildView::DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect)
{
@ -2438,6 +2449,8 @@ nsChildView::DoRemoteComposition(const nsIntRect& aRenderRect)
DrawWindowOverlay(mGLPresenter, aRenderRect);
mGLPresenter->EndFrame();
[(ChildView*)mView postRender:mGLPresenter->GetNSOpenGLContext()];
}
#ifdef ACCESSIBILITY
@ -2883,11 +2896,22 @@ NSEvent* gLastDragMouseDownEvent = nil;
[self updateGLContext];
}
CGLLockContext((CGLContextObj)[aGLContext CGLContextObj]);
return true;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
}
- (void)postRender:(NSOpenGLContext *)aGLContext
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
CGLUnlockContext((CGLContextObj)[aGLContext CGLContextObj]);
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (void)dealloc
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
@ -3220,8 +3244,10 @@ NSEvent* gLastDragMouseDownEvent = nil;
-(void)updateGLContext
{
if (mGLContext) {
CGLLockContext((CGLContextObj)[mGLContext CGLContextObj]);
[mGLContext setView:self];
[mGLContext update];
CGLUnlockContext((CGLContextObj)[mGLContext CGLContextObj]);
}
}

View File

@ -96,8 +96,8 @@ typedef void* nsNativeWidget;
#endif
#define NS_IWIDGET_IID \
{ 0x8e2afc1c, 0x7087, 0x4ec2, \
{ 0xac, 0xc6, 0xd4, 0xf2, 0x3e, 0x13, 0xd2, 0xb7 } }
{ 0xa1f684e6, 0x2ae1, 0x4513, \
{ 0xb6, 0x89, 0xf4, 0xd4, 0xfe, 0x9d, 0x2c, 0xdb } }
/*
* Window shadow styles
@ -1224,6 +1224,15 @@ class nsIWidget : public nsISupports {
*/
virtual bool PreRender(LayerManager* aManager) = 0;
/**
* Called after rendering using OpenGL. Not called when rendering was
* cancelled by a negative return value from PreRender.
*
* Always called from the compositing thread, which may be the main-thread if
* OMTC is not enabled.
*/
virtual void PostRender(LayerManager* aManager) = 0;
/**
* Called before the LayerManager draws the layer tree.
*

View File

@ -137,6 +137,7 @@ public:
virtual void PrepareWindowEffects() {}
virtual void CleanupWindowEffects() {}
virtual bool PreRender(LayerManager* aManager) { return true; }
virtual void PostRender(LayerManager* aManager) {}
virtual void DrawWindowUnderlay(LayerManager* aManager, nsIntRect aRect) {}
virtual void DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect) {}
virtual mozilla::TemporaryRef<mozilla::gfx::DrawTarget> StartRemoteDrawing();