Add gm for displaying different variants of 8888 bitmaps and fix a small rejection...
authorherb <herb@google.com>
Fri, 3 Jun 2016 16:44:53 +0000 (09:44 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 3 Jun 2016 16:44:53 +0000 (09:44 -0700)
BUG=skia:5378
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2036493004

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

gm/all_bitmap_configs.cpp
src/core/SkBlitter_Sprite.cpp

index bc296fc..7ea1746 100644 (file)
@@ -191,7 +191,6 @@ DEF_SIMPLE_GM(all_bitmap_configs, canvas, SCALE, 6 * SCALE) {
     draw(canvas, p, bitmapG8, kGray_8_SkColorType, "Gray 8");
 }
 
-// Works on Ganesh, fails on Raster.
 sk_sp<SkImage> make_not_native32_color_wheel() {
     SkBitmap n32bitmap, notN32bitmap;
     n32bitmap.allocN32Pixels(SCALE, SCALE);
@@ -216,3 +215,70 @@ DEF_SIMPLE_GM(not_native32_bitmap_config, canvas, SCALE, SCALE) {
     sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
     canvas->drawImage(notN32image.get(), 0.0f, 0.0f);
 }
+
+static uint32_t make_pixel(int x, int y, SkAlphaType alphaType) {
+    SkASSERT(x >= 0 && x < SCALE);
+    SkASSERT(y >= 0 && y < SCALE);
+
+    SkScalar R = SCALE / 2.0f;
+
+    uint32_t alpha = 0x00;
+
+    if ((x - R) * (x - R) + (y - R) * (y - R) < R * R) {
+        alpha = 0xFF;
+    }
+
+    uint32_t component;
+    switch (alphaType) {
+        case kPremul_SkAlphaType:
+            component = alpha;
+            break;
+        case kUnpremul_SkAlphaType:
+            component = 0xFF;
+            break;
+        default:
+            SkFAIL("Should not get here - invalid alpha type");
+            return 0xFF000000;
+    }
+    return alpha << 24 | component;
+}
+
+static void make_color_test_bitmap_variant(
+    SkColorType colorType,
+    SkAlphaType alphaType,
+    SkColorProfileType profile,
+    SkBitmap* bm)
+{
+    SkASSERT(colorType == kRGBA_8888_SkColorType || colorType == kBGRA_8888_SkColorType);
+    SkASSERT(alphaType == kPremul_SkAlphaType || alphaType == kUnpremul_SkAlphaType);
+    bm->allocPixels(
+        SkImageInfo::Make(SCALE, SCALE, colorType, alphaType, profile));
+    SkPixmap pm;
+    bm->peekPixels(&pm);
+    for (int y = 0; y < bm->height(); y++) {
+        for (int x = 0; x < bm->width(); x++) {
+            *pm.writable_addr32(x, y) = make_pixel(x, y, alphaType);
+        }
+    }
+}
+
+DEF_SIMPLE_GM(all_variants_8888, canvas, 4 * SCALE + 30, 2 * SCALE + 10) {
+    sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
+
+    for (auto profile : {kSRGB_SkColorProfileType, kLinear_SkColorProfileType}) {
+        canvas->save();
+        for (auto alphaType : {kPremul_SkAlphaType, kUnpremul_SkAlphaType}) {
+            canvas->save();
+            for (auto colorType : {kRGBA_8888_SkColorType, kBGRA_8888_SkColorType}) {
+                SkBitmap bm;
+                make_color_test_bitmap_variant(colorType, alphaType, profile, &bm);
+                canvas->drawBitmap(bm, 0.0f, 0.0f);
+                canvas->translate(SCALE + 10, 0.0f);
+            }
+            canvas->restore();
+            canvas->translate(0.0f, SCALE + 10);
+        }
+        canvas->restore();
+        canvas->translate(2 * (SCALE + 10), 0.0f);
+    }
+}
index 2ddc5f4..dc912b0 100644 (file)
@@ -149,6 +149,12 @@ SkBlitter* SkBlitter::ChooseSprite(const SkPixmap& dst, const SkPaint& paint,
     */
     SkASSERT(allocator != nullptr);
 
+    // Defer to the general code if the pixels are unpremultipled. This case is not common,
+    // and this simplifies the code.
+    if (source.alphaType() == kUnpremul_SkAlphaType) {
+        return nullptr;
+    }
+
     SkSpriteBlitter* blitter = nullptr;
 
     if (SkSpriteBlitter_Src_SrcOver::Supports(dst, source, paint)) {