Never use CPU-built mips for Gray_8.
authorbrianosman <brianosman@google.com>
Tue, 21 Jun 2016 19:08:24 +0000 (12:08 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 21 Jun 2016 19:08:24 +0000 (12:08 -0700)
Fixes a bug where Gray_8 textures would still render as Alpha_8 (if the
first draw was detected as needing mips).

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2088883002

Review-Url: https://codereview.chromium.org/2088883002

src/gpu/SkGr.cpp

index f937b16..1e4ff52 100644 (file)
@@ -349,6 +349,15 @@ GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b
         return texture.release();
     }
 
+    // We don't support Gray8 directly in the GL backend, so fail-over to GrUploadBitmapToTexture.
+    // That will transform the Gray8 to 8888, then use the driver/GPU to build mipmaps. If we build
+    // the mips on the CPU here, they'll all be Gray8, which isn't useful. (They get treated as A8).
+    // TODO: A better option might be to transform the initial bitmap here to 8888, then run the
+    // CPU mip-mapper on that data before uploading. This is much less code for a rare case though:
+    if (kGray_8_SkColorType == bitmap.colorType()) {
+        return nullptr;
+    }
+
     SkASSERT(sizeof(int) <= sizeof(uint32_t));
     if (bitmap.width() < 0 || bitmap.height() < 0) {
         return nullptr;