Move filter/wrap out of GrSamplerState into GrTextureParams
Review URL: http://codereview.appspot.com/6440046/
git-svn-id: http://skia.googlecode.com/svn/trunk@4773 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 18abd4e..e0f5827 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -119,18 +119,16 @@
* Create a new entry, based on the specified key and texture, and return
* its "locked" entry. Must call be balanced with an unlockTexture() call.
*
- * @param sampler The sampler state used to draw a texture may be used
- * to determine how to store the pixel data in the texture
- * cache. (e.g. different versions may exist for different
- * wrap modes on GPUs with limited or no NPOT texture
- * support). Only the wrap and filter fields are used. NULL
- * implies clamp wrap modes and nearest filtering.
+ * @param params The tex params used to draw a texture may help determine
+ * the cache entry used. (e.g. different versions may exist
+ * for different wrap modes on GPUs with limited NPOT
+ * texture support). NULL implies clamp wrap modes.
* @param desc Description of the texture properties.
* @param srcData Pointer to the pixel values.
* @param rowBytes The number of bytes between rows of the texture. Zero
* implies tightly packed rows.
*/
- TextureCacheEntry createAndLockTexture(const GrSamplerState* sampler,
+ TextureCacheEntry createAndLockTexture(const GrTextureParams* params,
const GrTextureDesc& desc,
void* srcData, size_t rowBytes);
@@ -139,23 +137,21 @@
* return it. The entry's texture() function will return NULL if not found.
* Must be balanced with an unlockTexture() call.
*
- * @param desc Description of the texture properties.
- * @param sampler The sampler state used to draw a texture may be used
- * to determine the cache entry used. (e.g. different
- * versions may exist for different wrap modes on GPUs with
- * limited or no NPOT texture support). Only the wrap and
- * filter fields are used. NULL implies clamp wrap modes
- * and nearest filtering.
+ * @param desc Description of the texture properties.
+ * @param params The tex params used to draw a texture may help determine
+ * the cache entry used. (e.g. different versions may exist
+ * for different wrap modes on GPUs with limited NPOT
+ * texture support). NULL implies clamp wrap modes.
*/
TextureCacheEntry findAndLockTexture(const GrTextureDesc& desc,
- const GrSamplerState* sampler);
+ const GrTextureParams* params);
/**
* Determines whether a texture is in the cache. If the texture is found it
* will not be locked or returned. This call does not affect the priority of
* the texture for deletion.
*/
bool isTextureInCache(const GrTextureDesc& desc,
- const GrSamplerState* sampler) const;
+ const GrTextureParams* params) const;
/**
* Enum that determines how closely a returned scratch texture must match
@@ -212,9 +208,12 @@
size_t rowBytes);
/**
- * Returns true if the specified use of an indexed texture is supported.
+ * Returns true if the specified use of an indexed texture is supported.
+ * Support may depend upon whether the texture params indicate that the
+ * texture will be tiled. Passing NULL for the texture params indicates
+ * clamp mode.
*/
- bool supportsIndex8PixelConfig(const GrSamplerState* sampler,
+ bool supportsIndex8PixelConfig(const GrTextureParams*,
int width,
int height) const;
diff --git a/include/gpu/GrSamplerState.h b/include/gpu/GrSamplerState.h
index 0731848..04fbe00 100644
--- a/include/gpu/GrSamplerState.h
+++ b/include/gpu/GrSamplerState.h
@@ -15,31 +15,76 @@
#include "GrMatrix.h"
#include "GrTypes.h"
+#include "SkShader.h"
+
+class GrTextureParams {
+public:
+ GrTextureParams() {
+ this->reset();
+ }
+
+ GrTextureParams(const GrTextureParams& params) {
+ *this = params;
+ }
+
+ GrTextureParams& operator =(const GrTextureParams& params) {
+ fTileModes[0] = params.fTileModes[0];
+ fTileModes[1] = params.fTileModes[1];
+ fBilerp = params.fBilerp;
+ return *this;
+ }
+
+ void reset() {
+ this->reset(SkShader::kClamp_TileMode, false);
+ }
+
+ void reset(SkShader::TileMode tileXAndY, bool filter) {
+ fTileModes[0] = fTileModes[1] = tileXAndY;
+ fBilerp = filter;
+ }
+ void reset(SkShader::TileMode tileModes[2], bool filter) {
+ fTileModes[0] = tileModes[0];
+ fTileModes[1] = tileModes[1];
+ fBilerp = filter;
+ }
+
+ void setClampNoFilter() {
+ fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode;
+ fBilerp = false;
+ }
+
+ void setClamp() {
+ fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode;
+ }
+
+ void setBilerp(bool bilerp) { fBilerp = bilerp; }
+
+ void setTileModeX(const SkShader::TileMode tm) { fTileModes[0] = tm; }
+ void setTileModeY(const SkShader::TileMode tm) { fTileModes[1] = tm; }
+ void setTileModeXAndY(const SkShader::TileMode tm) { fTileModes[0] = fTileModes[1] = tm; }
+
+ SkShader::TileMode getTileModeX() const { return fTileModes[0]; }
+
+ SkShader::TileMode getTileModeY() const { return fTileModes[1]; }
+
+ bool isTiled() const {
+ return SkShader::kClamp_TileMode != fTileModes[0] ||
+ SkShader::kClamp_TileMode != fTileModes[1];
+ }
+
+ bool isBilerp() const { return fBilerp; }
+
+private:
+
+ SkShader::TileMode fTileModes[2];
+ bool fBilerp;
+};
+
class GrSamplerState {
public:
- enum Filter {
- /**
- * Read the closest src texel to the sample position
- */
- kNearest_Filter,
- /**
- * Blend between closest 4 src texels to sample position (tent filter)
- */
- kBilinear_Filter,
- kDefault_Filter = kNearest_Filter
- };
+ static const bool kBilerpDefault = false;
- /**
- * Describes how a texture is sampled when coordinates are outside the
- * texture border
- */
- enum WrapMode {
- kClamp_WrapMode,
- kRepeat_WrapMode,
- kMirror_WrapMode,
-
- kDefault_WrapMode = kClamp_WrapMode
- };
+ static const SkShader::TileMode kTileModeDefault = SkShader::kClamp_TileMode;
/**
* Default sampler state is set to clamp, use normal sampling mode, be
@@ -74,9 +119,7 @@
GrSamplerState& operator =(const GrSamplerState& s) {
// memcpy() breaks refcounting
- fWrapX = s.fWrapX;
- fWrapY = s.fWrapY;
- fFilter = s.fFilter;
+ fTextureParams = s.fTextureParams;
fMatrix = s.fMatrix;
fSwapRAndB = s.fSwapRAndB;
@@ -85,15 +128,11 @@
return *this;
}
- WrapMode getWrapX() const { return fWrapX; }
- WrapMode getWrapY() const { return fWrapY; }
const GrMatrix& getMatrix() const { return fMatrix; }
- Filter getFilter() const { return fFilter; }
bool swapsRAndB() const { return fSwapRAndB; }
- void setWrapX(WrapMode mode) { fWrapX = mode; }
- void setWrapY(WrapMode mode) { fWrapY = mode; }
-
+ GrTextureParams* textureParams() { return &fTextureParams; }
+ const GrTextureParams& getTextureParams() const { return fTextureParams; }
/**
* Access the sampler's matrix. See SampleMode for explanation of
* relationship between the matrix and sample mode.
@@ -118,30 +157,22 @@
*/
void preConcatMatrix(const GrMatrix& matrix) { fMatrix.preConcat(matrix); }
- /**
- * Sets filtering type.
- * @param filter type of filtering to apply
- */
- void setFilter(Filter filter) { fFilter = filter; }
-
- void reset(WrapMode wrapXAndY,
- Filter filter,
+ void reset(SkShader::TileMode tileXAndY,
+ bool filter,
const GrMatrix& matrix) {
- fWrapX = wrapXAndY;
- fWrapY = wrapXAndY;
- fFilter = filter;
+ fTextureParams.reset(tileXAndY, filter);
fMatrix = matrix;
fSwapRAndB = false;
GrSafeSetNull(fCustomStage);
}
- void reset(WrapMode wrapXAndY, Filter filter) {
+ void reset(SkShader::TileMode wrapXAndY, bool filter) {
this->reset(wrapXAndY, filter, GrMatrix::I());
}
void reset(const GrMatrix& matrix) {
- this->reset(kDefault_WrapMode, kDefault_Filter, matrix);
+ this->reset(kTileModeDefault, kBilerpDefault, matrix);
}
void reset() {
- this->reset(kDefault_WrapMode, kDefault_Filter, GrMatrix::I());
+ this->reset(kTileModeDefault, kBilerpDefault, GrMatrix::I());
}
GrCustomStage* setCustomStage(GrCustomStage* stage) {
@@ -151,9 +182,7 @@
GrCustomStage* getCustomStage() const { return fCustomStage; }
private:
- WrapMode fWrapX : 8;
- WrapMode fWrapY : 8;
- Filter fFilter : 8;
+ GrTextureParams fTextureParams;
bool fSwapRAndB;
GrMatrix fMatrix;
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index 783a147..d4a7cc6 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -13,7 +13,7 @@
class GrRenderTarget;
class GrResourceKey;
-class GrSamplerState;
+class GrTextureParams;
/*
* All uncached textures should have this value as their fClientCacheID
@@ -162,7 +162,7 @@
#endif
static GrResourceKey ComputeKey(const GrGpu* gpu,
- const GrSamplerState* sampler,
+ const GrTextureParams* sampler,
const GrTextureDesc& desc,
bool scratch);
diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h
index 2af1149..4a62813 100644
--- a/include/gpu/SkGpuDevice.h
+++ b/include/gpu/SkGpuDevice.h
@@ -118,7 +118,7 @@
protected:
typedef GrContext::TextureCacheEntry TexCache;
bool isBitmapInTextureCache(const SkBitmap& bitmap,
- const GrSamplerState& sampler) const;
+ const GrTextureParams& params) const;
// overrides from SkDevice
virtual bool onReadPixels(const SkBitmap& bitmap,
@@ -157,7 +157,7 @@
void prepareRenderTarget(const SkDraw&);
bool shouldTileBitmap(const SkBitmap& bitmap,
- const GrSamplerState& sampler,
+ const GrTextureParams& sampler,
const SkIRect* srcRectPtr,
int* tileSize) const;
void internalDrawBitmap(const SkDraw&, const SkBitmap&,
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index ea79c63..6c6e3da 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -24,7 +24,6 @@
#include "SkPath.h"
#include "SkPoint.h"
#include "SkRegion.h"
-#include "SkShader.h"
#include "SkClipStack.h"
#if (GR_DEBUG && defined(SK_RELEASE)) || (GR_RELEASE && defined(SK_DEBUG))
@@ -34,14 +33,6 @@
////////////////////////////////////////////////////////////////////////////////
// Sk to Gr Type conversions
-GR_STATIC_ASSERT((int)GrSamplerState::kClamp_WrapMode == (int)SkShader::kClamp_TileMode);
-GR_STATIC_ASSERT((int)GrSamplerState::kRepeat_WrapMode ==(
- int)SkShader::kRepeat_TileMode);
-GR_STATIC_ASSERT((int)GrSamplerState::kMirror_WrapMode ==
- (int)SkShader::kMirror_TileMode);
-
-#define sk_tile_mode_to_grwrap(X) ((GrSamplerState::WrapMode)(X))
-
GR_STATIC_ASSERT((int)kZero_GrBlendCoeff == (int)SkXfermode::kZero_Coeff);
GR_STATIC_ASSERT((int)kOne_GrBlendCoeff == (int)SkXfermode::kOne_Coeff);
GR_STATIC_ASSERT((int)kSC_GrBlendCoeff == (int)SkXfermode::kSC_Coeff);
@@ -85,11 +76,11 @@
////////////////////////////////////////////////////////////////////////////////
-GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext* ctx,
- const SkBitmap& bitmap,
- const GrSamplerState* sampler);
+GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext*,
+ const SkBitmap&,
+ const GrTextureParams*);
-void GrUnlockCachedBitmapTexture(GrContext* ctx, GrContext::TextureCacheEntry cache);
+void GrUnlockCachedBitmapTexture(GrContext*, GrContext::TextureCacheEntry);
////////////////////////////////////////////////////////////////////////////////
// Classes