aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-16 20:36:03 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-16 20:36:03 +0000
commit6f3795105b2b458079e53a721c1735c9518f6bb5 (patch)
tree107d2ec0b8986a3bf96220fe9e86974fe9f7b8e3 /include/gpu
parentaa336da0838c3da8b3be2e0348da3c6abeebf273 (diff)
Make all pixel ops go thru ctx so we can correctly flush. Unify two texture upload code paths.
Review URL: http://codereview.appspot.com/5373108/ git-svn-id: http://skia.googlecode.com/svn/trunk@2701 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/gpu')
-rw-r--r--include/gpu/GrContext.h112
-rw-r--r--include/gpu/GrRenderTarget.h21
-rw-r--r--include/gpu/GrTexture.h41
3 files changed, 136 insertions, 38 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 4edb187dc8..6bdd37d976 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -445,10 +445,10 @@ public:
* FlushBits.
*/
void flush(int flagsBitfield = 0);
-
+
/**
* Reads a rectangle of pixels from a render target.
- * @param renderTarget the render target to read from. NULL means the
+ * @param target the render target to read from. NULL means the
* current render target.
* @param left left edge of the rectangle to read (inclusive)
* @param top top edge of the rectangle to read (inclusive)
@@ -456,42 +456,88 @@ public:
* @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 bewtween consecueive rows. Zero
+ * @param rowBytes number of bytes bewtween consecutive rows. Zero
* means rows are tightly packed.
*
* @return true if the read succeeded, false if not. The read can fail
- * because of a unsupported pixel config or because no render
+ * because of an unsupported pixel config or because no render
* target is currently set.
*/
bool readRenderTargetPixels(GrRenderTarget* target,
int left, int top, int width, int height,
GrPixelConfig config, void* buffer,
- size_t rowBytes = 0);
+ size_t rowBytes) {
+ return this->internalReadRenderTargetPixels(target, left, top,
+ width, height,
+ config, buffer,
+ rowBytes, 0);
+ }
+
+ /**
+ * Copy the src pixels [buffer, rowbytes, pixelconfig] into a render target
+ * at the specified rectangle.
+ * @param target the render target to write into. NULL means the
+ * current render target.
+ * @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 bewtween consecutive rows. Zero
+ * means rows are tightly packed.
+ */
+ void writeRenderTargetPixels(GrRenderTarget* target,
+ int left, int top, int width, int height,
+ GrPixelConfig config, const void* buffer,
+ size_t rowBytes) {
+ this->internalWriteRenderTargetPixels(target, left, top, width, height,
+ config, buffer, rowBytes, 0);
+ }
/**
* Reads a rectangle of pixels from a texture.
- * @param texture the render target to read from.
+ * @param texture the texture to read from.
* @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 bewtween consecutive rows. Zero
+ * means rows are tightly packed.
*
* @return true if the read succeeded, false if not. The read can fail
- * because of a unsupported pixel config.
+ * because of an unsupported pixel config.
*/
- bool readTexturePixels(GrTexture* target,
+ bool readTexturePixels(GrTexture* texture,
int left, int top, int width, int height,
- GrPixelConfig config, void* buffer);
+ GrPixelConfig config, void* buffer,
+ size_t rowBytes) {
+ return this->internalReadTexturePixels(texture, left, top,
+ width, height,
+ config, buffer, rowBytes, 0);
+ }
/**
- * Copy the src pixels [buffer, stride, pixelconfig] into the current
- * render-target at the specified rectangle.
+ * Writes a rectangle of pixels to a texture.
+ * @param texture the render target to read from.
+ * @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 pixels from
+ * @param rowBytes number of bytes bewtween consecutive rows. Zero
+ * means rows are tightly packed.
*/
- void writePixels(int left, int top, int width, int height,
- GrPixelConfig, const void* buffer, size_t stride);
-
+ void writeTexturePixels(GrTexture* texture,
+ int left, int top, int width, int height,
+ GrPixelConfig config, const void* buffer,
+ size_t rowBytes) {
+ this->internalWriteTexturePixels(texture, left, top, width, height,
+ config, buffer, rowBytes, 0);
+ }
/**
* Applies a 1D convolution kernel in the X direction to a rectangle of
* pixels from a given texture.
@@ -654,7 +700,43 @@ private:
float imageIncrement[2],
const float* kernel,
int kernelWidth);
-
+
+ /**
+ * Flags to the internal read/write pixels funcs
+ */
+ enum PixelOpsFlags {
+ kDontFlush_PixelOpsFlag = 0x1,
+ };
+
+ bool internalReadRenderTargetPixels(GrRenderTarget* target,
+ int left, int top,
+ int width, int height,
+ GrPixelConfig config, void* buffer,
+ size_t rowBytes, uint32_t flags);
+
+ void internalWriteRenderTargetPixels(GrRenderTarget* target,
+ int left, int top,
+ int width, int height,
+ GrPixelConfig, const void* buffer,
+ size_t rowBytes, uint32_t flags);
+
+ bool internalReadTexturePixels(GrTexture* texture,
+ int left, int top,
+ int width, int height,
+ GrPixelConfig config, void* buffer,
+ size_t rowBytes, uint32_t flags);
+
+ void internalWriteTexturePixels(GrTexture* texture,
+ int left, int top,
+ int width, int height,
+ GrPixelConfig config, const void* buffer,
+ size_t rowBytes, uint32_t flags);
+ // needed for access to internalWriteTexturePixels. TODO: make GrContext
+ // be a facade for an internal class. Then functions that are public on the
+ // internal class would have only be callable in src/gpu. The facade would
+ // only have to functions necessary for clients.
+ friend class GrAtlas;
+
// computes vertex layout bits based on the paint. If paint expresses
// a texture for a stage, the stage coords will be bound to postitions
// unless hasTexCoords[s]==true in which case stage s's input coords
diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h
index 1b11aeefac..13b2160f79 100644
--- a/include/gpu/GrRenderTarget.h
+++ b/include/gpu/GrRenderTarget.h
@@ -123,12 +123,29 @@ public:
* @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 bewtween consecutive rows. Zero
+ * means rows are tightly packed.
*
* @return true if the read succeeded, false if not. The read can fail
- * because of a unsupported pixel config.
+ * because of an unsupported pixel config.
*/
bool readPixels(int left, int top, int width, int height,
- GrPixelConfig config, void* buffer);
+ GrPixelConfig config, void* buffer, size_t rowBytes);
+
+ /**
+ * Copy the src pixels [buffer, rowbytes, pixelconfig] into the render
+ * target at the specified rectangle.
+ * @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 bewtween consecutive rows. Zero
+ * means rows are tightly packed.
+ */
+ void writePixels(int left, int top, int width, int height,
+ GrPixelConfig config, const void* buffer, size_t rowBytes);
// a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
// 0 in GL), or be unresolvable because the client didn't give us the
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index 019268827a..8274140adc 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -54,38 +54,37 @@ public:
}
/**
- * Updates a subrectangle of texels in the texture.
- *
- * @param x left edge of rectangle to update
- * @param y top edge of rectangle to update
- * @param width width of rectangle to update
- * @param height height of rectangle to update
- * @param srcData width*height texels of data in same format that was
- * used at texture creation.
- * @param rowBytes number of bytes per row in srcData, 0 means rows are
- * packed
- */
- virtual void uploadTextureData(int x,
- int y,
- int width,
- int height,
- const void* srcData,
- size_t rowBytes) = 0;
-
- /**
- * Reads a rectangle of pixels from the texture.
+ * Read a rectangle of pixels from the texture.
* @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 bewtween consecutive rows. Zero
+ * means rows are tightly packed.
*
* @return true if the read succeeded, false if not. The read can fail
* because of a unsupported pixel config.
*/
bool readPixels(int left, int top, int width, int height,
- GrPixelConfig config, void* buffer);
+ GrPixelConfig config, void* buffer,
+ size_t rowBytes);
+
+ /**
+ * Writes a rectangle of pixels to the texture.
+ * @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 pixels from
+ * @param rowBytes number of bytes bewtween consecutive rows. Zero
+ * means rows are tightly packed.
+ */
+ void writePixels(int left, int top, int width, int height,
+ GrPixelConfig config, const void* buffer,
+ size_t rowBytes);
/**
* Retrieves the render target underlying this texture that can be passed to