Move clientID into texture desc

http://codereview.appspot.com/6305044/



git-svn-id: http://skia.googlecode.com/svn/trunk@4201 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrAtlas.cpp b/src/gpu/GrAtlas.cpp
index f8586fa..fb12719 100644
--- a/src/gpu/GrAtlas.cpp
+++ b/src/gpu/GrAtlas.cpp
@@ -177,13 +177,12 @@
     GrAssert(0 == kA8_GrMaskFormat);
     GrAssert(1 == kA565_GrMaskFormat);
     if (NULL == fTexture[format]) {
-        GrTextureDesc desc = {
-            kDynamicUpdate_GrTextureFlagBit,
-            GR_ATLAS_TEXTURE_WIDTH,
-            GR_ATLAS_TEXTURE_HEIGHT,
-            maskformat2pixelconfig(format),
-            0 // samples
-        };
+        GrTextureDesc desc;
+        desc.fFlags = kDynamicUpdate_GrTextureFlagBit;
+        desc.fWidth = GR_ATLAS_TEXTURE_WIDTH;
+        desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT;
+        desc.fConfig = maskformat2pixelconfig(format);
+
         fTexture[format] = fGpu->createTexture(desc, NULL, 0);
         if (NULL == fTexture[format]) {
             return NULL;
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index c0272bb..28ce46d 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -481,13 +481,11 @@
         return;
     }
 
-    const GrTextureDesc desc = {
-        kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit,
-        bounds.width(),
-        bounds.height(),
-        kAlpha_8_GrPixelConfig,
-        0           // samples
-    };
+    GrTextureDesc desc;
+    desc.fFlags = kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit;
+    desc.fWidth = bounds.width();
+    desc.fHeight = bounds.height();
+    desc.fConfig = kAlpha_8_GrPixelConfig;
 
     temp->set(this->getContext(), desc);
 }
@@ -499,13 +497,11 @@
     // Free up the currently cached mask so it can be reused
     fAACache.reset();
 
-    const GrTextureDesc desc = {
-        kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit,
-        bounds.width(),
-        bounds.height(),
-        kAlpha_8_GrPixelConfig,
-        0           // samples
-    };
+    GrTextureDesc desc;
+    desc.fFlags = kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit;
+    desc.fWidth = bounds.width();
+    desc.fHeight = bounds.height();
+    desc.fConfig = kAlpha_8_GrPixelConfig;
 
     fAACache.acquireMask(clipIn, desc, bounds);
 }
diff --git a/src/gpu/GrClipMaskManager.h b/src/gpu/GrClipMaskManager.h
index 2f4d8c7..1acdba5 100644
--- a/src/gpu/GrClipMaskManager.h
+++ b/src/gpu/GrClipMaskManager.h
@@ -251,8 +251,7 @@
         void reset () {
             fLastClip.setEmpty();
 
-            const GrTextureDesc desc = { kNone_GrTextureFlags, 0, 0, 
-                                         kUnknown_GrPixelConfig, 0 };
+            GrTextureDesc desc;
 
             fLastMask.set(NULL, desc);
             fLastBound.setEmpty();
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 1c55ecf..3708993 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -252,18 +252,16 @@
 }
 
 GrContext::TextureCacheEntry GrContext::findAndLockTexture(
-        GrTexture::TextureKey key,
         const GrTextureDesc& desc,
         const GrSamplerState* sampler) {
-    GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, key, desc, false);
+    GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, desc, false);
     return TextureCacheEntry(fTextureCache->findAndLock(resourceKey,
                                             GrResourceCache::kNested_LockType));
 }
 
-bool GrContext::isTextureInCache(GrTexture::TextureKey key,
-                                 const GrTextureDesc& desc,
+bool GrContext::isTextureInCache(const GrTextureDesc& desc,
                                  const GrSamplerState* sampler) const {
-    GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, key, desc, false);
+    GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, desc, false);
     return fTextureCache->hasKey(resourceKey);
 }
 
