summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2010-03-01 15:31:04 -0800
committerJason Sams <rjsams@android.com>2010-03-01 15:31:04 -0800
commit8a64743f37ed35af7c2204acd18bb3d62d8f66d5 (patch)
tree13222fdd1021b6af52f78d1d3576b0139b724ee1 /graphics
parentc2908e60c9b021fb4bb69acff8d49981dd4dade8 (diff)
downloadframeworks_base-8a64743f37ed35af7c2204acd18bb3d62d8f66d5.zip
frameworks_base-8a64743f37ed35af7c2204acd18bb3d62d8f66d5.tar.gz
frameworks_base-8a64743f37ed35af7c2204acd18bb3d62d8f66d5.tar.bz2
Add support for linking to a skia bitmap rather than always copying the data from the bitmap.
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/renderscript/Allocation.java46
-rw-r--r--graphics/java/android/renderscript/RenderScript.java1
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp21
3 files changed, 67 insertions, 1 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 8185404..17c0778 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -32,6 +32,7 @@ import android.util.TypedValue;
**/
public class Allocation extends BaseObj {
Type mType;
+ Bitmap mBitmap;
Allocation(int id, RenderScript rs, Type t) {
super(rs);
@@ -262,15 +263,58 @@ public class Allocation extends BaseObj {
return new Allocation(id, rs, t);
}
+ static private Element elementFromBitmap(RenderScript rs, Bitmap b) {
+ final Bitmap.Config bc = b.getConfig();
+ if (bc == Bitmap.Config.ALPHA_8) {
+ return Element.A_8(rs);
+ }
+ if (bc == Bitmap.Config.ARGB_4444) {
+ return Element.RGBA_4444(rs);
+ }
+ if (bc == Bitmap.Config.ARGB_8888) {
+ return Element.RGBA_8888(rs);
+ }
+ if (bc == Bitmap.Config.RGB_565) {
+ return Element.RGB_565(rs);
+ }
+ throw new IllegalStateException("Bad bitmap type.");
+ }
+
+ static private Type typeFromBitmap(RenderScript rs, Bitmap b) {
+ Element e = elementFromBitmap(rs, b);
+ Type.Builder tb = new Type.Builder(rs, e);
+ tb.add(Dimension.X, b.getWidth());
+ tb.add(Dimension.Y, b.getHeight());
+ return tb.create();
+ }
+
static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
throws IllegalArgumentException {
rs.validate();
+ Type t = typeFromBitmap(rs, b);
+
int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b);
if(id == 0) {
throw new IllegalStateException("Load failed.");
}
- return new Allocation(id, rs, null);
+ return new Allocation(id, rs, t);
+ }
+
+ static public Allocation createBitmapRef(RenderScript rs, Bitmap b)
+ throws IllegalArgumentException {
+
+ rs.validate();
+ Type t = typeFromBitmap(rs, b);
+
+ int id = rs.nAllocationCreateBitmapRef(t.getID(), b);
+ if(id == 0) {
+ throw new IllegalStateException("Load failed.");
+ }
+
+ Allocation a = new Allocation(id, rs, t);
+ a.mBitmap = b;
+ return a;
}
static Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 70c97ea..a935243 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -98,6 +98,7 @@ public class RenderScript {
native int nAllocationCreateTyped(int type);
native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
+ native int nAllocationCreateBitmapRef(int type, Bitmap bmp);
native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
native int nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream);
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index cb5a00e..d8e0393 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -501,6 +501,26 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean g
return 0;
}
+static void ReleaseBitmapCallback(void *bmp)
+{
+ SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
+ nativeBitmap->unlockPixels();
+}
+
+static int
+nAllocationCreateBitmapRef(JNIEnv *_env, jobject _this, jint type, jobject jbitmap)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ SkBitmap * nativeBitmap =
+ (SkBitmap *)_env->GetIntField(jbitmap, gNativeBitmapID);
+
+
+ nativeBitmap->lockPixels();
+ void* ptr = nativeBitmap->getPixels();
+ jint id = (jint)rsAllocationCreateBitmapRef(con, (RsType)type, ptr, nativeBitmap, ReleaseBitmapCallback);
+ return id;
+}
+
static int
nAllocationCreateFromAssetStream(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jint native_asset)
{
@@ -1367,6 +1387,7 @@ static JNINativeMethod methods[] = {
{"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped },
{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap },
+{"nAllocationCreateBitmapRef", "(ILandroid/graphics/Bitmap;)I", (void*)nAllocationCreateBitmapRef },
{"nAllocationCreateFromBitmapBoxed","(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmapBoxed },
{"nAllocationCreateFromAssetStream","(IZI)I", (void*)nAllocationCreateFromAssetStream },
{"nAllocationUploadToTexture", "(IZI)V", (void*)nAllocationUploadToTexture },