Move texture lock/unlock functions from SkGpuDevice into SkGr as global functions, also removed inconsistent "SkGr" class.
Review URL: https://codereview.appspot.com/6420048

git-svn-id: http://skia.googlecode.com/svn/trunk@4664 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h
index 2390cdb..2af1149 100644
--- a/include/gpu/SkGpuDevice.h
+++ b/include/gpu/SkGpuDevice.h
@@ -117,11 +117,8 @@
 
 protected:
     typedef GrContext::TextureCacheEntry TexCache;
-    TexCache lockCachedTexture(const SkBitmap& bitmap,
-                               const GrSamplerState* sampler);
     bool isBitmapInTextureCache(const SkBitmap& bitmap,
                                 const GrSamplerState& sampler) const;
-    void unlockCachedTexture(TexCache);
 
     // overrides from SkDevice
     virtual bool onReadPixels(const SkBitmap& bitmap,
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index 44a351e..975a1ba 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -68,23 +68,28 @@
 
 #include "SkColorPriv.h"
 
-class SkGr {
-public:
-    /**
-     *  Convert the SkBitmap::Config to the corresponding PixelConfig, or
-     *  kUnknown_PixelConfig if the conversion cannot be done.
-     */
-    static GrPixelConfig BitmapConfig2PixelConfig(SkBitmap::Config);
+/**
+ *  Convert the SkBitmap::Config to the corresponding PixelConfig, or
+ *  kUnknown_PixelConfig if the conversion cannot be done.
+ */
+GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config);
 
-    static GrColor SkColor2GrColor(SkColor c) {
-        SkPMColor pm = SkPreMultiplyColor(c);
-        unsigned r = SkGetPackedR32(pm);
-        unsigned g = SkGetPackedG32(pm);
-        unsigned b = SkGetPackedB32(pm);
-        unsigned a = SkGetPackedA32(pm);
-        return GrColorPackRGBA(r, g, b, a);
-    }
-};
+static inline GrColor SkColor2GrColor(SkColor c) {
+    SkPMColor pm = SkPreMultiplyColor(c);
+    unsigned r = SkGetPackedR32(pm);
+    unsigned g = SkGetPackedG32(pm);
+    unsigned b = SkGetPackedB32(pm);
+    unsigned a = SkGetPackedA32(pm);
+    return GrColorPackRGBA(r, g, b, a);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext* ctx, 
+                                               const SkBitmap& bitmap,
+                                               const GrSamplerState* sampler);
+
+void GrUnlockCachedBitmapTexture(GrContext* ctx, GrContext::TextureCacheEntry cache);
 
 ////////////////////////////////////////////////////////////////////////////////
 // Classes
@@ -150,12 +155,5 @@
 };
 
 ////////////////////////////////////////////////////////////////////////////////
-// Helper functions
-
-GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
-                                                uint64_t key,
-                                                const GrSamplerState* sampler,
-                                                const SkBitmap& bitmap);
-
 
 #endif
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index ed52848..605b640 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -93,7 +93,7 @@
 
     ~SkAutoCachedTexture() {
         if (fTex.texture()) {
-            fDevice->unlockCachedTexture(fTex);
+            GrUnlockCachedBitmapTexture(fDevice->context(), fTex);
         }
     }
 
@@ -101,7 +101,7 @@
                    const SkBitmap& bitmap,
                    const GrSamplerState* sampler) {
         if (fTex.texture()) {
-            fDevice->unlockCachedTexture(fTex);
+            GrUnlockCachedBitmapTexture(fDevice->context(), fTex);
         }
         fDevice = device;
         GrTexture* texture = (GrTexture*)bitmap.getTexture();
@@ -110,7 +110,7 @@
             fTex.reset();
         } else {
             // look it up in our cache
-            fTex = device->lockCachedTexture(bitmap, sampler);
+            fTex = GrLockCachedBitmapTexture(device->context(), bitmap, sampler);
             texture = fTex.texture();
         }
         return texture;
@@ -238,7 +238,7 @@
     desc.fFlags = kRenderTarget_GrTextureFlagBit;
     desc.fWidth = width;
     desc.fHeight = height;
-    desc.fConfig = SkGr::BitmapConfig2PixelConfig(bm.config());
+    desc.fConfig = SkBitmapConfig2GrPixelConfig(bm.config());
 
     fTexture = fContext->createUncachedTexture(desc, NULL, 0);
 
@@ -341,7 +341,7 @@
     if (SkBitmap::kARGB_8888_Config == bitmap.config()) {
         config = config8888_to_gr_config(config8888);
     } else {
-        config= SkGr::BitmapConfig2PixelConfig(bitmap.config());
+        config= SkBitmapConfig2GrPixelConfig(bitmap.config());
     }
 
     fRenderTarget->writePixels(x, y, bitmap.width(), bitmap.height(),
@@ -484,7 +484,7 @@
         // so constantColor should not also be true.
         GrAssert(!constantColor);
     } else {
-        grPaint->fColor = SkGr::SkColor2GrColor(skPaint.getColor());
+        grPaint->fColor = SkColor2GrColor(skPaint.getColor());
         grPaint->setTexture(kShaderTextureIdx, NULL);
     }
     SkColorFilter* colorFilter = skPaint.getColorFilter();
