Bug 1444432 - Add Compositor::GetWindowRenderTarget() and implement it for CompositorOGL. r?jrmuizel draft
authorMarkus Stange <mstange@themasta.com>
Wed, 28 Mar 2018 14:44:17 -0400
changeset 781550 4683c63356a434e5283e82a9b50d0410521ee264
parent 781549 744d10d9f0d774e92d7b4d994700793cb66a1f9f
child 781551 1d93f11cb34a7fa18eec3a7317d6261385602184
push id106334
push userbmo:mstange@themasta.com
push dateFri, 13 Apr 2018 04:36:02 +0000
reviewersjrmuizel
bugs1444432
milestone61.0a1
Bug 1444432 - Add Compositor::GetWindowRenderTarget() and implement it for CompositorOGL. r?jrmuizel MozReview-Commit-ID: d0vBM6g2pM
gfx/layers/Compositor.h
gfx/layers/opengl/CompositorOGL.cpp
gfx/layers/opengl/CompositorOGL.h
--- a/gfx/layers/Compositor.h
+++ b/gfx/layers/Compositor.h
@@ -298,16 +298,24 @@ public:
 
   /**
    * Returns the current target for rendering. Will return null if we are
    * rendering to the screen.
    */
   virtual CompositingRenderTarget* GetCurrentRenderTarget() const = 0;
 
   /**
+   * Returns a render target which contains the entire window's drawing.
+   * On platforms where no such render target is used during compositing (e.g.
+   * with buffered BasicCompositor, where only the invalid area is drawn to a
+   * render target), this will return null.
+   */
+  virtual CompositingRenderTarget* GetWindowRenderTarget() const { return nullptr; }
+
+  /**
    * Mostly the compositor will pull the size from a widget and this method will
    * be ignored, but compositor implementations are free to use it if they like.
    */
   virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) = 0;
 
   /**
    * Declare an offset to use when rendering layers. This will be ignored when
    * rendering to a target instead of the screen.
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -681,16 +681,22 @@ CompositorOGL::SetRenderTarget(Compositi
 }
 
 CompositingRenderTarget*
 CompositorOGL::GetCurrentRenderTarget() const
 {
   return mCurrentRenderTarget;
 }
 
+CompositingRenderTarget*
+CompositorOGL::GetWindowRenderTarget() const
+{
+  return mWindowRenderTarget;
+}
+
 already_AddRefed<AsyncReadbackBuffer>
 CompositorOGL::CreateAsyncReadbackBuffer(const IntSize& aSize)
 {
   return MakeAndAddRef<AsyncReadbackBufferOGL>(mGLContext, aSize);
 }
 
 bool
 CompositorOGL::ReadbackRenderTarget(CompositingRenderTarget* aSource,
@@ -815,20 +821,17 @@ CompositorOGL::BeginFrame(const nsIntReg
   mGLContext->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA,
                                  LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA);
   mGLContext->fEnable(LOCAL_GL_BLEND);
 
   RefPtr<CompositingRenderTargetOGL> rt =
     CompositingRenderTargetOGL::RenderTargetForWindow(this,
                                                       IntSize(width, height));
   SetRenderTarget(rt);
-
-#ifdef DEBUG
   mWindowRenderTarget = mCurrentRenderTarget;
-#endif
 
   if (aClipRectOut && !aClipRectIn) {
     aClipRectOut->SetRect(0, 0, width, height);
   }
 
   mGLContext->fClearColor(mClearColor.r, mClearColor.g, mClearColor.b, mClearColor.a);
   mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT);
 }
@@ -1751,21 +1754,23 @@ CompositorOGL::EndFrame()
   }
 #endif
 
   mFrameInProgress = false;
 
   if (mTarget) {
     CopyToTarget(mTarget, mTargetBounds.TopLeft(), Matrix());
     mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
+    mWindowRenderTarget = nullptr;
     mCurrentRenderTarget = nullptr;
     Compositor::EndFrame();
     return;
   }
 
+  mWindowRenderTarget = nullptr;
   mCurrentRenderTarget = nullptr;
 
   if (mTexturePool) {
     mTexturePool->EndFrame();
   }
 
   mGLContext->SwapBuffers();
   mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
--- a/gfx/layers/opengl/CompositorOGL.h
+++ b/gfx/layers/opengl/CompositorOGL.h
@@ -152,16 +152,17 @@ public:
 
   virtual already_AddRefed<CompositingRenderTarget>
   CreateRenderTargetFromSource(const gfx::IntRect &aRect,
                                const CompositingRenderTarget *aSource,
                                const gfx::IntPoint &aSourcePoint) override;
 
   virtual void SetRenderTarget(CompositingRenderTarget *aSurface) override;
   virtual CompositingRenderTarget* GetCurrentRenderTarget() const override;
+  virtual CompositingRenderTarget* GetWindowRenderTarget() const override;
 
   virtual bool
   ReadbackRenderTarget(CompositingRenderTarget* aSource,
                        AsyncReadbackBuffer* aDest) override;
 
   virtual already_AddRefed<AsyncReadbackBuffer>
   CreateAsyncReadbackBuffer(const gfx::IntSize& aSize) override;
 
@@ -285,19 +286,18 @@ private:
 
   already_AddRefed<mozilla::gl::GLContext> CreateContext();
 
   /** Texture target to use for FBOs */
   GLenum mFBOTextureTarget;
 
   /** Currently bound render target */
   RefPtr<CompositingRenderTargetOGL> mCurrentRenderTarget;
-#ifdef DEBUG
+
   CompositingRenderTargetOGL* mWindowRenderTarget;
-#endif
 
   /**
    * VBO that has some basics in it for a textured quad, including vertex
    * coords and texcoords.
    */
   GLuint mQuadVBO;