reed 2014-09-02 12:50:45 -07:00 коммит произвёл Commit bot
Родитель 00f30bdc9e
Коммит 848250415e
47 изменённых файлов: 137 добавлений и 116 удалений

Просмотреть файл

@ -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',

Просмотреть файл

@ -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,19 +246,32 @@ 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;
@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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));

Просмотреть файл

@ -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());

Просмотреть файл

@ -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()) {

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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

Просмотреть файл

@ -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);
}
///////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -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");
}
}

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -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");
}

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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<SkDiscardablePixelRef> ref(
SkNEW_ARGS(SkDiscardablePixelRef,

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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());
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -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,

Просмотреть файл

@ -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:

Просмотреть файл

@ -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<uint8_t*>(bm8888.getPixels());
REPORTER_ASSERT(reporter, NULL != pixels);

Просмотреть файл

@ -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);

Просмотреть файл

@ -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<intptr_t>(bmp.getPixels());
for (int y = 0; y < DEV_H; ++y) {
for (int x = 0; x < DEV_W; ++x) {

Просмотреть файл

@ -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<SkPicture> pict(recorder.endRecording());
// Serialize picture

Просмотреть файл

@ -27,7 +27,7 @@ static bool test_scaled_image_cache_useage() {
SkAutoTUnref<SkCanvas> 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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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);