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 781252 9a5bce31ebf7aa52a951d5e044f1230b692cf528
parent 781251 bb5ea4256f9ac31213d93a295e6cc44c9e8b3155
child 781253 a6446282ed99199cbb8a5b74d60a95ce0680a30c
push id106256
push userbmo:mstange@themasta.com
push dateThu, 12 Apr 2018 19:45:55 +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
@@ -674,16 +674,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,
@@ -808,20 +814,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);
 }
@@ -1744,21 +1747,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;