blob: cdfec758733240ceb0fd69ffb702c1e48f8cf27e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2008 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#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*/
18class SkMallocPixelRef : public SkPixelRef {
19public:
20 /** Allocate the specified buffer for pixels. The memory is freed when the
reed@android.comf2b98d62010-12-20 18:26:13 +000021 last owner of this pixelref is gone. If addr is NULL, sk_malloc_throw()
22 is called to allocate it.
reed@android.com8a1c16f2008-12-17 15:59:43 +000023 */
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.comf2b98d62010-12-20 18:26:13 +000029 void* getAddr() const { return fStorage; }
reed@android.com8a1c16f2008-12-17 15:59:43 +000030
31 // overrides from SkPixelRef
djsollen@google.com5370cd92012-03-28 20:47:01 +000032 virtual void flatten(SkFlattenableWriteBuffer&);
33 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef)
reed@android.com8a1c16f2008-12-17 15:59:43 +000034
35protected:
36 // overrides from SkPixelRef
37 virtual void* onLockPixels(SkColorTable**);
38 virtual void onUnlockPixels();
39
40 SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
41
42private:
43 void* fStorage;
44 size_t fSize;
45 SkColorTable* fCTable;
46
47 typedef SkPixelRef INHERITED;
48};
49
reed@android.comf2b98d62010-12-20 18:26:13 +000050
reed@android.com8a1c16f2008-12-17 15:59:43 +000051#endif