@@ -323,7 +321,6 @@
 }
 
 GrContext::TextureCacheEntry GrContext::createAndLockTexture(
-        GrTexture::TextureKey key,
         const GrSamplerState* sampler,
         const GrTextureDesc& desc,
         void* srcData,
@@ -336,19 +333,18 @@
 
     TextureCacheEntry entry;
 
-    GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, key,
+    GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler,
                                                       desc, false);
 
     if (GrTexture::NeedsResizing(resourceKey)) {
         // The desired texture is NPOT and tiled but that isn't supported by 
         // the current hardware. Resize the texture to be a POT
         GrAssert(NULL != sampler);
-        TextureCacheEntry clampEntry = this->findAndLockTexture(key,
-                                                                desc,
+        TextureCacheEntry clampEntry = this->findAndLockTexture(desc,
                                                                 NULL);
 
         if (NULL == clampEntry.texture()) {
-            clampEntry = this->createAndLockTexture(key, NULL, desc,
+            clampEntry = this->createAndLockTexture(NULL, desc,
                                                     srcData, rowBytes);
             GrAssert(NULL != clampEntry.texture());
             if (NULL == clampEntry.texture()) {
@@ -438,8 +434,9 @@
 GrContext::TextureCacheEntry GrContext::lockScratchTexture(
                                                 const GrTextureDesc& inDesc,
                                                 ScratchTexMatch match) {
-
     GrTextureDesc desc = inDesc;
+    desc.fClientCacheID = kScratch_CacheID;
+
     if (kExact_ScratchTexMatch != match) {
         // bin by pow2 with a reasonable min
         static const int MIN_SIZE = 256;
@@ -454,7 +451,7 @@
     bool doubledH = false;
 
     do {
-        GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, 0, desc, true);
+        GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, desc, true);
         entry = fTextureCache->findAndLock(key,
                                            GrResourceCache::kNested_LockType);
         // if we miss, relax the fit of the flags...
@@ -487,7 +484,7 @@
         desc.fHeight = origHeight;
         GrTexture* texture = fGpu->createTexture(desc, NULL, 0);
         if (NULL != texture) {
-            GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, 0,
+            GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL,
                                                       texture->desc(),
                                                       true);
             entry = fTextureCache->createAndLock(key, texture);
@@ -515,10 +512,12 @@
     }
 }
 
-GrTexture* GrContext::createUncachedTexture(const GrTextureDesc& desc,
+GrTexture* GrContext::createUncachedTexture(const GrTextureDesc& descIn,
                                             void* srcData,
                                             size_t rowBytes) {
-    return fGpu->createTexture(desc, srcData, rowBytes);
+    GrTextureDesc descCopy = descIn;
+    descCopy.fClientCacheID = kUncached_CacheID;
+    return fGpu->createTexture(descCopy, srcData, rowBytes);
 }
 
 void GrContext::getTextureCacheLimits(int* maxTextures,
@@ -1547,12 +1546,11 @@
         }
         // Make the scratch a render target because we don't have a robust
         // readTexturePixels as of yet (it calls this function).
-        const GrTextureDesc desc = {
-            kRenderTarget_GrTextureFlagBit,
-            width, height,
-            config,
-            0 // samples
-        };
+        GrTextureDesc desc;
+        desc.fFlags = kRenderTarget_GrTextureFlagBit;
+        desc.fWidth = width;
+        desc.fHeight = height;
+        desc.fConfig = config;
 
         // When a full readback is faster than a partial we could always make
         // the scratch exactly match the passed rect. However, if we see many
@@ -1705,9 +1703,11 @@
         config = GrPixelConfigSwapRAndB(config);
     }
 
-    const GrTextureDesc desc = {
-        kNone_GrTextureFlags, width, height, config, 0
-    };
+    GrTextureDesc desc;
+    desc.fWidth = width;
+    desc.fHeight = height;
+    desc.fConfig = config;
+
     GrAutoScratchTexture ast(this, desc);
     GrTexture* texture = ast.texture();
     if (NULL == texture) {
@@ -1992,13 +1992,11 @@
              kRGBA_8888_PM_GrPixelConfig == srcTexture->config() ||
              kAlpha_8_GrPixelConfig == srcTexture->config());
 
-    const GrTextureDesc desc = {
-        kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit,
-        SkScalarFloorToInt(srcRect.width()),
-        SkScalarFloorToInt(srcRect.height()),
-        srcTexture->config(), 
-        0 // samples 
-    };
+    GrTextureDesc desc;
+    desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
+    desc.fWidth = SkScalarFloorToInt(srcRect.width());
+    desc.fHeight = SkScalarFloorToInt(srcRect.height());
+    desc.fConfig = srcTexture->config();
 
     temp1->set(this, desc);
     if (temp2) {
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index 99209c6..1213c41 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -201,13 +201,10 @@
  * Get a texture (from the texture cache) of the correct size & format
  */
 bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* tex) {
-    const GrTextureDesc desc = {
-        kNone_GrTextureFlags,
-        fBM.width(),
-        fBM.height(),
-        kAlpha_8_GrPixelConfig,
-        0 // samples
-    };
+    GrTextureDesc desc;
+    desc.fWidth = fBM.width();
+    desc.fHeight = fBM.height();
+    desc.fConfig = kAlpha_8_GrPixelConfig;
 
     tex->set(fContext, desc);
     GrTexture* texture = tex->texture();
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index 8dd0b0b..4f4c5f5 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -107,16 +107,16 @@
 namespace {
 void gen_texture_key_values(const GrGpu* gpu,
                             const GrSamplerState* sampler,
-                            GrTexture::TextureKey clientKey,
                             const GrTextureDesc& desc,
                             bool scratch,
                             uint32_t v[4]) {
-    GR_STATIC_ASSERT(sizeof(GrTexture::TextureKey) == sizeof(uint64_t));
+
+    uint64_t clientKey = desc.fClientCacheID;
 
     if (scratch) {
         // Instead of a client-provided key of the texture contents
         // we create a key of from the descriptor.
-        GrAssert(0 == clientKey);
+        GrAssert(kScratch_CacheID == clientKey);
         clientKey = (desc.fFlags << 8) | ((uint64_t) desc.fConfig << 32);
     }
 
@@ -156,11 +156,10 @@
 
 GrResourceKey GrTexture::ComputeKey(const GrGpu* gpu,
                                     const GrSamplerState* sampler,
-                                    TextureKey clientKey,
                                     const GrTextureDesc& desc,
                                     bool scratch) {
     uint32_t v[4];
-    gen_texture_key_values(gpu, sampler, clientKey, desc, scratch, v);
+    gen_texture_key_values(gpu, sampler, desc, scratch, v);
     return GrResourceKey(v);
 }
 
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index b0ff43a..b62e5be 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -226,13 +226,11 @@
     SkBitmap bm;
     bm.setConfig(config, width, height);
 
-    const GrTextureDesc desc = {
-        kRenderTarget_GrTextureFlagBit,
-        width,
-        height,
-        SkGr::BitmapConfig2PixelConfig(bm.config()),
-        0 // samples
-    };
+    GrTextureDesc desc;
+    desc.fFlags = kRenderTarget_GrTextureFlagBit;
+    desc.fWidth = width;
+    desc.fHeight = height;
+    desc.fConfig = SkGr::BitmapConfig2PixelConfig(bm.config());
 
     fTexture = fContext->createUncachedTexture(desc, NULL, 0);
 
@@ -792,15 +790,13 @@
     }
     GrPoint offset = GrPoint::Make(-srcRect.fLeft, -srcRect.fTop);
     srcRect.offset(offset);
-    GrTextureDesc desc = {
-        kRenderTarget_GrTextureFlagBit,
-        SkScalarCeilToInt(srcRect.width()),
-        SkScalarCeilToInt(srcRect.height()),
-        // We actually only need A8, but it often isn't supported as a
-        // render target so default to RGBA_8888
-        kRGBA_8888_PM_GrPixelConfig,
-        0 // samples
-    };
+    GrTextureDesc desc;
+    desc.fFlags = kRenderTarget_GrTextureFlagBit;
+    desc.fWidth = SkScalarCeilToInt(srcRect.width());
+    desc.fHeight = SkScalarCeilToInt(srcRect.height());
+    // We actually only need A8, but it often isn't supported as a
+    // render target so default to RGBA_8888
+    desc.fConfig = kRGBA_8888_PM_GrPixelConfig;
 
     if (context->isConfigRenderable(kAlpha_8_GrPixelConfig)) {
         desc.fConfig = kAlpha_8_GrPixelConfig;
@@ -930,13 +926,10 @@
 
     GrAutoMatrix avm(context, GrMatrix::I());
 
-    const GrTextureDesc desc = {
-        kNone_GrTextureFlags,
-        dstM.fBounds.width(),
-        dstM.fBounds.height(),
-        kAlpha_8_GrPixelConfig,
-        0, // samples
-    };
+    GrTextureDesc desc;
+    desc.fWidth = dstM.fBounds.width();
+    desc.fHeight = dstM.fBounds.height();
+    desc.fConfig = kAlpha_8_GrPixelConfig;
 
     GrAutoScratchTexture ast(context, desc);
     GrTexture* texture = ast.texture();
@@ -1436,13 +1429,11 @@
     SkSize blurSize;
     SkISize radius;
 
-    const GrTextureDesc desc = {
-        kRenderTarget_GrTextureFlagBit,
-        SkScalarCeilToInt(rect.width()),
-        SkScalarCeilToInt(rect.height()),
-        kRGBA_8888_PM_GrPixelConfig,
-        0 // samples
-    };
+    GrTextureDesc desc;
+    desc.fFlags = kRenderTarget_GrTextureFlagBit,
+    desc.fWidth = SkScalarCeilToInt(rect.width());
+    desc.fHeight = SkScalarCeilToInt(rect.height());
+    desc.fConfig = kRGBA_8888_PM_GrPixelConfig;
 
     if (filter->asABlur(&blurSize)) {
         GrAutoScratchTexture temp1, temp2;
@@ -1833,24 +1824,21 @@
     GrContext* ctx = this->context();
 
     if (!bitmap.isVolatile()) {
-        GrTexture::TextureKey key = bitmap.getGenerationID();
+        uint64_t key = bitmap.getGenerationID();
         key |= ((uint64_t) bitmap.pixelRefOffset()) << 32;
 
-        GrTextureDesc desc = {
-            kNone_GrTextureFlags,
-            bitmap.width(),
-            bitmap.height(),
-            SkGr::BitmapConfig2PixelConfig(bitmap.config()),
-            0 // samples
-        };
+        GrTextureDesc desc;
+        desc.fWidth = bitmap.width();
+        desc.fHeight = bitmap.height();
+        desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap.config());
 
-        entry = ctx->findAndLockTexture(key, desc, sampler);
+        entry = ctx->findAndLockTexture(desc, sampler);
         if (NULL == entry.texture()) {
             entry = sk_gr_create_bitmap_texture(ctx, key, sampler,
                                                 bitmap);
         }
     } else {
-        entry = sk_gr_create_bitmap_texture(ctx, gUNCACHED_KEY,
+        entry = sk_gr_create_bitmap_texture(ctx, kUncached_CacheID,
                                             sampler, bitmap);
     }
     if (NULL == entry.texture()) {
@@ -1866,18 +1854,16 @@
 
 bool SkGpuDevice::isBitmapInTextureCache(const SkBitmap& bitmap,
                                          const GrSamplerState& sampler) const {
-    GrTexture::TextureKey key = bitmap.getGenerationID();
+    uint64_t key = bitmap.getGenerationID();
     key |= ((uint64_t) bitmap.pixelRefOffset()) << 32;
 
-    GrTextureDesc desc = {
-        kNone_GrTextureFlags,
-        bitmap.width(),
-        bitmap.height(),
-        SkGr::BitmapConfig2PixelConfig(bitmap.config()),
-        0 // samples
-    };
+    GrTextureDesc desc;
+    desc.fWidth = bitmap.width();
+    desc.fHeight = bitmap.height();
+    desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap.config());
+    desc.fClientCacheID = key;
 
-    return this->context()->isTextureInCache(key, desc, &sampler);
+    return this->context()->isTextureInCache(desc, &sampler);
 }
 
 
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 00a0282..6fc851a 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -57,7 +57,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
-                                                GrTexture::TextureKey key,
+                                                uint64_t key,
                                                 const GrSamplerState* sampler,
                                                 const SkBitmap& origBitmap) {
     SkAutoLockPixels alp(origBitmap);
@@ -71,13 +71,11 @@
 
     const SkBitmap* bitmap = &origBitmap;
 
-    GrTextureDesc desc = {
-        kNone_GrTextureFlags,
-        bitmap->width(),
-        bitmap->height(),
-        SkGr::BitmapConfig2PixelConfig(bitmap->config()),
-        0 // samples
-    };
+    GrTextureDesc desc;
+    desc.fWidth = bitmap->width();
+    desc.fHeight = bitmap->height();
+    desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap->config());
+    desc.fClientCacheID = key;
 
     if (SkBitmap::kIndex8_Config == bitmap->config()) {
         // build_compressed_data doesn't do npot->pot expansion
@@ -93,8 +91,8 @@
             // our compressed data will be trimmed, so pass width() for its
             // "rowBytes", since they are the same now.
             
-            if (gUNCACHED_KEY != key) {
-                return ctx->createAndLockTexture(key, sampler, desc, storage.get(),
+            if (kUncached_CacheID != key) {
+                return ctx->createAndLockTexture(sampler, desc, storage.get(),
                                                  bitmap->width());
             } else {
                 entry = ctx->lockScratchTexture(desc,
@@ -113,8 +111,8 @@
     }
 
     desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap->config());
-    if (gUNCACHED_KEY != key) {
-        return ctx->createAndLockTexture(key, sampler, desc,
+    if (kUncached_CacheID != key) {
+        return ctx->createAndLockTexture(sampler, desc,
                                          bitmap->getPixels(),
                                          bitmap->rowBytes());
     } else {
diff --git a/src/gpu/SkGrTexturePixelRef.cpp b/src/gpu/SkGrTexturePixelRef.cpp
index 485d572..0caf0b4 100644
--- a/src/gpu/SkGrTexturePixelRef.cpp
+++ b/src/gpu/SkGrTexturePixelRef.cpp
@@ -63,7 +63,6 @@
     desc.fHeight = texture->height();
     desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
     desc.fConfig = SkGr::BitmapConfig2PixelConfig(dstConfig);
-    desc.fSampleCnt = 0;
 
     GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
     if (NULL == dst) {
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index d5c0bd2..da168cd 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -375,7 +375,6 @@
         dstDesc.fWidth = 256;
         dstDesc.fHeight = 256;
         dstDesc.fConfig = kRGBA_8888_PM_GrPixelConfig;
-        dstDesc.fSampleCnt = 0;
 
         SkAutoTUnref<GrTexture> dstTex(this->createTexture(dstDesc, NULL, 0));
         if (!dstTex.get()) {
@@ -1015,6 +1014,7 @@
     glTexDesc.fHeight = desc.fHeight;
     glTexDesc.fConfig = desc.fConfig;
     glTexDesc.fSampleCnt = desc.fSampleCnt;
+    glTexDesc.fClientCacheID = desc.fClientCacheID;
 
     glTexDesc.fOwnsID = true;