Reland r9043 with fix.



git-svn-id: http://skia.googlecode.com/svn/trunk@9046 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index d76a34a..23aa49b 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -24,7 +24,7 @@
 static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
     SkASSERT(SkBitmap::kIndex8_Config == bitmap.config());
 
-    SkAutoLockPixels apl(bitmap);
+    SkAutoLockPixels alp(bitmap);
     if (!bitmap.readyToDraw()) {
         SkDEBUGFAIL("bitmap not ready to draw!");
         return;
@@ -88,12 +88,6 @@
                                               bool cache,
                                               const GrTextureParams* params,
                                               const SkBitmap& origBitmap) {
-    SkAutoLockPixels alp(origBitmap);
-
-    if (!origBitmap.readyToDraw()) {
-        return NULL;
-    }
-
     SkBitmap tmpBitmap;
 
     const SkBitmap* bitmap = &origBitmap;
@@ -104,10 +98,8 @@
     if (SkBitmap::kIndex8_Config == bitmap->config()) {
         // build_compressed_data doesn't do npot->pot expansion
         // and paletted textures can't be sub-updated
-        if (ctx->supportsIndex8PixelConfig(params,
-                                           bitmap->width(), bitmap->height())) {
-            size_t imagesize = bitmap->width() * bitmap->height() +
-                                kGrColorTableSize;
+        if (ctx->supportsIndex8PixelConfig(params, bitmap->width(), bitmap->height())) {
+            size_t imagesize = bitmap->width() * bitmap->height() + kGrColorTableSize;
             SkAutoMalloc storage(imagesize);
 
             build_compressed_data(storage.get(), origBitmap);
@@ -135,6 +127,10 @@
         }
     }
 
+    SkAutoLockPixels alp(*bitmap);
+    if (!bitmap->readyToDraw()) {
+        return NULL;
+    }
     if (cache) {
         // This texture is likely to be used again so leave it in the cache
         GrCacheID cacheID;