diff --git a/gfx/webrender_bindings/RenderCompositor.h b/gfx/webrender_bindings/RenderCompositor.h index 38072ccbd0c0..872512e523c4 100644 --- a/gfx/webrender_bindings/RenderCompositor.h +++ b/gfx/webrender_bindings/RenderCompositor.h @@ -19,7 +19,6 @@ class GLContext; } namespace layers { -class NativeLayer; class SyncObjectHost; } // namespace layers @@ -37,7 +36,7 @@ class RenderCompositor { RenderCompositor(RefPtr&& aWidget); virtual ~RenderCompositor(); - virtual bool BeginFrame(layers::NativeLayer* aNativeLayer) = 0; + virtual bool BeginFrame() = 0; virtual void EndFrame() = 0; // Returns false when waiting gpu tasks is failed. // It might happen when rendering context is lost. diff --git a/gfx/webrender_bindings/RenderCompositorANGLE.cpp b/gfx/webrender_bindings/RenderCompositorANGLE.cpp index 1068feba0861..b2df8dd4ad86 100644 --- a/gfx/webrender_bindings/RenderCompositorANGLE.cpp +++ b/gfx/webrender_bindings/RenderCompositorANGLE.cpp @@ -349,8 +349,7 @@ RefPtr RenderCompositorANGLE::CreateSwapChainForDComp( return nullptr; } -bool RenderCompositorANGLE::BeginFrame(layers::NativeLayer* aNativeLayer) { - MOZ_RELEASE_ASSERT(!aNativeLayer, "Unexpected native layer on this platform"); +bool RenderCompositorANGLE::BeginFrame() { mWidget->AsWindows()->UpdateCompositorWndSizeIfNecessary(); if (mDCLayerTree) { diff --git a/gfx/webrender_bindings/RenderCompositorANGLE.h b/gfx/webrender_bindings/RenderCompositorANGLE.h index 96863da89728..092b3f8e1138 100644 --- a/gfx/webrender_bindings/RenderCompositorANGLE.h +++ b/gfx/webrender_bindings/RenderCompositorANGLE.h @@ -39,7 +39,7 @@ class RenderCompositorANGLE : public RenderCompositor { virtual ~RenderCompositorANGLE(); bool Initialize(); - bool BeginFrame(layers::NativeLayer* aNativeLayer) override; + bool BeginFrame() override; void EndFrame() override; bool WaitForGPU() override; void Pause() override; diff --git a/gfx/webrender_bindings/RenderCompositorEGL.cpp b/gfx/webrender_bindings/RenderCompositorEGL.cpp index 6ce675d07c90..e105e115df92 100644 --- a/gfx/webrender_bindings/RenderCompositorEGL.cpp +++ b/gfx/webrender_bindings/RenderCompositorEGL.cpp @@ -63,8 +63,7 @@ RenderCompositorEGL::~RenderCompositorEGL() { DestroyEGLSurface(); } -bool RenderCompositorEGL::BeginFrame(layers::NativeLayer* aNativeLayer) { - MOZ_RELEASE_ASSERT(!aNativeLayer, "Unexpected native layer on this platform"); +bool RenderCompositorEGL::BeginFrame() { #ifdef MOZ_WAYLAND bool newSurface = mWidget->AsX11() && mWidget->AsX11()->WaylandRequestsUpdatingEGLSurface(); diff --git a/gfx/webrender_bindings/RenderCompositorEGL.h b/gfx/webrender_bindings/RenderCompositorEGL.h index 6aa9c2582bc2..6d551c64389c 100644 --- a/gfx/webrender_bindings/RenderCompositorEGL.h +++ b/gfx/webrender_bindings/RenderCompositorEGL.h @@ -22,7 +22,7 @@ class RenderCompositorEGL : public RenderCompositor { explicit RenderCompositorEGL(RefPtr aWidget); virtual ~RenderCompositorEGL(); - bool BeginFrame(layers::NativeLayer* aNativeLayer) override; + bool BeginFrame() override; void EndFrame() override; void Pause() override; bool Resume() override; diff --git a/gfx/webrender_bindings/RenderCompositorOGL.cpp b/gfx/webrender_bindings/RenderCompositorOGL.cpp index 67f0eb8b7f5a..f1c671527bb9 100644 --- a/gfx/webrender_bindings/RenderCompositorOGL.cpp +++ b/gfx/webrender_bindings/RenderCompositorOGL.cpp @@ -32,12 +32,28 @@ RenderCompositorOGL::RenderCompositorOGL( RefPtr&& aGL, RefPtr&& aWidget) : RenderCompositor(std::move(aWidget)), mGL(aGL), + mNativeLayerRoot(GetWidget()->GetNativeLayerRoot()), mPreviousFrameDoneSync(nullptr), mThisFrameDoneSync(nullptr) { MOZ_ASSERT(mGL); + + if (mNativeLayerRoot) { + mNativeLayerForEntireWindow = mNativeLayerRoot->CreateLayer(); + mNativeLayerForEntireWindow->SetSurfaceIsFlipped(true); + mNativeLayerForEntireWindow->SetGLContext(mGL); + mNativeLayerRoot->AppendLayer(mNativeLayerForEntireWindow); + } } RenderCompositorOGL::~RenderCompositorOGL() { + if (mNativeLayerRoot) { + if (mNativeLayerForEntireWindow) { + mNativeLayerRoot->RemoveLayer(mNativeLayerForEntireWindow); + mNativeLayerForEntireWindow = nullptr; + } + mNativeLayerRoot = nullptr; + } + if (!mGL->MakeCurrent()) { gfxCriticalNote << "Failed to make render context current during destroying."; @@ -55,21 +71,21 @@ RenderCompositorOGL::~RenderCompositorOGL() { } } -bool RenderCompositorOGL::BeginFrame(layers::NativeLayer* aNativeLayer) { +bool RenderCompositorOGL::BeginFrame() { if (!mGL->MakeCurrent()) { gfxCriticalNote << "Failed to make render context current, can't draw."; return false; } - if (aNativeLayer) { - aNativeLayer->SetSurfaceIsFlipped(true); - aNativeLayer->SetGLContext(mGL); - Maybe fbo = aNativeLayer->NextSurfaceAsFramebuffer(true); + if (mNativeLayerForEntireWindow) { + gfx::IntRect bounds({}, GetBufferSize().ToUnknownSize()); + mNativeLayerForEntireWindow->SetRect(bounds); + Maybe fbo = + mNativeLayerForEntireWindow->NextSurfaceAsFramebuffer(true); if (!fbo) { return false; } mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, *fbo); - mCurrentNativeLayer = aNativeLayer; } else { mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mGL->GetDefaultFramebuffer()); } @@ -81,9 +97,8 @@ void RenderCompositorOGL::EndFrame() { InsertFrameDoneSync(); mGL->SwapBuffers(); - if (mCurrentNativeLayer) { - mCurrentNativeLayer->NotifySurfaceReady(); - mCurrentNativeLayer = nullptr; + if (mNativeLayerForEntireWindow) { + mNativeLayerForEntireWindow->NotifySurfaceReady(); } } diff --git a/gfx/webrender_bindings/RenderCompositorOGL.h b/gfx/webrender_bindings/RenderCompositorOGL.h index f5c0787f2508..d1a2eba7acfb 100644 --- a/gfx/webrender_bindings/RenderCompositorOGL.h +++ b/gfx/webrender_bindings/RenderCompositorOGL.h @@ -11,6 +11,11 @@ namespace mozilla { +namespace layers { +class NativeLayerRoot; +class NativeLayer; +} // namespace layers + namespace wr { class RenderCompositorOGL : public RenderCompositor { @@ -22,7 +27,7 @@ class RenderCompositorOGL : public RenderCompositor { RefPtr&& aWidget); virtual ~RenderCompositorOGL(); - bool BeginFrame(layers::NativeLayer* aNativeLayer) override; + bool BeginFrame() override; void EndFrame() override; bool WaitForGPU() override; void Pause() override; @@ -39,10 +44,9 @@ class RenderCompositorOGL : public RenderCompositor { RefPtr mGL; - // The native layer that we're currently rendering to, if any. - // Non-null only between BeginFrame and EndFrame if BeginFrame has been called - // with a non-null aNativeLayer. - RefPtr mCurrentNativeLayer; + // Can be null. + RefPtr mNativeLayerRoot; + RefPtr mNativeLayerForEntireWindow; // Used to apply back-pressure in WaitForGPU(). GLsync mPreviousFrameDoneSync; diff --git a/gfx/webrender_bindings/RendererOGL.cpp b/gfx/webrender_bindings/RendererOGL.cpp index 85ee75531ec5..d7a65d6f6a81 100644 --- a/gfx/webrender_bindings/RendererOGL.cpp +++ b/gfx/webrender_bindings/RendererOGL.cpp @@ -58,12 +58,6 @@ RendererOGL::RendererOGL(RefPtr&& aThread, MOZ_ASSERT(mRenderer); MOZ_ASSERT(mBridge); MOZ_COUNT_CTOR(RendererOGL); - - mNativeLayerRoot = mCompositor->GetWidget()->GetNativeLayerRoot(); - if (mNativeLayerRoot) { - mNativeLayerForEntireWindow = mNativeLayerRoot->CreateLayer(); - mNativeLayerRoot->AppendLayer(mNativeLayerForEntireWindow); - } } RendererOGL::~RendererOGL() { @@ -74,11 +68,6 @@ RendererOGL::~RendererOGL() { // Leak resources! return; } - if (mNativeLayerRoot) { - mNativeLayerRoot->RemoveLayer(mNativeLayerForEntireWindow); - mNativeLayerForEntireWindow = nullptr; - mNativeLayerRoot = nullptr; - } wr_renderer_delete(mRenderer); } @@ -120,12 +109,7 @@ bool RendererOGL::UpdateAndRender(const Maybe& aReadbackSize, } // XXX set clear color if MOZ_WIDGET_ANDROID is defined. - if (mNativeLayerForEntireWindow) { - gfx::IntRect bounds({}, mCompositor->GetBufferSize().ToUnknownSize()); - mNativeLayerForEntireWindow->SetRect(bounds); - } - - if (!mCompositor->BeginFrame(mNativeLayerForEntireWindow)) { + if (!mCompositor->BeginFrame()) { if (mCompositor->IsContextLost()) { RenderThread::Get()->HandleDeviceReset("BeginFrame", /* aNotify */ true); } diff --git a/gfx/webrender_bindings/RendererOGL.h b/gfx/webrender_bindings/RendererOGL.h index 3bf829d8d22a..3087130b64ea 100644 --- a/gfx/webrender_bindings/RendererOGL.h +++ b/gfx/webrender_bindings/RendererOGL.h @@ -26,8 +26,6 @@ class GLContext; namespace layers { class CompositorBridgeParent; -class NativeLayerRoot; -class NativeLayer; class SyncObjectHost; } // namespace layers @@ -108,8 +106,6 @@ class RendererOGL { protected: RefPtr mThread; UniquePtr mCompositor; - RefPtr mNativeLayerRoot; - RefPtr mNativeLayerForEntireWindow; wr::Renderer* mRenderer; layers::CompositorBridgeParent* mBridge; wr::WindowId mWindowId;