Chromium Code Reviews| Index: include/core/SkMallocPixelRef.h |
| diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h |
| index 2241a513e7ea223ac8ddeac340bf8f73ee92d2ca..0d4666c29c0a0704820980013db5e542d88e5505 100644 |
| --- a/include/core/SkMallocPixelRef.h |
| +++ b/include/core/SkMallocPixelRef.h |
| @@ -17,32 +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. This pixelref will ref() the |
| + * specified colortable (if not NULL). |
|
scroggo
2013/11/20 21:04:28
Can you add a comment that this does not take owne
reed1
2013/11/20 21:27:18
"The caller is responsible for managing the lifet
scroggo
2013/11/20 21:35:19
D'oh! No, that's clear.
|
| + * |
| + * Returns NULL on failure. |
| */ |
| - SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable, bool ownPixels = true); |
| - virtual ~SkMallocPixelRef(); |
| + static SkMallocPixelRef* Create(const SkImageInfo&, void* addr, |
|
scroggo
2013/11/20 21:04:28
Maybe a better name for this would be Wrap or Wrap
reed1
2013/11/20 21:27:18
Hmmm
|
| + size_t rowBytes, SkColorTable*); |
| + /** |
| + * Return a new SkMallocPixelRef, automatically allocating storage for the |
| + * pixels. If rowBytes are 0, an optimal value will be chosen automatically. |
| + * If rowBytes is > 0, then it will be respected, or NULL will be returned |
| + * if rowBytes is invalid for the specified info. |
| + * |
| + * Returns NULL on failure. |
| + */ |
| + static SkMallocPixelRef* Allocate(const SkImageInfo& info, |
| + size_t rowBytes, SkColorTable*); |
| - //! Return the allocation size for the pixels |
| - size_t getSize() const { return fSize; } |
| void* getAddr() const { return fStorage; } |
| SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef) |
| protected: |
| - // overrides from SkPixelRef |
| - virtual void* onLockPixels(SkColorTable**); |
| - virtual void onUnlockPixels(); |
| + virtual void* onLockPixels(SkImageInfo*, size_t*, SkColorTable**) SK_OVERRIDE; |
| + virtual void onUnlockPixels() SK_OVERRIDE; |
| + virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
| SkMallocPixelRef(SkFlattenableReadBuffer& buffer); |
| - virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
| + SkMallocPixelRef(const SkImageInfo&, void* addr, size_t rb, SkColorTable*, |
| + bool ownsPixels); |
| + virtual ~SkMallocPixelRef(); |
| private: |
| - void* fStorage; |
| - size_t fSize; |
| - SkColorTable* fCTable; |
| - bool fOwnPixels; |
| + void* fStorage; |
| + SkColorTable* fCTable; |
| + size_t fRB; |
| + SkImageInfo fInfo; |
| + const bool fOwnPixels; |
| + |
| + size_t computeMinSize() const { |
| + if (fInfo.fHeight == 0) { |
| + return 0; |
| + } |
| + return (fInfo.fHeight - 1) * fRB + fInfo.minRowBytes(); |
| + } |
| typedef SkPixelRef INHERITED; |
| }; |