Revert "Revert "guard old apis for querying byte-size of a bitmap/imageinfo/pixmap""

This reverts commit 809cbedd4b.

Bug: skia:
Change-Id: I680d8daeeeeb15526b44c1305d8fb0c6bfa38e1d
Reviewed-on: https://skia-review.googlesource.com/52665
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Mike Reed 2017-09-29 15:22:56 -04:00 committed by Skia Commit-Bot
parent 3c83668862
commit cd284c5323
40 changed files with 103 additions and 97 deletions

View File

@ -38,7 +38,7 @@ void AndroidCodecBench::onDelayedSetup() {
fInfo = fInfo.makeAlphaType(kPremul_SkAlphaType);
}
fPixelStorage.reset(fInfo.getSafeSize(fInfo.minRowBytes()));
fPixelStorage.reset(fInfo.computeMinByteSize());
}
void AndroidCodecBench::onDraw(int n, SkCanvas* canvas) {

View File

@ -43,7 +43,7 @@ void CodecBench::onDelayedSetup() {
.makeAlphaType(fAlphaType)
.makeColorSpace(nullptr);
fPixelStorage.reset(fInfo.getSafeSize(fInfo.minRowBytes()));
fPixelStorage.reset(fInfo.computeMinByteSize());
}
void CodecBench::onDraw(int n, SkCanvas* canvas) {

View File

@ -88,10 +88,10 @@ void ColorCodecBench::onDelayedSetup() {
fDstSpace = static_cast<SkColorSpace_XYZ*>(fDstSpace.get())->makeLinearGamma();
}
fDst.reset(fDstInfo.getSafeSize(fDstInfo.minRowBytes()));
fDst.reset(fDstInfo.computeMinByteSize());
if (FLAGS_xform_only) {
fSrc.reset(fSrcInfo.getSafeSize(fSrcInfo.minRowBytes()));
fSrc.reset(fSrcInfo.computeMinByteSize());
fSrcSpace = codec->getInfo().refColorSpace();
codec->getPixels(fSrcInfo, fSrc.get(), fSrcInfo.minRowBytes());
}

View File

@ -887,7 +887,7 @@ public:
SkImageInfo info =
codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType);
const size_t rowBytes = info.minRowBytes();
SkAutoMalloc storage(info.getSafeSize(rowBytes));
SkAutoMalloc storage(info.computeByteSize(rowBytes));
const SkCodec::Result result = codec->getPixels(
info, storage.get(), rowBytes);

View File

@ -1128,9 +1128,9 @@ struct Task {
SkBitmap swizzle;
SkAssertResult(sk_tool_utils::copy_to(&swizzle, kRGBA_8888_SkColorType,
bitmap));
hash.write(swizzle.getPixels(), swizzle.getSize());
hash.write(swizzle.getPixels(), swizzle.computeByteSize());
} else {
hash.write(bitmap.getPixels(), bitmap.getSize());
hash.write(bitmap.getPixels(), bitmap.computeByteSize());
}
}
SkMD5::Digest digest;

View File

