| Index: src/core/SkBitmap.cpp
|
| diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
|
| index 128726cb63d9198477afd698e377c6ee02cef6ed..0f30945ab4b5dd225d25c1f723905f4c82a07def 100644
|
| --- a/src/core/SkBitmap.cpp
|
| +++ b/src/core/SkBitmap.cpp
|
| @@ -266,33 +266,88 @@ void SkBitmap::getBounds(SkIRect* bounds) const {
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
| -void SkBitmap::setConfig(Config c, int width, int height, size_t rowBytes) {
|
| - this->freePixels();
|
| -
|
| +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);
|
| + // check for legal/supported config+alphaType combinations
|
| + //
|
| + switch (config) {
|
| + case kNo_Config:
|
| + alphaType = kIgnore_SkAlphaType; // canonicalize
|
| + break;
|
| + case kA1_Config:
|
| + case kA8_Config:
|
| + if (kUnpremul_SkAlphaType == alphaType) {
|
| + alphaType = kPremul_SkAlphaType;
|
| + }
|
| + // fall-through
|
| + case kIndex8_Config:
|
| + case kARGB_4444_Config:
|
| + case kARGB_8888_Config:
|
| + if (kIgnore_SkAlphaType == alphaType) {
|
| + goto ERROR; // not supported yet
|
| + }
|
| + break;
|
| + case kRGB_565_Config:
|
| + alphaType = kOpaque_SkAlphaType; // canonicalize
|
| + break;
|
| + }
|
| +
|
| + 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;
|
| +}
|
| +
|
| +void SkBitmap::setAlphaType(SkAlphaType alphaType) {
|
| + // check for legal/supported config+alphaType combinations
|
| + //
|
| + switch (this->config()) {
|
| + case kNo_Config:
|
| + alphaType = kIgnore_SkAlphaType; // canonicalize
|
| + break;
|
| + case kA1_Config:
|
| + case kA8_Config:
|
| + if (kUnpremul_SkAlphaType == alphaType) {
|
| + alphaType = kPremul_SkAlphaType;
|
| + }
|
| + // fall-through
|
| + case kIndex8_Config:
|
| + case kARGB_4444_Config:
|
| + case kARGB_8888_Config:
|
| + if (kIgnore_SkAlphaType == alphaType) {
|
| + SkDEBUGFAIL("bad alphaType for existing config");
|
| + return;
|
| + }
|
| + break;
|
| + case kRGB_565_Config:
|
| + alphaType = kOpaque_SkAlphaType; // canonicalize
|
| + break;
|
| + }
|
| +
|
| + fAlphaType = SkToU8(alphaType);
|
| }
|
|
|
| void SkBitmap::updatePixelsFromRef() const {
|
| @@ -525,6 +580,9 @@ void SkBitmap::setImmutable() {
|
| }
|
|
|
| bool SkBitmap::isOpaque() const {
|
| + return kOpaque_SkAlphaType == fAlphaType ||
|
| + kIgnore_SkAlphaType == fAlphaType;
|
| +#if 0
|
| switch (fConfig) {
|
| case kNo_Config:
|
| return true;
|
| @@ -555,8 +613,10 @@ bool SkBitmap::isOpaque() const {
|
| SkDEBUGFAIL("unknown bitmap config pased to isOpaque");
|
| return false;
|
| }
|
| +#endif
|
| }
|
|
|
| +#if 0
|
| 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.
|
| @@ -567,6 +627,7 @@ void SkBitmap::setIsOpaque(bool isOpaque) {
|
| fFlags &= ~kImageIsOpaque_Flag;
|
| }
|
| }
|
| +#endif
|
|
|
| bool SkBitmap::isVolatile() const {
|
| return (fFlags & kImageIsVolatile_Flag) != 0;
|
| @@ -962,9 +1023,10 @@ 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->isOpaque() ?
|
| + kOpaque_SkAlphaType : kPremul_SkAlphaType);
|
| dst.setIsVolatile(this->isVolatile());
|
| - dst.setIsOpaque(this->isOpaque());
|
| dst.setPixelRef(pixelRef)->unref();
|
| SkDEBUGCODE(dst.validate());
|
| result->swap(dst);
|
| @@ -983,9 +1045,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->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
|
| dst.setIsVolatile(this->isVolatile());
|
| - dst.setIsOpaque(this->isOpaque());
|
|
|
| if (fPixelRef) {
|
| // share the pixelref with a custom offset
|
| @@ -1135,7 +1197,8 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const {
|
| canvas.drawBitmap(*src, 0, 0, &paint);
|
| }
|
|
|
| - tmpDst.setIsOpaque(src->isOpaque());
|
| + tmpDst.setAlphaType(src->isOpaque() ?
|
| + kOpaque_SkAlphaType : kPremul_SkAlphaType);
|
|
|
| dst->swap(tmpDst);
|
| return true;
|
| @@ -1608,8 +1671,9 @@ void SkBitmap::unflatten(SkFlattenableReadBuffer& buffer) {
|
| int rowBytes = buffer.readInt();
|
| int config = buffer.readInt();
|
|
|
| - this->setConfig((Config)config, width, height, rowBytes);
|
| - this->setIsOpaque(buffer.readBool());
|
| + bool isOpaque = buffer.readBool();
|
| + this->setConfig((Config)config, width, height, rowBytes,
|
| + isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
|
|
|
| int reftype = buffer.readInt();
|
| switch (reftype) {
|
|
|