Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Unified Diff: src/utils/SkTextureCompressor.cpp

Issue 560653004: SkData can allocate room for its contents in the same block (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update dox, change fPtr to non const Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/sfnt/SkOTUtils.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkTextureCompressor.cpp
diff --git a/src/utils/SkTextureCompressor.cpp b/src/utils/SkTextureCompressor.cpp
index 07b58c5a607639f64df06fd2174d83a04b9cb97f..799eadc84b8e3df26ed16f4f4f49fad096a28af1 100644
--- a/src/utils/SkTextureCompressor.cpp
+++ b/src/utils/SkTextureCompressor.cpp
@@ -173,7 +173,7 @@ bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcCol
return false;
}
-SkData *CompressBitmapToFormat(const SkBitmap &bitmap, Format format) {
+SkData* CompressBitmapToFormat(const SkBitmap &bitmap, Format format) {
SkAutoLockPixels alp(bitmap);
int compressedDataSize = GetCompressedDataSize(format, bitmap.width(), bitmap.height());
@@ -182,15 +182,14 @@ SkData *CompressBitmapToFormat(const SkBitmap &bitmap, Format format) {
}
const uint8_t* src = reinterpret_cast<const uint8_t*>(bitmap.getPixels());
- uint8_t* dst = reinterpret_cast<uint8_t*>(sk_malloc_throw(compressedDataSize));
+ SkData* dst = SkData::NewUninitialized(compressedDataSize);
- if (CompressBufferToFormat(dst, src, bitmap.colorType(), bitmap.width(), bitmap.height(),
- bitmap.rowBytes(), format)) {
- return SkData::NewFromMalloc(dst, compressedDataSize);
+ if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, bitmap.colorType(),
+ bitmap.width(), bitmap.height(), bitmap.rowBytes(), format)) {
+ dst->unref();
+ dst = NULL;
}
-
- sk_free(dst);
- return NULL;
+ return dst;
}
SkBlitter* CreateBlitterForFormat(int width, int height, void* compressedBuffer,
« no previous file with comments | « src/sfnt/SkOTUtils.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698