From 8a64743f37ed35af7c2204acd18bb3d62d8f66d5 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Mon, 1 Mar 2010 15:31:04 -0800 Subject: Add support for linking to a skia bitmap rather than always copying the data from the bitmap. --- libs/rs/rsAllocation.cpp | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'libs/rs/rsAllocation.cpp') diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index f1798de0f7b4..4e8278d79840 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -24,6 +24,27 @@ using namespace android; using namespace android::renderscript; Allocation::Allocation(Context *rsc, const Type *type) : ObjectBase(rsc) +{ + init(rsc, type); + + mPtr = malloc(mType->getSizeBytes()); + if (!mPtr) { + LOGE("Allocation::Allocation, alloc failure"); + } +} + +Allocation::Allocation(Context *rsc, const Type *type, void *bmp, + void *callbackData, RsBitmapCallback_t callback) +: ObjectBase(rsc) +{ + init(rsc, type); + + mPtr = bmp; + mUserBitmapCallback = callback; + mUserBitmapCallbackData = callbackData; +} + +void Allocation::init(Context *rsc, const Type *type) { mAllocFile = __FILE__; mAllocLine = __LINE__; @@ -43,17 +64,22 @@ Allocation::Allocation(Context *rsc, const Type *type) : ObjectBase(rsc) mBufferID = 0; mUploadDefered = false; + mUserBitmapCallback = NULL; + mUserBitmapCallbackData = NULL; + mType.set(type); rsAssert(type); - mPtr = malloc(mType->getSizeBytes()); - if (!mPtr) { - LOGE("Allocation::Allocation, alloc failure"); - } + + mPtr = NULL; } Allocation::~Allocation() { - free(mPtr); + if (mUserBitmapCallback != NULL) { + mUserBitmapCallback(mUserBitmapCallbackData); + } else { + free(mPtr); + } mPtr = NULL; if (mBufferID) { @@ -486,6 +512,14 @@ static ElementConverter_t pickConverter(const Element *dst, const Element *src) return 0; } +RsAllocation rsi_AllocationCreateBitmapRef(Context *rsc, RsType vtype, + void *bmp, void *callbackData, RsBitmapCallback_t callback) +{ + const Type * type = static_cast(vtype); + Allocation * alloc = new Allocation(rsc, type, bmp, callbackData, callback); + alloc->incUserRef(); + return alloc; +} RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h, RsElement _dst, RsElement _src, bool genMips, const void *data) { -- cgit v1.2.3-59-g8ed1b