Implement rs.sendMessage()

Change-Id: Ib4f4bb7bb4f697d0b5405ad55721394ed2456c65
This commit is contained in:
Jason Sams
2013-02-05 19:20:18 -08:00
parent a4b7bc9786
commit 455d644266
5 changed files with 44 additions and 26 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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 },

View File

@@ -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() {

View File

@@ -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);
}