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
#include "SkImageInfo.h"
class SkColorTable;
+class SkData;
struct SkMask;
/**
*/
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() {
void freeStorage() {
sk_free(fStorage);
- fStorage = NULL;
+ fStorage = nullptr;
}
typedef SkPixmap INHERITED;
#include "SkColorPriv.h"
#include "SkConfig8888.h"
+#include "SkData.h"
#include "SkMask.h"
#include "SkPixmap.h"
#include "SkUtils.h"
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;
+}