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: |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 20 | /** Allocate the specified buffer for pixels. The memory is freed when the |
| 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 | */ |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 24 | SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable, bool ownPixels = true); |
| 25 | virtual ~SkMallocPixelRef(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 26 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 27 | void* getAddr() const { return fStorage; } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | |
djsollen@google.com | 5370cd9 | 2012-03-28 20:47:01 +0000 | [diff] [blame] | 29 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | |
| 31 | protected: |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 32 | // overrides from SkPixelRef |
| 33 | virtual void* onLockPixels(SkColorTable**); |
| 34 | virtual void onUnlockPixels(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | |
| 36 | SkMallocPixelRef(SkFlattenableReadBuffer& buffer); |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 37 | virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
| 38 | |
| 39 | // Returns the allocation size for the pixels |
| 40 | virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE { return fSize; } |
commit-bot@chromium.org | cd3b15c | 2013-12-04 17:06:49 +0000 | [diff] [blame] | 41 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 42 | private: |
reed@google.com | 398337b | 2013-12-11 21:22:39 +0000 | [diff] [blame^] | 43 | void* fStorage; |
| 44 | size_t fSize; |
| 45 | SkColorTable* fCTable; |
| 46 | bool fOwnPixels; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 47 | |
| 48 | typedef SkPixelRef INHERITED; |
| 49 | }; |
| 50 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 51 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | #endif |