aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-20 19:22:38 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-20 19:22:38 +0000
commit0342a85091fd430c90a142d155dc9642aa729d9e (patch)
treead84edb6b6194b35ca77783c7147c2e62a56542f /include
parentb7961193a3ecca44cf2650d9e446ebaa10b1583d (diff)
Remove _UPM_ GrPixelConfigs
Review URL: http://codereview.appspot.com/6460113/ git-svn-id: http://skia.googlecode.com/svn/trunk@5196 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r--include/gpu/GrContext.h116
-rw-r--r--include/gpu/GrRenderTarget.h38
-rw-r--r--include/gpu/GrSamplerState.h9
-rw-r--r--include/gpu/GrSurface.h32
-rw-r--r--include/gpu/GrTexture.h39
-rw-r--r--include/gpu/GrTypes.h78
6 files changed, 107 insertions, 205 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 0687dcf7b5..dbb404ffe9 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -465,54 +465,60 @@ public:
*/
void flush(int flagsBitfield = 0);
+ /**
+ * These flags can be used with the read/write pixels functions below.
+ */
+ enum PixelOpsFlags {
+ /** The GrContext will not be flushed. This means that the read or write may occur before
+ previous draws have executed. */
+ kDontFlush_PixelOpsFlag = 0x1,
+ /** 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 = 0x2,
+ };
+
/**
* Reads a rectangle of pixels from a render target.
- * @param target the render target to read from. NULL means the
- * current render target.
+ * @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)
* @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.
+ * @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 config or because no render
- * target is currently set.
+ * @return true if the read succeeded, false if not. The read can fail because of an unsupported
+ * pixel config or because no render target is currently set and NULL was passed for
+ * target.
*/
bool readRenderTargetPixels(GrRenderTarget* target,
int left, int top, int width, int height,
- GrPixelConfig config, void* buffer,
- size_t rowBytes) {
- return this->internalReadRenderTargetPixels(target, left, top,
- width, height,
- config, buffer,
- rowBytes, 0);
- }
+ GrPixelConfig config, void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 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.
+ * 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.
+ * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
+ * packed.
+ * @param pixelOpsFlags see PixelOpsFlags enum above.
*/
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);
- }
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0);
/**
* Reads a rectangle of pixels from a texture.
@@ -523,20 +529,18 @@ 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.
+ * @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 config.
+ * @return true if the read succeeded, false if not. The read can fail because of an unsupported
+ * pixel config.
*/
bool readTexturePixels(GrTexture* texture,
int left, int top, int width, int height,
GrPixelConfig config, void* buffer,
- size_t rowBytes) {
- return this->internalReadTexturePixels(texture, left, top,
- width, height,
- config, buffer, rowBytes, 0);
- }
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0);
/**
* Writes a rectangle of pixels to a texture.
@@ -549,14 +553,15 @@ public:
* @param buffer memory to read pixels from
* @param rowBytes number of bytes bewtween consecutive rows. Zero
* means rows are tightly packed.
+ * @param pixelOpsFlags see PixelOpsFlags enum above.
*/
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);
- }
+ size_t rowBytes,
+ uint32_t pixelOpsFlags = 0);
+
+
/**
* Copies all texels from one texture to another.
* @param src the texture to copy from.
@@ -785,49 +790,12 @@ private:
void internalDrawPath(const GrPaint& paint, const SkPath& path,
GrPathFill fill, const GrPoint* translate);
- /**
- * Flags to the internal read/write pixels funcs
- */
- enum PixelOpsFlags {
- kDontFlush_PixelOpsFlag = 0x1,
- };
-
GrTexture* createResizedTexture(const GrTextureDesc& desc,
const GrCacheData& cacheData,
void* srcData,
size_t rowBytes,
bool needsFiltering);
- 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;
- friend class GrTextureStripAtlas;
-
// Needed so GrTexture's returnToCache helper function can call
// addExistingTextureToCache
friend class GrTexture;
diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h
index d69e5cada9..33df8c6329 100644
--- a/include/gpu/GrRenderTarget.h
+++ b/include/gpu/GrRenderTarget.h
@@ -53,39 +53,17 @@ public:
return this;
}
- /**
- * Reads a rectangle of pixels from the render target.
- * @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 an unsupported pixel config.
- */
virtual bool readPixels(int left, int top, int width, int height,
- GrPixelConfig config, void* buffer,
- size_t rowBytes) SK_OVERRIDE;
+ GrPixelConfig config,
+ void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
- /**
- * 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.
- */
virtual void writePixels(int left, int top, int width, int height,
- GrPixelConfig config, const void* buffer,
- size_t rowBytes) SK_OVERRIDE;
+ GrPixelConfig config,
+ const void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
// GrRenderTarget
/**
diff --git a/include/gpu/GrSamplerState.h b/include/gpu/GrSamplerState.h
index dcd5b66283..f87b9b4e10 100644
--- a/include/gpu/GrSamplerState.h
+++ b/include/gpu/GrSamplerState.h
@@ -130,6 +130,7 @@ public:
const GrMatrix& getMatrix() const { return fMatrix; }
bool swapsRAndB() const { return fSwapRAndB; }
+ bool premultiply() const { return fPremultiply; }
GrTextureParams* textureParams() { return &fTextureParams; }
const GrTextureParams& getTextureParams() const { return fTextureParams; }
@@ -146,6 +147,12 @@ public:
void setRAndBSwap(bool swap) { fSwapRAndB = swap; }
/**
+ * If the texture is RGBA/BGRA 8888 config then its rgb components will be
+ * multiplied by its a component after the texture read.
+ **/
+ void setPremultiply(bool premul) { fPremultiply = premul; }
+
+ /**
* Multiplies the current sampler matrix a matrix
*
* After this call M' = M*m where M is the old matrix, m is the parameter
@@ -163,6 +170,7 @@ public:
fTextureParams.reset(tileXAndY, filter);
fMatrix = matrix;
fSwapRAndB = false;
+ fPremultiply = false;
GrSafeSetNull(fCustomStage);
}
void reset(SkShader::TileMode wrapXAndY, bool filter) {
@@ -184,6 +192,7 @@ public:
private:
GrTextureParams fTextureParams;
bool fSwapRAndB;
+ bool fPremultiply; // temporary, will be replaced soon by a custom stage.
GrMatrix fMatrix;
GrCustomStage* fCustomStage;
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h
index 2d39b5e10b..aa237aee4d 100644
--- a/include/gpu/GrSurface.h
+++ b/include/gpu/GrSurface.h
@@ -66,34 +66,40 @@ 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.
+ * @param rowBytes number of bytes bewtween 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.
+ * @return true if the read succeeded, false if not. The read can fail because of an unsupported
+ * pixel config.
*/
virtual bool readPixels(int left, int top, int width, int height,
- GrPixelConfig config, void* buffer,
- size_t rowBytes) = 0;
+ GrPixelConfig config,
+ void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0) = 0;
/**
- * Copy the src pixels [buffer, rowbytes, pixelconfig] into the surface
- * at the specified rectangle.
+ * Copy the src pixels [buffer, rowbytes, pixelconfig] into the surface 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.
+ * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
+ * packed.
+ * @param pixelOpsFlags See the GrContext::PixelOpsFlags enum.
*/
virtual void writePixels(int left, int top, int width, int height,
- GrPixelConfig config, const void* buffer,
- size_t rowBytes) = 0;
+ GrPixelConfig config,
+ const void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0) = 0;
protected:
- GrTextureDesc fDesc;
+ GrTextureDesc fDesc;
GrSurface(GrGpu* gpu, const GrTextureDesc& desc)
: INHERITED(gpu)
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index a1b7eabd85..c7bfb8c363 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -55,39 +55,18 @@ public:
GrBytesPerPixel(fDesc.fConfig);
}
- // from GrSurface
- /**
- * 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.
- */
+ // GrSurface overrides
virtual bool readPixels(int left, int top, int width, int height,
- GrPixelConfig config, void* buffer,
- size_t rowBytes) SK_OVERRIDE;
+ GrPixelConfig config,
+ void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
- /**
- * 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 between consecutive rows. Zero
- * means rows are tightly packed.
- */
virtual void writePixels(int left, int top, int width, int height,
- GrPixelConfig config, const void* buffer,
- size_t rowBytes) SK_OVERRIDE;
+ GrPixelConfig config,
+ const void* buffer,
+ size_t rowBytes = 0,
+ uint32_t pixelOpsFlags = 0) SK_OVERRIDE;
/**
* @return this texture
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index 9fbdb741ab..58f8968530 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -276,13 +276,6 @@ static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) {
/**
* Pixel configurations.
- *
- * Unpremultiplied configs are intended for converting pixel data in and out
- * from skia. Surfaces with these configs have limited support. As an input
- * (GrPaint texture) the corresponding GrSamplerState must have its filter set
- * to kNearest_Filter. Otherwise, the draw will fail. When the render target
- * has an unpremultiplied config draws must use blend coeffs 1,0 (AKA src-mode).
- * Other coeffs will cause the draw to fail.
*/
enum GrPixelConfig {
kUnknown_GrPixelConfig,
@@ -294,47 +287,39 @@ enum GrPixelConfig {
*/
kRGBA_4444_GrPixelConfig,
/**
- * Premultiplied. Byte order is r,g,b,a
- */
- kRGBA_8888_PM_GrPixelConfig,
- /**
- * Unpremultiplied. Byte order is r,g,b,a
- */
- kRGBA_8888_UPM_GrPixelConfig,
- /**
- * Premultiplied. Byte order is b,g,r,a
+ * Premultiplied. Byte order is r,g,b,a.
*/
- kBGRA_8888_PM_GrPixelConfig,
+ kRGBA_8888_GrPixelConfig,
/**
- * Unpremultiplied. Byte order is b,g,r,a
+ * Premultiplied. Byte order is b,g,r,a.
*/
- kBGRA_8888_UPM_GrPixelConfig,
+ kBGRA_8888_GrPixelConfig,
kGrPixelConfigCount
};
-// Aliases for pixel configs that match skia's byte order
+// Aliases for pixel configs that match skia's byte order.
#ifndef SK_CPU_LENDIAN
#error "Skia gpu currently assumes little endian"
#endif
#if 24 == SK_A32_SHIFT && 16 == SK_R32_SHIFT && \
8 == SK_G32_SHIFT && 0 == SK_B32_SHIFT
- static const GrPixelConfig kSkia8888_PM_GrPixelConfig = kBGRA_8888_PM_GrPixelConfig;
- static const GrPixelConfig kSkia8888_UPM_GrPixelConfig = kBGRA_8888_UPM_GrPixelConfig;
+ static const GrPixelConfig kSkia8888_GrPixelConfig = kBGRA_8888_GrPixelConfig;
#elif 24 == SK_A32_SHIFT && 16 == SK_B32_SHIFT && \
8 == SK_G32_SHIFT && 0 == SK_R32_SHIFT
- static const GrPixelConfig kSkia8888_PM_GrPixelConfig = kRGBA_8888_PM_GrPixelConfig;
- static const GrPixelConfig kSkia8888_UPM_GrPixelConfig = kRGBA_8888_UPM_GrPixelConfig;
+ static const GrPixelConfig kSkia8888_GrPixelConfig = kRGBA_8888_GrPixelConfig;
#else
#error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format."
#endif
+// This alias is deprecated and will be removed.
+static const GrPixelConfig kSkia8888_PM_GrPixelConfig = kSkia8888_GrPixelConfig;
+
// Returns true if the pixel config has 8bit r,g,b,a components in that byte
// order
static inline bool GrPixelConfigIsRGBA8888(GrPixelConfig config) {
switch (config) {
- case kRGBA_8888_PM_GrPixelConfig:
- case kRGBA_8888_UPM_GrPixelConfig:
+ case kRGBA_8888_GrPixelConfig:
return true;
default:
return false;
@@ -345,8 +330,7 @@ static inline bool GrPixelConfigIsRGBA8888(GrPixelConfig config) {
// order
static inline bool GrPixelConfigIsBGRA8888(GrPixelConfig config) {
switch (config) {
- case kBGRA_8888_PM_GrPixelConfig:
- case kBGRA_8888_UPM_GrPixelConfig:
+ case kBGRA_8888_GrPixelConfig:
return true;
default:
return false;
@@ -356,10 +340,8 @@ static inline bool GrPixelConfigIsBGRA8888(GrPixelConfig config) {
// Returns true if the pixel config is 32 bits per pixel
static inline bool GrPixelConfigIs32Bit(GrPixelConfig config) {
switch (config) {
- case kRGBA_8888_PM_GrPixelConfig:
- case kRGBA_8888_UPM_GrPixelConfig:
- case kBGRA_8888_PM_GrPixelConfig:
- case kBGRA_8888_UPM_GrPixelConfig:
+ case kRGBA_8888_GrPixelConfig:
+ case kBGRA_8888_GrPixelConfig:
return true;
default:
return false;
@@ -370,14 +352,10 @@ static inline bool GrPixelConfigIs32Bit(GrPixelConfig config) {
// swapped if such a config exists. Otherwise, kUnknown_GrPixelConfig
static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
switch (config) {
- case kBGRA_8888_PM_GrPixelConfig:
- return kRGBA_8888_PM_GrPixelConfig;
- case kBGRA_8888_UPM_GrPixelConfig:
- return kRGBA_8888_UPM_GrPixelConfig;
- case kRGBA_8888_PM_GrPixelConfig:
- return kBGRA_8888_PM_GrPixelConfig;
- case kRGBA_8888_UPM_GrPixelConfig:
- return kBGRA_8888_UPM_GrPixelConfig;
+ case kBGRA_8888_GrPixelConfig:
+ return kRGBA_8888_GrPixelConfig;
+ case kRGBA_8888_GrPixelConfig:
+ return kBGRA_8888_GrPixelConfig;
default:
return kUnknown_GrPixelConfig;
}
@@ -391,10 +369,8 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
return 2;
- case kRGBA_8888_PM_GrPixelConfig:
- case kRGBA_8888_UPM_GrPixelConfig:
- case kBGRA_8888_PM_GrPixelConfig:
- case kBGRA_8888_UPM_GrPixelConfig:
+ case kRGBA_8888_GrPixelConfig:
+ case kBGRA_8888_GrPixelConfig:
return 4;
default:
return 0;
@@ -410,20 +386,6 @@ static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
}
}
-/**
- * Premultiplied alpha is the usual for skia. Therefore, configs that are
- * ambiguous (alpha-only or color-only) are considered premultiplied.
- */
-static inline bool GrPixelConfigIsUnpremultiplied(GrPixelConfig config) {
- switch (config) {
- case kRGBA_8888_UPM_GrPixelConfig:
- case kBGRA_8888_UPM_GrPixelConfig:
- return true;
- default:
- return false;
- }
-}
-
static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) {
switch (config) {
case kAlpha_8_GrPixelConfig: