epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2008 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkMallocPixelRef_DEFINED |
| 11 | #define SkMallocPixelRef_DEFINED |
| 12 | |
| 13 | #include "SkPixelRef.h" |
| 14 | |
| 15 | /** We explicitly use the same allocator for our pixels that SkMask does, |
| 16 | so that we can freely assign memory allocated by one class to the other. |
| 17 | */ |
| 18 | class SkMallocPixelRef : public SkPixelRef { |
| 19 | public: |
| 20 | /** Allocate the specified buffer for pixels. The memory is freed when the |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 21 | last owner of this pixelref is gone. If addr is NULL, sk_malloc_throw() |
| 22 | is called to allocate it. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | */ |
| 24 | SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable); |
| 25 | virtual ~SkMallocPixelRef(); |
| 26 | |
| 27 | //! Return the allocation size for the pixels |
| 28 | size_t getSize() const { return fSize; } |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 29 | void* getAddr() const { return fStorage; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | |
| 31 | // overrides from SkPixelRef |
djsollen@google.com | 5370cd9 | 2012-03-28 20:47:01 +0000 | [diff] [blame] | 32 | virtual void flatten(SkFlattenableWriteBuffer&); |
| 33 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | |
| 35 | protected: |
| 36 | // overrides from SkPixelRef |
| 37 | virtual void* onLockPixels(SkColorTable**); |
| 38 | virtual void onUnlockPixels(); |
| 39 | |
| 40 | SkMallocPixelRef(SkFlattenableReadBuffer& buffer); |
| 41 | |
| 42 | private: |
| 43 | void* fStorage; |
| 44 | size_t fSize; |
| 45 | SkColorTable* fCTable; |
| 46 | |
| 47 | typedef SkPixelRef INHERITED; |
| 48 | }; |
| 49 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 50 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | #endif |