зеркало из https://github.com/mozilla/moz-skia.git
make allocPixels throw on failure
BUG=skia: R=mtklein@google.com, fmalita@google.com, fmalita@chromium.org Author: reed@google.com Review URL: https://codereview.chromium.org/510423005
This commit is contained in:
Родитель
00f30bdc9e
Коммит
848250415e
|
@ -13,6 +13,7 @@
|
||||||
# If these become 'permanent', they should be moved into skia_common.gypi
|
# If these become 'permanent', they should be moved into skia_common.gypi
|
||||||
#
|
#
|
||||||
'skia_for_chromium_defines': [
|
'skia_for_chromium_defines': [
|
||||||
|
'SK_SUPPORT_LEGACY_ALLOCPIXELS_BOOL',
|
||||||
'SK_IGNORE_PROPER_FRACTIONAL_SCALING',
|
'SK_IGNORE_PROPER_FRACTIONAL_SCALING',
|
||||||
'SK_SUPPORT_LEGACY_PICTURE_CLONE',
|
'SK_SUPPORT_LEGACY_PICTURE_CLONE',
|
||||||
'SK_SUPPORT_LEGACY_GETDEVICE',
|
'SK_SUPPORT_LEGACY_GETDEVICE',
|
||||||
|
|
|
@ -14,6 +14,16 @@
|
||||||
#include "SkPoint.h"
|
#include "SkPoint.h"
|
||||||
#include "SkRefCnt.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 SkMask;
|
||||||
struct SkIRect;
|
struct SkIRect;
|
||||||
struct SkRect;
|
struct SkRect;
|
||||||
|
@ -218,7 +228,15 @@ public:
|
||||||
* a colortable, then ColorTable must be non-null, and will be ref'd.
|
* 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.
|
* 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
|
* 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
|
* the pixel size specified by info.colorType()) then false is returned
|
||||||
* and the bitmap is set to empty.
|
* 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);
|
||||||
|
|
||||||
/**
|
SK_ALLOCPIXELS_RETURN_TYPE allocPixels(const SkImageInfo& info, size_t rowBytes) {
|
||||||
* Allocate a pixelref to match the specified image info, using the default
|
if (!this->tryAllocPixels(info, rowBytes)) {
|
||||||
* allocator.
|
SK_ALLOCPIXELS_RETURN_FAIL;
|
||||||
* On success, the bitmap's pixels will be "locked", and return true.
|
}
|
||||||
* On failure, the bitmap will be set to empty and return false.
|
SK_ALLOCPIXELS_RETURN_TRUE;
|
||||||
*/
|
}
|
||||||
bool allocPixels(const SkImageInfo& info) {
|
|
||||||
|
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());
|
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);
|
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
||||||
if (isOpaque) {
|
if (isOpaque) {
|
||||||
info.fAlphaType = kOpaque_SkAlphaType;
|
info.fAlphaType = kOpaque_SkAlphaType;
|
||||||
}
|
}
|
||||||
return this->allocPixels(info);
|
return this->allocPixels(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install a pixelref that wraps the specified pixels and rowBytes, and
|
* Install a pixelref that wraps the specified pixels and rowBytes, and
|
||||||
* optional ReleaseProc and context. When the pixels are no longer
|
* 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
|
@return true if the allocation succeeds. If not the pixelref field of
|
||||||
the bitmap will be unchanged.
|
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);
|
return this->allocPixels(NULL, ctable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +377,14 @@ public:
|
||||||
@return true if the allocation succeeds. If not the pixelref field of
|
@return true if the allocation succeeds. If not the pixelref field of
|
||||||
the bitmap will be unchanged.
|
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
|
* 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) {
|
static SkBitmap capture_bitmap(SkCanvas* canvas) {
|
||||||
SkBitmap bm;
|
SkBitmap bm;
|
||||||
if (bm.allocPixels(canvas->imageInfo())) {
|
if (bm.tryAllocPixels(canvas->imageInfo())) {
|
||||||
canvas->readPixels(&bm, 0, 0);
|
canvas->readPixels(&bm, 0, 0);
|
||||||
}
|
}
|
||||||
return bm;
|
return bm;
|
||||||
|
|
|
@ -153,7 +153,7 @@ static void rand_bitmap_for_canvas(SkBitmap* bitmap) {
|
||||||
do {
|
do {
|
||||||
info = SkImageInfo::Make(kBitmapSize, kBitmapSize, rand_colortype(),
|
info = SkImageInfo::Make(kBitmapSize, kBitmapSize, rand_colortype(),
|
||||||
kPremul_SkAlphaType);
|
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) {
|
static void make_g_bitmap(SkBitmap& bitmap) {
|
||||||
|
|
|
@ -128,11 +128,7 @@ protected:
|
||||||
// Copy it to a bitmap which can be drawn, converting
|
// Copy it to a bitmap which can be drawn, converting
|
||||||
// to premultiplied:
|
// to premultiplied:
|
||||||
SkBitmap bm;
|
SkBitmap bm;
|
||||||
if (!bm.allocN32Pixels(fBitmap.width(), fBitmap.height())) {
|
bm.allocN32Pixels(fBitmap.width(), fBitmap.height());
|
||||||
SkString errMsg("allocPixels failed");
|
|
||||||
canvas->drawText(errMsg.c_str(), errMsg.size(), 0, height, paint);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < fBitmap.width(); ++i) {
|
for (int i = 0; i < fBitmap.width(); ++i) {
|
||||||
for (int j = 0; j < fBitmap.height(); ++j) {
|
for (int j = 0; j < fBitmap.height(); ++j) {
|
||||||
*bm.getAddr32(i, j) = premultiply_unpmcolor(*fBitmap.getAddr32(i, 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();)
|
SkDEBUGCODE(this->validate();)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) {
|
bool SkBitmap::tryAllocPixels(Allocator* allocator, SkColorTable* ctable) {
|
||||||
HeapAllocator stdalloc;
|
HeapAllocator stdalloc;
|
||||||
|
|
||||||
if (NULL == allocator) {
|
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()) {
|
if (kIndex_8_SkColorType == requestedInfo.colorType()) {
|
||||||
return reset_return_false(this);
|
return reset_return_false(this);
|
||||||
}
|
}
|
||||||
|
@ -308,8 +308,8 @@ bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkBitmap::allocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactory* factory,
|
bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactory* factory,
|
||||||
SkColorTable* ctable) {
|
SkColorTable* ctable) {
|
||||||
if (kIndex_8_SkColorType == requestedInfo.fColorType && NULL == ctable) {
|
if (kIndex_8_SkColorType == requestedInfo.fColorType && NULL == ctable) {
|
||||||
return reset_return_false(this);
|
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?
|
// TODO: can we just ref() the src colortable? Is it reentrant-safe?
|
||||||
ctable.reset(SkNEW_ARGS(SkColorTable, (*src->getColorTable())));
|
ctable.reset(SkNEW_ARGS(SkColorTable, (*src->getColorTable())));
|
||||||
}
|
}
|
||||||
if (!tmpDst.allocPixels(alloc, ctable)) {
|
if (!tmpDst.tryAllocPixels(alloc, ctable)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1122,7 +1122,7 @@ bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint,
|
||||||
} else {
|
} else {
|
||||||
NO_FILTER_CASE:
|
NO_FILTER_CASE:
|
||||||
tmpBitmap.setInfo(SkImageInfo::MakeA8(this->width(), this->height()), srcM.fRowBytes);
|
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.
|
// Allocation of pixels for alpha bitmap failed.
|
||||||
SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n",
|
SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n",
|
||||||
tmpBitmap.width(), tmpBitmap.height());
|
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()),
|
tmpBitmap.setInfo(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.height()),
|
||||||
dstM.fRowBytes);
|
dstM.fRowBytes);
|
||||||
if (!tmpBitmap.allocPixels(allocator, NULL)) {
|
if (!tmpBitmap.tryAllocPixels(allocator, NULL)) {
|
||||||
// Allocation of pixels for alpha bitmap failed.
|
// Allocation of pixels for alpha bitmap failed.
|
||||||
SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n",
|
SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n",
|
||||||
tmpBitmap.width(), tmpBitmap.height());
|
tmpBitmap.width(), tmpBitmap.height());
|
||||||
|
|
|
@ -82,7 +82,7 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!bitmap.allocPixels(info)) {
|
if (!bitmap.tryAllocPixels(info)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!bitmap.info().isOpaque()) {
|
if (!bitmap.info().isOpaque()) {
|
||||||
|
|
|
@ -568,7 +568,7 @@ bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) {
|
||||||
|
|
||||||
bool weAllocated = false;
|
bool weAllocated = false;
|
||||||
if (NULL == bitmap->pixelRef()) {
|
if (NULL == bitmap->pixelRef()) {
|
||||||
if (!bitmap->allocPixels()) {
|
if (!bitmap->tryAllocPixels()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
weAllocated = true;
|
weAllocated = true;
|
||||||
|
@ -594,7 +594,7 @@ bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bitmap->allocN32Pixels(r.width(), r.height())) {
|
if (!bitmap->tryAllocN32Pixels(r.width(), r.height())) {
|
||||||
// bitmap will already be reset.
|
// bitmap will already be reset.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1006,7 +1006,7 @@ SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) {
|
||||||
fAddr = canvas->peekPixels(&fInfo, &fRowBytes);
|
fAddr = canvas->peekPixels(&fInfo, &fRowBytes);
|
||||||
if (NULL == fAddr) {
|
if (NULL == fAddr) {
|
||||||
fInfo = canvas->imageInfo();
|
fInfo = canvas->imageInfo();
|
||||||
if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.allocPixels(fInfo)) {
|
if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.tryAllocPixels(fInfo)) {
|
||||||
return; // failure, fAddr is NULL
|
return; // failure, fAddr is NULL
|
||||||
}
|
}
|
||||||
if (!canvas->readPixels(&fBitmap, 0, 0)) {
|
if (!canvas->readPixels(&fBitmap, 0, 0)) {
|
||||||
|
@ -2535,7 +2535,7 @@ SkCanvas* SkCanvas::NewRaster(const SkImageInfo& info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
if (!bitmap.allocPixels(info)) {
|
if (!bitmap.tryAllocPixels(info)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
|
||||||
|
|
||||||
if (!fCachedBitmapShader || tileScale != fCachedTileScale) {
|
if (!fCachedBitmapShader || tileScale != fCachedTileScale) {
|
||||||
SkBitmap bm;
|
SkBitmap bm;
|
||||||
if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) {
|
if (!bm.tryAllocN32Pixels(tileSize.width(), tileSize.height())) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bm.eraseColor(SK_ColorTRANSPARENT);
|
bm.eraseColor(SK_ColorTRANSPARENT);
|
||||||
|
|
|
@ -437,7 +437,7 @@ static void generateMask(const SkMask& mask, const SkPath& path,
|
||||||
SkBitmap bm;
|
SkBitmap bm;
|
||||||
|
|
||||||
if (0 == dstRB) {
|
if (0 == dstRB) {
|
||||||
if (!bm.allocPixels(info)) {
|
if (!bm.tryAllocPixels(info)) {
|
||||||
// can't allocate offscreen, so empty the mask and return
|
// can't allocate offscreen, so empty the mask and return
|
||||||
sk_bzero(mask.fImage, mask.computeImageSize());
|
sk_bzero(mask.fImage, mask.computeImageSize());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -343,7 +343,7 @@ bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dst->allocPixels(src.info())) {
|
if (!dst->tryAllocPixels(src.info())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dst->allocPixels(src.info().makeWH(srcBounds.width(), srcBounds.height()))) {
|
if (!dst->tryAllocPixels(src.info().makeWH(srcBounds.width(), srcBounds.height()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dst->getBounds(&dstBounds);
|
dst->getBounds(&dstBounds);
|
||||||
|
@ -199,7 +199,7 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy,
|
||||||
}
|
}
|
||||||
|
|
||||||
SkBitmap temp;
|
SkBitmap temp;
|
||||||
if (!temp.allocPixels(dst->info())) {
|
if (!temp.tryAllocPixels(dst->info())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,7 +254,7 @@ bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dst->allocPixels(color.info().makeWH(bounds.width(), bounds.height()))) {
|
if (!dst->tryAllocPixels(color.info().makeWH(bounds.width(), bounds.height()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1016,7 +1016,7 @@ bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1134,7 +1134,7 @@ bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -321,7 +321,7 @@ bool SkMagnifierImageFilter::onFilterImage(Proxy*, const SkBitmap& src,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dst->allocPixels(src.info())) {
|
if (!dst->tryAllocPixels(src.info())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,7 @@ static SkBitmap unpremultiplyBitmap(const SkBitmap& src)
|
||||||
return SkBitmap();
|
return SkBitmap();
|
||||||
}
|
}
|
||||||
SkBitmap result;
|
SkBitmap result;
|
||||||
if (!result.allocPixels(src.info())) {
|
if (!result.tryAllocPixels(src.info())) {
|
||||||
return SkBitmap();
|
return SkBitmap();
|
||||||
}
|
}
|
||||||
for (int y = 0; y < src.height(); ++y) {
|
for (int y = 0; y < src.height(); ++y) {
|
||||||
|
@ -307,7 +307,7 @@ bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
if (!result->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p
|
||||||
}
|
}
|
||||||
|
|
||||||
SkBitmap temp;
|
SkBitmap temp;
|
||||||
if (!temp.allocPixels(dst->info())) {
|
if (!temp.tryAllocPixels(dst->info())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,7 +205,7 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds,
|
||||||
// allocate the pixels for a bitmap
|
// allocate the pixels for a bitmap
|
||||||
const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(cmpWidth, cmpHeight);
|
const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(cmpWidth, cmpHeight);
|
||||||
if (kBlitter_CompressionMode != fCompressionMode) {
|
if (kBlitter_CompressionMode != fCompressionMode) {
|
||||||
if (!fBM.allocPixels(bmImageInfo)) {
|
if (!fBM.tryAllocPixels(bmImageInfo)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,7 @@ SkImageInfo GrSurface::info() const {
|
||||||
|
|
||||||
bool GrSurface::savePixels(const char* filename) {
|
bool GrSurface::savePixels(const char* filename) {
|
||||||
SkBitmap bm;
|
SkBitmap bm;
|
||||||
if (!bm.allocPixels(SkImageInfo::MakeN32Premul(this->width(),
|
if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(this->width(), this->height()))) {
|
||||||
this->height()))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
|
||||||
top = 0;
|
top = 0;
|
||||||
height = this->info().fHeight;
|
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");
|
SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,9 +117,8 @@ bool SkImage_Base::onReadPixels(SkBitmap* bitmap, const SkIRect& subset) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const SkImageInfo info = SkImageInfo::MakeN32Premul(subset.width(), subset.height());
|
|
||||||
SkBitmap tmp;
|
SkBitmap tmp;
|
||||||
if (!tmp.allocPixels(info)) {
|
if (!tmp.tryAllocN32Pixels(subset.width(), subset.height())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*bitmap = tmp;
|
*bitmap = tmp;
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) {
|
virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) {
|
||||||
if (NULL == fTarget || !equal_modulo_alpha(fInfo, bm->info())) {
|
if (NULL == fTarget || !equal_modulo_alpha(fInfo, bm->info())) {
|
||||||
// Call default allocator.
|
// Call default allocator.
|
||||||
return bm->allocPixels(NULL, ct);
|
return bm->tryAllocPixels(NULL, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(halcanary): verify that all callers of this function
|
// 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,
|
bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap,
|
||||||
SkColorTable* ctable) const {
|
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");
|
return return_false(*cinfo, bitmap, "allocPixelRef");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!bitmap.allocPixels()) {
|
if (!bitmap.tryAllocPixels()) {
|
||||||
return return_false(*cinfo, bitmap, "allocPixels");
|
return return_false(*cinfo, bitmap, "allocPixels");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -823,7 +823,7 @@ bool SkPNGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!decodedBitmap.allocPixels(NULL, needColorTable ? colorTable : NULL)) {
|
if (!decodedBitmap.tryAllocPixels(NULL, needColorTable ? colorTable : NULL)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -375,7 +375,7 @@ bool SkWEBPImageDecoder::onDecodeSubset(SkBitmap* decodedBitmap,
|
||||||
// alloc from native heap if it is a temp bitmap. (prevent GC)
|
// alloc from native heap if it is a temp bitmap. (prevent GC)
|
||||||
bool allocResult = (bitmap == decodedBitmap)
|
bool allocResult = (bitmap == decodedBitmap)
|
||||||
? allocPixelRef(bitmap, NULL)
|
? allocPixelRef(bitmap, NULL)
|
||||||
: bitmap->allocPixels();
|
: bitmap->tryAllocPixels();
|
||||||
if (!allocResult) {
|
if (!allocResult) {
|
||||||
return return_false(*decodedBitmap, "allocPixelRef");
|
return return_false(*decodedBitmap, "allocPixelRef");
|
||||||
}
|
}
|
||||||
|
|
|
@ -364,11 +364,11 @@ bool SkGIFMovie::onGetBitmap(SkBitmap* bm)
|
||||||
startIndex = 0;
|
startIndex = 0;
|
||||||
|
|
||||||
// create bitmap
|
// create bitmap
|
||||||
if (!bm->allocPixels(SkImageInfo::MakeN32Premul(width, height))) {
|
if (!bm->tryAllocN32Pixels(width, height)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// create bitmap for backup
|
// create bitmap for backup
|
||||||
if (!fBackup.allocPixels(SkImageInfo::MakeN32Premul(width, height))) {
|
if (!fBackup.tryAllocN32Pixels(width, height)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (startIndex > fCurrIndex) {
|
} else if (startIndex > fCurrIndex) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
|
||||||
const SkImageInfo& info = this->info();
|
const SkImageInfo& info = this->info();
|
||||||
if (!SkBitmapCache::Find(this->getGenerationID(), info.fWidth, info.fHeight, &fLockedBitmap)) {
|
if (!SkBitmapCache::Find(this->getGenerationID(), info.fWidth, info.fHeight, &fLockedBitmap)) {
|
||||||
// Cache has been purged, must re-decode.
|
// Cache has been purged, must re-decode.
|
||||||
if (!fLockedBitmap.allocPixels(info, fRowBytes)) {
|
if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) {
|
||||||
fErrorInDecoding = true;
|
fErrorInDecoding = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst,
|
||||||
|
|
||||||
SkASSERT(info.colorType() != kUnknown_SkColorType);
|
SkASSERT(info.colorType() != kUnknown_SkColorType);
|
||||||
if (dst->empty()) { // Use a normal pixelref.
|
if (dst->empty()) { // Use a normal pixelref.
|
||||||
return dst->allocPixels();
|
return dst->tryAllocPixels();
|
||||||
}
|
}
|
||||||
SkAutoTUnref<SkDiscardablePixelRef> ref(
|
SkAutoTUnref<SkDiscardablePixelRef> ref(
|
||||||
SkNEW_ARGS(SkDiscardablePixelRef,
|
SkNEW_ARGS(SkDiscardablePixelRef,
|
||||||
|
|
|
@ -2120,7 +2120,7 @@ void SkPDFDevice::internalDrawBitmap(const SkMatrix& origMatrix,
|
||||||
|
|
||||||
const int w = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().width());
|
const int w = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().width());
|
||||||
const int h = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().height());
|
const int h = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().height());
|
||||||
if (!perspectiveBitmap.allocPixels(SkImageInfo::MakeN32Premul(w, h))) {
|
if (!perspectiveBitmap.tryAllocN32Pixels(w, h)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
perspectiveBitmap.eraseColor(SK_ColorTRANSPARENT);
|
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,
|
static SkBitmap unpremultiply_bitmap(const SkBitmap& bitmap,
|
||||||
const SkIRect& srcRect) {
|
const SkIRect& srcRect) {
|
||||||
SkBitmap outBitmap;
|
SkBitmap outBitmap;
|
||||||
SkAssertResult(outBitmap.allocPixels(
|
outBitmap.allocPixels(bitmap.info().makeWH(srcRect.width(), srcRect.height()));
|
||||||
bitmap.info().makeWH(srcRect.width(), srcRect.height())));
|
|
||||||
int dstRow = 0;
|
int dstRow = 0;
|
||||||
|
|
||||||
SkAutoLockPixels outBitmapPixelLock(outBitmap);
|
SkAutoLockPixels outBitmapPixelLock(outBitmap);
|
||||||
|
|
|
@ -50,7 +50,7 @@ bool SkPopplerRasterizePDF(SkStream* pdf, SkBitmap* output) {
|
||||||
char *imgData = image.data();
|
char *imgData = image.data();
|
||||||
|
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
if (!bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height))) {
|
if (!bitmap.tryAllocN32Pixels(width, height)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bitmap.eraseColor(SK_ColorWHITE);
|
bitmap.eraseColor(SK_ColorWHITE);
|
||||||
|
|
|
@ -221,7 +221,7 @@ bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output) {
|
||||||
int h = (int)CGRectGetHeight(bounds);
|
int h = (int)CGRectGetHeight(bounds);
|
||||||
|
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
if (!bitmap.allocPixels(SkImageInfo::MakeN32Premul(w, h))) {
|
if (!bitmap.tryAllocN32Pixels(w, h)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bitmap.eraseColor(SK_ColorWHITE);
|
bitmap.eraseColor(SK_ColorWHITE);
|
||||||
|
@ -287,7 +287,7 @@ bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef image, SkISize* scaleTo
|
||||||
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
||||||
|
|
||||||
SkBitmap tmp;
|
SkBitmap tmp;
|
||||||
if (!tmp.allocPixels(info)) {
|
if (!tmp.tryAllocPixels(info)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,8 @@ DEF_TEST(ARGBImageEncoder, reporter) {
|
||||||
// A bitmap that should generate the above bytes:
|
// A bitmap that should generate the above bytes:
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
{
|
{
|
||||||
bool success = bitmap.allocPixels(SkImageInfo::Make(kWidth, kHeight,
|
bitmap.allocPixels(SkImageInfo::Make(kWidth, kHeight, gColorTypes[ctIndex],
|
||||||
gColorTypes[ctIndex], kOpaque_SkAlphaType));
|
kOpaque_SkAlphaType));
|
||||||
REPORTER_ASSERT(reporter, success);
|
|
||||||
bitmap.eraseColor(SK_ColorBLUE);
|
bitmap.eraseColor(SK_ColorBLUE);
|
||||||
// Change rows [0,1] from blue to [red,green].
|
// Change rows [0,1] from blue to [red,green].
|
||||||
SkCanvas canvas(bitmap);
|
SkCanvas canvas(bitmap);
|
||||||
|
|
|
@ -387,14 +387,16 @@ DEF_TEST(BitmapCopy, reporter) {
|
||||||
ct = init_ctable(kPremul_SkAlphaType);
|
ct = init_ctable(kPremul_SkAlphaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int localSubW;
|
||||||
if (isExtracted[copyCase]) { // A larger image to extract from.
|
if (isExtracted[copyCase]) { // A larger image to extract from.
|
||||||
src.allocPixels(SkImageInfo::Make(2 * subW + 1, subH,
|
localSubW = 2 * subW + 1;
|
||||||
gPairs[i].fColorType,
|
|
||||||
kPremul_SkAlphaType));
|
|
||||||
} else { // Tests expect a 2x2 bitmap, so make smaller.
|
} else { // Tests expect a 2x2 bitmap, so make smaller.
|
||||||
src.allocPixels(SkImageInfo::Make(subW, subH,
|
localSubW = subW;
|
||||||
gPairs[i].fColorType,
|
}
|
||||||
kPremul_SkAlphaType));
|
// 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);
|
SkSafeUnref(ct);
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,7 @@ typedef uint64_t checksum_result;
|
||||||
// Fill in bitmap with test data.
|
// Fill in bitmap with test data.
|
||||||
static void CreateTestBitmap(SkBitmap* bitmap, int width, int height,
|
static void CreateTestBitmap(SkBitmap* bitmap, int width, int height,
|
||||||
SkColor color, skiatest::Reporter* reporter) {
|
SkColor color, skiatest::Reporter* reporter) {
|
||||||
SkImageInfo info = SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType);
|
bitmap->allocN32Pixels(width, height, kOpaque_SkAlphaType);
|
||||||
REPORTER_ASSERT(reporter, bitmap->allocPixels(info));
|
|
||||||
bitmap->eraseColor(color);
|
bitmap->eraseColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ DEF_TEST(Bitmap, reporter) {
|
||||||
bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height));
|
bool setConf = bm.setInfo(SkImageInfo::MakeN32Premul(width, height));
|
||||||
REPORTER_ASSERT(reporter, setConf);
|
REPORTER_ASSERT(reporter, setConf);
|
||||||
if (setConf) {
|
if (setConf) {
|
||||||
REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
|
bm.allocPixels();
|
||||||
}
|
}
|
||||||
REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty());
|
REPORTER_ASSERT(reporter, SkToBool(width & height) != bm.empty());
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,8 +348,7 @@ DEF_TEST(Image_NewFromGenerator, r) {
|
||||||
REPORTER_ASSERT(r, TestImageGenerator::Height() == image->height());
|
REPORTER_ASSERT(r, TestImageGenerator::Height() == image->height());
|
||||||
|
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
SkAssertResult(bitmap.allocN32Pixels(TestImageGenerator::Width(),
|
bitmap.allocN32Pixels(TestImageGenerator::Width(), TestImageGenerator::Height());
|
||||||
TestImageGenerator::Height()));
|
|
||||||
SkCanvas canvas(bitmap);
|
SkCanvas canvas(bitmap);
|
||||||
const SkColor kDefaultColor = 0xffabcdef;
|
const SkColor kDefaultColor = 0xffabcdef;
|
||||||
canvas.clear(kDefaultColor);
|
canvas.clear(kDefaultColor);
|
||||||
|
|
|
@ -190,7 +190,9 @@ static void test_wacky_bitmapshader(skiatest::Reporter* reporter,
|
||||||
c.concat(matrix);
|
c.concat(matrix);
|
||||||
|
|
||||||
SkBitmap bm;
|
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);
|
bm.eraseColor(SK_ColorRED);
|
||||||
|
|
||||||
matrix.setAll(0.0078740157f,
|
matrix.setAll(0.0078740157f,
|
||||||
|
|
|
@ -770,7 +770,7 @@ public:
|
||||||
fSize = 0;
|
fSize = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return bm->allocPixels(NULL, ct);
|
return bm->tryAllocPixels(NULL, ct);
|
||||||
}
|
}
|
||||||
bool ready() { return fPixels != NULL; }
|
bool ready() { return fPixels != NULL; }
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -28,8 +28,7 @@ DEF_TEST(KtxReadWrite, reporter) {
|
||||||
SkRandom rand(0x1005cbad);
|
SkRandom rand(0x1005cbad);
|
||||||
|
|
||||||
SkBitmap bm8888;
|
SkBitmap bm8888;
|
||||||
bool pixelsAllocated = bm8888.allocN32Pixels(128, 128);
|
bm8888.allocN32Pixels(128, 128);
|
||||||
REPORTER_ASSERT(reporter, pixelsAllocated);
|
|
||||||
|
|
||||||
uint8_t *pixels = reinterpret_cast<uint8_t*>(bm8888.getPixels());
|
uint8_t *pixels = reinterpret_cast<uint8_t*>(bm8888.getPixels());
|
||||||
REPORTER_ASSERT(reporter, NULL != pixels);
|
REPORTER_ASSERT(reporter, NULL != pixels);
|
||||||
|
|
|
@ -482,8 +482,7 @@ void TestResult::testOne() {
|
||||||
do {
|
do {
|
||||||
int dimX = SkScalarCeilToInt(width / fScale);
|
int dimX = SkScalarCeilToInt(width / fScale);
|
||||||
int dimY = SkScalarCeilToInt(height / fScale);
|
int dimY = SkScalarCeilToInt(height / fScale);
|
||||||
if (oldBitmap.allocN32Pixels(dimX, dimY) &&
|
if (oldBitmap.tryAllocN32Pixels(dimX, dimY) && opBitmap.tryAllocN32Pixels(dimX, dimY)) {
|
||||||
opBitmap.allocN32Pixels(dimX, dimY)) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SkDebugf("-%d-", fScale);
|
SkDebugf("-%d-", fScale);
|
||||||
|
|
|
@ -96,9 +96,7 @@ static SkPMColor convertToPMColor(SkColorType ct, SkAlphaType at, const uint32_t
|
||||||
static void fillCanvas(SkCanvas* canvas) {
|
static void fillCanvas(SkCanvas* canvas) {
|
||||||
static SkBitmap bmp;
|
static SkBitmap bmp;
|
||||||
if (bmp.isNull()) {
|
if (bmp.isNull()) {
|
||||||
SkDEBUGCODE(bool alloc =) bmp.allocN32Pixels(DEV_W, DEV_H);
|
bmp.allocN32Pixels(DEV_W, DEV_H);
|
||||||
SkASSERT(alloc);
|
|
||||||
SkAutoLockPixels alp(bmp);
|
|
||||||
intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
|
intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
|
||||||
for (int y = 0; y < DEV_H; ++y) {
|
for (int y = 0; y < DEV_H; ++y) {
|
||||||
for (int x = 0; x < DEV_W; ++x) {
|
for (int x = 0; x < DEV_W; ++x) {
|
||||||
|
|
|
@ -335,14 +335,12 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
|
||||||
compare_bitmaps(reporter, origBitmap, destBitmap);
|
compare_bitmaps(reporter, origBitmap, destBitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool setup_bitmap_for_canvas(SkBitmap* bitmap) {
|
static void setup_bitmap_for_canvas(SkBitmap* bitmap) {
|
||||||
SkImageInfo info = SkImageInfo::Make(
|
bitmap->allocN32Pixels(kBitmapSize, kBitmapSize);
|
||||||
kBitmapSize, kBitmapSize, kN32_SkColorType, kPremul_SkAlphaType);
|
|
||||||
return bitmap->allocPixels(info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool make_checkerboard_bitmap(SkBitmap& bitmap) {
|
static void make_checkerboard_bitmap(SkBitmap& bitmap) {
|
||||||
bool success = setup_bitmap_for_canvas(&bitmap);
|
setup_bitmap_for_canvas(&bitmap);
|
||||||
|
|
||||||
SkCanvas canvas(bitmap);
|
SkCanvas canvas(bitmap);
|
||||||
canvas.clear(0x00000000);
|
canvas.clear(0x00000000);
|
||||||
|
@ -363,14 +361,12 @@ static bool make_checkerboard_bitmap(SkBitmap& bitmap) {
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool draw_something(SkCanvas* canvas) {
|
static void draw_something(SkCanvas* canvas) {
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
bool success = make_checkerboard_bitmap(bitmap);
|
make_checkerboard_bitmap(bitmap);
|
||||||
|
|
||||||
canvas->save();
|
canvas->save();
|
||||||
canvas->scale(0.5f, 0.5f);
|
canvas->scale(0.5f, 0.5f);
|
||||||
|
@ -389,8 +385,6 @@ static bool draw_something(SkCanvas* canvas) {
|
||||||
paint.setColor(SK_ColorBLACK);
|
paint.setColor(SK_ColorBLACK);
|
||||||
paint.setTextSize(SkIntToScalar(kBitmapSize/3));
|
paint.setTextSize(SkIntToScalar(kBitmapSize/3));
|
||||||
canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), paint);
|
canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), paint);
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEF_TEST(Serialization, reporter) {
|
DEF_TEST(Serialization, reporter) {
|
||||||
|
@ -481,10 +475,9 @@ DEF_TEST(Serialization, reporter) {
|
||||||
// Test simple SkPicture serialization
|
// Test simple SkPicture serialization
|
||||||
{
|
{
|
||||||
SkPictureRecorder recorder;
|
SkPictureRecorder recorder;
|
||||||
bool didDraw = draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize),
|
draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize),
|
||||||
SkIntToScalar(kBitmapSize),
|
SkIntToScalar(kBitmapSize),
|
||||||
NULL, 0));
|
NULL, 0));
|
||||||
REPORTER_ASSERT(reporter, didDraw);
|
|
||||||
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
|
SkAutoTUnref<SkPicture> pict(recorder.endRecording());
|
||||||
|
|
||||||
// Serialize picture
|
// Serialize picture
|
||||||
|
|
|
@ -27,7 +27,7 @@ static bool test_scaled_image_cache_useage() {
|
||||||
SkAutoTUnref<SkCanvas> canvas(
|
SkAutoTUnref<SkCanvas> canvas(
|
||||||
SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize));
|
SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize));
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
SkAssertResult(bitmap.allocN32Pixels(kBitmapSize, kBitmapSize));
|
bitmap.allocN32Pixels(kBitmapSize, kBitmapSize);
|
||||||
bitmap.eraseColor(0xFFFFFFFF);
|
bitmap.eraseColor(0xFFFFFFFF);
|
||||||
SkScalar scale = SkIntToScalar(kScale);
|
SkScalar scale = SkIntToScalar(kScale);
|
||||||
SkScalar scaledSize = SkIntToScalar(kBitmapSize) * scale;
|
SkScalar scaledSize = SkIntToScalar(kBitmapSize) * scale;
|
||||||
|
|
|
@ -58,8 +58,7 @@ DEF_TEST(CompressAlphaFailDimensions, reporter) {
|
||||||
bool setInfoSuccess = bitmap.setInfo(info);
|
bool setInfoSuccess = bitmap.setInfo(info);
|
||||||
REPORTER_ASSERT(reporter, setInfoSuccess);
|
REPORTER_ASSERT(reporter, setInfoSuccess);
|
||||||
|
|
||||||
bool allocPixelsSuccess = bitmap.allocPixels(info);
|
bitmap.allocPixels(info);
|
||||||
REPORTER_ASSERT(reporter, allocPixelsSuccess);
|
|
||||||
bitmap.unlockPixels();
|
bitmap.unlockPixels();
|
||||||
|
|
||||||
for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
|
for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
|
||||||
|
@ -92,8 +91,7 @@ DEF_TEST(CompressAlphaFailColorType, reporter) {
|
||||||
bool setInfoSuccess = bitmap.setInfo(info);
|
bool setInfoSuccess = bitmap.setInfo(info);
|
||||||
REPORTER_ASSERT(reporter, setInfoSuccess);
|
REPORTER_ASSERT(reporter, setInfoSuccess);
|
||||||
|
|
||||||
bool allocPixelsSuccess = bitmap.allocPixels(info);
|
bitmap.allocPixels(info);
|
||||||
REPORTER_ASSERT(reporter, allocPixelsSuccess);
|
|
||||||
bitmap.unlockPixels();
|
bitmap.unlockPixels();
|
||||||
|
|
||||||
for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
|
for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
|
||||||
|
@ -128,8 +126,7 @@ DEF_TEST(CompressCheckerboard, reporter) {
|
||||||
bool setInfoSuccess = bitmap.setInfo(info);
|
bool setInfoSuccess = bitmap.setInfo(info);
|
||||||
REPORTER_ASSERT(reporter, setInfoSuccess);
|
REPORTER_ASSERT(reporter, setInfoSuccess);
|
||||||
|
|
||||||
bool allocPixelsSuccess = bitmap.allocPixels(info);
|
bitmap.allocPixels(info);
|
||||||
REPORTER_ASSERT(reporter, allocPixelsSuccess);
|
|
||||||
bitmap.unlockPixels();
|
bitmap.unlockPixels();
|
||||||
|
|
||||||
// Populate bitmap
|
// Populate bitmap
|
||||||
|
@ -215,8 +212,7 @@ DEF_TEST(CompressLATC, reporter) {
|
||||||
bool setInfoSuccess = bitmap.setInfo(info);
|
bool setInfoSuccess = bitmap.setInfo(info);
|
||||||
REPORTER_ASSERT(reporter, setInfoSuccess);
|
REPORTER_ASSERT(reporter, setInfoSuccess);
|
||||||
|
|
||||||
bool allocPixelsSuccess = bitmap.allocPixels(info);
|
bitmap.allocPixels(info);
|
||||||
REPORTER_ASSERT(reporter, allocPixelsSuccess);
|
|
||||||
bitmap.unlockPixels();
|
bitmap.unlockPixels();
|
||||||
|
|
||||||
int latcDimX, latcDimY;
|
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) {
|
static void fillCanvas(SkCanvas* canvas) {
|
||||||
SkBitmap bmp;
|
SkBitmap bmp;
|
||||||
if (bmp.isNull()) {
|
if (bmp.isNull()) {
|
||||||
SkDEBUGCODE(bool alloc = ) bmp.allocN32Pixels(DEV_W, DEV_H);
|
bmp.allocN32Pixels(DEV_W, DEV_H);
|
||||||
SkASSERT(alloc);
|
|
||||||
for (int y = 0; y < DEV_H; ++y) {
|
for (int y = 0; y < DEV_H; ++y) {
|
||||||
for (int x = 0; x < DEV_W; ++x) {
|
for (int x = 0; x < DEV_W; ++x) {
|
||||||
*bmp.getAddr32(x, y) = getCanvasColor(x, y);
|
*bmp.getAddr32(x, y) = getCanvasColor(x, y);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче