Skip to content

Commit 170dc84

Browse files
author
Jason Sams
committed
More RS cpp binding work. All classes for
compute should be partially implemented at this time. Change-Id: Iddf9405cc69513b708975d20783395f0be04c680
1 parent a23c4eb commit 170dc84

File tree

13 files changed

+259
-33
lines changed

13 files changed

+259
-33
lines changed

libs/rs/Allocation.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
#ifndef __ANDROID_ALLOCATION_H__
18+
#define __ANDROID_ALLOCATION_H__
1719

1820
#include <pthread.h>
1921
#include <rs.h>
@@ -22,7 +24,7 @@
2224
#include "Type.h"
2325
#include "Element.h"
2426

25-
class Allocation : BaseObj {
27+
class Allocation : public BaseObj {
2628
protected:
2729
const Type *mType;
2830
uint32_t mUsage;
@@ -121,4 +123,4 @@ class Allocation : BaseObj {
121123

122124
};
123125

124-
126+
#endif

libs/rs/Android.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ LOCAL_SRC_FILES:= \
132132
BaseObj.cpp \
133133
Element.cpp \
134134
Type.cpp \
135-
Allocation.cpp
135+
Allocation.cpp \
136+
Script.cpp \
137+
ScriptC.cpp
136138

137139
LOCAL_SHARED_LIBRARIES += libz libcutils libutils libEGL libGLESv1_CM libGLESv2 libui libbcc libbcinfo libgui
138140

libs/rs/BaseObj.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ void * BaseObj::getID() const {
2727
return mID;
2828
}
2929

30+
void * BaseObj::getObjID(const BaseObj *o) {
31+
return o == NULL ? NULL : o->getID();
32+
}
33+
34+
3035
BaseObj::BaseObj(void *id, RenderScript *rs) {
3136
mRS = rs;
3237
mID = id;

libs/rs/BaseObj.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class BaseObj {
2727
protected:
2828
friend class Element;
2929
friend class Type;
30+
friend class Allocation;
31+
friend class Script;
32+
friend class ScriptC;
3033

3134
void *mID;
3235
RenderScript *mRS;
@@ -37,6 +40,8 @@ class BaseObj {
3740
BaseObj(void *id, RenderScript *rs);
3841
void checkValid();
3942

43+
static void * getObjID(const BaseObj *o);
44+
4045
public:
4146

4247
virtual ~BaseObj();

libs/rs/Element.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,40 @@
2424

2525
const Element * Element::getSubElement(uint32_t index) {
2626
if (!mVisibleElementMap.size()) {
27-
ALOGE("Element contains no sub-elements");
28-
return NULL;
27+
mRS->throwError("Element contains no sub-elements");
2928
}
3029
if (index >= mVisibleElementMap.size()) {
31-
ALOGE("Illegal sub-element index");
30+
mRS->throwError("Illegal sub-element index");
3231
}
3332
return mElements[mVisibleElementMap[index]];
3433
}
3534

3635
const char * Element::getSubElementName(uint32_t index) {
3736
if (!mVisibleElementMap.size()) {
38-
ALOGE("Element contains no sub-elements");
37+
mRS->throwError("Element contains no sub-elements");
3938
}
4039
if (index >= mVisibleElementMap.size()) {
41-
ALOGE("Illegal sub-element index");
40+
mRS->throwError("Illegal sub-element index");
4241
}
4342
return mElementNames[mVisibleElementMap[index]];
4443
}
4544

4645
size_t Element::getSubElementArraySize(uint32_t index) {
4746
if (!mVisibleElementMap.size()) {
48-
ALOGE("Element contains no sub-elements");
47+
mRS->throwError("Element contains no sub-elements");
4948
}
5049
if (index >= mVisibleElementMap.size()) {
51-
ALOGE("Illegal sub-element index");
50+
mRS->throwError("Illegal sub-element index");
5251
}
5352
return mArraySizes[mVisibleElementMap[index]];
5453
}
5554

5655
uint32_t Element::getSubElementOffsetBytes(uint32_t index) {
5756
if (mVisibleElementMap.size()) {
58-
ALOGE("Element contains no sub-elements");
57+
mRS->throwError("Element contains no sub-elements");
5958
}
6059
if (index >= mVisibleElementMap.size()) {
61-
ALOGE("Illegal sub-element index");
60+
mRS->throwError("Illegal sub-element index");
6261
}
6362
return mOffsetInBytes[mVisibleElementMap[index]];
6463
}
@@ -293,54 +292,45 @@ void Element::updateFromNative() {
293292
}
294293

295294
const Element * Element::createUser(RenderScript *rs, RsDataType dt) {
296-
ALOGE("createUser %p %i", rs, dt);
297295
void * id = rsElementCreate(rs->mContext, dt, RS_KIND_USER, false, 1);
298296
return new Element(id, rs, dt, RS_KIND_USER, false, 1);
299297
}
300298

301299
const Element * Element::createVector(RenderScript *rs, RsDataType dt, uint32_t size) {
302300
if (size < 2 || size > 4) {
303-
ALOGE("Vector size out of range 2-4.");
304-
return NULL;
301+
rs->throwError("Vector size out of range 2-4.");
305302
}
306303
void *id = rsElementCreate(rs->mContext, dt, RS_KIND_USER, false, size);
307304
return new Element(id, rs, dt, RS_KIND_USER, false, size);
308305
}
309306

310307
const Element * Element::createPixel(RenderScript *rs, RsDataType dt, RsDataKind dk) {
311-
ALOGE("createPixel %p %i %i", rs, dt, dk);
312308
if (!(dk == RS_KIND_PIXEL_L ||
313309
dk == RS_KIND_PIXEL_A ||
314310
dk == RS_KIND_PIXEL_LA ||
315311
dk == RS_KIND_PIXEL_RGB ||
316312
dk == RS_KIND_PIXEL_RGBA ||
317313
dk == RS_KIND_PIXEL_DEPTH)) {
318-
ALOGE("Unsupported DataKind");
319-
return NULL;
314+
rs->throwError("Unsupported DataKind");
320315
}
321316
if (!(dt == RS_TYPE_UNSIGNED_8 ||
322317
dt == RS_TYPE_UNSIGNED_16 ||
323318
dt == RS_TYPE_UNSIGNED_5_6_5 ||
324319
dt == RS_TYPE_UNSIGNED_4_4_4_4 ||
325320
dt == RS_TYPE_UNSIGNED_5_5_5_1)) {
326-
ALOGE("Unsupported DataType");
327-
return NULL;
321+
rs->throwError("Unsupported DataType");
328322
}
329323
if (dt == RS_TYPE_UNSIGNED_5_6_5 && dk != RS_KIND_PIXEL_RGB) {
330-
ALOGE("Bad kind and type combo");
331-
return NULL;
324+
rs->throwError("Bad kind and type combo");
332325
}
333326
if (dt == RS_TYPE_UNSIGNED_5_5_5_1 && dk != RS_KIND_PIXEL_RGBA) {
334-
ALOGE("Bad kind and type combo");
335-
return NULL;
327+
rs->throwError("Bad kind and type combo");
336328
}
337329
if (dt == RS_TYPE_UNSIGNED_4_4_4_4 && dk != RS_KIND_PIXEL_RGBA) {
338-
ALOGE("Bad kind and type combo");
339-
return NULL;
330+
rs->throwError("Bad kind and type combo");
340331
}
341332
if (dt == RS_TYPE_UNSIGNED_16 && dk != RS_KIND_PIXEL_DEPTH) {
342-
ALOGE("Bad kind and type combo");
343-
return NULL;
333+
rs->throwError("Bad kind and type combo");
344334
}
345335

346336
int size = 1;

libs/rs/RenderScript.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ bool RenderScript::init(int targetApi) {
7676
return true;
7777
}
7878

79+
void RenderScript::throwError(const char *err) const {
80+
ALOGE("RS CPP error: %s", err);
81+
int * v = NULL;
82+
v[0] = 0;
83+
}
84+
85+
7986
void * RenderScript::threadProc(void *vrsc) {
8087
RenderScript *rs = static_cast<RenderScript *>(vrsc);
8188
size_t rbuf_size = 256;

libs/rs/RenderScript.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class RenderScript {
3333
friend class Allocation;
3434
friend class Element;
3535
friend class Type;
36+
friend class Script;
37+
friend class ScriptC;
3638

3739
public:
3840
RenderScript();
@@ -144,6 +146,7 @@ class RenderScript {
144146

145147

146148

149+
void throwError(const char *err) const;
147150

148151
static void * threadProc(void *);
149152

libs/rs/Script.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (C) 2008-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+
#include <utils/Log.h>
18+
#include <malloc.h>
19+
20+
#include "RenderScript.h"
21+
#include "Element.h"
22+
#include "Type.h"
23+
#include "Allocation.h"
24+
#include "Script.h"
25+
26+
void Script::invoke(uint32_t slot, const void *v, size_t len) {
27+
rsScriptInvokeV(mRS->mContext, getID(), slot, v, len);
28+
}
29+
30+
void Script::forEach(uint32_t slot, const Allocation *ain, const Allocation *aout,
31+
const void *usr, size_t usrLen) {
32+
if ((ain == NULL) && (aout == NULL)) {
33+
mRS->throwError("At least one of ain or aout is required to be non-null.");
34+
}
35+
void *in_id = BaseObj::getObjID(ain);
36+
void *out_id = BaseObj::getObjID(aout);
37+
rsScriptForEach(mRS->mContext, getID(), slot, in_id, out_id, usr, usrLen);
38+
}
39+
40+
41+
Script::Script(void *id, RenderScript *rs) : BaseObj(id, rs) {
42+
}
43+
44+
45+
void Script::bindAllocation(const Allocation *va, uint32_t slot) {
46+
rsScriptBindAllocation(mRS->mContext, getID(), BaseObj::getObjID(va), slot);
47+
}
48+
49+
50+
void Script::setVar(uint32_t index, const BaseObj *o) {
51+
rsScriptSetVarObj(mRS->mContext, getID(), index, (o == NULL) ? 0 : o->getID());
52+
}
53+
54+
void Script::setVar(uint32_t index, const void *v, size_t len) {
55+
rsScriptSetVarV(mRS->mContext, getID(), index, v, len);
56+
}
57+
58+
59+
60+
void Script::FieldBase::init(RenderScript *rs, uint32_t dimx, uint32_t usages) {
61+
mAllocation = Allocation::createSized(rs, mElement, dimx, RS_ALLOCATION_USAGE_SCRIPT | usages);
62+
}
63+
64+
//Script::FieldBase::FieldBase() {
65+
//}
66+
67+

libs/rs/Script.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (C) 2008-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+
#ifndef __ANDROID_SCRIPT_H__
18+
#define __ANDROID_SCRIPT_H__
19+
20+
#include <pthread.h>
21+
#include <rs.h>
22+
23+
#include "RenderScript.h"
24+
#include "Allocation.h"
25+
26+
class Type;
27+
class Element;
28+
class Allocation;
29+
30+
class Script : public BaseObj {
31+
protected:
32+
Script(void *id, RenderScript *rs);
33+
void forEach(uint32_t slot, const Allocation *in, const Allocation *out, const void *v, size_t);
34+
void bindAllocation(const Allocation *va, uint32_t slot);
35+
void setVar(uint32_t index, const void *, size_t len);
36+
void setVar(uint32_t index, const BaseObj *o);
37+
void invoke(uint32_t slot, const void *v, size_t len);
38+
39+
40+
void invoke(uint32_t slot) {
41+
invoke(slot, NULL, 0);
42+
}
43+
void setVar(uint32_t index, float v) {
44+
setVar(index, &v, sizeof(v));
45+
}
46+
void setVar(uint32_t index, double v) {
47+
setVar(index, &v, sizeof(v));
48+
}
49+
void setVar(uint32_t index, int32_t v) {
50+
setVar(index, &v, sizeof(v));
51+
}
52+
void setVar(uint32_t index, int64_t v) {
53+
setVar(index, &v, sizeof(v));
54+
}
55+
void setVar(uint32_t index, bool v) {
56+
setVar(index, &v, sizeof(v));
57+
}
58+
59+
public:
60+
class FieldBase {
61+
protected:
62+
const Element *mElement;
63+
Allocation *mAllocation;
64+
65+
void init(RenderScript *rs, uint32_t dimx, uint32_t usages = 0);
66+
67+
public:
68+
const Element *getElement() {
69+
return mElement;
70+
}
71+
72+
const Type *getType() {
73+
return mAllocation->getType();
74+
}
75+
76+
const Allocation *getAllocation() {
77+
return mAllocation;
78+
}
79+
80+
//void updateAllocation();
81+
};
82+
};
83+
84+
#endif

libs/rs/ScriptC.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2008-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+
#include <utils/Log.h>
18+
#include <malloc.h>
19+
20+
#include "ScriptC.h"
21+
22+
ScriptC::ScriptC(RenderScript *rs,
23+
const char *codeTxt, size_t codeLength,
24+
const char *cachedName, size_t cachedNameLength,
25+
const char *cacheDir, size_t cacheDirLength)
26+
: Script(NULL, rs) {
27+
mID = rsScriptCCreate(rs->mContext, cachedName, cachedNameLength,
28+
cacheDir, cacheDirLength, codeTxt, codeLength);
29+
}
30+

0 commit comments

Comments
 (0)