Index: src/core/SkPixmap.cpp |
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp |
index aa1d213bf60cd46406bc39807ab1810f205ef239..f7672d082f0e3ca99024bf1a99c6d5b449875efb 100644 |
--- a/src/core/SkPixmap.cpp |
+++ b/src/core/SkPixmap.cpp |
@@ -281,3 +281,51 @@ |
////////////////////////////////////////////////////////////////////////////////////////////////// |
+SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(nullptr) {} |
+ |
+SkAutoPixmapStorage::~SkAutoPixmapStorage() { |
+ this->freeStorage(); |
+} |
+ |
+size_t SkAutoPixmapStorage::AllocSize(const SkImageInfo& info, size_t* rowBytes) { |
+ size_t rb = info.minRowBytes(); |
+ if (rowBytes) { |
+ *rowBytes = rb; |
+ } |
+ return info.getSafeSize(rb); |
+} |
+ |
+bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) { |
+ this->freeStorage(); |
+ |
+ size_t rb; |
+ size_t size = AllocSize(info, &rb); |
+ if (0 == size) { |
+ return false; |
+ } |
+ void* pixels = sk_malloc_flags(size, 0); |
+ if (nullptr == pixels) { |
+ return false; |
+ } |
+ this->reset(info, pixels, rb); |
+ fStorage = pixels; |
+ return true; |
+} |
+ |
+void SkAutoPixmapStorage::alloc(const SkImageInfo& info) { |
+ if (!this->tryAlloc(info)) { |
+ sk_throw(); |
+ } |
+} |
+ |
+const SkData* SkAutoPixmapStorage::detachPixelsAsData() { |
+ if (!fStorage) { |
+ return nullptr; |
+ } |
+ |
+ auto data = SkData::MakeFromMalloc(fStorage, this->getSafeSize()); |
+ fStorage = nullptr; |
+ this->INHERITED::reset(); |
+ |
+ return data.release(); |
+} |