aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-02 17:29:28 +0000
committerGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-02 17:29:28 +0000
commit1bed687f6b8fc67336f0f5d6fb5a5b38dd0fdff9 (patch)
tree0f89292bb40a1b048ac03f541d9dbc62ebbddab4 /include
parent261c66668269588a26757a0bfe28a3a3eac07665 (diff)
Add a release procedure to SkMallocPixelRef; remove SkDataPixelRef
This works in a way that is similar to SkData. SkMallocPixelRef::NewWithProc Motivation: Chrome has a ETC1PixelRef which calls delete[] on the pixles on destruction. There is no reason for them to almost duplicate our class, when we can provide them a more flexible class. Example use: static void delete_uint8_proc(void* ptr, void*) { delete[] static_cast<uint8_t>(ptr); } SkPixelRef* new_delete_pixref(const SkImageInfo& info, SkColorTable* ctable) { size_t rb = info.minRowBytes(); return SkMallocPixelRef::NewWithProc( info, rb, ctable, new uint8_t[info.getSafeSize(rb)], delete_uint8_proc, NULL); } SkMallocPixelRef::NewWithData Motivation: This allows up to eliminate SkDataPixelRef. We modified SkImage_Raster to use MallocPixelRef rather than SkDataPixlRef. Also: Unit tests in tests/MallocPixelRefTest. BUG= R=reed@google.com Review URL: https://codereview.chromium.org/106883006 git-svn-id: http://skia.googlecode.com/svn/trunk@12861 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r--include/core/SkMallocPixelRef.h41
1 files changed, 40 insertions, 1 deletions
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index a547ddb2b9..272dc21fd8 100644
--- a/include/core/SkMallocPixelRef.h
+++ b/include/core/SkMallocPixelRef.h
@@ -45,11 +45,46 @@ public:
static SkMallocPixelRef* NewAllocate(const SkImageInfo& info,
size_t rowBytes, SkColorTable*);
+ /**
+ * Return a new SkMallocPixelRef with the provided pixel storage,
+ * rowBytes, and optional colortable. On destruction, ReleaseProc
+ * will be called.
+ *
+ * This pixelref will ref() the specified colortable (if not NULL).
+ *
+ * Returns NULL on failure.
+ */
+ typedef void (*ReleaseProc)(void* addr, void* context);
+ static SkMallocPixelRef* NewWithProc(const SkImageInfo& info,
+ size_t rowBytes, SkColorTable*,
+ void* addr, ReleaseProc proc,
+ void* context);
+
+ /**
+ * Return a new SkMallocPixelRef that will use the provided
+ * SkData, rowBytes, and optional colortable as pixel storage.
+ * The SkData will be ref()ed and on destruction of the PielRef,
+ * the SkData will be unref()ed.
+ *
+ * @param offset (in bytes) into the provided SkData that the
+ * first pixel is located at.
+ *
+ * This pixelref will ref() the specified colortable (if not NULL).
+ *
+ * Returns NULL on failure.
+ */
+ static SkMallocPixelRef* NewWithData(const SkImageInfo& info,
+ size_t rowBytes,
+ SkColorTable* ctable,
+ SkData* data,
+ size_t offset = 0);
+
void* getAddr() const { return fStorage; }
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef)
protected:
+ // The ownPixels version of this constructor is deprecated.
SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
bool ownPixels);
SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
@@ -64,7 +99,11 @@ private:
void* fStorage;
SkColorTable* fCTable;
size_t fRB;
- const bool fOwnPixels;
+ ReleaseProc fReleaseProc;
+ void* fReleaseProcContext;
+
+ SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*,
+ ReleaseProc proc, void* context);
typedef SkPixelRef INHERITED;
};