GrTexture can now create its own cache key
http://codereview.appspot.com/6269047/
git-svn-id: http://skia.googlecode.com/svn/trunk@4148 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 8768528..adceb77 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -109,13 +109,6 @@
};
/**
- * Key generated by client. Should be a unique key on the texture data.
- * Does not need to consider that width and height of the texture. Two
- * textures with the same TextureKey but different bounds will not collide.
- */
- typedef uint64_t TextureKey;
-
- /**
* Create a new entry, based on the specified key and texture, and return
* its "locked" entry. Must call be balanced with an unlockTexture() call.
*
@@ -133,7 +126,7 @@
* @param rowBytes The number of bytes between rows of the texture. Zero
* implies tightly packed rows.
*/
- TextureCacheEntry createAndLockTexture(TextureKey key,
+ TextureCacheEntry createAndLockTexture(GrTexture::TextureKey key,
const GrSamplerState* sampler,
const GrTextureDesc& desc,
void* srcData, size_t rowBytes);
@@ -158,18 +151,16 @@
* filter fields are used. NULL implies clamp wrap modes
* and nearest filtering.
*/
- TextureCacheEntry findAndLockTexture(TextureKey key,
- int width,
- int height,
+ TextureCacheEntry findAndLockTexture(GrTexture::TextureKey key,
+ const GrTextureDesc& desc,
const GrSamplerState* sampler);
/**
* 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(TextureKey key,
- int width,
- int height,
+ bool isTextureInCache(GrTexture::TextureKey key,
+ const GrTextureDesc& desc,
const GrSamplerState*) const;
/**
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index e5c67d6..c3e2946 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -14,11 +14,20 @@
#include "GrResource.h"
class GrRenderTarget;
+class GrResourceKey;
+class GrSamplerState;
class GrTexture : public GrResource {
public:
/**
+ * Key generated by client. Should be a unique key on the texture data.
+ * Does not need to consider that width and height of the texture. Two
+ * textures with the same TextureKey but different bounds will not collide.
+ */
+ typedef uint64_t TextureKey;
+
+ /**
* Retrieves the width of the texture.
*
* @return the width in texels
@@ -130,6 +139,16 @@
void validate() const {}
#endif
+ static GrResourceKey ComputeKey(const GrGpu* gpu,
+ const GrSamplerState* sampler,
+ TextureKey clientKey,
+ const GrTextureDesc& desc,
+ bool scratch);
+
+ static bool NeedsResizing(const GrResourceKey& key);
+ static bool IsScratchTexture(const GrResourceKey& key);
+ static bool NeedsFiltering(const GrResourceKey& key);
+
protected:
GrRenderTarget* fRenderTarget; // texture refs its rt representation
// base class cons sets to NULL
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index 74dc2cf..9e6d83e 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -74,12 +74,7 @@
* Convert the SkBitmap::Config to the corresponding PixelConfig, or
* kUnknown_PixelConfig if the conversion cannot be done.
*/
- static GrPixelConfig BitmapConfig2PixelConfig(SkBitmap::Config,
- bool isOpaque);
-
- static GrPixelConfig Bitmap2PixelConfig(const SkBitmap& bm) {
- return BitmapConfig2PixelConfig(bm.config(), bm.isOpaque());
- }
+ static GrPixelConfig BitmapConfig2PixelConfig(SkBitmap::Config);
static GrColor SkColor2GrColor(SkColor c) {
SkPMColor pm = SkPreMultiplyColor(c);
@@ -157,9 +152,9 @@
////////////////////////////////////////////////////////////////////////////////
// Helper functions
-static const GrContext::TextureKey gUNCACHED_KEY = ~0;
+static const GrTexture::TextureKey gUNCACHED_KEY = ~0;
GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
- GrContext::TextureKey key,
+ GrTexture::TextureKey key,
const GrSamplerState* sampler,
const SkBitmap& bitmap);