diff options
author | Jason Sams <rjsams@android.com> | 2009-08-03 16:03:08 -0700 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2009-08-03 16:03:08 -0700 |
commit | bd1c3ad0cdf8e60b849a009cdc0b36764cc1dacb (patch) | |
tree | fa3ac33695695699563507abb0dad5691058596e | |
parent | b8c5a84e7c23746a3fc26013e0880d3d95ca6588 (diff) | |
download | frameworks_base-bd1c3ad0cdf8e60b849a009cdc0b36764cc1dacb.zip frameworks_base-bd1c3ad0cdf8e60b849a009cdc0b36764cc1dacb.tar.gz frameworks_base-bd1c3ad0cdf8e60b849a009cdc0b36764cc1dacb.tar.bz2 |
Implement the jni bindings for Adapter2D. Fix a refcount bug in the native adapter implementation. Use adapters in Film to border the mipmaps.
-rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 48 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 24 | ||||
-rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 91 | ||||
-rw-r--r-- | libs/rs/java/Film/src/com/android/film/FilmRS.java | 17 | ||||
-rw-r--r-- | libs/rs/rsAdapter.cpp | 16 |
5 files changed, 171 insertions, 25 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 1327328..3b6571a 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -90,14 +90,14 @@ public class Allocation extends BaseObj { mRS.nAdapter1DData(mID, d); } - public void subData(int off, int count, int[] d) { - mRS.nAdapter1DSubData(mID, off, count, d); - } - public void data(float[] d) { mRS.nAdapter1DData(mID, d); } + public void subData(int off, int count, int[] d) { + mRS.nAdapter1DSubData(mID, off, count, d); + } + public void subData(int off, int count, float[] d) { mRS.nAdapter1DSubData(mID, off, count, d); } @@ -112,6 +112,46 @@ public class Allocation extends BaseObj { } + public class Adapter2D extends BaseObj { + Adapter2D(int id, RenderScript rs) { + super(rs); + mID = id; + } + + public void destroy() { + mRS.nAdapter2DDestroy(mID); + mID = 0; + } + + public void setConstraint(Dimension dim, int value) { + mRS.nAdapter2DSetConstraint(mID, dim.mID, value); + } + + public void data(int[] d) { + mRS.nAdapter2DData(mID, d); + } + + public void data(float[] d) { + mRS.nAdapter2DData(mID, d); + } + + public void subData(int xoff, int yoff, int w, int h, int[] d) { + mRS.nAdapter2DSubData(mID, xoff, yoff, w, h, d); + } + + public void subData(int xoff, int yoff, int w, int h, float[] d) { + mRS.nAdapter2DSubData(mID, xoff, yoff, w, h, d); + } + } + + public Adapter2D createAdapter2D() { + int id = mRS.nAdapter2DCreate(); + if (id != 0) { + mRS.nAdapter2DBindAllocation(id, mID); + } + return new Adapter2D(id, mRS); + } + // creation diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index dc87b6a..dd7dd02 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -113,11 +113,20 @@ public class RenderScript { native void nAdapter1DBindAllocation(int ad, int alloc); native void nAdapter1DSetConstraint(int ad, int dim, int value); native void nAdapter1DData(int ad, int[] d); - native void nAdapter1DSubData(int ad, int off, int count, int[] d); native void nAdapter1DData(int ad, float[] d); + native void nAdapter1DSubData(int ad, int off, int count, int[] d); native void nAdapter1DSubData(int ad, int off, int count, float[] d); native int nAdapter1DCreate(); + native void nAdapter2DDestroy(int id); + native void nAdapter2DBindAllocation(int ad, int alloc); + native void nAdapter2DSetConstraint(int ad, int dim, int value); + native void nAdapter2DData(int ad, int[] d); + native void nAdapter2DData(int ad, float[] d); + native void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, int[] d); + native void nAdapter2DSubData(int ad, int xoff, int yoff, int w, int h, float[] d); + native int nAdapter2DCreate(); + native void nScriptDestroy(int script); native void nScriptBindAllocation(int vtm, int alloc, int slot); native void nScriptCBegin(); @@ -720,19 +729,6 @@ public class RenderScript { nContextBindProgramVertex(pf.mID); } -/* - RsAdapter2D rsAdapter2DCreate (); - void rsAdapter2DBindAllocation (RsAdapter2D adapt, RsAllocation alloc); - void rsAdapter2DDestroy (RsAdapter2D adapter); - void rsAdapter2DSetConstraint (RsAdapter2D adapter, RsDimension dim, uint32_t value); - void rsAdapter2DData (RsAdapter2D adapter, const void * data); - void rsAdapter2DSubData (RsAdapter2D adapter, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void * data); - void rsSamplerBegin (); - void rsSamplerSet (RsSamplerParam p, RsSamplerValue value); - RsSampler rsSamplerCreate (); - void rsSamplerBind (RsSampler sampler, RsAllocation alloc); -*/ - } diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index a02abca..f5227a0 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -551,6 +551,86 @@ nAdapter1DCreate(JNIEnv *_env, jobject _this) // ----------------------------------- static void +nAdapter2DDestroy(JNIEnv *_env, jobject _this, jint adapter) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + LOG_API("nAdapter2DDestroy, con(%p), adapter(%p)", con, (RsAdapter2D)adapter); + rsAdapter2DDestroy((RsAdapter2D)adapter); +} + +static void +nAdapter2DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + LOG_API("nAdapter2DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter2D)adapter, (RsAllocation)alloc); + rsAdapter2DBindAllocation((RsAdapter2D)adapter, (RsAllocation)alloc); +} + +static void +nAdapter2DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + LOG_API("nAdapter2DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter2D)adapter, dim, value); + rsAdapter2DSetConstraint((RsAdapter2D)adapter, (RsDimension)dim, value); +} + +static void +nAdapter2DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + jint len = _env->GetArrayLength(data); + LOG_API("nAdapter2DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len); + jint *ptr = _env->GetIntArrayElements(data, NULL); + rsAdapter2DData((RsAdapter2D)adapter, ptr); + _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); +} + +static void +nAdapter2DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + jint len = _env->GetArrayLength(data); + LOG_API("nAdapter2DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter2D)adapter, len); + jfloat *ptr = _env->GetFloatArrayElements(data, NULL); + rsAdapter2DData((RsAdapter2D)adapter, ptr); + _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); +} + +static void +nAdapter2DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jintArray data) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + jint len = _env->GetArrayLength(data); + LOG_API("nAdapter2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", + con, (RsAdapter2D)adapter, xoff, yoff, w, h, len); + jint *ptr = _env->GetIntArrayElements(data, NULL); + rsAdapter2DSubData((RsAdapter2D)adapter, xoff, yoff, w, h, ptr); + _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); +} + +static void +nAdapter2DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint xoff, jint yoff, jint w, jint h, jfloatArray data) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + jint len = _env->GetArrayLength(data); + LOG_API("nAdapter2DSubData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", + con, (RsAdapter2D)adapter, xoff, yoff, w, h, len); + jfloat *ptr = _env->GetFloatArrayElements(data, NULL); + rsAdapter2DSubData((RsAdapter1D)adapter, xoff, yoff, w, h, ptr); + _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); +} + +static jint +nAdapter2DCreate(JNIEnv *_env, jobject _this) +{ + RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); + LOG_API("nAdapter2DCreate, con(%p)", con); + return (jint)rsAdapter2DCreate(); +} + +// ----------------------------------- + +static void nScriptDestroy(JNIEnv *_env, jobject _this, jint script) { RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); @@ -1058,11 +1138,20 @@ static JNINativeMethod methods[] = { {"nAdapter1DBindAllocation", "(II)V", (void*)nAdapter1DBindAllocation }, {"nAdapter1DSetConstraint", "(III)V", (void*)nAdapter1DSetConstraint }, {"nAdapter1DData", "(I[I)V", (void*)nAdapter1DData_i }, -{"nAdapter1DSubData", "(III[I)V", (void*)nAdapter1DSubData_i }, {"nAdapter1DData", "(I[F)V", (void*)nAdapter1DData_f }, +{"nAdapter1DSubData", "(III[I)V", (void*)nAdapter1DSubData_i }, {"nAdapter1DSubData", "(III[F)V", (void*)nAdapter1DSubData_f }, {"nAdapter1DCreate", "()I", (void*)nAdapter1DCreate }, +{"nAdapter2DDestroy", "(I)V", (void*)nAdapter2DDestroy }, +{"nAdapter2DBindAllocation", "(II)V", (void*)nAdapter2DBindAllocation }, +{"nAdapter2DSetConstraint", "(III)V", (void*)nAdapter2DSetConstraint }, +{"nAdapter2DData", "(I[I)V", (void*)nAdapter2DData_i }, +{"nAdapter2DData", "(I[F)V", (void*)nAdapter2DData_f }, +{"nAdapter2DSubData", "(IIIII[I)V", (void*)nAdapter2DSubData_i }, +{"nAdapter2DSubData", "(IIIII[F)V", (void*)nAdapter2DSubData_f }, +{"nAdapter2DCreate", "()I", (void*)nAdapter2DCreate }, + {"nScriptDestroy", "(I)V", (void*)nScriptDestroy }, {"nScriptBindAllocation", "(III)V", (void*)nScriptBindAllocation }, {"nScriptCBegin", "()V", (void*)nScriptCBegin }, diff --git a/libs/rs/java/Film/src/com/android/film/FilmRS.java b/libs/rs/java/Film/src/com/android/film/FilmRS.java index 777a7cf..eda7624 100644 --- a/libs/rs/java/Film/src/com/android/film/FilmRS.java +++ b/libs/rs/java/Film/src/com/android/film/FilmRS.java @@ -28,6 +28,7 @@ import android.renderscript.ProgramVertexAlloc; import android.renderscript.RenderScript; import android.renderscript.Element; import android.renderscript.Allocation; +import android.renderscript.Dimension; public class FilmRS { private final int POS_TRANSLATE = 0; @@ -175,7 +176,23 @@ public class FilmRS { mImages[11] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p12, ie, true); mImages[12] = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.p13, ie, true); + int black[] = new int[1024]; for(int ct=0; ct < mImages.length; ct++) { + Allocation.Adapter2D a = mImages[ct].createAdapter2D(); + + int size = 512; + int mip = 0; + while(size >= 2) { + a.subData(0, 0, 2, size, black); + a.subData(size-2, 0, 2, size, black); + a.subData(0, 0, size, 2, black); + a.subData(0, size-2, size, 2, black); + size >>= 1; + mip++; + a.setConstraint(Dimension.LOD, mip); + } + a.destroy(); + mImages[ct].uploadToTexture(1); mBufferIDs[ct] = mImages[ct].getID(); } diff --git a/libs/rs/rsAdapter.cpp b/libs/rs/rsAdapter.cpp index 7ac2aed..25f3340 100644 --- a/libs/rs/rsAdapter.cpp +++ b/libs/rs/rsAdapter.cpp @@ -61,8 +61,8 @@ void Adapter1D::subData(uint32_t xoff, uint32_t count, const void *data) void Adapter1D::data(const void *data) { - memcpy(getElement(0), - data, + memcpy(getElement(0), + data, mAllocation.get()->getType()->getSizeBytes()); } @@ -71,7 +71,9 @@ namespace renderscript { RsAdapter1D rsi_Adapter1DCreate(Context *rsc) { - return new Adapter1D(); + Adapter1D *a = new Adapter1D(); + a->incRef(); + return a; } void rsi_Adapter1DDestroy(Context *rsc, RsAdapter1D va) @@ -176,8 +178,8 @@ void Adapter2D::subData(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, co void Adapter2D::data(const void *data) { - memcpy(getElement(0,0), - data, + memcpy(getElement(0,0), + data, mAllocation.get()->getType()->getSizeBytes()); } @@ -188,7 +190,9 @@ namespace renderscript { RsAdapter2D rsi_Adapter2DCreate(Context *rsc) { - return new Adapter2D(); + Adapter2D *a = new Adapter2D(); + a->incRef(); + return a; } void rsi_Adapter2DDestroy(Context *rsc, RsAdapter2D va) |