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
--- 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);