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:
|
|
|
|
/** Allocate the specified buffer for pixels. The memory is freed when the
|
2010-12-20 18:26:13 +00:00
|
|
|
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
|
|
|
*/
|
2012-07-27 13:41:44 +00:00
|
|
|
SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable, bool ownPixels = true);
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual ~SkMallocPixelRef();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
//! Return the allocation size for the pixels
|
|
|
|
size_t getSize() const { return fSize; }
|
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:
|
|
|
|
// overrides from SkPixelRef
|
|
|
|
virtual void* onLockPixels(SkColorTable**);
|
|
|
|
virtual void onUnlockPixels();
|
|
|
|
|
|
|
|
SkMallocPixelRef(SkFlattenableReadBuffer& buffer);
|
2012-03-29 15:18:04 +00:00
|
|
|
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void* fStorage;
|
|
|
|
size_t fSize;
|
|
|
|
SkColorTable* fCTable;
|
2012-07-27 13:41:44 +00:00
|
|
|
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
|