Add lockKeylessTexture() for caching texture without a content key.

Review URL: http://codereview.appspot.com/4440065/




git-svn-id: http://skia.googlecode.com/svn/trunk@1172 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 1c797c3..036d9b5 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -192,8 +192,7 @@
     if (fCache) {
         GrAssert(NULL != fTexture);
         GrAssert(fRenderTarget == fTexture->asRenderTarget());
-        // IMPORTANT: reattach the rendertarget/tex back to the cache.
-        fContext->reattachAndUnlockCachedTexture((GrTextureEntry*)fCache);
+        fContext->unlockTexture((GrTextureEntry*)fCache);
     } else if (NULL != fTexture) {
         GrAssert(!CACHE_LAYER_TEXTURES);
         GrAssert(fRenderTarget == fTexture->asRenderTarget());
@@ -655,34 +654,34 @@
 
 void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
                           const SkPaint& paint) {
-    CHECK_SHOULD_DRAW(draw);

-

-    bool doStroke = paint.getStyle() == SkPaint::kStroke_Style;

-    SkScalar width = paint.getStrokeWidth();

-

-    /*

-        We have special code for hairline strokes, miter-strokes, and fills.

-        Anything else we just call our path code.

-     */

-    bool usePath = doStroke && width > 0 &&

-                    paint.getStrokeJoin() != SkPaint::kMiter_Join;

-    // another reason we might need to call drawPath...

-    if (paint.getMaskFilter()) {

-        usePath = true;

-    }

-

-    if (usePath) {

-        SkPath path;

-        path.addRect(rect);

-        this->drawPath(draw, path, paint, NULL, true);

-        return;

-    }

-

-    GrPaint grPaint;

-    SkAutoCachedTexture act;

-    if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix,  &grPaint)) {

-        return;

-    }

+    CHECK_SHOULD_DRAW(draw);
+
+    bool doStroke = paint.getStyle() == SkPaint::kStroke_Style;
+    SkScalar width = paint.getStrokeWidth();
+
+    /*
+        We have special code for hairline strokes, miter-strokes, and fills.
+        Anything else we just call our path code.
+     */
+    bool usePath = doStroke && width > 0 &&
+                    paint.getStrokeJoin() != SkPaint::kMiter_Join;
+    // another reason we might need to call drawPath...
+    if (paint.getMaskFilter()) {
+        usePath = true;
+    }
+
+    if (usePath) {
+        SkPath path;
+        path.addRect(rect);
+        this->drawPath(draw, path, paint, NULL, true);
+        return;
+    }
+
+    GrPaint grPaint;
+    SkAutoCachedTexture act;
+    if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix,  &grPaint)) {
+        return;
+    }
     fContext->drawRect(grPaint, Sk2Gr(rect), doStroke ? width : -1);
 }
 
@@ -720,9 +719,9 @@
 
     GrAutoMatrix avm(context, GrMatrix::I());
 
-    const GrGpu::TextureDesc desc = {
-        0,
-        GrGpu::kNone_AALevel,
+    const GrTextureDesc desc = {
+        kNone_GrTextureFlags,
+        kNone_GrAALevel,
         dstM.fBounds.width(),
         dstM.fBounds.height(),
         kAlpha_8_GrPixelConfig
@@ -1242,40 +1241,36 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 SkGpuDevice::TexCache* SkGpuDevice::lockCachedTexture(const SkBitmap& bitmap,
-                                                  const GrSamplerState& sampler,
-                                                  GrTexture** texture,
-                                                  bool forDeviceRenderTarget) {
+                                                      const GrSamplerState& sampler,
+                                                      GrTexture** texture,
+                                                      bool forDeviceRenderTarget) {
+    GrTexture* newTexture = NULL;
+    GrTextureEntry* entry = NULL;
     GrContext* ctx = this->context();
-    uint32_t p0, p1;
+
     if (forDeviceRenderTarget) {
-        p0 = p1 = -1;
+        const GrTextureDesc desc = {
+            kRenderTarget_GrTextureFlagBit,
+            kNone_GrAALevel,
+            bitmap.width(),
+            bitmap.height(),
+            SkGr::Bitmap2PixelConfig(bitmap)
+        };
+        entry = ctx->lockKeylessTexture(desc, sampler);
     } else {
+        uint32_t p0, p1;
         p0 = bitmap.getGenerationID();
         p1 = bitmap.pixelRefOffset();
-    }
 
-    GrTexture* newTexture = NULL;
-    GrTextureKey key(p0, p1, bitmap.width(), bitmap.height());
-    GrTextureEntry* entry = ctx->findAndLockTexture(&key, sampler);
+        GrTextureKey key(p0, p1, bitmap.width(), bitmap.height());
+        entry = ctx->findAndLockTexture(&key, sampler);
 
-    if (NULL == entry) {
-
-        if (forDeviceRenderTarget) {
-            const GrGpu::TextureDesc desc = {
-                GrGpu::kRenderTarget_TextureFlag,
-                GrGpu::kNone_AALevel,
-                bitmap.width(),
-                bitmap.height(),
-                SkGr::Bitmap2PixelConfig(bitmap)
-            };
-            entry = ctx->createAndLockTexture(&key, sampler, desc, NULL, 0);
-
-        } else {
-            entry = sk_gr_create_bitmap_texture(ctx, &key, sampler, bitmap);
-        }
         if (NULL == entry) {
-            GrPrintf("---- failed to create texture for cache [%d %d]\n",
-                     bitmap.width(), bitmap.height());
+            entry = sk_gr_create_bitmap_texture(ctx, &key, sampler, bitmap);
+            if (NULL == entry) {
+                GrPrintf("---- failed to create texture for cache [%d %d]\n",
+                         bitmap.width(), bitmap.height());
+            }
         }
     }
 
@@ -1284,11 +1279,6 @@
         if (texture) {
             *texture = newTexture;
         }
-        // IMPORTANT: We can't allow another SkGpuDevice to get this
-        // cache entry until this one is destroyed!
-        if (forDeviceRenderTarget) {
-            ctx->detachCachedTexture(entry);
-        }
     }
     return (TexCache*)entry;
 }