aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/all_bitmap_configs.cpp
diff options
context:
space:
mode:
authorGravatar herb <herb@google.com>2016-06-03 09:44:53 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-03 09:44:53 -0700
commit5823846397066377b65e011a42becd2d665110ad (patch)
tree6b1f132de5ecf30f9fefe5724670f0855127bedd /gm/all_bitmap_configs.cpp
parentae92262f3ba5b3412ff468877277d817f1b61308 (diff)
Add gm for displaying different variants of 8888 bitmaps and fix a small rejection case for sprite blitters.
Diffstat (limited to 'gm/all_bitmap_configs.cpp')
-rw-r--r--gm/all_bitmap_configs.cpp68
1 files changed, 67 insertions, 1 deletions
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<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);
+ }
+}