Bug 1444432 - Create a currently-unimplemented abstraction called AsyncReadbackBuffer for the Compositor abstraction, and add a few more Compositor methods to aid in screenshotting. r?jrmuizel draft
authorMarkus Stange <mstange@themasta.com>
Mon, 26 Mar 2018 23:16:19 -0400
changeset 773409 0e2fc4198dad0ee2511c05fd201fe0f4d6689031
parent 773408 f6bcb9324d9213bc1fc01cab01b364a2739db9e8
child 773410 69e4826b88250710e9f5b645b88d4c985eb00ec1
push id104226
push userbmo:mstange@themasta.com
push dateTue, 27 Mar 2018 21:59:38 +0000
reviewersjrmuizel
bugs1444432
milestone61.0a1
Bug 1444432 - Create a currently-unimplemented abstraction called AsyncReadbackBuffer for the Compositor abstraction, and add a few more Compositor methods to aid in screenshotting. r?jrmuizel MozReview-Commit-ID: Jx1RFFoKypz
gfx/layers/Compositor.h
--- a/gfx/layers/Compositor.h
+++ b/gfx/layers/Compositor.h
@@ -130,16 +130,17 @@ class DataTextureSource;
 class CompositingRenderTarget;
 class CompositorBridgeParent;
 class LayerManagerComposite;
 class CompositorOGL;
 class CompositorD3D11;
 class BasicCompositor;
 class TextureReadLock;
 struct GPUStats;
+class AsyncReadbackBuffer;
 
 enum SurfaceInitMode
 {
   INIT_MODE_NONE,
   INIT_MODE_CLEAR
 };
 
 /**
@@ -258,16 +259,43 @@ public:
    * aSourcePoint specifies the point in aSource to copy data from.
    */
   virtual already_AddRefed<CompositingRenderTarget>
   CreateRenderTargetFromSource(const gfx::IntRect& aRect,
                                const CompositingRenderTarget* aSource,
                                const gfx::IntPoint& aSourcePoint) = 0;
 
   /**
+   * Request an asynchronous read from aSource into aDest.
+   * The pixels from aSourceRect end up in aDest at
+   * IntRect(IntPoint(0, 0), aSourceRect.Size()).
+   * Returns whether the operation was successful.
+   */
+  virtual bool
+  ReadbackRenderTarget(CompositingRenderTarget* aSource,
+                       const gfx::IntRect& aSourceRect,
+                       AsyncReadbackBuffer* aDest) { return false; }
+
+  /**
+   * Create an AsyncReadbackBuffer of the specified size. Can return null.
+   */
+  virtual already_AddRefed<AsyncReadbackBuffer>
+  CreateAsyncReadbackBuffer(const gfx::IntSize& aSize) { return nullptr; }
+
+  /**
+   * Draw a part of aSource into the current render target.
+   * Scaling is done with linear filtering.
+   * Returns whether the operation was successful.
+   */
+  virtual bool
+  BlitFromRenderTarget(CompositingRenderTarget* aSource,
+                       const gfx::IntSize& aSourceSize,
+                       const gfx::IntSize& aDestSize) { return false; }
+
+  /**
    * Sets the given surface as the target for subsequent calls to DrawQuad.
    * Passing null as aSurface sets the screen as the target.
    */
   virtual void SetRenderTarget(CompositingRenderTarget* aSurface) = 0;
 
   /**
    * Returns the current target for rendering. Will return null if we are
    * rendering to the screen.
@@ -620,16 +648,32 @@ BlendOpIsMixBlendMode(gfx::CompositionOp
   case gfx::CompositionOp::OP_COLOR:
   case gfx::CompositionOp::OP_LUMINOSITY:
     return true;
   default:
     return false;
   }
 }
 
+class AsyncReadbackBuffer
+{
+public:
+  NS_INLINE_DECL_REFCOUNTING(AsyncReadbackBuffer)
+
+  gfx::IntSize GetSize() const { return mSize; }
+  virtual bool MapAndCopyInto(gfx::DataSourceSurface* aSurface,
+                              const gfx::IntSize& aReadSize) const=0;
+
+protected:
+  AsyncReadbackBuffer(const gfx::IntSize& aSize) : mSize(aSize) {}
+  virtual ~AsyncReadbackBuffer() {}
+
+  gfx::IntSize mSize;
+};
+
 struct TexturedVertex
 {
   float position[2];
   float texCoords[2];
 };
 
 nsTArray<TexturedVertex>
 TexturedTrianglesToVertexArray(const nsTArray<gfx::TexturedTriangle>& aTriangles);