@@ -495,11 +495,11 @@
     if (colorFilter != NULL && colorFilter->asColorMode(&color, &filterMode)) {
         grPaint->fColorMatrixEnabled = false;
         if (!constantColor) {
-            grPaint->fColorFilterColor = SkGr::SkColor2GrColor(color);
+            grPaint->fColorFilterColor = SkColor2GrColor(color);
             grPaint->fColorFilterXfermode = filterMode;
         } else {
             SkColor filtered = colorFilter->filterColor(skPaint.getColor());
-            grPaint->fColor = SkGr::SkColor2GrColor(filtered);
+            grPaint->fColor = SkColor2GrColor(filtered);
             grPaint->resetColorFilter();
         }
     } else if (colorFilter != NULL && colorFilter->asColorMatrix(matrix)) {
@@ -1738,7 +1738,7 @@
         // need to convert byte order and from non-PM to PM
         convertedColors.reset(vertexCount);
         for (int i = 0; i < vertexCount; ++i) {
-            convertedColors[i] = SkGr::SkColor2GrColor(colors[i]);
+            convertedColors[i] = SkColor2GrColor(colors[i]);
         }
         colors = convertedColors.get();
     }
@@ -1902,42 +1902,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkGpuDevice::TexCache SkGpuDevice::lockCachedTexture(
-                                            const SkBitmap& bitmap,
-                                            const GrSamplerState* sampler) {
-    GrContext::TextureCacheEntry entry;
-    GrContext* ctx = this->context();
-
-    if (!bitmap.isVolatile()) {
-        uint64_t key = bitmap.getGenerationID();
-        key |= ((uint64_t) bitmap.pixelRefOffset()) << 32;
-
-        GrTextureDesc desc;
-        desc.fWidth = bitmap.width();
-        desc.fHeight = bitmap.height();
-        desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap.config());
-        desc.fClientCacheID = key;
-
-        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, kUncached_CacheID,
-                                            sampler, bitmap);
-    }
-    if (NULL == entry.texture()) {
-        GrPrintf("---- failed to create texture for cache [%d %d]\n",
-                    bitmap.width(), bitmap.height());
-    }
-    return entry;
-}
-
-void SkGpuDevice::unlockCachedTexture(TexCache cache) {
-    this->context()->unlockTexture(cache);
-}
-
 bool SkGpuDevice::isBitmapInTextureCache(const SkBitmap& bitmap,
                                          const GrSamplerState& sampler) const {
     uint64_t key = bitmap.getGenerationID();
@@ -1946,7 +1910,7 @@
     GrTextureDesc desc;
     desc.fWidth = bitmap.width();
     desc.fHeight = bitmap.height();
-    desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap.config());
+    desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap.config());
     desc.fClientCacheID = key;
 
     return this->context()->isTextureInCache(desc, &sampler);
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 6fc851a..41f50f5 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -56,7 +56,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
+static GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
                                                 uint64_t key,
                                                 const GrSamplerState* sampler,
                                                 const SkBitmap& origBitmap) {
@@ -74,7 +74,7 @@
     GrTextureDesc desc;
     desc.fWidth = bitmap->width();
     desc.fHeight = bitmap->height();
-    desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap->config());
+    desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config());
     desc.fClientCacheID = key;
 
     if (SkBitmap::kIndex8_Config == bitmap->config()) {
@@ -110,7 +110,7 @@
         }
     }
 
-    desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap->config());
+    desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config());
     if (kUncached_CacheID != key) {
         return ctx->createAndLockTexture(sampler, desc,
                                          bitmap->getPixels(),
@@ -129,6 +129,42 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
+GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext* ctx, 
+                      const SkBitmap& bitmap, const GrSamplerState* sampler) {
+    GrContext::TextureCacheEntry entry;
+
+    if (!bitmap.isVolatile()) {
+        uint64_t key = bitmap.getGenerationID();
+        key |= ((uint64_t) bitmap.pixelRefOffset()) << 32;
+
+        GrTextureDesc desc;
+        desc.fWidth = bitmap.width();
+        desc.fHeight = bitmap.height();
+        desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap.config());
+        desc.fClientCacheID = key;
+
+        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, kUncached_CacheID,
+                                            sampler, bitmap);
+    }
+    if (NULL == entry.texture()) {
+        GrPrintf("---- failed to create texture for cache [%d %d]\n",
+                    bitmap.width(), bitmap.height());
+    }
+    return entry;
+}
+
+void GrUnlockCachedBitmapTexture(GrContext* ctx, GrContext::TextureCacheEntry cache) {
+    ctx->unlockTexture(cache);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
 void SkGrClipIterator::reset(const SkClipStack& clipStack) {
     fClipStack = &clipStack;
     fIter.reset(clipStack);
@@ -192,7 +228,7 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-GrPixelConfig SkGr::BitmapConfig2PixelConfig(SkBitmap::Config config) {
+GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config config) {
     switch (config) {
         case SkBitmap::kA8_Config:
             return kAlpha_8_GrPixelConfig;
diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp
index 7e0e2cd..05c3f02 100644
--- a/src/gpu/SkGrPixelRef.cpp
+++ b/src/gpu/SkGrPixelRef.cpp
@@ -62,7 +62,7 @@
     desc.fWidth  = texture->width();
     desc.fHeight = texture->height();
     desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
-    desc.fConfig = SkGr::BitmapConfig2PixelConfig(dstConfig);
+    desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig);
 
     GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
     if (NULL == dst) {