Skip to content

Commit adeb809

Browse files
committed
Start passing element/dim information along with FieldPacker.
BUG=6009244 Change-Id: I3c82c8b40c899b875831f53cf0ad82ea36c1a043
1 parent 9da1b5d commit adeb809

File tree

7 files changed

+110
-1
lines changed

7 files changed

+110
-1
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19239,6 +19239,7 @@ package android.renderscript {
1923919239
method public deprecated void setVar(int, boolean);
1924019240
method public deprecated void setVar(int, android.renderscript.BaseObj);
1924119241
method public deprecated void setVar(int, android.renderscript.FieldPacker);
19242+
method public deprecated void setVar(int, android.renderscript.FieldPacker, android.renderscript.Element, int[]);
1924219243
}
1924319244

1924419245
public static class Script.Builder {

graphics/java/android/renderscript/RenderScript.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,13 @@ synchronized void nScriptSetVarV(int id, int slot, byte[] val) {
541541
validate();
542542
rsnScriptSetVarV(mContext, id, slot, val);
543543
}
544+
native void rsnScriptSetVarVE(int con, int id, int slot, byte[] val,
545+
int e, int[] dims);
546+
synchronized void nScriptSetVarVE(int id, int slot, byte[] val,
547+
int e, int[] dims) {
548+
validate();
549+
rsnScriptSetVarVE(mContext, id, slot, val, e, dims);
550+
}
544551
native void rsnScriptSetVarObj(int con, int id, int slot, int val);
545552
synchronized void nScriptSetVarObj(int id, int slot, int val) {
546553
validate();

graphics/java/android/renderscript/Script.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008 The Android Open Source Project
2+
* Copyright (C) 2008-2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -162,6 +162,18 @@ public void setVar(int index, FieldPacker v) {
162162
mRS.nScriptSetVarV(getID(mRS), index, v.getData());
163163
}
164164

165+
/** @deprecated renderscript is deprecated in J
166+
* Only intended for use by generated reflected code.
167+
*
168+
* @param index
169+
* @param v
170+
* @param e
171+
* @param dims
172+
*/
173+
public void setVar(int index, FieldPacker v, Element e, int[] dims) {
174+
mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims);
175+
}
176+
165177
/** @deprecated renderscript is deprecated in J
166178
*/
167179
public void setTimeZone(String timeZone) {

graphics/jni/android_renderscript_RenderScript.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,20 @@ nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slo
953953
_env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
954954
}
955955

956+
static void
957+
nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims)
958+
{
959+
LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
960+
jint len = _env->GetArrayLength(data);
961+
jbyte *ptr = _env->GetByteArrayElements(data, NULL);
962+
jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
963+
jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
964+
rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem,
965+
(const size_t*) dimsPtr, dimsLen);
966+
_env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
967+
_env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
968+
}
969+
956970

957971
static void
958972
nScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
@@ -1394,6 +1408,7 @@ static JNINativeMethod methods[] = {
13941408
{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF },
13951409
{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD },
13961410
{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV },
1411+
{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE },
13971412
{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj },
13981413

13991414
{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate },

tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public void init(RenderScriptGL rs, Resources res, int width, int height) {
6868
unitTests.add(new UT_constant(this, mRes, mCtx));
6969
unitTests.add(new UT_vector(this, mRes, mCtx));
7070
unitTests.add(new UT_array_init(this, mRes, mCtx));
71+
unitTests.add(new UT_array_alloc(this, mRes, mCtx));
7172
unitTests.add(new UT_convert(this, mRes, mCtx));
7273
unitTests.add(new UT_rsdebug(this, mRes, mCtx));
7374
unitTests.add(new UT_rstime(this, mRes, mCtx));
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.rs.test;
18+
19+
import android.content.Context;
20+
import android.content.res.Resources;
21+
import android.renderscript.*;
22+
23+
public class UT_array_alloc extends UnitTest {
24+
private Resources mRes;
25+
26+
protected UT_array_alloc(RSTestCore rstc, Resources res, Context ctx) {
27+
super(rstc, "Array Allocation", ctx);
28+
mRes = res;
29+
}
30+
31+
public void run() {
32+
RenderScript pRS = RenderScript.create(mCtx);
33+
ScriptC_array_alloc s = new ScriptC_array_alloc(pRS, mRes, R.raw.array_alloc);
34+
pRS.setMessageHandler(mRsMessage);
35+
36+
int dimX = s.get_dimX();
37+
Allocation[] Arr = new Allocation[dimX];
38+
Type.Builder typeBuilder = new Type.Builder(pRS, Element.I32(pRS));
39+
Type T = typeBuilder.setX(1).create();
40+
for (int i = 0; i < dimX; i++) {
41+
Allocation A = Allocation.createTyped(pRS, T);
42+
Arr[i] = A;
43+
}
44+
s.set_a(Arr);
45+
46+
s.invoke_array_alloc_test();
47+
pRS.finish();
48+
waitForMessage();
49+
pRS.destroy();
50+
passTest();
51+
}
52+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "shared.rsh"
2+
3+
const int dimX = 20;
4+
rs_allocation a[dimX];
5+
6+
void array_alloc_test() {
7+
bool failed = false;
8+
9+
for (int i = 0; i < dimX; i++) {
10+
rsDebug("i: ", i);
11+
_RS_ASSERT(rsAllocationGetDimX(a[i]) == 1);
12+
}
13+
14+
if (failed) {
15+
rsSendToClientBlocking(RS_MSG_TEST_FAILED);
16+
}
17+
else {
18+
rsSendToClientBlocking(RS_MSG_TEST_PASSED);
19+
}
20+
}
21+

0 commit comments

Comments
 (0)