Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: gm/all_bitmap_configs.cpp

Issue 2036493004: Add gm for displaying different variants of 8888. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Sync pdf Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/core/SkBlitter_Sprite.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/all_bitmap_configs.cpp
diff --git a/gm/all_bitmap_configs.cpp b/gm/all_bitmap_configs.cpp
index bc296fcbe434c74765a854b975115c5f2d278efd..7ea17466d928ec42bf64a520c250bcc0d18c3fc1 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);
+ }
+}
« no previous file with comments | « no previous file | src/core/SkBlitter_Sprite.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698