diff options
author | Jason Sams <jsams@google.com> | 2013-02-05 19:20:18 -0800 |
---|---|---|
committer | Jason Sams <jsams@google.com> | 2013-02-05 19:20:18 -0800 |
commit | 455d64426615e5d269a3bd05cd91b67c3811fcdf (patch) | |
tree | 25014401d9053c07d9d4091ef65e6a15dde5913f | |
parent | a4b7bc97862e01d38b483524f1d1cf433d29e294 (diff) | |
download | frameworks_base-455d64426615e5d269a3bd05cd91b67c3811fcdf.zip frameworks_base-455d64426615e5d269a3bd05cd91b67c3811fcdf.tar.gz frameworks_base-455d64426615e5d269a3bd05cd91b67c3811fcdf.tar.bz2 |
Implement rs.sendMessage()
Change-Id: Ib4f4bb7bb4f697d0b5405ad55721394ed2456c65
5 files changed, 44 insertions, 26 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 5e9872f..22434dd 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 bfa09c2..ceeb1fd 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(); @@ -824,6 +830,16 @@ public class RenderScript { } /** + * @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 * the fields in this class will be filled and the run method called. diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 54413b4..80001a6 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 b5df38d..faef83a 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 1a19ffc..0000000 --- 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); -} - |