diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index ea02a17041ea2..5f0844af2f524 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -1466,6 +1466,10 @@ public class Allocation extends BaseObj { * Creates a non-mipmapped renderscript allocation to use as a * graphics texture from the bitmap referenced by resource id * + * With target API version 18 or greater, this allocation will be + * created with USAGE_SHARED. With target API version 17 or lower, + * this allocation will be created with USAGE_GRAPHICS_TEXTURE. + * * @param rs Context to which the allocation will belong. * @param res application resources * @param id resource id to load the data from @@ -1476,6 +1480,11 @@ public class Allocation extends BaseObj { static public Allocation createFromBitmapResource(RenderScript rs, Resources res, int id) { + if (rs.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) { + return createFromBitmapResource(rs, res, id, + MipmapControl.MIPMAP_NONE, + USAGE_SHARED | USAGE_SCRIPT); + } return createFromBitmapResource(rs, res, id, MipmapControl.MIPMAP_NONE, USAGE_GRAPHICS_TEXTURE); diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 7518ea8a93117..00e8769d4e5e5 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -157,6 +157,12 @@ public class RenderScript { rsnContextFinish(mContext); } + native void rsnContextSendMessage(int con, int id, int[] data); + synchronized void nContextSendMessage(int id, int[] data) { + validate(); + rsnContextSendMessage(mContext, id, data); + } + native void rsnContextBindRootScript(int con, int script); synchronized void nContextBindRootScript(int script) { validate(); @@ -823,6 +829,16 @@ public class RenderScript { return mMessageCallback; } + /** + * @hide + * + * @param id + * @param data + */ + public void sendMessage(int id, int[] data) { + nContextSendMessage(id, data); + } + /** * Runtime error base class. An application should derive from this class * if it wishes to install an error handler. When errors occur at runtime diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 54413b46092e4..80001a6fc136f 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -346,6 +346,23 @@ static void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con) rsContextDeinitToClient(con); } +static void +nContextSendMessage(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray data) +{ + jint *ptr = NULL; + jint len = 0; + if (data) { + len = _env->GetArrayLength(data); + jint *ptr = _env->GetIntArrayElements(data, NULL); + } + LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", con, id, len); + rsContextSendMessage(con, id, (const uint8_t *)ptr, len * sizeof(int)); + if (data) { + _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); + } +} + + static jint nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size) @@ -1434,6 +1451,7 @@ static JNINativeMethod methods[] = { {"rsnContextDump", "(II)V", (void*)nContextDump }, {"rsnContextPause", "(I)V", (void*)nContextPause }, {"rsnContextResume", "(I)V", (void*)nContextResume }, +{"rsnContextSendMessage", "(II[I)V", (void*)nContextSendMessage }, {"rsnAssignName", "(II[B)V", (void*)nAssignName }, {"rsnGetName", "(II)Ljava/lang/String;", (void*)nGetName }, {"rsnObjDestroy", "(II)V", (void*)nObjDestroy }, diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/TestBase.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/TestBase.java index b5df38d92b4ee..faef83aafb0b8 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/TestBase.java +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/TestBase.java @@ -45,7 +45,6 @@ public class TestBase { protected Allocation mInPixelsAllocation; protected Allocation mInPixelsAllocation2; protected Allocation mOutPixelsAllocation; - protected ScriptC_msg mMessageScript; protected ImageProcessingActivity act; @@ -110,7 +109,6 @@ public class TestBase { act = ipact; mRS = RenderScript.create(act); mRS.setMessageHandler(new MessageProcessor(act)); - mMessageScript = new ScriptC_msg(mRS); mInPixelsAllocation = Allocation.createFromBitmap(mRS, b); mInPixelsAllocation2 = Allocation.createFromBitmap(mRS, b2); @@ -129,7 +127,7 @@ public class TestBase { final public void runTestSendMessage() { runTest(); - mMessageScript.invoke_sendMsg(); + mRS.sendMessage(0, null); } public void finish() { diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/msg.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/msg.rs deleted file mode 100644 index 1a19ffc6a4d61..0000000000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/msg.rs +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) - -void sendMsg() { - rsSendToClientBlocking(0); -} -