Split cache-specific fields out of GrTextureDesc
http://codereview.appspot.com/6448143/
git-svn-id: http://skia.googlecode.com/svn/trunk@5065 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrCacheID.h b/include/gpu/GrCacheID.h
index 231304d..e6f5f75 100644
--- a/include/gpu/GrCacheID.h
+++ b/include/gpu/GrCacheID.h
@@ -75,7 +75,7 @@
GrCacheID(uint8_t resourceType)
: fPublicID(kDefaultPublicCacheID)
- , fDomain(kUnrestricted_ResourceDomain)
+ , fDomain(GrCacheData::kScratch_ResourceDomain)
, fResourceType(resourceType) {
}
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 52dafd0..abe7453 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -125,12 +125,14 @@
* for different wrap modes on GPUs with limited NPOT
* texture support). NULL implies clamp wrap modes.
* @param desc Description of the texture properties.
+ * @param cacheData Cache-specific properties (e.g., texture gen ID)
* @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 GrTextureParams* params,
const GrTextureDesc& desc,
+ const GrCacheData& cacheData,
void* srcData, size_t rowBytes);
/**
@@ -139,12 +141,14 @@
* Must be balanced with an unlockTexture() call.
*
* @param desc Description of the texture properties.
+ * @param cacheData Cache-specific properties (e.g., texture gen ID)
* @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 GrCacheData& cacheData,
const GrTextureParams* params);
/**
* Determines whether a texture is in the cache. If the texture is found it
@@ -152,6 +156,7 @@
* the texture for deletion.
*/
bool isTextureInCache(const GrTextureDesc& desc,
+ const GrCacheData& cacheData,
const GrTextureParams* params) const;
/**
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index 2ccd301..a1b7eab 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -16,17 +16,6 @@
class GrResourceKey;
class GrTextureParams;
-/*
- * All uncached textures should have this value as their fClientCacheID
- */
-static const uint64_t kUncached_CacheID = 0xAAAAAAAA;
-
-/*
- * Scratch textures should all have this value as their fClientCacheID
- */
-static const uint64_t kScratch_CacheID = 0xBBBBBBBB;
-
-
class GrTexture : public GrSurface {
public:
@@ -166,6 +155,7 @@
static GrResourceKey ComputeKey(const GrGpu* gpu,
const GrTextureParams* sampler,
const GrTextureDesc& desc,
+ const GrCacheData& cacheData,
bool scratch);
static bool NeedsResizing(const GrResourceKey& key);
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index a3f0059..9fbdb74 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -468,17 +468,6 @@
kGrColorTableSize = 256 * 4 //sizeof(GrColor)
};
-/*
- * Default value for fClientCacheID
- */
-static const uint64_t kDefault_CacheID = 0;
-
-/**
- * All scratch resources should be Unrestricted so they can be used
- * by any domain.
- */
-static const uint8_t kUnrestricted_ResourceDomain = 0;
-
/**
* Describes a texture to be created.
@@ -489,9 +478,7 @@
, fWidth(0)
, fHeight(0)
, fConfig(kUnknown_GrPixelConfig)
- , fSampleCnt(0)
- , fClientCacheID(kDefault_CacheID)
- , fResourceDomain(kUnrestricted_ResourceDomain) {
+ , fSampleCnt(0) {
}
GrTextureFlags fFlags; //!< bitfield of TextureFlags
@@ -512,6 +499,33 @@
* max supportex count.
*/
int fSampleCnt;
+};
+
+/**
+ * GrCacheData holds user-provided cache-specific data. It is used in
+ * combination with the GrTextureDesc to construct a cache key for texture
+ * resources.
+ */
+struct GrCacheData {
+ /*
+ * Scratch textures should all have this value as their fClientCacheID
+ */
+ static const uint64_t kScratch_CacheID = 0xBBBBBBBB;
+
+ /**
+ * Resources in the "scratch" domain can be used by any domain. All
+ * scratch textures will have this as their domain.
+ */
+ static const uint8_t kScratch_ResourceDomain = 0;
+
+
+ // No default constructor is provided since, if you are creating one
+ // of these, you should definitely have a key (or be using the scratch
+ // key).
+ GrCacheData(uint64_t key)
+ : fClientCacheID(key)
+ , fResourceDomain(kScratch_ResourceDomain) {
+ }
/**
* A user-provided texture ID. It should be unique to the texture data and