2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2008 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkMallocPixelRef_DEFINED
|
|
|
|
#define SkMallocPixelRef_DEFINED
|
|
|
|
|
|
|
|
#include "SkPixelRef.h"
|
|
|
|
|
|
|
|
/** We explicitly use the same allocator for our pixels that SkMask does,
|
|
|
|
so that we can freely assign memory allocated by one class to the other.
|
|
|
|
*/
|
|
|
|
class SkMallocPixelRef : public SkPixelRef {
|
|
|
|
public:
|
2013-12-06 21:43:05 +00:00
|
|
|
/** 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.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2013-12-06 21:43:05 +00:00
|
|
|
SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable, bool ownPixels = true);
|
|
|
|
virtual ~SkMallocPixelRef();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
void* getAddr() const { return fStorage; }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-03-28 20:47:01 +00:00
|
|
|
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMallocPixelRef)
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2013-12-06 21:43:05 +00:00
|
|
|
// overrides from SkPixelRef
|
|
|
|
virtual void* onLockPixels(SkColorTable**);
|
|
|
|
virtual void onUnlockPixels();
|
2013-12-06 18:51:08 +00:00
|
|
|
|
2013-12-06 20:31:45 +00:00
|
|
|
SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
|
2013-12-06 21:43:05 +00:00
|
|
|
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
|
|
|
|
|
|
|
|
// Returns the allocation size for the pixels
|
|
|
|
virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE { return fSize; }
|
2013-12-04 17:06:49 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2013-12-06 21:43:05 +00:00
|
|
|
void* fStorage;
|
|
|
|
size_t fSize;
|
|
|
|
SkColorTable* fCTable;
|
|
|
|
bool fOwnPixels;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
typedef SkPixelRef INHERITED;
|
|
|
|
};
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|