diff --git a/gyp/skia_for_chromium_defines.gypi b/gyp/skia_for_chromium_defines.gypi index ac4a19f22..636fd87a8 100644 --- a/gyp/skia_for_chromium_defines.gypi +++ b/gyp/skia_for_chromium_defines.gypi @@ -13,6 +13,7 @@ # If these become 'permanent', they should be moved into skia_common.gypi # 'skia_for_chromium_defines': [ + 'SK_SUPPORT_LEGACY_ALLOCPIXELS_BOOL', 'SK_IGNORE_PROPER_FRACTIONAL_SCALING', 'SK_SUPPORT_LEGACY_PICTURE_CLONE', 'SK_SUPPORT_LEGACY_GETDEVICE', diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 13a7e304c..c58c78d76 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -14,6 +14,16 @@ #include "SkPoint.h" #include "SkRefCnt.h" +#ifdef SK_SUPPORT_LEGACY_ALLOCPIXELS_BOOL + #define SK_ALLOCPIXELS_RETURN_TYPE bool + #define SK_ALLOCPIXELS_RETURN_TRUE return true + #define SK_ALLOCPIXELS_RETURN_FAIL return false +#else + #define SK_ALLOCPIXELS_RETURN_TYPE void + #define SK_ALLOCPIXELS_RETURN_TRUE return + #define SK_ALLOCPIXELS_RETURN_FAIL sk_throw() +#endif + struct SkMask; struct SkIRect; struct SkRect; @@ -218,7 +228,15 @@ public: * a colortable, then ColorTable must be non-null, and will be ref'd. * On failure, the bitmap will be set to empty and return false. */ - bool allocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*); + bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo&, SkPixelRefFactory*, SkColorTable*); + + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, + SkColorTable* ctable) { + if (!this->tryAllocPixels(info, factory, ctable)) { + SK_ALLOCPIXELS_RETURN_FAIL; + } + SK_ALLOCPIXELS_RETURN_TRUE; + } /** * Allocate the bitmap's pixels to match the requested image info and @@ -228,26 +246,39 @@ public: * the pixel size specified by info.colorType()) then false is returned * and the bitmap is set to empty. */ - bool allocPixels(const SkImageInfo& info, size_t rowBytes); + bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info, size_t rowBytes); - /** - * Allocate a pixelref to match the specified image info, using the default - * allocator. - * On success, the bitmap's pixels will be "locked", and return true. - * On failure, the bitmap will be set to empty and return false. - */ - bool allocPixels(const SkImageInfo& info) { + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, size_t rowBytes) { + if (!this->tryAllocPixels(info, rowBytes)) { + SK_ALLOCPIXELS_RETURN_FAIL; + } + SK_ALLOCPIXELS_RETURN_TRUE; + } + + bool SK_WARN_UNUSED_RESULT tryAllocPixels(const SkImageInfo& info) { + return this->tryAllocPixels(info, info.minRowBytes()); + } + + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info) { return this->allocPixels(info, info.minRowBytes()); } - bool allocN32Pixels(int width, int height, bool isOpaque = false) { + bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false) { + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); + if (isOpaque) { + info.fAlphaType = kOpaque_SkAlphaType; + } + return this->tryAllocPixels(info); + } + + SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaque = false) { SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); if (isOpaque) { info.fAlphaType = kOpaque_SkAlphaType; } return this->allocPixels(info); } - + /** * Install a pixelref that wraps the specified pixels and rowBytes, and * optional ReleaseProc and context. When the pixels are no longer @@ -320,7 +351,11 @@ public: @return true if the allocation succeeds. If not the pixelref field of the bitmap will be unchanged. */ - bool allocPixels(SkColorTable* ctable = NULL) { + bool SK_WARN_UNUSED_RESULT tryAllocPixels(SkColorTable* ctable = NULL) { + return this->tryAllocPixels(NULL, ctable); + } + + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(SkColorTable* ctable = NULL) { return this->allocPixels(NULL, ctable); } @@ -342,7 +377,14 @@ public: @return true if the allocation succeeds. If not the pixelref field of the bitmap will be unchanged. */ - bool allocPixels(Allocator* allocator, SkColorTable* ctable); + bool SK_WARN_UNUSED_RESULT tryAllocPixels(Allocator* allocator, SkColorTable* ctable); + + SK_ALLOCPIXELS_RETURN_TYPE allocPixels(Allocator* allocator, SkColorTable* ctable) { + if (!this->tryAllocPixels(allocator, ctable)) { + SK_ALLOCPIXELS_RETURN_FAIL; + } + SK_ALLOCPIXELS_RETURN_TRUE; + } /** * Return the current pixelref object or NULL if there is none. This does diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 34d1b9736..e8d6d9911 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -999,7 +999,7 @@ void SampleWindow::listTitles() { static SkBitmap capture_bitmap(SkCanvas* canvas) { SkBitmap bm; - if (bm.allocPixels(canvas->imageInfo())) { + if (bm.tryAllocPixels(canvas->imageInfo())) { canvas->readPixels(&bm, 0, 0); } return bm; diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index 8aa48ed5c..f4157cd6b 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -153,7 +153,7 @@ static void rand_bitmap_for_canvas(SkBitmap* bitmap) { do { info = SkImageInfo::Make(kBitmapSize, kBitmapSize, rand_colortype(), kPremul_SkAlphaType); - } while (!valid_for_raster_canvas(info) || !bitmap->allocPixels(info)); + } while (!valid_for_raster_canvas(info) || !bitmap->tryAllocPixels(info)); } static void make_g_bitmap(SkBitmap& bitmap) { diff --git a/samplecode/SampleUnpremul.cpp b/samplecode/SampleUnpremul.cpp index bfe69e0b5..992444d05 100644 --- a/samplecode/SampleUnpremul.cpp +++ b/samplecode/SampleUnpremul.cpp @@ -128,11 +128,7 @@ protected: // Copy it to a bitmap which can be drawn, converting // to premultiplied: SkBitmap bm; - if (!bm.allocN32Pixels(fBitmap.width(), fBitmap.height())) { - SkString errMsg("allocPixels failed"); - canvas->drawText(errMsg.c_str(), errMsg.size(), 0, height, paint); - return; - } + bm.allocN32Pixels(fBitmap.width(), fBitmap.height()); for (int i = 0; i < fBitmap.width(); ++i) { for (int j = 0; j < fBitmap.height(); ++j) { *bm.getAddr32(i, j) = premultiply_unpmcolor(*fBitmap.getAddr32(i, j)); diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index d83199ddc..928a4b74e 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -268,7 +268,7 @@ void SkBitmap::setPixels(void* p, SkColorTable* ctable) { SkDEBUGCODE(this->validate();) } -bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { +bool SkBitmap::tryAllocPixels(Allocator* allocator, SkColorTable* ctable) { HeapAllocator stdalloc; if (NULL == allocator) { @@ -279,7 +279,7 @@ bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { /////////////////////////////////////////////////////////////////////////////// -bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) { +bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) { if (kIndex_8_SkColorType == requestedInfo.colorType()) { return reset_return_false(this); } @@ -308,8 +308,8 @@ bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) { return true; } -bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactory* factory, - SkColorTable* ctable) { +bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactory* factory, + SkColorTable* ctable) { if (kIndex_8_SkColorType == requestedInfo.fColorType && NULL == ctable) { return reset_return_false(this); } @@ -950,7 +950,7 @@ bool SkBitmap::copyTo(SkBitmap* dst, SkColorType dstColorType, Allocator* alloc) // TODO: can we just ref() the src colortable? Is it reentrant-safe? ctable.reset(SkNEW_ARGS(SkColorTable, (*src->getColorTable()))); } - if (!tmpDst.allocPixels(alloc, ctable)) { + if (!tmpDst.tryAllocPixels(alloc, ctable)) { return false; } @@ -1122,7 +1122,7 @@ bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, } else { NO_FILTER_CASE: tmpBitmap.setInfo(SkImageInfo::MakeA8(this->width(), this->height()), srcM.fRowBytes); - if (!tmpBitmap.allocPixels(allocator, NULL)) { + if (!tmpBitmap.tryAllocPixels(allocator, NULL)) { // Allocation of pixels for alpha bitmap failed. SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", tmpBitmap.width(), tmpBitmap.height()); @@ -1146,7 +1146,7 @@ bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, tmpBitmap.setInfo(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.height()), dstM.fRowBytes); - if (!tmpBitmap.allocPixels(allocator, NULL)) { + if (!tmpBitmap.tryAllocPixels(allocator, NULL)) { // Allocation of pixels for alpha bitmap failed. SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", tmpBitmap.width(), tmpBitmap.height()); diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 5f205ce1e..2287864ba 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -82,7 +82,7 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, return NULL; } } else { - if (!bitmap.allocPixels(info)) { + if (!bitmap.tryAllocPixels(info)) { return NULL; } if (!bitmap.info().isOpaque()) { diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 717878c82..f071fc99f 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -568,7 +568,7 @@ bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) { bool weAllocated = false; if (NULL == bitmap->pixelRef()) { - if (!bitmap->allocPixels()) { + if (!bitmap->tryAllocPixels()) { return false; } weAllocated = true; @@ -594,7 +594,7 @@ bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { return false; } - if (!bitmap->allocN32Pixels(r.width(), r.height())) { + if (!bitmap->tryAllocN32Pixels(r.width(), r.height())) { // bitmap will already be reset. return false; } @@ -1006,7 +1006,7 @@ SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) { fAddr = canvas->peekPixels(&fInfo, &fRowBytes); if (NULL == fAddr) { fInfo = canvas->imageInfo(); - if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.allocPixels(fInfo)) { + if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.tryAllocPixels(fInfo)) { return; // failure, fAddr is NULL } if (!canvas->readPixels(&fBitmap, 0, 0)) { @@ -2535,7 +2535,7 @@ SkCanvas* SkCanvas::NewRaster(const SkImageInfo& info) { } SkBitmap bitmap; - if (!bitmap.allocPixels(info)) { + if (!bitmap.tryAllocPixels(info)) { return NULL; } diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp index 73ab170f1..a7b5412b5 100644 --- a/src/core/SkPictureShader.cpp +++ b/src/core/SkPictureShader.cpp @@ -107,7 +107,7 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri if (!fCachedBitmapShader || tileScale != fCachedTileScale) { SkBitmap bm; - if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) { + if (!bm.tryAllocN32Pixels(tileSize.width(), tileSize.height())) { return NULL; } bm.eraseColor(SK_ColorTRANSPARENT); diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index db3c0fb2f..4d7f3629e 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -437,7 +437,7 @@ static void generateMask(const SkMask& mask, const SkPath& path, SkBitmap bm; if (0 == dstRB) { - if (!bm.allocPixels(info)) { + if (!bm.tryAllocPixels(info)) { // can't allocate offscreen, so empty the mask and return sk_bzero(mask.fImage, mask.computeImageSize()); return; diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp index ce35ba2ba..261640f3e 100644 --- a/src/effects/SkAlphaThresholdFilter.cpp +++ b/src/effects/SkAlphaThresholdFilter.cpp @@ -343,7 +343,7 @@ bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src, return false; } - if (!dst->allocPixels(src.info())) { + if (!dst->tryAllocPixels(src.info())) { return false; } diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp index d08209874..859040000 100644 --- a/src/effects/SkBlurImageFilter.cpp +++ b/src/effects/SkBlurImageFilter.cpp @@ -172,7 +172,7 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy, return false; } - if (!dst->allocPixels(src.info().makeWH(srcBounds.width(), srcBounds.height()))) { + if (!dst->tryAllocPixels(src.info().makeWH(srcBounds.width(), srcBounds.height()))) { return false; } dst->getBounds(&dstBounds); @@ -199,7 +199,7 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy, } SkBitmap temp; - if (!temp.allocPixels(dst->info())) { + if (!temp.tryAllocPixels(dst->info())) { return false; } diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 5d15b4f8e..bb71aa13e 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -254,7 +254,7 @@ bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy, return false; } - if (!dst->allocPixels(color.info().makeWH(bounds.width(), bounds.height()))) { + if (!dst->tryAllocPixels(color.info().makeWH(bounds.width(), bounds.height()))) { return false; } diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 69e27609f..1eb2a3642 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -1016,7 +1016,7 @@ bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, return false; } - if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) { + if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) { return false; } @@ -1134,7 +1134,7 @@ bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, return false; } - if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) { + if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) { return false; } diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index 70e95f6e7..9293f7fc2 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -321,7 +321,7 @@ bool SkMagnifierImageFilter::onFilterImage(Proxy*, const SkBitmap& src, return false; } - if (!dst->allocPixels(src.info())) { + if (!dst->tryAllocPixels(src.info())) { return false; } diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp index aa8b8049c..c8959eecf 100644 --- a/src/effects/SkMatrixConvolutionImageFilter.cpp +++ b/src/effects/SkMatrixConvolutionImageFilter.cpp @@ -265,7 +265,7 @@ static SkBitmap unpremultiplyBitmap(const SkBitmap& src) return SkBitmap(); } SkBitmap result; - if (!result.allocPixels(src.info())) { + if (!result.tryAllocPixels(src.info())) { return SkBitmap(); } for (int y = 0; y < src.height(); ++y) { @@ -307,7 +307,7 @@ bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy, return false; } - if (!result->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) { + if (!result->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) { return false; } diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 2b9c91eb5..c6c470c39 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -166,7 +166,7 @@ bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p return false; } - if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) { + if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) { return false; } @@ -191,7 +191,7 @@ bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p } SkBitmap temp; - if (!temp.allocPixels(dst->info())) { + if (!temp.tryAllocPixels(dst->info())) { return false; } diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp index b7b2d1a7c..b51bae437 100644 --- a/src/gpu/GrSWMaskHelper.cpp +++ b/src/gpu/GrSWMaskHelper.cpp @@ -205,7 +205,7 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds, // allocate the pixels for a bitmap const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(cmpWidth, cmpHeight); if (kBlitter_CompressionMode != fCompressionMode) { - if (!fBM.allocPixels(bmImageInfo)) { + if (!fBM.tryAllocPixels(bmImageInfo)) { return false; } diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp index a07fe67ae..54497fe8c 100644 --- a/src/gpu/GrSurface.cpp +++ b/src/gpu/GrSurface.cpp @@ -25,8 +25,7 @@ SkImageInfo GrSurface::info() const { bool GrSurface::savePixels(const char* filename) { SkBitmap bm; - if (!bm.allocPixels(SkImageInfo::MakeN32Premul(this->width(), - this->height()))) { + if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(this->width(), this->height()))) { return false; } diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp index d378032c0..2371ea72e 100644 --- a/src/gpu/SkGrPixelRef.cpp +++ b/src/gpu/SkGrPixelRef.cpp @@ -170,7 +170,7 @@ bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { top = 0; height = this->info().fHeight; } - if (!dst->allocPixels(SkImageInfo::MakeN32Premul(width, height))) { + if (!dst->tryAllocN32Pixels(width, height)) { SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\n"); return false; } diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 795b8420e..a6063846c 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -117,9 +117,8 @@ bool SkImage_Base::onReadPixels(SkBitmap* bitmap, const SkIRect& subset) const { return false; } } else { - const SkImageInfo info = SkImageInfo::MakeN32Premul(subset.width(), subset.height()); SkBitmap tmp; - if (!tmp.allocPixels(info)) { + if (!tmp.tryAllocN32Pixels(subset.width(), subset.height())) { return false; } *bitmap = tmp; diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp index dfa093bec..5c66c94a5 100644 --- a/src/images/SkDecodingImageGenerator.cpp +++ b/src/images/SkDecodingImageGenerator.cpp @@ -69,7 +69,7 @@ public: virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) { if (NULL == fTarget || !equal_modulo_alpha(fInfo, bm->info())) { // Call default allocator. - return bm->allocPixels(NULL, ct); + return bm->tryAllocPixels(NULL, ct); } // TODO(halcanary): verify that all callers of this function diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp index ed2ad164a..4a5e73462 100644 --- a/src/images/SkImageDecoder.cpp +++ b/src/images/SkImageDecoder.cpp @@ -133,7 +133,7 @@ bool SkImageDecoder::chooseFromOneChoice(SkColorType colorType, int width, int h bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) const { - return bitmap->allocPixels(fAllocator, ctable); + return bitmap->tryAllocPixels(fAllocator, ctable); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp index 9b937162b..99401e6b6 100644 --- a/src/images/SkImageDecoder_libjpeg.cpp +++ b/src/images/SkImageDecoder_libjpeg.cpp @@ -852,7 +852,7 @@ bool SkJPEGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) { return return_false(*cinfo, bitmap, "allocPixelRef"); } } else { - if (!bitmap.allocPixels()) { + if (!bitmap.tryAllocPixels()) { return return_false(*cinfo, bitmap, "allocPixels"); } } diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp index 01b7c69c2..b69f87996 100644 --- a/src/images/SkImageDecoder_libpng.cpp +++ b/src/images/SkImageDecoder_libpng.cpp @@ -823,7 +823,7 @@ bool SkPNGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) { return false; } } else { - if (!decodedBitmap.allocPixels(NULL, needColorTable ? colorTable : NULL)) { + if (!decodedBitmap.tryAllocPixels(NULL, needColorTable ? colorTable : NULL)) { return false; } } diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp index f7cfa8b4c..f32587ddc 100644 --- a/src/images/SkImageDecoder_libwebp.cpp +++ b/src/images/SkImageDecoder_libwebp.cpp @@ -375,7 +375,7 @@ bool SkWEBPImageDecoder::onDecodeSubset(SkBitmap* decodedBitmap, // alloc from native heap if it is a temp bitmap. (prevent GC) bool allocResult = (bitmap == decodedBitmap) ? allocPixelRef(bitmap, NULL) - : bitmap->allocPixels(); + : bitmap->tryAllocPixels(); if (!allocResult) { return return_false(*decodedBitmap, "allocPixelRef"); } diff --git a/src/images/SkMovie_gif.cpp b/src/images/SkMovie_gif.cpp index decefd5ac..3810db566 100644 --- a/src/images/SkMovie_gif.cpp +++ b/src/images/SkMovie_gif.cpp @@ -364,11 +364,11 @@ bool SkGIFMovie::onGetBitmap(SkBitmap* bm) startIndex = 0; // create bitmap - if (!bm->allocPixels(SkImageInfo::MakeN32Premul(width, height))) { + if (!bm->tryAllocN32Pixels(width, height)) { return false; } // create bitmap for backup - if (!fBackup.allocPixels(SkImageInfo::MakeN32Premul(width, height))) { + if (!fBackup.tryAllocN32Pixels(width, height)) { return false; } } else if (startIndex > fCurrIndex) { diff --git a/src/lazy/SkCachingPixelRef.cpp b/src/lazy/SkCachingPixelRef.cpp index 56431880c..bd675324f 100644 --- a/src/lazy/SkCachingPixelRef.cpp +++ b/src/lazy/SkCachingPixelRef.cpp @@ -46,7 +46,7 @@ bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) { const SkImageInfo& info = this->info(); if (!SkBitmapCache::Find(this->getGenerationID(), info.fWidth, info.fHeight, &fLockedBitmap)) { // Cache has been purged, must re-decode. - if (!fLockedBitmap.allocPixels(info, fRowBytes)) { + if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) { fErrorInDecoding = true; return false; } diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp index a86c3deff..ec8d5ea9a 100644 --- a/src/lazy/SkDiscardablePixelRef.cpp +++ b/src/lazy/SkDiscardablePixelRef.cpp @@ -110,7 +110,7 @@ bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst, SkASSERT(info.colorType() != kUnknown_SkColorType); if (dst->empty()) { // Use a normal pixelref. - return dst->allocPixels(); + return dst->tryAllocPixels(); } SkAutoTUnref ref( SkNEW_ARGS(SkDiscardablePixelRef, diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index ec07a8ff0..f4ea69445 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -2120,7 +2120,7 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix, const int w = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().width()); const int h = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().height()); - if (!perspectiveBitmap.allocPixels(SkImageInfo::MakeN32Premul(w, h))) { + if (!perspectiveBitmap.tryAllocN32Pixels(w, h)) { return; } perspectiveBitmap.eraseColor(SK_ColorTRANSPARENT); diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp index 49460510d..0c9b7417a 100644 --- a/src/pdf/SkPDFImage.cpp +++ b/src/pdf/SkPDFImage.cpp @@ -375,8 +375,7 @@ static uint16_t get_argb4444_neighbor_avg_color(const SkBitmap& bitmap, static SkBitmap unpremultiply_bitmap(const SkBitmap& bitmap, const SkIRect& srcRect) { SkBitmap outBitmap; - SkAssertResult(outBitmap.allocPixels( - bitmap.info().makeWH(srcRect.width(), srcRect.height()))); + outBitmap.allocPixels(bitmap.info().makeWH(srcRect.width(), srcRect.height())); int dstRow = 0; SkAutoLockPixels outBitmapPixelLock(outBitmap); diff --git a/src/utils/SkPDFRasterizer.cpp b/src/utils/SkPDFRasterizer.cpp index 66634804b..1cb792fb8 100644 --- a/src/utils/SkPDFRasterizer.cpp +++ b/src/utils/SkPDFRasterizer.cpp @@ -50,7 +50,7 @@ bool SkPopplerRasterizePDF(SkStream* pdf, SkBitmap* output) { char *imgData = image.data(); SkBitmap bitmap; - if (!bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height))) { + if (!bitmap.tryAllocN32Pixels(width, height)) { return false; } bitmap.eraseColor(SK_ColorWHITE); diff --git a/src/utils/mac/SkCreateCGImageRef.cpp b/src/utils/mac/SkCreateCGImageRef.cpp index 01b774df0..14a24d871 100644 --- a/src/utils/mac/SkCreateCGImageRef.cpp +++ b/src/utils/mac/SkCreateCGImageRef.cpp @@ -221,7 +221,7 @@ bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output) { int h = (int)CGRectGetHeight(bounds); SkBitmap bitmap; - if (!bitmap.allocPixels(SkImageInfo::MakeN32Premul(w, h))) { + if (!bitmap.tryAllocN32Pixels(w, h)) { return false; } bitmap.eraseColor(SK_ColorWHITE); @@ -287,7 +287,7 @@ bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef image, SkISize* scaleTo SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); SkBitmap tmp; - if (!tmp.allocPixels(info)) { + if (!tmp.tryAllocPixels(info)) { return false; } diff --git a/tests/ARGBImageEncoderTest.cpp b/tests/ARGBImageEncoderTest.cpp index 18f315fca..4d16f4cc6 100644 --- a/tests/ARGBImageEncoderTest.cpp +++ b/tests/ARGBImageEncoderTest.cpp @@ -35,9 +35,8 @@ DEF_TEST(ARGBImageEncoder, reporter) { // A bitmap that should generate the above bytes: SkBitmap bitmap; { - bool success = bitmap.allocPixels(SkImageInfo::Make(kWidth, kHeight, - gColorTypes[ctIndex], kOpaque_SkAlphaType)); - REPORTER_ASSERT(reporter, success); + bitmap.allocPixels(SkImageInfo::Make(kWidth, kHeight, gColorTypes[ctIndex], + 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 4a49a6b48..6a20668cf 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -387,14 +387,16 @@ DEF_TEST(BitmapCopy, reporter) { ct = init_ctable(kPremul_SkAlphaType); } + int localSubW; if (isExtracted[copyCase]) { // A larger image to extract from. - src.allocPixels(SkImageInfo::Make(2 * subW + 1, subH, - gPairs[i].fColorType, - kPremul_SkAlphaType)); + localSubW = 2 * subW + 1; } else { // Tests expect a 2x2 bitmap, so make smaller. - src.allocPixels(SkImageInfo::Make(subW, subH, - gPairs[i].fColorType, - kPremul_SkAlphaType)); + localSubW = subW; + } + // could fail if we pass kIndex_8 for the colortype + if (src.tryAllocPixels(SkImageInfo::Make(localSubW, subH, gPairs[i].fColorType, + kPremul_SkAlphaType))) { + // failure is fine, as we will notice later on } SkSafeUnref(ct); diff --git a/tests/BitmapHasherTest.cpp b/tests/BitmapHasherTest.cpp index e39439a11..3b5170692 100644 --- a/tests/BitmapHasherTest.cpp +++ b/tests/BitmapHasherTest.cpp @@ -17,8 +17,7 @@ typedef uint64_t checksum_result; // Fill in bitmap with test data. static void CreateTestBitmap(SkBitmap* bitmap, int width, int height, SkColor color, skiatest::Reporter* reporter) { - SkImageInfo info = SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType); - REPORTER_ASSERT(reporter, bitmap->allocPixels(info)); + bitmap->allocN32Pixels(width, height, kOpaque_SkAlphaType); bitmap->eraseColor(color); } diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp index 42ed8841b..4826b831f 100644 --- a/tests/BitmapTest.cpp +++ b/tests/BitmapTest.cpp @@ -75,7 +75,7 @@ DEF_TEST(Bitmap, reporter) { bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height)); REPORTER_ASSERT(reporter, setConf); if (setConf) { - REPORTER_ASSERT(reporter, bm.allocPixels(NULL)); + bm.allocPixels(); } REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty()); } diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp index 65623d0e4..7c63a0e92 100644 --- a/tests/CachedDecodingPixelRefTest.cpp +++ b/tests/CachedDecodingPixelRefTest.cpp @@ -348,8 +348,7 @@ DEF_TEST(Image_NewFromGenerator, r) { REPORTER_ASSERT(r, TestImageGenerator::Height() == image->height()); SkBitmap bitmap; - SkAssertResult(bitmap.allocN32Pixels(TestImageGenerator::Width(), - TestImageGenerator::Height())); + bitmap.allocN32Pixels(TestImageGenerator::Width(), TestImageGenerator::Height()); SkCanvas canvas(bitmap); const SkColor kDefaultColor = 0xffabcdef; canvas.clear(kDefaultColor); diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp index 6dca98b52..720155ca0 100644 --- a/tests/DrawBitmapRectTest.cpp +++ b/tests/DrawBitmapRectTest.cpp @@ -190,7 +190,9 @@ static void test_wacky_bitmapshader(skiatest::Reporter* reporter, c.concat(matrix); SkBitmap bm; - bm.allocN32Pixels(width, height); + if (bm.tryAllocN32Pixels(width, height)) { + // allow this to fail silently, to test the code downstream + } bm.eraseColor(SK_ColorRED); matrix.setAll(0.0078740157f, diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp index 8838e7556..4d2616737 100644 --- a/tests/ImageDecodingTest.cpp +++ b/tests/ImageDecodingTest.cpp @@ -770,7 +770,7 @@ public: fSize = 0; return true; } - return bm->allocPixels(NULL, ct); + return bm->tryAllocPixels(NULL, ct); } bool ready() { return fPixels != NULL; } private: diff --git a/tests/KtxTest.cpp b/tests/KtxTest.cpp index bddd09abb..32dacd5a0 100644 --- a/tests/KtxTest.cpp +++ b/tests/KtxTest.cpp @@ -28,8 +28,7 @@ DEF_TEST(KtxReadWrite, reporter) { SkRandom rand(0x1005cbad); SkBitmap bm8888; - bool pixelsAllocated = bm8888.allocN32Pixels(128, 128); - REPORTER_ASSERT(reporter, pixelsAllocated); + bm8888.allocN32Pixels(128, 128); uint8_t *pixels = reinterpret_cast(bm8888.getPixels()); REPORTER_ASSERT(reporter, NULL != pixels); diff --git a/tests/PathOpsSkpClipTest.cpp b/tests/PathOpsSkpClipTest.cpp index d413a08a6..cdc3c1fcd 100755 --- a/tests/PathOpsSkpClipTest.cpp +++ b/tests/PathOpsSkpClipTest.cpp @@ -482,8 +482,7 @@ void TestResult::testOne() { do { int dimX = SkScalarCeilToInt(width / fScale); int dimY = SkScalarCeilToInt(height / fScale); - if (oldBitmap.allocN32Pixels(dimX, dimY) && - opBitmap.allocN32Pixels(dimX, dimY)) { + if (oldBitmap.tryAllocN32Pixels(dimX, dimY) && opBitmap.tryAllocN32Pixels(dimX, dimY)) { break; } SkDebugf("-%d-", fScale); diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index d0bf9031f..77aac1fdd 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -96,9 +96,7 @@ static SkPMColor convertToPMColor(SkColorType ct, SkAlphaType at, const uint32_t static void fillCanvas(SkCanvas* canvas) { static SkBitmap bmp; if (bmp.isNull()) { - SkDEBUGCODE(bool alloc =) bmp.allocN32Pixels(DEV_W, DEV_H); - SkASSERT(alloc); - SkAutoLockPixels alp(bmp); + bmp.allocN32Pixels(DEV_W, DEV_H); intptr_t pixels = reinterpret_cast(bmp.getPixels()); for (int y = 0; y < DEV_H; ++y) { for (int x = 0; x < DEV_W; ++x) { diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index 4e11f120d..450f94f47 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp @@ -335,14 +335,12 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) { compare_bitmaps(reporter, origBitmap, destBitmap); } -static bool setup_bitmap_for_canvas(SkBitmap* bitmap) { - SkImageInfo info = SkImageInfo::Make( - kBitmapSize, kBitmapSize, kN32_SkColorType, kPremul_SkAlphaType); - return bitmap->allocPixels(info); +static void setup_bitmap_for_canvas(SkBitmap* bitmap) { + bitmap->allocN32Pixels(kBitmapSize, kBitmapSize); } -static bool make_checkerboard_bitmap(SkBitmap& bitmap) { - bool success = setup_bitmap_for_canvas(&bitmap); +static void make_checkerboard_bitmap(SkBitmap& bitmap) { + setup_bitmap_for_canvas(&bitmap); SkCanvas canvas(bitmap); canvas.clear(0x00000000); @@ -363,14 +361,12 @@ static bool make_checkerboard_bitmap(SkBitmap& bitmap) { canvas.restore(); } } - - return success; } -static bool draw_something(SkCanvas* canvas) { +static void draw_something(SkCanvas* canvas) { SkPaint paint; SkBitmap bitmap; - bool success = make_checkerboard_bitmap(bitmap); + make_checkerboard_bitmap(bitmap); canvas->save(); canvas->scale(0.5f, 0.5f); @@ -389,8 +385,6 @@ static bool draw_something(SkCanvas* canvas) { paint.setColor(SK_ColorBLACK); paint.setTextSize(SkIntToScalar(kBitmapSize/3)); canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), paint); - - return success; } DEF_TEST(Serialization, reporter) { @@ -481,10 +475,9 @@ DEF_TEST(Serialization, reporter) { // Test simple SkPicture serialization { SkPictureRecorder recorder; - bool didDraw = draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize), - SkIntToScalar(kBitmapSize), - NULL, 0)); - REPORTER_ASSERT(reporter, didDraw); + draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize), + SkIntToScalar(kBitmapSize), + NULL, 0)); SkAutoTUnref pict(recorder.endRecording()); // Serialize picture diff --git a/tests/SkResourceCacheTest.cpp b/tests/SkResourceCacheTest.cpp index b71c7443e..454f8c204 100644 --- a/tests/SkResourceCacheTest.cpp +++ b/tests/SkResourceCacheTest.cpp @@ -27,7 +27,7 @@ static bool test_scaled_image_cache_useage() { SkAutoTUnref canvas( SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize)); SkBitmap bitmap; - SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize)); + bitmap.allocN32Pixels(kBitmapSize, kBitmapSize); bitmap.eraseColor(0xFFFFFFFF); SkScalar scale = SkIntToScalar(kScale); SkScalar scaledSize = SkIntToScalar(kBitmapSize) * scale; diff --git a/tests/TextureCompressionTest.cpp b/tests/TextureCompressionTest.cpp index da7a87bd4..b93cabb4e 100644 --- a/tests/TextureCompressionTest.cpp +++ b/tests/TextureCompressionTest.cpp @@ -58,8 +58,7 @@ DEF_TEST(CompressAlphaFailDimensions, reporter) { bool setInfoSuccess = bitmap.setInfo(info); REPORTER_ASSERT(reporter, setInfoSuccess); - bool allocPixelsSuccess = bitmap.allocPixels(info); - REPORTER_ASSERT(reporter, allocPixelsSuccess); + bitmap.allocPixels(info); bitmap.unlockPixels(); for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { @@ -92,8 +91,7 @@ DEF_TEST(CompressAlphaFailColorType, reporter) { bool setInfoSuccess = bitmap.setInfo(info); REPORTER_ASSERT(reporter, setInfoSuccess); - bool allocPixelsSuccess = bitmap.allocPixels(info); - REPORTER_ASSERT(reporter, allocPixelsSuccess); + bitmap.allocPixels(info); bitmap.unlockPixels(); for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { @@ -128,8 +126,7 @@ DEF_TEST(CompressCheckerboard, reporter) { bool setInfoSuccess = bitmap.setInfo(info); REPORTER_ASSERT(reporter, setInfoSuccess); - bool allocPixelsSuccess = bitmap.allocPixels(info); - REPORTER_ASSERT(reporter, allocPixelsSuccess); + bitmap.allocPixels(info); bitmap.unlockPixels(); // Populate bitmap @@ -215,8 +212,7 @@ DEF_TEST(CompressLATC, reporter) { bool setInfoSuccess = bitmap.setInfo(info); REPORTER_ASSERT(reporter, setInfoSuccess); - bool allocPixelsSuccess = bitmap.allocPixels(info); - REPORTER_ASSERT(reporter, allocPixelsSuccess); + bitmap.allocPixels(info); bitmap.unlockPixels(); int latcDimX, latcDimY; diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp index 2a8d0592b..f47c67bd3 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -115,8 +115,7 @@ static uint32_t getBitmapColor(int x, int y, int w, SkColorType ct, SkAlphaType static void fillCanvas(SkCanvas* canvas) { SkBitmap bmp; if (bmp.isNull()) { - SkDEBUGCODE(bool alloc = ) bmp.allocN32Pixels(DEV_W, DEV_H); - SkASSERT(alloc); + bmp.allocN32Pixels(DEV_W, DEV_H); for (int y = 0; y < DEV_H; ++y) { for (int x = 0; x < DEV_W; ++x) { *bmp.getAddr32(x, y) = getCanvasColor(x, y);