@ -454,7 +454,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
const int bpp = SkColorTypeBytesPerPixel(decodeInfo.colorType());
const size_t rowBytes = size.width() * bpp;
const size_t safeSize = decodeInfo.getSafeSize(rowBytes);
const size_t safeSize = decodeInfo.computeByteSize(rowBytes);
SkAutoMalloc pixels(safeSize);
SkCodec::Options options;
@ -1468,12 +1468,12 @@ static bool encode_png_base64(const SkBitmap& bitmap, SkString* dst) {
static Error compare_bitmaps(const SkBitmap& reference, const SkBitmap& bitmap) {
// The dimensions are a property of the Src only, and so should be identical.
SkASSERT(reference.getSize() == bitmap.getSize());
if (reference.getSize() != bitmap.getSize()) {
SkASSERT(reference.computeByteSize() == bitmap.computeByteSize());
if (reference.computeByteSize() != bitmap.computeByteSize()) {
return "Dimensions don't match reference";
}
// All SkBitmaps in DM are tight, so this comparison is easy.
if (0 != memcmp(reference.getPixels(), bitmap.getPixels(), reference.getSize())) {
if (0 != memcmp(reference.getPixels(), bitmap.getPixels(), reference.computeByteSize())) {
SkString encoded;
SkString errString("Pixels don't match reference");
if (encode_png_base64(reference, &encoded)) {

View File

@ -5,4 +5,5 @@
flutter_defines = [
"SK_SUPPORT_LEGACY_IMAGE_ENCODE_API",
"SK_SUPPORT_LEGACY_FONTMGR_API",
"SK_SUPPORT_LEGACY_SAFESIZE64",
]

View File

@ -147,10 +147,7 @@ public:
*/
size_t computeByteSize() const { return fInfo.computeByteSize(fRowBytes); }
/** Return the byte size of the pixels, based on the height and rowBytes.
Note this truncates the result to 32bits. Call getSize64() to detect
if the real size exceeds 32bits.
*/
#ifdef SK_SUPPORT_LEGACY_SAFESIZE64
size_t getSize() const { return fInfo.height() * fRowBytes; }
/** Return the number of bytes from the pointer returned by getPixels()
@ -174,6 +171,7 @@ public:
int64_t computeSafeSize64() const {
return fInfo.getSafeSize64(fRowBytes);
}
#endif
/** Returns true if this bitmap is marked as immutable, meaning that the
contents of its pixels will not change for the lifetime of the bitmap.

View File

@ -300,6 +300,7 @@ public:
void unflatten(SkReadBuffer&);
void flatten(SkWriteBuffer&) const;
#ifdef SK_SUPPORT_LEGACY_SAFESIZE64
int64_t getSafeSize64(size_t rowBytes) const {
if (0 == fHeight) {
return 0;
@ -314,6 +315,7 @@ public:
}
return sk_64_asS32(size);
}
#endif
/**
* Returns the size (in bytes) of the image buffer that this info needs, given the specified
@ -331,8 +333,8 @@ public:
}
bool validRowBytes(size_t rowBytes) const {
uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel());
return rowBytes >= rb;
uint64_t minRB = sk_64_mul(fWidth, this->bytesPerPixel());
return rowBytes >= minRB;
}
void reset() {

View File

@ -206,6 +206,7 @@ public:
*/
int shiftPerPixel() const { return fInfo.shiftPerPixel(); }
#ifdef SK_SUPPORT_LEGACY_SAFESIZE64
/** Returns conservative memory required for pixel storage.
Includes unused memory on last row when rowBytesAsPixels() exceeds width().
@ -228,6 +229,7 @@ public:
@return exact pixel storage size if size fits in signed 32 bits
*/
size_t getSafeSize() const { return fInfo.getSafeSize(fRowBytes); }
#endif
/**
* Returns the size (in bytes) of the pixmap's image buffer.

View File

@ -656,6 +656,7 @@ DEFINES_ALL = [
# Required for building dm.
"GR_TEST_UTILS",
# Staging flags for API changes
"SK_SUPPORT_LEGACY_SAFESIZE64",
# Should remove after we update golden images
"SK_WEBP_ENCODER_USE_DEFAULT_METHOD",
# Experiment to diagnose image diffs in Google3

View File

@ -344,7 +344,7 @@ public:
// We made/have an off-screen surface. Extract the pixels exactly as we rendered them:
SkImageInfo info = win->info();
size_t rowBytes = info.minRowBytes();
size_t size = info.getSafeSize(rowBytes);
size_t size = info.computeByteSize(rowBytes);
auto data = SkData::MakeUninitialized(size);
SkASSERT(data);

View File

@ -96,7 +96,7 @@ bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocat
if (SubsetType::kPartiallyInside_SubsetType == type &&
SkCodec::kNo_ZeroInitialized == zeroInit) {
void* pixels = bitmap->getPixels();
size_t bytes = outInfo.getSafeSize(bitmap->rowBytes());
size_t bytes = outInfo.computeByteSize(bitmap->rowBytes());
memset(pixels, 0, bytes);
}

View File

@ -173,7 +173,7 @@ std::unique_ptr<SkCodec> SkIcoCodec::MakeFromStream(std::unique_ptr<SkStream> st
int maxIndex = 0;
for (int i = 0; i < codecs->count(); i++) {
SkImageInfo info = codecs->operator[](i)->getInfo();
size_t size = info.getSafeSize(info.minRowBytes());
size_t size = info.computeMinByteSize();
if (size > maxSize) {
maxSize = size;

View File

@ -14,8 +14,8 @@ void SkSampler::Fill(const SkImageInfo& info, void* dst, size_t rowBytes,
uint64_t colorOrIndex, SkCodec::ZeroInitialized zeroInit) {
SkASSERT(dst != nullptr);
// Calculate bytes to fill. We use getSafeSize since the last row may not be padded.
const size_t bytesToFill = info.getSafeSize(rowBytes);
// Calculate bytes to fill.
const size_t bytesToFill = info.computeByteSize(rowBytes);
const int width = info.width();
const int numRows = info.height();

View File

@ -542,7 +542,7 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
config.output.u.RGBA.rgba = reinterpret_cast<uint8_t*>(webpDst.getAddr(dstX, dstY));
config.output.u.RGBA.stride = static_cast<int>(webpDst.rowBytes());
config.output.u.RGBA.size = webpDst.getSafeSize();
config.output.u.RGBA.size = webpDst.computeByteSize();
SkAutoTCallVProc<WebPIDecoder, WebPIDelete> idec(WebPIDecode(nullptr, 0, &config));
if (!idec) {

View File

@ -29,7 +29,7 @@ size_t SkAutoPixmapStorage::AllocSize(const SkImageInfo& info, size_t* rowBytes)
if (rowBytes) {
*rowBytes = rb;
}
return info.getSafeSize(rb);
return info.computeByteSize(rb);
}
bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) {
@ -58,7 +58,7 @@ const SkData* SkAutoPixmapStorage::detachPixelsAsData() {
return nullptr;
}
auto data = SkData::MakeFromMalloc(fStorage, this->getSafeSize());
auto data = SkData::MakeFromMalloc(fStorage, this->computeByteSize());
fStorage = nullptr;
this->INHERITED::reset();

View File

@ -678,7 +678,7 @@ bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) {
}
// write_raw_pixels() always writes snug buffers with rowBytes == minRowBytes().
size_t bytes = info.getSafeSize(info.minRowBytes());
size_t bytes = info.computeMinByteSize();
if (!buffer->validate(bytes != 0)) {
return false;
}

View File

@ -160,7 +160,7 @@ public:
const Key& getKey() const override { return fKey; }
size_t bytesUsed() const override {
return sizeof(fKey) + fInfo.getSafeSize(fRowBytes);
return sizeof(fKey) + fInfo.computeByteSize(fRowBytes);
}
bool canBePurged() override {
SkAutoMutexAcquire ama(fMutex);
@ -289,7 +289,7 @@ SkBitmapCache::RecPtr SkBitmapCache::Alloc(const SkBitmapCacheDesc& desc, const
}
const size_t rb = info.minRowBytes();
size_t size = info.getSafeSize(rb);
size_t size = info.computeByteSize(rb);
if (0 == size) {
return nullptr;
}

View File

@ -35,38 +35,39 @@ sk_sp<SkPixelRef> SkMallocPixelRef::MakeDirect(const SkImageInfo& info,
}
sk_sp<SkPixelRef> SkMallocPixelRef::MakeUsing(void*(*alloc)(size_t),
const SkImageInfo& info,
size_t requestedRowBytes) {
if (!is_valid(info)) {
sk_sp<SkPixelRef> SkMallocPixelRef::MakeUsing(void*(*allocProc)(size_t),
const SkImageInfo& info,
size_t rowBytes) {
if (rowBytes == 0) {
rowBytes = info.minRowBytes();
}
if (!is_valid(info) || !info.validRowBytes(rowBytes)) {
return nullptr;
}
// only want to permit 31bits of rowBytes
int64_t minRB = (int64_t)info.minRowBytes64();
if (minRB < 0 || !sk_64_isS32(minRB)) {
return nullptr; // allocation will be too large
}
if (requestedRowBytes > 0 && (int32_t)requestedRowBytes < minRB) {
return nullptr; // cannot meet requested rowbytes
size_t size = 0;
// if the info is empty, or rowBytes is 0 (which can be valid), then we don't need to compute
// a size.
if (!info.isEmpty() && rowBytes > 0) {
#ifdef SK_SUPPORT_LEGACY_SAFESIZE64
int64_t bigSize = (int64_t)info.height() * rowBytes;
if (!sk_64_isS32(bigSize)) {
return nullptr;
}
size = sk_64_asS32(bigSize);
SkASSERT(size >= info.getSafeSize(rowBytes));
SkASSERT(info.computeByteSize(rowBytes) == info.getSafeSize(rowBytes));
#else
size = info.computeByteSize(rowBytes);
#endif
if (size == 0) {
return nullptr; // overflow
}
}
int32_t rowBytes;
if (requestedRowBytes) {
rowBytes = SkToS32(requestedRowBytes);
} else {
rowBytes = minRB;
}
int64_t bigSize = (int64_t)info.height() * rowBytes;
if (!sk_64_isS32(bigSize)) {
return nullptr;
}
size_t size = sk_64_asS32(bigSize);
SkASSERT(size >= info.getSafeSize(rowBytes));
SkASSERT(info.getSafeSize(rowBytes) == info.computeByteSize(rowBytes));
void* addr = alloc(size);
void* addr = allocProc(size);
if (nullptr == addr) {
return nullptr;
}
@ -108,10 +109,11 @@ sk_sp<SkPixelRef> SkMallocPixelRef::MakeWithData(const SkImageInfo& info,
size_t rowBytes,
sk_sp<SkData> data) {
SkASSERT(data != nullptr);
if (!is_valid(info)) {
if (!is_valid(info) || !info.validRowBytes(rowBytes)) {
return nullptr;
}
if ((rowBytes < info.minRowBytes()) || (data->size() < info.getSafeSize(rowBytes))) {
size_t sizeNeeded = info.computeByteSize(rowBytes);
if (!info.isEmpty() && (sizeNeeded == 0 || data->size() < sizeNeeded)) {
return nullptr;
}
// must get this address before we call release

View File

@ -400,7 +400,7 @@ static void generateMask(const SkMask& mask, const SkPath& path,
} else {
dst.reset(info, mask.fImage, dstRB);
}
sk_bzero(dst.writable_addr(), dst.getSafeSize());
sk_bzero(dst.writable_addr(), dst.computeByteSize());
SkDraw draw;
draw.fDst = dst;

View File

@ -219,7 +219,7 @@ public:
SkAlphaType alphaType() const override { return fBitmap.alphaType(); }
size_t getSize() const override { return fBitmap.getSize(); }
size_t getSize() const override { return fBitmap.computeByteSize(); }
void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
SkRect dst = SkRect::MakeXYWH(x, y,

View File

@ -455,7 +455,7 @@ private:
devPathBounds.height()))) {
return false;
}
sk_bzero(dst.writable_addr(), dst.getSafeSize());
sk_bzero(dst.writable_addr(), dst.computeByteSize());
// rasterize path
SkPaint paint;
@ -562,7 +562,7 @@ private:
devPathBounds.height()))) {
return false;
}
sk_bzero(dst.writable_addr(), dst.getSafeSize());
sk_bzero(dst.writable_addr(), dst.computeByteSize());
// rasterize path
SkPaint paint;

View File

@ -422,7 +422,10 @@ sk_sp<SkImage> SkImageMakeRasterCopyAndAssignColorSpace(const SkImage* src,
}
size_t rowBytes = info.minRowBytes();
size_t size = info.getSafeSize(rowBytes);
size_t size = info.computeByteSize(rowBytes);
if (size == 0) {
return nullptr;
}
auto data = SkData::MakeUninitialized(size);
if (!data) {
return nullptr;

View File

@ -518,7 +518,7 @@ sk_sp<SkImage> SkImage::makeNonTextureImage() const {
}
SkImageInfo info = as_IB(this)->onImageInfo();
size_t rowBytes = info.minRowBytes();
size_t size = info.getSafeSize(rowBytes);
size_t size = info.computeByteSize(rowBytes);
auto data = SkData::MakeUninitialized(size);
if (!data) {
return nullptr;
@ -667,7 +667,7 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox
size_t pixelSize = 0;
if (!isScaled && this->peekPixels(&pixmap) && pixmap.info().colorType() == dstColorType) {
info = pixmap.info();
pixelSize = SkAlign8(pixmap.getSafeSize());
pixelSize = SkAlign8(pixmap.computeByteSize());
if (!dstColorSpace) {
pixmap.setColorSpace(nullptr);
info = info.makeColorSpace(nullptr);
@ -773,7 +773,7 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox
void* pixels = pixelsAsCharPtr;
memcpy(reinterpret_cast<void*>(SkAlign8(reinterpret_cast<uintptr_t>(pixelsAsCharPtr))),
pixmap.addr(), pixmap.getSafeSize());
pixmap.addr(), pixmap.computeByteSize());
// If the context has sRGB support, and we're intending to render to a surface with an attached
// color space, and the image has an sRGB-like color space attached, then use our gamma (sRGB)
@ -824,7 +824,7 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox
}
// Fill in the mipmap levels if they exist
char* mipLevelPtr = pixelsAsCharPtr + SkAlign8(pixmap.getSafeSize());
char* mipLevelPtr = pixelsAsCharPtr + SkAlign8(pixmap.computeByteSize());
if (useMipMaps) {
static_assert(std::is_standard_layout<MipMapLevelData>::value,
@ -845,13 +845,10 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox
// Make sure the mipmap data starts before the end of the buffer
SkASSERT(mipLevelPtr < bufferAsCharPtr + pixelOffset + pixelSize);
// Make sure the mipmap data ends before the end of the buffer
SkASSERT(mipLevelPtr + mipLevel.fPixmap.getSafeSize() <=
SkASSERT(mipLevelPtr + mipLevel.fPixmap.computeByteSize() <=
bufferAsCharPtr + pixelOffset + pixelSize);
// getSafeSize includes rowbyte padding except for the last row,
// right?
memcpy(mipLevelPtr, mipLevel.fPixmap.addr(), mipLevel.fPixmap.getSafeSize());
memcpy(mipLevelPtr, mipLevel.fPixmap.addr(), mipLevel.fPixmap.computeByteSize());
memcpy(bufferAsCharPtr + offsetof(DeferredTextureImage, fMipMapLevelData) +
sizeof(MipMapLevelData) * (generatedMipLevelIndex + 1) +
@ -861,7 +858,7 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox
sizeof(MipMapLevelData) * (generatedMipLevelIndex + 1) +
offsetof(MipMapLevelData, fRowBytes), &rowBytes, sizeof(rowBytes));
mipLevelPtr += SkAlign8(mipLevel.fPixmap.getSafeSize());
mipLevelPtr += SkAlign8(mipLevel.fPixmap.computeByteSize());
}
}
return size;

View File

@ -57,11 +57,11 @@ public:
if (kUnknown_SkColorType == info.colorType()) {
return false;
}
if (rowBytes < info.minRowBytes()) {
if (!info.validRowBytes(rowBytes)) {
return false;
}
size_t size = info.getSafeSize(rowBytes);
size_t size = info.computeByteSize(rowBytes);
if (0 == size) {
return false;
}

View File

@ -162,7 +162,7 @@ void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) {
fBitmap.allocPixels();
SkASSERT(prev.info() == fBitmap.info());
SkASSERT(prev.rowBytes() == fBitmap.rowBytes());
memcpy(fBitmap.getPixels(), prev.getPixels(), fBitmap.getSafeSize());
memcpy(fBitmap.getPixels(), prev.getPixels(), fBitmap.computeByteSize());
}
SkASSERT(fBitmap.rowBytes() == fRowBytes); // be sure we always use the same value

View File

@ -132,7 +132,7 @@ CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
const int w = bitmap->width();
const int h = bitmap->height();
const size_t s = bitmap->getSize();
const size_t s = bitmap->computeByteSize();
// our provider "owns" the bitmap*, and will take care of deleting it
CGDataProviderRef dataRef = CGDataProviderCreateWithData(bitmap, bitmap->getPixels(), s,

View File

@ -573,7 +573,7 @@ static void TestOverrideStateConsistency(skiatest::Reporter* reporter, const Tes
static void test_newraster(skiatest::Reporter* reporter) {
SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
const size_t minRowBytes = info.minRowBytes();
const size_t size = info.getSafeSize(minRowBytes);
const size_t size = info.computeByteSize(minRowBytes);
SkAutoTMalloc<SkPMColor> storage(size);
SkPMColor* baseAddr = storage.get();
sk_bzero(baseAddr, size);

View File

@ -584,7 +584,7 @@ static void test_dimensions(skiatest::Reporter* r, const char path[]) {
// Set up for the decode
size_t rowBytes = scaledDims.width() * sizeof(SkPMColor);
size_t totalBytes = scaledInfo.getSafeSize(rowBytes);
size_t totalBytes = scaledInfo.computeByteSize(rowBytes);
SkAutoTMalloc<SkPMColor> pixels(totalBytes);
SkAndroidCodec::AndroidOptions options;
@ -1011,7 +1011,7 @@ static void check_color_xform(skiatest::Reporter* r, const char* path) {
.makeColorSpace(colorSpace);
size_t rowBytes = dstInfo.minRowBytes();
SkAutoMalloc pixelStorage(dstInfo.getSafeSize(rowBytes));
SkAutoMalloc pixelStorage(dstInfo.computeByteSize(rowBytes));
SkCodec::Result result = codec->getAndroidPixels(dstInfo, pixelStorage.get(), rowBytes, &opts);
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
}

View File

@ -144,9 +144,10 @@ static void test_wacky_bitmapshader(skiatest::Reporter* reporter,
SkBitmap bm;
if (bm.tryAllocN32Pixels(width, height)) {
// allow this to fail silently, to test the code downstream
bm.eraseColor(SK_ColorRED);
} else {
shouldBeDrawn = false;
}
bm.eraseColor(SK_ColorRED);
matrix.setAll(0.0078740157f,
0,
@ -179,7 +180,7 @@ static void test_wacky_bitmapshader(skiatest::Reporter* reporter,
* sign-extension bleed when packing the two values (X,Y) into our 32bit
* slot.
*
* This tests exercises the original setup, plus 3 more to ensure that we can,
* This tests exercises the original setup, plus 2 more to ensure that we can,
* in fact, handle bitmaps at 64K-1 (assuming we don't exceed the total
* memory allocation limit).
*/
@ -192,7 +193,6 @@ static void test_giantrepeat_crbug118018(skiatest::Reporter* reporter) {
{ 0x1b294, 0x7f, false }, // crbug 118018 (width exceeds 64K)
{ 0xFFFF, 0x7f, true }, // should draw, test max width
{ 0x7f, 0xFFFF, true }, // should draw, test max height
{ 0xFFFF, 0xFFFF, false }, // allocation fails (too much RAM)
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gTests); ++i) {

View File

@ -43,7 +43,7 @@ DEF_TEST(color_half_float, reporter) {
SkAutoPixmapStorage pm;
pm.alloc(info);
REPORTER_ASSERT(reporter, pm.getSafeSize() == SkToSizeT(w * h * sizeof(uint64_t)));
REPORTER_ASSERT(reporter, pm.computeByteSize() == SkToSizeT(w * h * sizeof(uint64_t)));
SkColor4f c4 { 1, 0.5f, 0.25f, 0.5f };
pm.erase(c4);

View File

@ -17,8 +17,8 @@
#endif
static void test_bitmap_equality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& bm2) {
REPORTER_ASSERT(reporter, bm1.getSize() == bm2.getSize());
REPORTER_ASSERT(reporter, 0 == memcmp(bm1.getPixels(), bm2.getPixels(), bm1.getSize()));
REPORTER_ASSERT(reporter, bm1.computeByteSize() == bm2.computeByteSize());
REPORTER_ASSERT(reporter, 0 == memcmp(bm1.getPixels(), bm2.getPixels(), bm1.computeByteSize()));
}
static void paint_source(SkSurface* sourceSurface) {

View File

@ -549,7 +549,7 @@ DEF_TEST(ImageEmpty, reporter) {
DEF_TEST(ImageDataRef, reporter) {
SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
size_t rowBytes = info.minRowBytes();
size_t size = info.getSafeSize(rowBytes);
size_t size = info.computeByteSize(rowBytes);
sk_sp<SkData> data = SkData::MakeUninitialized(size);
REPORTER_ASSERT(reporter, data->unique());
sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, rowBytes);

View File

@ -32,7 +32,7 @@ DEF_TEST(MallocPixelRef, reporter) {
}
{
size_t rowBytes = info.minRowBytes() - 1;
size_t size = info.getSafeSize(rowBytes);
size_t size = info.computeByteSize(rowBytes);
sk_sp<SkData> data(SkData::MakeUninitialized(size));
sk_sp<SkPixelRef> pr(
SkMallocPixelRef::MakeWithData(info, rowBytes, data));
@ -41,7 +41,7 @@ DEF_TEST(MallocPixelRef, reporter) {
}
{
size_t rowBytes = info.minRowBytes() + 2;
size_t size = info.getSafeSize(rowBytes) - 1;
size_t size = info.computeByteSize(rowBytes) - 1;
sk_sp<SkData> data(SkData::MakeUninitialized(size));
sk_sp<SkPixelRef> pr(
SkMallocPixelRef::MakeWithData(info, rowBytes, data));
@ -49,7 +49,7 @@ DEF_TEST(MallocPixelRef, reporter) {
REPORTER_ASSERT(reporter, nullptr == pr.get());
}
size_t rowBytes = info.minRowBytes() + 7;
size_t size = info.getSafeSize(rowBytes) + 9;
size_t size = info.computeByteSize(rowBytes) + 9;
{
SkAutoMalloc memory(size);
sk_sp<SkPixelRef> pr(

View File

@ -151,8 +151,8 @@ DEF_TEST(SkRecordingAccuracyXfermode, reporter) {
const SkBitmap& goldenBM = golden.recordAndReplay(drawer, clip, mode);
const SkBitmap& pictureBM = picture.recordAndReplay(drawer, clip, mode);
size_t pixelsSize = goldenBM.getSize();
REPORTER_ASSERT(reporter, pixelsSize == pictureBM.getSize());
size_t pixelsSize = goldenBM.computeByteSize();
REPORTER_ASSERT(reporter, pixelsSize == pictureBM.computeByteSize());
// The pixel arrays should match.
#if FINEGRAIN

View File

@ -49,7 +49,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, ctxInfo) {
SkBitmap src;
src.allocN32Pixels(size.width(), size.height());
src.eraseColor(SK_ColorBLACK);
size_t srcSize = src.getSize();
size_t srcSize = src.computeByteSize();
size_t initialCacheSize;
context->getResourceCacheUsage(nullptr, &initialCacheSize);

View File

@ -50,7 +50,7 @@ static sk_sp<SkSurface> create_direct_surface(SkAlphaType at = kPremul_SkAlphaTy
*requestedInfo = info;
}
const size_t rowBytes = info.minRowBytes();
void* storage = sk_malloc_throw(info.getSafeSize(rowBytes));
void* storage = sk_malloc_throw(info.computeByteSize(rowBytes));
return SkSurface::MakeRasterDirectReleaseProc(info, storage, rowBytes,
release_direct_surface_storage,
storage);
@ -565,7 +565,7 @@ DEF_TEST(surface_rowbytes, reporter) {
// Try some illegal rowByte values
auto s = SkSurface::MakeRaster(info, 396, nullptr); // needs to be at least 400
REPORTER_ASSERT(reporter, nullptr == s);
s = SkSurface::MakeRaster(info, 1 << 30, nullptr); // allocation to large
s = SkSurface::MakeRaster(info, std::numeric_limits<size_t>::max(), nullptr);
REPORTER_ASSERT(reporter, nullptr == s);
}

View File

@ -28,7 +28,7 @@ static void check_fill(skiatest::Reporter* r,
// to test on different memory alignments. If offset is nonzero, we need to increase the
// size of the memory we allocate in order to make sure that we have enough. We are
// still allocating the smallest possible size.
const size_t totalBytes = imageInfo.getSafeSize(rowBytes) + offset;
const size_t totalBytes = imageInfo.computeByteSize(rowBytes) + offset;
// Create fake image data where every byte has a value of 0
std::unique_ptr<uint8_t[]> storage(new uint8_t[totalBytes]);

View File

@ -394,7 +394,7 @@ DEF_TEST(WritePixels, reporter) {
const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
for (auto& tightRowBytes : { true, false }) {
const size_t rowBytes = tightRowBytes ? info.minRowBytes() : 4 * DEV_W + 100;
const size_t size = info.getSafeSize(rowBytes);
const size_t size = info.computeByteSize(rowBytes);
void* pixels = sk_malloc_throw(size);
// if rowBytes isn't tight then set the padding to a known value
if (!tightRowBytes) {