From 5823846397066377b65e011a42becd2d665110ad Mon Sep 17 00:00:00 2001 From: herb Date: Fri, 3 Jun 2016 09:44:53 -0700 Subject: Add gm for displaying different variants of 8888 bitmaps and fix a small rejection case for sprite blitters. 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 | 68 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'gm/all_bitmap_configs.cpp') diff --git a/gm/all_bitmap_configs.cpp b/gm/all_bitmap_configs.cpp index bc296fcbe4..7ea17466d9 100644 --- a/gm/all_bitmap_configs.cpp +++ b/gm/all_bitmap_configs.cpp @@ -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 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); + } +} -- cgit v1.2.3