explictly fail to draw unpremul, as this is buggy, incomplete, tricky, and unused
BUG=skia: Change-Id: Ie9da6015cc4955c0f27f6db53fc6ae532e0132f4 Reviewed-on: https://skia-review.googlesource.com/7304 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Matt Sarett <msarett@google.com>
This commit is contained in:
parent
43ae4b4e6b
commit
1baaacac74
@ -260,27 +260,37 @@ static void make_color_test_bitmap_variant(
|
||||
*pm.writable_addr32(x, y) = make_pixel(x, y, alphaType);
|
||||
}
|
||||
}
|
||||
bm->setImmutable();
|
||||
}
|
||||
|
||||
DEF_SIMPLE_GM(all_variants_8888, canvas, 4 * SCALE + 30, 2 * SCALE + 10) {
|
||||
DEF_SIMPLE_GM(all_variants_8888, canvas, 4 * SCALE + 30, 4 * SCALE + 30) {
|
||||
sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
|
||||
|
||||
sk_sp<SkColorSpace> colorSpaces[] {
|
||||
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named),
|
||||
nullptr,
|
||||
};
|
||||
|
||||
SkPaint rectPaint;
|
||||
rectPaint.setColor(0x8000FF00);
|
||||
SkRect r = { 0, 0, SCALE, SCALE };
|
||||
|
||||
for (auto colorSpace : colorSpaces) {
|
||||
canvas->save();
|
||||
// unpremul is expected to *not* draw anything
|
||||
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, colorSpace, &bm);
|
||||
canvas->drawRect(r, rectPaint);
|
||||
canvas->drawBitmap(bm, 0.0f, 0.0f);
|
||||
canvas->drawRect(r.makeOffset(0, SCALE + 10), rectPaint);
|
||||
canvas->drawImage(SkImage::MakeFromBitmap(bm), 0, SCALE + 10, nullptr);
|
||||
canvas->translate(SCALE + 10, 0.0f);
|
||||
}
|
||||
canvas->restore();
|
||||
canvas->translate(0.0f, SCALE + 10);
|
||||
canvas->translate(0.0f, (SCALE + 10) * 2);
|
||||
}
|
||||
canvas->restore();
|
||||
canvas->translate(2 * (SCALE + 10), 0.0f);
|
||||
|
@ -40,8 +40,8 @@ enum SkAlphaType {
|
||||
* All pixels have their color components stored without any regard to the
|
||||
* alpha. e.g. this is the default configuration for PNG images.
|
||||
*
|
||||
* This alpha-type is ONLY supported for input images. Rendering cannot
|
||||
* generate this on output.
|
||||
* This alpha-type is ONLY supported for readPixels/writePixels operations,
|
||||
* and is not supported for drawing.
|
||||
*/
|
||||
kUnpremul_SkAlphaType,
|
||||
|
||||
|
@ -53,6 +53,12 @@
|
||||
|
||||
#define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0)
|
||||
|
||||
#define RETURN_ON_UNPREMUL_IMAGE(image) \
|
||||
do { if (as_IB(image)->onAlphaType() == kUnpremul_SkAlphaType) return; } while (0)
|
||||
|
||||
#define RETURN_ON_UNPREMUL_BITMAP(bitmap) \
|
||||
do { if (bitmap.alphaType() == kUnpremul_SkAlphaType) return; } while (0)
|
||||
|
||||
/*
|
||||
* Return true if the drawing this rect would hit every pixels in the canvas.
|
||||
*
|
||||
@ -1909,12 +1915,14 @@ void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
|
||||
|
||||
void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) {
|
||||
RETURN_ON_NULL(image);
|
||||
RETURN_ON_UNPREMUL_IMAGE(image);
|
||||
this->onDrawImage(image, x, y, paint);
|
||||
}
|
||||
|
||||
void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
|
||||
const SkPaint* paint, SrcRectConstraint constraint) {
|
||||
RETURN_ON_NULL(image);
|
||||
RETURN_ON_UNPREMUL_IMAGE(image);
|
||||
if (dst.isEmpty() || src.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -1924,12 +1932,14 @@ void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRe
|
||||
void SkCanvas::drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
|
||||
const SkPaint* paint, SrcRectConstraint constraint) {
|
||||
RETURN_ON_NULL(image);
|
||||
RETURN_ON_UNPREMUL_IMAGE(image);
|
||||
this->drawImageRect(image, SkRect::Make(isrc), dst, paint, constraint);
|
||||
}
|
||||
|
||||
void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint,
|
||||
SrcRectConstraint constraint) {
|
||||
RETURN_ON_NULL(image);
|
||||
RETURN_ON_UNPREMUL_IMAGE(image);
|
||||
this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, paint,
|
||||
constraint);
|
||||
}
|
||||
@ -1937,6 +1947,7 @@ void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst, const SkPa
|
||||
void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
|
||||
const SkPaint* paint) {
|
||||
RETURN_ON_NULL(image);
|
||||
RETURN_ON_UNPREMUL_IMAGE(image);
|
||||
if (dst.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -1950,6 +1961,7 @@ void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const
|
||||
void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
|
||||
const SkPaint* paint) {
|
||||
RETURN_ON_NULL(image);
|
||||
RETURN_ON_UNPREMUL_IMAGE(image);
|
||||
if (dst.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -1972,6 +1984,7 @@ void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons
|
||||
if (bitmap.drawsNothing()) {
|
||||
return;
|
||||
}
|
||||
RETURN_ON_UNPREMUL_BITMAP(bitmap);
|
||||
this->onDrawBitmap(bitmap, dx, dy, paint);
|
||||
}
|
||||
|
||||
@ -1980,6 +1993,7 @@ void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const S
|
||||
if (bitmap.drawsNothing() || dst.isEmpty() || src.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
RETURN_ON_UNPREMUL_BITMAP(bitmap);
|
||||
this->onDrawBitmapRect(bitmap, &src, dst, paint, constraint);
|
||||
}
|
||||
|
||||
@ -1999,6 +2013,7 @@ void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con
|
||||
if (bitmap.drawsNothing() || dst.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
RETURN_ON_UNPREMUL_BITMAP(bitmap);
|
||||
if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), center)) {
|
||||
this->onDrawBitmapNine(bitmap, center, dst, paint);
|
||||
} else {
|
||||
@ -2011,6 +2026,7 @@ void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
|
||||
if (bitmap.drawsNothing() || dst.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
RETURN_ON_UNPREMUL_BITMAP(bitmap);
|
||||
|
||||
SkIRect bounds;
|
||||
Lattice latticePlusBounds = lattice;
|
||||
@ -2030,10 +2046,10 @@ void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk
|
||||
const SkColor colors[], int count, SkBlendMode mode,
|
||||
const SkRect* cull, const SkPaint* paint) {
|
||||
RETURN_ON_NULL(atlas);
|
||||
RETURN_ON_UNPREMUL_IMAGE(atlas);
|
||||
if (count <= 0) {
|
||||
return;
|
||||
}
|
||||
SkASSERT(atlas);
|
||||
SkASSERT(tex);
|
||||
this->onDrawAtlas(atlas, xform, tex, colors, count, mode, cull, paint);
|
||||
}
|
||||
|
@ -103,6 +103,10 @@ static bool bitmap_is_too_big(int w, int h) {
|
||||
sk_sp<SkShader> SkImageShader::Make(sk_sp<SkImage> image, TileMode tx, TileMode ty,
|
||||
const SkMatrix* localMatrix,
|
||||
SkTBlitterAllocator* allocator) {
|
||||
if (image && as_IB(image)->onAlphaType() == kUnpremul_SkAlphaType) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkShader* shader;
|
||||
if (!image || bitmap_is_too_big(image->width(), image->height())) {
|
||||
if (nullptr == allocator) {
|
||||
|
Loading…
Reference in New Issue
Block a user