Index: include/core/SkMallocPixelRef.h |
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h |
index 100a15d90abb4ca55b30aa9af47e5ce17f18fa67..ba0b953cf6fe5ef68998dddc8a5602aaccd3d493 100644 |
--- a/include/core/SkMallocPixelRef.h |
+++ b/include/core/SkMallocPixelRef.h |
@@ -17,33 +17,54 @@ |
*/ |
class SkMallocPixelRef : public SkPixelRef { |
public: |
- /** Allocate the specified buffer for pixels. The memory is freed when the |
- last owner of this pixelref is gone. If addr is NULL, sk_malloc_throw() |
- is called to allocate it. |
+ /** |
+ * Return a new SkMallocPixelRef with the provided pixel storage, rowBytes, |
+ * and optional colortable. The caller is responsible for managing the |
+ * lifetime of the pixel storage buffer, as this pixelref will not try |
+ * to delete it. |
+ * |
+ * The pixelref will ref() the colortable (if not NULL). |
+ * |
+ * Returns NULL on failure. |
*/ |
- SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable, bool ownPixels = true); |
- virtual ~SkMallocPixelRef(); |
+ static SkMallocPixelRef* NewDirect(const SkImageInfo&, void* addr, |
+ size_t rowBytes, SkColorTable*); |
+ /** |
+ * Return a new SkMallocPixelRef, automatically allocating storage for the |
+ * pixels. |
+ * |
+ * If rowBytes is 0, an optimal value will be chosen automatically. |
+ * If rowBytes is > 0, then it will be used, unless it is invald for the |
+ * specified info, in which case NULL will be returned (failure). |
+ * |
+ * This pixelref will ref() the specified colortable (if not NULL). |
+ * |
+ * Returns NULL on failure. |
+ */ |
+ static SkMallocPixelRef* NewAllocate(const SkImageInfo& info, |
+ size_t rowBytes, SkColorTable*); |
+ |
void* getAddr() const { return fStorage; } |
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef) |
protected: |
- // overrides from SkPixelRef |
- virtual void* onLockPixels(SkColorTable**); |
- virtual void onUnlockPixels(); |
- |
+ SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*, |
+ bool ownPixels); |
SkMallocPixelRef(SkFlattenableReadBuffer& buffer); |
- virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
+ virtual ~SkMallocPixelRef(); |
- // Returns the allocation size for the pixels |
- virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE { return fSize; } |
+ virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; |
+ virtual void onUnlockPixels() SK_OVERRIDE; |
+ virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
+ virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE; |
private: |
void* fStorage; |
- size_t fSize; |
SkColorTable* fCTable; |
- bool fOwnPixels; |
+ size_t fRB; |
+ const bool fOwnPixels; |
typedef SkPixelRef INHERITED; |
}; |