summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/renderscript/Allocation.java53
-rw-r--r--graphics/java/android/renderscript/RenderScript.java3
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp29
3 files changed, 78 insertions, 7 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index e5cf38e..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);
@@ -45,7 +46,12 @@ public class Allocation extends BaseObj {
public void uploadToTexture(int baseMipLevel) {
mRS.validate();
- mRS.nAllocationUploadToTexture(mID, baseMipLevel);
+ mRS.nAllocationUploadToTexture(mID, false, baseMipLevel);
+ }
+
+ public void uploadToTexture(boolean genMips, int baseMipLevel) {
+ mRS.validate();
+ mRS.nAllocationUploadToTexture(mID, genMips, baseMipLevel);
}
public void uploadToBufferObject() {
@@ -257,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 84b1a70..a935243 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -98,10 +98,11 @@ 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);
- native void nAllocationUploadToTexture(int alloc, int baseMioLevel);
+ native void nAllocationUploadToTexture(int alloc, boolean genMips, int baseMioLevel);
native void nAllocationUploadToBufferObject(int alloc);
native void nAllocationSubData1D(int id, int off, int count, int[] d, int sizeBytes);
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 0ffdf71..d8e0393 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -444,11 +444,11 @@ nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e)
}
static void
-nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip)
+nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jboolean genMip, jint mip)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
- LOG_API("nAllocationUploadToTexture, con(%p), a(%p), mip(%i)", con, (RsAllocation)a, mip);
- rsAllocationUploadToTexture(con, (RsAllocation)a, mip);
+ LOG_API("nAllocationUploadToTexture, con(%p), a(%p), genMip(%i), mip(%i)", con, (RsAllocation)a, genMip, mip);
+ rsAllocationUploadToTexture(con, (RsAllocation)a, genMip, mip);
}
static void
@@ -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,9 +1387,10 @@ 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", "(II)V", (void*)nAllocationUploadToTexture },
+{"nAllocationUploadToTexture", "(IZI)V", (void*)nAllocationUploadToTexture },
{"nAllocationUploadToBufferObject","(I)V", (void*)nAllocationUploadToBufferObject },
{"nAllocationSubData1D", "(III[II)V", (void*)nAllocationSubData1D_i },
{"nAllocationSubData1D", "(III[SI)V", (void*)nAllocationSubData1D_s },