diff options
author | Tim Murray <timmurray@google.com> | 2012-12-04 17:59:29 -0800 |
---|---|---|
committer | Tim Murray <timmurray@google.com> | 2012-12-04 18:27:07 -0800 |
commit | a314551d69098537337c970da615a8f8af58e1f1 (patch) | |
tree | 608b65ccb3d7f5324d57c907c7a80fec46faddc6 /graphics/java/android/renderscript/Allocation.java | |
parent | 43cdf6d6795424e93ef232570ab8bbd9ae912041 (diff) |
Add support for Bitmap-backed Allocations in Java.
Change-Id: Iab38a275aa6cdac91c76fa0d134fbc1e8f387913
Bug: 7256604
Diffstat (limited to 'graphics/java/android/renderscript/Allocation.java')
-rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index e44a3ef50a6a..2ce2f33742fd 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -233,6 +233,10 @@ public class Allocation extends BaseObj { } } + private void setBitmap(Bitmap b) { + mBitmap = b; + } + Allocation(int id, RenderScript rs, Type t, int usage) { super(id, rs); if ((usage & ~(USAGE_SCRIPT | @@ -1151,6 +1155,22 @@ public class Allocation extends BaseObj { rs.validate(); Type t = typeFromBitmap(rs, b, mips); + // enable optimized bitmap path only with no mipmap and script-only usage + if (mips == MipmapControl.MIPMAP_NONE && + t.getElement().isCompatible(Element.RGBA_8888(rs)) && + usage == USAGE_SCRIPT) { + int id = rs.nAllocationCreateBitmapBackedAllocation(t.getID(rs), mips.mID, b, usage); + if (id == 0) { + throw new RSRuntimeException("Load failed."); + } + + // keep a reference to the Bitmap around to prevent GC + Allocation alloc = new Allocation(id, rs, t, usage); + alloc.setBitmap(b); + return alloc; + } + + int id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage); if (id == 0) { throw new RSRuntimeException("Load failed."); |