From: fmalita Date: Thu, 4 Feb 2016 21:09:59 +0000 (-0800) Subject: Add SkAutoPixmapStorage::detachPixelsAsData() X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~129^2~2219 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3a94c6c62c3c40866684b4c4772551fa95be097d;p=platform%2Fupstream%2FlibSkiaSharp.git Add SkAutoPixmapStorage::detachPixelsAsData() Allows passing pixels ownership to clients. BUG=skia:4896 R=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1662353002 Review URL: https://codereview.chromium.org/1662353002 --- diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h index da97025..523c40f 100644 --- a/include/core/SkPixmap.h +++ b/include/core/SkPixmap.h @@ -13,6 +13,7 @@ #include "SkImageInfo.h" class SkColorTable; +class SkData; struct SkMask; /** @@ -184,6 +185,12 @@ public: */ void alloc(const SkImageInfo&); + /** + * Returns an SkData object wrapping the allocated pixels memory, and resets the pixmap. + * If the storage hasn't been allocated, the result is NULL. + */ + const SkData* SK_WARN_UNUSED_RESULT detachPixelsAsData(); + // We wrap these so we can clear our internal storage void reset() { @@ -208,7 +215,7 @@ private: void freeStorage() { sk_free(fStorage); - fStorage = NULL; + fStorage = nullptr; } typedef SkPixmap INHERITED; diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index 943287b..e2d4d30 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -7,6 +7,7 @@ #include "SkColorPriv.h" #include "SkConfig8888.h" +#include "SkData.h" #include "SkMask.h" #include "SkPixmap.h" #include "SkUtils.h" @@ -272,3 +273,15 @@ void SkAutoPixmapStorage::alloc(const SkImageInfo& info) { sk_throw(); } } + +const SkData* SkAutoPixmapStorage::detachPixelsAsData() { + if (!fStorage) { + return nullptr; + } + + const SkData* data = SkData::NewFromMalloc(fStorage, this->getSafeSize()); + fStorage = nullptr; + this->INHERITED::reset(); + + return data; +}