diff options
author | 2011-03-14 20:30:14 +0000 | |
---|---|---|
committer | 2011-03-14 20:30:14 +0000 | |
commit | cd9d69b9ce7eb301a9fd8d91b9f95fd99b07bae5 (patch) | |
tree | 699c584b39fd1e30022bb05ce58dad15fcd9b4c7 /src/core/SkBitmap.cpp | |
parent | 260db92d4975c50fd929399e8d6875a4c854cd5d (diff) |
Upstreaming changes from android.
- fix compile warnings in the GPU code
- upstream android specific code (ifdef protected)
- fail gracefully when a custom allocator fails
git-svn-id: http://skia.googlecode.com/svn/trunk@936 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkBitmap.cpp')
-rw-r--r-- | src/core/SkBitmap.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index c1a9998bf1..a5f7d57ad5 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -1237,10 +1237,11 @@ static bool GetBitmapAlpha(const SkBitmap& src, uint8_t SK_RESTRICT alpha[], #include "SkMaskFilter.h" #include "SkMatrix.h" -void SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, +bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, Allocator *allocator, SkIPoint* offset) const { SkDEBUGCODE(this->validate();) + SkBitmap tmpBitmap; SkMatrix identity; SkMask srcM, dstM; @@ -1260,14 +1261,20 @@ void SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, dstM.fRowBytes = SkAlign4(dstM.fBounds.width()); } else { NO_FILTER_CASE: - dst->setConfig(SkBitmap::kA8_Config, this->width(), this->height(), + tmpBitmap.setConfig(SkBitmap::kA8_Config, this->width(), this->height(), srcM.fRowBytes); - dst->allocPixels(allocator, NULL); - GetBitmapAlpha(*this, dst->getAddr8(0, 0), srcM.fRowBytes); + if (!tmpBitmap.allocPixels(allocator, NULL)) { + // Allocation of pixels for alpha bitmap failed. + SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", + tmpBitmap.width(), tmpBitmap.height()); + return false; + } + GetBitmapAlpha(*this, tmpBitmap.getAddr8(0, 0), srcM.fRowBytes); if (offset) { offset->set(0, 0); } - return; + tmpBitmap.swap(*dst); + return true; } SkAutoMaskImage srcCleanup(&srcM, true); @@ -1279,14 +1286,22 @@ void SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, SkAutoMaskImage dstCleanup(&dstM, false); - dst->setConfig(SkBitmap::kA8_Config, dstM.fBounds.width(), + tmpBitmap.setConfig(SkBitmap::kA8_Config, dstM.fBounds.width(), dstM.fBounds.height(), dstM.fRowBytes); - dst->allocPixels(allocator, NULL); - memcpy(dst->getPixels(), dstM.fImage, dstM.computeImageSize()); + if (!tmpBitmap.allocPixels(allocator, NULL)) { + // Allocation of pixels for alpha bitmap failed. + SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", + tmpBitmap.width(), tmpBitmap.height()); + return false; + } + memcpy(tmpBitmap.getPixels(), dstM.fImage, dstM.computeImageSize()); if (offset) { offset->set(dstM.fBounds.fLeft, dstM.fBounds.fTop); } - SkDEBUGCODE(dst->validate();) + SkDEBUGCODE(tmpBitmap.validate();) + + tmpBitmap.swap(*dst); + return true; } /////////////////////////////////////////////////////////////////////////////// |