blob: 100a15d90abb4ca55b30aa9af47e5ce17f18fa67 [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:
reed@google.com398337b2013-12-11 21:22:39 +000020 /** 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.com8a1c16f2008-12-17 15:59:43 +000023 */
reed@google.com398337b2013-12-11 21:22:39 +000024 SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable, bool ownPixels = true);
25 virtual ~SkMallocPixelRef();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000026
reed@android.comf2b98d62010-12-20 18:26:13 +000027 void* getAddr() const { return fStorage; }
reed@android.com8a1c16f2008-12-17 15:59:43 +000028
djsollen@google.com5370cd92012-03-28 20:47:01 +000029 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef)
reed@android.com8a1c16f2008-12-17 15:59:43 +000030
31protected:
reed@google.com398337b2013-12-11 21:22:39 +000032 // overrides from SkPixelRef
33 virtual void* onLockPixels(SkColorTable**);
34 virtual void onUnlockPixels();
reed@android.com8a1c16f2008-12-17 15:59:43 +000035
36 SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
reed@google.com398337b2013-12-11 21:22:39 +000037 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.orgcd3b15c2013-12-04 17:06:49 +000041
reed@android.com8a1c16f2008-12-17 15:59:43 +000042private:
reed@google.com398337b2013-12-11 21:22:39 +000043 void* fStorage;
44 size_t fSize;
45 SkColorTable* fCTable;
46 bool fOwnPixels;
reed@android.com8a1c16f2008-12-17 15:59:43 +000047
48 typedef SkPixelRef INHERITED;
49};
50
reed@android.comf2b98d62010-12-20 18:26:13 +000051
reed@android.com8a1c16f2008-12-17 15:59:43 +000052#endif