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
This commit is contained in:
herb 2016-06-03 09:44:53 -07:00 committed by Commit bot
parent ae92262f3b
commit 5823846397
2 changed files with 73 additions and 1 deletions

View 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);
}
}

View 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)) {