aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/gpu/GrContext.h62
-rw-r--r--include/gpu/GrProcessorUnitTest.h6
-rw-r--r--include/gpu/GrSurface.h100
3 files changed, 165 insertions, 3 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 0987d96b2e..ccd27286c7 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -246,6 +246,68 @@ public:
*/
void flush();
+ /**
+ * These flags can be used with the read/write pixels functions below.
+ */
+ enum PixelOpsFlags {
+ /** The GrContext will not be flushed before the surface read or write. This means that
+ the read or write may occur before previous draws have executed. */
+ kDontFlush_PixelOpsFlag = 0x1,
+ /** Any surface writes should be flushed to the backend 3D API after the surface operation
+ is complete */
+ kFlushWrites_PixelOp = 0x2,
+ /** The src for write or dst read is unpremultiplied. This is only respected if both the
+ config src and dst configs are an RGBA/BGRA 8888 format. */
+ kUnpremul_PixelOpsFlag = 0x4,
+ };
+
+ /**
+ * Reads a rectangle of pixels from a surface.
+ * @param surface the surface to read from.
+ * @param srcColorSpace color space of the surface
+ * @param left left edge of the rectangle to read (inclusive)
+ * @param top top edge of the rectangle to read (inclusive)
+ * @param width width of rectangle to read in pixels.
+ * @param height height of rectangle to read in pixels.
+ * @param config the pixel config of the destination buffer
+ * @param dstColorSpace color space of the destination buffer
+ * @param buffer memory to read the rectangle into.
+ * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
+ * packed.
+ * @param pixelOpsFlags see PixelOpsFlags enum above.
+ *
+ * @return true if the read succeeded, false if not. The read can fail because of an unsupported
+ * pixel configs
+ */
+ bool readSurfacePixels(GrSurface* surface, SkColorSpace* srcColorSpace,
+ int left, int top, int width, int height,
+ GrPixelConfig config, SkColorSpace* dstColorSpace, void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0);
+
+ /**
+ * Writes a rectangle of pixels to a surface.
+ * @param surface the surface to write to.
+ * @param dstColorSpace color space of the surface
+ * @param left left edge of the rectangle to write (inclusive)
+ * @param top top edge of the rectangle to write (inclusive)
+ * @param width width of rectangle to write in pixels.
+ * @param height height of rectangle to write in pixels.
+ * @param config the pixel config of the source buffer
+ * @param srcColorSpace color space of the source buffer
+ * @param buffer memory to read pixels from
+ * @param rowBytes number of bytes between consecutive rows. Zero
+ * means rows are tightly packed.
+ * @param pixelOpsFlags see PixelOpsFlags enum above.
+ * @return true if the write succeeded, false if not. The write can fail because of an
+ * unsupported combination of surface and src configs.
+ */
+ bool writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpace,
+ int left, int top, int width, int height,
+ GrPixelConfig config, SkColorSpace* srcColorSpace, const void* buffer,
+ size_t rowBytes,
+ uint32_t pixelOpsFlags = 0);
+
/**
* An ID associated with this context, guaranteed to be unique.
*/
diff --git a/include/gpu/GrProcessorUnitTest.h b/include/gpu/GrProcessorUnitTest.h
index d6269c85bd..912e393ca0 100644
--- a/include/gpu/GrProcessorUnitTest.h
+++ b/include/gpu/GrProcessorUnitTest.h
@@ -49,12 +49,12 @@ struct GrProcessorTestData {
GrProcessorTestData(SkRandom* random,
GrContext* context,
const GrRenderTargetContext* renderTargetContext,
- sk_sp<GrTextureProxy> proxies[2])
+ GrTexture* const textures[2])
: fRandom(random)
, fRenderTargetContext(renderTargetContext)
, fContext(context) {
- fProxies[0] = proxies[0];
- fProxies[1] = proxies[1];
+ fProxies[0] = GrSurfaceProxy::MakeWrapped(sk_ref_sp(textures[0]));
+ fProxies[1] = GrSurfaceProxy::MakeWrapped(sk_ref_sp(textures[1]));
}
SkRandom* fRandom;
const GrRenderTargetContext* fRenderTargetContext;
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h
index 81bc215c01..328731c38f 100644
--- a/include/gpu/GrSurface.h
+++ b/include/gpu/GrSurface.h
@@ -66,6 +66,106 @@ public:
virtual GrRenderTarget* asRenderTarget() { return NULL; }
virtual const GrRenderTarget* asRenderTarget() const { return NULL; }
+ /**
+ * Reads a rectangle of pixels from the surface, possibly performing color space conversion.
+ * @param srcColorSpace color space of the source data (this surface)
+ * @param left left edge of the rectangle to read (inclusive)
+ * @param top top edge of the rectangle to read (inclusive)
+ * @param width width of rectangle to read in pixels.
+ * @param height height of rectangle to read in pixels.
+ * @param config the pixel config of the destination buffer
+ * @param dstColorSpace color space of the destination buffer
+ * @param buffer memory to read the rectangle into.
+ * @param rowBytes number of bytes between consecutive rows. Zero means rows are tightly
+ * packed.
+ * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
+ *
+ * @return true if the read succeeded, false if not. The read can fail because of an unsupported
+ * pixel config.
+ */
+ bool readPixels(SkColorSpace* srcColorSpace,
+ int left, int top, int width, int height,
+ GrPixelConfig config,
+ SkColorSpace* dstColorSpace,
+ void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0);
+
+ /**
+ * Reads a rectangle of pixels from the surface. Does not perform any color space conversion.
+ * @param left left edge of the rectangle to read (inclusive)
+ * @param top top edge of the rectangle to read (inclusive)
+ * @param width width of rectangle to read in pixels.
+ * @param height height of rectangle to read in pixels.
+ * @param config the pixel config of the destination buffer
+ * @param buffer memory to read the rectangle into.
+ * @param rowBytes number of bytes between consecutive rows. Zero means rows are tightly
+ * packed.
+ * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
+ *
+ * @return true if the read succeeded, false if not. The read can fail because of an unsupported
+ * pixel config.
+ */
+ bool readPixels(int left, int top, int width, int height,
+ GrPixelConfig config,
+ void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0) {
+ return this->readPixels(nullptr, left, top, width, height, config, nullptr, buffer,
+ rowBytes, pixelOpsFlags);
+ }
+
+ /**
+ * Copy the src pixels [buffer, rowbytes, pixelconfig] into the surface at the specified
+ * rectangle, possibly performing color space conversion.
+ * @param dstColorSpace color space of the destination (this surface)
+ * @param left left edge of the rectangle to write (inclusive)
+ * @param top top edge of the rectangle to write (inclusive)
+ * @param width width of rectangle to write in pixels.
+ * @param height height of rectangle to write in pixels.
+ * @param config the pixel config of the source buffer
+ * @param srcColorSpace color space of the source buffer
+ * @param buffer memory to read the rectangle from.
+ * @param rowBytes number of bytes between consecutive rows. Zero means rows are tightly
+ * packed.
+ * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
+ *
+ * @return true if the write succeeded, false if not. The write can fail because of an
+ * unsupported pixel config.
+ */
+ bool writePixels(SkColorSpace* dstColorSpace,
+ int left, int top, int width, int height,
+ GrPixelConfig config,
+ SkColorSpace* srcColorSpace,
+ const void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0);
+
+ /**
+ * Copy the src pixels [buffer, rowbytes, pixelconfig] into the surface at the specified
+ * rectangle. Does not perform any color space conversion.
+ * @param left left edge of the rectangle to write (inclusive)
+ * @param top top edge of the rectangle to write (inclusive)
+ * @param width width of rectangle to write in pixels.
+ * @param height height of rectangle to write in pixels.
+ * @param config the pixel config of the source buffer
+ * @param buffer memory to read the rectangle from.
+ * @param rowBytes number of bytes between consecutive rows. Zero means rows are tightly
+ * packed.
+ * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
+ *
+ * @return true if the write succeeded, false if not. The write can fail because of an
+ * unsupported pixel config.
+ */
+ bool writePixels(int left, int top, int width, int height,
+ GrPixelConfig config,
+ const void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0) {
+ return this->writePixels(nullptr, left, top, width, height, config, nullptr, buffer,
+ rowBytes, pixelOpsFlags);
+ }
+
/** Access methods that are only to be used within Skia code. */
inline GrSurfacePriv surfacePriv();
inline const GrSurfacePriv surfacePriv() const;