diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-10-21 14:00:07 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-10-21 14:00:07 +0000 |
commit | 383a697692cf46951fd451f6f4c3d03634a6a1cb (patch) | |
tree | a1dac6fe4fa0e4d34d032e70ff85503843ad39b8 | |
parent | c2eae4795478ab134a2315b1a9ff2c5de1d049e4 (diff) |
store SkAlphaType inside SkBitmap, on road to support unpremul
BUG=
R=bsalomon@google.com, scroggo@google.com
Review URL: https://codereview.chromium.org/25275004
git-svn-id: http://skia.googlecode.com/svn/trunk@11877 2bbb7eff-a529-9590-31e7-b0007b416f81
39 files changed, 206 insertions, 224 deletions
diff --git a/bench/BitmapBench.cpp b/bench/BitmapBench.cpp index 982c917c02..6dc759283e 100644 --- a/bench/BitmapBench.cpp +++ b/bench/BitmapBench.cpp @@ -126,7 +126,7 @@ protected: fBitmap = bm; } - fBitmap.setIsOpaque(fIsOpaque); + fBitmap.setAlphaType(fIsOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); fBitmap.setIsVolatile(fIsVolatile); } diff --git a/bench/BitmapRectBench.cpp b/bench/BitmapRectBench.cpp index 1dd98ef975..104cb24bd9 100644 --- a/bench/BitmapRectBench.cpp +++ b/bench/BitmapRectBench.cpp @@ -66,7 +66,7 @@ protected: virtual void onPreDraw() SK_OVERRIDE { fBitmap.allocPixels(); - fBitmap.setIsOpaque(true); + fBitmap.setAlphaType(kOpaque_SkAlphaType); fBitmap.eraseColor(SK_ColorBLACK); draw_into_bitmap(fBitmap); diff --git a/bench/BitmapScaleBench.cpp b/bench/BitmapScaleBench.cpp index cc2a33a894..ae3df71c22 100644 --- a/bench/BitmapScaleBench.cpp +++ b/bench/BitmapScaleBench.cpp @@ -57,14 +57,14 @@ protected: } virtual void onPreDraw() { - fInputBitmap.setConfig(SkBitmap::kARGB_8888_Config, fInputSize, fInputSize); + fInputBitmap.setConfig(SkBitmap::kARGB_8888_Config, + fInputSize, fInputSize, 0, kOpaque_SkAlphaType); fInputBitmap.allocPixels(); fInputBitmap.eraseColor(SK_ColorWHITE); - fInputBitmap.setIsOpaque(true); - fOutputBitmap.setConfig(SkBitmap::kARGB_8888_Config, fOutputSize, fOutputSize); + fOutputBitmap.setConfig(SkBitmap::kARGB_8888_Config, + fOutputSize, fOutputSize, 0, kOpaque_SkAlphaType); fOutputBitmap.allocPixels(); - fOutputBitmap.setIsOpaque(true); fMatrix.setScale( scale(), scale() ); } diff --git a/bench/RepeatTileBench.cpp b/bench/RepeatTileBench.cpp index 612a149d6d..957ec2a83e 100644 --- a/bench/RepeatTileBench.cpp +++ b/bench/RepeatTileBench.cpp @@ -115,7 +115,8 @@ protected: virtual void onPreDraw() SK_OVERRIDE { fBitmap.allocPixels(); fBitmap.eraseColor(fIsOpaque ? SK_ColorWHITE : 0); - fBitmap.setIsOpaque(fIsOpaque); + fBitmap.setAlphaType(fIsOpaque ? + kOpaque_SkAlphaType : kPremul_SkAlphaType); draw_into_bitmap(fBitmap); diff --git a/bench/TileBench.cpp b/bench/TileBench.cpp index 60312a3d56..03a758cdea 100644 --- a/bench/TileBench.cpp +++ b/bench/TileBench.cpp @@ -48,11 +48,10 @@ public: , fDoScale(doScale) { SkBitmap bm; - bm.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight); - + bm.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight, 0, + kOpaque_SkAlphaType); bm.allocPixels(); bm.eraseColor(SK_ColorWHITE); - bm.setIsOpaque(true); create_gradient(&bm); diff --git a/gm/bleed.cpp b/gm/bleed.cpp index dc7e96fbb1..0d093940de 100644 --- a/gm/bleed.cpp +++ b/gm/bleed.cpp @@ -19,7 +19,8 @@ static void make_red_ringed_bitmap(SkBitmap* result, int width, int height) { SkASSERT(0 == width % 2 && 0 == width % 2); - result->setConfig(SkBitmap::kARGB_8888_Config, width, height); + result->setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, + kOpaque_SkAlphaType); result->allocPixels(); SkAutoLockPixels lock(*result); @@ -56,7 +57,6 @@ static void make_red_ringed_bitmap(SkBitmap* result, int width, int height) { for (int x = 0; x < width; ++x) { scanline[x] = SK_ColorRED; } - result->setIsOpaque(true); result->setImmutable(); } diff --git a/gm/xfermodes.cpp b/gm/xfermodes.cpp index 65f53bffe7..e839b0ee71 100644 --- a/gm/xfermodes.cpp +++ b/gm/xfermodes.cpp @@ -60,9 +60,8 @@ class XfermodesGM : public GM { } virtual void onOnceBeforeDraw() SK_OVERRIDE { - fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4); + fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4, kOpaque_SkAlphaType); fBG.setPixels(gData); - fBG.setIsOpaque(true); make_bitmaps(W, H, &fSrcB, &fDstB); } diff --git a/gm/xfermodes2.cpp b/gm/xfermodes2.cpp index 990ee508d5..046c3ddc2a 100644 --- a/gm/xfermodes2.cpp +++ b/gm/xfermodes2.cpp @@ -93,11 +93,10 @@ private: SkPackARGB32(0xFF, 0x40, 0x40, 0x40) }; SkBitmap bg; - bg.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); + bg.setConfig(SkBitmap::kARGB_8888_Config, 2, 2, 0, kOpaque_SkAlphaType); bg.allocPixels(); SkAutoLockPixels bgAlp(bg); memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData)); - bg.setIsOpaque(true); fBG.reset(SkShader::CreateBitmapShader(bg, SkShader::kRepeat_TileMode, diff --git a/gm/xfermodes3.cpp b/gm/xfermodes3.cpp index baac3cdaff..d01c0190d4 100644 --- a/gm/xfermodes3.cpp +++ b/gm/xfermodes3.cpp @@ -188,11 +188,10 @@ private: SkPackARGB32(0xFF, 0x40, 0x40, 0x40) }; SkBitmap bg; - bg.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); + bg.setConfig(SkBitmap::kARGB_8888_Config, 2, 2, 0, kOpaque_SkAlphaType); bg.allocPixels(); SkAutoLockPixels bgAlp(bg); memcpy(bg.getPixels(), kCheckData, sizeof(kCheckData)); - bg.setIsOpaque(true); fBGShader.reset(SkShader::CreateBitmapShader(bg, SkShader::kRepeat_TileMode, diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 07d2b95553..3e22069e60 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -11,6 +11,7 @@ #define SkBitmap_DEFINED #include "Sk64.h" +#include "SkAlpha.h" #include "SkColor.h" #include "SkColorTable.h" #include "SkPoint.h" @@ -130,6 +131,15 @@ public: */ int rowBytesAsPixels() const { return fRowBytes >> (fBytesPerPixel >> 1); } + SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; } + + /** + * Set the bitmap's alphaType, returning true on success. If false is + * returned, then the specified new alphaType is incompatible with the + * Config, and the current alphaType is unchanged. + */ + bool setAlphaType(SkAlphaType); + /** Return the address of the pixels for this SkBitmap. */ void* getPixels() const { return fPixels; } @@ -175,12 +185,16 @@ public: /** Returns true if the bitmap is opaque (has no translucent/transparent pixels). */ - bool isOpaque() const; + bool isOpaque() const { + return SkAlphaTypeIsOpaque(this->alphaType()); + } - /** Specify if this bitmap's pixels are all opaque or not. Is only meaningful for configs - that support per-pixel alpha (RGB32, A1, A8). - */ - void setIsOpaque(bool); + /** + * DEPRECATED: use setAlpahType() instead. + */ + void setIsOpaque(bool opaque) { + this->setAlphaType(opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); + } /** Returns true if the bitmap is volatile (i.e. should not be cached by devices.) */ @@ -232,13 +246,6 @@ public: static bool ComputeIsOpaque(const SkBitmap&); /** - * Calls ComputeIsOpaque, and passes its result to setIsOpaque(). - */ - void computeAndSetOpaquePredicate() { - this->setIsOpaque(ComputeIsOpaque(*this)); - } - - /** * Return the bitmap's bounds [0, 0, width, height] as an SkRect */ void getBounds(SkRect* bounds) const; @@ -248,7 +255,14 @@ public: ComputeRowBytes() is called to compute the optimal value. This resets any pixel/colortable ownership, just like reset(). */ - void setConfig(Config, int width, int height, size_t rowBytes = 0); + bool setConfig(Config, int width, int height, size_t rowBytes, SkAlphaType); + + bool setConfig(Config config, int width, int height, size_t rowBytes = 0) { + return this->setConfig(config, width, height, rowBytes, + kPremul_SkAlphaType); + } + + /** Use this to assign a new pixel address for an existing bitmap. This will automatically release any pixelref previously installed. Only call this if you are handling ownership/lifetime of the pixel memory. @@ -672,6 +686,7 @@ private: uint32_t fWidth; uint32_t fHeight; uint8_t fConfig; + uint8_t fAlphaType; uint8_t fFlags; uint8_t fBytesPerPixel; // based on config diff --git a/samplecode/SampleDitherBitmap.cpp b/samplecode/SampleDitherBitmap.cpp index 7f29305a51..9132ceb195 100644 --- a/samplecode/SampleDitherBitmap.cpp +++ b/samplecode/SampleDitherBitmap.cpp @@ -100,7 +100,7 @@ protected: static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) { SkAutoLockPixels alp(*bm); // needed for ctable - bm->setIsOpaque(isOpaque); + bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); #if 0 SkColorTable* ctable = bm->getColorTable(); if (ctable) { diff --git a/samplecode/SampleTinyBitmap.cpp b/samplecode/SampleTinyBitmap.cpp index 42866d07ad..dc7157ff99 100644 --- a/samplecode/SampleTinyBitmap.cpp +++ b/samplecode/SampleTinyBitmap.cpp @@ -57,9 +57,8 @@ protected: static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) { SkAutoLockPixels alp(*bm); // needed for ctable - bm->setIsOpaque(isOpaque); + bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); #if 0 - // TODO - I think we just want to not allow this anymore SkColorTable* ctable = bm->getColorTable(); if (ctable) { ctable->setIsOpaque(isOpaque); diff --git a/samplecode/SampleXfermodesBlur.cpp b/samplecode/SampleXfermodesBlur.cpp index 59aa87e214..a73d9f2e20 100644 --- a/samplecode/SampleXfermodesBlur.cpp +++ b/samplecode/SampleXfermodesBlur.cpp @@ -77,9 +77,8 @@ public: const static int W = 64; const static int H = 64; XfermodesBlurView() { - fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4); + fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4, kOpaque_SkAlphaType); fBG.setPixels(gBG); - fBG.setIsOpaque(true); } protected: diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 63a760c4cf..bad63bac18 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -143,6 +143,7 @@ void SkBitmap::swap(SkBitmap& other) { SkTSwap(fWidth, other.fWidth); SkTSwap(fHeight, other.fHeight); SkTSwap(fConfig, other.fConfig); + SkTSwap(fAlphaType, other.fAlphaType); SkTSwap(fFlags, other.fFlags); SkTSwap(fBytesPerPixel, other.fBytesPerPixel); @@ -266,33 +267,76 @@ void SkBitmap::getBounds(SkIRect* bounds) const { /////////////////////////////////////////////////////////////////////////////// -void SkBitmap::setConfig(Config c, int width, int height, size_t rowBytes) { - this->freePixels(); +static bool validate_alphaType(SkBitmap::Config config, SkAlphaType alphaType, + SkAlphaType* canonical) { + switch (config) { + case SkBitmap::kNo_Config: + alphaType = kIgnore_SkAlphaType; + break; + case SkBitmap::kA1_Config: + case SkBitmap::kA8_Config: + if (kUnpremul_SkAlphaType == alphaType) { + alphaType = kPremul_SkAlphaType; + } + // fall-through + case SkBitmap::kIndex8_Config: + case SkBitmap::kARGB_4444_Config: + case SkBitmap::kARGB_8888_Config: + if (kIgnore_SkAlphaType == alphaType) { + return false; + } + break; + case SkBitmap::kRGB_565_Config: + alphaType = kOpaque_SkAlphaType; + break; + } + if (canonical) { + *canonical = alphaType; + } + return true; +} +bool SkBitmap::setConfig(Config config, int width, int height, size_t rowBytes, + SkAlphaType alphaType) { if ((width | height) < 0) { - goto err; + goto ERROR; } - if (rowBytes == 0) { - rowBytes = SkBitmap::ComputeRowBytes(c, width); - if (0 == rowBytes && kNo_Config != c) { - goto err; + rowBytes = SkBitmap::ComputeRowBytes(config, width); + if (0 == rowBytes && kNo_Config != config) { + goto ERROR; } } - fConfig = SkToU8(c); + if (!validate_alphaType(config, alphaType, &alphaType)) { + goto ERROR; + } + + this->freePixels(); + + fConfig = SkToU8(config); + fAlphaType = SkToU8(alphaType); fWidth = width; fHeight = height; fRowBytes = SkToU32(rowBytes); - fBytesPerPixel = (uint8_t)ComputeBytesPerPixel(c); + fBytesPerPixel = (uint8_t)ComputeBytesPerPixel(config); SkDEBUGCODE(this->validate();) - return; + return true; // if we got here, we had an error, so we reset the bitmap to empty -err: +ERROR: this->reset(); + return false; +} + +bool SkBitmap::setAlphaType(SkAlphaType alphaType) { + if (!validate_alphaType(this->config(), alphaType, &alphaType)) { + return false; + } + fAlphaType = SkToU8(alphaType); + return true; } void SkBitmap::updatePixelsFromRef() const { @@ -524,46 +568,6 @@ void SkBitmap::setImmutable() { } } -bool SkBitmap::isOpaque() const { - switch (fConfig) { - case kNo_Config: - return true; - - case kA1_Config: - case kA8_Config: - case kARGB_4444_Config: - case kARGB_8888_Config: - return (fFlags & kImageIsOpaque_Flag) != 0; - - case kIndex8_Config: { - bool isOpaque; - - this->lockPixels(); - isOpaque = fColorTable && fColorTable->isOpaque(); - this->unlockPixels(); - return isOpaque; - } - - case kRGB_565_Config: - return true; - - default: - SkDEBUGFAIL("unknown bitmap config pased to isOpaque"); - return false; - } -} - -void SkBitmap::setIsOpaque(bool isOpaque) { - /* we record this regardless of fConfig, though it is ignored in - isOpaque() for configs that can't support per-pixel alpha. - */ - if (isOpaque) { - fFlags |= kImageIsOpaque_Flag; - } else { - fFlags &= ~kImageIsOpaque_Flag; - } -} - bool SkBitmap::isVolatile() const { return (fFlags & kImageIsVolatile_Flag) != 0; } @@ -958,9 +962,9 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const { SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset); if (pixelRef != NULL) { SkBitmap dst; - dst.setConfig(this->config(), subset.width(), subset.height()); + dst.setConfig(this->config(), subset.width(), subset.height(), 0, + this->alphaType()); dst.setIsVolatile(this->isVolatile()); - dst.setIsOpaque(this->isOpaque()); dst.setPixelRef(pixelRef)->unref(); SkDEBUGCODE(dst.validate()); result->swap(dst); @@ -979,9 +983,9 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const { } SkBitmap dst; - dst.setConfig(this->config(), r.width(), r.height(), this->rowBytes()); + dst.setConfig(this->config(), r.width(), r.height(), this->rowBytes(), + this->alphaType()); dst.setIsVolatile(this->isVolatile()); - dst.setIsOpaque(this->isOpaque()); if (fPixelRef) { // share the pixelref with a custom offset @@ -1070,7 +1074,8 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const { } SkBitmap tmpDst; - tmpDst.setConfig(dstConfig, src->width(), src->height()); + tmpDst.setConfig(dstConfig, src->width(), src->height(), 0, + src->alphaType()); // allocate colortable if srcConfig == kIndex8_Config SkColorTable* ctable = (dstConfig == kIndex8_Config) ? @@ -1130,8 +1135,6 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const { canvas.drawBitmap(*src, 0, 0, &paint); } - tmpDst.setIsOpaque(src->isOpaque()); - dst->swap(tmpDst); return true; } @@ -1579,7 +1582,7 @@ void SkBitmap::flatten(SkFlattenableWriteBuffer& buffer) const { buffer.writeInt(fHeight); buffer.writeInt(fRowBytes); buffer.writeInt(fConfig); - buffer.writeBool(this->isOpaque()); + buffer.writeInt(fAlphaType); if (fPixelRef) { if (fPixelRef->getFactory()) { @@ -1602,9 +1605,9 @@ void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) { int height = buffer.readInt(); int rowBytes = buffer.readInt(); int config = buffer.readInt(); + int alphaType = buffer.readInt(); - this->setConfig((Config)config, width, height, rowBytes); - this->setIsOpaque(buffer.readBool()); + this->setConfig((Config)config, width, height, rowBytes, (SkAlphaType)alphaType); int reftype = buffer.readInt(); switch (reftype) { diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index eee201881a..ff68481538 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -27,9 +27,9 @@ SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& } SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque) { - fBitmap.setConfig(config, width, height); + fBitmap.setConfig(config, width, height, 0, isOpaque ? + kOpaque_SkAlphaType : kPremul_SkAlphaType); fBitmap.allocPixels(); - fBitmap.setIsOpaque(isOpaque); if (!isOpaque) { fBitmap.eraseColor(SK_ColorTRANSPARENT); } @@ -39,9 +39,9 @@ SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b const SkDeviceProperties& deviceProperties) : SkBaseDevice(deviceProperties) { - fBitmap.setConfig(config, width, height); + fBitmap.setConfig(config, width, height, 0, isOpaque ? + kOpaque_SkAlphaType : kPremul_SkAlphaType); fBitmap.allocPixels(); - fBitmap.setIsOpaque(isOpaque); if (!isOpaque) { fBitmap.eraseColor(SK_ColorTRANSPARENT); } diff --git a/src/core/SkBitmapScaler.cpp b/src/core/SkBitmapScaler.cpp index 114836dd79..c28d4779c7 100644 --- a/src/core/SkBitmapScaler.cpp +++ b/src/core/SkBitmapScaler.cpp @@ -287,7 +287,8 @@ bool SkBitmapScaler::Resize(SkBitmap* resultPtr, // Convolve into the result. SkBitmap result; result.setConfig(SkBitmap::kARGB_8888_Config, - destSubset.width(), destSubset.height()); + destSubset.width(), destSubset.height(), 0, + source.alphaType()); result.allocPixels(allocator, NULL); if (!result.readyToDraw()) { return false; @@ -299,8 +300,6 @@ bool SkBitmapScaler::Resize(SkBitmap* resultPtr, static_cast<unsigned char*>(result.getPixels()), convolveProcs, true); - // Preserve the "opaque" flag for use as an optimization later. - result.setIsOpaque(source.isOpaque()); *resultPtr = result; return true; } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 3c91101b34..1498fc4c42 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -137,14 +137,17 @@ static SkBitmap::Config grConfig2skConfig(GrPixelConfig config, bool* isOpaque) } } +/* + * GrRenderTarget does not know its opaqueness, only its config, so we have + * to make conservative guesses when we return an "equivalent" bitmap. + */ static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { - GrPixelConfig config = renderTarget->config(); - bool isOpaque; + SkBitmap::Config config = grConfig2skConfig(renderTarget->config(), &isOpaque); + SkBitmap bitmap; - bitmap.setConfig(grConfig2skConfig(config, &isOpaque), - renderTarget->width(), renderTarget->height()); - bitmap.setIsOpaque(isOpaque); + bitmap.setConfig(config, renderTarget->width(), renderTarget->height(), 0, + isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); return bitmap; } diff --git a/src/image/SkImagePriv.cpp b/src/image/SkImagePriv.cpp index f707543c2a..eeeb9d87f7 100644 --- a/src/image/SkImagePriv.cpp +++ b/src/image/SkImagePriv.cpp @@ -9,45 +9,16 @@ #include "SkCanvas.h" #include "SkPicture.h" -SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info& info, - bool* isOpaque) { +SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info& info) { switch (info.fColorType) { case SkImage::kAlpha_8_ColorType: - switch (info.fAlphaType) { - case kIgnore_SkAlphaType: - // makes no sense - return SkBitmap::kNo_Config; - - case kOpaque_SkAlphaType: - *isOpaque = true; - return SkBitmap::kA8_Config; - - case kPremul_SkAlphaType: - case kUnpremul_SkAlphaType: - *isOpaque = false; - return SkBitmap::kA8_Config; - } - break; + return SkBitmap::kA8_Config; case SkImage::kRGB_565_ColorType: - // we ignore fAlpahType, though some would not make sense - *isOpaque = true; return SkBitmap::kRGB_565_Config; case SkImage::kPMColor_ColorType: - switch (info.fAlphaType) { - case kIgnore_SkAlphaType: - case kUnpremul_SkAlphaType: - // not supported yet - return SkBitmap::kNo_Config; - case kOpaque_SkAlphaType: - *isOpaque = true; - return SkBitmap::kARGB_8888_Config; - case kPremul_SkAlphaType: - *isOpaque = false; - return SkBitmap::kARGB_8888_Config; - } - break; + return SkBitmap::kARGB_8888_Config; default: // break for unsupported colortypes diff --git a/src/image/SkImagePriv.h b/src/image/SkImagePriv.h index 2af8bbea92..5d93605566 100644 --- a/src/image/SkImagePriv.h +++ b/src/image/SkImagePriv.h @@ -13,8 +13,7 @@ class SkPicture; -extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info&, - bool* isOpaque); +extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImage::Info&); extern int SkImageBytesPerPixel(SkImage::ColorType); diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index cd9b70f018..a208d83a7f 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -31,8 +31,7 @@ public: return false; } - bool isOpaque; - if (SkImageInfoToBitmapConfig(info, &isOpaque) == SkBitmap::kNo_Config) { + if (SkImageInfoToBitmapConfig(info) == SkBitmap::kNo_Config) { return false; } @@ -85,23 +84,19 @@ SkImage* SkImage_Raster::NewEmpty() { SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes) : INHERITED(info.fWidth, info.fHeight) { - bool isOpaque; - SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); + SkBitmap::Config config = SkImageInfoToBitmapConfig(info); - fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes); + fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaType); fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (data)))->unref(); - fBitmap.setIsOpaque(isOpaque); fBitmap.setImmutable(); } SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes) : INHERITED(info.fWidth, info.fHeight) { - bool isOpaque; - SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); + SkBitmap::Config config = SkImageInfoToBitmapConfig(info); - fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes); + fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaType); fBitmap.setPixelRef(pr); - fBitmap.setIsOpaque(isOpaque); } SkImage_Raster::~SkImage_Raster() {} diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index e5b7bd4486..7b3a6437d9 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -38,12 +38,11 @@ SK_DEFINE_INST_COUNT(SkSurface_Gpu) SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, const SkImage::Info& info, int sampleCount) : INHERITED(info.fWidth, info.fHeight) { - bool isOpaque; - SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); + SkBitmap::Config config = SkImageInfoToBitmapConfig(info); fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, config, info.fWidth, info.fHeight, sampleCount)); - if (!isOpaque) { + if (!SkAlphaTypeIsOpaque(info.fAlphaType)) { fDevice->clear(0x0); } } @@ -119,8 +118,7 @@ SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImage::Info& info, return NULL; } - bool isOpaque; - SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); + SkBitmap::Config config = SkImageInfoToBitmapConfig(info); GrTextureDesc desc; desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFlagBit; @@ -136,3 +134,4 @@ SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImage::Info& info, return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget())); } + diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp index ccfdd27b1c..5beabf71cc 100644 --- a/src/image/SkSurface_Raster.cpp +++ b/src/image/SkSurface_Raster.cpp @@ -39,8 +39,7 @@ private: bool SkSurface_Raster::Valid(const SkImage::Info& info, size_t rowBytes) { static const size_t kMaxTotalSize = SK_MaxS32; - bool isOpaque; - SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); + SkBitmap::Config config = SkImageInfoToBitmapConfig(info); int shift = 0; switch (config) { @@ -83,26 +82,20 @@ bool SkSurface_Raster::Valid(const SkImage::Info& info, size_t rowBytes) { SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, void* pixels, size_t rb) : INHERITED(info.fWidth, info.fHeight) { - bool isOpaque; - SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); - - fBitmap.setConfig(config, info.fWidth, info.fHeight, rb); + SkBitmap::Config config = SkImageInfoToBitmapConfig(info); + fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, info.fAlphaType); fBitmap.setPixels(pixels); - fBitmap.setIsOpaque(isOpaque); fWeOwnThePixels = false; // We are "Direct" } SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, SkPixelRef* pr, size_t rb) : INHERITED(info.fWidth, info.fHeight) { - bool isOpaque; - SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); - - fBitmap.setConfig(config, info.fWidth, info.fHeight, rb); + SkBitmap::Config config = SkImageInfoToBitmapConfig(info); + fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, info.fAlphaType); fBitmap.setPixelRef(pr); - fBitmap.setIsOpaque(isOpaque); fWeOwnThePixels = true; - if (!isOpaque) { + if (!SkAlphaTypeIsOpaque(info.fAlphaType)) { fBitmap.eraseColor(SK_ColorTRANSPARENT); } } diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp index 15cd1a60c0..3ee41124c0 100644 --- a/src/images/SkImageDecoder.cpp +++ b/src/images/SkImageDecoder.cpp @@ -245,8 +245,7 @@ bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, } // if the destination has no pixels then we must allocate them. if (dst->isNull()) { - dst->setConfig(src->getConfig(), w, h); - dst->setIsOpaque(src->isOpaque()); + dst->setConfig(src->getConfig(), w, h, 0, src->alphaType()); if (!this->allocPixelRef(dst, NULL)) { SkDEBUGF(("failed to allocate pixels needed to crop the bitmap")); diff --git a/src/images/SkImageDecoder_libbmp.cpp b/src/images/SkImageDecoder_libbmp.cpp index 2283dbf51d..34a88ac6b0 100644 --- a/src/images/SkImageDecoder_libbmp.cpp +++ b/src/images/SkImageDecoder_libbmp.cpp @@ -133,8 +133,8 @@ bool SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { SkScaledBitmapSampler sampler(width, height, getSampleSize()); - bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); - bm->setIsOpaque(true); + bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0, + kOpaque_SkAlphaType); if (justBounds) { return true; diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp index 52c7483d7c..67b17823e2 100644 --- a/src/images/SkImageDecoder_libjpeg.cpp +++ b/src/images/SkImageDecoder_libjpeg.cpp @@ -543,9 +543,9 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { #endif if (1 == sampleSize && SkImageDecoder::kDecodeBounds_Mode == mode) { - bm->setConfig(config, cinfo.image_width, cinfo.image_height); - bm->setIsOpaque(config != SkBitmap::kA8_Config); - return true; + return bm->setConfig(config, cinfo.image_width, cinfo.image_height, 0, + SkBitmap::kA8_Config == config ? + kPremul_SkAlphaType : kOpaque_SkAlphaType); } /* image_width and image_height are the original dimensions, available @@ -565,9 +565,9 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { if (SkImageDecoder::kDecodeBounds_Mode == mode && valid_output_dimensions(cinfo)) { SkScaledBitmapSampler smpl(cinfo.output_width, cinfo.output_height, recompute_sampleSize(sampleSize, cinfo)); - bm->setConfig(config, smpl.scaledWidth(), smpl.scaledHeight()); - bm->setIsOpaque(config != SkBitmap::kA8_Config); - return true; + return bm->setConfig(config, smpl.scaledWidth(), smpl.scaledHeight(), + 0, SkBitmap::kA8_Config == config ? + kPremul_SkAlphaType : kOpaque_SkAlphaType); } else { return return_false(cinfo, *bm, "start_decompress"); } @@ -580,8 +580,8 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { } SkScaledBitmapSampler sampler(cinfo.output_width, cinfo.output_height, sampleSize); - bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); - bm->setIsOpaque(config != SkBitmap::kA8_Config); + bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0, + SkBitmap::kA8_Config != config ? kOpaque_SkAlphaType : kPremul_SkAlphaType); if (SkImageDecoder::kDecodeBounds_Mode == mode) { return true; } @@ -801,8 +801,8 @@ bool SkJPEGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) { SkScaledBitmapSampler sampler(width, height, skiaSampleSize); SkBitmap bitmap; - bitmap.setConfig(config, sampler.scaledWidth(), sampler.scaledHeight()); - bitmap.setIsOpaque(true); + bitmap.setConfig(config, sampler.scaledWidth(), sampler.scaledHeight(), 0, + kOpaque_SkAlphaType); // Check ahead of time if the swap(dest, src) is possible or not. // If yes, then we will stick to AllocPixelRef since it's cheaper with the diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp index 5fc9350b51..e54387af34 100644 --- a/src/images/SkImageDecoder_libpng.cpp +++ b/src/images/SkImageDecoder_libpng.cpp @@ -466,7 +466,16 @@ bool SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* decodedBitmap, if (SkBitmap::kA8_Config == decodedBitmap->config()) { reallyHasAlpha = true; } - decodedBitmap->setIsOpaque(!reallyHasAlpha); + + SkAlphaType alphaType = kOpaque_SkAlphaType; + if (reallyHasAlpha) { + if (this->getRequireUnpremultipliedColors()) { + alphaType = kUnpremul_SkAlphaType; + } else { + alphaType = kPremul_SkAlphaType; + } + } + decodedBitmap->setAlphaType(alphaType); return true; } @@ -939,7 +948,15 @@ bool SkPNGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) { if (SkBitmap::kA8_Config == decodedBitmap.config()) { reallyHasAlpha = true; } - decodedBitmap.setIsOpaque(!reallyHasAlpha); + SkAlphaType alphaType = kOpaque_SkAlphaType; + if (reallyHasAlpha) { + if (this->getRequireUnpremultipliedColors()) { + alphaType = kUnpremul_SkAlphaType; + } else { + alphaType = kPremul_SkAlphaType; + } + } + decodedBitmap.setAlphaType(alphaType); if (swapOnly) { bm->swap(decodedBitmap); diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp index 8bb716bae8..68014dd392 100644 --- a/src/images/SkImageDecoder_libwebp.cpp +++ b/src/images/SkImageDecoder_libwebp.cpp @@ -293,11 +293,8 @@ bool SkWEBPImageDecoder::setDecodeConfig(SkBitmap* decodedBitmap, return false; } - decodedBitmap->setConfig(config, width, height, 0); - - decodedBitmap->setIsOpaque(!fHasAlpha); - - return true; + return decodedBitmap->setConfig(config, width, height, 0, + fHasAlpha ? kPremul_SkAlphaType : kOpaque_SkAlphaType); } bool SkWEBPImageDecoder::onBuildTileIndex(SkStreamRewindable* stream, diff --git a/src/images/SkImageDecoder_wbmp.cpp b/src/images/SkImageDecoder_wbmp.cpp index 4a9944dbcd..8dce62cdf0 100644 --- a/src/images/SkImageDecoder_wbmp.cpp +++ b/src/images/SkImageDecoder_wbmp.cpp @@ -111,8 +111,8 @@ bool SkWBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap, int width = head.fWidth; int height = head.fHeight; - decodedBitmap->setConfig(SkBitmap::kIndex8_Config, width, height); - decodedBitmap->setIsOpaque(true); + decodedBitmap->setConfig(SkBitmap::kIndex8_Config, width, height, 0, + kOpaque_SkAlphaType); if (SkImageDecoder::kDecodeBounds_Mode == mode) { return true; diff --git a/src/images/SkImageRef.cpp b/src/images/SkImageRef.cpp index 9093b05156..ead835f7ab 100644 --- a/src/images/SkImageRef.cpp +++ b/src/images/SkImageRef.cpp @@ -64,7 +64,8 @@ bool SkImageRef::getInfo(SkBitmap* bitmap) { bool SkImageRef::isOpaque(SkBitmap* bitmap) { if (bitmap && bitmap->pixelRef() == this) { bitmap->lockPixels(); - bitmap->setIsOpaque(fBitmap.isOpaque()); + // what about colortables?????? + bitmap->setAlphaType(fBitmap.alphaType()); bitmap->unlockPixels(); return true; } diff --git a/src/lazy/SkBitmapFactory.cpp b/src/lazy/SkBitmapFactory.cpp index 0ff4ee2d17..5464851402 100644 --- a/src/lazy/SkBitmapFactory.cpp +++ b/src/lazy/SkBitmapFactory.cpp @@ -53,16 +53,13 @@ bool SkBitmapFactory::installPixelRef(SkData* data, SkBitmap* dst) { return false; } - bool isOpaque = false; - SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); + SkBitmap::Config config = SkImageInfoToBitmapConfig(info); Target target; // FIMXE: There will be a problem if this rowbytes is calculated differently from // in SkLazyPixelRef. target.fRowBytes = SkImageMinRowBytes(info); - - dst->setConfig(config, info.fWidth, info.fHeight, target.fRowBytes); - dst->setIsOpaque(isOpaque); + dst->setConfig(config, info.fWidth, info.fHeight, target.fRowBytes, info.fAlphaType); // fImageCache and fCacheSelector are mutually exclusive. SkASSERT(NULL == fImageCache || NULL == fCacheSelector); diff --git a/src/lazy/SkLazyPixelRef.cpp b/src/lazy/SkLazyPixelRef.cpp index 9e023c4a7c..22d4b112f1 100644 --- a/src/lazy/SkLazyPixelRef.cpp +++ b/src/lazy/SkLazyPixelRef.cpp @@ -150,15 +150,14 @@ SkData* SkLazyPixelRef::onRefEncodedData() { static bool init_from_info(SkBitmap* bm, const SkImage::Info& info, size_t rowBytes) { - bool isOpaque; - SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); + SkBitmap::Config config = SkImageInfoToBitmapConfig(info); if (SkBitmap::kNo_Config == config) { return false; } - bm->setConfig(config, info.fWidth, info.fHeight, rowBytes); - bm->setIsOpaque(isOpaque); - return bm->allocPixels(); + return bm->setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaType) + && + bm->allocPixels(); } bool SkLazyPixelRef::onImplementsDecodeInto() { diff --git a/src/ports/SkImageDecoder_CG.cpp b/src/ports/SkImageDecoder_CG.cpp index 8956acaebc..3f850b544d 100644 --- a/src/ports/SkImageDecoder_CG.cpp +++ b/src/ports/SkImageDecoder_CG.cpp @@ -104,11 +104,13 @@ bool SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { case kCGImageAlphaNoneSkipLast: case kCGImageAlphaNoneSkipFirst: SkASSERT(SkBitmap::ComputeIsOpaque(*bm)); - bm->setIsOpaque(true); + bm->setAlphaType(kOpaque_SkAlphaType); break; default: // we don't know if we're opaque or not, so compute it. - bm->computeAndSetOpaquePredicate(); + if (SkBitmap::ComputeIsOpaque(*bm)) { + bm->setAlphaType(kOpaque_SkAlphaType); + } } if (!bm->isOpaque() && this->getRequireUnpremultipliedColors()) { // CGBitmapContext does not support unpremultiplied, so the image has been premultiplied. @@ -119,6 +121,7 @@ bool SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { *addr = unpremultiply_pmcolor(*addr); } } + bm->setAlphaType(kUnpremul_SkAlphaType); } bm->unlockPixels(); return true; diff --git a/src/ports/SkImageDecoder_WIC.cpp b/src/ports/SkImageDecoder_WIC.cpp index c3666aca5c..1bda67fe91 100644 --- a/src/ports/SkImageDecoder_WIC.cpp +++ b/src/ports/SkImageDecoder_WIC.cpp @@ -240,7 +240,9 @@ bool SkImageDecoder_WIC::decodeStream(SkStream* stream, SkBitmap* bm, WICModes w ); // Note: we don't need to premultiply here since we specified PBGRA - bm->computeAndSetOpaquePredicate(); + if (ComputeIsOpaque(*bm)) { + bm->setAlphaType(kOpaque_SkAlphaType); + } } return SUCCEEDED(hr); diff --git a/src/views/SkWindow.cpp b/src/views/SkWindow.cpp index f25eb12379..d6fe32bd88 100644 --- a/src/views/SkWindow.cpp +++ b/src/views/SkWindow.cpp @@ -102,9 +102,8 @@ void SkWindow::resize(int width, int height, SkBitmap::Config config) if (width != fBitmap.width() || height != fBitmap.height() || config != fConfig) { fConfig = config; - fBitmap.setConfig(config, width, height); + fBitmap.setConfig(config, width, height, 0, kOpaque_SkAlphaType); fBitmap.allocPixels(); - fBitmap.setIsOpaque(true); this->setSize(SkIntToScalar(width), SkIntToScalar(height)); this->inval(NULL); diff --git a/tests/ARGBImageEncoderTest.cpp b/tests/ARGBImageEncoderTest.cpp index 9f68a0a151..bffcaa4f78 100644 --- a/tests/ARGBImageEncoderTest.cpp +++ b/tests/ARGBImageEncoderTest.cpp @@ -48,7 +48,7 @@ void BitmapTransformerTestClass::onRun(Reporter* reporter) { { bitmap.setConfig(configs[configIndex], kWidth, kHeight); REPORTER_ASSERT(reporter, bitmap.allocPixels()); - bitmap.setIsOpaque(true); + bitmap.setAlphaType(kOpaque_SkAlphaType); bitmap.eraseColor(SK_ColorBLUE); // Change rows [0,1] from blue to [red,green]. SkCanvas canvas(bitmap); diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index cccde8af92..bf0d2f7813 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -249,8 +249,8 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) { SkColorTable* ctOpaque = NULL; SkColorTable* ctPremul = NULL; - srcOpaque.setConfig(gPairs[i].fConfig, W, H); - srcPremul.setConfig(gPairs[i].fConfig, W, H); + srcOpaque.setConfig(gPairs[i].fConfig, W, H, 0, kOpaque_SkAlphaType); + srcPremul.setConfig(gPairs[i].fConfig, W, H, 0, kPremul_SkAlphaType); if (SkBitmap::kIndex8_Config == gPairs[i].fConfig) { ctOpaque = init_ctable(kOpaque_SkAlphaType); ctPremul = init_ctable(kPremul_SkAlphaType); @@ -259,9 +259,6 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) { srcPremul.allocPixels(ctPremul); SkSafeUnref(ctOpaque); SkSafeUnref(ctPremul); - - srcOpaque.setIsOpaque(true); - srcPremul.setIsOpaque(false); } init_src(srcOpaque); init_src(srcPremul); @@ -315,7 +312,7 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, subset.width() == 1); REPORTER_ASSERT(reporter, subset.height() == 1); REPORTER_ASSERT(reporter, - subset.isOpaque() == bitmap.isOpaque()); + subset.alphaType() == bitmap.alphaType()); REPORTER_ASSERT(reporter, subset.isVolatile() == true); @@ -333,12 +330,11 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, (copy.getColorTable() != NULL) == hasCT); } - bitmap = srcPremul; bitmap.setIsVolatile(false); if (bitmap.extractSubset(&subset, r)) { REPORTER_ASSERT(reporter, - subset.isOpaque() == bitmap.isOpaque()); + subset.alphaType() == bitmap.alphaType()); REPORTER_ASSERT(reporter, subset.isVolatile() == false); } diff --git a/tests/BitmapHasherTest.cpp b/tests/BitmapHasherTest.cpp index 924cea2dcc..d6c9e6ab2f 100644 --- a/tests/BitmapHasherTest.cpp +++ b/tests/BitmapHasherTest.cpp @@ -31,7 +31,7 @@ namespace skiatest { SkColor color) { bitmap.setConfig(config, width, height); REPORTER_ASSERT(fReporter, bitmap.allocPixels()); - bitmap.setIsOpaque(true); + bitmap.setAlphaType(kOpaque_SkAlphaType); bitmap.eraseColor(color); } diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp index e8075bd68f..537a810aa9 100644 --- a/tests/DeferredCanvasTest.cpp +++ b/tests/DeferredCanvasTest.cpp @@ -333,7 +333,7 @@ static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { paint.setStyle(SkPaint::kFill_Style); SkBitmap bmp; create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); - bmp.setIsOpaque(true); + bmp.setAlphaType(kOpaque_SkAlphaType); SkShader* shader = SkShader::CreateBitmapShader(bmp, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); paint.setShader(shader)->unref(); @@ -371,7 +371,7 @@ static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) { paint.setStyle(SkPaint::kFill_Style); SkBitmap bmp; create(&bmp, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF); - bmp.setIsOpaque(false); + bmp.setAlphaType(kPremul_SkAlphaType); SkShader* shader = SkShader::CreateBitmapShader(bmp, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); paint.setShader(shader)->unref(); diff --git a/tests/ShaderOpacityTest.cpp b/tests/ShaderOpacityTest.cpp index 0af25d1ec2..c3dc888ba3 100644 --- a/tests/ShaderOpacityTest.cpp +++ b/tests/ShaderOpacityTest.cpp @@ -32,7 +32,7 @@ static void test_bitmap(skiatest::Reporter* reporter) { shader->unref(); // test 3: explicitly opaque - bmp.setIsOpaque(true); + bmp.setAlphaType(kOpaque_SkAlphaType); shader = SkShader::CreateBitmapShader(bmp, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); REPORTER_ASSERT(reporter, shader); @@ -40,7 +40,7 @@ static void test_bitmap(skiatest::Reporter* reporter) { shader->unref(); // test 4: explicitly not opaque - bmp.setIsOpaque(false); + bmp.setAlphaType(kPremul_SkAlphaType); shader = SkShader::CreateBitmapShader(bmp, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); REPORTER_ASSERT(reporter, shader); |