summaryrefslogtreecommitdiffstats
path: root/libs/rs
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs')
-rw-r--r--libs/rs/Android.mk17
-rw-r--r--libs/rs/RenderScript.h61
-rw-r--r--libs/rs/RenderScriptEnv.h2
-rw-r--r--libs/rs/java/Film/src/com/android/film/FilmRS.java5
-rw-r--r--libs/rs/java/Fountain/res/raw/fountain.c52
-rw-r--r--libs/rs/java/Fountain/res/raw/fountain.rs77
-rw-r--r--libs/rs/java/Fountain/res/raw/fountain2.rs73
-rw-r--r--libs/rs/java/Fountain/res/raw/fountain_bc.bcbin0 -> 2632 bytes
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java100
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/ScriptC_Fountain.java77
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point_s.java79
-rw-r--r--libs/rs/java/ImageProcessing/AndroidManifest.xml3
-rw-r--r--libs/rs/java/ImageProcessing/res/layout/main.xml153
-rw-r--r--libs/rs/java/ImageProcessing/res/raw/threshold.rs383
-rw-r--r--libs/rs/java/ImageProcessing/res/raw/threshold_bc.bcbin0 -> 8772 bytes
-rw-r--r--libs/rs/java/ImageProcessing/res/values/strings.xml33
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java440
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java115
-rw-r--r--libs/rs/java/ModelViewer/Android.mk27
-rw-r--r--libs/rs/java/ModelViewer/AndroidManifest.xml14
-rw-r--r--libs/rs/java/ModelViewer/res/drawable/robot.pngbin0 -> 1268637 bytes
-rw-r--r--libs/rs/java/ModelViewer/res/raw/modelviewer.rs59
-rw-r--r--libs/rs/java/ModelViewer/res/raw/modelviewer_bc.bcbin0 -> 1404 bytes
-rw-r--r--libs/rs/java/ModelViewer/res/raw/robot.a3dbin0 -> 144508 bytes
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewer.java71
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerRS.java156
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerView.java95
-rw-r--r--libs/rs/java/ModelViewer/src/com/android/modelviewer/ScriptC_ModelViewer.java42
-rw-r--r--libs/rs/rs.spec106
-rw-r--r--libs/rs/rsAdapter.cpp23
-rw-r--r--libs/rs/rsAdapter.h8
-rw-r--r--libs/rs/rsAllocation.cpp71
-rw-r--r--libs/rs/rsAllocation.h3
-rw-r--r--libs/rs/rsAnimation.cpp149
-rw-r--r--libs/rs/rsAnimation.h71
-rw-r--r--libs/rs/rsComponent.cpp25
-rw-r--r--libs/rs/rsComponent.h4
-rw-r--r--libs/rs/rsContext.cpp107
-rw-r--r--libs/rs/rsContext.h27
-rw-r--r--libs/rs/rsContextHostStub.h153
-rw-r--r--libs/rs/rsDevice.cpp6
-rw-r--r--libs/rs/rsElement.cpp91
-rw-r--r--libs/rs/rsElement.h5
-rw-r--r--libs/rs/rsFileA3D.cpp610
-rw-r--r--libs/rs/rsFileA3D.h102
-rw-r--r--libs/rs/rsHandcode.h43
-rw-r--r--libs/rs/rsLight.cpp16
-rw-r--r--libs/rs/rsLight.h3
-rw-r--r--libs/rs/rsLocklessFifo.cpp92
-rw-r--r--libs/rs/rsLocklessFifo.h24
-rw-r--r--libs/rs/rsMesh.cpp171
-rw-r--r--libs/rs/rsMesh.h8
-rw-r--r--libs/rs/rsMutex.cpp64
-rw-r--r--libs/rs/rsMutex.h (renamed from libs/rs/rsNoise.h)28
-rw-r--r--libs/rs/rsNoise.cpp256
-rw-r--r--libs/rs/rsObjectBase.cpp21
-rw-r--r--libs/rs/rsObjectBase.h7
-rw-r--r--libs/rs/rsProgram.cpp10
-rw-r--r--libs/rs/rsProgramFragment.cpp27
-rw-r--r--libs/rs/rsProgramFragment.h5
-rw-r--r--libs/rs/rsProgramRaster.cpp22
-rw-r--r--libs/rs/rsProgramRaster.h5
-rw-r--r--libs/rs/rsProgramStore.cpp (renamed from libs/rs/rsProgramFragmentStore.cpp)67
-rw-r--r--libs/rs/rsProgramStore.h (renamed from libs/rs/rsProgramFragmentStore.h)31
-rw-r--r--libs/rs/rsProgramVertex.cpp56
-rw-r--r--libs/rs/rsProgramVertex.h7
-rw-r--r--libs/rs/rsSampler.cpp19
-rw-r--r--libs/rs/rsSampler.h4
-rw-r--r--libs/rs/rsScript.cpp85
-rw-r--r--libs/rs/rsScript.h32
-rw-r--r--libs/rs/rsScriptC.cpp381
-rw-r--r--libs/rs/rsScriptC.h49
-rw-r--r--libs/rs/rsScriptC_Lib.cpp1111
-rw-r--r--libs/rs/rsScriptC_LibCL.cpp314
-rw-r--r--libs/rs/rsScriptC_LibGL.cpp524
-rw-r--r--libs/rs/rsShaderCache.cpp21
-rw-r--r--libs/rs/rsSignal.cpp98
-rw-r--r--libs/rs/rsSignal.h (renamed from libs/rs/rsFileA3DDecls.h)30
-rw-r--r--libs/rs/rsSimpleMesh.cpp134
-rw-r--r--libs/rs/rsSimpleMesh.h4
-rw-r--r--libs/rs/rsStream.cpp132
-rw-r--r--libs/rs/rsStream.h163
-rw-r--r--libs/rs/rsType.cpp183
-rw-r--r--libs/rs/rsType.h14
-rw-r--r--libs/rs/rsUtils.h31
-rw-r--r--libs/rs/rsVertexArray.cpp105
-rw-r--r--libs/rs/rsVertexArray.h6
-rw-r--r--libs/rs/rsg_ScriptJavaClass.cpp15
-rw-r--r--libs/rs/scriptc/rs_cl.rsh785
-rw-r--r--libs/rs/scriptc/rs_core.rsh54
-rw-r--r--libs/rs/scriptc/rs_graphics.rsh79
-rw-r--r--libs/rs/scriptc/rs_math.rsh366
-rw-r--r--libs/rs/scriptc/rs_types.rsh23
93 files changed, 6297 insertions, 3123 deletions
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 98464a0..3f01415 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -76,34 +76,39 @@ ifneq ($(TARGET_SIMULATOR),true)
LOCAL_SRC_FILES:= \
rsAdapter.cpp \
rsAllocation.cpp \
+ rsAnimation.cpp \
rsComponent.cpp \
rsContext.cpp \
rsDevice.cpp \
rsElement.cpp \
- rsFileA3D.cpp \
+ rsFileA3D.cpp \
rsLight.cpp \
rsLocklessFifo.cpp \
rsObjectBase.cpp \
rsMatrix.cpp \
- rsMesh.cpp \
- rsNoise.cpp \
+ rsMesh.cpp \
+ rsMutex.cpp \
rsProgram.cpp \
rsProgramFragment.cpp \
- rsProgramFragmentStore.cpp \
+ rsProgramStore.cpp \
rsProgramRaster.cpp \
rsProgramVertex.cpp \
rsSampler.cpp \
rsScript.cpp \
rsScriptC.cpp \
rsScriptC_Lib.cpp \
- rsShaderCache.cpp \
+ rsScriptC_LibCL.cpp \
+ rsScriptC_LibGL.cpp \
+ rsShaderCache.cpp \
+ rsSignal.cpp \
rsSimpleMesh.cpp \
+ rsStream.cpp \
rsThreadIO.cpp \
rsType.cpp \
rsVertexArray.cpp
-LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libGLESv2 libui libacc
+LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libGLESv2 libui libbcc
LOCAL_LDLIBS := -lpthread -ldl
LOCAL_MODULE:= libRS
LOCAL_MODULE_TAGS := optional
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index d280f50..f01eadd 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -30,6 +30,7 @@ extern "C" {
typedef void * RsAdapter1D;
typedef void * RsAdapter2D;
typedef void * RsAllocation;
+typedef void * RsAnimation;
typedef void * RsContext;
typedef void * RsDevice;
typedef void * RsElement;
@@ -39,11 +40,12 @@ typedef void * RsScript;
typedef void * RsSimpleMesh;
typedef void * RsType;
typedef void * RsLight;
+typedef void * RsObjectBase;
typedef void * RsProgram;
typedef void * RsProgramVertex;
typedef void * RsProgramFragment;
-typedef void * RsProgramFragmentStore;
+typedef void * RsProgramStore;
typedef void * RsProgramRaster;
typedef void (* RsBitmapCallback_t)(void *);
@@ -101,19 +103,12 @@ enum RsDataType {
enum RsDataKind {
RS_KIND_USER,
- RS_KIND_COLOR,
- RS_KIND_POSITION,
- RS_KIND_TEXTURE,
- RS_KIND_NORMAL,
- RS_KIND_INDEX,
- RS_KIND_POINT_SIZE,
-
- RS_KIND_PIXEL_L,
+
+ RS_KIND_PIXEL_L = 7,
RS_KIND_PIXEL_A,
RS_KIND_PIXEL_LA,
RS_KIND_PIXEL_RGB,
RS_KIND_PIXEL_RGBA,
-
};
enum RsSamplerParam {
@@ -205,9 +200,53 @@ enum RsPrimitive {
enum RsError {
RS_ERROR_NONE,
RS_ERROR_BAD_SHADER,
- RS_ERROR_BAD_SCRIPT
+ RS_ERROR_BAD_SCRIPT,
+ RS_ERROR_BAD_VALUE,
+ RS_ERROR_OUT_OF_MEMORY
};
+enum RsAnimationInterpolation {
+ RS_ANIMATION_INTERPOLATION_STEP,
+ RS_ANIMATION_INTERPOLATION_LINEAR,
+ RS_ANIMATION_INTERPOLATION_BEZIER,
+ RS_ANIMATION_INTERPOLATION_CARDINAL,
+ RS_ANIMATION_INTERPOLATION_HERMITE,
+ RS_ANIMATION_INTERPOLATION_BSPLINE
+};
+
+enum RsAnimationEdge {
+ RS_ANIMATION_EDGE_UNDEFINED,
+ RS_ANIMATION_EDGE_CONSTANT,
+ RS_ANIMATION_EDGE_GRADIENT,
+ RS_ANIMATION_EDGE_CYCLE,
+ RS_ANIMATION_EDGE_OSCILLATE,
+ RS_ANIMATION_EDGE_CYLE_RELATIVE
+};
+
+enum RsA3DClassID {
+ RS_A3D_CLASS_ID_UNKNOWN,
+ RS_A3D_CLASS_ID_MESH,
+ RS_A3D_CLASS_ID_SIMPLE_MESH,
+ RS_A3D_CLASS_ID_TYPE,
+ RS_A3D_CLASS_ID_ELEMENT,
+ RS_A3D_CLASS_ID_ALLOCATION,
+ RS_A3D_CLASS_ID_PROGRAM_VERTEX,
+ RS_A3D_CLASS_ID_PROGRAM_RASTER,
+ RS_A3D_CLASS_ID_PROGRAM_FRAGMENT,
+ RS_A3D_CLASS_ID_PROGRAM_STORE,
+ RS_A3D_CLASS_ID_SAMPLER,
+ RS_A3D_CLASS_ID_ANIMATION,
+ RS_A3D_CLASS_ID_LIGHT,
+ RS_A3D_CLASS_ID_ADAPTER_1D,
+ RS_A3D_CLASS_ID_ADAPTER_2D,
+ RS_A3D_CLASS_ID_SCRIPT_C
+};
+
+typedef struct {
+ RsA3DClassID classID;
+ const char* objectName;
+} RsFileIndexEntry;
+
#ifndef NO_RS_FUNCS
#include "rsgApiFuncDecl.h"
#endif
diff --git a/libs/rs/RenderScriptEnv.h b/libs/rs/RenderScriptEnv.h
index 99b8c04..144e539 100644
--- a/libs/rs/RenderScriptEnv.h
+++ b/libs/rs/RenderScriptEnv.h
@@ -12,7 +12,7 @@ typedef void * RsScript;
typedef void * RsSimpleMesh;
typedef void * RsType;
typedef void * RsProgramFragment;
-typedef void * RsProgramFragmentStore;
+typedef void * RsProgramStore;
typedef void * RsLight;
diff --git a/libs/rs/java/Film/src/com/android/film/FilmRS.java b/libs/rs/java/Film/src/com/android/film/FilmRS.java
index 7d04502..93438a0 100644
--- a/libs/rs/java/Film/src/com/android/film/FilmRS.java
+++ b/libs/rs/java/Film/src/com/android/film/FilmRS.java
@@ -213,14 +213,9 @@ public class FilmRS {
Log.e("rs", "Done loading named");
- mStripPositionType = Type.createFromClass(mRS, StripPosition.class, 1);
-
ScriptC.Builder sb = new ScriptC.Builder(mRS);
sb.setScript(mRes, R.raw.filmstrip);
- sb.setRoot(true);
- sb.setType(mStripPositionType, "Pos", 1);
mScriptStrip = sb.create();
- mScriptStrip.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
mAllocPos = Allocation.createTyped(mRS, mStripPositionType);
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
deleted file mode 100644
index 73b819b..0000000
--- a/libs/rs/java/Fountain/res/raw/fountain.c
+++ /dev/null
@@ -1,52 +0,0 @@
-// Fountain test script
-#pragma version(1)
-
-int newPart = 0;
-
-int main(int launchID) {
- int ct;
- int count = Control->count;
- int rate = Control->rate;
- float height = getHeight();
- struct point_s * p = (struct point_s *)point;
-
- if (rate) {
- float rMax = ((float)rate) * 0.005f;
- int x = Control->x;
- int y = Control->y;
- int color = ((int)(Control->r * 255.f)) |
- ((int)(Control->g * 255.f)) << 8 |
- ((int)(Control->b * 255.f)) << 16 |
- (0xf0 << 24);
- struct point_s * np = &p[newPart];
-
- while (rate--) {
- vec2Rand((float *)&np->delta.x, rMax);
- np->position.x = x;
- np->position.y = y;
- np->color = color;
- newPart++;
- np++;
- if (newPart >= count) {
- newPart = 0;
- np = &p[newPart];
- }
- }
- }
-
- for (ct=0; ct < count; ct++) {
- float dy = p->delta.y + 0.15f;
- float posy = p->position.y + dy;
- if ((posy > height) && (dy > 0)) {
- dy *= -0.3f;
- }
- p->delta.y = dy;
- p->position.x += p->delta.x;
- p->position.y = posy;
- p++;
- }
-
- uploadToBufferObject(NAMED_PartBuffer);
- drawSimpleMesh(NAMED_PartMesh);
- return 1;
-}
diff --git a/libs/rs/java/Fountain/res/raw/fountain.rs b/libs/rs/java/Fountain/res/raw/fountain.rs
new file mode 100644
index 0000000..7573398
--- /dev/null
+++ b/libs/rs/java/Fountain/res/raw/fountain.rs
@@ -0,0 +1,77 @@
+// Fountain test script
+#pragma version(1)
+
+#include "../../../../scriptc/rs_types.rsh"
+#include "../../../../scriptc/rs_math.rsh"
+#include "../../../../scriptc/rs_graphics.rsh"
+
+static int newPart = 0;
+
+float4 partColor;
+rs_mesh partMesh;
+
+typedef struct __attribute__((packed, aligned(4))) Point_s {
+ float2 delta;
+ float2 position;
+ uchar4 color;
+} Point_t;
+Point_t *point;
+
+#pragma rs export_var(point, partColor, partMesh)
+
+int root() {
+ rsgClearColor(0.f, 0.f, 0.f, 1.f);
+ float height = rsgGetHeight();
+ rs_allocation alloc = rsGetAllocation(point);
+ int size = rsAllocationGetDimX(alloc);
+
+ Point_t * p = point;
+ for (int ct=0; ct < size; ct++) {
+ p->delta.y += 0.15f;
+ p->position += p->delta;
+ if ((p->position.y > height) && (p->delta.y > 0)) {
+ p->delta.y *= -0.3f;
+ }
+ p++;
+ }
+
+ rsgUploadToBufferObject(alloc);
+ rsgDrawSimpleMesh(partMesh);
+ return 1;
+}
+
+#pragma rs export_func(addParticles)
+
+void addParticles(int rate, int x, int y)
+{
+ //rsDebug("partColor", partColor);
+ //rsDebug("partColor x", partColor.x);
+ //rsDebug("partColor y", partColor.y);
+ //rsDebug("partColor z", partColor.z);
+ //rsDebug("partColor w", partColor.w);
+
+ float rMax = ((float)rate) * 0.005f;
+ int size = rsAllocationGetDimX(rsGetAllocation(point));
+
+ uchar4 c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z);
+
+ //rsDebug("color ", ((int *)&c)[0]);
+ Point_t * np = &point[newPart];
+
+ float2 p = {x, y};
+ while (rate--) {
+ float angle = rsRand(3.14f * 2.f);
+ float len = rsRand(rMax);
+ np->delta.x = len * sin(angle);
+ np->delta.y = len * cos(angle);
+ np->position = p;
+ np->color = c;
+ newPart++;
+ np++;
+ if (newPart >= size) {
+ newPart = 0;
+ np = &point[newPart];
+ }
+ }
+}
+
diff --git a/libs/rs/java/Fountain/res/raw/fountain2.rs b/libs/rs/java/Fountain/res/raw/fountain2.rs
deleted file mode 100644
index 3301140..0000000
--- a/libs/rs/java/Fountain/res/raw/fountain2.rs
+++ /dev/null
@@ -1,73 +0,0 @@
-// Fountain test script
-#pragma version(1)
-
-#include "rs_types.rsh"
-#include "rs_math.rsh"
-#include "rs_graphics.rsh"
-
-static int newPart = 0;
-
-typedef struct Control_s {
- int x, y;
- int rate;
- int count;
- float r, g, b;
- rs_allocation partBuffer;
- rs_mesh partMesh;
-} Control_t;
-Control_t *Control;
-
-typedef struct Point_s{
- float2 delta;
- float2 position;
- unsigned int color;
-} Point_t;
-Point_t *point;
-
-int main(int launchID) {
- int ct;
- int count = Control->count;
- int rate = Control->rate;
- float height = getHeight();
- Point_t * p = point;
-
- if (rate) {
- float rMax = ((float)rate) * 0.005f;
- int x = Control->x;
- int y = Control->y;
- int color = ((int)(Control->r * 255.f)) |
- ((int)(Control->g * 255.f)) << 8 |
- ((int)(Control->b * 255.f)) << 16 |
- (0xf0 << 24);
- Point_t * np = &p[newPart];
-
- while (rate--) {
- np->delta = vec2Rand(rMax);
- np->position.x = x;
- np->position.y = y;
- np->color = color;
- newPart++;
- np++;
- if (newPart >= count) {
- newPart = 0;
- np = &p[newPart];
- }
- }
- }
-
- for (ct=0; ct < count; ct++) {
- float dy = p->delta.y + 0.15f;
- float posy = p->position.y + dy;
- if ((posy > height) && (dy > 0)) {
- dy *= -0.3f;
- }
- p->delta.y = dy;
- p->position.x += p->delta.x;
- p->position.y = posy;
- p++;
- }
-
- uploadToBufferObject(Control->partBuffer);
- drawSimpleMesh(Control->partMesh);
- return 1;
-}
diff --git a/libs/rs/java/Fountain/res/raw/fountain_bc.bc b/libs/rs/java/Fountain/res/raw/fountain_bc.bc
new file mode 100644
index 0000000..b01098b
--- /dev/null
+++ b/libs/rs/java/Fountain/res/raw/fountain_bc.bc
Binary files differ
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
index 9356579..5433597 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -24,92 +24,48 @@ import android.util.Log;
public class FountainRS {
public static final int PART_COUNT = 20000;
- static class SomeData {
- public int x;
- public int y;
- public int rate;
- public int count;
- public float r;
- public float g;
- public float b;
- }
-
public FountainRS() {
}
+ private Resources mRes;
+ private RenderScriptGL mRS;
+ private ScriptC_Fountain mScript;
public void init(RenderScriptGL rs, Resources res, int width, int height) {
mRS = rs;
mRes = res;
- initRS();
- }
-
- public void newTouchPosition(int x, int y, int rate) {
- if (mSD.rate == 0) {
- mSD.r = ((x & 0x1) != 0) ? 0.f : 1.f;
- mSD.g = ((x & 0x2) != 0) ? 0.f : 1.f;
- mSD.b = ((x & 0x4) != 0) ? 0.f : 1.f;
- if ((mSD.r + mSD.g + mSD.b) < 0.9f) {
- mSD.r = 0.8f;
- mSD.g = 0.5f;
- mSD.b = 1.f;
- }
- }
- mSD.rate = rate;
- mSD.x = x;
- mSD.y = y;
- mIntAlloc.data(mSD);
- }
-
-
- /////////////////////////////////////////
-
- private Resources mRes;
-
- private RenderScriptGL mRS;
- private Allocation mIntAlloc;
- private SimpleMesh mSM;
- private SomeData mSD;
- private Type mSDType;
-
- private void initRS() {
- mSD = new SomeData();
- mSDType = Type.createFromClass(mRS, SomeData.class, 1, "SomeData");
- mIntAlloc = Allocation.createTyped(mRS, mSDType);
- mSD.count = PART_COUNT;
- mIntAlloc.data(mSD);
-
- Element.Builder eb = new Element.Builder(mRS);
- eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 2), "delta");
- eb.add(Element.createAttrib(mRS, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "position");
- eb.add(Element.createAttrib(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.COLOR, 4), "color");
- Element primElement = eb.create();
+ ScriptField_Point_s points = new ScriptField_Point_s(mRS, PART_COUNT);
SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS);
- int vtxSlot = smb.addVertexType(primElement, PART_COUNT);
+ int vtxSlot = smb.addVertexType(points.getType());
smb.setPrimitive(Primitive.POINT);
- mSM = smb.create();
- mSM.setName("PartMesh");
+ SimpleMesh sm = smb.create();
+ sm.bindVertexAllocation(points.getAllocation(), vtxSlot);
- Allocation partAlloc = mSM.createVertexAllocation(vtxSlot);
- partAlloc.setName("PartBuffer");
- mSM.bindVertexAllocation(partAlloc, 0);
+ mScript = new ScriptC_Fountain(mRS, mRes, true);
+ mScript.set_partMesh(sm);
+ mScript.bind_point(points);
+ mRS.contextBindRootScript(mScript);
+ }
- // All setup of named objects should be done by this point
- // because we are about to compile the script.
- ScriptC.Builder sb = new ScriptC.Builder(mRS);
- sb.setScript(mRes, R.raw.fountain);
- sb.setRoot(true);
- sb.setType(mSDType, "Control", 0);
- sb.setType(mSM.getVertexType(0), "point", 1);
- Script script = sb.create();
- script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ Float4 tmpColor = new Float4();
+ boolean holdingColor = false;
+ java.util.Random mRand = new java.util.Random();
+ public void newTouchPosition(int x, int y, int rate) {
+ if (rate > 0) {
+ if (!holdingColor) {
+ tmpColor.x = mRand.nextFloat() * 0.5f + 0.5f;
+ tmpColor.y = mRand.nextFloat();
+ tmpColor.z = mRand.nextFloat();
+ mScript.set_partColor(tmpColor);
+ }
+ mScript.invoke_addParticles(rate, x, y);
+ holdingColor = true;
+ } else {
+ holdingColor = false;
+ }
- script.bindAllocation(mIntAlloc, 0);
- script.bindAllocation(partAlloc, 1);
- mRS.contextBindRootScript(script);
}
-
}
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/ScriptC_Fountain.java b/libs/rs/java/Fountain/src/com/android/fountain/ScriptC_Fountain.java
new file mode 100644
index 0000000..f6bef27
--- /dev/null
+++ b/libs/rs/java/Fountain/src/com/android/fountain/ScriptC_Fountain.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package com.android.fountain;
+
+import android.renderscript.*;
+import android.content.res.Resources;
+import android.util.Log;
+
+public class ScriptC_Fountain extends ScriptC {
+ // Constructor
+ public ScriptC_Fountain(RenderScript rs, Resources resources, boolean isRoot) {
+ super(rs, resources, R.raw.fountain_bc, isRoot);
+ }
+
+ private final static int mExportVarIdx_partColor = 0;
+ private Float4 mExportVar_partColor;
+ public void set_partColor(Float4 v) {
+ mExportVar_partColor = v;
+ FieldPacker fp = new FieldPacker(16);
+ fp.addF32(v);
+ setVar(mExportVarIdx_partColor, fp);
+ }
+
+ public Float4 get_partColor() {
+ return mExportVar_partColor;
+ }
+
+ private final static int mExportVarIdx_partMesh = 1;
+ private SimpleMesh mExportVar_partMesh;
+ public void set_partMesh(SimpleMesh v) {
+ mExportVar_partMesh = v;
+ int id = 0;
+ if (v != null) id = v.getID();
+ setVar(mExportVarIdx_partMesh, id);
+ }
+
+ public SimpleMesh get_partMesh() {
+ return mExportVar_partMesh;
+ }
+
+ private final static int mExportVarIdx_point = 2;
+ private ScriptField_Point_s mExportVar_point;
+ public void bind_point(ScriptField_Point_s v) {
+ mExportVar_point = v;
+ if(v == null) bindAllocation(null, mExportVarIdx_point);
+ else bindAllocation(v.getAllocation(), mExportVarIdx_point);
+ }
+
+ public ScriptField_Point_s get_point() {
+ return mExportVar_point;
+ }
+
+ private final static int mExportFuncIdx_addParticles = 0;
+ public void invoke_addParticles(int rate, int x, int y) {
+ FieldPacker addParticles_fp = new FieldPacker(12);
+ addParticles_fp.addI32(rate);
+ addParticles_fp.addI32(x);
+ addParticles_fp.addI32(y);
+ invokeV(mExportFuncIdx_addParticles, addParticles_fp);
+ }
+
+}
+
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point_s.java b/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point_s.java
new file mode 100644
index 0000000..9697a4d
--- /dev/null
+++ b/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point_s.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package com.android.fountain;
+
+import android.renderscript.*;
+import android.content.res.Resources;
+import android.util.Log;
+
+public class ScriptField_Point_s extends android.renderscript.Script.FieldBase {
+ static public class Item {
+ public static final int sizeof = 20;
+
+ Float2 delta;
+ Float2 position;
+ Short4 color;
+
+ Item() {
+ delta = new Float2();
+ position = new Float2();
+ color = new Short4();
+ }
+
+ }
+
+ private Item mItemArray[];
+ private FieldPacker mIOBuffer;
+ public ScriptField_Point_s(RenderScript rs, int count) {
+ mItemArray = null;
+ mIOBuffer = null;
+ {
+ Element.Builder eb = new Element.Builder(rs);
+ eb.add(Element.createVector(rs, Element.DataType.FLOAT_32, 2), "delta");
+ eb.add(Element.createVector(rs, Element.DataType.FLOAT_32, 2), "position");
+ eb.add(Element.createVector(rs, Element.DataType.UNSIGNED_8, 4), "color");
+ mElement = eb.create();
+ }
+
+ init(rs, count);
+ }
+
+ private void copyToArray(Item i, int index) {
+ if (mIOBuffer == null) mIOBuffer = new FieldPacker(Item.sizeof * mType.getX() /* count */);
+ mIOBuffer.reset(index * Item.sizeof);
+ mIOBuffer.addF32(i.delta);
+ mIOBuffer.addF32(i.position);
+ mIOBuffer.addU8(i.color);
+ }
+
+ public void set(Item i, int index, boolean copyNow) {
+ if (mItemArray == null) mItemArray = new Item[mType.getX() /* count */];
+ mItemArray[index] = i;
+ if (copyNow) {
+ copyToArray(i, index);
+ mAllocation.subData1D(index * Item.sizeof, Item.sizeof, mIOBuffer.getData());
+ }
+
+ }
+
+ public void copyAll() {
+ for (int ct=0; ct < mItemArray.length; ct++) copyToArray(mItemArray[ct], ct);
+ mAllocation.data(mIOBuffer.getData());
+ }
+
+}
+
diff --git a/libs/rs/java/ImageProcessing/AndroidManifest.xml b/libs/rs/java/ImageProcessing/AndroidManifest.xml
index b48d208..d6a2db4 100644
--- a/libs/rs/java/ImageProcessing/AndroidManifest.xml
+++ b/libs/rs/java/ImageProcessing/AndroidManifest.xml
@@ -6,7 +6,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="Image Processing">
- <activity android:name="ImageProcessingActivity">
+ <activity android:name="ImageProcessingActivity"
+ android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
diff --git a/libs/rs/java/ImageProcessing/res/layout/main.xml b/libs/rs/java/ImageProcessing/res/layout/main.xml
index 6770c18..c6ec729 100644
--- a/libs/rs/java/ImageProcessing/res/layout/main.xml
+++ b/libs/rs/java/ImageProcessing/res/layout/main.xml
@@ -25,9 +25,147 @@
android:id="@+id/display"
android:layout_width="320dip"
android:layout_height="266dip" />
-
+
+ <Button
+ android:layout_marginBottom="170dip"
+ android:layout_width="wrap_content"
+ android:layout_height="40dip"
+ android:text="@string/benchmark"
+ android:onClick="benchmark"
+ android:layout_gravity="bottom"/>
+
+ <TextView
+ android:id="@+id/benchmarkText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="18sp"
+ android:layout_marginLeft="100dip"
+ android:layout_marginBottom="175dip"
+ android:layout_gravity="bottom"
+ android:text="@string/saturation"/>
+
+ <SeekBar
+ android:id="@+id/inSaturation"
+ android:layout_marginBottom="140dip"
+ android:layout_marginLeft="10dip"
+ android:layout_marginRight="10dip"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom" />
+
+ <TextView
+ android:id="@+id/inSaturationText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="18sp"
+ android:layout_marginLeft="50dip"
+ android:layout_marginBottom="142dip"
+ android:textColor="#000"
+ android:layout_gravity="bottom"
+ android:text="@string/saturation"/>
+
+ <SeekBar
+ android:id="@+id/inGamma"
+ android:layout_marginBottom="110dip"
+ android:layout_marginLeft="10dip"
+ android:layout_marginRight="10dip"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom" />
+
+ <TextView
+ android:id="@+id/inGammaText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="18sp"
+ android:layout_marginLeft="50dip"
+ android:layout_marginBottom="112dip"
+ android:textColor="#000"
+ android:layout_gravity="bottom"
+ android:text="@string/gamma"/>
+
<SeekBar
- android:id="@+id/threshold"
+ android:id="@+id/outWhite"
+ android:layout_marginBottom="80dip"
+ android:layout_marginLeft="170dip"
+ android:layout_marginRight="10dip"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom" />
+
+ <TextView
+ android:id="@+id/outWhiteText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="18sp"
+ android:layout_marginLeft="220dip"
+ android:layout_marginBottom="82dip"
+ android:textColor="#000"
+ android:layout_gravity="bottom"
+ android:text="@string/out_white"/>
+
+ <SeekBar
+ android:id="@+id/inWhite"
+ android:layout_marginBottom="80dip"
+ android:layout_marginLeft="10dip"
+ android:layout_marginRight="170dip"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom" />
+
+ <TextView
+ android:id="@+id/inWhiteText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="18sp"
+ android:layout_marginLeft="50dip"
+ android:layout_marginBottom="82dip"
+ android:textColor="#000"
+ android:layout_gravity="bottom"
+ android:text="@string/in_white"/>
+
+ <SeekBar
+ android:id="@+id/outBlack"
+ android:layout_marginBottom="50dip"
+ android:layout_marginLeft="170dip"
+ android:layout_marginRight="10dip"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom" />
+
+ <TextView
+ android:id="@+id/outBlackText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="18sp"
+ android:layout_marginLeft="220dip"
+ android:layout_marginBottom="52dip"
+ android:textColor="#000"
+ android:layout_gravity="bottom"
+ android:text="@string/out_black"/>
+
+ <SeekBar
+ android:id="@+id/inBlack"
+ android:layout_marginBottom="50dip"
+ android:layout_marginLeft="10dip"
+ android:layout_marginRight="170dip"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom" />
+
+ <TextView
+ android:id="@+id/inBlackText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="18sp"
+ android:layout_marginLeft="50dip"
+ android:layout_marginBottom="52dip"
+ android:textColor="#000"
+ android:layout_gravity="bottom"
+ android:text="@string/in_black"/>
+
+ <SeekBar
+ android:id="@+id/radius"
android:layout_marginBottom="10dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
@@ -35,4 +173,15 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
+ <TextView
+ android:id="@+id/blurText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="18sp"
+ android:layout_marginLeft="50dip"
+ android:layout_marginBottom="12dip"
+ android:textColor="#000"
+ android:layout_gravity="bottom"
+ android:text="@string/blur_description"/>
+
</merge> \ No newline at end of file
diff --git a/libs/rs/java/ImageProcessing/res/raw/threshold.rs b/libs/rs/java/ImageProcessing/res/raw/threshold.rs
index 888f0cd..6af4012 100644
--- a/libs/rs/java/ImageProcessing/res/raw/threshold.rs
+++ b/libs/rs/java/ImageProcessing/res/raw/threshold.rs
@@ -1,62 +1,333 @@
-/*
-// block of defines matching what RS will insert at runtime.
-struct Params_s{
- int inHeight;
- int inWidth;
- int outHeight;
- int outWidth;
- float threshold;
-};
-struct Params_s * Params;
-struct InPixel_s{
- char a;
- char b;
- char g;
- char r;
-};
-struct InPixel_s * InPixel;
-struct OutPixel_s{
- char a;
- char b;
- char g;
- char r;
-};
-struct OutPixel_s * OutPixel;
-*/
-
-struct color_s {
- char b;
- char g;
- char r;
- char a;
-};
-
-void main() {
- int t = uptimeMillis();
-
- struct color_s *in = (struct color_s *) InPixel;
- struct color_s *out = (struct color_s *) OutPixel;
-
- int count = Params->inWidth * Params->inHeight;
- int i;
- float threshold = (Params->threshold * 255.f);
-
- for (i = 0; i < count; i++) {
- float luminance = 0.2125f * in->r +
- 0.7154f * in->g +
- 0.0721f * in->b;
- if (luminance > threshold) {
- *out = *in;
- } else {
- *((int *)out) = *((int *)in) & 0xff000000;
+#pragma version(1)
+
+#include "../../../../scriptc/rs_types.rsh"
+#include "../../../../scriptc/rs_math.rsh"
+#include "../../../../scriptc/rs_graphics.rsh"
+
+#define MAX_RADIUS 25
+
+int height;
+int width;
+int radius;
+
+typedef struct c4u_s {
+ uint8_t r, g, b, a;
+} c4u_t;
+
+c4u_t * InPixel;
+c4u_t * OutPixel;
+c4u_t * ScratchPixel;
+
+float inBlack;
+float outBlack;
+float inWhite;
+float outWhite;
+float gamma;
+
+float saturation;
+
+float inWMinInB;
+float outWMinOutB;
+
+#pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation)
+#pragma rs export_func(filter, processNoBlur, computeColorMatrix, computeGaussianWeights);
+
+// Store our coefficients here
+float gaussian[MAX_RADIUS * 2 + 1];
+float colorMat[4][4];
+
+void computeColorMatrix() {
+ // Saturation
+ // Linear weights
+ //float rWeight = 0.3086f;
+ //float gWeight = 0.6094f;
+ //float bWeight = 0.0820f;
+
+ // Gamma 2.2 weights (we haven't converted our image to linear space yet for perf reasons)
+ float rWeight = 0.299f;
+ float gWeight = 0.587f;
+ float bWeight = 0.114f;
+
+ float oneMinusS = 1.0f - saturation;
+
+ rsMatrixLoadIdentity((rs_matrix4x4 *)colorMat);
+
+ colorMat[0][0] = oneMinusS * rWeight + saturation;
+ colorMat[0][1] = oneMinusS * rWeight;
+ colorMat[0][2] = oneMinusS * rWeight;
+ colorMat[1][0] = oneMinusS * gWeight;
+ colorMat[1][1] = oneMinusS * gWeight + saturation;
+ colorMat[1][2] = oneMinusS * gWeight;
+ colorMat[2][0] = oneMinusS * bWeight;
+ colorMat[2][1] = oneMinusS * bWeight;
+ colorMat[2][2] = oneMinusS * bWeight + saturation;
+
+ inWMinInB = inWhite - inBlack;
+ outWMinOutB = outWhite - outBlack;
+}
+
+void computeGaussianWeights() {
+ // Compute gaussian weights for the blur
+ // e is the euler's number
+ float e = 2.718281828459045f;
+ float pi = 3.1415926535897932f;
+ // g(x) = ( 1 / sqrt( 2 * pi ) * sigma) * e ^ ( -x^2 / 2 * sigma^2 )
+ // x is of the form [-radius .. 0 .. radius]
+ // and sigma varies with radius.
+ // Based on some experimental radius values and sigma's
+ // we approximately fit sigma = f(radius) as
+ // sigma = radius * 0.4 + 0.6
+ // The larger the radius gets, the more our gaussian blur
+ // will resemble a box blur since with large sigma
+ // the gaussian curve begins to lose its shape
+ float sigma = 0.4f * (float)radius + 0.6f;
+
+ // Now compute the coefficints
+ // We will store some redundant values to save some math during
+ // the blur calculations
+ // precompute some values
+ float coeff1 = 1.0f / (sqrt( 2.0f * pi ) * sigma);
+ float coeff2 = - 1.0f / (2.0f * sigma * sigma);
+
+ float normalizeFactor = 0.0f;
+ float floatR = 0.0f;
+ int r;
+ for(r = -radius; r <= radius; r ++) {
+ floatR = (float)r;
+ gaussian[r + radius] = coeff1 * pow(e, floatR * floatR * coeff2);
+ normalizeFactor += gaussian[r + radius];
+ }
+
+ //Now we need to normalize the weights because all our coefficients need to add up to one
+ normalizeFactor = 1.0f / normalizeFactor;
+ for(r = -radius; r <= radius; r ++) {
+ floatR = (float)r;
+ gaussian[r + radius] *= normalizeFactor;
+ }
+}
+
+// This needs to be inline
+void levelsSaturation(float4 *currentPixel) {
+ // Color matrix multiply
+ float tempX = colorMat[0][0] * currentPixel->x + colorMat[1][0] * currentPixel->y + colorMat[2][0] * currentPixel->z;
+ float tempY = colorMat[0][1] * currentPixel->x + colorMat[1][1] * currentPixel->y + colorMat[2][1] * currentPixel->z;
+ float tempZ = colorMat[0][2] * currentPixel->x + colorMat[1][2] * currentPixel->y + colorMat[2][2] * currentPixel->z;
+
+ currentPixel->x = tempX;
+ currentPixel->y = tempY;
+ currentPixel->z = tempZ;
+
+ // Clamp to 0..255
+ // Inline the code here to avoid funciton calls
+ currentPixel->x = currentPixel->x > 255.0f ? 255.0f : currentPixel->x;
+ currentPixel->y = currentPixel->y > 255.0f ? 255.0f : currentPixel->y;
+ currentPixel->z = currentPixel->z > 255.0f ? 255.0f : currentPixel->z;
+
+ currentPixel->x = currentPixel->x <= 0.0f ? 0.1f : currentPixel->x;
+ currentPixel->y = currentPixel->y <= 0.0f ? 0.1f : currentPixel->y;
+ currentPixel->z = currentPixel->z <= 0.0f ? 0.1f : currentPixel->z;
+
+ currentPixel->x = pow( (currentPixel->x - inBlack) / (inWMinInB), gamma) * (outWMinOutB) + outBlack;
+ currentPixel->y = pow( (currentPixel->y - inBlack) / (inWMinInB), gamma) * (outWMinOutB) + outBlack;
+ currentPixel->z = pow( (currentPixel->z - inBlack) / (inWMinInB), gamma) * (outWMinOutB) + outBlack;
+
+ currentPixel->x = currentPixel->x > 255.0f ? 255.0f : currentPixel->x;
+ currentPixel->y = currentPixel->y > 255.0f ? 255.0f : currentPixel->y;
+ currentPixel->z = currentPixel->z > 255.0f ? 255.0f : currentPixel->z;
+
+ currentPixel->x = currentPixel->x <= 0.0f ? 0.1f : currentPixel->x;
+ currentPixel->y = currentPixel->y <= 0.0f ? 0.1f : currentPixel->y;
+ currentPixel->z = currentPixel->z <= 0.0f ? 0.1f : currentPixel->z;
+}
+
+void processNoBlur() {
+ int w, h, r;
+ int count = 0;
+
+ float inWMinInB = inWhite - inBlack;
+ float outWMinOutB = outWhite - outBlack;
+ float4 currentPixel = 0;
+
+ for(h = 0; h < height; h ++) {
+ for(w = 0; w < width; w ++) {
+ c4u_t *input = InPixel + h*width + w;
+
+ currentPixel.x = (float)(input->r);
+ currentPixel.y = (float)(input->g);
+ currentPixel.z = (float)(input->b);
+
+ levelsSaturation(&currentPixel);
+
+ c4u_t *output = OutPixel + h*width + w;
+ output->r = (uint8_t)currentPixel.x;
+ output->g = (uint8_t)currentPixel.y;
+ output->b = (uint8_t)currentPixel.z;
+ output->a = input->a;
}
+ }
+ rsSendToClient(&count, 1, 4, 0);
+}
+
+void horizontalBlur() {
+ float4 blurredPixel = 0;
+ float4 currentPixel = 0;
+ // Horizontal blur
+ int w, h, r;
+ for(h = 0; h < height; h ++) {
+ for(w = 0; w < width; w ++) {
- in++;
- out++;
+ blurredPixel = 0;
+
+ for(r = -radius; r <= radius; r ++) {
+ // Stepping left and right away from the pixel
+ int validW = w + r;
+ // Clamp to zero and width max() isn't exposed for ints yet
+ if(validW < 0) {
+ validW = 0;
+ }
+ if(validW > width - 1) {
+ validW = width - 1;
+ }
+
+ c4u_t *input = InPixel + h*width + validW;
+
+ float weight = gaussian[r + radius];
+ currentPixel.x = (float)(input->r);
+ currentPixel.y = (float)(input->g);
+ currentPixel.z = (float)(input->b);
+ //currentPixel.w = (float)(input->a);
+
+ blurredPixel += currentPixel*weight;
+ }
+
+ c4u_t *output = ScratchPixel + h*width + w;
+ output->r = (uint8_t)blurredPixel.x;
+ output->g = (uint8_t)blurredPixel.y;
+ output->b = (uint8_t)blurredPixel.z;
+ //output->a = (uint8_t)blurredPixel.w;
+ }
+ }
+}
+
+void horizontalBlurLevels() {
+ float4 blurredPixel = 0;
+ float4 currentPixel = 0;
+ // Horizontal blur
+ int w, h, r;
+ for(h = 0; h < height; h ++) {
+ for(w = 0; w < width; w ++) {
+
+ blurredPixel = 0;
+
+ for(r = -radius; r <= radius; r ++) {
+ // Stepping left and right away from the pixel
+ int validW = w + r;
+ // Clamp to zero and width max() isn't exposed for ints yet
+ if(validW < 0) {
+ validW = 0;
+ }
+ if(validW > width - 1) {
+ validW = width - 1;
+ }
+
+ c4u_t *input = InPixel + h*width + validW;
+
+ float weight = gaussian[r + radius];
+ currentPixel.x = (float)(input->r);
+ currentPixel.y = (float)(input->g);
+ currentPixel.z = (float)(input->b);
+ //currentPixel.w = (float)(input->a);
+
+ blurredPixel += currentPixel*weight;
+ }
+
+ levelsSaturation(&blurredPixel);
+
+ c4u_t *output = ScratchPixel + h*width + w;
+ output->r = (uint8_t)blurredPixel.x;
+ output->g = (uint8_t)blurredPixel.y;
+ output->b = (uint8_t)blurredPixel.z;
+ //output->a = (uint8_t)blurredPixel.w;
+ }
+ }
+}
+
+void verticalBlur() {
+ float4 blurredPixel = 0;
+ float4 currentPixel = 0;
+ // Vertical blur
+ int w, h, r;
+ for(h = 0; h < height; h ++) {
+ for(w = 0; w < width; w ++) {
+
+ blurredPixel = 0;
+ for(r = -radius; r <= radius; r ++) {
+ int validH = h + r;
+ // Clamp to zero and width
+ if(validH < 0) {
+ validH = 0;
+ }
+ if(validH > height - 1) {
+ validH = height - 1;
+ }
+
+ c4u_t *input = ScratchPixel + validH*width + w;
+
+ float weight = gaussian[r + radius];
+
+ currentPixel.x = (float)(input->r);
+ currentPixel.y = (float)(input->g);
+ currentPixel.z = (float)(input->b);
+ //currentPixel.w = (float)(input->a);
+
+ blurredPixel += currentPixel*weight;
+ }
+
+ c4u_t *output = OutPixel + h*width + w;
+
+ output->r = (uint8_t)blurredPixel.x;
+ output->g = (uint8_t)blurredPixel.y;
+ output->b = (uint8_t)blurredPixel.z;
+ //output->a = (uint8_t)blurredPixel.w;
+ }
+ }
+}
+
+void filter() {
+ RS_DEBUG(height);
+ RS_DEBUG(width);
+ RS_DEBUG(radius);
+ RS_DEBUG(inBlack);
+ RS_DEBUG(outBlack);
+ RS_DEBUG(inWhite);
+ RS_DEBUG(outWhite);
+ RS_DEBUG(gamma);
+ RS_DEBUG(saturation);
+
+ computeColorMatrix();
+
+ if(radius == 0) {
+ processNoBlur();
+ return;
}
- t= uptimeMillis() - t;
- debugI32("Filter time", t);
+ computeGaussianWeights();
+
+ horizontalBlurLevels();
+ verticalBlur();
+
+ int count = 0;
+ rsSendToClient(&count, 1, 4, 0);
+}
+
+void filterBenchmark() {
+
+ computeGaussianWeights();
- sendToClient(&count, 1, 4, 0);
+ horizontalBlur();
+ verticalBlur();
+
+ int count = 0;
+ rsSendToClient(&count, 1, 4, 0);
}
+
diff --git a/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc b/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc
new file mode 100644
index 0000000..29eba2d
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc
Binary files differ
diff --git a/libs/rs/java/ImageProcessing/res/values/strings.xml b/libs/rs/java/ImageProcessing/res/values/strings.xml
new file mode 100644
index 0000000..cc5cc4d
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/res/values/strings.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+* Copyright (C) 2008 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.
+*/
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- General -->
+ <skip />
+ <!--slider label -->
+ <string name="blur_description">Blur Radius</string>
+ <string name="in_white">In White</string>
+ <string name="out_white">Out White</string>
+ <string name="in_black">In Black</string>
+ <string name="out_black">Out Black</string>
+ <string name="gamma">Gamma</string>
+ <string name="saturation">Saturation</string>
+ <string name="benchmark">Benchmark</string>
+
+</resources>
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
index 9ce53d8..5e36a78 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
@@ -31,53 +31,53 @@ import android.view.SurfaceView;
import android.view.SurfaceHolder;
import android.widget.ImageView;
import android.widget.SeekBar;
+import android.widget.TextView;
+import android.view.View;
import java.lang.Math;
-public class ImageProcessingActivity extends Activity implements SurfaceHolder.Callback {
- private Bitmap mBitmap;
- private Params mParams;
- private Script.Invokable mInvokable;
- private int[] mInData;
- private int[] mOutData;
+public class ImageProcessingActivity extends Activity
+ implements SurfaceHolder.Callback,
+ SeekBar.OnSeekBarChangeListener {
+ private Bitmap mBitmapIn;
+ private Bitmap mBitmapOut;
+ private Bitmap mBitmapScratch;
+ private ScriptC_Threshold mScript;
+ private int mRadius = 0;
+ private SeekBar mRadiusSeekBar;
+
+ private float mInBlack = 0.0f;
+ private SeekBar mInBlackSeekBar;
+ private float mOutBlack = 0.0f;
+ private SeekBar mOutBlackSeekBar;
+ private float mInWhite = 255.0f;
+ private SeekBar mInWhiteSeekBar;
+ private float mOutWhite = 255.0f;
+ private SeekBar mOutWhiteSeekBar;
+ private float mGamma = 1.0f;
+ private SeekBar mGammaSeekBar;
+
+ private float mSaturation = 1.0f;
+ private SeekBar mSaturationSeekBar;
+
+ private TextView mBenchmarkResult;
@SuppressWarnings({"FieldCanBeLocal"})
private RenderScript mRS;
@SuppressWarnings({"FieldCanBeLocal"})
- private Type mParamsType;
- @SuppressWarnings({"FieldCanBeLocal"})
- private Allocation mParamsAllocation;
- @SuppressWarnings({"FieldCanBeLocal"})
private Type mPixelType;
@SuppressWarnings({"FieldCanBeLocal"})
private Allocation mInPixelsAllocation;
@SuppressWarnings({"FieldCanBeLocal"})
private Allocation mOutPixelsAllocation;
+ @SuppressWarnings({"FieldCanBeLocal"})
+ private Allocation mScratchPixelsAllocation;
private SurfaceView mSurfaceView;
private ImageView mDisplayView;
- static class Params {
- public int inWidth;
- public int outWidth;
- public int inHeight;
- public int outHeight;
-
- public float threshold;
- }
-
- static class Pixel {
- public byte a;
- public byte r;
- public byte g;
- public byte b;
- }
-
class FilterCallback extends RenderScript.RSMessage {
private Runnable mAction = new Runnable() {
public void run() {
- mOutPixelsAllocation.readData(mOutData);
- mBitmap.setPixels(mOutData, 0, mParams.outWidth, 0, 0,
- mParams.outWidth, mParams.outHeight);
mDisplayView.invalidate();
}
};
@@ -89,29 +89,218 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
}
}
- private void javaFilter() {
+ int in[];
+ int interm[];
+ int out[];
+ int MAX_RADIUS = 25;
+ // Store our coefficients here
+ float gaussian[];
+
+ private long javaFilter() {
+ final int width = mBitmapIn.getWidth();
+ final int height = mBitmapIn.getHeight();
+ final int count = width * height;
+
+ if (in == null) {
+ in = new int[count];
+ interm = new int[count];
+ out = new int[count];
+ gaussian = new float[MAX_RADIUS * 2 + 1];
+ mBitmapIn.getPixels(in, 0, width, 0, 0, width, height);
+ }
+
long t = java.lang.System.currentTimeMillis();
- int count = mParams.inWidth * mParams.inHeight;
- float threshold = mParams.threshold * 255.f;
-
- for (int i = 0; i < count; i++) {
- final float r = (float)((mInData[i] >> 0) & 0xff);
- final float g = (float)((mInData[i] >> 8) & 0xff);
- final float b = (float)((mInData[i] >> 16) & 0xff);
-
- final float luminance = 0.2125f * r +
- 0.7154f * g +
- 0.0721f * b;
- if (luminance > threshold) {
- mOutData[i] = mInData[i];
- } else {
- mOutData[i] = mInData[i] & 0xff000000;
+
+ int w, h, r;
+
+ float fRadius = (float)mRadius;
+ int radius = (int)mRadius;
+
+ // Compute gaussian weights for the blur
+ // e is the euler's number
+ float e = 2.718281828459045f;
+ float pi = 3.1415926535897932f;
+ // g(x) = ( 1 / sqrt( 2 * pi ) * sigma) * e ^ ( -x^2 / 2 * sigma^2 )
+ // x is of the form [-radius .. 0 .. radius]
+ // and sigma varies with radius.
+ // Based on some experimental radius values and sigma's
+ // we approximately fit sigma = f(radius) as
+ // sigma = radius * 0.4 + 0.6
+ // The larger the radius gets, the more our gaussian blur
+ // will resemble a box blur since with large sigma
+ // the gaussian curve begins to lose its shape
+ float sigma = 0.4f * fRadius + 0.6f;
+ // Now compute the coefficints
+ // We will store some redundant values to save some math during
+ // the blur calculations
+ // precompute some values
+ float coeff1 = 1.0f / (float)(Math.sqrt( 2.0f * pi ) * sigma);
+ float coeff2 = - 1.0f / (2.0f * sigma * sigma);
+ float normalizeFactor = 0.0f;
+ float floatR = 0.0f;
+ for(r = -radius; r <= radius; r ++) {
+ floatR = (float)r;
+ gaussian[r + radius] = coeff1 * (float)Math.pow(e, floatR * floatR * coeff2);
+ normalizeFactor += gaussian[r + radius];
+ }
+
+ //Now we need to normalize the weights because all our coefficients need to add up to one
+ normalizeFactor = 1.0f / normalizeFactor;
+ for(r = -radius; r <= radius; r ++) {
+ floatR = (float)r;
+ gaussian[r + radius] *= normalizeFactor;
+ }
+
+ float blurredPixelR = 0.0f;
+ float blurredPixelG = 0.0f;
+ float blurredPixelB = 0.0f;
+ float blurredPixelA = 0.0f;
+
+ for(h = 0; h < height; h ++) {
+ for(w = 0; w < width; w ++) {
+
+ blurredPixelR = 0.0f;
+ blurredPixelG = 0.0f;
+ blurredPixelB = 0.0f;
+ blurredPixelA = 0.0f;
+
+ for(r = -radius; r <= radius; r ++) {
+ // Stepping left and right away from the pixel
+ int validW = w + r;
+ // Clamp to zero and width max() isn't exposed for ints yet
+ if(validW < 0) {
+ validW = 0;
+ }
+ if(validW > width - 1) {
+ validW = width - 1;
+ }
+
+ int input = in[h*width + validW];
+
+ int R = ((input >> 24) & 0xff);
+ int G = ((input >> 16) & 0xff);
+ int B = ((input >> 8) & 0xff);
+ int A = (input & 0xff);
+
+ float weight = gaussian[r + radius];
+
+ blurredPixelR += (float)(R)*weight;
+ blurredPixelG += (float)(G)*weight;
+ blurredPixelB += (float)(B)*weight;
+ blurredPixelA += (float)(A)*weight;
+ }
+
+ int R = (int)blurredPixelR;
+ int G = (int)blurredPixelG;
+ int B = (int)blurredPixelB;
+ int A = (int)blurredPixelA;
+
+ interm[h*width + w] = (R << 24) | (G << 16) | (B << 8) | (A);
+ }
+ }
+
+ for(h = 0; h < height; h ++) {
+ for(w = 0; w < width; w ++) {
+
+ blurredPixelR = 0.0f;
+ blurredPixelG = 0.0f;
+ blurredPixelB = 0.0f;
+ blurredPixelA = 0.0f;
+ for(r = -radius; r <= radius; r ++) {
+ int validH = h + r;
+ // Clamp to zero and width
+ if(validH < 0) {
+ validH = 0;
+ }
+ if(validH > height - 1) {
+ validH = height - 1;
+ }
+
+ int input = interm[validH*width + w];
+
+ int R = ((input >> 24) & 0xff);
+ int G = ((input >> 16) & 0xff);
+ int B = ((input >> 8) & 0xff);
+ int A = (input & 0xff);
+
+ float weight = gaussian[r + radius];
+
+ blurredPixelR += (float)(R)*weight;
+ blurredPixelG += (float)(G)*weight;
+ blurredPixelB += (float)(B)*weight;
+ blurredPixelA += (float)(A)*weight;
+ }
+
+ int R = (int)blurredPixelR;
+ int G = (int)blurredPixelG;
+ int B = (int)blurredPixelB;
+ int A = (int)blurredPixelA;
+
+ out[h*width + w] = (R << 24) | (G << 16) | (B << 8) | (A);
}
}
t = java.lang.System.currentTimeMillis() - t;
+ android.util.Log.v("Img", "Java frame time ms " + t);
+ mBitmapOut.setPixels(out, 0, width, 0, 0, width, height);
+ return t;
+ }
+
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ if (fromUser) {
- android.util.Log.v("Img", "frame time ms " + t);
+ if(seekBar == mRadiusSeekBar) {
+ float fRadius = progress / 100.0f;
+ fRadius *= (float)(MAX_RADIUS);
+ mRadius = (int)fRadius;
+
+ mScript.set_radius(mRadius);
+ }
+ else if(seekBar == mInBlackSeekBar) {
+ mInBlack = (float)progress;
+ mScript.set_inBlack(mInBlack);
+ }
+ else if(seekBar == mOutBlackSeekBar) {
+ mOutBlack = (float)progress;
+ mScript.set_outBlack(mOutBlack);
+ }
+ else if(seekBar == mInWhiteSeekBar) {
+ mInWhite = (float)progress + 127.0f;
+ mScript.set_inWhite(mInWhite);
+ }
+ else if(seekBar == mOutWhiteSeekBar) {
+ mOutWhite = (float)progress + 127.0f;
+ mScript.set_outWhite(mOutWhite);
+ }
+ else if(seekBar == mGammaSeekBar) {
+ mGamma = (float)progress/100.0f;
+ mGamma = Math.max(mGamma, 0.1f);
+ mGamma = 1.0f / mGamma;
+ mScript.set_gamma(mGamma);
+ }
+ else if(seekBar == mSaturationSeekBar) {
+ mSaturation = (float)progress / 50.0f;
+ mScript.set_saturation(mSaturation);
+ }
+
+ long t = java.lang.System.currentTimeMillis();
+ if (true) {
+ mScript.invokable_Filter();
+ } else {
+ javaFilter();
+ }
+
+ t = java.lang.System.currentTimeMillis() - t;
+ android.util.Log.v("Img", "Renderscript frame time core ms " + t);
+
+ mDisplayView.invalidate();
+ }
+ }
+
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
@@ -119,45 +308,53 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
- mBitmap = loadBitmap(R.drawable.data);
+ mBitmapIn = loadBitmap(R.drawable.data);
+ mBitmapOut = loadBitmap(R.drawable.data);
+ mBitmapScratch = loadBitmap(R.drawable.data);
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
mSurfaceView.getHolder().addCallback(this);
mDisplayView = (ImageView) findViewById(R.id.display);
- mDisplayView.setImageBitmap(mBitmap);
-
- ((SeekBar) findViewById(R.id.threshold)).setOnSeekBarChangeListener(
- new SeekBar.OnSeekBarChangeListener() {
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- if (fromUser) {
- mParams.threshold = progress / 100.0f;
- mParamsAllocation.data(mParams);
-
- if (true) {
- mInvokable.execute();
- } else {
- javaFilter();
- mBitmap.setPixels(mOutData, 0, mParams.outWidth, 0, 0,
- mParams.outWidth, mParams.outHeight);
- mDisplayView.invalidate();
- }
- }
- }
-
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
-
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
- });
+ mDisplayView.setImageBitmap(mBitmapOut);
+
+ mRadiusSeekBar = (SeekBar) findViewById(R.id.radius);
+ mRadiusSeekBar.setOnSeekBarChangeListener(this);
+
+ mInBlackSeekBar = (SeekBar)findViewById(R.id.inBlack);
+ mInBlackSeekBar.setOnSeekBarChangeListener(this);
+ mInBlackSeekBar.setMax(128);
+ mInBlackSeekBar.setProgress(0);
+ mOutBlackSeekBar = (SeekBar)findViewById(R.id.outBlack);
+ mOutBlackSeekBar.setOnSeekBarChangeListener(this);
+ mOutBlackSeekBar.setMax(128);
+ mOutBlackSeekBar.setProgress(0);
+
+ mInWhiteSeekBar = (SeekBar)findViewById(R.id.inWhite);
+ mInWhiteSeekBar.setOnSeekBarChangeListener(this);
+ mInWhiteSeekBar.setMax(128);
+ mInWhiteSeekBar.setProgress(128);
+ mOutWhiteSeekBar = (SeekBar)findViewById(R.id.outWhite);
+ mOutWhiteSeekBar.setOnSeekBarChangeListener(this);
+ mOutWhiteSeekBar.setMax(128);
+ mOutWhiteSeekBar.setProgress(128);
+
+ mGammaSeekBar = (SeekBar)findViewById(R.id.inGamma);
+ mGammaSeekBar.setOnSeekBarChangeListener(this);
+ mGammaSeekBar.setMax(150);
+ mGammaSeekBar.setProgress(100);
+
+ mSaturationSeekBar = (SeekBar)findViewById(R.id.inSaturation);
+ mSaturationSeekBar.setOnSeekBarChangeListener(this);
+ mSaturationSeekBar.setProgress(50);
+
+ mBenchmarkResult = (TextView) findViewById(R.id.benchmarkText);
+ mBenchmarkResult.setText("Benchmark no yet run");
}
public void surfaceCreated(SurfaceHolder holder) {
- mParams = createParams();
- mInvokable = createScript();
-
- mInvokable.execute();
+ createScript();
+ mScript.invokable_Filter();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
@@ -166,54 +363,29 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
public void surfaceDestroyed(SurfaceHolder holder) {
}
- private Script.Invokable createScript() {
+ private void createScript() {
mRS = RenderScript.create();
mRS.mMessageCallback = new FilterCallback();
- mParamsType = Type.createFromClass(mRS, Params.class, 1, "Parameters");
- mParamsAllocation = Allocation.createTyped(mRS, mParamsType);
- mParamsAllocation.data(mParams);
-
- final int pixelCount = mParams.inWidth * mParams.inHeight;
-
- mPixelType = Type.createFromClass(mRS, Pixel.class, 1, "Pixel");
- mInPixelsAllocation = Allocation.createSized(mRS,
- Element.createUser(mRS, Element.DataType.SIGNED_32),
- pixelCount);
- mOutPixelsAllocation = Allocation.createSized(mRS,
- Element.createUser(mRS, Element.DataType.SIGNED_32),
- pixelCount);
-
- mInData = new int[pixelCount];
- mBitmap.getPixels(mInData, 0, mParams.inWidth, 0, 0, mParams.inWidth, mParams.inHeight);
- mInPixelsAllocation.data(mInData);
-
- mOutData = new int[pixelCount];
- mOutPixelsAllocation.data(mOutData);
-
- ScriptC.Builder sb = new ScriptC.Builder(mRS);
- sb.setType(mParamsType, "Params", 0);
- sb.setType(mPixelType, "InPixel", 1);
- sb.setType(mPixelType, "OutPixel", 2);
- sb.setType(true, 2);
- Script.Invokable invokable = sb.addInvokable("main");
- sb.setScript(getResources(), R.raw.threshold);
- //sb.setRoot(true);
-
- ScriptC script = sb.create();
- script.bindAllocation(mParamsAllocation, 0);
- script.bindAllocation(mInPixelsAllocation, 1);
- script.bindAllocation(mOutPixelsAllocation, 2);
-
- return invokable;
- }
-
- private Params createParams() {
- final Params params = new Params();
- params.inWidth = params.outWidth = mBitmap.getWidth();
- params.inHeight = params.outHeight = mBitmap.getHeight();
- params.threshold = 0.5f;
- return params;
+ mInPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapIn);
+ mOutPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapOut);
+ mScratchPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapScratch);
+
+ mScript = new ScriptC_Threshold(mRS, getResources(), false);
+ mScript.set_width(mBitmapIn.getWidth());
+ mScript.set_height(mBitmapIn.getHeight());
+ mScript.set_radius(mRadius);
+
+ mScript.set_inBlack(mInBlack);
+ mScript.set_outBlack(mOutBlack);
+ mScript.set_inWhite(mInWhite);
+ mScript.set_outWhite(mOutWhite);
+ mScript.set_gamma(mGamma);
+ mScript.set_saturation(mSaturation);
+
+ mScript.bind_InPixel(mInPixelsAllocation);
+ mScript.bind_OutPixel(mOutPixelsAllocation);
+ mScript.bind_ScratchPixel(mScratchPixelsAllocation);
}
private Bitmap loadBitmap(int resource) {
@@ -229,4 +401,28 @@ public class ImageProcessingActivity extends Activity implements SurfaceHolder.C
source.recycle();
return b;
}
+
+ // button hook
+ public void benchmark(View v) {
+ android.util.Log.v("Img", "Benchmarking");
+ int oldRadius = mRadius;
+ mRadius = MAX_RADIUS;
+ mScript.set_radius(mRadius);
+
+ long t = java.lang.System.currentTimeMillis();
+
+ mScript.invokable_FilterBenchmark();
+
+ t = java.lang.System.currentTimeMillis() - t;
+ android.util.Log.v("Img", "Renderscript frame time core ms " + t);
+
+ long javaTime = javaFilter();
+
+ mBenchmarkResult.setText("RS: " + t + " ms Java: " + javaTime + " ms");
+
+ mRadius = oldRadius;
+ mScript.set_radius(mRadius);
+
+ mScript.invokable_Filter();
+ }
}
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java
new file mode 100644
index 0000000..dfed9e5
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java
@@ -0,0 +1,115 @@
+
+package com.android.rs.image;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.util.Log;
+
+public class ScriptC_Threshold
+ extends android.renderscript.ScriptC
+{
+ private final static int mFieldIndex_height = 0;
+ private final static int mFieldIndex_width = 1;
+ private final static int mFieldIndex_radius = 2;
+ private final static int mFieldIndex_InPixel = 3;
+ private final static int mFieldIndex_OutPixel = 4;
+ private final static int mFieldIndex_ScratchPixel = 5;
+
+ private final static int mFieldIndex_inBlack = 6;
+ private final static int mFieldIndex_outBlack = 7;
+ private final static int mFieldIndex_inWhite = 8;
+ private final static int mFieldIndex_outWhite = 9;
+ private final static int mFieldIndex_gamma = 10;
+
+ private final static int mFieldIndex_saturation = 11;
+ private final static int mFieldIndex_hue = 12;
+
+ private Allocation mField_InPixel;
+ private Allocation mField_OutPixel;
+ private Allocation mField_ScratchPixel;
+
+ public ScriptC_Threshold(RenderScript rs, Resources resources, boolean isRoot) {
+ super(rs, resources, R.raw.threshold_bc, isRoot);
+ }
+
+ public void bind_InPixel(Allocation f) {
+ if (f != null) {
+ //if (f.getType().getElement() != Element.ATTRIB_COLOR_U8_4(mRS)) {
+ //throw new IllegalArgumentException("Element type mismatch.");
+ //}
+ }
+ bindAllocation(f, mFieldIndex_InPixel);
+ mField_InPixel = f;
+ }
+ public Allocation get_InPixel() {
+ return mField_InPixel;
+ }
+
+ public void bind_OutPixel(Allocation f) {
+ if (f != null) {
+ //if (f.getType().getElement() != Element.ATTRIB_COLOR_U8_4(mRS)) {
+ //throw new IllegalArgumentException("Element type mismatch.");
+ //}
+ }
+ bindAllocation(f, mFieldIndex_OutPixel);
+ mField_OutPixel = f;
+ }
+ public void bind_ScratchPixel(Allocation f) {
+ if (f != null) {
+ //if (f.getType().getElement() != Element.ATTRIB_COLOR_U8_4(mRS)) {
+ //throw new IllegalArgumentException("Element type mismatch.");
+ //}
+ }
+ bindAllocation(f, mFieldIndex_ScratchPixel);
+ mField_ScratchPixel = f;
+ }
+ public Allocation get_OutPixel() {
+ return mField_OutPixel;
+ }
+
+ public void set_height(int v) {
+ setVar(mFieldIndex_height, v);
+ }
+
+ public void set_width(int v) {
+ setVar(mFieldIndex_width, v);
+ }
+
+ public void set_radius(int v) {
+ setVar(mFieldIndex_radius, v);
+ }
+
+ public void set_inBlack(float v) {
+ setVar(mFieldIndex_inBlack, v);
+ }
+ public void set_outBlack(float v) {
+ setVar(mFieldIndex_outBlack, v);
+ }
+ public void set_inWhite(float v) {
+ setVar(mFieldIndex_inWhite, v);
+ }
+ public void set_outWhite(float v) {
+ setVar(mFieldIndex_outWhite, v);
+ }
+ public void set_gamma(float v) {
+ setVar(mFieldIndex_gamma, v);
+ }
+
+ public void set_saturation(float v) {
+ setVar(mFieldIndex_saturation, v);
+ }
+ public void set_hue(float v) {
+ setVar(mFieldIndex_hue, v);
+ }
+
+ private final static int mInvokableIndex_Filter = 2;
+ public void invokable_Filter() {
+ invokeData(mInvokableIndex_Filter);
+ }
+
+ private final static int mInvokableIndex_FilterBenchmark = 3;
+ public void invokable_FilterBenchmark() {
+ invokeData(mInvokableIndex_FilterBenchmark);
+ }
+}
+
diff --git a/libs/rs/java/ModelViewer/Android.mk b/libs/rs/java/ModelViewer/Android.mk
new file mode 100644
index 0000000..8bec6d6
--- /dev/null
+++ b/libs/rs/java/ModelViewer/Android.mk
@@ -0,0 +1,27 @@
+#
+# Copyright (C) 2008 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+#LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
+
+LOCAL_PACKAGE_NAME := ModelViewer
+
+include $(BUILD_PACKAGE)
diff --git a/libs/rs/java/ModelViewer/AndroidManifest.xml b/libs/rs/java/ModelViewer/AndroidManifest.xml
new file mode 100644
index 0000000..ebbe743
--- /dev/null
+++ b/libs/rs/java/ModelViewer/AndroidManifest.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.modelviewer">
+ <application android:label="ModelViewer">
+ <activity android:name="ModelViewer"
+ android:screenOrientation="portrait"
+ android:theme="@android:style/Theme.Black.NoTitleBar">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/libs/rs/java/ModelViewer/res/drawable/robot.png b/libs/rs/java/ModelViewer/res/drawable/robot.png
new file mode 100644
index 0000000..7c85e56
--- /dev/null
+++ b/libs/rs/java/ModelViewer/res/drawable/robot.png
Binary files differ
diff --git a/libs/rs/java/ModelViewer/res/raw/modelviewer.rs b/libs/rs/java/ModelViewer/res/raw/modelviewer.rs
new file mode 100644
index 0000000..6a98f90
--- /dev/null
+++ b/libs/rs/java/ModelViewer/res/raw/modelviewer.rs
@@ -0,0 +1,59 @@
+// Copyright (C) 2009 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)
+
+#include "../../../../scriptc/rs_types.rsh"
+#include "../../../../scriptc/rs_math.rsh"
+#include "../../../../scriptc/rs_graphics.rsh"
+
+rs_program_vertex gPVBackground;
+rs_program_fragment gPFBackground;
+
+rs_allocation gTGrid;
+rs_mesh gTestMesh;
+
+rs_program_store gPFSBackground;
+
+float gRotate;
+
+#pragma rs export_var(gPVBackground, gPFBackground, gTGrid, gTestMesh, gPFSBackground, gRotate)
+
+void init() {
+ gRotate = 0.0f;
+}
+
+int root(int launchID) {
+
+ rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ rsgClearDepth(1.0f);
+
+ rsgBindProgramVertex(gPVBackground);
+
+ rsgBindProgramFragment(gPFBackground);
+ rsgBindProgramStore(gPFSBackground);
+ rsgBindTexture(gPFBackground, 0, gTGrid);
+
+ rs_matrix4x4 matrix;
+ rsMatrixLoadIdentity(&matrix);
+ // Position our model on the screen
+ rsMatrixTranslate(&matrix, 0.0f, -0.3f, 1.2f);
+ rsMatrixScale(&matrix, 0.2f, 0.2f, 0.2f);
+ rsMatrixRotate(&matrix, gRotate, 0.0f, 1.0f, 0.0f);
+ rsgProgramVertexLoadModelMatrix(&matrix);
+
+ rsgDrawSimpleMesh(gTestMesh);
+
+ return 10;
+}
diff --git a/libs/rs/java/ModelViewer/res/raw/modelviewer_bc.bc b/libs/rs/java/ModelViewer/res/raw/modelviewer_bc.bc
new file mode 100644
index 0000000..b02250b
--- /dev/null
+++ b/libs/rs/java/ModelViewer/res/raw/modelviewer_bc.bc
Binary files differ
diff --git a/libs/rs/java/ModelViewer/res/raw/robot.a3d b/libs/rs/java/ModelViewer/res/raw/robot.a3d
new file mode 100644
index 0000000..c0c66ae
--- /dev/null
+++ b/libs/rs/java/ModelViewer/res/raw/robot.a3d
Binary files differ
diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewer.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewer.java
new file mode 100644
index 0000000..7491744
--- /dev/null
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewer.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2008 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.
+ */
+
+package com.android.modelviewer;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScript;
+
+import android.app.Activity;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.provider.Settings.System;
+import android.util.Config;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.Window;
+import android.widget.Button;
+import android.widget.ListView;
+
+import java.lang.Runtime;
+
+public class ModelViewer extends Activity {
+
+ private ModelViewerView mView;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ // Create our Preview view and set it as the content of our
+ // Activity
+ mView = new ModelViewerView(this);
+ setContentView(mView);
+ }
+
+ @Override
+ protected void onResume() {
+ // Ideally a game should implement onResume() and onPause()
+ // to take appropriate action when the activity looses focus
+ super.onResume();
+ mView.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ // Ideally a game should implement onResume() and onPause()
+ // to take appropriate action when the activity looses focus
+ super.onPause();
+ mView.onPause();
+ }
+
+}
+
diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerRS.java
new file mode 100644
index 0000000..dd52955
--- /dev/null
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerRS.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2008 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.
+ */
+
+package com.android.modelviewer;
+
+import java.io.Writer;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.renderscript.ProgramStore.DepthFunc;
+import android.util.Log;
+
+
+public class ModelViewerRS {
+
+ private final int STATE_LAST_FOCUS = 1;
+
+ int mWidth;
+ int mHeight;
+ int mRotation;
+
+ public ModelViewerRS() {
+ }
+
+ public void init(RenderScriptGL rs, Resources res, int width, int height) {
+ mRS = rs;
+ mRes = res;
+ mWidth = width;
+ mHeight = height;
+ mRotation = 0;
+ initRS();
+ }
+
+ private Resources mRes;
+ private RenderScriptGL mRS;
+ private Sampler mSampler;
+ private ProgramStore mPSBackground;
+ private ProgramFragment mPFBackground;
+ private ProgramVertex mPVBackground;
+ private ProgramVertex.MatrixAllocation mPVA;
+
+ private Allocation mGridImage;
+ private Allocation mAllocPV;
+
+ private SimpleMesh mMesh;
+
+ private ScriptC_ModelViewer mScript;
+
+ int mLastX;
+ int mLastY;
+
+ public void touchEvent(int x, int y) {
+ int dx = mLastX - x;
+ if(Math.abs(dx) > 50 || Math.abs(dx) < 3) {
+ dx = 0;
+ }
+
+ mRotation -= dx;
+ if(mRotation > 360) {
+ mRotation -= 360;
+ }
+ if(mRotation < 0) {
+ mRotation += 360;
+ }
+
+ mScript.set_gRotate(-(float)mRotation);
+
+ mLastX = x;
+ mLastY = y;
+ }
+
+ private void initPFS() {
+ ProgramStore.Builder b = new ProgramStore.Builder(mRS, null, null);
+
+ b.setDepthFunc(ProgramStore.DepthFunc.LESS);
+ b.setDitherEnable(false);
+ b.setDepthMask(true);
+ mPSBackground = b.create();
+
+ mScript.set_gPFSBackground(mPSBackground);
+ }
+
+ private void initPF() {
+ Sampler.Builder bs = new Sampler.Builder(mRS);
+ bs.setMin(Sampler.Value.LINEAR);
+ bs.setMag(Sampler.Value.LINEAR);
+ bs.setWrapS(Sampler.Value.CLAMP);
+ bs.setWrapT(Sampler.Value.WRAP);
+ mSampler = bs.create();
+
+ ProgramFragment.Builder b = new ProgramFragment.Builder(mRS);
+ b.setTexture(ProgramFragment.Builder.EnvMode.REPLACE,
+ ProgramFragment.Builder.Format.RGBA, 0);
+ mPFBackground = b.create();
+ mPFBackground.bindSampler(mSampler, 0);
+
+ mScript.set_gPFBackground(mPFBackground);
+ }
+
+ private void initPV() {
+ ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
+ mPVBackground = pvb.create();
+
+ mPVA = new ProgramVertex.MatrixAllocation(mRS);
+ mPVBackground.bindAllocation(mPVA);
+ mPVA.setupProjectionNormalized(mWidth, mHeight);
+
+ mScript.set_gPVBackground(mPVBackground);
+ }
+
+ private void loadImage() {
+ mGridImage = Allocation.createFromBitmapResourceBoxed(mRS, mRes, R.drawable.robot, Element.RGB_565(mRS), true);
+ mGridImage.uploadToTexture(1);
+
+ mScript.set_gTGrid(mGridImage);
+ }
+
+ private void initRS() {
+
+ mScript = new ScriptC_ModelViewer(mRS, mRes, true);
+
+ initPFS();
+ initPF();
+ initPV();
+
+ loadImage();
+
+ FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
+ FileA3D.IndexEntry entry = model.getIndexEntry(0);
+ if(entry == null || entry.getClassID() != FileA3D.ClassID.SIMPLE_MESH) {
+ Log.e("rs", "could not load model");
+ }
+ else {
+ mMesh = (SimpleMesh)entry.getObject();
+ mScript.set_gTestMesh(mMesh);
+ }
+
+ mRS.contextBindRootScript(mScript);
+ }
+}
+
+
+
diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerView.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerView.java
new file mode 100644
index 0000000..ce76e1a
--- /dev/null
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ModelViewerView.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2008 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.
+ */
+
+package com.android.modelviewer;
+
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.concurrent.Semaphore;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScript;
+import android.renderscript.RenderScriptGL;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.Handler;
+import android.os.Message;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.Surface;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+
+public class ModelViewerView extends RSSurfaceView {
+
+ public ModelViewerView(Context context) {
+ super(context);
+ //setFocusable(true);
+ }
+
+ private RenderScriptGL mRS;
+ private ModelViewerRS mRender;
+
+
+ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+ super.surfaceChanged(holder, format, w, h);
+ if (mRS == null) {
+ mRS = createRenderScript(true);
+ mRS.contextSetSurface(w, h, holder.getSurface());
+ mRender = new ModelViewerRS();
+ mRender.init(mRS, getResources(), w, h);
+ }
+ }
+
+ @Override
+ protected void onDetachedFromWindow() {
+ if(mRS != null) {
+ mRS = null;
+ destroyRenderScript();
+ }
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event)
+ {
+ // break point at here
+ // this method doesn't work when 'extends View' include 'extends ScrollView'.
+ return super.onKeyDown(keyCode, event);
+ }
+
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev)
+ {
+ boolean ret = true;
+ int act = ev.getAction();
+ if (act == ev.ACTION_UP) {
+ ret = false;
+ }
+
+ Log.v("rs", "Values " + (int)ev.getX() + " " + (int)ev.getY());
+ mRender.touchEvent((int)ev.getX(), (int)ev.getY());
+ return ret;
+ }
+}
+
+
diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/ScriptC_ModelViewer.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ScriptC_ModelViewer.java
new file mode 100644
index 0000000..f617c77
--- /dev/null
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/ScriptC_ModelViewer.java
@@ -0,0 +1,42 @@
+
+package com.android.modelviewer;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.util.Log;
+
+
+
+public class ScriptC_ModelViewer
+ extends android.renderscript.ScriptC
+{
+ public ScriptC_ModelViewer(RenderScript rs, Resources resources, boolean isRoot) {
+ super(rs, resources, R.raw.modelviewer_bc, isRoot);
+ }
+
+ public void set_gPVBackground(ProgramVertex v) {
+ setVar(0, v.getID());
+ }
+
+ public void set_gPFBackground(ProgramFragment v) {
+ setVar(1, v.getID());
+ }
+
+ public void set_gTGrid(Allocation v) {
+ setVar(2, v.getID());
+ }
+
+ public void set_gTestMesh(SimpleMesh v) {
+ setVar(3, v.getID());
+ }
+
+ public void set_gPFSBackground(ProgramStore v) {
+ setVar(4, v.getID());
+ }
+
+ public void set_gRotate(float v) {
+ setVar(5, v);
+ }
+
+}
+
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index cb9937c..4867cad 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -4,8 +4,8 @@ ContextBindRootScript {
param RsScript sampler
}
-ContextBindProgramFragmentStore {
- param RsProgramFragmentStore pgm
+ContextBindProgramStore {
+ param RsProgramStore pgm
}
ContextBindProgramFragment {
@@ -248,13 +248,6 @@ ScriptBindAllocation {
ScriptCBegin {
}
-ScriptSetClearColor {
- param RsScript s
- param float r
- param float g
- param float b
- param float a
- }
ScriptSetTimeZone {
param RsScript s
@@ -262,39 +255,49 @@ ScriptSetTimeZone {
param uint32_t length
}
-ScriptSetClearDepth {
+
+ScriptInvoke {
param RsScript s
- param float depth
+ param uint32_t slot
}
-ScriptSetClearStencil {
+ScriptInvokeData {
param RsScript s
- param uint32_t stencil
+ param uint32_t slot
+ param void * data
}
-ScriptSetType {
- param RsType type
+ScriptInvokeV {
+ param RsScript s
param uint32_t slot
- param bool isWritable
- param const char * name
+ param const void * data
+ param uint32_t dataLen
+ handcodeApi
+ togglePlay
}
-ScriptSetInvoke {
- param const char * name
+ScriptSetVarI {
+ param RsScript s
param uint32_t slot
+ param int value
}
-ScriptInvoke {
+ScriptSetVarF {
param RsScript s
param uint32_t slot
+ param float value
}
-ScriptSetRoot {
- param bool isRoot
+ScriptSetVarV {
+ param RsScript s
+ param uint32_t slot
+ param const void * data
+ param uint32_t dataLen
+ handcodeApi
+ togglePlay
}
-
ScriptCSetScript {
param void * codePtr
}
@@ -308,47 +311,38 @@ ScriptCCreate {
ret RsScript
}
-ScriptCSetDefineF {
- param const char* name
- param float value
- }
-ScriptCSetDefineI32 {
- param const char* name
- param int32_t value
- }
-
-ProgramFragmentStoreBegin {
+ProgramStoreBegin {
param RsElement in
param RsElement out
}
-ProgramFragmentStoreColorMask {
+ProgramStoreColorMask {
param bool r
param bool g
param bool b
param bool a
}
-ProgramFragmentStoreBlendFunc {
+ProgramStoreBlendFunc {
param RsBlendSrcFunc srcFunc
param RsBlendDstFunc destFunc
}
-ProgramFragmentStoreDepthMask {
+ProgramStoreDepthMask {
param bool enable
}
-ProgramFragmentStoreDither {
+ProgramStoreDither {
param bool enable
}
-ProgramFragmentStoreDepthFunc {
+ProgramStoreDepthFunc {
param RsDepthFunc func
}
-ProgramFragmentStoreCreate {
- ret RsProgramFragmentStore
+ProgramStoreCreate {
+ ret RsProgramStore
}
ProgramRasterCreate {
@@ -447,12 +441,34 @@ LightSetColor {
param float b
}
+FileA3DCreateFromAssetStream {
+ param const void * data
+ param size_t len
+ ret RsFile
+ }
+
FileOpen {
ret RsFile
param const char *name
param size_t len
}
+FileA3DGetNumIndexEntries {
+ param int32_t * numEntries
+ param RsFile file
+ }
+
+FileA3DGetIndexEntries {
+ param RsFileIndexEntry * fileEntries
+ param uint32_t numEntries
+ param RsFile fileA3D
+ }
+
+FileA3DGetEntryByIndex {
+ param uint32_t index
+ param RsFile file
+ ret RsObjectBase
+ }
SimpleMeshCreate {
ret RsSimpleMesh
@@ -480,3 +496,13 @@ SimpleMeshBindVertex {
param uint32_t slot
}
+AnimationCreate {
+ param const float *inValues
+ param const float *outValues
+ param uint32_t valueCount
+ param RsAnimationInterpolation interp
+ param RsAnimationEdge pre
+ param RsAnimationEdge post
+ ret RsAnimation
+ }
+
diff --git a/libs/rs/rsAdapter.cpp b/libs/rs/rsAdapter.cpp
index 0d31fac..b4ec250 100644
--- a/libs/rs/rsAdapter.cpp
+++ b/libs/rs/rsAdapter.cpp
@@ -15,7 +15,11 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#else
+#include "rsContextHostStub.h"
+#endif
using namespace android;
using namespace android::renderscript;
@@ -70,6 +74,16 @@ void Adapter1D::data(const void *data)
mAllocation.get()->getType()->getSizeBytes());
}
+void Adapter1D::serialize(OStream *stream) const
+{
+
+}
+
+Adapter1D *Adapter1D::createFromStream(Context *rsc, IStream *stream)
+{
+ return NULL;
+}
+
namespace android {
namespace renderscript {
@@ -185,6 +199,15 @@ void Adapter2D::data(const void *data)
mAllocation.get()->getType()->getSizeBytes());
}
+void Adapter2D::serialize(OStream *stream) const
+{
+
+}
+
+Adapter2D *Adapter2D::createFromStream(Context *rsc, IStream *stream)
+{
+ return NULL;
+}
namespace android {
diff --git a/libs/rs/rsAdapter.h b/libs/rs/rsAdapter.h
index cb2872e..449e7ad 100644
--- a/libs/rs/rsAdapter.h
+++ b/libs/rs/rsAdapter.h
@@ -50,6 +50,10 @@ public:
void subData(uint32_t xoff, uint32_t count, const void *data);
void data(const void *data);
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ADAPTER_1D; }
+ static Adapter1D *createFromStream(Context *rsc, IStream *stream);
+
protected:
ObjectBaseRef<Allocation> mAllocation;
uint32_t mY;
@@ -82,6 +86,10 @@ public:
void data(const void *data);
void subData(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data);
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ADAPTER_2D; }
+ static Adapter2D *createFromStream(Context *rsc, IStream *stream);
+
protected:
ObjectBaseRef<Allocation> mAllocation;
uint32_t mZ;
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 4e8278d..289cb30 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -13,12 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
#include <GLES/gl.h>
#include <GLES2/gl2.h>
#include <GLES/glext.h>
+#else
+#include "rsContextHostStub.h"
+
+#include <OpenGL/gl.h>
+#include <OpenGl/glext.h>
+#endif
using namespace android;
using namespace android::renderscript;
@@ -167,9 +173,12 @@ void Allocation::uploadToTexture(const Context *rsc)
0, format, type, ptr);
}
if (mTextureGenMipmap) {
+#ifndef ANDROID_RS_BUILD_FOR_HOST
glGenerateMipmap(GL_TEXTURE_2D);
+#endif //ANDROID_RS_BUILD_FOR_HOST
}
+ rsc->checkError("Allocation::uploadToTexture");
}
void Allocation::deferedUploadToBufferObject(const Context *rsc)
@@ -201,6 +210,7 @@ void Allocation::uploadToBufferObject(const Context *rsc)
glBindBuffer(GL_ARRAY_BUFFER, mBufferID);
glBufferData(GL_ARRAY_BUFFER, mType->getSizeBytes(), getPtr(), GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
+ rsc->checkError("Allocation::uploadToBufferObject");
}
void Allocation::uploadCheck(const Context *rsc)
@@ -284,7 +294,7 @@ void Allocation::subData(uint32_t xoff, uint32_t yoff, uint32_t zoff,
void Allocation::addProgramToDirty(const Program *p)
{
- mToDirtyList.add(p);
+ mToDirtyList.push(p);
}
void Allocation::removeProgramToDirty(const Program *p)
@@ -316,6 +326,60 @@ void Allocation::dumpLOGV(const char *prefix) const
}
+void Allocation::serialize(OStream *stream) const
+{
+ // Need to identify ourselves
+ stream->addU32((uint32_t)getClassId());
+
+ String8 name(getName());
+ stream->addString(&name);
+
+ // First thing we need to serialize is the type object since it will be needed
+ // to initialize the class
+ mType->serialize(stream);
+
+ uint32_t dataSize = mType->getSizeBytes();
+ // Write how much data we are storing
+ stream->addU32(dataSize);
+ // Now write the data
+ stream->addByteArray(mPtr, dataSize);
+}
+
+Allocation *Allocation::createFromStream(Context *rsc, IStream *stream)
+{
+ // First make sure we are reading the correct object
+ RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
+ if(classID != RS_A3D_CLASS_ID_ALLOCATION) {
+ LOGE("allocation loading skipped due to invalid class id\n");
+ return NULL;
+ }
+
+ String8 name;
+ stream->loadString(&name);
+
+ Type *type = Type::createFromStream(rsc, stream);
+ if(!type) {
+ return NULL;
+ }
+ type->compute();
+
+ // Number of bytes we wrote out for this allocation
+ uint32_t dataSize = stream->loadU32();
+ if(dataSize != type->getSizeBytes()) {
+ LOGE("failed to read allocation because numbytes written is not the same loaded type wants\n");
+ delete type;
+ return NULL;
+ }
+
+ Allocation *alloc = new Allocation(rsc, type);
+ alloc->setName(name.string(), name.size());
+
+ // Read in all of our allocation data
+ stream->loadByteArray(alloc->getPtr(), dataSize);
+
+ return alloc;
+}
+
void Allocation::sendDirty() const
{
for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
@@ -512,6 +576,8 @@ static ElementConverter_t pickConverter(const Element *dst, const Element *src)
return 0;
}
+#ifndef ANDROID_RS_BUILD_FOR_HOST
+
RsAllocation rsi_AllocationCreateBitmapRef(Context *rsc, RsType vtype,
void *bmp, void *callbackData, RsBitmapCallback_t callback)
{
@@ -613,6 +679,7 @@ void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data)
a->read(data);
}
+#endif //ANDROID_RS_BUILD_FOR_HOST
}
}
diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h
index 516f8b7..a408a57 100644
--- a/libs/rs/rsAllocation.h
+++ b/libs/rs/rsAllocation.h
@@ -72,6 +72,9 @@ public:
void removeProgramToDirty(const Program *);
virtual void dumpLOGV(const char *prefix) const;
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ALLOCATION; }
+ static Allocation *createFromStream(Context *rsc, IStream *stream);
virtual void uploadCheck(const Context *rsc);
diff --git a/libs/rs/rsAnimation.cpp b/libs/rs/rsAnimation.cpp
new file mode 100644
index 0000000..6200715
--- /dev/null
+++ b/libs/rs/rsAnimation.cpp
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#ifndef ANDROID_RS_BUILD_FOR_HOST
+#include "rsContext.h"
+#else
+#include "rsContextHostStub.h"
+#endif //ANDROID_RS_BUILD_FOR_HOST
+
+#include "rsAnimation.h"
+
+
+using namespace android;
+using namespace android::renderscript;
+
+void Animation::serialize(OStream *stream) const
+{
+
+}
+
+Animation *Animation::createFromStream(Context *rsc, IStream *stream)
+{
+ return NULL;
+}
+
+/*
+Animation::Animation(Context *rsc) : ObjectBase(rsc)
+{
+ mAllocFile = __FILE__;
+ mAllocLine = __LINE__;
+
+ mValuesInput = NULL;
+ mValuesOutput = NULL;
+ mValueCount = 0;
+ mInterpolation = RS_ANIMATION_INTERPOLATION_STEP;
+ mEdgePre = RS_ANIMATION_EDGE_UNDEFINED;
+ mEdgePost = RS_ANIMATION_EDGE_UNDEFINED;
+ mInputMin = 0;
+ mInputMax = 0;
+}
+
+Animation * Animation::create(Context *rsc,
+ const float *inValues, const float *outValues,
+ uint32_t valueCount, RsAnimationInterpolation interp,
+ RsAnimationEdge pre, RsAnimationEdge post)
+{
+ if (valueCount < 2) {
+ rsc->setError(RS_ERROR_BAD_VALUE, "Animations require more than 2 values.");
+ return NULL;
+ }
+ Animation *a = new Animation(rsc);
+ if (!a) {
+ rsc->setError(RS_ERROR_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ float *vin = (float *)malloc(valueCount * sizeof(float));
+ float *vout = (float *)malloc(valueCount * sizeof(float));
+ a->mValuesInput = vin;
+ a->mValuesOutput = vout;
+ if (a->mValuesInput == NULL || a->mValuesOutput == NULL) {
+ delete a;
+ rsc->setError(RS_ERROR_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ a->mEdgePre = pre;
+ a->mEdgePost = post;
+ a->mInterpolation = interp;
+ a->mValueCount = valueCount;
+
+ memcpy(vin, inValues, valueCount * sizeof(float));
+ memcpy(vout, outValues, valueCount * sizeof(float));
+ a->mInputMin = inValues[0];
+ a->mInputMax = inValues[0];
+
+ bool needSort = false;
+ for (uint32_t ct=1; ct < valueCount; ct++) {
+ if (a->mInputMin > vin[ct]) {
+ needSort = true;
+ a->mInputMin = vin[ct];
+ }
+ if (a->mInputMax < vin[ct]) {
+ a->mInputMax = vin[ct];
+ } else {
+ needSort = true;
+ }
+ }
+
+ while (1) {
+ bool changed = false;
+ for (uint32_t ct=1; ct < valueCount; ct++) {
+ if (vin[ct-1] > vin[ct]) {
+ float t = vin[ct-1];
+ vin[ct-1] = vin[ct];
+ vin[ct] = t;
+ t = vout[ct-1];
+ vout[ct-1] = vout[ct];
+ vout[ct] = t;
+ changed = true;
+ }
+ }
+ if (!changed) break;
+ }
+
+ return a;
+}
+*/
+
+
+/////////////////////////////////////////
+//
+
+namespace android {
+namespace renderscript {
+
+RsAnimation rsi_AnimationCreate(Context *rsc,
+ const float *inValues,
+ const float *outValues,
+ uint32_t valueCount,
+ RsAnimationInterpolation interp,
+ RsAnimationEdge pre,
+ RsAnimationEdge post)
+{
+ //LOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize);
+ Animation *a = NULL;//Animation::create(rsc, inValues, outValues, valueCount, interp, pre, post);
+ if (a != NULL) {
+ a->incUserRef();
+ }
+ return (RsAnimation)a;
+}
+
+
+}
+}
+
diff --git a/libs/rs/rsAnimation.h b/libs/rs/rsAnimation.h
new file mode 100644
index 0000000..340314e
--- /dev/null
+++ b/libs/rs/rsAnimation.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#ifndef ANDROID_RS_ANIMATION_H
+#define ANDROID_RS_ANIMATION_H
+
+#include "rsUtils.h"
+#include "rsObjectBase.h"
+
+// ---------------------------------------------------------------------------
+namespace android {
+namespace renderscript {
+
+
+class Animation : public ObjectBase
+{
+public:
+ ~Animation();
+
+ static Animation * create(Context *rsc,
+ const float *inValues, const float *outValues,
+ uint32_t valueCount, RsAnimationInterpolation,
+ RsAnimationEdge pre, RsAnimationEdge post);
+
+ float eval(float) const;
+
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ANIMATION; }
+ static Animation *createFromStream(Context *rsc, IStream *stream);
+
+protected:
+ Animation(Context *rsc);
+
+
+
+ float evalInRange(float) const;
+
+
+
+ const float *mValuesInput;
+ const float *mValuesOutput;
+ uint32_t mValueCount;
+ RsAnimationInterpolation mInterpolation;
+ RsAnimationEdge mEdgePre;
+ RsAnimationEdge mEdgePost;
+
+ // derived
+ float mInputMin;
+ float mInputMax;
+};
+
+
+
+
+}
+}
+#endif //ANDROID_STRUCTURED_ELEMENT_H
+
diff --git a/libs/rs/rsComponent.cpp b/libs/rs/rsComponent.cpp
index 15a56f7..b120c21 100644
--- a/libs/rs/rsComponent.cpp
+++ b/libs/rs/rsComponent.cpp
@@ -16,7 +16,11 @@
#include "rsComponent.h"
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include <GLES/gl.h>
+#else
+#include <OpenGL/gl.h>
+#endif
using namespace android;
using namespace android::renderscript;
@@ -334,4 +338,25 @@ void Component::dumpLOGV(const char *prefix) const
prefix, gTypeStrings[mType], gKindStrings[mKind], mVectorSize, mBits);
}
+void Component::serialize(OStream *stream) const
+{
+ stream->addU8((uint8_t)mType);
+ stream->addU8((uint8_t)mKind);
+ stream->addU8((uint8_t)(mNormalized ? 1 : 0));
+ stream->addU32(mVectorSize);
+}
+
+void Component::loadFromStream(IStream *stream)
+{
+ mType = (RsDataType)stream->loadU8();
+ mKind = (RsDataKind)stream->loadU8();
+ uint8_t temp = stream->loadU8();
+ mNormalized = temp != 0;
+ mVectorSize = stream->loadU32();
+
+ set(mType, mKind, mNormalized, mVectorSize);
+}
+
+
+
diff --git a/libs/rs/rsComponent.h b/libs/rs/rsComponent.h
index 71de324..0f93a91 100644
--- a/libs/rs/rsComponent.h
+++ b/libs/rs/rsComponent.h
@@ -48,6 +48,10 @@ public:
bool getIsSigned() const {return mIsSigned;}
uint32_t getBits() const {return mBits;}
+ // Helpers for reading / writing this class out
+ void serialize(OStream *stream) const;
+ void loadFromStream(IStream *stream);
+
protected:
RsDataType mType;
RsDataKind mKind;
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index d8a9a99..449e5dc 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -127,14 +127,14 @@ void Context::deinitEGL()
}
-uint32_t Context::runScript(Script *s, uint32_t launchID)
+uint32_t Context::runScript(Script *s)
{
ObjectBaseRef<ProgramFragment> frag(mFragment);
ObjectBaseRef<ProgramVertex> vtx(mVertex);
- ObjectBaseRef<ProgramFragmentStore> store(mFragmentStore);
+ ObjectBaseRef<ProgramStore> store(mFragmentStore);
ObjectBaseRef<ProgramRaster> raster(mRaster);
- uint32_t ret = s->run(this, launchID);
+ uint32_t ret = s->run(this);
mFragment.set(frag);
mVertex.set(vtx);
@@ -153,29 +153,11 @@ void Context::checkError(const char *msg) const
uint32_t Context::runRootScript()
{
- timerSet(RS_TIMER_CLEAR_SWAP);
- rsAssert(mRootScript->mEnviroment.mIsRoot);
-
- eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
- eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
- glViewport(0, 0, mEGL.mWidth, mEGL.mHeight);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-
- glClearColor(mRootScript->mEnviroment.mClearColor[0],
- mRootScript->mEnviroment.mClearColor[1],
- mRootScript->mEnviroment.mClearColor[2],
- mRootScript->mEnviroment.mClearColor[3]);
- if (mUseDepth) {
- glDepthMask(GL_TRUE);
- glClearDepthf(mRootScript->mEnviroment.mClearDepth);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- } else {
- glClear(GL_COLOR_BUFFER_BIT);
- }
+ glViewport(0, 0, mWidth, mHeight);
timerSet(RS_TIMER_SCRIPT);
mStateFragmentStore.mLast.clear();
- uint32_t ret = runScript(mRootScript.get(), 0);
+ uint32_t ret = runScript(mRootScript.get());
checkError("runRootScript");
if (mError != RS_ERROR_NONE) {
@@ -300,13 +282,13 @@ void * Context::threadProc(void *vrsc)
}
if (rsc->mIsGraphicsContext) {
- rsc->mStateRaster.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
+ rsc->mStateRaster.init(rsc);
rsc->setRaster(NULL);
- rsc->mStateVertex.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
+ rsc->mStateVertex.init(rsc);
rsc->setVertex(NULL);
- rsc->mStateFragment.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
+ rsc->mStateFragment.init(rsc);
rsc->setFragment(NULL);
- rsc->mStateFragmentStore.init(rsc, rsc->mEGL.mWidth, rsc->mEGL.mHeight);
+ rsc->mStateFragmentStore.init(rsc);
rsc->setFragmentStore(NULL);
rsc->mStateVertexArray.init(rsc);
}
@@ -486,14 +468,14 @@ void Context::setSurface(uint32_t w, uint32_t h, android_native_window_t *sur)
checkEglError("eglDestroySurface", ret);
mEGL.mSurface = NULL;
- mEGL.mWidth = 0;
- mEGL.mHeight = 0;
mWidth = 0;
mHeight = 0;
}
mWndSurface = sur;
if (mWndSurface != NULL) {
+ mWidth = w;
+ mHeight = h;
bool first = false;
if (!mEGL.mContext) {
first = true;
@@ -511,15 +493,7 @@ void Context::setSurface(uint32_t w, uint32_t h, android_native_window_t *sur)
ret = eglMakeCurrent(mEGL.mDisplay, mEGL.mSurface, mEGL.mSurface, mEGL.mContext);
checkEglError("eglMakeCurrent", ret);
- eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_WIDTH, &mEGL.mWidth);
- eglQuerySurface(mEGL.mDisplay, mEGL.mSurface, EGL_HEIGHT, &mEGL.mHeight);
- mWidth = w;
- mHeight = h;
- mStateVertex.updateSize(this, w, h);
-
- if ((int)mWidth != mEGL.mWidth || (int)mHeight != mEGL.mHeight) {
- LOGE("EGL/Surface mismatch EGL (%i x %i) SF (%i x %i)", mEGL.mWidth, mEGL.mHeight, mWidth, mHeight);
- }
+ mStateVertex.updateSize(this);
if (first) {
mGL.mVersion = glGetString(GL_VERSION);
@@ -583,7 +557,7 @@ void Context::setRootScript(Script *s)
mRootScript.set(s);
}
-void Context::setFragmentStore(ProgramFragmentStore *pfs)
+void Context::setFragmentStore(ProgramStore *pfs)
{
rsAssert(mIsGraphicsContext);
if (pfs == NULL) {
@@ -640,32 +614,9 @@ void Context::removeName(ObjectBase *obj)
}
}
-ObjectBase * Context::lookupName(const char *name) const
-{
- for(size_t ct=0; ct < mNames.size(); ct++) {
- if (!strcmp(name, mNames[ct]->getName())) {
- return mNames[ct];
- }
- }
- return NULL;
-}
-
-void Context::appendNameDefines(String8 *str) const
-{
- char buf[256];
- for (size_t ct=0; ct < mNames.size(); ct++) {
- str->append("#define NAMED_");
- str->append(mNames[ct]->getName());
- str->append(" ");
- sprintf(buf, "%i\n", (int)mNames[ct]);
- str->append(buf);
- }
-}
-
bool Context::objDestroyOOBInit()
{
- int status = pthread_mutex_init(&mObjDestroy.mMutex, NULL);
- if (status) {
+ if (!mObjDestroy.mMutex.init()) {
LOGE("Context::ObjDestroyOOBInit mutex init failure");
return false;
}
@@ -675,9 +626,8 @@ bool Context::objDestroyOOBInit()
void Context::objDestroyOOBRun()
{
if (mObjDestroy.mNeedToEmpty) {
- int status = pthread_mutex_lock(&mObjDestroy.mMutex);
- if (status) {
- LOGE("Context::ObjDestroyOOBRun: error %i locking for OOBRun.", status);
+ if (!mObjDestroy.mMutex.lock()) {
+ LOGE("Context::ObjDestroyOOBRun: error locking for OOBRun.");
return;
}
@@ -686,35 +636,25 @@ void Context::objDestroyOOBRun()
}
mObjDestroy.mDestroyList.clear();
mObjDestroy.mNeedToEmpty = false;
-
- status = pthread_mutex_unlock(&mObjDestroy.mMutex);
- if (status) {
- LOGE("Context::ObjDestroyOOBRun: error %i unlocking for set condition.", status);
- }
+ mObjDestroy.mMutex.unlock();
}
}
void Context::objDestroyOOBDestroy()
{
rsAssert(!mObjDestroy.mNeedToEmpty);
- pthread_mutex_destroy(&mObjDestroy.mMutex);
}
void Context::objDestroyAdd(ObjectBase *obj)
{
- int status = pthread_mutex_lock(&mObjDestroy.mMutex);
- if (status) {
- LOGE("Context::ObjDestroyOOBRun: error %i locking for OOBRun.", status);
+ if (!mObjDestroy.mMutex.lock()) {
+ LOGE("Context::ObjDestroyOOBRun: error locking for OOBRun.");
return;
}
mObjDestroy.mNeedToEmpty = true;
mObjDestroy.mDestroyList.add(obj);
-
- status = pthread_mutex_unlock(&mObjDestroy.mMutex);
- if (status) {
- LOGE("Context::ObjDestroyOOBRun: error %i unlocking for set condition.", status);
- }
+ mObjDestroy.mMutex.unlock();
}
uint32_t Context::getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait)
@@ -799,8 +739,7 @@ void Context::dumpDebug() const
LOGE("RS Context debug");
LOGE(" EGL ver %i %i", mEGL.mMajorVersion, mEGL.mMinorVersion);
- LOGE(" EGL context %p surface %p, w=%i h=%i Display=%p", mEGL.mContext,
- mEGL.mSurface, mEGL.mWidth, mEGL.mHeight, mEGL.mDisplay);
+ LOGE(" EGL context %p surface %p, Display=%p", mEGL.mContext, mEGL.mSurface, mEGL.mDisplay);
LOGE(" GL vendor: %s", mGL.mVendor);
LOGE(" GL renderer: %s", mGL.mRenderer);
LOGE(" GL Version: %s", mGL.mVersion);
@@ -841,9 +780,9 @@ void rsi_ContextBindSampler(Context *rsc, uint32_t slot, RsSampler vs)
s->bindToContext(&rsc->mStateSampler, slot);
}
-void rsi_ContextBindProgramFragmentStore(Context *rsc, RsProgramFragmentStore vpfs)
+void rsi_ContextBindProgramStore(Context *rsc, RsProgramStore vpfs)
{
- ProgramFragmentStore *pfs = static_cast<ProgramFragmentStore *>(vpfs);
+ ProgramStore *pfs = static_cast<ProgramStore *>(vpfs);
rsc->setFragmentStore(pfs);
}
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 82c3687..31bf5d6 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -18,6 +18,7 @@
#define ANDROID_RS_CONTEXT_H
#include "rsUtils.h"
+#include "rsMutex.h"
#include "rsThreadIO.h"
#include "rsType.h"
@@ -32,7 +33,7 @@
#include "rsSampler.h"
#include "rsLight.h"
#include "rsProgramFragment.h"
-#include "rsProgramFragmentStore.h"
+#include "rsProgramStore.h"
#include "rsProgramRaster.h"
#include "rsProgramVertex.h"
#include "rsShaderCache.h"
@@ -70,7 +71,7 @@ public:
TypeState mStateType;
SamplerState mStateSampler;
ProgramFragmentState mStateFragment;
- ProgramFragmentStoreState mStateFragmentStore;
+ ProgramStoreState mStateFragmentStore;
ProgramRasterState mStateRaster;
ProgramVertexState mStateVertex;
LightState mStateLight;
@@ -84,12 +85,12 @@ public:
void setRaster(ProgramRaster *);
void setVertex(ProgramVertex *);
void setFragment(ProgramFragment *);
- void setFragmentStore(ProgramFragmentStore *);
+ void setFragmentStore(ProgramStore *);
void updateSurface(void *sur);
const ProgramFragment * getFragment() {return mFragment.get();}
- const ProgramFragmentStore * getFragmentStore() {return mFragmentStore.get();}
+ const ProgramStore * getFragmentStore() {return mFragmentStore.get();}
const ProgramRaster * getRaster() {return mRaster.get();}
const ProgramVertex * getVertex() {return mVertex.get();}
@@ -103,12 +104,10 @@ public:
void assignName(ObjectBase *obj, const char *name, uint32_t len);
void removeName(ObjectBase *obj);
- ObjectBase * lookupName(const char *name) const;
- void appendNameDefines(String8 *str) const;
uint32_t getMessageToClient(void *data, size_t *receiveLen, size_t bufferLen, bool wait);
bool sendMessageToClient(void *data, uint32_t cmdID, size_t len, bool waitForSpace);
- uint32_t runScript(Script *s, uint32_t launchID);
+ uint32_t runScript(Script *s);
void initToClient();
void deinitToClient();
@@ -119,15 +118,15 @@ public:
ProgramVertex * getDefaultProgramVertex() const {
return mStateVertex.mDefault.get();
}
- ProgramFragmentStore * getDefaultProgramFragmentStore() const {
+ ProgramStore * getDefaultProgramStore() const {
return mStateFragmentStore.mDefault.get();
}
ProgramRaster * getDefaultProgramRaster() const {
return mStateRaster.mDefault.get();
}
- uint32_t getWidth() const {return mEGL.mWidth;}
- uint32_t getHeight() const {return mEGL.mHeight;}
+ uint32_t getWidth() const {return mWidth;}
+ uint32_t getHeight() const {return mHeight;}
ThreadIO mIO;
@@ -161,7 +160,7 @@ public:
void dumpDebug() const;
void checkError(const char *) const;
const char * getError(RsError *);
- void setError(RsError e, const char *msg);
+ void setError(RsError e, const char *msg = NULL);
mutable const ObjectBase * mObjHead;
@@ -177,8 +176,6 @@ protected:
EGLConfig mConfig;
EGLContext mContext;
EGLSurface mSurface;
- EGLint mWidth;
- EGLint mHeight;
EGLDisplay mDisplay;
} mEGL;
@@ -222,12 +219,12 @@ protected:
ObjectBaseRef<Script> mRootScript;
ObjectBaseRef<ProgramFragment> mFragment;
ObjectBaseRef<ProgramVertex> mVertex;
- ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
+ ObjectBaseRef<ProgramStore> mFragmentStore;
ObjectBaseRef<ProgramRaster> mRaster;
struct ObjDestroyOOB {
- pthread_mutex_t mMutex;
+ Mutex mMutex;
Vector<ObjectBase *> mDestroyList;
bool mNeedToEmpty;
};
diff --git a/libs/rs/rsContextHostStub.h b/libs/rs/rsContextHostStub.h
new file mode 100644
index 0000000..be1fff6
--- /dev/null
+++ b/libs/rs/rsContextHostStub.h
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#ifndef ANDROID_RS_CONTEXT_HOST_STUB_H
+#define ANDROID_RS_CONTEXT_HOST_STUB_H
+
+#include "rsUtils.h"
+//#include "rsMutex.h"
+
+//#include "rsThreadIO.h"
+#include "rsType.h"
+#include "rsMatrix.h"
+#include "rsAllocation.h"
+#include "rsSimpleMesh.h"
+#include "rsMesh.h"
+//#include "rsDevice.h"
+#include "rsScriptC.h"
+#include "rsAllocation.h"
+#include "rsAdapter.h"
+#include "rsSampler.h"
+#include "rsLight.h"
+#include "rsProgramFragment.h"
+#include "rsProgramStore.h"
+#include "rsProgramRaster.h"
+#include "rsProgramVertex.h"
+#include "rsShaderCache.h"
+#include "rsVertexArray.h"
+
+//#include "rsgApiStructs.h"
+//#include "rsLocklessFifo.h"
+
+//#include <ui/egl/android_natives.h>
+
+// ---------------------------------------------------------------------------
+namespace android {
+
+namespace renderscript {
+
+class Device;
+
+class Context
+{
+public:
+ Context(Device *, bool isGraphics, bool useDepth) {
+ mObjHead = NULL;
+ }
+ ~Context() {
+ }
+
+
+ //StructuredAllocationContext mStateAllocation;
+ ElementState mStateElement;
+ TypeState mStateType;
+ SamplerState mStateSampler;
+ //ProgramFragmentState mStateFragment;
+ ProgramStoreState mStateFragmentStore;
+ //ProgramRasterState mStateRaster;
+ //ProgramVertexState mStateVertex;
+ LightState mStateLight;
+ VertexArrayState mStateVertexArray;
+
+ //ScriptCState mScriptC;
+ ShaderCache mShaderCache;
+
+
+ //bool setupCheck();
+ bool checkDriver() const {return false;}
+
+ ProgramFragment * getDefaultProgramFragment() const {
+ return NULL;
+ }
+ ProgramVertex * getDefaultProgramVertex() const {
+ return NULL;
+ }
+ ProgramStore * getDefaultProgramStore() const {
+ return NULL;
+ }
+ ProgramRaster * getDefaultProgramRaster() const {
+ return NULL;
+ }
+
+ uint32_t getWidth() const {return 0;}
+ uint32_t getHeight() const {return 0;}
+
+ // Timers
+ enum Timers {
+ RS_TIMER_IDLE,
+ RS_TIMER_INTERNAL,
+ RS_TIMER_SCRIPT,
+ RS_TIMER_CLEAR_SWAP,
+ _RS_TIMER_TOTAL
+ };
+
+ bool checkVersion1_1() const {return false; }
+ bool checkVersion2_0() const {return false; }
+
+ struct {
+ bool mLogTimes;
+ bool mLogScripts;
+ bool mLogObjects;
+ bool mLogShaders;
+ } props;
+
+ void dumpDebug() const { }
+ void checkError(const char *) const { };
+ void setError(RsError e, const char *msg = NULL) { }
+
+ mutable const ObjectBase * mObjHead;
+
+ bool ext_OES_texture_npot() const {return mGL.OES_texture_npot;}
+
+protected:
+
+ struct {
+ const uint8_t * mVendor;
+ const uint8_t * mRenderer;
+ const uint8_t * mVersion;
+ const uint8_t * mExtensions;
+
+ uint32_t mMajorVersion;
+ uint32_t mMinorVersion;
+
+ int32_t mMaxVaryingVectors;
+ int32_t mMaxTextureImageUnits;
+
+ int32_t mMaxFragmentTextureImageUnits;
+ int32_t mMaxFragmentUniformVectors;
+
+ int32_t mMaxVertexAttribs;
+ int32_t mMaxVertexUniformVectors;
+ int32_t mMaxVertexTextureUnits;
+
+ bool OES_texture_npot;
+ } mGL;
+
+};
+
+}
+}
+#endif
diff --git a/libs/rs/rsDevice.cpp b/libs/rs/rsDevice.cpp
index b670ad4..a96b114 100644
--- a/libs/rs/rsDevice.cpp
+++ b/libs/rs/rsDevice.cpp
@@ -15,7 +15,11 @@
*/
#include "rsDevice.h"
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#else
+#include "rsContextHostStub.h"
+#endif
using namespace android;
using namespace android::renderscript;
@@ -33,7 +37,7 @@ Device::~Device()
void Device::addContext(Context *rsc)
{
- mContexts.add(rsc);
+ mContexts.push(rsc);
}
void Device::removeContext(Context *rsc)
diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp
index 6288bc4..8fbf004 100644
--- a/libs/rs/rsElement.cpp
+++ b/libs/rs/rsElement.cpp
@@ -14,9 +14,14 @@
* limitations under the License.
*/
-#include "rsContext.h"
+#ifndef ANDROID_RS_BUILD_FOR_HOST
+#include "rsContext.h"
#include <GLES/gl.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#endif
using namespace android;
using namespace android::renderscript;
@@ -83,6 +88,90 @@ void Element::dumpLOGV(const char *prefix) const
}
}
+void Element::serialize(OStream *stream) const
+{
+ // Need to identify ourselves
+ stream->addU32((uint32_t)getClassId());
+
+ String8 name(getName());
+ stream->addString(&name);
+
+ mComponent.serialize(stream);
+
+ // Now serialize all the fields
+ stream->addU32(mFieldCount);
+ for(uint32_t ct = 0; ct < mFieldCount; ct++) {
+ stream->addString(&mFields[ct].name);
+ mFields[ct].e->serialize(stream);
+ }
+}
+
+Element *Element::createFromStream(Context *rsc, IStream *stream)
+{
+ // First make sure we are reading the correct object
+ RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
+ if(classID != RS_A3D_CLASS_ID_ELEMENT) {
+ LOGE("element loading skipped due to invalid class id\n");
+ return NULL;
+ }
+
+ String8 name;
+ stream->loadString(&name);
+
+ Element *elem = new Element(rsc);
+ elem->mComponent.loadFromStream(stream);
+ elem->mBits = elem->mComponent.getBits();
+
+ elem->mFieldCount = stream->loadU32();
+ if(elem->mFieldCount) {
+ elem->mFields = new ElementField_t [elem->mFieldCount];
+ for(uint32_t ct = 0; ct < elem->mFieldCount; ct ++) {
+ stream->loadString(&elem->mFields[ct].name);
+ Element *fieldElem = Element::createFromStream(rsc, stream);
+ elem->mFields[ct].e.set(fieldElem);
+ }
+ }
+
+ // We need to check if this already exists
+ for (uint32_t ct=0; ct < rsc->mStateElement.mElements.size(); ct++) {
+ Element *ee = rsc->mStateElement.mElements[ct];
+
+ if (!ee->getFieldCount() ) {
+
+ if((ee->getComponent().getType() == elem->getComponent().getType()) &&
+ (ee->getComponent().getKind() == elem->getComponent().getKind()) &&
+ (ee->getComponent().getIsNormalized() == elem->getComponent().getIsNormalized()) &&
+ (ee->getComponent().getVectorSize() == elem->getComponent().getVectorSize())) {
+ // Match
+ delete elem;
+ ee->incUserRef();
+ return ee;
+ }
+
+ } else if (ee->getFieldCount() == elem->mFieldCount) {
+
+ bool match = true;
+ for (uint32_t i=0; i < elem->mFieldCount; i++) {
+ if ((ee->mFields[i].e.get() != elem->mFields[i].e.get()) ||
+ (ee->mFields[i].name.length() != elem->mFields[i].name.length()) ||
+ (ee->mFields[i].name != elem->mFields[i].name)) {
+ match = false;
+ break;
+ }
+ }
+ if (match) {
+ delete elem;
+ ee->incUserRef();
+ return ee;
+ }
+
+ }
+ }
+
+ rsc->mStateElement.mElements.push(elem);
+ return elem;
+}
+
const Element * Element::create(Context *rsc, RsDataType dt, RsDataKind dk,
bool isNorm, uint32_t vecSize)
diff --git a/libs/rs/rsElement.h b/libs/rs/rsElement.h
index 02a1ca2..5c4f5c4 100644
--- a/libs/rs/rsElement.h
+++ b/libs/rs/rsElement.h
@@ -59,6 +59,9 @@ public:
String8 getGLSLType(uint32_t indent=0) const;
void dumpLOGV(const char *prefix) const;
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_ELEMENT; }
+ static Element *createFromStream(Context *rsc, IStream *stream);
static const Element * create(Context *rsc, RsDataType dt, RsDataKind dk,
bool isNorm, uint32_t vecSize);
@@ -90,7 +93,7 @@ public:
~ElementState();
// Cache of all existing elements.
- Vector<const Element *> mElements;
+ Vector<Element *> mElements;
};
diff --git a/libs/rs/rsFileA3D.cpp b/libs/rs/rsFileA3D.cpp
index e3272c5..23c0cf5 100644
--- a/libs/rs/rsFileA3D.cpp
+++ b/libs/rs/rsFileA3D.cpp
@@ -15,29 +15,155 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#else
+#include "rsContextHostStub.h"
+#endif
-
-#include <utils/String8.h>
#include "rsFileA3D.h"
#include "rsMesh.h"
+#include "rsAnimation.h"
using namespace android;
using namespace android::renderscript;
+FileA3D::FileA3D(Context *rsc) : ObjectBase(rsc)
+{
+ mAlloc = NULL;
+ mData = NULL;
+ mWriteStream = NULL;
+ mReadStream = NULL;
+
+ mMajorVersion = 0;
+ mMinorVersion = 1;
+ mDataSize = 0;
+}
+FileA3D::~FileA3D()
+{
+ for(size_t i = 0; i < mIndex.size(); i ++) {
+ delete mIndex[i];
+ }
+ for(size_t i = 0; i < mWriteIndex.size(); i ++) {
+ delete mWriteIndex[i];
+ }
+ if(mWriteStream) {
+ delete mWriteStream;
+ }
+ if(mReadStream) {
+ delete mWriteStream;
+ }
+ if(mAlloc) {
+ free(mAlloc);
+ }
+}
-FileA3D::FileA3D()
+void FileA3D::parseHeader(IStream *headerStream)
{
- mRsc = NULL;
+ mMajorVersion = headerStream->loadU32();
+ mMinorVersion = headerStream->loadU32();
+ uint32_t flags = headerStream->loadU32();
+ mUse64BitOffsets = (flags & 1) != 0;
+
+ LOGE("file open 64bit = %i", mUse64BitOffsets);
+
+ uint32_t numIndexEntries = headerStream->loadU32();
+ for(uint32_t i = 0; i < numIndexEntries; i ++) {
+ A3DIndexEntry *entry = new A3DIndexEntry();
+ headerStream->loadString(&entry->mObjectName);
+ LOGE("Header data, entry name = %s", entry->mObjectName.string());
+ entry->mType = (RsA3DClassID)headerStream->loadU32();
+ if(mUse64BitOffsets){
+ entry->mOffset = headerStream->loadOffset();
+ entry->mLength = headerStream->loadOffset();
+ }
+ else {
+ entry->mOffset = headerStream->loadU32();
+ entry->mLength = headerStream->loadU32();
+ }
+ entry->mRsObj = NULL;
+ mIndex.push(entry);
+ }
}
-FileA3D::~FileA3D()
+bool FileA3D::load(const void *data, size_t length)
{
+ LOGE("Loading data. Size: %u", length);
+ const uint8_t *localData = (const uint8_t *)data;
+
+ size_t lengthRemaining = length;
+ size_t magicStrLen = 12;
+ if ((length < magicStrLen) ||
+ memcmp(data, "Android3D_ff", magicStrLen)) {
+ return false;
+ }
+
+ localData += magicStrLen;
+ lengthRemaining -= magicStrLen;
+
+ // Next we get our header size
+ uint64_t headerSize = 0;
+ if(lengthRemaining < sizeof(headerSize)) {
+ return false;
+ }
+
+ memcpy(&headerSize, localData, sizeof(headerSize));
+ localData += sizeof(headerSize);
+ lengthRemaining -= sizeof(headerSize);
+
+ LOGE("Loading data, headerSize = %lli", headerSize);
+
+ if(lengthRemaining < headerSize) {
+ return false;
+ }
+
+ uint8_t *headerData = (uint8_t *)malloc(headerSize);
+ if(!headerData) {
+ return false;
+ }
+
+ memcpy(headerData, localData, headerSize);
+
+ // Now open the stream to parse the header
+ IStream headerStream(headerData, false);
+ parseHeader(&headerStream);
+
+ free(headerData);
+
+ localData += headerSize;
+ lengthRemaining -= headerSize;
+
+ if(lengthRemaining < sizeof(mDataSize)) {
+ return false;
+ }
+
+ // Read the size of the data
+ memcpy(&mDataSize, localData, sizeof(mDataSize));
+ localData += sizeof(mDataSize);
+ lengthRemaining -= sizeof(mDataSize);
+
+ LOGE("Loading data, mDataSize = %lli", mDataSize);
+
+ if(lengthRemaining < mDataSize) {
+ return false;
+ }
+
+ // We should know enough to read the file in at this point.
+ mAlloc = malloc(mDataSize);
+ if (!mAlloc) {
+ return false;
+ }
+ mData = (uint8_t *)mAlloc;
+ memcpy(mAlloc, localData, mDataSize);
+
+ mReadStream = new IStream(mData, mUse64BitOffsets);
+
+ return true;
}
-bool FileA3D::load(Context *rsc, FILE *f)
+bool FileA3D::load(FILE *f)
{
char magicString[12];
size_t len;
@@ -49,47 +175,39 @@ bool FileA3D::load(Context *rsc, FILE *f)
return false;
}
- LOGE("file open 2");
- len = fread(&mMajorVersion, 1, sizeof(mMajorVersion), f);
- if (len != sizeof(mMajorVersion)) {
+ // Next thing is the size of the header
+ uint64_t headerSize = 0;
+ len = fread(&headerSize, 1, sizeof(headerSize), f);
+ if (len != sizeof(headerSize) || headerSize == 0) {
return false;
}
- LOGE("file open 3");
- len = fread(&mMinorVersion, 1, sizeof(mMinorVersion), f);
- if (len != sizeof(mMinorVersion)) {
+ uint8_t *headerData = (uint8_t *)malloc(headerSize);
+ if(!headerData) {
return false;
}
- LOGE("file open 4");
- uint32_t flags;
- len = fread(&flags, 1, sizeof(flags), f);
- if (len != sizeof(flags)) {
+ len = fread(headerData, 1, headerSize, f);
+ if (len != headerSize) {
return false;
}
- mUse64BitOffsets = (flags & 1) != 0;
- LOGE("file open 64bit = %i", mUse64BitOffsets);
+ // Now open the stream to parse the header
+ IStream headerStream(headerData, false);
+ parseHeader(&headerStream);
- if (mUse64BitOffsets) {
- len = fread(&mDataSize, 1, sizeof(mDataSize), f);
- if (len != sizeof(mDataSize)) {
- return false;
- }
- } else {
- uint32_t tmp;
- len = fread(&tmp, 1, sizeof(tmp), f);
- if (len != sizeof(tmp)) {
- return false;
- }
- mDataSize = tmp;
+ free(headerData);
+
+ // Next thing is the size of the header
+ len = fread(&mDataSize, 1, sizeof(mDataSize), f);
+ if (len != sizeof(mDataSize) || mDataSize == 0) {
+ return false;
}
LOGE("file open size = %lli", mDataSize);
// We should know enough to read the file in at this point.
- fseek(f, SEEK_SET, 0);
- mAlloc= malloc(mDataSize);
+ mAlloc = malloc(mDataSize);
if (!mAlloc) {
return false;
}
@@ -99,282 +217,258 @@ bool FileA3D::load(Context *rsc, FILE *f)
return false;
}
- LOGE("file start processing");
- return process(rsc);
+ mReadStream = new IStream(mData, mUse64BitOffsets);
+
+ LOGE("Header is read an stream initialized");
+ return true;
}
-bool FileA3D::processIndex(Context *rsc, A3DIndexEntry *ie)
-{
- bool ret = false;
- IO io(mData + ie->mOffset, mUse64BitOffsets);
-
- LOGE("process index, type %i", ie->mType);
-
- switch(ie->mType) {
- case CHUNK_ELEMENT:
- processChunk_Element(rsc, &io, ie);
- break;
- case CHUNK_ELEMENT_SOURCE:
- processChunk_ElementSource(rsc, &io, ie);
- break;
- case CHUNK_VERTICIES:
- processChunk_Verticies(rsc, &io, ie);
- break;
- case CHUNK_MESH:
- processChunk_Mesh(rsc, &io, ie);
- break;
- case CHUNK_PRIMITIVE:
- processChunk_Primitive(rsc, &io, ie);
- break;
- default:
- LOGE("FileA3D Unknown chunk type");
- break;
- }
- return (ie->mRsObj != NULL);
+size_t FileA3D::getNumIndexEntries() const {
+ return mIndex.size();
}
-bool FileA3D::process(Context *rsc)
-{
- LOGE("process");
- IO io(mData + 12, mUse64BitOffsets);
- bool ret = true;
-
- // Build the index first
- LOGE("process 1");
- io.loadU32(); // major version, already loaded
- io.loadU32(); // minor version, already loaded
- LOGE("process 2");
-
- io.loadU32(); // flags
- io.loadOffset(); // filesize, already loaded.
- LOGE("process 4");
- uint64_t mIndexOffset = io.loadOffset();
- uint64_t mStringOffset = io.loadOffset();
-
- LOGE("process mIndexOffset= 0x%016llx", mIndexOffset);
- LOGE("process mStringOffset= 0x%016llx", mStringOffset);
-
- IO index(mData + mIndexOffset, mUse64BitOffsets);
- IO stringTable(mData + mStringOffset, mUse64BitOffsets);
-
- uint32_t stringEntryCount = stringTable.loadU32();
- LOGE("stringEntryCount %i", stringEntryCount);
- mStrings.setCapacity(stringEntryCount);
- mStringIndexValues.setCapacity(stringEntryCount);
- if (stringEntryCount) {
- uint32_t stringType = stringTable.loadU32();
- LOGE("stringType %i", stringType);
- rsAssert(stringType==0);
- for (uint32_t ct = 0; ct < stringEntryCount; ct++) {
- uint64_t offset = stringTable.loadOffset();
- LOGE("string offset 0x%016llx", offset);
- IO tmp(mData + offset, mUse64BitOffsets);
- String8 s;
- tmp.loadString(&s);
- LOGE("string %s", s.string());
- mStrings.push(s);
- }
+const FileA3D::A3DIndexEntry *FileA3D::getIndexEntry(size_t index) const {
+ if(index < mIndex.size()) {
+ return mIndex[index];
}
+ return NULL;
+}
- LOGE("strings done");
- uint32_t indexEntryCount = index.loadU32();
- LOGE("index count %i", indexEntryCount);
- mIndex.setCapacity(indexEntryCount);
- for (uint32_t ct = 0; ct < indexEntryCount; ct++) {
- A3DIndexEntry e;
- uint32_t stringIndex = index.loadU32();
- LOGE("index %i", ct);
- LOGE(" string index %i", stringIndex);
- e.mType = (A3DChunkType)index.loadU32();
- LOGE(" type %i", e.mType);
- e.mOffset = index.loadOffset();
- LOGE(" offset 0x%016llx", e.mOffset);
-
- if (stringIndex && (stringIndex < mStrings.size())) {
- e.mID = mStrings[stringIndex];
- mStringIndexValues.editItemAt(stringIndex) = ct;
- LOGE(" id %s", e.mID.string());
- }
+ObjectBase *FileA3D::initializeFromEntry(size_t index) {
+ if(index >= mIndex.size()) {
+ return NULL;
+ }
- mIndex.push(e);
+ FileA3D::A3DIndexEntry *entry = mIndex[index];
+ if(!entry) {
+ return NULL;
}
- LOGE("index done");
- // At this point the index should be fully populated.
- // We can now walk though it and load all the objects.
- for (uint32_t ct = 0; ct < indexEntryCount; ct++) {
- LOGE("processing index entry %i", ct);
- processIndex(rsc, &mIndex.editItemAt(ct));
+ if(entry->mRsObj) {
+ entry->mRsObj->incUserRef();
+ return entry->mRsObj;
}
- return ret;
+ // Seek to the beginning of object
+ mReadStream->reset(entry->mOffset);
+ switch (entry->mType) {
+ case RS_A3D_CLASS_ID_UNKNOWN:
+ return NULL;
+ case RS_A3D_CLASS_ID_MESH:
+ entry->mRsObj = Mesh::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_SIMPLE_MESH:
+ entry->mRsObj = SimpleMesh::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_TYPE:
+ entry->mRsObj = Type::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_ELEMENT:
+ entry->mRsObj = Element::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_ALLOCATION:
+ entry->mRsObj = Allocation::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_PROGRAM_VERTEX:
+ entry->mRsObj = ProgramVertex::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_PROGRAM_RASTER:
+ entry->mRsObj = ProgramRaster::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_PROGRAM_FRAGMENT:
+ entry->mRsObj = ProgramFragment::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_PROGRAM_STORE:
+ entry->mRsObj = ProgramStore::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_SAMPLER:
+ entry->mRsObj = Sampler::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_ANIMATION:
+ entry->mRsObj = Animation::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_LIGHT:
+ entry->mRsObj = Light::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_ADAPTER_1D:
+ entry->mRsObj = Adapter1D::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_ADAPTER_2D:
+ entry->mRsObj = Adapter2D::createFromStream(mRSC, mReadStream);
+ break;
+ case RS_A3D_CLASS_ID_SCRIPT_C:
+ return NULL;
+ }
+ if(entry->mRsObj) {
+ entry->mRsObj->incUserRef();
+ }
+ return entry->mRsObj;
}
-
-FileA3D::IO::IO(const uint8_t *buf, bool use64)
+bool FileA3D::writeFile(const char *filename)
{
- mData = buf;
- mPos = 0;
- mUse64 = use64;
-}
+ if(!mWriteStream) {
+ LOGE("No objects to write\n");
+ return false;
+ }
+ if(mWriteStream->getPos() == 0) {
+ LOGE("No objects to write\n");
+ return false;
+ }
-uint64_t FileA3D::IO::loadOffset()
-{
- uint64_t tmp;
- if (mUse64) {
- mPos = (mPos + 7) & (~7);
- tmp = reinterpret_cast<const uint64_t *>(&mData[mPos])[0];
- mPos += sizeof(uint64_t);
- return tmp;
- }
- return loadU32();
-}
+ FILE *writeHandle = fopen(filename, "wb");
+ if(!writeHandle) {
+ LOGE("Couldn't open the file for writing\n");
+ return false;
+ }
-void FileA3D::IO::loadString(String8 *s)
-{
- LOGE("loadString");
- uint32_t len = loadU32();
- LOGE("loadString len %i", len);
- s->setTo((const char *)&mData[mPos], len);
- mPos += len;
-}
+ // Open a new stream to make writing the header easier
+ OStream headerStream(5*1024, false);
+ headerStream.addU32(mMajorVersion);
+ headerStream.addU32(mMinorVersion);
+ uint32_t is64Bit = 0;
+ headerStream.addU32(is64Bit);
+
+ uint32_t writeIndexSize = mWriteIndex.size();
+ headerStream.addU32(writeIndexSize);
+ for(uint32_t i = 0; i < writeIndexSize; i ++) {
+ headerStream.addString(&mWriteIndex[i]->mObjectName);
+ headerStream.addU32((uint32_t)mWriteIndex[i]->mType);
+ if(mUse64BitOffsets){
+ headerStream.addOffset(mWriteIndex[i]->mOffset);
+ headerStream.addOffset(mWriteIndex[i]->mLength);
+ }
+ else {
+ uint32_t offset = (uint32_t)mWriteIndex[i]->mOffset;
+ headerStream.addU32(offset);
+ offset = (uint32_t)mWriteIndex[i]->mLength;
+ headerStream.addU32(offset);
+ }
+ }
+ // Write our magic string so we know we are reading the right file
+ String8 magicString(A3D_MAGIC_KEY);
+ fwrite(magicString.string(), sizeof(char), magicString.size(), writeHandle);
-void FileA3D::processChunk_Mesh(Context *rsc, IO *io, A3DIndexEntry *ie)
-{
- Mesh * m = new Mesh(rsc);
+ // Store the size of the header to make it easier to parse when we read it
+ uint64_t headerSize = headerStream.getPos();
+ fwrite(&headerSize, sizeof(headerSize), 1, writeHandle);
- m->mPrimitivesCount = io->loadU32();
- m->mPrimitives = new Mesh::Primitive_t *[m->mPrimitivesCount];
+ // Now write our header
+ fwrite(headerStream.getPtr(), sizeof(uint8_t), headerStream.getPos(), writeHandle);
- for (uint32_t ct = 0; ct < m->mPrimitivesCount; ct++) {
- uint32_t index = io->loadU32();
+ // Now write the size of the data part of the file for easier parsing later
+ uint64_t fileDataSize = mWriteStream->getPos();
+ fwrite(&fileDataSize, sizeof(fileDataSize), 1, writeHandle);
- m->mPrimitives[ct] = (Mesh::Primitive_t *)mIndex[index].mRsObj;
+ fwrite(mWriteStream->getPtr(), sizeof(uint8_t), mWriteStream->getPos(), writeHandle);
+
+ int status = fclose(writeHandle);
+
+ if(status != 0) {
+ LOGE("Couldn't close file\n");
+ return false;
}
- ie->mRsObj = m;
+
+ return true;
}
-void FileA3D::processChunk_Primitive(Context *rsc, IO *io, A3DIndexEntry *ie)
+void FileA3D::appendToFile(ObjectBase *obj) {
+ if(!obj) {
+ return;
+ }
+ if(!mWriteStream) {
+ const uint64_t initialStreamSize = 256*1024;
+ mWriteStream = new OStream(initialStreamSize, false);
+ }
+ A3DIndexEntry *indexEntry = new A3DIndexEntry();
+ indexEntry->mObjectName.setTo(obj->getName());
+ indexEntry->mType = obj->getClassId();
+ indexEntry->mOffset = mWriteStream->getPos();
+ indexEntry->mRsObj = obj;
+ mWriteIndex.push(indexEntry);
+ obj->serialize(mWriteStream);
+ indexEntry->mLength = mWriteStream->getPos() - indexEntry->mOffset;
+ mWriteStream->align(4);
+}
+
+namespace android {
+namespace renderscript {
+
+void rsi_FileA3DGetNumIndexEntries(Context *rsc, int32_t *numEntries, RsFile file)
{
- Mesh::Primitive_t * p = new Mesh::Primitive_t;
+ FileA3D *fa3d = static_cast<FileA3D *>(file);
- p->mIndexCount = io->loadU32();
- uint32_t vertIdx = io->loadU32();
- p->mRestartCounts = io->loadU16();
- uint32_t bits = io->loadU8();
- p->mType = (RsPrimitive)io->loadU8();
+ if(fa3d) {
+ *numEntries = fa3d->getNumIndexEntries();
+ }
+ else {
+ *numEntries = 0;
+ }
+}
- LOGE("processChunk_Primitive count %i, bits %i", p->mIndexCount, bits);
+void rsi_FileA3DGetIndexEntries(Context *rsc, RsFileIndexEntry *fileEntries, uint32_t numEntries, RsFile file)
+{
+ FileA3D *fa3d = static_cast<FileA3D *>(file);
- p->mVerticies = (Mesh::Verticies_t *)mIndex[vertIdx].mRsObj;
+ if(!fa3d) {
+ LOGE("Can't load index entries. No valid file");
+ return;
+ }
- p->mIndicies = new uint16_t[p->mIndexCount];
- for (uint32_t ct = 0; ct < p->mIndexCount; ct++) {
- switch(bits) {
- case 8:
- p->mIndicies[ct] = io->loadU8();
- break;
- case 16:
- p->mIndicies[ct] = io->loadU16();
- break;
- case 32:
- p->mIndicies[ct] = io->loadU32();
- break;
- }
- LOGE(" idx %i", p->mIndicies[ct]);
- }
-
- if (p->mRestartCounts) {
- p->mRestarts = new uint16_t[p->mRestartCounts];
- for (uint32_t ct = 0; ct < p->mRestartCounts; ct++) {
- switch(bits) {
- case 8:
- p->mRestarts[ct] = io->loadU8();
- break;
- case 16:
- p->mRestarts[ct] = io->loadU16();
- break;
- case 32:
- p->mRestarts[ct] = io->loadU32();
- break;
- }
- LOGE(" idx %i", p->mRestarts[ct]);
- }
- } else {
- p->mRestarts = NULL;
+ uint32_t numFileEntries = fa3d->getNumIndexEntries();
+ if(numFileEntries != numEntries || numEntries == 0 || fileEntries == NULL) {
+ LOGE("Can't load index entries. Invalid number requested");
+ return;
}
- ie->mRsObj = p;
-}
+ for(uint32_t i = 0; i < numFileEntries; i ++) {
+ const FileA3D::A3DIndexEntry *entry = fa3d->getIndexEntry(i);
+ fileEntries[i].classID = entry->getType();
+ fileEntries[i].objectName = entry->getObjectName().string();
+ }
-void FileA3D::processChunk_Verticies(Context *rsc, IO *io, A3DIndexEntry *ie)
-{
- Mesh::Verticies_t *cv = new Mesh::Verticies_t;
- cv->mAllocationCount = io->loadU32();
- cv->mAllocations = new Allocation *[cv->mAllocationCount];
- LOGE("processChunk_Verticies count %i", cv->mAllocationCount);
- for (uint32_t ct = 0; ct < cv->mAllocationCount; ct++) {
- uint32_t i = io->loadU32();
- cv->mAllocations[ct] = (Allocation *)mIndex[i].mRsObj;
- LOGE(" idx %i", i);
- }
- ie->mRsObj = cv;
}
-void FileA3D::processChunk_Element(Context *rsc, IO *io, A3DIndexEntry *ie)
+RsObjectBase rsi_FileA3DGetEntryByIndex(Context *rsc, uint32_t index, RsFile file)
{
- /*
- rsi_ElementBegin(rsc);
-
- uint32_t count = io->loadU32();
- LOGE("processChunk_Element count %i", count);
- while (count--) {
- RsDataKind dk = (RsDataKind)io->loadU8();
- RsDataType dt = (RsDataType)io->loadU8();
- uint32_t bits = io->loadU8();
- bool isNorm = io->loadU8() != 0;
- LOGE(" %i %i %i %i", dk, dt, bits, isNorm);
- rsi_ElementAdd(rsc, dk, dt, isNorm, bits, 0);
- }
- LOGE("processChunk_Element create");
- ie->mRsObj = rsi_ElementCreate(rsc);
- */
+ FileA3D *fa3d = static_cast<FileA3D *>(file);
+ if(!fa3d) {
+ LOGE("Can't load entry. No valid file");
+ return NULL;
+ }
+
+ ObjectBase *obj = fa3d->initializeFromEntry(index);
+ LOGE("Returning object with name %s", obj->getName());
+
+ return obj;
}
-void FileA3D::processChunk_ElementSource(Context *rsc, IO *io, A3DIndexEntry *ie)
+RsFile rsi_FileA3DCreateFromAssetStream(Context *rsc, const void *data, uint32_t len)
{
- uint32_t index = io->loadU32();
- uint32_t count = io->loadU32();
-
- LOGE("processChunk_ElementSource count %i, index %i", count, index);
+ if (data == NULL) {
+ LOGE("File load failed. Asset stream is NULL");
+ return NULL;
+ }
- RsElement e = (RsElement)mIndex[index].mRsObj;
+ FileA3D *fa3d = new FileA3D(rsc);
- RsAllocation a = rsi_AllocationCreateSized(rsc, e, count);
- Allocation * alloc = static_cast<Allocation *>(a);
+ fa3d->load(data, len);
+ fa3d->incUserRef();
- float * data = (float *)alloc->getPtr();
- while(count--) {
- *data = io->loadF();
- LOGE(" %f", *data);
- data++;
- }
- ie->mRsObj = alloc;
+ return fa3d;
}
-namespace android {
-namespace renderscript {
-
RsFile rsi_FileOpen(Context *rsc, char const *path, unsigned int len)
{
- FileA3D *fa3d = new FileA3D;
+ FileA3D *fa3d = new FileA3D(rsc);
FILE *f = fopen("/sdcard/test.a3d", "rb");
if (f) {
- fa3d->load(rsc, f);
+ fa3d->load(f);
fclose(f);
+ fa3d->incUserRef();
return fa3d;
}
delete fa3d;
diff --git a/libs/rs/rsFileA3D.h b/libs/rs/rsFileA3D.h
index 9ee08ec..b985907 100644
--- a/libs/rs/rsFileA3D.h
+++ b/libs/rs/rsFileA3D.h
@@ -18,20 +18,23 @@
#define ANDROID_RS_FILE_A3D_H
#include "RenderScript.h"
-#include "rsFileA3DDecls.h"
#include "rsMesh.h"
#include <utils/String8.h>
+#include "rsStream.h"
#include <stdio.h>
+#define A3D_MAGIC_KEY "Android3D_ff"
+
// ---------------------------------------------------------------------------
namespace android {
+
namespace renderscript {
-class FileA3D
+class FileA3D : public ObjectBase
{
public:
- FileA3D();
+ FileA3D(Context *rsc);
~FileA3D();
uint32_t mMajorVersion;
@@ -40,78 +43,53 @@ public:
uint64_t mStringTableOffset;
bool mUse64BitOffsets;
- struct A3DIndexEntry {
- String8 mID;
- A3DChunkType mType;
+ class A3DIndexEntry {
+ String8 mObjectName;
+ RsA3DClassID mType;
uint64_t mOffset;
- void * mRsObj;
- };
-
- bool load(Context *rsc, FILE *f);
-
-protected:
- class IO
- {
+ uint64_t mLength;
+ ObjectBase *mRsObj;
public:
- IO(const uint8_t *, bool use64);
-
- float loadF() {
- mPos = (mPos + 3) & (~3);
- float tmp = reinterpret_cast<const float *>(&mData[mPos])[0];
- mPos += sizeof(float);
- return tmp;
- }
- int32_t loadI32() {
- mPos = (mPos + 3) & (~3);
- int32_t tmp = reinterpret_cast<const int32_t *>(&mData[mPos])[0];
- mPos += sizeof(int32_t);
- return tmp;
+ friend class FileA3D;
+ const String8 &getObjectName() const {
+ return mObjectName;
}
- uint32_t loadU32() {
- mPos = (mPos + 3) & (~3);
- uint32_t tmp = reinterpret_cast<const uint32_t *>(&mData[mPos])[0];
- mPos += sizeof(uint32_t);
- return tmp;
+ RsA3DClassID getType() const {
+ return mType;
}
- uint16_t loadU16() {
- mPos = (mPos + 1) & (~1);
- uint16_t tmp = reinterpret_cast<const uint16_t *>(&mData[mPos])[0];
- mPos += sizeof(uint16_t);
- return tmp;
- }
- uint8_t loadU8() {
- uint8_t tmp = reinterpret_cast<const uint8_t *>(&mData[mPos])[0];
- mPos += sizeof(uint8_t);
- return tmp;
- }
- uint64_t loadOffset();
- void loadString(String8 *s);
- uint64_t getPos() const {return mPos;}
- const uint8_t * getPtr() const;
- protected:
- const uint8_t * mData;
- uint64_t mPos;
- bool mUse64;
};
+ bool load(FILE *f);
+ bool load(const void *data, size_t length);
+
+ size_t getNumIndexEntries() const;
+ const A3DIndexEntry* getIndexEntry(size_t index) const;
+ ObjectBase *initializeFromEntry(size_t index);
+
+ void appendToFile(ObjectBase *obj);
+ bool writeFile(const char *filename);
+
+ // Currently files do not get serialized,
+ // but we need to inherit from ObjectBase for ref tracking
+ virtual void serialize(OStream *stream) const {
+ }
+ virtual RsA3DClassID getClassId() const {
+ return RS_A3D_CLASS_ID_UNKNOWN;
+ }
+
+protected:
- bool process(Context *rsc);
- bool processIndex(Context *rsc, A3DIndexEntry *);
- void processChunk_Mesh(Context *rsc, IO *io, A3DIndexEntry *ie);
- void processChunk_Primitive(Context *rsc, IO *io, A3DIndexEntry *ie);
- void processChunk_Verticies(Context *rsc, IO *io, A3DIndexEntry *ie);
- void processChunk_Element(Context *rsc, IO *io, A3DIndexEntry *ie);
- void processChunk_ElementSource(Context *rsc, IO *io, A3DIndexEntry *ie);
+ void parseHeader(IStream *headerStream);
const uint8_t * mData;
void * mAlloc;
uint64_t mDataSize;
- Context * mRsc;
- Vector<A3DIndexEntry> mIndex;
- Vector<String8> mStrings;
- Vector<uint32_t> mStringIndexValues;
+ OStream *mWriteStream;
+ Vector<A3DIndexEntry*> mWriteIndex;
+ IStream *mReadStream;
+ Vector<A3DIndexEntry*> mIndex;
};
diff --git a/libs/rs/rsHandcode.h b/libs/rs/rsHandcode.h
index 800eddd..f6e56ac 100644
--- a/libs/rs/rsHandcode.h
+++ b/libs/rs/rsHandcode.h
@@ -1,6 +1,49 @@
#define DATA_SYNC_SIZE 1024
+static inline void rsHCAPI_ScriptInvokeV (RsContext rsc, RsScript va, uint32_t slot, const void * data, uint32_t sizeBytes)
+{
+ ThreadIO *io = &((Context *)rsc)->mIO;
+ uint32_t size = sizeof(RS_CMD_ScriptInvokeV);
+ if (sizeBytes < DATA_SYNC_SIZE) {
+ size += (sizeBytes + 3) & ~3;
+ }
+ RS_CMD_ScriptInvokeV *cmd = static_cast<RS_CMD_ScriptInvokeV *>(io->mToCore.reserve(size));
+ cmd->s = va;
+ cmd->slot = slot;
+ cmd->dataLen = sizeBytes;
+ cmd->data = data;
+ if (sizeBytes < DATA_SYNC_SIZE) {
+ cmd->data = (void *)(cmd+1);
+ memcpy(cmd+1, data, sizeBytes);
+ io->mToCore.commit(RS_CMD_ID_ScriptInvokeV, size);
+ } else {
+ io->mToCore.commitSync(RS_CMD_ID_ScriptInvokeV, size);
+ }
+}
+
+
+static inline void rsHCAPI_ScriptSetVarV (RsContext rsc, RsScript va, uint32_t slot, const void * data, uint32_t sizeBytes)
+{
+ ThreadIO *io = &((Context *)rsc)->mIO;
+ uint32_t size = sizeof(RS_CMD_ScriptSetVarV);
+ if (sizeBytes < DATA_SYNC_SIZE) {
+ size += (sizeBytes + 3) & ~3;
+ }
+ RS_CMD_ScriptSetVarV *cmd = static_cast<RS_CMD_ScriptSetVarV *>(io->mToCore.reserve(size));
+ cmd->s = va;
+ cmd->slot = slot;
+ cmd->dataLen = sizeBytes;
+ cmd->data = data;
+ if (sizeBytes < DATA_SYNC_SIZE) {
+ cmd->data = (void *)(cmd+1);
+ memcpy(cmd+1, data, sizeBytes);
+ io->mToCore.commit(RS_CMD_ID_ScriptSetVarV, size);
+ } else {
+ io->mToCore.commitSync(RS_CMD_ID_ScriptSetVarV, size);
+ }
+}
+
static inline void rsHCAPI_AllocationData (RsContext rsc, RsAllocation va, const void * data, uint32_t sizeBytes)
{
ThreadIO *io = &((Context *)rsc)->mIO;
diff --git a/libs/rs/rsLight.cpp b/libs/rs/rsLight.cpp
index 6f2cf3e..eab9a07 100644
--- a/libs/rs/rsLight.cpp
+++ b/libs/rs/rsLight.cpp
@@ -14,9 +14,13 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-
#include <GLES/gl.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#endif //ANDROID_RS_BUILD_FOR_HOST
using namespace android;
using namespace android::renderscript;
@@ -65,6 +69,16 @@ void Light::setupGL(uint32_t num) const
glLightfv(GL_LIGHT0 + num, GL_POSITION, mPosition);
}
+void Light::serialize(OStream *stream) const
+{
+
+}
+
+Light *Light::createFromStream(Context *rsc, IStream *stream)
+{
+ return NULL;
+}
+
////////////////////////////////////////////
LightState::LightState()
diff --git a/libs/rs/rsLight.h b/libs/rs/rsLight.h
index d8796e6..bd58979 100644
--- a/libs/rs/rsLight.h
+++ b/libs/rs/rsLight.h
@@ -37,6 +37,9 @@ public:
void setColor(float r, float g, float b);
void setupGL(uint32_t num) const;
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_LIGHT; }
+ static Light *createFromStream(Context *rsc, IStream *stream);
protected:
float mColor[4];
diff --git a/libs/rs/rsLocklessFifo.cpp b/libs/rs/rsLocklessFifo.cpp
index c796520..76ca32e 100644
--- a/libs/rs/rsLocklessFifo.cpp
+++ b/libs/rs/rsLocklessFifo.cpp
@@ -17,7 +17,7 @@
#include "rsLocklessFifo.h"
using namespace android;
-
+using namespace android::renderscript;
LocklessCommandFifo::LocklessCommandFifo()
{
@@ -128,15 +128,19 @@ void LocklessCommandFifo::flush()
//dumpState("flush 2");
}
+void LocklessCommandFifo::wait()
+{
+ while(isEmpty() && !mInShutdown) {
+ mSignalToControl.set();
+ mSignalToWorker.wait();
+ }
+}
+
const void * LocklessCommandFifo::get(uint32_t *command, uint32_t *bytesData)
{
while(1) {
//dumpState("get");
- while(isEmpty() && !mInShutdown) {
- mSignalToControl.set();
- mSignalToWorker.wait();
- }
-
+ wait();
if (mInShutdown) {
*command = 0;
*bytesData = 0;
@@ -192,79 +196,3 @@ void LocklessCommandFifo::dumpState(const char *s) const
LOGV("%s put %p, get %p, buf %p, end %p", s, mPut, mGet, mBuffer, mEnd);
}
-LocklessCommandFifo::Signal::Signal()
-{
- mSet = true;
-}
-
-LocklessCommandFifo::Signal::~Signal()
-{
- pthread_mutex_destroy(&mMutex);
- pthread_cond_destroy(&mCondition);
-}
-
-bool LocklessCommandFifo::Signal::init()
-{
- int status = pthread_mutex_init(&mMutex, NULL);
- if (status) {
- LOGE("LocklessFifo mutex init failure");
- return false;
- }
-
- status = pthread_cond_init(&mCondition, NULL);
- if (status) {
- LOGE("LocklessFifo condition init failure");
- pthread_mutex_destroy(&mMutex);
- return false;
- }
-
- return true;
-}
-
-void LocklessCommandFifo::Signal::set()
-{
- int status;
-
- status = pthread_mutex_lock(&mMutex);
- if (status) {
- LOGE("LocklessCommandFifo: error %i locking for set condition.", status);
- return;
- }
-
- mSet = true;
-
- status = pthread_cond_signal(&mCondition);
- if (status) {
- LOGE("LocklessCommandFifo: error %i on set condition.", status);
- }
-
- status = pthread_mutex_unlock(&mMutex);
- if (status) {
- LOGE("LocklessCommandFifo: error %i unlocking for set condition.", status);
- }
-}
-
-void LocklessCommandFifo::Signal::wait()
-{
- int status;
-
- status = pthread_mutex_lock(&mMutex);
- if (status) {
- LOGE("LocklessCommandFifo: error %i locking for condition.", status);
- return;
- }
-
- if (!mSet) {
- status = pthread_cond_wait(&mCondition, &mMutex);
- if (status) {
- LOGE("LocklessCommandFifo: error %i waiting on condition.", status);
- }
- }
- mSet = false;
-
- status = pthread_mutex_unlock(&mMutex);
- if (status) {
- LOGE("LocklessCommandFifo: error %i unlocking for condition.", status);
- }
-}
-
diff --git a/libs/rs/rsLocklessFifo.h b/libs/rs/rsLocklessFifo.h
index d0a4356..ae906ca 100644
--- a/libs/rs/rsLocklessFifo.h
+++ b/libs/rs/rsLocklessFifo.h
@@ -19,8 +19,10 @@
#include "rsUtils.h"
+#include "rsSignal.h"
namespace android {
+namespace renderscript {
// A simple FIFO to be used as a producer / consumer between two
@@ -37,24 +39,7 @@ public:
LocklessCommandFifo();
~LocklessCommandFifo();
-
protected:
- class Signal {
- public:
- Signal();
- ~Signal();
-
- bool init();
-
- void set();
- void wait();
-
- protected:
- bool mSet;
- pthread_mutex_t mMutex;
- pthread_cond_t mCondition;
- };
-
uint8_t * volatile mPut;
uint8_t * volatile mGet;
uint8_t * mBuffer;
@@ -65,14 +50,14 @@ protected:
Signal mSignalToWorker;
Signal mSignalToControl;
-
-
public:
void * reserve(uint32_t bytes);
void commit(uint32_t command, uint32_t bytes);
void commitSync(uint32_t command, uint32_t bytes);
void flush();
+ void wait();
+
const void * get(uint32_t *command, uint32_t *bytesData);
void next();
@@ -88,4 +73,5 @@ private:
}
+}
#endif
diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp
index d595b4e..bd9cd27 100644
--- a/libs/rs/rsMesh.cpp
+++ b/libs/rs/rsMesh.cpp
@@ -14,13 +14,22 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-using namespace android;
-using namespace android::renderscript;
-
#include <GLES/gl.h>
+#include <GLES2/gl2.h>
#include <GLES/glext.h>
+#else
+#include "rsContextHostStub.h"
+
+#include <OpenGL/gl.h>
+#include <OpenGl/glext.h>
+#endif
+
+
+using namespace android;
+using namespace android::renderscript;
Mesh::Mesh(Context *rsc) : ObjectBase(rsc)
{
@@ -36,6 +45,162 @@ Mesh::~Mesh()
{
}
+void Mesh::serialize(OStream *stream) const
+{
+ // Need to identify ourselves
+ stream->addU32((uint32_t)getClassId());
+
+ String8 name(getName());
+ stream->addString(&name);
+
+ stream->addU32(mVerticiesCount);
+
+ for(uint32_t vCount = 0; vCount < mVerticiesCount; vCount ++) {
+ Verticies_t *verts = mVerticies[vCount];
+
+ stream->addU32(verts->mAllocationCount);
+
+ for (uint32_t aCount = 0; aCount < verts->mAllocationCount; aCount++) {
+ verts->mAllocations[aCount]->serialize(stream);
+ }
+ stream->addU32(verts->mVertexDataSize);
+
+ stream->addU32(verts->mOffsetCoord);
+ stream->addU32(verts->mOffsetTex);
+ stream->addU32(verts->mOffsetNorm);
+
+ stream->addU32(verts->mSizeCoord);
+ stream->addU32(verts->mSizeTex);
+ stream->addU32(verts->mSizeNorm );
+ }
+
+ stream->addU32(mPrimitivesCount);
+ // Store the primitives
+ for (uint32_t pCount = 0; pCount < mPrimitivesCount; pCount ++) {
+ Primitive_t * prim = mPrimitives[pCount];
+
+ stream->addU8((uint8_t)prim->mType);
+
+ // We store the index to the vertices
+ // So iterate over our vertices to find which one we point to
+ uint32_t vertexIndex = 0;
+ for(uint32_t vCount = 0; vCount < mVerticiesCount; vCount ++) {
+ if(prim->mVerticies == mVerticies[vCount]) {
+ vertexIndex = vCount;
+ break;
+ }
+ }
+ stream->addU32(vertexIndex);
+
+ stream->addU32(prim->mIndexCount);
+ for (uint32_t ct = 0; ct < prim->mIndexCount; ct++) {
+ stream->addU16(prim->mIndicies[ct]);
+ }
+
+ stream->addU32(prim->mRestartCounts);
+ for (uint32_t ct = 0; ct < prim->mRestartCounts; ct++) {
+ stream->addU16(prim->mRestarts[ct]);
+ }
+ }
+}
+
+Mesh *Mesh::createFromStream(Context *rsc, IStream *stream)
+{
+ // First make sure we are reading the correct object
+ RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
+ if(classID != RS_A3D_CLASS_ID_MESH) {
+ LOGE("mesh loading skipped due to invalid class id");
+ return NULL;
+ }
+
+ Mesh * mesh = new Mesh(rsc);
+
+ String8 name;
+ stream->loadString(&name);
+ mesh->setName(name.string(), name.size());
+
+ mesh->mVerticiesCount = stream->loadU32();
+ if(mesh->mVerticiesCount) {
+ mesh->mVerticies = new Verticies_t *[mesh->mVerticiesCount];
+ }
+ else {
+ mesh->mVerticies = NULL;
+ }
+
+ for(uint32_t vCount = 0; vCount < mesh->mVerticiesCount; vCount ++) {
+ Verticies_t *verts = new Verticies_t();
+ // Store our vertices one the mesh
+ mesh->mVerticies[vCount] = verts;
+
+ verts->mAllocationCount = stream->loadU32();
+ verts->mAllocations = new Allocation *[verts->mAllocationCount];
+
+ LOGE("processChunk_Verticies count %i", verts->mAllocationCount);
+ for (uint32_t aCount = 0; aCount < verts->mAllocationCount; aCount++) {
+ verts->mAllocations[aCount] = Allocation::createFromStream(rsc, stream);
+ }
+ verts->mVertexDataSize = stream->loadU32();
+
+ verts->mOffsetCoord = stream->loadU32();
+ verts->mOffsetTex = stream->loadU32();
+ verts->mOffsetNorm = stream->loadU32();
+
+ verts->mSizeCoord = stream->loadU32();
+ verts->mSizeTex = stream->loadU32();
+ verts->mSizeNorm = stream->loadU32();
+ }
+
+ mesh->mPrimitivesCount = stream->loadU32();
+ if(mesh->mPrimitivesCount) {
+ mesh->mPrimitives = new Primitive_t *[mesh->mPrimitivesCount];
+ }
+ else {
+ mesh->mPrimitives = NULL;
+ }
+
+ // load all primitives
+ for (uint32_t pCount = 0; pCount < mesh->mPrimitivesCount; pCount ++) {
+ Primitive_t * prim = new Primitive_t;
+ mesh->mPrimitives[pCount] = prim;
+
+ prim->mType = (RsPrimitive)stream->loadU8();
+
+ // We store the index to the vertices
+ uint32_t vertexIndex = stream->loadU32();
+ if(vertexIndex < mesh->mVerticiesCount) {
+ prim->mVerticies = mesh->mVerticies[vertexIndex];
+ }
+ else {
+ prim->mVerticies = NULL;
+ }
+
+ prim->mIndexCount = stream->loadU32();
+ if(prim->mIndexCount){
+ prim->mIndicies = new uint16_t[prim->mIndexCount];
+ for (uint32_t ct = 0; ct < prim->mIndexCount; ct++) {
+ prim->mIndicies[ct] = stream->loadU16();
+ }
+ }
+ else {
+ prim->mIndicies = NULL;
+ }
+
+ prim->mRestartCounts = stream->loadU32();
+ if (prim->mRestartCounts) {
+ prim->mRestarts = new uint16_t[prim->mRestartCounts];
+ for (uint32_t ct = 0; ct < prim->mRestartCounts; ct++) {
+ prim->mRestarts[ct] = stream->loadU16();
+
+ }
+ }
+ else {
+ prim->mRestarts = NULL;
+ }
+
+ }
+
+ return mesh;
+}
MeshContext::MeshContext()
diff --git a/libs/rs/rsMesh.h b/libs/rs/rsMesh.h
index 5201abd..8c7e8a4 100644
--- a/libs/rs/rsMesh.h
+++ b/libs/rs/rsMesh.h
@@ -62,15 +62,17 @@ public:
uint16_t *mRestarts;
};
- Verticies_t * mVerticies;
+ Verticies_t ** mVerticies;
uint32_t mVerticiesCount;
Primitive_t ** mPrimitives;
uint32_t mPrimitivesCount;
-
-
void analyzeElement();
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
+ static Mesh *createFromStream(Context *rsc, IStream *stream);
+
protected:
};
diff --git a/libs/rs/rsMutex.cpp b/libs/rs/rsMutex.cpp
new file mode 100644
index 0000000..37752f2
--- /dev/null
+++ b/libs/rs/rsMutex.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#include "rsMutex.h"
+
+using namespace android;
+using namespace android::renderscript;
+
+
+Mutex::Mutex()
+{
+}
+
+Mutex::~Mutex()
+{
+ pthread_mutex_destroy(&mMutex);
+}
+
+bool Mutex::init()
+{
+ int status = pthread_mutex_init(&mMutex, NULL);
+ if (status) {
+ LOGE("Mutex::Mutex init failure");
+ return false;
+ }
+ return true;
+}
+
+bool Mutex::lock()
+{
+ int status;
+ status = pthread_mutex_lock(&mMutex);
+ if (status) {
+ LOGE("Mutex: error %i locking.", status);
+ return false;
+ }
+ return true;
+}
+
+bool Mutex::unlock()
+{
+ int status;
+ status = pthread_mutex_unlock(&mMutex);
+ if (status) {
+ LOGE("Mutex error %i unlocking.", status);
+ return false;
+ }
+ return true;
+}
+
+
diff --git a/libs/rs/rsNoise.h b/libs/rs/rsMutex.h
index 9040751..47725d7 100644
--- a/libs/rs/rsNoise.h
+++ b/libs/rs/rsMutex.h
@@ -14,22 +14,30 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_NOISE_H
-#define ANDROID_RS_NOISE_H
+#ifndef ANDROID_RS_MUTEX_H
+#define ANDROID_RS_MUTEX_H
+
+
+#include "rsUtils.h"
-// ---------------------------------------------------------------------------
namespace android {
namespace renderscript {
-void SC_normalizef2(float v[]);
-void SC_normalizef3(float v[]);
-float SC_noisef(float x);
-float SC_noisef2(float x, float y);
-float SC_noisef3(float x, float y, float z);
-float SC_turbulencef2(float x, float y, float octaves);
-float SC_turbulencef3(float x, float y, float z, float octaves);
+class Mutex {
+public:
+ Mutex();
+ ~Mutex();
+
+ bool init();
+ bool lock();
+ bool unlock();
+
+protected:
+ pthread_mutex_t mMutex;
+};
}
}
#endif
+
diff --git a/libs/rs/rsNoise.cpp b/libs/rs/rsNoise.cpp
deleted file mode 100644
index 764dc1a..0000000
--- a/libs/rs/rsNoise.cpp
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * This implementation of the noise functions was ported from the Java
- * implementation by Jerry Huxtable (http://www.jhlabs.com) under
- * Apache License 2.0 (see http://jhlabs.com/ip/filters/download.html)
- *
- * Original header:
- *
- * Copyright 2006 Jerry Huxtable
- *
- * 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.
- */
-
-#include "rsNoise.h"
-
-#include <math.h>
-#include <stdlib.h>
-#include <time.h>
-
-namespace android {
-namespace renderscript {
-
-#define B 0x100
-#define BM 0xff
-#define N 0x1000
-
-static int p[B + B + 2];
-static float g3[B + B + 2][3];
-static float g2[B + B + 2][2];
-static float g1[B + B + 2];
-static bool noise_start = true;
-
-#define lerpf(start, stop, amount) start + (stop - start) * amount
-
-static inline float noise_sCurve(float t)
-{
- return t * t * (3.0f - 2.0f * t);
-}
-
-inline void SC_normalizef2(float v[])
-{
- float s = (float)sqrtf(v[0] * v[0] + v[1] * v[1]);
- v[0] = v[0] / s;
- v[1] = v[1] / s;
-}
-
-inline void SC_normalizef3(float v[])
-{
- float s = (float)sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
- v[0] = v[0] / s;
- v[1] = v[1] / s;
- v[2] = v[2] / s;
-}
-
-static void noise_init()
-{
- int i, j, k;
-
- for (i = 0; i < B; i++) {
- p[i] = i;
-
- g1[i] = (float)((rand() % (B + B)) - B) / B;
-
- for (j = 0; j < 2; j++)
- g2[i][j] = (float)((rand() % (B + B)) - B) / B;
- SC_normalizef2(g2[i]);
-
- for (j = 0; j < 3; j++)
- g3[i][j] = (float)((rand() % (B + B)) - B) / B;
- SC_normalizef3(g3[i]);
- }
-
- for (i = B-1; i >= 0; i--) {
- k = p[i];
- p[i] = p[j = rand() % B];
- p[j] = k;
- }
-
- for (i = 0; i < B + 2; i++) {
- p[B + i] = p[i];
- g1[B + i] = g1[i];
- for (j = 0; j < 2; j++)
- g2[B + i][j] = g2[i][j];
- for (j = 0; j < 3; j++)
- g3[B + i][j] = g3[i][j];
- }
-}
-
-float SC_noisef(float x)
-{
- srand(time(NULL));
- int bx0, bx1;
- float rx0, rx1, sx, t, u, v;
-
- if (noise_start) {
- noise_start = false;
- noise_init();
- }
-
- t = x + N;
- bx0 = ((int)t) & BM;
- bx1 = (bx0+1) & BM;
- rx0 = t - (int)t;
- rx1 = rx0 - 1.0f;
-
- sx = noise_sCurve(rx0);
-
- u = rx0 * g1[p[bx0]];
- v = rx1 * g1[p[bx1]];
- return 2.3f * lerpf(u, v, sx);
-}
-
-float SC_noisef2(float x, float y)
-{
- srand(time(NULL));
- int bx0, bx1, by0, by1, b00, b10, b01, b11;
- float rx0, rx1, ry0, ry1, sx, sy, a, b, t, u, v;
- float *q;
- int i, j;
-
- if (noise_start) {
- noise_start = false;
- noise_init();
- }
-
- t = x + N;
- bx0 = ((int)t) & BM;
- bx1 = (bx0+1) & BM;
- rx0 = t - (int)t;
- rx1 = rx0 - 1.0f;
-
- t = y + N;
- by0 = ((int)t) & BM;
- by1 = (by0+1) & BM;
- ry0 = t - (int)t;
- ry1 = ry0 - 1.0f;
-
- i = p[bx0];
- j = p[bx1];
-
- b00 = p[i + by0];
- b10 = p[j + by0];
- b01 = p[i + by1];
- b11 = p[j + by1];
-
- sx = noise_sCurve(rx0);
- sy = noise_sCurve(ry0);
-
- q = g2[b00]; u = rx0 * q[0] + ry0 * q[1];
- q = g2[b10]; v = rx1 * q[0] + ry0 * q[1];
- a = lerpf(u, v, sx);
-
- q = g2[b01]; u = rx0 * q[0] + ry1 * q[1];
- q = g2[b11]; v = rx1 * q[0] + ry1 * q[1];
- b = lerpf(u, v, sx);
-
- return 1.5f*lerpf(a, b, sy);
-}
-
-float SC_noisef3(float x, float y, float z)
-{
- srand(time(NULL));
- int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
- float rx0, rx1, ry0, ry1, rz0, rz1, sy, sz, a, b, c, d, t, u, v;
- float *q;
- int i, j;
-
- if (noise_start) {
- noise_start = false;
- noise_init();
- }
-
- t = x + N;
- bx0 = ((int)t) & BM;
- bx1 = (bx0+1) & BM;
- rx0 = t - (int)t;
- rx1 = rx0 - 1.0f;
-
- t = y + N;
- by0 = ((int)t) & BM;
- by1 = (by0+1) & BM;
- ry0 = t - (int)t;
- ry1 = ry0 - 1.0f;
-
- t = z + N;
- bz0 = ((int)t) & BM;
- bz1 = (bz0+1) & BM;
- rz0 = t - (int)t;
- rz1 = rz0 - 1.0f;
-
- i = p[bx0];
- j = p[bx1];
-
- b00 = p[i + by0];
- b10 = p[j + by0];
- b01 = p[i + by1];
- b11 = p[j + by1];
-
- t = noise_sCurve(rx0);
- sy = noise_sCurve(ry0);
- sz = noise_sCurve(rz0);
-
- q = g3[b00 + bz0]; u = rx0 * q[0] + ry0 * q[1] + rz0 * q[2];
- q = g3[b10 + bz0]; v = rx1 * q[0] + ry0 * q[1] + rz0 * q[2];
- a = lerpf(u, v, t);
-
- q = g3[b01 + bz0]; u = rx0 * q[0] + ry1 * q[1] + rz0 * q[2];
- q = g3[b11 + bz0]; v = rx1 * q[0] + ry1 * q[1] + rz0 * q[2];
- b = lerpf(u, v, t);
-
- c = lerpf(a, b, sy);
-
- q = g3[b00 + bz1]; u = rx0 * q[0] + ry0 * q[1] + rz1 * q[2];
- q = g3[b10 + bz1]; v = rx1 * q[0] + ry0 * q[1] + rz1 * q[2];
- a = lerpf(u, v, t);
-
- q = g3[b01 + bz1]; u = rx0 * q[0] + ry1 * q[1] + rz1 * q[2];
- q = g3[b11 + bz1]; v = rx1 * q[0] + ry1 * q[1] + rz1 * q[2];
- b = lerpf(u, v, t);
-
- d = lerpf(a, b, sy);
-
- return 1.5f*lerpf(c, d, sz);
-}
-
-float SC_turbulencef2(float x, float y, float octaves)
-{
- srand(time(NULL));
- float t = 0.0f;
-
- for (float f = 1.0f; f <= octaves; f *= 2)
- t += fabs(SC_noisef2(f * x, f * y)) / f;
- return t;
-}
-
-float SC_turbulencef3(float x, float y, float z, float octaves)
-{
- srand(time(NULL));
- float t = 0.0f;
-
- for (float f = 1.0f; f <= octaves; f *= 2)
- t += fabs(SC_noisef3(f * x, f * y, f * z)) / f;
- return t;
-}
-
-}
-} \ No newline at end of file
diff --git a/libs/rs/rsObjectBase.cpp b/libs/rs/rsObjectBase.cpp
index 677413e..48f1fee 100644
--- a/libs/rs/rsObjectBase.cpp
+++ b/libs/rs/rsObjectBase.cpp
@@ -15,7 +15,12 @@
*/
#include "rsObjectBase.h"
+
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#else
+#include "rsContextHostStub.h"
+#endif
using namespace android;
using namespace android::renderscript;
@@ -24,7 +29,6 @@ ObjectBase::ObjectBase(Context *rsc)
{
mUserRefCount = 0;
mSysRefCount = 0;
- mName = NULL;
mRSC = NULL;
mNext = NULL;
mPrev = NULL;
@@ -39,14 +43,13 @@ ObjectBase::~ObjectBase()
rsAssert(!mUserRefCount);
rsAssert(!mSysRefCount);
remove();
- delete[] mName;
}
void ObjectBase::dumpLOGV(const char *op) const
{
- if (mName) {
+ if (mName.size()) {
LOGV("%s RSobj %p, name %s, refs %i,%i from %s,%i links %p,%p,%p",
- op, this, mName, mUserRefCount, mSysRefCount, mAllocFile, mAllocLine, mNext, mPrev, mRSC);
+ op, this, mName.string(), mUserRefCount, mSysRefCount, mAllocFile, mAllocLine, mNext, mPrev, mRSC);
} else {
LOGV("%s RSobj %p, no-name, refs %i,%i from %s,%i links %p,%p,%p",
op, this, mUserRefCount, mSysRefCount, mAllocFile, mAllocLine, mNext, mPrev, mRSC);
@@ -113,18 +116,12 @@ bool ObjectBase::decSysRef() const
void ObjectBase::setName(const char *name)
{
- setName(name, strlen(name));
+ mName.setTo(name);
}
void ObjectBase::setName(const char *name, uint32_t len)
{
- delete mName;
- mName = NULL;
- if (name) {
- mName = new char[len + 1];
- memcpy(mName, name, len);
- mName[len] = 0;
- }
+ mName.setTo(name, len);
}
void ObjectBase::add() const
diff --git a/libs/rs/rsObjectBase.h b/libs/rs/rsObjectBase.h
index bb03b87..ad95b81 100644
--- a/libs/rs/rsObjectBase.h
+++ b/libs/rs/rsObjectBase.h
@@ -24,6 +24,7 @@ namespace android {
namespace renderscript {
class Context;
+class OStream;
// An element is a group of Components that occupies one cell in a structure.
class ObjectBase
@@ -40,7 +41,7 @@ public:
bool zeroUserRef() const;
const char * getName() const {
- return mName;
+ return mName.string();
}
void setName(const char *);
void setName(const char *, uint32_t len);
@@ -52,6 +53,8 @@ public:
static void dumpAll(Context *rsc);
virtual void dumpLOGV(const char *prefix) const;
+ virtual void serialize(OStream *stream) const = 0;
+ virtual RsA3DClassID getClassId() const = 0;
protected:
const char *mAllocFile;
@@ -64,7 +67,7 @@ private:
bool checkDelete() const;
- char * mName;
+ String8 mName;
mutable int32_t mSysRefCount;
mutable int32_t mUserRefCount;
diff --git a/libs/rs/rsProgram.cpp b/libs/rs/rsProgram.cpp
index 70e2868..c4f8b2e 100644
--- a/libs/rs/rsProgram.cpp
+++ b/libs/rs/rsProgram.cpp
@@ -14,11 +14,17 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#include "rsProgram.h"
-
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#include <OpenGL/glext.h>
+#endif //ANDROID_RS_BUILD_FOR_HOST
+
+#include "rsProgram.h"
using namespace android;
using namespace android::renderscript;
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index c17b94c..8151f06 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -14,13 +14,19 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#include "rsProgramFragment.h"
-
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#include <OpenGL/glext.h>
+#endif //ANDROID_RS_BUILD_FOR_HOST
+
+#include "rsProgramFragment.h"
using namespace android;
using namespace android::renderscript;
@@ -83,12 +89,15 @@ void ProgramFragment::setupGL(const Context *rsc, ProgramFragmentState *state)
glEnable(GL_TEXTURE_2D);
if (rsc->checkVersion1_1()) {
+#ifndef ANDROID_RS_BUILD_FOR_HOST // These are GLES only
if (mPointSpriteEnable) {
glEnable(GL_POINT_SPRITE_OES);
} else {
glDisable(GL_POINT_SPRITE_OES);
}
glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, mPointSpriteEnable);
+#endif //ANDROID_RS_BUILD_FOR_HOST
+
}
mTextures[ct]->uploadCheck(rsc);
glBindTexture(GL_TEXTURE_2D, mTextures[ct]->getTextureID());
@@ -289,6 +298,16 @@ void ProgramFragment::init(Context *rsc)
createShader();
}
+void ProgramFragment::serialize(OStream *stream) const
+{
+
+}
+
+ProgramFragment *ProgramFragment::createFromStream(Context *rsc, IStream *stream)
+{
+ return NULL;
+}
+
ProgramFragmentState::ProgramFragmentState()
{
mPF = NULL;
@@ -300,7 +319,7 @@ ProgramFragmentState::~ProgramFragmentState()
}
-void ProgramFragmentState::init(Context *rsc, int32_t w, int32_t h)
+void ProgramFragmentState::init(Context *rsc)
{
uint32_t tmp[5] = {
RS_TEX_ENV_MODE_NONE, 0,
@@ -328,6 +347,7 @@ RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc,
{
ProgramFragment *pf = new ProgramFragment(rsc, params, paramLength);
pf->incUserRef();
+ //LOGE("rsi_ProgramFragmentCreate %p", pf);
return pf;
}
@@ -337,6 +357,7 @@ RsProgramFragment rsi_ProgramFragmentCreate2(Context *rsc, const char * shaderTe
{
ProgramFragment *pf = new ProgramFragment(rsc, shaderText, shaderLength, params, paramLength);
pf->incUserRef();
+ //LOGE("rsi_ProgramFragmentCreate2 %p", pf);
return pf;
}
diff --git a/libs/rs/rsProgramFragment.h b/libs/rs/rsProgramFragment.h
index 9fa565d..e5bbe1b 100644
--- a/libs/rs/rsProgramFragment.h
+++ b/libs/rs/rsProgramFragment.h
@@ -40,6 +40,9 @@ public:
virtual void createShader();
virtual void loadShader(Context *rsc);
virtual void init(Context *rsc);
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_FRAGMENT; }
+ static ProgramFragment *createFromStream(Context *rsc, IStream *stream);
protected:
// Hacks to create a program for now
@@ -57,7 +60,7 @@ public:
~ProgramFragmentState();
ProgramFragment *mPF;
- void init(Context *rsc, int32_t w, int32_t h);
+ void init(Context *rsc);
void deinit(Context *rsc);
ObjectBaseRef<Type> mTextureTypes[ProgramFragment::MAX_TEXTURE];
diff --git a/libs/rs/rsProgramRaster.cpp b/libs/rs/rsProgramRaster.cpp
index 13887d1..66f6ef8 100644
--- a/libs/rs/rsProgramRaster.cpp
+++ b/libs/rs/rsProgramRaster.cpp
@@ -14,11 +14,17 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#include "rsProgramRaster.h"
-
#include <GLES/gl.h>
#include <GLES/glext.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#include <OpenGl/glext.h>
+#endif //ANDROID_RS_BUILD_FOR_HOST
+
+#include "rsProgramRaster.h"
using namespace android;
using namespace android::renderscript;
@@ -76,11 +82,13 @@ void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state)
}
if (rsc->checkVersion1_1()) {
+#ifndef ANDROID_RS_BUILD_FOR_HOST
if (mPointSprite) {
glEnable(GL_POINT_SPRITE_OES);
} else {
glDisable(GL_POINT_SPRITE_OES);
}
+#endif //ANDROID_RS_BUILD_FOR_HOST
}
}
@@ -92,7 +100,15 @@ void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state)
state->mLast.set(this);
}
+void ProgramRaster::serialize(OStream *stream) const
+{
+
+}
+ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream)
+{
+ return NULL;
+}
ProgramRasterState::ProgramRasterState()
{
@@ -102,7 +118,7 @@ ProgramRasterState::~ProgramRasterState()
{
}
-void ProgramRasterState::init(Context *rsc, int32_t w, int32_t h)
+void ProgramRasterState::init(Context *rsc)
{
ProgramRaster *pr = new ProgramRaster(rsc, false, false, false);
mDefault.set(pr);
diff --git a/libs/rs/rsProgramRaster.h b/libs/rs/rsProgramRaster.h
index c3a9c90..79b1475 100644
--- a/libs/rs/rsProgramRaster.h
+++ b/libs/rs/rsProgramRaster.h
@@ -36,6 +36,9 @@ public:
virtual void setupGL(const Context *, ProgramRasterState *);
virtual void setupGL2(const Context *, ProgramRasterState *);
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_RASTER; }
+ static ProgramRaster *createFromStream(Context *rsc, IStream *stream);
void setLineWidth(float w);
void setPointSize(float s);
@@ -56,7 +59,7 @@ class ProgramRasterState
public:
ProgramRasterState();
~ProgramRasterState();
- void init(Context *rsc, int32_t w, int32_t h);
+ void init(Context *rsc);
void deinit(Context *rsc);
ObjectBaseRef<ProgramRaster> mDefault;
diff --git a/libs/rs/rsProgramFragmentStore.cpp b/libs/rs/rsProgramStore.cpp
index 8a2157f..e741c0a 100644
--- a/libs/rs/rsProgramFragmentStore.cpp
+++ b/libs/rs/rsProgramStore.cpp
@@ -14,17 +14,23 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#include "rsProgramFragmentStore.h"
-
#include <GLES/gl.h>
#include <GLES/glext.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#include <OpenGl/glext.h>
+#endif //ANDROID_RS_BUILD_FOR_HOST
+
+#include "rsProgramStore.h"
using namespace android;
using namespace android::renderscript;
-ProgramFragmentStore::ProgramFragmentStore(Context *rsc) :
+ProgramStore::ProgramStore(Context *rsc) :
Program(rsc)
{
mAllocFile = __FILE__;
@@ -46,11 +52,11 @@ ProgramFragmentStore::ProgramFragmentStore(Context *rsc) :
}
-ProgramFragmentStore::~ProgramFragmentStore()
+ProgramStore::~ProgramStore()
{
}
-void ProgramFragmentStore::setupGL(const Context *rsc, ProgramFragmentStoreState *state)
+void ProgramStore::setupGL(const Context *rsc, ProgramStoreState *state)
{
if (state->mLast.get() == this) {
return;
@@ -85,7 +91,7 @@ void ProgramFragmentStore::setupGL(const Context *rsc, ProgramFragmentStoreState
}
}
-void ProgramFragmentStore::setupGL2(const Context *rsc, ProgramFragmentStoreState *state)
+void ProgramStore::setupGL2(const Context *rsc, ProgramStoreState *state)
{
if (state->mLast.get() == this) {
return;
@@ -121,12 +127,23 @@ void ProgramFragmentStore::setupGL2(const Context *rsc, ProgramFragmentStoreStat
}
-void ProgramFragmentStore::setDitherEnable(bool enable)
+void ProgramStore::setDitherEnable(bool enable)
{
mDitherEnable = enable;
}
-void ProgramFragmentStore::setDepthFunc(RsDepthFunc func)
+void ProgramStore::serialize(OStream *stream) const
+{
+
+}
+
+ProgramStore *ProgramStore::createFromStream(Context *rsc, IStream *stream)
+{
+ return NULL;
+}
+
+
+void ProgramStore::setDepthFunc(RsDepthFunc func)
{
mDepthTestEnable = true;
@@ -156,12 +173,12 @@ void ProgramFragmentStore::setDepthFunc(RsDepthFunc func)
}
}
-void ProgramFragmentStore::setDepthMask(bool mask)
+void ProgramStore::setDepthMask(bool mask)
{
mDepthWriteEnable = mask;
}
-void ProgramFragmentStore::setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst)
+void ProgramStore::setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst)
{
mBlendEnable = true;
if ((src == RS_BLEND_SRC_ONE) &&
@@ -227,7 +244,7 @@ void ProgramFragmentStore::setBlendFunc(RsBlendSrcFunc src, RsBlendDstFunc dst)
}
}
-void ProgramFragmentStore::setColorMask(bool r, bool g, bool b, bool a)
+void ProgramStore::setColorMask(bool r, bool g, bool b, bool a)
{
mColorRWriteEnable = r;
mColorGWriteEnable = g;
@@ -236,24 +253,24 @@ void ProgramFragmentStore::setColorMask(bool r, bool g, bool b, bool a)
}
-ProgramFragmentStoreState::ProgramFragmentStoreState()
+ProgramStoreState::ProgramStoreState()
{
mPFS = NULL;
}
-ProgramFragmentStoreState::~ProgramFragmentStoreState()
+ProgramStoreState::~ProgramStoreState()
{
delete mPFS;
}
-void ProgramFragmentStoreState::init(Context *rsc, int32_t w, int32_t h)
+void ProgramStoreState::init(Context *rsc)
{
- ProgramFragmentStore *pfs = new ProgramFragmentStore(rsc);
+ ProgramStore *pfs = new ProgramStore(rsc);
mDefault.set(pfs);
}
-void ProgramFragmentStoreState::deinit(Context *rsc)
+void ProgramStoreState::deinit(Context *rsc)
{
mDefault.clear();
mLast.clear();
@@ -263,42 +280,42 @@ void ProgramFragmentStoreState::deinit(Context *rsc)
namespace android {
namespace renderscript {
-void rsi_ProgramFragmentStoreBegin(Context * rsc, RsElement in, RsElement out)
+void rsi_ProgramStoreBegin(Context * rsc, RsElement in, RsElement out)
{
delete rsc->mStateFragmentStore.mPFS;
- rsc->mStateFragmentStore.mPFS = new ProgramFragmentStore(rsc);
+ rsc->mStateFragmentStore.mPFS = new ProgramStore(rsc);
}
-void rsi_ProgramFragmentStoreDepthFunc(Context *rsc, RsDepthFunc func)
+void rsi_ProgramStoreDepthFunc(Context *rsc, RsDepthFunc func)
{
rsc->mStateFragmentStore.mPFS->setDepthFunc(func);
}
-void rsi_ProgramFragmentStoreDepthMask(Context *rsc, bool mask)
+void rsi_ProgramStoreDepthMask(Context *rsc, bool mask)
{
rsc->mStateFragmentStore.mPFS->setDepthMask(mask);
}
-void rsi_ProgramFragmentStoreColorMask(Context *rsc, bool r, bool g, bool b, bool a)
+void rsi_ProgramStoreColorMask(Context *rsc, bool r, bool g, bool b, bool a)
{
rsc->mStateFragmentStore.mPFS->setColorMask(r, g, b, a);
}
-void rsi_ProgramFragmentStoreBlendFunc(Context *rsc, RsBlendSrcFunc src, RsBlendDstFunc dst)
+void rsi_ProgramStoreBlendFunc(Context *rsc, RsBlendSrcFunc src, RsBlendDstFunc dst)
{
rsc->mStateFragmentStore.mPFS->setBlendFunc(src, dst);
}
-RsProgramFragmentStore rsi_ProgramFragmentStoreCreate(Context *rsc)
+RsProgramStore rsi_ProgramStoreCreate(Context *rsc)
{
- ProgramFragmentStore *pfs = rsc->mStateFragmentStore.mPFS;
+ ProgramStore *pfs = rsc->mStateFragmentStore.mPFS;
pfs->incUserRef();
rsc->mStateFragmentStore.mPFS = 0;
return pfs;
}
-void rsi_ProgramFragmentStoreDither(Context *rsc, bool enable)
+void rsi_ProgramStoreDither(Context *rsc, bool enable)
{
rsc->mStateFragmentStore.mPFS->setDitherEnable(enable);
}
diff --git a/libs/rs/rsProgramFragmentStore.h b/libs/rs/rsProgramStore.h
index 3412c99..fe8d78e 100644
--- a/libs/rs/rsProgramFragmentStore.h
+++ b/libs/rs/rsProgramStore.h
@@ -18,21 +18,22 @@
#define ANDROID_RS_PROGRAM_FRAGMENT_STORE_H
#include "rsProgram.h"
+#include "rsStream.h"
// ---------------------------------------------------------------------------
namespace android {
namespace renderscript {
-class ProgramFragmentStoreState;
+class ProgramStoreState;
-class ProgramFragmentStore : public Program
+class ProgramStore : public Program
{
public:
- ProgramFragmentStore(Context *);
- virtual ~ProgramFragmentStore();
+ ProgramStore(Context *);
+ virtual ~ProgramStore();
- virtual void setupGL(const Context *, ProgramFragmentStoreState *);
- virtual void setupGL2(const Context *, ProgramFragmentStoreState *);
+ virtual void setupGL(const Context *, ProgramStoreState *);
+ virtual void setupGL2(const Context *, ProgramStoreState *);
void setDepthFunc(RsDepthFunc);
void setDepthMask(bool);
@@ -42,6 +43,10 @@ public:
void setDitherEnable(bool);
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_STORE; }
+ static ProgramStore *createFromStream(Context *rsc, IStream *stream);
+
protected:
bool mDitherEnable;
@@ -60,19 +65,19 @@ protected:
bool mStencilTestEnable;
};
-class ProgramFragmentStoreState
+class ProgramStoreState
{
public:
- ProgramFragmentStoreState();
- ~ProgramFragmentStoreState();
- void init(Context *rsc, int32_t w, int32_t h);
+ ProgramStoreState();
+ ~ProgramStoreState();
+ void init(Context *rsc);
void deinit(Context *rsc);
- ObjectBaseRef<ProgramFragmentStore> mDefault;
- ObjectBaseRef<ProgramFragmentStore> mLast;
+ ObjectBaseRef<ProgramStore> mDefault;
+ ObjectBaseRef<ProgramStore> mLast;
- ProgramFragmentStore *mPFS;
+ ProgramStore *mPFS;
};
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index a2b2df4..d667c86 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -14,13 +14,19 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-#include "rsProgramVertex.h"
-
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#include <OpenGL/glext.h>
+#endif //ANDROID_RS_BUILD_FOR_HOST
+
+#include "rsProgramVertex.h"
using namespace android;
using namespace android::renderscript;
@@ -81,9 +87,12 @@ void ProgramVertex::setupGL(const Context *rsc, ProgramVertexState *state)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (mLightCount) {
+#ifndef ANDROID_RS_BUILD_FOR_HOST // GLES Only
int v = 0;
glEnable(GL_LIGHTING);
+
glLightModelxv(GL_LIGHT_MODEL_TWO_SIDE, &v);
+
for (uint32_t ct = 0; ct < mLightCount; ct++) {
const Light *l = mLights[ct].get();
glEnable(GL_LIGHT0 + ct);
@@ -92,6 +101,7 @@ void ProgramVertex::setupGL(const Context *rsc, ProgramVertexState *state)
for (uint32_t ct = mLightCount; ct < MAX_LIGHTS; ct++) {
glDisable(GL_LIGHT0 + ct);
}
+#endif //ANDROID_RS_BUILD_FOR_HOST
} else {
glDisable(GL_LIGHTING);
}
@@ -168,11 +178,11 @@ void ProgramVertex::createShader()
}
mShader.append(mUserShader);
} else {
- mShader.append("attribute vec4 ATTRIB_LegacyPosition;\n");
- mShader.append("attribute vec4 ATTRIB_LegacyColor;\n");
- mShader.append("attribute vec3 ATTRIB_LegacyNormal;\n");
- mShader.append("attribute float ATTRIB_LegacyPointSize;\n");
- mShader.append("attribute vec4 ATTRIB_LegacyTexture;\n");
+ mShader.append("attribute vec4 ATTRIB_position;\n");
+ mShader.append("attribute vec4 ATTRIB_color;\n");
+ mShader.append("attribute vec3 ATTRIB_normal;\n");
+ mShader.append("attribute float ATTRIB_pointSize;\n");
+ mShader.append("attribute vec4 ATTRIB_texture0;\n");
for (uint32_t ct=0; ct < mUniformCount; ct++) {
mShader.append("uniform mat4 ");
@@ -181,14 +191,14 @@ void ProgramVertex::createShader()
}
mShader.append("void main() {\n");
- mShader.append(" gl_Position = UNI_MVP * ATTRIB_LegacyPosition;\n");
- mShader.append(" gl_PointSize = ATTRIB_LegacyPointSize;\n");
+ mShader.append(" gl_Position = UNI_MVP * ATTRIB_position;\n");
+ mShader.append(" gl_PointSize = ATTRIB_pointSize;\n");
- mShader.append(" varColor = ATTRIB_LegacyColor;\n");
+ mShader.append(" varColor = ATTRIB_color;\n");
if (mTextureMatrixEnable) {
- mShader.append(" varTex0 = UNI_TexMatrix * ATTRIB_LegacyTexture;\n");
+ mShader.append(" varTex0 = UNI_TexMatrix * ATTRIB_texture0;\n");
} else {
- mShader.append(" varTex0 = ATTRIB_LegacyTexture;\n");
+ mShader.append(" varTex0 = ATTRIB_texture0;\n");
}
//mShader.append(" pos.x = pos.x / 480.0;\n");
//mShader.append(" pos.y = pos.y / 800.0;\n");
@@ -351,6 +361,16 @@ void ProgramVertex::init(Context *rsc)
createShader();
}
+void ProgramVertex::serialize(OStream *stream) const
+{
+
+}
+
+ProgramVertex *ProgramVertex::createFromStream(Context *rsc, IStream *stream)
+{
+ return NULL;
+}
+
///////////////////////////////////////////////////////////////////////
@@ -362,8 +382,9 @@ ProgramVertexState::~ProgramVertexState()
{
}
-void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h)
+void ProgramVertexState::init(Context *rsc)
{
+#ifndef ANDROID_RS_BUILD_FOR_HOST
RsElement e = (RsElement) Element::create(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 1);
rsi_TypeBegin(rsc, e);
@@ -372,6 +393,7 @@ void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h)
ProgramVertex *pv = new ProgramVertex(rsc, false);
Allocation *alloc = (Allocation *)rsi_AllocationCreateTyped(rsc, mAllocType.get());
+
mDefaultAlloc.set(alloc);
mDefault.set(pv);
pv->init(rsc);
@@ -382,13 +404,15 @@ void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h)
color[2] = 1.f;
color[3] = 1.f;
- updateSize(rsc, w, h);
+ updateSize(rsc);
+#endif //ANDROID_RS_BUILD_FOR_HOST
+
}
-void ProgramVertexState::updateSize(Context *rsc, int32_t w, int32_t h)
+void ProgramVertexState::updateSize(Context *rsc)
{
Matrix m;
- m.loadOrtho(0,w, h,0, -1,1);
+ m.loadOrtho(0,rsc->getWidth(), rsc->getHeight(),0, -1,1);
mDefaultAlloc->subData(RS_PROGRAM_VERTEX_PROJECTION_OFFSET, 16, &m.m[0], 16*4);
m.loadIdentity();
diff --git a/libs/rs/rsProgramVertex.h b/libs/rs/rsProgramVertex.h
index 28554cc..cb93eaf 100644
--- a/libs/rs/rsProgramVertex.h
+++ b/libs/rs/rsProgramVertex.h
@@ -52,6 +52,9 @@ public:
virtual void loadShader(Context *);
virtual void init(Context *);
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_VERTEX; }
+ static ProgramVertex *createFromStream(Context *rsc, IStream *stream);
protected:
uint32_t mLightCount;
@@ -71,9 +74,9 @@ public:
ProgramVertexState();
~ProgramVertexState();
- void init(Context *rsc, int32_t w, int32_t h);
+ void init(Context *rsc);
void deinit(Context *rsc);
- void updateSize(Context *rsc, int32_t w, int32_t h);
+ void updateSize(Context *rsc);
ObjectBaseRef<ProgramVertex> mDefault;
ObjectBaseRef<ProgramVertex> mLast;
diff --git a/libs/rs/rsSampler.cpp b/libs/rs/rsSampler.cpp
index 71f508f..f41f295 100644
--- a/libs/rs/rsSampler.cpp
+++ b/libs/rs/rsSampler.cpp
@@ -14,10 +14,16 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include <GLES/gl.h>
#include <GLES/glext.h>
-
#include "rsContext.h"
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#include <OpenGL/glext.h>
+#endif //ANDROID_RS_BUILD_FOR_HOST
+
#include "rsSampler.h"
@@ -94,6 +100,17 @@ void Sampler::unbindFromContext(SamplerState *ss)
mBoundSlot = -1;
ss->mSamplers[slot].clear();
}
+
+void Sampler::serialize(OStream *stream) const
+{
+
+}
+
+Sampler *Sampler::createFromStream(Context *rsc, IStream *stream)
+{
+ return NULL;
+}
+
/*
void SamplerState::setupGL()
{
diff --git a/libs/rs/rsSampler.h b/libs/rs/rsSampler.h
index 0506081..3786439 100644
--- a/libs/rs/rsSampler.h
+++ b/libs/rs/rsSampler.h
@@ -46,6 +46,10 @@ public:
void bindToContext(SamplerState *, uint32_t slot);
void unbindFromContext(SamplerState *);
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; }
+ static Sampler *createFromStream(Context *rsc, IStream *stream);
+
protected:
RsSamplerValue mMagFilter;
RsSamplerValue mMinFilter;
diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp
index a33933b..fc22fc3 100644
--- a/libs/rs/rsScript.cpp
+++ b/libs/rs/rsScript.cpp
@@ -24,19 +24,25 @@ Script::Script(Context *rsc) : ObjectBase(rsc)
mAllocFile = __FILE__;
mAllocLine = __LINE__;
memset(&mEnviroment, 0, sizeof(mEnviroment));
- mEnviroment.mClearColor[0] = 0;
- mEnviroment.mClearColor[1] = 0;
- mEnviroment.mClearColor[2] = 0;
- mEnviroment.mClearColor[3] = 1;
- mEnviroment.mClearDepth = 1;
- mEnviroment.mClearStencil = 0;
- mEnviroment.mIsRoot = false;
}
Script::~Script()
{
}
+void Script::setVar(uint32_t slot, const void *val, uint32_t len)
+{
+ int32_t *destPtr = ((int32_t **)mEnviroment.mFieldAddress)[slot];
+ if (destPtr) {
+ //LOGE("setVar f1 %f", ((const float *)destPtr)[0]);
+ //LOGE("setVar %p %i", destPtr, len);
+ memcpy(destPtr, val, len);
+ //LOGE("setVar f2 %f", ((const float *)destPtr)[0]);
+ } else {
+ LOGE("Calling setVar on slot = %i which is null", slot);
+ }
+}
+
namespace android {
namespace renderscript {
@@ -44,71 +50,62 @@ namespace renderscript {
void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot)
{
Script *s = static_cast<Script *>(vs);
- s->mSlots[slot].set(static_cast<Allocation *>(va));
+ Allocation *a = static_cast<Allocation *>(va);
+ s->mSlots[slot].set(a);
+ //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr());
}
-void rsi_ScriptSetClearColor(Context * rsc, RsScript vs, float r, float g, float b, float a)
+void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length)
{
Script *s = static_cast<Script *>(vs);
- s->mEnviroment.mClearColor[0] = r;
- s->mEnviroment.mClearColor[1] = g;
- s->mEnviroment.mClearColor[2] = b;
- s->mEnviroment.mClearColor[3] = a;
+ s->mEnviroment.mTimeZone = timeZone;
}
-void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length)
+void rsi_ScriptSetType(Context * rsc, RsType vt, uint32_t slot, bool writable, const char *name)
{
- Script *s = static_cast<Script *>(vs);
- s->mEnviroment.mTimeZone = timeZone;
+ ScriptCState *ss = &rsc->mScriptC;
+ const Type *t = static_cast<const Type *>(vt);
+ ss->mConstantBufferTypes[slot].set(t);
+ ss->mSlotWritable[slot] = writable;
+ LOGE("rsi_ScriptSetType");
}
-void rsi_ScriptSetClearDepth(Context * rsc, RsScript vs, float v)
+void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot)
{
Script *s = static_cast<Script *>(vs);
- s->mEnviroment.mClearDepth = v;
+ s->Invoke(rsc, slot, NULL, 0);
}
-void rsi_ScriptSetClearStencil(Context * rsc, RsScript vs, uint32_t v)
+
+void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data)
{
Script *s = static_cast<Script *>(vs);
- s->mEnviroment.mClearStencil = v;
+ s->Invoke(rsc, slot, NULL, 0);
}
-void rsi_ScriptSetType(Context * rsc, RsType vt, uint32_t slot, bool writable, const char *name)
+void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len)
{
- ScriptCState *ss = &rsc->mScriptC;
- const Type *t = static_cast<const Type *>(vt);
- ss->mConstantBufferTypes[slot].set(t);
- ss->mSlotWritable[slot] = writable;
- if (name) {
- ss->mSlotNames[slot].setTo(name);
- } else {
- ss->mSlotNames[slot].setTo("");
- }
+ Script *s = static_cast<Script *>(vs);
+ s->Invoke(rsc, slot, data, len);
}
-void rsi_ScriptSetInvoke(Context *rsc, const char *name, uint32_t slot)
+void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value)
{
- ScriptCState *ss = &rsc->mScriptC;
- ss->mInvokableNames[slot] = name;
+ Script *s = static_cast<Script *>(vs);
+ s->setVar(slot, &value, sizeof(value));
}
-void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot)
+void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value)
{
Script *s = static_cast<Script *>(vs);
- if (s->mEnviroment.mInvokables[slot] == NULL) {
- rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
- return;
- }
- s->setupScript();
- s->mEnviroment.mInvokables[slot]();
+ s->setVar(slot, &value, sizeof(value));
}
-
-void rsi_ScriptSetRoot(Context * rsc, bool isRoot)
+void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len)
{
- ScriptCState *ss = &rsc->mScriptC;
- ss->mScript->mEnviroment.mIsRoot = isRoot;
+ const float *fp = (const float *)data;
+ Script *s = static_cast<Script *>(vs);
+ s->setVar(slot, data, len);
}
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index 5f4a536..ea6aec5 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -27,9 +27,9 @@ namespace renderscript {
class ProgramVertex;
class ProgramFragment;
class ProgramRaster;
-class ProgramFragmentStore;
+class ProgramStore;
-#define MAX_SCRIPT_BANKS 16
+#define MAX_SCRIPT_BANKS 32
class Script : public ObjectBase
{
@@ -39,38 +39,38 @@ public:
Script(Context *);
virtual ~Script();
-
struct Enviroment_t {
- bool mIsRoot;
- float mClearColor[4];
- float mClearDepth;
- uint32_t mClearStencil;
-
uint32_t mStartTimeMillis;
const char* mTimeZone;
ObjectBaseRef<ProgramVertex> mVertex;
ObjectBaseRef<ProgramFragment> mFragment;
ObjectBaseRef<ProgramRaster> mRaster;
- ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
- InvokeFunc_t mInvokables[MAX_SCRIPT_BANKS];
+ ObjectBaseRef<ProgramStore> mFragmentStore;
+
+ uint32_t mInvokeFunctionCount;
+ InvokeFunc_t *mInvokeFunctions;
+ uint32_t mFieldCount;
+ void ** mFieldAddress;
+
char * mScriptText;
uint32_t mScriptTextLength;
};
Enviroment_t mEnviroment;
- uint32_t mCounstantBufferCount;
-
-
ObjectBaseRef<Allocation> mSlots[MAX_SCRIPT_BANKS];
ObjectBaseRef<const Type> mTypes[MAX_SCRIPT_BANKS];
- String8 mSlotNames[MAX_SCRIPT_BANKS];
bool mSlotWritable[MAX_SCRIPT_BANKS];
+ void setVar(uint32_t slot, const void *val, uint32_t len);
+ virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout) = 0;
+ virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout, uint32_t xStart, uint32_t xEnd) = 0;
+ virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout, uint32_t xStart, uint32_t yStart, uint32_t xEnd, uint32_t yEnd) = 0;
- virtual void setupScript() = 0;
- virtual uint32_t run(Context *, uint32_t launchID) = 0;
+ virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) = 0;
+ virtual void setupScript(Context *rsc) = 0;
+ virtual uint32_t run(Context *) = 0;
};
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index f4d2451..ef37286 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -17,8 +17,7 @@
#include "rsContext.h"
#include "rsScriptC.h"
#include "rsMatrix.h"
-
-#include "acc/acc.h"
+#include "../../../external/llvm/libbcc/include/bcc/bcc.h"
#include "utils/Timers.h"
#include <GLES/gl.h>
@@ -37,40 +36,74 @@ ScriptC::ScriptC(Context *rsc) : Script(rsc)
{
mAllocFile = __FILE__;
mAllocLine = __LINE__;
- mAccScript = NULL;
+ mBccScript = NULL;
memset(&mProgram, 0, sizeof(mProgram));
}
ScriptC::~ScriptC()
{
- if (mAccScript) {
- accDeleteScript(mAccScript);
+ if (mBccScript) {
+ bccDeleteScript(mBccScript);
}
free(mEnviroment.mScriptText);
mEnviroment.mScriptText = NULL;
}
-void ScriptC::setupScript()
+void ScriptC::setupScript(Context *rsc)
{
- for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
- if (mProgram.mSlotPointers[ct]) {
- *mProgram.mSlotPointers[ct] = mSlots[ct]->getPtr();
+ setupGLState(rsc);
+ mEnviroment.mStartTimeMillis
+ = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
+
+ for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) {
+ if (!mSlots[ct].get())
+ continue;
+ void *ptr = mSlots[ct]->getPtr();
+ void **dest = ((void ***)mEnviroment.mFieldAddress)[ct];
+ //LOGE("setupScript %i %p = %p %p %i", ct, dest, ptr, mSlots[ct]->getType(), mSlots[ct]->getType()->getDimX());
+
+ //const uint32_t *p32 = (const uint32_t *)ptr;
+ //for (uint32_t ct2=0; ct2 < mSlots[ct]->getType()->getDimX(); ct2++) {
+ //LOGE(" %i = 0x%08x ", ct2, p32[ct2]);
+ //}
+
+ if (dest) {
+ *dest = ptr;
+ } else {
+ LOGE("ScriptC::setupScript, NULL var binding address.");
}
}
}
-
-uint32_t ScriptC::run(Context *rsc, uint32_t launchIndex)
+const Allocation *ScriptC::ptrToAllocation(const void *ptr) const
{
- if (mProgram.mScript == NULL) {
- rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script");
- return 0;
+ if (!ptr) {
+ return NULL;
+ }
+ for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) {
+ if (!mSlots[ct].get())
+ continue;
+ if (mSlots[ct]->getPtr() == ptr) {
+ return mSlots[ct].get();
+ }
}
+ LOGE("ScriptC::ptrToAllocation, failed to find %p", ptr);
+ return NULL;
+}
- Context::ScriptTLSStruct * tls =
- (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey);
+Script * ScriptC::setTLS(Script *sc)
+{
+ Context::ScriptTLSStruct * tls = (Context::ScriptTLSStruct *)
+ pthread_getspecific(Context::gThreadTLSKey);
rsAssert(tls);
+ Script *old = tls->mScript;
+ tls->mScript = sc;
+ return old;
+}
+
+void ScriptC::setupGLState(Context *rsc)
+{
if (mEnviroment.mFragmentStore.get()) {
rsc->setFragmentStore(mEnviroment.mFragmentStore.get());
}
@@ -83,20 +116,92 @@ uint32_t ScriptC::run(Context *rsc, uint32_t launchIndex)
if (mEnviroment.mRaster.get()) {
rsc->setRaster(mEnviroment.mRaster.get());
}
+}
- if (launchIndex == 0) {
- mEnviroment.mStartTimeMillis
- = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
+uint32_t ScriptC::run(Context *rsc)
+{
+ if (mProgram.mRoot == NULL) {
+ rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script");
+ return 0;
}
- setupScript();
+
+ setupScript(rsc);
uint32_t ret = 0;
- tls->mScript = this;
- ret = mProgram.mScript(launchIndex);
- tls->mScript = NULL;
+ Script * oldTLS = setTLS(this);
+ //LOGE("ScriptC::run %p", mProgram.mRoot);
+ ret = mProgram.mRoot();
+ setTLS(oldTLS);
+ //LOGE("ScriptC::run ret %i", ret);
return ret;
}
+void ScriptC::runForEach(Context *rsc, const Allocation *ain, Allocation *aout,
+ uint32_t xStart, uint32_t yStart, uint32_t xEnd, uint32_t yEnd)
+{
+ LOGE("ScriptC::runForEach not implemented");
+}
+
+void ScriptC::runForEach(Context *rsc, const Allocation *ain, Allocation *aout, uint32_t xStart, uint32_t xEnd)
+{
+ uint32_t dimX = ain->getType()->getDimX();
+ rsAssert(xStart < dimX);
+ rsAssert(xEnd <= dimX);
+ rsAssert(ain->getType()->getDimY() == 0);
+ rsAssert(ain->getType()->getDimZ() == 0);
+
+ if (xStart >= dimX) xStart = dimX - 1;
+ if (xEnd >= dimX) xEnd = dimX - 1;
+ if (xStart > xEnd) return;
+
+ setupScript(rsc);
+ Script * oldTLS = setTLS(this);
+
+ typedef int (*rs_t)(const void *, void *, uint32_t);
+ const uint8_t *ptrIn = (const uint8_t *)ain->getPtr();
+ uint32_t strideIn = ain->getType()->getElementSizeBytes();
+
+ uint8_t *ptrOut = NULL;
+ uint32_t strideOut = 0;
+ if (aout) {
+ ptrOut = (uint8_t *)aout->getPtr();
+ strideOut = aout->getType()->getElementSizeBytes();
+ }
+
+ for (uint32_t ct=xStart; ct < xEnd; ct++) {
+ ((rs_t)mProgram.mRoot) (ptrIn + (strideIn * ct), ptrOut + (strideOut * ct), ct);
+ }
+
+ setTLS(oldTLS);
+}
+
+void ScriptC::runForEach(Context *rsc, const Allocation *ain, Allocation *aout)
+{
+ if (ain->getType()->getDimY()) {
+ runForEach(rsc, ain, aout, 0, 0, 0xffffffff, 0xffffffff);
+ } else {
+ runForEach(rsc, ain, aout, 0, 0xffffffff);
+ }
+}
+
+
+void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len)
+{
+ //LOGE("rsi_ScriptInvoke %i", slot);
+ if ((slot >= mEnviroment.mInvokeFunctionCount) ||
+ (mEnviroment.mInvokeFunctions[slot] == NULL)) {
+ rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
+ return;
+ }
+ setupScript(rsc);
+ Script * oldTLS = setTLS(this);
+
+ ((void (*)(const void *, uint32_t))
+ mEnviroment.mInvokeFunctions[slot])(data, len);
+
+ setTLS(oldTLS);
+}
+
ScriptCState::ScriptCState()
{
mScript = NULL;
@@ -113,21 +218,25 @@ void ScriptCState::clear()
{
for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
mConstantBufferTypes[ct].clear();
- mSlotNames[ct].setTo("");
- mInvokableNames[ct].setTo("");
mSlotWritable[ct] = false;
}
delete mScript;
mScript = new ScriptC(NULL);
-
- mInt32Defines.clear();
- mFloatDefines.clear();
}
-static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name)
+static BCCvoid* symbolLookup(BCCvoid* pContext, const BCCchar* name)
{
- const ScriptCState::SymbolTable_t *sym = ScriptCState::lookupSymbol(name);
+ const ScriptCState::SymbolTable_t *sym;
+ sym = ScriptCState::lookupSymbol(name);
+ if (sym) {
+ return sym->mPtr;
+ }
+ sym = ScriptCState::lookupSymbolCL(name);
+ if (sym) {
+ return sym->mPtr;
+ }
+ sym = ScriptCState::lookupSymbolGL(name);
if (sym) {
return sym->mPtr;
}
@@ -137,65 +246,52 @@ static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name)
void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
{
- s->mAccScript = accCreateScript();
- String8 tmp;
-
- rsc->appendNameDefines(&tmp);
- appendDecls(&tmp);
- appendVarDefines(rsc, &tmp);
- appendTypes(rsc, &tmp);
- tmp.append("#line 1\n");
-
- const char* scriptSource[] = {tmp.string(), s->mEnviroment.mScriptText};
- int scriptLength[] = {tmp.length(), s->mEnviroment.mScriptTextLength} ;
- accScriptSource(s->mAccScript, sizeof(scriptLength) / sizeof(int), scriptSource, scriptLength);
- accRegisterSymbolCallback(s->mAccScript, symbolLookup, NULL);
- accCompileScript(s->mAccScript);
- accGetScriptLabel(s->mAccScript, "main", (ACCvoid**) &s->mProgram.mScript);
- accGetScriptLabel(s->mAccScript, "init", (ACCvoid**) &s->mProgram.mInit);
- rsAssert(s->mProgram.mScript);
-
- if (!s->mProgram.mScript) {
- ACCchar buf[4096];
- ACCsizei len;
- accGetScriptInfoLog(s->mAccScript, sizeof(buf), &len, buf);
- LOGE("%s", buf);
- rsc->setError(RS_ERROR_BAD_SCRIPT, "Error compiling user script.");
- return;
- }
+ LOGE("ScriptCState::runCompiler ");
+
+ s->mBccScript = bccCreateScript();
+ bccScriptBitcode(s->mBccScript, s->mEnviroment.mScriptText, s->mEnviroment.mScriptTextLength);
+ bccRegisterSymbolCallback(s->mBccScript, symbolLookup, NULL);
+ bccCompileScript(s->mBccScript);
+ bccGetScriptLabel(s->mBccScript, "root", (BCCvoid**) &s->mProgram.mRoot);
+ bccGetScriptLabel(s->mBccScript, "init", (BCCvoid**) &s->mProgram.mInit);
+ LOGE("root %p, init %p", s->mProgram.mRoot, s->mProgram.mInit);
if (s->mProgram.mInit) {
s->mProgram.mInit();
}
- for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
- if (mSlotNames[ct].length() > 0) {
- accGetScriptLabel(s->mAccScript,
- mSlotNames[ct].string(),
- (ACCvoid**) &s->mProgram.mSlotPointers[ct]);
- }
+ s->mEnviroment.mInvokeFunctions = (Script::InvokeFunc_t *)calloc(100, sizeof(void *));
+ BCCchar **labels = new char*[100];
+ bccGetFunctions(s->mBccScript, (BCCsizei *)&s->mEnviroment.mInvokeFunctionCount,
+ 100, (BCCchar **)labels);
+ //LOGE("func count %i", s->mEnviroment.mInvokeFunctionCount);
+ for (uint32_t i=0; i < s->mEnviroment.mInvokeFunctionCount; i++) {
+ BCCsizei length;
+ bccGetFunctionBinary(s->mBccScript, labels[i], (BCCvoid **)&(s->mEnviroment.mInvokeFunctions[i]), &length);
+ //LOGE("func %i %p", i, s->mEnviroment.mInvokeFunctions[i]);
}
- for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
- if (mInvokableNames[ct].length() > 0) {
- accGetScriptLabel(s->mAccScript,
- mInvokableNames[ct].string(),
- (ACCvoid**) &s->mEnviroment.mInvokables[ct]);
- }
+ s->mEnviroment.mFieldAddress = (void **)calloc(100, sizeof(void *));
+ bccGetExportVars(s->mBccScript, (BCCsizei *)&s->mEnviroment.mFieldCount,
+ 100, s->mEnviroment.mFieldAddress);
+ //LOGE("var count %i", s->mEnviroment.mFieldCount);
+ for (uint32_t i=0; i < s->mEnviroment.mFieldCount; i++) {
+ //LOGE("var %i %p", i, s->mEnviroment.mFieldAddress[i]);
}
s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
s->mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
- s->mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore());
+ s->mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore());
s->mEnviroment.mRaster.set(rsc->getDefaultProgramRaster());
- if (s->mProgram.mScript) {
+ if (s->mProgram.mRoot) {
const static int pragmaMax = 16;
- ACCsizei pragmaCount;
- ACCchar * str[pragmaMax];
- accGetPragmas(s->mAccScript, &pragmaCount, pragmaMax, &str[0]);
+ BCCsizei pragmaCount;
+ BCCchar * str[pragmaMax];
+ bccGetPragmas(s->mBccScript, &pragmaCount, pragmaMax, &str[0]);
for (int ct=0; ct < pragmaCount; ct+=2) {
+ //LOGE("pragme %s %s", str[ct], str[ct+1]);
if (!strcmp(str[ct], "version")) {
continue;
}
@@ -208,11 +304,6 @@ void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
s->mEnviroment.mVertex.clear();
continue;
}
- ProgramVertex * pv = (ProgramVertex *)rsc->lookupName(str[ct+1]);
- if (pv != NULL) {
- s->mEnviroment.mVertex.set(pv);
- continue;
- }
LOGE("Unreconized value %s passed to stateVertex", str[ct+1]);
}
@@ -224,11 +315,6 @@ void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
s->mEnviroment.mRaster.clear();
continue;
}
- ProgramRaster * pr = (ProgramRaster *)rsc->lookupName(str[ct+1]);
- if (pr != NULL) {
- s->mEnviroment.mRaster.set(pr);
- continue;
- }
LOGE("Unreconized value %s passed to stateRaster", str[ct+1]);
}
@@ -240,11 +326,6 @@ void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
s->mEnviroment.mFragment.clear();
continue;
}
- ProgramFragment * pf = (ProgramFragment *)rsc->lookupName(str[ct+1]);
- if (pf != NULL) {
- s->mEnviroment.mFragment.set(pf);
- continue;
- }
LOGE("Unreconized value %s passed to stateFragment", str[ct+1]);
}
@@ -256,12 +337,6 @@ void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
s->mEnviroment.mFragmentStore.clear();
continue;
}
- ProgramFragmentStore * pfs =
- (ProgramFragmentStore *)rsc->lookupName(str[ct+1]);
- if (pfs != NULL) {
- s->mEnviroment.mFragmentStore.set(pfs);
- continue;
- }
LOGE("Unreconized value %s passed to stateStore", str[ct+1]);
}
@@ -273,111 +348,6 @@ void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
}
}
-static void appendElementBody(String8 *s, const Element *e)
-{
- s->append(" {\n");
- for (size_t ct2=0; ct2 < e->getFieldCount(); ct2++) {
- const Element *c = e->getField(ct2);
- s->append(" ");
- s->append(c->getCType());
- s->append(" ");
- s->append(e->getFieldName(ct2));
- s->append(";\n");
- }
- s->append("}");
-}
-
-void ScriptCState::appendVarDefines(const Context *rsc, String8 *str)
-{
- char buf[256];
- if (rsc->props.mLogScripts) {
- LOGD("appendVarDefines mInt32Defines.size()=%d mFloatDefines.size()=%d\n",
- mInt32Defines.size(), mFloatDefines.size());
- }
- for (size_t ct=0; ct < mInt32Defines.size(); ct++) {
- str->append("#define ");
- str->append(mInt32Defines.keyAt(ct));
- str->append(" ");
- sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct));
- str->append(buf);
- }
- for (size_t ct=0; ct < mFloatDefines.size(); ct++) {
- str->append("#define ");
- str->append(mFloatDefines.keyAt(ct));
- str->append(" ");
- sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct));
- str->append(buf);
- }
-}
-
-
-
-void ScriptCState::appendTypes(const Context *rsc, String8 *str)
-{
- char buf[256];
- String8 tmp;
-
- str->append("struct vecF32_2_s {float x; float y;};\n");
- str->append("struct vecF32_3_s {float x; float y; float z;};\n");
- str->append("struct vecF32_4_s {float x; float y; float z; float w;};\n");
- str->append("struct vecU8_4_s {char r; char g; char b; char a;};\n");
- str->append("#define vecF32_2_t struct vecF32_2_s\n");
- str->append("#define vecF32_3_t struct vecF32_3_s\n");
- str->append("#define vecF32_4_t struct vecF32_4_s\n");
- str->append("#define vecU8_4_t struct vecU8_4_s\n");
- str->append("#define vecI8_4_t struct vecU8_4_s\n");
-
- for (size_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
- const Type *t = mConstantBufferTypes[ct].get();
- if (!t) {
- continue;
- }
- const Element *e = t->getElement();
- if (e->getName() && (e->getFieldCount() > 1)) {
- String8 s("struct struct_");
- s.append(e->getName());
- s.append(e->getCStructBody());
- s.append(";\n");
-
- s.append("#define ");
- s.append(e->getName());
- s.append("_t struct struct_");
- s.append(e->getName());
- s.append("\n\n");
- if (rsc->props.mLogScripts) {
- LOGV("%s", static_cast<const char*>(s));
- }
- str->append(s);
- }
-
- if (mSlotNames[ct].length() > 0) {
- String8 s;
- if (e->getName()) {
- // Use the named struct
- s.setTo(e->getName());
- } else {
- // create an struct named from the slot.
- s.setTo("struct ");
- s.append(mSlotNames[ct]);
- s.append("_s");
- s.append(e->getCStructBody());
- //appendElementBody(&s, e);
- s.append(";\n");
- s.append("struct ");
- s.append(mSlotNames[ct]);
- s.append("_s");
- }
-
- s.append(" * ");
- s.append(mSlotNames[ct]);
- s.append(";\n");
- if (rsc->props.mLogScripts) {
- LOGV("%s", static_cast<const char*>(s));
- }
- str->append(s);
- }
- }
-}
namespace android {
@@ -420,7 +390,6 @@ RsScript rsi_ScriptCCreate(Context * rsc)
s->setContext(rsc);
for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
s->mTypes[ct].set(ss->mConstantBufferTypes[ct].get());
- s->mSlotNames[ct] = ss->mSlotNames[ct];
s->mSlotWritable[ct] = ss->mSlotWritable[ct];
}
@@ -428,18 +397,6 @@ RsScript rsi_ScriptCCreate(Context * rsc)
return s;
}
-void rsi_ScriptCSetDefineF(Context *rsc, const char* name, float value)
-{
- ScriptCState *ss = &rsc->mScriptC;
- ss->mFloatDefines.add(String8(name), value);
-}
-
-void rsi_ScriptCSetDefineI32(Context *rsc, const char* name, int32_t value)
-{
- ScriptCState *ss = &rsc->mScriptC;
- ss->mInt32Defines.add(String8(name), value);
-}
-
}
}
diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h
index 35abadf..50e8a4c 100644
--- a/libs/rs/rsScriptC.h
+++ b/libs/rs/rsScriptC.h
@@ -21,9 +21,7 @@
#include "RenderScriptEnv.h"
-#include <utils/KeyedVector.h>
-
-struct ACCscript;
+struct BCCscript;
// ---------------------------------------------------------------------------
namespace android {
@@ -34,7 +32,7 @@ namespace renderscript {
class ScriptC : public Script
{
public:
- typedef int (*RunScript_t)(uint32_t launchIndex);
+ typedef int (*RunScript_t)();
typedef void (*VoidFunc_t)();
ScriptC(Context *);
@@ -44,18 +42,33 @@ public:
int mVersionMajor;
int mVersionMinor;
- RunScript_t mScript;
+ RunScript_t mRoot;
VoidFunc_t mInit;
-
- void ** mSlotPointers[MAX_SCRIPT_BANKS];
};
Program_t mProgram;
- ACCscript* mAccScript;
+ BCCscript* mBccScript;
+
+ const Allocation *ptrToAllocation(const void *) const;
+
+
+ virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len);
- virtual void setupScript();
- virtual uint32_t run(Context *, uint32_t launchID);
+ virtual uint32_t run(Context *);
+
+ virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout);
+ virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout, uint32_t xStart, uint32_t xEnd);
+ virtual void runForEach(Context *rsc, const Allocation *ain, Allocation *aout, uint32_t xStart, uint32_t yStart, uint32_t xEnd, uint32_t yEnd);
+
+ virtual void serialize(OStream *stream) const { }
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; }
+ static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; }
+
+protected:
+ void setupScript(Context *);
+ void setupGLState(Context *);
+ Script * setTLS(Script *);
};
class ScriptCState
@@ -67,27 +80,21 @@ public:
ScriptC *mScript;
ObjectBaseRef<const Type> mConstantBufferTypes[MAX_SCRIPT_BANKS];
- String8 mSlotNames[MAX_SCRIPT_BANKS];
+ //String8 mSlotNames[MAX_SCRIPT_BANKS];
bool mSlotWritable[MAX_SCRIPT_BANKS];
- String8 mInvokableNames[MAX_SCRIPT_BANKS];
+ //String8 mInvokableNames[MAX_SCRIPT_BANKS];
void clear();
void runCompiler(Context *rsc, ScriptC *s);
- void appendVarDefines(const Context *rsc, String8 *str);
- void appendTypes(const Context *rsc, String8 *str);
struct SymbolTable_t {
const char * mName;
void * mPtr;
- const char * mRet;
- const char * mParam;
};
- static SymbolTable_t gSyms[];
+ //static SymbolTable_t gSyms[];
static const SymbolTable_t * lookupSymbol(const char *);
- static void appendDecls(String8 *str);
-
- KeyedVector<String8,int> mInt32Defines;
- KeyedVector<String8,float> mFloatDefines;
+ static const SymbolTable_t * lookupSymbolCL(const char *);
+ static const SymbolTable_t * lookupSymbolGL(const char *);
};
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 202ca3d..3f3ff23 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -17,18 +17,10 @@
#include "rsContext.h"
#include "rsScriptC.h"
#include "rsMatrix.h"
-#include "rsNoise.h"
#include "acc/acc.h"
#include "utils/Timers.h"
-#define GL_GLEXT_PROTOTYPES
-
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-
#include <time.h>
using namespace android;
@@ -39,6 +31,13 @@ using namespace android::renderscript;
Context * rsc = tls->mContext; \
ScriptC * sc = (ScriptC *) tls->mScript
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+// Non-Updated code below
+//////////////////////////////////////////////////////////////////////////////
+
typedef struct {
float x;
float y;
@@ -57,123 +56,6 @@ typedef struct {
float y;
} vec2_t;
-//////////////////////////////////////////////////////////////////////////////
-// IO routines
-//////////////////////////////////////////////////////////////////////////////
-
-static float SC_loadF(uint32_t bank, uint32_t offset)
-{
- GET_TLS();
- const void *vp = sc->mSlots[bank]->getPtr();
- const float *f = static_cast<const float *>(vp);
- //LOGE("loadF %i %i = %f %x", bank, offset, f, ((int *)&f)[0]);
- return f[offset];
-}
-
-static int32_t SC_loadI32(uint32_t bank, uint32_t offset)
-{
- GET_TLS();
- const void *vp = sc->mSlots[bank]->getPtr();
- const int32_t *i = static_cast<const int32_t *>(vp);
- //LOGE("loadI32 %i %i = %i", bank, offset, t);
- return i[offset];
-}
-
-static float* SC_loadArrayF(uint32_t bank, uint32_t offset)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- float *f = static_cast<float *>(vp);
- return f + offset;
-}
-
-static int32_t* SC_loadArrayI32(uint32_t bank, uint32_t offset)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- int32_t *i = static_cast<int32_t *>(vp);
- return i + offset;
-}
-
-static float* SC_loadSimpleMeshVerticesF(RsSimpleMesh mesh, uint32_t idx)
-{
- SimpleMesh *tm = static_cast<SimpleMesh *>(mesh);
- void *vp = tm->mVertexBuffers[idx]->getPtr();;
- return static_cast<float *>(vp);
-}
-
-static void SC_updateSimpleMesh(RsSimpleMesh mesh)
-{
- GET_TLS();
- SimpleMesh *sm = static_cast<SimpleMesh *>(mesh);
- sm->uploadAll(rsc);
-}
-
-static uint32_t SC_loadU32(uint32_t bank, uint32_t offset)
-{
- GET_TLS();
- const void *vp = sc->mSlots[bank]->getPtr();
- const uint32_t *i = static_cast<const uint32_t *>(vp);
- return i[offset];
-}
-
-static void SC_loadVec4(uint32_t bank, uint32_t offset, rsc_Vector4 *v)
-{
- GET_TLS();
- const void *vp = sc->mSlots[bank]->getPtr();
- const float *f = static_cast<const float *>(vp);
- memcpy(v, &f[offset], sizeof(rsc_Vector4));
-}
-
-static void SC_loadMatrix(uint32_t bank, uint32_t offset, rsc_Matrix *m)
-{
- GET_TLS();
- const void *vp = sc->mSlots[bank]->getPtr();
- const float *f = static_cast<const float *>(vp);
- memcpy(m, &f[offset], sizeof(rsc_Matrix));
-}
-
-
-static void SC_storeF(uint32_t bank, uint32_t offset, float v)
-{
- //LOGE("storeF %i %i %f", bank, offset, v);
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- float *f = static_cast<float *>(vp);
- f[offset] = v;
-}
-
-static void SC_storeI32(uint32_t bank, uint32_t offset, int32_t v)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- int32_t *f = static_cast<int32_t *>(vp);
- static_cast<int32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
-}
-
-static void SC_storeU32(uint32_t bank, uint32_t offset, uint32_t v)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- uint32_t *f = static_cast<uint32_t *>(vp);
- static_cast<uint32_t *>(sc->mSlots[bank]->getPtr())[offset] = v;
-}
-
-static void SC_storeVec4(uint32_t bank, uint32_t offset, const rsc_Vector4 *v)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- float *f = static_cast<float *>(vp);
- memcpy(&f[offset], v, sizeof(rsc_Vector4));
-}
-
-static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m)
-{
- GET_TLS();
- void *vp = sc->mSlots[bank]->getPtr();
- float *f = static_cast<float *>(vp);
- memcpy(&f[offset], m, sizeof(rsc_Matrix));
-}
//////////////////////////////////////////////////////////////////////////////
// Vec3 routines
@@ -281,10 +163,6 @@ static void SC_vec4Scale(vec4_t *lhs, float scale)
// Math routines
//////////////////////////////////////////////////////////////////////////////
-#define PI 3.1415926f
-#define DEG_TO_RAD PI / 180.0f
-#define RAD_TO_DEG 180.0f / PI
-
static float SC_sinf_fast(float x)
{
const float A = 1.0f / (2.0f * M_PI);
@@ -323,6 +201,7 @@ static float SC_cosf_fast(float x)
return 0.2215f * (y * fabsf(y) - y) + y;
}
+
static float SC_randf(float max)
{
float r = (float)rand();
@@ -335,19 +214,14 @@ static float SC_randf2(float min, float max)
return r / RAND_MAX * (max - min) + min;
}
-static int SC_sign(int value)
+static int SC_randi(int max)
{
- return (value > 0) - (value < 0);
+ return (int)SC_randf(max);
}
-static float SC_signf(float value)
+static int SC_randi2(int min, int max)
{
- return (value > 0) - (value < 0);
-}
-
-static float SC_clampf(float amount, float low, float high)
-{
- return amount < low ? low : (amount > high ? high : amount);
+ return (int)SC_randf2(min, max);
}
static int SC_clamp(int amount, int low, int high)
@@ -355,31 +229,6 @@ static int SC_clamp(int amount, int low, int high)
return amount < low ? low : (amount > high ? high : amount);
}
-static float SC_maxf(float a, float b)
-{
- return a > b ? a : b;
-}
-
-static float SC_minf(float a, float b)
-{
- return a < b ? a : b;
-}
-
-static float SC_sqrf(float v)
-{
- return v * v;
-}
-
-static int SC_sqr(int v)
-{
- return v * v;
-}
-
-static float SC_fracf(float v)
-{
- return v - floorf(v);
-}
-
static float SC_roundf(float v)
{
return floorf(v + 0.4999999999);
@@ -410,29 +259,10 @@ static float SC_magf3(float a, float b, float c)
return sqrtf(a * a + b * b + c * c);
}
-static float SC_radf(float degrees)
-{
- return degrees * DEG_TO_RAD;
-}
-
-static float SC_degf(float radians)
-{
- return radians * RAD_TO_DEG;
-}
-
-static float SC_lerpf(float start, float stop, float amount)
-{
- return start + (stop - start) * amount;
-}
-
-static float SC_normf(float start, float stop, float value)
-{
- return (value - start) / (stop - start);
-}
-
-static float SC_mapf(float minStart, float minStop, float maxStart, float maxStop, float value)
+static float SC_frac(float v)
{
- return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
+ int i = (int)floor(v);
+ return fmin(v - i, 0x1.fffffep-1f);
}
//////////////////////////////////////////////////////////////////////////////
@@ -511,6 +341,24 @@ static int32_t SC_year()
return timeinfo->tm_year;
}
+static int64_t SC_uptimeMillis2()
+{
+ return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
+}
+
+static int64_t SC_startTimeMillis2()
+{
+ GET_TLS();
+ return sc->mEnviroment.mStartTimeMillis;
+}
+
+static int64_t SC_elapsedTimeMillis2()
+{
+ GET_TLS();
+ return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC))
+ - sc->mEnviroment.mStartTimeMillis;
+}
+
static int32_t SC_uptimeMillis()
{
return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
@@ -602,477 +450,161 @@ static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z)
}
-static void SC_vec2Rand(float *vec, float maxLen)
-{
- float angle = SC_randf(PI * 2);
- float len = SC_randf(maxLen);
- vec[0] = len * sinf(angle);
- vec[1] = len * cosf(angle);
-}
-
-
-
//////////////////////////////////////////////////////////////////////////////
-// Context
+//
//////////////////////////////////////////////////////////////////////////////
-static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
+static uint32_t SC_allocGetDimX(RsAllocation va)
{
GET_TLS();
- rsi_ProgramBindTexture(rsc,
- static_cast<ProgramFragment *>(vpf),
- slot,
- static_cast<Allocation *>(va));
-
+ const Allocation *a = static_cast<const Allocation *>(va);
+ //LOGE("SC_allocGetDimX a=%p", a);
+ //LOGE(" type=%p", a->getType());
+ return a->getType()->getDimX();
}
-static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
+static uint32_t SC_allocGetDimY(RsAllocation va)
{
GET_TLS();
- rsi_ProgramBindSampler(rsc,
- static_cast<ProgramFragment *>(vpf),
- slot,
- static_cast<Sampler *>(vs));
-
+ const Allocation *a = static_cast<const Allocation *>(va);
+ return a->getType()->getDimY();
}
-static void SC_bindProgramFragmentStore(RsProgramFragmentStore pfs)
+static uint32_t SC_allocGetDimZ(RsAllocation va)
{
GET_TLS();
- rsi_ContextBindProgramFragmentStore(rsc, pfs);
-
+ const Allocation *a = static_cast<const Allocation *>(va);
+ return a->getType()->getDimZ();
}
-static void SC_bindProgramFragment(RsProgramFragment pf)
+static uint32_t SC_allocGetDimLOD(RsAllocation va)
{
GET_TLS();
- rsi_ContextBindProgramFragment(rsc, pf);
-
+ const Allocation *a = static_cast<const Allocation *>(va);
+ return a->getType()->getDimLOD();
}
-static void SC_bindProgramVertex(RsProgramVertex pv)
+static uint32_t SC_allocGetDimFaces(RsAllocation va)
{
GET_TLS();
- rsi_ContextBindProgramVertex(rsc, pv);
-
+ const Allocation *a = static_cast<const Allocation *>(va);
+ return a->getType()->getDimFaces();
}
-//////////////////////////////////////////////////////////////////////////////
-// VP
-//////////////////////////////////////////////////////////////////////////////
-static void SC_vpLoadModelMatrix(const rsc_Matrix *m)
-{
- GET_TLS();
- rsc->getVertex()->setModelviewMatrix(m);
-}
-static void SC_vpLoadTextureMatrix(const rsc_Matrix *m)
-{
- GET_TLS();
- rsc->getVertex()->setTextureMatrix(m);
+static void SC_debugF(const char *s, float f) {
+ LOGE("%s %f, 0x%08x", s, f, *((int *) (&f)));
}
-
-
-
-//////////////////////////////////////////////////////////////////////////////
-// Drawing
-//////////////////////////////////////////////////////////////////////////////
-
-static void SC_drawLine(float x1, float y1, float z1,
- float x2, float y2, float z2)
-{
- GET_TLS();
- if (!rsc->setupCheck()) {
- return;
- }
-
- float vtx[] = { x1, y1, z1, x2, y2, z2 };
- VertexArray va;
- va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
- if (rsc->checkVersion2_0()) {
- va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
- } else {
- va.setupGL(rsc, &rsc->mStateVertexArray);
- }
-
- glDrawArrays(GL_LINES, 0, 2);
+static void SC_debugFv2(const char *s, rsvF_2 fv) {
+ float *f = (float *)&fv;
+ LOGE("%s {%f, %f}", s, f[0], f[1]);
}
-
-static void SC_drawPoint(float x, float y, float z)
-{
- GET_TLS();
- if (!rsc->setupCheck()) {
- return;
- }
-
- float vtx[] = { x, y, z };
-
- VertexArray va;
- va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
- if (rsc->checkVersion2_0()) {
- va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
- } else {
- va.setupGL(rsc, &rsc->mStateVertexArray);
- }
-
- glDrawArrays(GL_POINTS, 0, 1);
+static void SC_debugFv3(const char *s, rsvF_4 fv) {
+ float *f = (float *)&fv;
+ LOGE("%s {%f, %f, %f}", s, f[0], f[1], f[2]);
}
-
-static void SC_drawQuadTexCoords(float x1, float y1, float z1,
- float u1, float v1,
- float x2, float y2, float z2,
- float u2, float v2,
- float x3, float y3, float z3,
- float u3, float v3,
- float x4, float y4, float z4,
- float u4, float v4)
-{
- GET_TLS();
- if (!rsc->setupCheck()) {
- return;
- }
-
- //LOGE("Quad");
- //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
- //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
- //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
- //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
-
- float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
- const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
-
- VertexArray va;
- va.addLegacy(GL_FLOAT, 3, 12, RS_KIND_POSITION, false, (uint32_t)vtx);
- va.addLegacy(GL_FLOAT, 2, 8, RS_KIND_TEXTURE, false, (uint32_t)tex);
- if (rsc->checkVersion2_0()) {
- va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
- } else {
- va.setupGL(rsc, &rsc->mStateVertexArray);
- }
-
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+static void SC_debugFv4(const char *s, rsvF_4 fv) {
+ float *f = (float *)&fv;
+ LOGE("%s {%f, %f, %f, %f}", s, f[0], f[1], f[2], f[3]);
}
-
-static void SC_drawQuad(float x1, float y1, float z1,
- float x2, float y2, float z2,
- float x3, float y3, float z3,
- float x4, float y4, float z4)
-{
- SC_drawQuadTexCoords(x1, y1, z1, 0, 1,
- x2, y2, z2, 1, 1,
- x3, y3, z3, 1, 0,
- x4, y4, z4, 0, 0);
+static void SC_debugI32(const char *s, int32_t i) {
+ LOGE("%s %i 0x%x", s, i, i);
}
-static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h)
-{
- GET_TLS();
- ObjectBaseRef<const ProgramVertex> tmp(rsc->getVertex());
- rsc->setVertex(rsc->getDefaultProgramVertex());
- //rsc->setupCheck();
-
- //GLint crop[4] = {0, h, w, -h};
-
- float sh = rsc->getHeight();
-
- SC_drawQuad(x, sh - y, z,
- x+w, sh - y, z,
- x+w, sh - (y+h), z,
- x, sh - (y+h), z);
- rsc->setVertex((ProgramVertex *)tmp.get());
+static uchar4 SC_convertColorTo8888_f3(float r, float g, float b) {
+ uchar4 t;
+ t.f[0] = (uint8_t)(r * 255.f);
+ t.f[1] = (uint8_t)(g * 255.f);
+ t.f[2] = (uint8_t)(b * 255.f);
+ t.f[3] = 0xff;
+ return t;
}
-static void SC_drawSpriteScreenspaceCropped(float x, float y, float z, float w, float h,
- float cx0, float cy0, float cx1, float cy1)
-{
- GET_TLS();
- if (!rsc->setupCheck()) {
- return;
- }
-
- GLint crop[4] = {cx0, cy0, cx1, cy1};
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
- glDrawTexfOES(x, y, z, w, h);
+static uchar4 SC_convertColorTo8888_f4(float r, float g, float b, float a) {
+ uchar4 t;
+ t.f[0] = (uint8_t)(r * 255.f);
+ t.f[1] = (uint8_t)(g * 255.f);
+ t.f[2] = (uint8_t)(b * 255.f);
+ t.f[3] = (uint8_t)(a * 255.f);
+ return t;
}
-static void SC_drawSprite(float x, float y, float z, float w, float h)
+static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace)
{
GET_TLS();
- float vin[3] = {x, y, z};
- float vout[4];
-
- //LOGE("ds in %f %f %f", x, y, z);
- rsc->getVertex()->transformToScreen(rsc, vout, vin);
- //LOGE("ds out %f %f %f %f", vout[0], vout[1], vout[2], vout[3]);
- vout[0] /= vout[3];
- vout[1] /= vout[3];
- vout[2] /= vout[3];
-
- vout[0] *= rsc->getWidth() / 2;
- vout[1] *= rsc->getHeight() / 2;
- vout[0] += rsc->getWidth() / 2;
- vout[1] += rsc->getHeight() / 2;
-
- vout[0] -= w/2;
- vout[1] -= h/2;
-
- //LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]);
-
- // U, V, W, H
- SC_drawSpriteScreenspace(vout[0], vout[1], z, h, w);
- //rsc->setupCheck();
-}
-
-
-static void SC_drawRect(float x1, float y1,
- float x2, float y2, float z)
-{
- SC_drawQuad(x1, y2, z,
- x2, y2, z,
- x2, y1, z,
- x1, y1, z);
+ //LOGE("SC_toClient %i %i %i", cmdID, len, waitForSpace);
+ return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0);
}
-static void SC_drawSimpleMesh(RsSimpleMesh vsm)
+static void SC_scriptCall(int scriptID)
{
GET_TLS();
- SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
- if (!rsc->setupCheck()) {
- return;
- }
- sm->render(rsc);
+ rsc->runScript((Script *)scriptID);
}
-static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len)
+int SC_divsi3(int a, int b)
{
- GET_TLS();
- SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
- if (!rsc->setupCheck()) {
- return;
- }
- sm->renderRange(rsc, start, len);
+ return a / b;
}
-
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-
-static void SC_color(float r, float g, float b, float a)
+int SC_getAllocation(const void *ptr)
{
GET_TLS();
- rsc->mStateVertex.color[0] = r;
- rsc->mStateVertex.color[1] = g;
- rsc->mStateVertex.color[2] = b;
- rsc->mStateVertex.color[3] = a;
- if (!rsc->checkVersion2_0()) {
- glColor4f(r, g, b, a);
- }
-}
-
-static void SC_ambient(float r, float g, float b, float a)
-{
- GLfloat params[] = { r, g, b, a };
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, params);
+ const Allocation *alloc = sc->ptrToAllocation(ptr);
+ return (int)alloc;
}
-static void SC_diffuse(float r, float g, float b, float a)
-{
- GLfloat params[] = { r, g, b, a };
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, params);
-}
-static void SC_specular(float r, float g, float b, float a)
-{
- GLfloat params[] = { r, g, b, a };
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, params);
-}
-
-static void SC_emission(float r, float g, float b, float a)
-{
- GLfloat params[] = { r, g, b, a };
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, params);
-}
-
-static void SC_shininess(float s)
-{
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, s);
-}
-
-static void SC_pointAttenuation(float a, float b, float c)
-{
- GLfloat params[] = { a, b, c };
- glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, params);
-}
-
-static void SC_hsbToRgb(float h, float s, float b, float* rgb)
-{
- float red = 0.0f;
- float green = 0.0f;
- float blue = 0.0f;
-
- float x = h;
- float y = s;
- float z = b;
-
- float hf = (x - (int) x) * 6.0f;
- int ihf = (int) hf;
- float f = hf - ihf;
- float pv = z * (1.0f - y);
- float qv = z * (1.0f - y * f);
- float tv = z * (1.0f - y * (1.0f - f));
-
- switch (ihf) {
- case 0: // Red is the dominant color
- red = z;
- green = tv;
- blue = pv;
- break;
- case 1: // Green is the dominant color
- red = qv;
- green = z;
- blue = pv;
- break;
- case 2:
- red = pv;
- green = z;
- blue = tv;
- break;
- case 3: // Blue is the dominant color
- red = pv;
- green = qv;
- blue = z;
- break;
- case 4:
- red = tv;
- green = pv;
- blue = z;
- break;
- case 5: // Red is the dominant color
- red = z;
- green = pv;
- blue = qv;
- break;
- }
-
- rgb[0] = red;
- rgb[1] = green;
- rgb[2] = blue;
-}
-
-static int SC_hsbToAbgr(float h, float s, float b, float a)
-{
- float rgb[3];
- SC_hsbToRgb(h, s, b, rgb);
- return int(a * 255.0f) << 24 |
- int(rgb[2] * 255.0f) << 16 |
- int(rgb[1] * 255.0f) << 8 |
- int(rgb[0] * 255.0f);
-}
-
-static void SC_hsb(float h, float s, float b, float a)
+void SC_ForEachii(RsScript vs, RsAllocation vin)
{
GET_TLS();
- float rgb[3];
- SC_hsbToRgb(h, s, b, rgb);
- if (rsc->checkVersion2_0()) {
- glVertexAttrib4f(1, rgb[0], rgb[1], rgb[2], a);
- } else {
- glColor4f(rgb[0], rgb[1], rgb[2], a);
- }
+ Script *s = static_cast<Script *>(vs);
+ Allocation *ain = static_cast<Allocation *>(vin);
+ s->runForEach(rsc, ain, NULL);
}
-static void SC_uploadToTexture(RsAllocation va, uint32_t baseMipLevel)
+void SC_ForEachiii(RsScript vs, RsAllocation vin, RsAllocation vout)
{
GET_TLS();
- rsi_AllocationUploadToTexture(rsc, va, false, baseMipLevel);
+ Script *s = static_cast<Script *>(vs);
+ Allocation *ain = static_cast<Allocation *>(vin);
+ Allocation *aout = static_cast<Allocation *>(vout);
+ s->runForEach(rsc, ain, aout);
}
-static void SC_uploadToBufferObject(RsAllocation va)
+void SC_ForEachiiii(RsScript vs, RsAllocation vin, int xStart, int xEnd)
{
GET_TLS();
- rsi_AllocationUploadToBufferObject(rsc, va);
+ Script *s = static_cast<Script *>(vs);
+ Allocation *ain = static_cast<Allocation *>(vin);
+ s->runForEach(rsc, ain, NULL, xStart, xEnd);
}
-static void SC_syncToGL(RsAllocation va)
+void SC_ForEachiiiii(RsScript vs, RsAllocation vin, RsAllocation vout, int xStart, int xEnd)
{
GET_TLS();
- Allocation *a = static_cast<Allocation *>(va);
-
+ Script *s = static_cast<Script *>(vs);
+ Allocation *ain = static_cast<Allocation *>(vin);
+ Allocation *aout = static_cast<Allocation *>(vout);
+ s->runForEach(rsc, ain, aout, xStart, xEnd);
}
-static void SC_ClearColor(float r, float g, float b, float a)
+void SC_ForEachiiiiii(RsScript vs, RsAllocation vin, int xStart, int yStart, int xEnd, int yEnd)
{
- //LOGE("c %f %f %f %f", r, g, b, a);
GET_TLS();
- sc->mEnviroment.mClearColor[0] = r;
- sc->mEnviroment.mClearColor[1] = g;
- sc->mEnviroment.mClearColor[2] = b;
- sc->mEnviroment.mClearColor[3] = a;
-}
-
-static void SC_debugF(const char *s, float f)
-{
- LOGE("%s %f", s, f);
-}
-
-static void SC_debugHexF(const char *s, float f)
-{
- LOGE("%s 0x%x", s, *((int *) (&f)));
-}
-
-static void SC_debugI32(const char *s, int32_t i)
-{
- LOGE("%s %i", s, i);
+ Script *s = static_cast<Script *>(vs);
+ Allocation *ain = static_cast<Allocation *>(vin);
+ s->runForEach(rsc, ain, NULL, xStart, yStart, xEnd, yEnd);
}
-static void SC_debugHexI32(const char *s, int32_t i)
-{
- LOGE("%s 0x%x", s, i);
-}
-
-static uint32_t SC_getWidth()
-{
- GET_TLS();
- return rsc->getWidth();
-}
-
-static uint32_t SC_getHeight()
-{
- GET_TLS();
- return rsc->getHeight();
-}
-
-static uint32_t SC_colorFloatRGBAtoUNorm8(float r, float g, float b, float a)
-{
- uint32_t c = 0;
- c |= (uint32_t)(r * 255.f + 0.5f);
- c |= ((uint32_t)(g * 255.f + 0.5f)) << 8;
- c |= ((uint32_t)(b * 255.f + 0.5f)) << 16;
- c |= ((uint32_t)(a * 255.f + 0.5f)) << 24;
- return c;
-}
-
-static uint32_t SC_colorFloatRGBAto565(float r, float g, float b)
-{
- uint32_t ir = (uint32_t)(r * 255.f + 0.5f);
- uint32_t ig = (uint32_t)(g * 255.f + 0.5f);
- uint32_t ib = (uint32_t)(b * 255.f + 0.5f);
- return rs888to565(ir, ig, ib);
-}
-
-static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace)
-{
- GET_TLS();
- return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0);
-}
-
-static void SC_scriptCall(int scriptID)
+void SC_ForEachiiiiiii(RsScript vs, RsAllocation vin, RsAllocation vout, int xStart, int yStart, int xEnd, int yEnd)
{
GET_TLS();
- rsc->runScript((Script *)scriptID, 0);
+ Script *s = static_cast<Script *>(vs);
+ Allocation *ain = static_cast<Allocation *>(vin);
+ Allocation *aout = static_cast<Allocation *>(vout);
+ s->runForEach(rsc, ain, aout, xStart, yStart, xEnd, yEnd);
}
@@ -1080,311 +612,108 @@ static void SC_scriptCall(int scriptID)
// Class implementation
//////////////////////////////////////////////////////////////////////////////
-ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
- // IO
- { "loadI32", (void *)&SC_loadI32,
- "int", "(int, int)" },
- //{ "loadU32", (void *)&SC_loadU32, "unsigned int", "(int, int)" },
- { "loadF", (void *)&SC_loadF,
- "float", "(int, int)" },
- { "loadArrayF", (void *)&SC_loadArrayF,
- "float*", "(int, int)" },
- { "loadArrayI32", (void *)&SC_loadArrayI32,
- "int*", "(int, int)" },
- { "loadVec4", (void *)&SC_loadVec4,
- "void", "(int, int, float *)" },
- { "loadMatrix", (void *)&SC_loadMatrix,
- "void", "(int, int, float *)" },
- { "storeI32", (void *)&SC_storeI32,
- "void", "(int, int, int)" },
- //{ "storeU32", (void *)&SC_storeU32, "void", "(int, int, unsigned int)" },
- { "storeF", (void *)&SC_storeF,
- "void", "(int, int, float)" },
- { "storeVec4", (void *)&SC_storeVec4,
- "void", "(int, int, float *)" },
- { "storeMatrix", (void *)&SC_storeMatrix,
- "void", "(int, int, float *)" },
- { "loadSimpleMeshVerticesF", (void *)&SC_loadSimpleMeshVerticesF,
- "float*", "(int, int)" },
- { "updateSimpleMesh", (void *)&SC_updateSimpleMesh,
- "void", "(int)" },
-
- // math
- { "modf", (void *)&fmod,
- "float", "(float, float)" },
- { "abs", (void *)&abs,
- "int", "(int)" },
- { "absf", (void *)&fabsf,
- "float", "(float)" },
- { "sinf_fast", (void *)&SC_sinf_fast,
- "float", "(float)" },
- { "cosf_fast", (void *)&SC_cosf_fast,
- "float", "(float)" },
- { "sinf", (void *)&sinf,
- "float", "(float)" },
- { "cosf", (void *)&cosf,
- "float", "(float)" },
- { "asinf", (void *)&asinf,
- "float", "(float)" },
- { "acosf", (void *)&acosf,
- "float", "(float)" },
- { "atanf", (void *)&atanf,
- "float", "(float)" },
- { "atan2f", (void *)&atan2f,
- "float", "(float, float)" },
- { "fabsf", (void *)&fabsf,
- "float", "(float)" },
- { "randf", (void *)&SC_randf,
- "float", "(float)" },
- { "randf2", (void *)&SC_randf2,
- "float", "(float, float)" },
- { "floorf", (void *)&floorf,
- "float", "(float)" },
- { "fracf", (void *)&SC_fracf,
- "float", "(float)" },
- { "ceilf", (void *)&ceilf,
- "float", "(float)" },
- { "roundf", (void *)&SC_roundf,
- "float", "(float)" },
- { "expf", (void *)&expf,
- "float", "(float)" },
- { "logf", (void *)&logf,
- "float", "(float)" },
- { "powf", (void *)&powf,
- "float", "(float, float)" },
- { "maxf", (void *)&SC_maxf,
- "float", "(float, float)" },
- { "minf", (void *)&SC_minf,
- "float", "(float, float)" },
- { "sqrt", (void *)&sqrt,
- "int", "(int)" },
- { "sqrtf", (void *)&sqrtf,
- "float", "(float)" },
- { "sqr", (void *)&SC_sqr,
- "int", "(int)" },
- { "sqrf", (void *)&SC_sqrf,
- "float", "(float)" },
- { "sign", (void *)&SC_sign,
- "int", "(int)" },
- { "signf", (void *)&SC_signf,
- "float", "(float)" },
- { "clamp", (void *)&SC_clamp,
- "int", "(int, int, int)" },
- { "clampf", (void *)&SC_clampf,
- "float", "(float, float, float)" },
- { "distf2", (void *)&SC_distf2,
- "float", "(float, float, float, float)" },
- { "distf3", (void *)&SC_distf3,
- "float", "(float, float, float, float, float, float)" },
- { "magf2", (void *)&SC_magf2,
- "float", "(float, float)" },
- { "magf3", (void *)&SC_magf3,
- "float", "(float, float, float)" },
- { "radf", (void *)&SC_radf,
- "float", "(float)" },
- { "degf", (void *)&SC_degf,
- "float", "(float)" },
- { "lerpf", (void *)&SC_lerpf,
- "float", "(float, float, float)" },
- { "normf", (void *)&SC_normf,
- "float", "(float, float, float)" },
- { "mapf", (void *)&SC_mapf,
- "float", "(float, float, float, float, float)" },
- { "noisef", (void *)&SC_noisef,
- "float", "(float)" },
- { "noisef2", (void *)&SC_noisef2,
- "float", "(float, float)" },
- { "noisef3", (void *)&SC_noisef3,
- "float", "(float, float, float)" },
- { "turbulencef2", (void *)&SC_turbulencef2,
- "float", "(float, float, float)" },
- { "turbulencef3", (void *)&SC_turbulencef3,
- "float", "(float, float, float, float)" },
+// llvm name mangling ref
+// <builtin-type> ::= v # void
+// ::= b # bool
+// ::= c # char
+// ::= a # signed char
+// ::= h # unsigned char
+// ::= s # short
+// ::= t # unsigned short
+// ::= i # int
+// ::= j # unsigned int
+// ::= l # long
+// ::= m # unsigned long
+// ::= x # long long, __int64
+// ::= y # unsigned long long, __int64
+// ::= f # float
+// ::= d # double
+
+static ScriptCState::SymbolTable_t gSyms[] = {
+ { "__divsi3", (void *)&SC_divsi3 },
+
+ // allocation
+ { "rsAllocationGetDimX", (void *)&SC_allocGetDimX },
+ { "rsAllocationGetDimY", (void *)&SC_allocGetDimY },
+ { "rsAllocationGetDimZ", (void *)&SC_allocGetDimZ },
+ { "rsAllocationGetDimLOD", (void *)&SC_allocGetDimLOD },
+ { "rsAllocationGetDimFaces", (void *)&SC_allocGetDimFaces },
+ { "rsGetAllocation", (void *)&SC_getAllocation },
+
+ // color
+ { "_Z17rsPackColorTo8888fff", (void *)&SC_convertColorTo8888_f3 },
+ { "_Z17rsPackColorTo8888ffff", (void *)&SC_convertColorTo8888_f4 },
+ //extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3);
+ //extern uchar4 __attribute__((overloadable)) rsPackColorTo8888(float4);
+ //extern float4 rsUnpackColor8888(uchar4);
+ //extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float r, float g, float b);
+ //extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float3);
+ //extern float4 rsUnpackColor565(uchar4);
+
+ // Debug
+ { "_Z7rsDebugPKcf", (void *)&SC_debugF },
+ { "_Z7rsDebugPKcDv2_f", (void *)&SC_debugFv2 },
+ { "_Z7rsDebugPKcDv3_f", (void *)&SC_debugFv3 },
+ { "_Z7rsDebugPKcDv4_f", (void *)&SC_debugFv4 },
+ { "_Z7rsDebugPKci", (void *)&SC_debugI32 },
+ //extern void __attribute__((overloadable))rsDebug(const char *, const void *);
+
+
+ // RS Math
+ { "_Z6rsRandi", (void *)&SC_randi },
+ { "_Z6rsRandii", (void *)&SC_randi2 },
+ { "_Z6rsRandf", (void *)&SC_randf },
+ { "_Z6rsRandff", (void *)&SC_randf2 },
+ { "_Z6rsFracf", (void *)&SC_frac },
// time
- { "second", (void *)&SC_second,
- "int", "()" },
- { "minute", (void *)&SC_minute,
- "int", "()" },
- { "hour", (void *)&SC_hour,
- "int", "()" },
- { "day", (void *)&SC_day,
- "int", "()" },
- { "month", (void *)&SC_month,
- "int", "()" },
- { "year", (void *)&SC_year,
- "int", "()" },
- { "uptimeMillis", (void*)&SC_uptimeMillis,
- "int", "()" }, // TODO: use long instead
- { "startTimeMillis", (void*)&SC_startTimeMillis,
- "int", "()" }, // TODO: use long instead
- { "elapsedTimeMillis", (void*)&SC_elapsedTimeMillis,
- "int", "()" }, // TODO: use long instead
+ { "rsSecond", (void *)&SC_second },
+ { "rsMinute", (void *)&SC_minute },
+ { "rsHour", (void *)&SC_hour },
+ { "rsDay", (void *)&SC_day },
+ { "rsMonth", (void *)&SC_month },
+ { "rsYear", (void *)&SC_year },
+ { "rsUptimeMillis", (void*)&SC_uptimeMillis2 },
+ { "rsStartTimeMillis", (void*)&SC_startTimeMillis2 },
+ { "rsElapsedTimeMillis", (void*)&SC_elapsedTimeMillis2 },
+
+ { "rsSendToClient", (void *)&SC_toClient },
// matrix
- { "matrixLoadIdentity", (void *)&SC_matrixLoadIdentity,
- "void", "(float *mat)" },
- { "matrixLoadFloat", (void *)&SC_matrixLoadFloat,
- "void", "(float *mat, float *f)" },
- { "matrixLoadMat", (void *)&SC_matrixLoadMat,
- "void", "(float *mat, float *newmat)" },
- { "matrixLoadRotate", (void *)&SC_matrixLoadRotate,
- "void", "(float *mat, float rot, float x, float y, float z)" },
- { "matrixLoadScale", (void *)&SC_matrixLoadScale,
- "void", "(float *mat, float x, float y, float z)" },
- { "matrixLoadTranslate", (void *)&SC_matrixLoadTranslate,
- "void", "(float *mat, float x, float y, float z)" },
- { "matrixLoadMultiply", (void *)&SC_matrixLoadMultiply,
- "void", "(float *mat, float *lhs, float *rhs)" },
- { "matrixMultiply", (void *)&SC_matrixMultiply,
- "void", "(float *mat, float *rhs)" },
- { "matrixRotate", (void *)&SC_matrixRotate,
- "void", "(float *mat, float rot, float x, float y, float z)" },
- { "matrixScale", (void *)&SC_matrixScale,
- "void", "(float *mat, float x, float y, float z)" },
- { "matrixTranslate", (void *)&SC_matrixTranslate,
- "void", "(float *mat, float x, float y, float z)" },
-
- // vector
- { "vec2Rand", (void *)&SC_vec2Rand,
- "void", "(float *vec, float maxLen)" },
-
- // vec3
- { "vec3Norm", (void *)&SC_vec3Norm,
- "void", "(struct vecF32_3_s *)" },
- { "vec3Length", (void *)&SC_vec3Length,
- "float", "(struct vecF32_3_s *)" },
- { "vec3Add", (void *)&SC_vec3Add,
- "void", "(struct vecF32_3_s *dest, struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
- { "vec3Sub", (void *)&SC_vec3Sub,
- "void", "(struct vecF32_3_s *dest, struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
- { "vec3Cross", (void *)&SC_vec3Cross,
- "void", "(struct vecF32_3_s *dest, struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
- { "vec3Dot", (void *)&SC_vec3Dot,
- "float", "(struct vecF32_3_s *lhs, struct vecF32_3_s *rhs)" },
- { "vec3Scale", (void *)&SC_vec3Scale,
- "void", "(struct vecF32_3_s *lhs, float scale)" },
-
- // vec4
- { "vec4Norm", (void *)&SC_vec4Norm,
- "void", "(struct vecF32_4_s *)" },
- { "vec4Length", (void *)&SC_vec4Length,
- "float", "(struct vecF32_4_s *)" },
- { "vec4Add", (void *)&SC_vec4Add,
- "void", "(struct vecF32_4_s *dest, struct vecF32_4_s *lhs, struct vecF32_4_s *rhs)" },
- { "vec4Sub", (void *)&SC_vec4Sub,
- "void", "(struct vecF32_4_s *dest, struct vecF32_4_s *lhs, struct vecF32_4_s *rhs)" },
- { "vec4Dot", (void *)&SC_vec4Dot,
- "float", "(struct vecF32_4_s *lhs, struct vecF32_4_s *rhs)" },
- { "vec4Scale", (void *)&SC_vec4Scale,
- "void", "(struct vecF32_4_s *lhs, float scale)" },
-
- // context
- { "bindProgramFragment", (void *)&SC_bindProgramFragment,
- "void", "(int)" },
- { "bindProgramFragmentStore", (void *)&SC_bindProgramFragmentStore,
- "void", "(int)" },
- { "bindProgramStore", (void *)&SC_bindProgramFragmentStore,
- "void", "(int)" },
- { "bindProgramVertex", (void *)&SC_bindProgramVertex,
- "void", "(int)" },
- { "bindSampler", (void *)&SC_bindSampler,
- "void", "(int, int, int)" },
- { "bindTexture", (void *)&SC_bindTexture,
- "void", "(int, int, int)" },
-
- // vp
- { "vpLoadModelMatrix", (void *)&SC_vpLoadModelMatrix,
- "void", "(void *)" },
- { "vpLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix,
- "void", "(void *)" },
-
-
-
- // drawing
- { "drawRect", (void *)&SC_drawRect,
- "void", "(float x1, float y1, float x2, float y2, float z)" },
- { "drawQuad", (void *)&SC_drawQuad,
- "void", "(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" },
- { "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
- "void", "(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4)" },
- { "drawSprite", (void *)&SC_drawSprite,
- "void", "(float x, float y, float z, float w, float h)" },
- { "drawSpriteScreenspace", (void *)&SC_drawSpriteScreenspace,
- "void", "(float x, float y, float z, float w, float h)" },
- { "drawSpriteScreenspaceCropped", (void *)&SC_drawSpriteScreenspaceCropped,
- "void", "(float x, float y, float z, float w, float h, float cx0, float cy0, float cx1, float cy1)" },
- { "drawLine", (void *)&SC_drawLine,
- "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
- { "drawPoint", (void *)&SC_drawPoint,
- "void", "(float x1, float y1, float z1)" },
- { "drawSimpleMesh", (void *)&SC_drawSimpleMesh,
- "void", "(int ism)" },
- { "drawSimpleMeshRange", (void *)&SC_drawSimpleMeshRange,
- "void", "(int ism, int start, int len)" },
-
-
- // misc
- { "pfClearColor", (void *)&SC_ClearColor,
- "void", "(float, float, float, float)" },
- { "color", (void *)&SC_color,
- "void", "(float, float, float, float)" },
- { "hsb", (void *)&SC_hsb,
- "void", "(float, float, float, float)" },
- { "hsbToRgb", (void *)&SC_hsbToRgb,
- "void", "(float, float, float, float*)" },
- { "hsbToAbgr", (void *)&SC_hsbToAbgr,
- "int", "(float, float, float, float)" },
- { "ambient", (void *)&SC_ambient,
- "void", "(float, float, float, float)" },
- { "diffuse", (void *)&SC_diffuse,
- "void", "(float, float, float, float)" },
- { "specular", (void *)&SC_specular,
- "void", "(float, float, float, float)" },
- { "emission", (void *)&SC_emission,
- "void", "(float, float, float, float)" },
- { "shininess", (void *)&SC_shininess,
- "void", "(float)" },
- { "pointAttenuation", (void *)&SC_pointAttenuation,
- "void", "(float, float, float)" },
-
- { "uploadToTexture", (void *)&SC_uploadToTexture,
- "void", "(int, int)" },
- { "uploadToBufferObject", (void *)&SC_uploadToBufferObject,
- "void", "(int)" },
-
- { "syncToGL", (void *)&SC_syncToGL,
- "void", "(int)" },
-
- { "colorFloatRGBAtoUNorm8", (void *)&SC_colorFloatRGBAtoUNorm8,
- "int", "(float, float, float, float)" },
- { "colorFloatRGBto565", (void *)&SC_colorFloatRGBAto565,
- "int", "(float, float, float)" },
-
-
- { "getWidth", (void *)&SC_getWidth,
- "int", "()" },
- { "getHeight", (void *)&SC_getHeight,
- "int", "()" },
-
- { "sendToClient", (void *)&SC_toClient,
- "int", "(void *data, int cmdID, int len, int waitForSpace)" },
-
-
- { "debugF", (void *)&SC_debugF,
- "void", "(void *, float)" },
- { "debugI32", (void *)&SC_debugI32,
- "void", "(void *, int)" },
- { "debugHexF", (void *)&SC_debugHexF,
- "void", "(void *, float)" },
- { "debugHexI32", (void *)&SC_debugHexI32,
- "void", "(void *, int)" },
-
- { "scriptCall", (void *)&SC_scriptCall,
- "void", "(int)" },
-
-
- { NULL, NULL, NULL, NULL }
+ { "rsMatrixLoadIdentity", (void *)&SC_matrixLoadIdentity },
+ { "rsMatrixLoadFloat", (void *)&SC_matrixLoadFloat },
+ { "rsMatrixLoadMat", (void *)&SC_matrixLoadMat },
+ { "rsMatrixLoadRotate", (void *)&SC_matrixLoadRotate },
+ { "rsMatrixLoadScale", (void *)&SC_matrixLoadScale },
+ { "rsMatrixLoadTranslate", (void *)&SC_matrixLoadTranslate },
+ { "rsMatrixLoadMultiply", (void *)&SC_matrixLoadMultiply },
+ { "rsMatrixMultiply", (void *)&SC_matrixMultiply },
+ { "rsMatrixRotate", (void *)&SC_matrixRotate },
+ { "rsMatrixScale", (void *)&SC_matrixScale },
+ { "rsMatrixTranslate", (void *)&SC_matrixTranslate },
+
+ { "_Z9rsForEachii", (void *)&SC_ForEachii },
+ { "_Z9rsForEachiii", (void *)&SC_ForEachiii },
+ { "_Z9rsForEachiiii", (void *)&SC_ForEachiiii },
+ { "_Z9rsForEachiiiii", (void *)&SC_ForEachiiiii },
+ { "_Z9rsForEachiiiiii", (void *)&SC_ForEachiiiiii },
+ { "_Z9rsForEachiiiiiii", (void *)&SC_ForEachiiiiiii },
+
+////////////////////////////////////////////////////////////////////
+
+ //{ "sinf_fast", (void *)&SC_sinf_fast },
+ //{ "cosf_fast", (void *)&SC_cosf_fast },
+ //{ "clamp", (void *)&SC_clamp },
+ //{ "distf2", (void *)&SC_distf2 },
+ //{ "distf3", (void *)&SC_distf3 },
+ //{ "magf2", (void *)&SC_magf2 },
+ //{ "magf3", (void *)&SC_magf3 },
+ //{ "mapf", (void *)&SC_mapf },
+
+ { "scriptCall", (void *)&SC_scriptCall },
+
+
+ { NULL, NULL }
};
const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
@@ -1400,17 +729,3 @@ const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
return NULL;
}
-void ScriptCState::appendDecls(String8 *str)
-{
- ScriptCState::SymbolTable_t *syms = gSyms;
- while (syms->mPtr) {
- str->append(syms->mRet);
- str->append(" ");
- str->append(syms->mName);
- str->append(syms->mParam);
- str->append(";\n");
- syms++;
- }
-}
-
-
diff --git a/libs/rs/rsScriptC_LibCL.cpp b/libs/rs/rsScriptC_LibCL.cpp
new file mode 100644
index 0000000..ce8e7b2
--- /dev/null
+++ b/libs/rs/rsScriptC_LibCL.cpp
@@ -0,0 +1,314 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#include "rsContext.h"
+#include "rsScriptC.h"
+
+// Implements rs_cl.rsh
+
+
+using namespace android;
+using namespace android::renderscript;
+
+
+static float SC_acospi(float v) {
+ return acosf(v)/ M_PI;
+}
+
+static float SC_asinpi(float v) {
+ return asinf(v) / M_PI;
+}
+
+static float SC_atanpi(float v) {
+ return atanf(v) / M_PI;
+}
+
+static float SC_atan2pi(float y, float x) {
+ return atan2f(y, x) / M_PI;
+}
+
+static float SC_cospi(float v) {
+ return cosf(v * M_PI);
+}
+
+static float SC_exp10(float v) {
+ return pow(10.f, v);
+
+}
+
+static float SC_fract(float v, int *iptr) {
+ int i = (int)floor(v);
+ iptr[0] = i;
+ return fmin(v - i, 0x1.fffffep-1f);
+}
+
+static float SC_log2(float v) {
+ return log10(v) / log10(2.f);
+}
+
+static float SC_pown(float v, int p) {
+ return powf(v, (float)p);
+}
+
+static float SC_powr(float v, float p) {
+ return powf(v, p);
+}
+
+float SC_rootn(float v, int r) {
+ return pow(v, 1.f / r);
+}
+
+float SC_rsqrt(float v) {
+ return 1.f / sqrtf(v);
+}
+
+float SC_sincos(float v, float *cosptr) {
+ *cosptr = cosf(v);
+ return sinf(v);
+}
+
+static float SC_sinpi(float v) {
+ return sinf(v * M_PI);
+}
+
+static float SC_tanpi(float v) {
+ return tanf(v * M_PI);
+}
+
+ //{ "logb", (void *)& },
+ //{ "mad", (void *)& },
+ //{ "nan", (void *)& },
+ //{ "tgamma", (void *)& },
+
+//////////////////////////////////////////////////////////////////////////////
+// Integer
+//////////////////////////////////////////////////////////////////////////////
+
+
+static uint32_t SC_abs_i32(int32_t v) {return abs(v);}
+static uint16_t SC_abs_i16(int16_t v) {return (uint16_t)abs(v);}
+static uint8_t SC_abs_i8(int8_t v) {return (uint8_t)abs(v);}
+
+static uint32_t SC_clz_u32(uint32_t v) {return __builtin_clz(v);}
+static uint16_t SC_clz_u16(uint16_t v) {return (uint16_t)__builtin_clz(v);}
+static uint8_t SC_clz_u8(uint8_t v) {return (uint8_t)__builtin_clz(v);}
+static int32_t SC_clz_i32(int32_t v) {return (int32_t)__builtin_clz((uint32_t)v);}
+static int16_t SC_clz_i16(int16_t v) {return (int16_t)__builtin_clz(v);}
+static int8_t SC_clz_i8(int8_t v) {return (int8_t)__builtin_clz(v);}
+
+static uint32_t SC_max_u32(uint32_t v, uint32_t v2) {return rsMax(v, v2);}
+static uint16_t SC_max_u16(uint16_t v, uint16_t v2) {return rsMax(v, v2);}
+static uint8_t SC_max_u8(uint8_t v, uint8_t v2) {return rsMax(v, v2);}
+static int32_t SC_max_i32(int32_t v, int32_t v2) {return rsMax(v, v2);}
+static int16_t SC_max_i16(int16_t v, int16_t v2) {return rsMax(v, v2);}
+static int8_t SC_max_i8(int8_t v, int8_t v2) {return rsMax(v, v2);}
+
+static uint32_t SC_min_u32(uint32_t v, uint32_t v2) {return rsMin(v, v2);}
+static uint16_t SC_min_u16(uint16_t v, uint16_t v2) {return rsMin(v, v2);}
+static uint8_t SC_min_u8(uint8_t v, uint8_t v2) {return rsMin(v, v2);}
+static int32_t SC_min_i32(int32_t v, int32_t v2) {return rsMin(v, v2);}
+static int16_t SC_min_i16(int16_t v, int16_t v2) {return rsMin(v, v2);}
+static int8_t SC_min_i8(int8_t v, int8_t v2) {return rsMin(v, v2);}
+
+//////////////////////////////////////////////////////////////////////////////
+// Float util
+//////////////////////////////////////////////////////////////////////////////
+
+static float SC_clamp_f32(float amount, float low, float high)
+{
+ return amount < low ? low : (amount > high ? high : amount);
+}
+
+static float SC_degrees(float radians)
+{
+ return radians * (180.f / M_PI);
+}
+
+static float SC_max_f32(float v, float v2)
+{
+ return rsMax(v, v2);
+}
+
+static float SC_min_f32(float v, float v2)
+{
+ return rsMin(v, v2);
+}
+
+static float SC_mix_f32(float start, float stop, float amount)
+{
+ //LOGE("lerpf %f %f %f", start, stop, amount);
+ return start + (stop - start) * amount;
+}
+
+static float SC_radians(float degrees)
+{
+ return degrees * (M_PI / 180.f);
+}
+
+static float SC_step_f32(float edge, float v)
+{
+ if (v < edge) return 0.f;
+ return 1.f;
+}
+
+static float SC_sign_f32(float value)
+{
+ if (value > 0) return 1.f;
+ if (value < 0) return -1.f;
+ return value;
+}
+
+
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+// Class implementation
+//////////////////////////////////////////////////////////////////////////////
+
+// llvm name mangling ref
+// <builtin-type> ::= v # void
+// ::= b # bool
+// ::= c # char
+// ::= a # signed char
+// ::= h # unsigned char
+// ::= s # short
+// ::= t # unsigned short
+// ::= i # int
+// ::= j # unsigned int
+// ::= l # long
+// ::= m # unsigned long
+// ::= x # long long, __int64
+// ::= y # unsigned long long, __int64
+// ::= f # float
+// ::= d # double
+
+static ScriptCState::SymbolTable_t gSyms[] = {
+ // OpenCL math
+ { "_Z4acosf", (void *)&acosf },
+ { "_Z5acoshf", (void *)&acoshf },
+ { "_Z6acospif", (void *)&SC_acospi },
+ { "_Z4asinf", (void *)&asinf },
+ { "_Z5asinhf", (void *)&asinhf },
+ { "_Z6asinpif", (void *)&SC_asinpi },
+ { "_Z4atanf", (void *)&atanf },
+ { "_Z5atan2f", (void *)&atan2f },
+ { "_Z6atanpif", (void *)&SC_atanpi },
+ { "_Z7atan2pif", (void *)&SC_atan2pi },
+ { "_Z4cbrtf", (void *)&cbrtf },
+ { "_Z4ceilf", (void *)&ceilf },
+ { "_Z8copysignff", (void *)&copysignf },
+ { "_Z3cosf", (void *)&cosf },
+ { "_Z4coshf", (void *)&coshf },
+ { "_Z5cospif", (void *)&SC_cospi },
+ { "_Z4erfcf", (void *)&erfcf },
+ { "_Z3erff", (void *)&erff },
+ { "_Z3expf", (void *)&expf },
+ { "_Z4exp2f", (void *)&exp2f },
+ { "_Z5exp10f", (void *)&SC_exp10 },
+ { "_Z5expm1f", (void *)&expm1f },
+ { "_Z4fabsf", (void *)&fabsf },
+ { "_Z4fdimff", (void *)&fdimf },
+ { "_Z5floorf", (void *)&floorf },
+ { "_Z3fmafff", (void *)&fmaf },
+ { "_Z4fmaxff", (void *)&fmaxf },
+ { "_Z4fminff", (void *)&fminf }, // float fmin(float, float)
+ { "_Z4fmodff", (void *)&fmodf },
+ { "_Z5fractfPf", (void *)&SC_fract },
+ { "_Z5frexpfPi", (void *)&frexpf },
+ { "_Z5hypotff", (void *)&hypotf },
+ { "_Z5ilogbf", (void *)&ilogbf },
+ { "_Z5ldexpfi", (void *)&ldexpf },
+ { "_Z6lgammaf", (void *)&lgammaf },
+ { "_Z3logf", (void *)&logf },
+ { "_Z4log2f", (void *)&SC_log2 },
+ { "_Z5log10f", (void *)&log10f },
+ { "_Z5log1pf", (void *)&log1pf },
+ //{ "logb", (void *)& },
+ //{ "mad", (void *)& },
+ { "modf", (void *)&modff },
+ //{ "nan", (void *)& },
+ { "_Z9nextafterff", (void *)&nextafterf },
+ { "_Z3powff", (void *)&powf },
+ { "_Z4pownfi", (void *)&SC_pown },
+ { "_Z4powrff", (void *)&SC_powr },
+ { "_Z9remainderff", (void *)&remainderf },
+ { "remquo", (void *)&remquof },
+ { "_Z4rintf", (void *)&rintf },
+ { "_Z5rootnfi", (void *)&SC_rootn },
+ { "_Z5roundf", (void *)&roundf },
+ { "_Z5rsqrtf", (void *)&SC_rsqrt },
+ { "_Z3sinf", (void *)&sinf },
+ { "sincos", (void *)&SC_sincos },
+ { "_Z4sinhf", (void *)&sinhf },
+ { "_Z5sinpif", (void *)&SC_sinpi },
+ { "_Z4sqrtf", (void *)&sqrtf },
+ { "_Z3tanf", (void *)&tanf },
+ { "_Z4tanhf", (void *)&tanhf },
+ { "_Z5tanpif", (void *)&SC_tanpi },
+ //{ "tgamma", (void *)& },
+ { "_Z5truncf", (void *)&truncf },
+
+ // OpenCL Int
+ { "_Z3absi", (void *)&SC_abs_i32 },
+ { "_Z3abss", (void *)&SC_abs_i16 },
+ { "_Z3absc", (void *)&SC_abs_i8 },
+ { "_Z3clzj", (void *)&SC_clz_u32 },
+ { "_Z3clzt", (void *)&SC_clz_u16 },
+ { "_Z3clzh", (void *)&SC_clz_u8 },
+ { "_Z3clzi", (void *)&SC_clz_i32 },
+ { "_Z3clzs", (void *)&SC_clz_i16 },
+ { "_Z3clzc", (void *)&SC_clz_i8 },
+ { "_Z3maxjj", (void *)&SC_max_u32 },
+ { "_Z3maxtt", (void *)&SC_max_u16 },
+ { "_Z3maxhh", (void *)&SC_max_u8 },
+ { "_Z3maxii", (void *)&SC_max_i32 },
+ { "_Z3maxss", (void *)&SC_max_i16 },
+ { "_Z3maxcc", (void *)&SC_max_i8 },
+ { "_Z3minjj", (void *)&SC_min_u32 },
+ { "_Z3mintt", (void *)&SC_min_u16 },
+ { "_Z3minhh", (void *)&SC_min_u8 },
+ { "_Z3minii", (void *)&SC_min_i32 },
+ { "_Z3minss", (void *)&SC_min_i16 },
+ { "_Z3mincc", (void *)&SC_min_i8 },
+
+ // OpenCL 6.11.4
+ { "_Z5clampfff", (void *)&SC_clamp_f32 },
+ { "_Z7degreesf", (void *)&SC_degrees },
+ { "_Z3maxff", (void *)&SC_max_f32 },
+ { "_Z3minff", (void *)&SC_min_f32 },
+ { "_Z3mixfff", (void *)&SC_mix_f32 },
+ { "_Z7radiansf", (void *)&SC_radians },
+ { "_Z4stepff", (void *)&SC_step_f32 },
+ //{ "smoothstep", (void *)& },
+ { "_Z4signf", (void *)&SC_sign_f32 },
+
+ { NULL, NULL }
+};
+
+const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbolCL(const char *sym)
+{
+ ScriptCState::SymbolTable_t *syms = gSyms;
+
+ while (syms->mPtr) {
+ if (!strcmp(syms->mName, sym)) {
+ return syms;
+ }
+ syms++;
+ }
+ return NULL;
+}
+
diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp
new file mode 100644
index 0000000..8f650f8
--- /dev/null
+++ b/libs/rs/rsScriptC_LibGL.cpp
@@ -0,0 +1,524 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#include "rsContext.h"
+#include "rsScriptC.h"
+#include "rsMatrix.h"
+
+#include "acc/acc.h"
+#include "utils/Timers.h"
+
+#define GL_GLEXT_PROTOTYPES
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
+#include <time.h>
+
+using namespace android;
+using namespace android::renderscript;
+
+#define GET_TLS() Context::ScriptTLSStruct * tls = \
+ (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
+ Context * rsc = tls->mContext; \
+ ScriptC * sc = (ScriptC *) tls->mScript
+
+
+//////////////////////////////////////////////////////////////////////////////
+// IO routines
+//////////////////////////////////////////////////////////////////////////////
+
+static void SC_updateSimpleMesh(RsSimpleMesh mesh)
+{
+ GET_TLS();
+ SimpleMesh *sm = static_cast<SimpleMesh *>(mesh);
+ sm->uploadAll(rsc);
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+// Context
+//////////////////////////////////////////////////////////////////////////////
+
+static void SC_bindTexture(RsProgramFragment vpf, uint32_t slot, RsAllocation va)
+{
+ GET_TLS();
+ rsi_ProgramBindTexture(rsc,
+ static_cast<ProgramFragment *>(vpf),
+ slot,
+ static_cast<Allocation *>(va));
+
+}
+
+static void SC_bindSampler(RsProgramFragment vpf, uint32_t slot, RsSampler vs)
+{
+ GET_TLS();
+ rsi_ProgramBindSampler(rsc,
+ static_cast<ProgramFragment *>(vpf),
+ slot,
+ static_cast<Sampler *>(vs));
+
+}
+
+static void SC_bindProgramStore(RsProgramStore pfs)
+{
+ GET_TLS();
+ rsi_ContextBindProgramStore(rsc, pfs);
+}
+
+static void SC_bindProgramFragment(RsProgramFragment pf)
+{
+ GET_TLS();
+ rsi_ContextBindProgramFragment(rsc, pf);
+}
+
+static void SC_bindProgramVertex(RsProgramVertex pv)
+{
+ GET_TLS();
+ rsi_ContextBindProgramVertex(rsc, pv);
+}
+
+static void SC_bindProgramRaster(RsProgramRaster pv)
+{
+ GET_TLS();
+ rsi_ContextBindProgramRaster(rsc, pv);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// VP
+//////////////////////////////////////////////////////////////////////////////
+
+static void SC_vpLoadModelMatrix(const rsc_Matrix *m)
+{
+ GET_TLS();
+ rsc->getVertex()->setModelviewMatrix(m);
+}
+
+static void SC_vpLoadTextureMatrix(const rsc_Matrix *m)
+{
+ GET_TLS();
+ rsc->getVertex()->setTextureMatrix(m);
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////////
+// Drawing
+//////////////////////////////////////////////////////////////////////////////
+
+static void SC_drawLine(float x1, float y1, float z1,
+ float x2, float y2, float z2)
+{
+ GET_TLS();
+ if (!rsc->setupCheck()) {
+ return;
+ }
+
+ float vtx[] = { x1, y1, z1, x2, y2, z2 };
+ VertexArray va;
+ va.add(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "position");
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
+
+ glDrawArrays(GL_LINES, 0, 2);
+}
+
+static void SC_drawPoint(float x, float y, float z)
+{
+ GET_TLS();
+ if (!rsc->setupCheck()) {
+ return;
+ }
+
+ float vtx[] = { x, y, z };
+
+ VertexArray va;
+ va.add(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "position");
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
+
+ glDrawArrays(GL_POINTS, 0, 1);
+}
+
+static void SC_drawQuadTexCoords(float x1, float y1, float z1,
+ float u1, float v1,
+ float x2, float y2, float z2,
+ float u2, float v2,
+ float x3, float y3, float z3,
+ float u3, float v3,
+ float x4, float y4, float z4,
+ float u4, float v4)
+{
+ GET_TLS();
+ if (!rsc->setupCheck()) {
+ return;
+ }
+
+ //LOGE("Quad");
+ //LOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
+ //LOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
+ //LOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
+ //LOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
+
+ float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
+ const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
+
+ VertexArray va;
+ va.add(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "position");
+ va.add(GL_FLOAT, 2, 8, false, (uint32_t)tex, "texture0");
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+}
+
+static void SC_drawQuad(float x1, float y1, float z1,
+ float x2, float y2, float z2,
+ float x3, float y3, float z3,
+ float x4, float y4, float z4)
+{
+ SC_drawQuadTexCoords(x1, y1, z1, 0, 1,
+ x2, y2, z2, 1, 1,
+ x3, y3, z3, 1, 0,
+ x4, y4, z4, 0, 0);
+}
+
+static void SC_drawSpriteScreenspace(float x, float y, float z, float w, float h)
+{
+ GET_TLS();
+ ObjectBaseRef<const ProgramVertex> tmp(rsc->getVertex());
+ rsc->setVertex(rsc->getDefaultProgramVertex());
+ //rsc->setupCheck();
+
+ //GLint crop[4] = {0, h, w, -h};
+
+ float sh = rsc->getHeight();
+
+ SC_drawQuad(x, sh - y, z,
+ x+w, sh - y, z,
+ x+w, sh - (y+h), z,
+ x, sh - (y+h), z);
+ rsc->setVertex((ProgramVertex *)tmp.get());
+}
+
+static void SC_drawSpriteScreenspaceCropped(float x, float y, float z, float w, float h,
+ float cx0, float cy0, float cx1, float cy1)
+{
+ GET_TLS();
+ if (!rsc->setupCheck()) {
+ return;
+ }
+
+ GLint crop[4] = {cx0, cy0, cx1, cy1};
+ glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
+ glDrawTexfOES(x, y, z, w, h);
+}
+
+static void SC_drawSprite(float x, float y, float z, float w, float h)
+{
+ GET_TLS();
+ float vin[3] = {x, y, z};
+ float vout[4];
+
+ //LOGE("ds in %f %f %f", x, y, z);
+ rsc->getVertex()->transformToScreen(rsc, vout, vin);
+ //LOGE("ds out %f %f %f %f", vout[0], vout[1], vout[2], vout[3]);
+ vout[0] /= vout[3];
+ vout[1] /= vout[3];
+ vout[2] /= vout[3];
+
+ vout[0] *= rsc->getWidth() / 2;
+ vout[1] *= rsc->getHeight() / 2;
+ vout[0] += rsc->getWidth() / 2;
+ vout[1] += rsc->getHeight() / 2;
+
+ vout[0] -= w/2;
+ vout[1] -= h/2;
+
+ //LOGE("ds out2 %f %f %f", vout[0], vout[1], vout[2]);
+
+ // U, V, W, H
+ SC_drawSpriteScreenspace(vout[0], vout[1], z, h, w);
+ //rsc->setupCheck();
+}
+
+
+static void SC_drawRect(float x1, float y1,
+ float x2, float y2, float z)
+{
+ //LOGE("SC_drawRect %f,%f %f,%f %f", x1, y1, x2, y2, z);
+ SC_drawQuad(x1, y2, z,
+ x2, y2, z,
+ x2, y1, z,
+ x1, y1, z);
+}
+
+static void SC_drawSimpleMesh(RsSimpleMesh vsm)
+{
+ GET_TLS();
+ SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
+ if (!rsc->setupCheck()) {
+ return;
+ }
+ sm->render(rsc);
+}
+
+static void SC_drawSimpleMeshRange(RsSimpleMesh vsm, uint32_t start, uint32_t len)
+{
+ GET_TLS();
+ SimpleMesh *sm = static_cast<SimpleMesh *>(vsm);
+ if (!rsc->setupCheck()) {
+ return;
+ }
+ sm->renderRange(rsc, start, len);
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//////////////////////////////////////////////////////////////////////////////
+
+
+static void SC_color(float r, float g, float b, float a)
+{
+ GET_TLS();
+ rsc->mStateVertex.color[0] = r;
+ rsc->mStateVertex.color[1] = g;
+ rsc->mStateVertex.color[2] = b;
+ rsc->mStateVertex.color[3] = a;
+ if (!rsc->checkVersion2_0()) {
+ glColor4f(r, g, b, a);
+ }
+}
+
+static void SC_pointAttenuation(float a, float b, float c)
+{
+ GLfloat params[] = { a, b, c };
+ glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, params);
+}
+
+static void SC_hsbToRgb(float h, float s, float b, float* rgb)
+{
+ float red = 0.0f;
+ float green = 0.0f;
+ float blue = 0.0f;
+
+ float x = h;
+ float y = s;
+ float z = b;
+
+ float hf = (x - (int) x) * 6.0f;
+ int ihf = (int) hf;
+ float f = hf - ihf;
+ float pv = z * (1.0f - y);
+ float qv = z * (1.0f - y * f);
+ float tv = z * (1.0f - y * (1.0f - f));
+
+ switch (ihf) {
+ case 0: // Red is the dominant color
+ red = z;
+ green = tv;
+ blue = pv;
+ break;
+ case 1: // Green is the dominant color
+ red = qv;
+ green = z;
+ blue = pv;
+ break;
+ case 2:
+ red = pv;
+ green = z;
+ blue = tv;
+ break;
+ case 3: // Blue is the dominant color
+ red = pv;
+ green = qv;
+ blue = z;
+ break;
+ case 4:
+ red = tv;
+ green = pv;
+ blue = z;
+ break;
+ case 5: // Red is the dominant color
+ red = z;
+ green = pv;
+ blue = qv;
+ break;
+ }
+
+ rgb[0] = red;
+ rgb[1] = green;
+ rgb[2] = blue;
+}
+
+static int SC_hsbToAbgr(float h, float s, float b, float a)
+{
+ //LOGE("hsb a %f, %f, %f %f", h, s, b, a);
+ float rgb[3];
+ SC_hsbToRgb(h, s, b, rgb);
+ //LOGE("rgb %f, %f, %f ", rgb[0], rgb[1], rgb[2]);
+ return int(a * 255.0f) << 24 |
+ int(rgb[2] * 255.0f) << 16 |
+ int(rgb[1] * 255.0f) << 8 |
+ int(rgb[0] * 255.0f);
+}
+
+static void SC_hsb(float h, float s, float b, float a)
+{
+ GET_TLS();
+ float rgb[3];
+ SC_hsbToRgb(h, s, b, rgb);
+ if (rsc->checkVersion2_0()) {
+ glVertexAttrib4f(1, rgb[0], rgb[1], rgb[2], a);
+ } else {
+ glColor4f(rgb[0], rgb[1], rgb[2], a);
+ }
+}
+
+static void SC_uploadToTexture2(RsAllocation va, uint32_t baseMipLevel)
+{
+ GET_TLS();
+ rsi_AllocationUploadToTexture(rsc, va, false, baseMipLevel);
+}
+static void SC_uploadToTexture(RsAllocation va)
+{
+ GET_TLS();
+ rsi_AllocationUploadToTexture(rsc, va, false, 0);
+}
+
+static void SC_uploadToBufferObject(RsAllocation va)
+{
+ GET_TLS();
+ rsi_AllocationUploadToBufferObject(rsc, va);
+}
+
+static void SC_ClearColor(float r, float g, float b, float a)
+{
+ GET_TLS();
+ if (!rsc->setupCheck()) {
+ return;
+ }
+
+ glClearColor(r, g, b, a);
+ glClear(GL_COLOR_BUFFER_BIT);
+}
+
+static void SC_ClearDepth(float v)
+{
+ GET_TLS();
+ if (!rsc->setupCheck()) {
+ return;
+ }
+
+ glClearDepthf(v);
+ glClear(GL_DEPTH_BUFFER_BIT);
+}
+
+static uint32_t SC_getWidth()
+{
+ GET_TLS();
+ return rsc->getWidth();
+}
+
+static uint32_t SC_getHeight()
+{
+ GET_TLS();
+ return rsc->getHeight();
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+// Class implementation
+//////////////////////////////////////////////////////////////////////////////
+
+// llvm name mangling ref
+// <builtin-type> ::= v # void
+// ::= b # bool
+// ::= c # char
+// ::= a # signed char
+// ::= h # unsigned char
+// ::= s # short
+// ::= t # unsigned short
+// ::= i # int
+// ::= j # unsigned int
+// ::= l # long
+// ::= m # unsigned long
+// ::= x # long long, __int64
+// ::= y # unsigned long long, __int64
+// ::= f # float
+// ::= d # double
+
+static ScriptCState::SymbolTable_t gSyms[] = {
+ { "rsgBindProgramFragment", (void *)&SC_bindProgramFragment },
+ { "rsgBindProgramStore", (void *)&SC_bindProgramStore },
+ { "rsgBindProgramVertex", (void *)&SC_bindProgramVertex },
+ { "rsgBindProgramRaster", (void *)&SC_bindProgramRaster },
+ { "rsgBindSampler", (void *)&SC_bindSampler },
+ { "rsgBindTexture", (void *)&SC_bindTexture },
+
+ { "rsgProgramVertexLoadModelMatrix", (void *)&SC_vpLoadModelMatrix },
+ { "rsgProgramVertexLoadTextureMatrix", (void *)&SC_vpLoadTextureMatrix },
+
+ { "rsgGetWidth", (void *)&SC_getWidth },
+ { "rsgGetHeight", (void *)&SC_getHeight },
+
+ { "_Z18rsgUploadToTextureii", (void *)&SC_uploadToTexture2 },
+ { "_Z18rsgUploadToTexturei", (void *)&SC_uploadToTexture },
+ { "rsgUploadToBufferObject", (void *)&SC_uploadToBufferObject },
+
+ { "rsgDrawRect", (void *)&SC_drawRect },
+ { "rsgDrawQuad", (void *)&SC_drawQuad },
+ { "rsgDrawQuadTexCoords", (void *)&SC_drawQuadTexCoords },
+ //{ "drawSprite", (void *)&SC_drawSprite },
+ { "rsgDrawSpriteScreenspace", (void *)&SC_drawSpriteScreenspace },
+ { "rsgDrawSpriteScreenspaceCropped", (void *)&SC_drawSpriteScreenspaceCropped },
+ { "rsgDrawLine", (void *)&SC_drawLine },
+ { "rsgDrawPoint", (void *)&SC_drawPoint },
+ { "_Z17rsgDrawSimpleMeshi", (void *)&SC_drawSimpleMesh },
+ { "_Z17rsgDrawSimpleMeshiii", (void *)&SC_drawSimpleMeshRange },
+
+ { "rsgClearColor", (void *)&SC_ClearColor },
+ { "rsgClearDepth", (void *)&SC_ClearDepth },
+
+
+ //////////////////////////////////////
+ // IO
+ { "updateSimpleMesh", (void *)&SC_updateSimpleMesh },
+
+ // misc
+ //{ "pfClearColor", (void *)&SC_ClearColor },
+ { "color", (void *)&SC_color },
+ { "hsb", (void *)&SC_hsb },
+ { "hsbToRgb", (void *)&SC_hsbToRgb },
+ { "hsbToAbgr", (void *)&SC_hsbToAbgr },
+ { "pointAttenuation", (void *)&SC_pointAttenuation },
+
+ { NULL, NULL }
+};
+
+const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbolGL(const char *sym)
+{
+ ScriptCState::SymbolTable_t *syms = gSyms;
+
+ while (syms->mPtr) {
+ if (!strcmp(syms->mName, sym)) {
+ return syms;
+ }
+ syms++;
+ }
+ return NULL;
+}
+
diff --git a/libs/rs/rsShaderCache.cpp b/libs/rs/rsShaderCache.cpp
index 4711d1b..504ffba 100644
--- a/libs/rs/rsShaderCache.cpp
+++ b/libs/rs/rsShaderCache.cpp
@@ -14,10 +14,14 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-
#include <GLES/gl.h>
#include <GLES2/gl2.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#endif //ANDROID_RS_BUILD_FOR_HOST
using namespace android;
using namespace android::renderscript;
@@ -94,16 +98,11 @@ bool ShaderCache::lookup(Context *rsc, ProgramVertex *vtx, ProgramFragment *frag
glAttachShader(pgm, frag->getShaderID());
if (!vtx->isUserProgram()) {
- glBindAttribLocation(pgm, 0, "ATTRIB_LegacyPosition");
- glBindAttribLocation(pgm, 1, "ATTRIB_LegacyColor");
- glBindAttribLocation(pgm, 2, "ATTRIB_LegacyNormal");
- glBindAttribLocation(pgm, 3, "ATTRIB_LegacyPointSize");
- glBindAttribLocation(pgm, 4, "ATTRIB_LegacyTexture");
- e->mVtxAttribSlots[RS_KIND_POSITION] = 0;
- e->mVtxAttribSlots[RS_KIND_COLOR] = 1;
- e->mVtxAttribSlots[RS_KIND_NORMAL] = 2;
- e->mVtxAttribSlots[RS_KIND_POINT_SIZE] = 3;
- e->mVtxAttribSlots[RS_KIND_TEXTURE] = 4;
+ glBindAttribLocation(pgm, 0, "ATTRIB_position");
+ glBindAttribLocation(pgm, 1, "ATTRIB_color");
+ glBindAttribLocation(pgm, 2, "ATTRIB_normal");
+ glBindAttribLocation(pgm, 3, "ATTRIB_pointSize");
+ glBindAttribLocation(pgm, 4, "ATTRIB_texture0");
}
//LOGE("e2 %x", glGetError());
diff --git a/libs/rs/rsSignal.cpp b/libs/rs/rsSignal.cpp
new file mode 100644
index 0000000..9239bfd
--- /dev/null
+++ b/libs/rs/rsSignal.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#include "rsSignal.h"
+
+using namespace android;
+using namespace android::renderscript;
+
+
+Signal::Signal()
+{
+ mSet = true;
+}
+
+Signal::~Signal()
+{
+ pthread_mutex_destroy(&mMutex);
+ pthread_cond_destroy(&mCondition);
+}
+
+bool Signal::init()
+{
+ int status = pthread_mutex_init(&mMutex, NULL);
+ if (status) {
+ LOGE("LocklessFifo mutex init failure");
+ return false;
+ }
+
+ status = pthread_cond_init(&mCondition, NULL);
+ if (status) {
+ LOGE("LocklessFifo condition init failure");
+ pthread_mutex_destroy(&mMutex);
+ return false;
+ }
+
+ return true;
+}
+
+void Signal::set()
+{
+ int status;
+
+ status = pthread_mutex_lock(&mMutex);
+ if (status) {
+ LOGE("LocklessCommandFifo: error %i locking for set condition.", status);
+ return;
+ }
+
+ mSet = true;
+
+ status = pthread_cond_signal(&mCondition);
+ if (status) {
+ LOGE("LocklessCommandFifo: error %i on set condition.", status);
+ }
+
+ status = pthread_mutex_unlock(&mMutex);
+ if (status) {
+ LOGE("LocklessCommandFifo: error %i unlocking for set condition.", status);
+ }
+}
+
+void Signal::wait()
+{
+ int status;
+
+ status = pthread_mutex_lock(&mMutex);
+ if (status) {
+ LOGE("LocklessCommandFifo: error %i locking for condition.", status);
+ return;
+ }
+
+ if (!mSet) {
+ status = pthread_cond_wait(&mCondition, &mMutex);
+ if (status) {
+ LOGE("LocklessCommandFifo: error %i waiting on condition.", status);
+ }
+ }
+ mSet = false;
+
+ status = pthread_mutex_unlock(&mMutex);
+ if (status) {
+ LOGE("LocklessCommandFifo: error %i unlocking for condition.", status);
+ }
+}
+
diff --git a/libs/rs/rsFileA3DDecls.h b/libs/rs/rsSignal.h
index 2a08bd3..2e760f1 100644
--- a/libs/rs/rsFileA3DDecls.h
+++ b/libs/rs/rsSignal.h
@@ -14,31 +14,33 @@
* limitations under the License.
*/
-#ifndef ANDROID_RS_FILE_A3D_DECLS_H
-#define ANDROID_RS_FILE_A3D_DECLS_H
+#ifndef ANDROID_RS_SIGNAL_H
+#define ANDROID_RS_SIGNAL_H
-#define A3D_MAGIC_KEY "Android3D_ff"
+#include "rsUtils.h"
namespace android {
namespace renderscript {
- enum A3DChunkType {
- CHUNK_EMPTY,
+class Signal {
+public:
+ Signal();
+ ~Signal();
- CHUNK_ELEMENT,
- CHUNK_ELEMENT_SOURCE,
- CHUNK_VERTICIES,
- CHUNK_MESH,
- CHUNK_PRIMITIVE,
+ bool init();
- CHUNK_LAST
- };
+ void set();
+ void wait();
+protected:
+ bool mSet;
+ pthread_mutex_t mMutex;
+ pthread_cond_t mCondition;
+};
}
}
-#endif //ANDROID_RS_FILE_A3D_H
-
+#endif
diff --git a/libs/rs/rsSimpleMesh.cpp b/libs/rs/rsSimpleMesh.cpp
index 53ce5cd..6ec1a3b 100644
--- a/libs/rs/rsSimpleMesh.cpp
+++ b/libs/rs/rsSimpleMesh.cpp
@@ -14,13 +14,24 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
+#include <GLES/gl.h>
+#include <GLES2/gl2.h>
+#include <GLES/glext.h>
+#else
+#include "rsContextHostStub.h"
+
+#include <OpenGL/gl.h>
+#include <OpenGl/glext.h>
+#endif
+
using namespace android;
using namespace android::renderscript;
-#include <GLES/gl.h>
-#include <GLES/glext.h>
+
+
SimpleMesh::SimpleMesh(Context *rsc) : ObjectBase(rsc)
{
@@ -57,21 +68,12 @@ void SimpleMesh::renderRange(Context *rsc, uint32_t start, uint32_t len) const
rsc->checkError("SimpleMesh::renderRange 1");
VertexArray va;
- if (rsc->checkVersion2_0()) {
- for (uint32_t ct=0; ct < mVertexTypeCount; ct++) {
- mVertexBuffers[ct]->uploadCheck(rsc);
- va.setActiveBuffer(mVertexBuffers[ct]->getBufferObjectID());
- mVertexTypes[ct]->enableGLVertexBuffer2(&va);
- }
- va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
- } else {
- for (uint32_t ct=0; ct < mVertexTypeCount; ct++) {
- mVertexBuffers[ct]->uploadCheck(rsc);
- va.setActiveBuffer(mVertexBuffers[ct]->getBufferObjectID());
- mVertexTypes[ct]->enableGLVertexBuffer(&va);
- }
- va.setupGL(rsc, 0);
+ for (uint32_t ct=0; ct < mVertexTypeCount; ct++) {
+ mVertexBuffers[ct]->uploadCheck(rsc);
+ va.setActiveBuffer(mVertexBuffers[ct]->getBufferObjectID());
+ mVertexTypes[ct]->enableGLVertexBuffer(&va);
}
+ va.setupGL2(rsc, &rsc->mStateVertexArray, &rsc->mShaderCache);
rsc->checkError("SimpleMesh::renderRange 2");
if (mIndexType.get()) {
@@ -101,6 +103,97 @@ void SimpleMesh::uploadAll(Context *rsc)
rsc->checkError("SimpleMesh::uploadAll");
}
+void SimpleMesh::updateGLPrimitive()
+{
+ switch(mPrimitive) {
+ case RS_PRIMITIVE_POINT: mGLPrimitive = GL_POINTS; break;
+ case RS_PRIMITIVE_LINE: mGLPrimitive = GL_LINES; break;
+ case RS_PRIMITIVE_LINE_STRIP: mGLPrimitive = GL_LINE_STRIP; break;
+ case RS_PRIMITIVE_TRIANGLE: mGLPrimitive = GL_TRIANGLES; break;
+ case RS_PRIMITIVE_TRIANGLE_STRIP: mGLPrimitive = GL_TRIANGLE_STRIP; break;
+ case RS_PRIMITIVE_TRIANGLE_FAN: mGLPrimitive = GL_TRIANGLE_FAN; break;
+ }
+}
+
+void SimpleMesh::serialize(OStream *stream) const
+{
+ // Need to identify ourselves
+ stream->addU32((uint32_t)getClassId());
+
+ String8 name(getName());
+ stream->addString(&name);
+
+ // Add primitive type
+ stream->addU8((uint8_t)mPrimitive);
+
+ // And now serialize the allocations
+ mIndexBuffer->serialize(stream);
+
+ // We need to indicate if the primitive buffer is present
+ if(mPrimitiveBuffer.get() != NULL) {
+ // Write if the primitive buffer is present
+ stream->addU32(1);
+ mPrimitiveBuffer->serialize(stream);
+ }
+ else {
+ // No buffer present, will need this when we read
+ stream->addU32(0);
+ }
+
+ // Store number of vertex streams
+ stream->addU32(mVertexTypeCount);
+ for(uint32_t vCount = 0; vCount < mVertexTypeCount; vCount ++) {
+ mVertexBuffers[vCount]->serialize(stream);
+ }
+}
+
+SimpleMesh *SimpleMesh::createFromStream(Context *rsc, IStream *stream)
+{
+ // First make sure we are reading the correct object
+ RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
+ if(classID != RS_A3D_CLASS_ID_SIMPLE_MESH) {
+ LOGE("simple mesh loading skipped due to invalid class id");
+ return NULL;
+ }
+
+ SimpleMesh * mesh = new SimpleMesh(rsc);
+
+ String8 name;
+ stream->loadString(&name);
+ mesh->setName(name.string(), name.size());
+
+ mesh->mPrimitive = (RsPrimitive)stream->loadU8();
+ mesh->updateGLPrimitive();
+
+ Allocation *indexAlloc = Allocation::createFromStream(rsc, stream);
+ const Type *indexType = indexAlloc->getType();
+ mesh->mIndexBuffer.set(indexAlloc);
+ mesh->mIndexType.set(indexType);
+
+ bool isPrimitivePresent = stream->loadU32() != 0;
+ if(isPrimitivePresent) {
+ mesh->mPrimitiveBuffer.set(Allocation::createFromStream(rsc, stream));
+ mesh->mPrimitiveType.set(mesh->mPrimitiveBuffer->getType());
+ }
+
+ mesh->mVertexTypeCount = stream->loadU32();
+ if(mesh->mVertexTypeCount) {
+ mesh->mVertexTypes = new ObjectBaseRef<const Type>[mesh->mVertexTypeCount];
+ mesh->mVertexBuffers = new ObjectBaseRef<Allocation>[mesh->mVertexTypeCount];
+
+ for(uint32_t vCount = 0; vCount < mesh->mVertexTypeCount; vCount ++) {
+ Allocation *vertexAlloc = Allocation::createFromStream(rsc, stream);
+ const Type *vertexType = vertexAlloc->getType();
+ mesh->mVertexBuffers[vCount].set(vertexAlloc);
+ mesh->mVertexTypes[vCount].set(vertexType);
+ }
+ }
+
+ mesh->uploadAll(rsc);
+
+ return mesh;
+}
+
SimpleMeshContext::SimpleMeshContext()
{
@@ -131,14 +224,7 @@ RsSimpleMesh rsi_SimpleMeshCreate(Context *rsc, RsType prim, RsType idx, RsType
}
sm->mPrimitive = (RsPrimitive)primType;
- switch(sm->mPrimitive) {
- case RS_PRIMITIVE_POINT: sm->mGLPrimitive = GL_POINTS; break;
- case RS_PRIMITIVE_LINE: sm->mGLPrimitive = GL_LINES; break;
- case RS_PRIMITIVE_LINE_STRIP: sm->mGLPrimitive = GL_LINE_STRIP; break;
- case RS_PRIMITIVE_TRIANGLE: sm->mGLPrimitive = GL_TRIANGLES; break;
- case RS_PRIMITIVE_TRIANGLE_STRIP: sm->mGLPrimitive = GL_TRIANGLE_STRIP; break;
- case RS_PRIMITIVE_TRIANGLE_FAN: sm->mGLPrimitive = GL_TRIANGLE_FAN; break;
- }
+ sm->updateGLPrimitive();
return sm;
}
diff --git a/libs/rs/rsSimpleMesh.h b/libs/rs/rsSimpleMesh.h
index 6defbda..362c7fb 100644
--- a/libs/rs/rsSimpleMesh.h
+++ b/libs/rs/rsSimpleMesh.h
@@ -48,7 +48,11 @@ public:
void render(Context *) const;
void renderRange(Context *, uint32_t start, uint32_t len) const;
void uploadAll(Context *);
+ void updateGLPrimitive();
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SIMPLE_MESH; }
+ static SimpleMesh *createFromStream(Context *rsc, IStream *stream);
protected:
};
diff --git a/libs/rs/rsStream.cpp b/libs/rs/rsStream.cpp
new file mode 100644
index 0000000..39874a9
--- /dev/null
+++ b/libs/rs/rsStream.cpp
@@ -0,0 +1,132 @@
+
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#ifndef ANDROID_RS_BUILD_FOR_HOST
+#include "rsContext.h"
+#else
+#include "rsContextHostStub.h"
+#endif
+
+#include "rsStream.h"
+
+using namespace android;
+using namespace android::renderscript;
+
+IStream::IStream(const uint8_t *buf, bool use64)
+{
+ mData = buf;
+ mPos = 0;
+ mUse64 = use64;
+}
+
+void IStream::loadByteArray(void *dest, size_t numBytes)
+{
+ memcpy(dest, mData + mPos, numBytes);
+ mPos += numBytes;
+}
+
+uint64_t IStream::loadOffset()
+{
+ uint64_t tmp;
+ if (mUse64) {
+ mPos = (mPos + 7) & (~7);
+ tmp = reinterpret_cast<const uint64_t *>(&mData[mPos])[0];
+ mPos += sizeof(uint64_t);
+ return tmp;
+ }
+ return loadU32();
+}
+
+void IStream::loadString(String8 *s)
+{
+ uint32_t len = loadU32();
+ s->setTo((const char *)&mData[mPos], len);
+ LOGE("loadString %s", s->string());
+ mPos += len;
+}
+
+
+// Output stream implementation
+
+OStream::OStream(uint64_t len, bool use64)
+{
+ mData = (uint8_t*)malloc(len);
+ mLength = len;
+ mPos = 0;
+ mUse64 = use64;
+}
+
+OStream::~OStream()
+{
+ free(mData);
+}
+
+void OStream::addByteArray(const void *src, size_t numBytes)
+{
+ // We need to potentially grow more than once if the number of byes we write is substantial
+ while(mPos + numBytes >= mLength) {
+ growSize();
+ }
+ memcpy(mData + mPos, src, numBytes);
+ mPos += numBytes;
+}
+
+void OStream::addOffset(uint64_t v)
+{
+ if (mUse64) {
+ mPos = (mPos + 7) & (~7);
+ if(mPos + sizeof(v) >= mLength) {
+ growSize();
+ }
+ mData[mPos++] = (uint8_t)(v & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 8) & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 16) & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 24) & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 32) & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 40) & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 48) & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 56) & 0xff);
+ }
+ else {
+ addU32(v);
+ }
+}
+
+void OStream::addString(String8 *s)
+{
+ uint32_t len = s->size();
+ addU32(len);
+ if(mPos + len*sizeof(char) >= mLength) {
+ growSize();
+ }
+ char *stringData = reinterpret_cast<char *>(&mData[mPos]);
+ for(uint32_t i = 0; i < len; i ++) {
+ stringData[i] = s->string()[i];
+ }
+ mPos += len*sizeof(char);
+}
+
+void OStream::growSize()
+{
+ uint8_t *newData = (uint8_t*)malloc(mLength*2);
+ memcpy(newData, mData, mLength*sizeof(uint8_t));
+ mLength = mLength * 2;
+ free(mData);
+ mData = newData;
+}
+
+
diff --git a/libs/rs/rsStream.h b/libs/rs/rsStream.h
new file mode 100644
index 0000000..d401cd1
--- /dev/null
+++ b/libs/rs/rsStream.h
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#ifndef ANDROID_RS_STREAM_H
+#define ANDROID_RS_STREAM_H
+
+#include <utils/String8.h>
+#include <stdio.h>
+
+// ---------------------------------------------------------------------------
+namespace android {
+namespace renderscript {
+
+class IStream
+{
+public:
+ IStream(const uint8_t *, bool use64);
+
+ float loadF() {
+ mPos = (mPos + 3) & (~3);
+ float tmp = reinterpret_cast<const float *>(&mData[mPos])[0];
+ mPos += sizeof(float);
+ return tmp;
+ }
+ int32_t loadI32() {
+ mPos = (mPos + 3) & (~3);
+ int32_t tmp = reinterpret_cast<const int32_t *>(&mData[mPos])[0];
+ mPos += sizeof(int32_t);
+ return tmp;
+ }
+ uint32_t loadU32() {
+ mPos = (mPos + 3) & (~3);
+ uint32_t tmp = reinterpret_cast<const uint32_t *>(&mData[mPos])[0];
+ mPos += sizeof(uint32_t);
+ return tmp;
+ }
+ uint16_t loadU16() {
+ mPos = (mPos + 1) & (~1);
+ uint16_t tmp = reinterpret_cast<const uint16_t *>(&mData[mPos])[0];
+ mPos += sizeof(uint16_t);
+ return tmp;
+ }
+ inline uint8_t loadU8() {
+ uint8_t tmp = reinterpret_cast<const uint8_t *>(&mData[mPos])[0];
+ mPos += sizeof(uint8_t);
+ return tmp;
+ }
+ void loadByteArray(void *dest, size_t numBytes);
+ uint64_t loadOffset();
+ void loadString(String8 *s);
+ uint64_t getPos() const {
+ return mPos;
+ }
+ void reset(uint64_t pos) {
+ mPos = pos;
+ }
+ void reset() {
+ mPos = 0;
+ }
+
+ const uint8_t * getPtr() const {
+ return mData;
+ }
+protected:
+ const uint8_t * mData;
+ uint64_t mPos;
+ bool mUse64;
+};
+
+class OStream
+{
+public:
+ OStream(uint64_t length, bool use64);
+ ~OStream();
+
+ void align(uint32_t bytes) {
+ mPos = (mPos + (bytes - 1)) & (~(bytes - 1));
+ if(mPos >= mLength) {
+ growSize();
+ }
+ }
+
+ void addF(float v) {
+ uint32_t uintV = *reinterpret_cast<uint32_t*> (&v);
+ addU32(uintV);
+ }
+ void addI32(int32_t v) {
+ mPos = (mPos + 3) & (~3);
+ if(mPos + sizeof(v) >= mLength) {
+ growSize();
+ }
+ mData[mPos++] = (uint8_t)(v & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 8) & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 16) & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 24) & 0xff);
+ }
+ void addU32(uint32_t v) {
+ mPos = (mPos + 3) & (~3);
+ if(mPos + sizeof(v) >= mLength) {
+ growSize();
+ }
+ mData[mPos++] = (uint8_t)(v & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 8) & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 16) & 0xff);
+ mData[mPos++] = (uint8_t)((v >> 24) & 0xff);
+ }
+ void addU16(uint16_t v) {
+ mPos = (mPos + 1) & (~1);
+ if(mPos + sizeof(v) >= mLength) {
+ growSize();
+ }
+ mData[mPos++] = (uint8_t)(v & 0xff);
+ mData[mPos++] = (uint8_t)(v >> 8);
+ }
+ inline void addU8(uint8_t v) {
+ if(mPos + 1 >= mLength) {
+ growSize();
+ }
+ reinterpret_cast<uint8_t *>(&mData[mPos])[0] = v;
+ mPos ++;
+ }
+ void addByteArray(const void *src, size_t numBytes);
+ void addOffset(uint64_t v);
+ void addString(String8 *s);
+ uint64_t getPos() const {
+ return mPos;
+ }
+ void reset(uint64_t pos) {
+ mPos = pos;
+ }
+ void reset() {
+ mPos = 0;
+ }
+ const uint8_t * getPtr() const {
+ return mData;
+ }
+protected:
+ void growSize();
+ uint8_t * mData;
+ uint64_t mLength;
+ uint64_t mPos;
+ bool mUse64;
+};
+
+
+} // renderscript
+} // android
+#endif //ANDROID_RS_STREAM_H
+
+
diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp
index c09e979..75abc76 100644
--- a/libs/rs/rsType.cpp
+++ b/libs/rs/rsType.cpp
@@ -14,8 +14,13 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
#include <GLES/gl.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#endif
using namespace android;
using namespace android::renderscript;
@@ -143,131 +148,22 @@ void Type::makeGLComponents()
for (uint32_t ct=0; ct < getElement()->getFieldCount(); ct++) {
const Component &c = getElement()->getField(ct)->getComponent();
- switch(c.getKind()) {
- case RS_KIND_USER:
- mGL.mUser[userNum].size = c.getVectorSize();
- mGL.mUser[userNum].offset = mElement->getFieldOffsetBytes(ct);
- mGL.mUser[userNum].type = c.getGLType();
- mGL.mUser[userNum].normalized = c.getType() != RS_TYPE_FLOAT_32;//c.getIsNormalized();
- mGL.mUser[userNum].name.setTo(getElement()->getFieldName(ct));
- userNum ++;
- break;
-
- case RS_KIND_POSITION:
- rsAssert(mGL.mVtx.size == 0);
- mGL.mVtx.size = c.getVectorSize();
- mGL.mVtx.offset = mElement->getFieldOffsetBytes(ct);
- mGL.mVtx.type = c.getGLType();
- mGL.mVtx.normalized = false;
- mGL.mVtx.name.setTo("Position");
- break;
-
- case RS_KIND_COLOR:
- rsAssert(mGL.mColor.size == 0);
- mGL.mColor.size = c.getVectorSize();
- mGL.mColor.offset = mElement->getFieldOffsetBytes(ct);
- mGL.mColor.type = c.getGLType();
- mGL.mColor.normalized = c.getType() != RS_TYPE_FLOAT_32;
- mGL.mColor.name.setTo("Color");
- break;
-
- case RS_KIND_NORMAL:
- rsAssert(mGL.mNorm.size == 0);
- mGL.mNorm.size = c.getVectorSize();
- mGL.mNorm.offset = mElement->getFieldOffsetBytes(ct);
- mGL.mNorm.type = c.getGLType();
- mGL.mNorm.normalized = false;
- mGL.mNorm.name.setTo("Normal");
- break;
-
- case RS_KIND_TEXTURE:
- rsAssert(mGL.mTex.size == 0);
- mGL.mTex.size = c.getVectorSize();
- mGL.mTex.offset = mElement->getFieldOffsetBytes(ct);
- mGL.mTex.type = c.getGLType();
- mGL.mTex.normalized = false;
- mGL.mTex.name.setTo("Texture");
- break;
-
- case RS_KIND_POINT_SIZE:
- rsAssert(!mGL.mPointSize.size);
- mGL.mPointSize.size = c.getVectorSize();
- mGL.mPointSize.offset = mElement->getFieldOffsetBytes(ct);
- mGL.mPointSize.type = c.getGLType();
- mGL.mPointSize.normalized = false;
- mGL.mPointSize.name.setTo("PointSize");
- break;
-
- default:
- break;
- }
+ mAttribs[userNum].size = c.getVectorSize();
+ mAttribs[userNum].offset = mElement->getFieldOffsetBytes(ct);
+ mAttribs[userNum].type = c.getGLType();
+ mAttribs[userNum].normalized = c.getType() != RS_TYPE_FLOAT_32;//c.getIsNormalized();
+ mAttribs[userNum].name.setTo(getElement()->getFieldName(ct));
+ userNum ++;
}
}
-void Type::enableGLVertexBuffer(VertexArray *va) const
-{
- // Note: We are only going to enable buffers and never disable them
- // here. The reason is more than one Allocation may be used as a vertex
- // source. So we cannot disable arrays that may have been in use by
- // another allocation.
-
- uint32_t stride = mElement->getSizeBytes();
- if (mGL.mVtx.size) {
- va->addLegacy(mGL.mVtx.type,
- mGL.mVtx.size,
- stride,
- RS_KIND_POSITION,
- false,
- mGL.mVtx.offset);
- }
-
- if (mGL.mNorm.size) {
- va->addLegacy(mGL.mNorm.type,
- 3,
- stride,
- RS_KIND_NORMAL,
- false,
- mGL.mNorm.offset);
- }
-
- if (mGL.mColor.size) {
- va->addLegacy(mGL.mColor.type,
- mGL.mColor.size,
- stride,
- RS_KIND_COLOR,
- true,
- mGL.mColor.offset);
- }
-
- if (mGL.mTex.size) {
- va->addLegacy(mGL.mTex.type,
- mGL.mTex.size,
- stride,
- RS_KIND_TEXTURE,
- false,
- mGL.mTex.offset);
- }
-
- if (mGL.mPointSize.size) {
- va->addLegacy(mGL.mPointSize.type,
- 1,
- stride,
- RS_KIND_POINT_SIZE,
- false,
- mGL.mPointSize.offset);
- }
-
-}
-void Type::enableGLVertexBuffer2(VertexArray *va) const
+void Type::enableGLVertexBuffer(VertexArray *va) const
{
- // Do legacy buffers
- enableGLVertexBuffer(va);
-
uint32_t stride = mElement->getSizeBytes();
for (uint32_t ct=0; ct < RS_MAX_ATTRIBS; ct++) {
- if (mGL.mUser[ct].size) {
- va->addUser(mGL.mUser[ct], stride);
+ if (mAttribs[ct].size) {
+ va->add(mAttribs[ct], stride);
}
}
}
@@ -283,6 +179,57 @@ void Type::dumpLOGV(const char *prefix) const
mElement->dumpLOGV(buf);
}
+void Type::serialize(OStream *stream) const
+{
+ // Need to identify ourselves
+ stream->addU32((uint32_t)getClassId());
+
+ String8 name(getName());
+ stream->addString(&name);
+
+ mElement->serialize(stream);
+
+ stream->addU32(mDimX);
+ stream->addU32(mDimY);
+ stream->addU32(mDimZ);
+
+ stream->addU8((uint8_t)(mDimLOD ? 1 : 0));
+ stream->addU8((uint8_t)(mFaces ? 1 : 0));
+}
+
+Type *Type::createFromStream(Context *rsc, IStream *stream)
+{
+ // First make sure we are reading the correct object
+ RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
+ if(classID != RS_A3D_CLASS_ID_TYPE) {
+ LOGE("type loading skipped due to invalid class id\n");
+ return NULL;
+ }
+
+ String8 name;
+ stream->loadString(&name);
+
+ Element *elem = Element::createFromStream(rsc, stream);
+ if(!elem) {
+ return NULL;
+ }
+
+ Type *type = new Type(rsc);
+ type->mDimX = stream->loadU32();
+ type->mDimY = stream->loadU32();
+ type->mDimZ = stream->loadU32();
+
+ uint8_t temp = stream->loadU8();
+ type->mDimLOD = temp != 0;
+
+ temp = stream->loadU8();
+ type->mFaces = temp != 0;
+
+ type->setElement(elem);
+
+ return type;
+}
+
bool Type::getIsNp2() const
{
uint32_t x = getDimX();
diff --git a/libs/rs/rsType.h b/libs/rs/rsType.h
index c25577c..5b51e20 100644
--- a/libs/rs/rsType.h
+++ b/libs/rs/rsType.h
@@ -71,9 +71,11 @@ public:
void compute();
void enableGLVertexBuffer(class VertexArray *) const;
- void enableGLVertexBuffer2(class VertexArray *) const;
void dumpLOGV(const char *prefix) const;
+ virtual void serialize(OStream *stream) const;
+ virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_TYPE; }
+ static Type *createFromStream(Context *rsc, IStream *stream);
protected:
struct LOD {
@@ -112,15 +114,7 @@ protected:
LOD *mLODs;
uint32_t mLODCount;
- struct GLState_t {
- VertexArray::Attrib mUser[RS_MAX_ATTRIBS];
- VertexArray::Attrib mVtx;
- VertexArray::Attrib mNorm;
- VertexArray::Attrib mColor;
- VertexArray::Attrib mTex;
- VertexArray::Attrib mPointSize;
- };
- GLState_t mGL;
+ VertexArray::Attrib mAttribs[RS_MAX_ATTRIBS];
void makeGLComponents();
private:
diff --git a/libs/rs/rsUtils.h b/libs/rs/rsUtils.h
index 07f8933..0a37a5b 100644
--- a/libs/rs/rsUtils.h
+++ b/libs/rs/rsUtils.h
@@ -19,15 +19,22 @@
#define LOG_NDEBUG 0
#define LOG_TAG "RenderScript"
+
#include <utils/Log.h>
-#include <utils/Vector.h>
-#include <utils/KeyedVector.h>
+
+#include "rsStream.h"
+
#include <utils/String8.h>
+#include <utils/Vector.h>
+
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include <EGL/egl.h>
+#endif
+
#include <math.h>
#include "RenderScript.h"
@@ -41,6 +48,26 @@ namespace renderscript {
#define rsAssert(v) while(0)
#endif
+typedef float rsvF_2 __attribute__ ((vector_size (8)));
+typedef float rsvF_4 __attribute__ ((vector_size (16)));
+typedef uint8_t rsvU8_4 __attribute__ ((vector_size (4)));
+
+union float2 {
+ rsvF_2 v;
+ float f[2];
+};
+
+union float4 {
+ rsvF_4 v;
+ float f[4];
+};
+
+union uchar4 {
+ rsvU8_4 v;
+ uint8_t f[4];
+ uint32_t packed;
+};
+
template<typename T>
T rsMin(T in1, T in2)
{
diff --git a/libs/rs/rsVertexArray.cpp b/libs/rs/rsVertexArray.cpp
index 6c2002d..6f15db0 100644
--- a/libs/rs/rsVertexArray.cpp
+++ b/libs/rs/rsVertexArray.cpp
@@ -14,10 +14,15 @@
* limitations under the License.
*/
+#ifndef ANDROID_RS_BUILD_FOR_HOST
#include "rsContext.h"
-
#include <GLES/gl.h>
#include <GLES2/gl2.h>
+#else
+#include "rsContextHostStub.h"
+#include <OpenGL/gl.h>
+#endif
+
using namespace android;
using namespace android::renderscript;
@@ -55,7 +60,6 @@ void VertexArray::Attrib::set(const Attrib &a)
size = a.size;
stride = a.stride;
normalized = a.normalized;
- kind = RS_KIND_USER;
name.setTo(a.name);
}
@@ -75,19 +79,18 @@ void VertexArray::clear(uint32_t n)
mAttribs[n].clear();
}
-void VertexArray::addUser(const Attrib &a, uint32_t stride)
+void VertexArray::add(const Attrib &a, uint32_t stride)
{
- assert(mCount < RS_MAX_ATTRIBS);
+ rsAssert(mCount < RS_MAX_ATTRIBS);
mAttribs[mCount].set(a);
mAttribs[mCount].buffer = mActiveBuffer;
mAttribs[mCount].stride = stride;
- mAttribs[mCount].kind = RS_KIND_USER;
mCount ++;
}
-void VertexArray::addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDataKind kind, bool normalized, uint32_t offset)
+void VertexArray::add(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset, const char *name)
{
- assert(mCount < RS_MAX_ATTRIBS);
+ rsAssert(mCount < RS_MAX_ATTRIBS);
mAttribs[mCount].clear();
mAttribs[mCount].type = type;
mAttribs[mCount].size = size;
@@ -95,93 +98,25 @@ void VertexArray::addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDat
mAttribs[mCount].normalized = normalized;
mAttribs[mCount].buffer = mActiveBuffer;
mAttribs[mCount].stride = stride;
- mAttribs[mCount].kind = kind;
+ mAttribs[mCount].name.setTo(name);
mCount ++;
}
void VertexArray::logAttrib(uint32_t idx, uint32_t slot) const {
- LOGE("va %i: slot=%i name=%s buf=%i size=%i type=0x%x kind=%i stride=0x%x norm=%i offset=0x%x", idx, slot,
+ LOGE("va %i: slot=%i name=%s buf=%i size=%i type=0x%x stride=0x%x norm=%i offset=0x%x", idx, slot,
mAttribs[idx].name.string(),
mAttribs[idx].buffer,
mAttribs[idx].size,
mAttribs[idx].type,
- mAttribs[idx].kind,
mAttribs[idx].stride,
mAttribs[idx].normalized,
mAttribs[idx].offset);
}
-void VertexArray::setupGL(const Context *rsc, class VertexArrayState *state) const
-{
- glClientActiveTexture(GL_TEXTURE0);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glDisableClientState(GL_POINT_SIZE_ARRAY_OES);
-
- for (uint32_t ct=0; ct < mCount; ct++) {
- switch(mAttribs[ct].kind) {
- case RS_KIND_POSITION:
- //logAttrib(POSITION);
- glEnableClientState(GL_VERTEX_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
- glVertexPointer(mAttribs[ct].size,
- mAttribs[ct].type,
- mAttribs[ct].stride,
- (void *)mAttribs[ct].offset);
- break;
-
- case RS_KIND_NORMAL:
- //logAttrib(NORMAL);
- glEnableClientState(GL_NORMAL_ARRAY);
- rsAssert(mAttribs[ct].size == 3);
- glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
- glNormalPointer(mAttribs[ct].type,
- mAttribs[ct].stride,
- (void *)mAttribs[ct].offset);
- break;
-
- case RS_KIND_COLOR:
- //logAttrib(COLOR);
- glEnableClientState(GL_COLOR_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
- glColorPointer(mAttribs[ct].size,
- mAttribs[ct].type,
- mAttribs[ct].stride,
- (void *)mAttribs[ct].offset);
- break;
-
- case RS_KIND_TEXTURE:
- //logAttrib(TEXTURE);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
- glTexCoordPointer(mAttribs[ct].size,
- mAttribs[ct].type,
- mAttribs[ct].stride,
- (void *)mAttribs[ct].offset);
- break;
-
- case RS_KIND_POINT_SIZE:
- //logAttrib(POINT_SIZE);
- glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
- glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
- glPointSizePointerOES(mAttribs[ct].type,
- mAttribs[ct].stride,
- (void *)mAttribs[ct].offset);
- break;
-
- default:
- rsAssert(0);
- }
- }
-
- rsc->checkError("VertexArray::setupGL");
-}
-
void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, ShaderCache *sc) const
{
rsc->checkError("VertexArray::setupGL2 start");
- for (uint32_t ct=1; ct <= state->mLastEnableCount; ct++) {
+ for (uint32_t ct=1; ct <= 0xf/*state->mLastEnableCount*/; ct++) {
glDisableVertexAttribArray(ct);
}
@@ -191,16 +126,24 @@ void VertexArray::setupGL2(const Context *rsc, class VertexArrayState *state, Sh
if (sc->isUserVertexProgram()) {
slot = sc->vtxAttribSlot(ct);
} else {
- if (mAttribs[ct].kind == RS_KIND_USER) {
+ if (mAttribs[ct].name == "position") {
+ slot = 0;
+ } else if (mAttribs[ct].name == "color") {
+ slot = 1;
+ } else if (mAttribs[ct].name == "normal") {
+ slot = 2;
+ } else if (mAttribs[ct].name == "pointSize") {
+ slot = 3;
+ } else if (mAttribs[ct].name == "texture0") {
+ slot = 4;
+ } else {
continue;
}
- slot = sc->vtxAttribSlot(mAttribs[ct].kind);
}
//logAttrib(ct, slot);
glEnableVertexAttribArray(slot);
glBindBuffer(GL_ARRAY_BUFFER, mAttribs[ct].buffer);
-
glVertexAttribPointer(slot,
mAttribs[ct].size,
mAttribs[ct].type,
diff --git a/libs/rs/rsVertexArray.h b/libs/rs/rsVertexArray.h
index 3904cb6..e5b51d7 100644
--- a/libs/rs/rsVertexArray.h
+++ b/libs/rs/rsVertexArray.h
@@ -43,7 +43,6 @@ public:
uint32_t stride;
bool normalized;
String8 name;
- RsDataKind kind;
Attrib();
void set(const Attrib &);
@@ -53,8 +52,9 @@ public:
void clearAll();
void setActiveBuffer(uint32_t id) {mActiveBuffer = id;}
- void addUser(const Attrib &, uint32_t stride);
- void addLegacy(uint32_t type, uint32_t size, uint32_t stride, RsDataKind kind, bool normalized, uint32_t offset);
+ void add(const Attrib &, uint32_t stride);
+ //void addLegacy(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset);
+ void add(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset, const char *name);
void setupGL(const Context *rsc, class VertexArrayState *) const;
void setupGL2(const Context *rsc, class VertexArrayState *, ShaderCache *) const;
diff --git a/libs/rs/rsg_ScriptJavaClass.cpp b/libs/rs/rsg_ScriptJavaClass.cpp
index cee9f52..0169b98 100644
--- a/libs/rs/rsg_ScriptJavaClass.cpp
+++ b/libs/rs/rsg_ScriptJavaClass.cpp
@@ -7,8 +7,12 @@
struct Element;
struct ElementField {
+ // An Element Field is a combination of an Element with a name assigned.
+
const char *name;
Element *e;
+
+
ElementField(const char *n, Element *_e) {
name = n;
e = _e;
@@ -20,12 +24,21 @@ struct ElementField {
};
struct Element {
+ // An Element can take one of two forms.
+ // 1: Basic. It contains a single basic type and vector size.
+ // 2: Complex. It contains a list of fields with names. Each field
+ // will in turn be another element.
+
ElementField *fields;
- size_t fieldCount;
+ size_t fieldCount; // If field count is 0, the element is a Basic type.
const char *name;
bool generated;
+ // The basic data type from RenderScript.h
RsDataType compType;
+
+ // The vector size of the data type for float2, float3, ....
+ // Allowed sizes are 2,3,4,8,16
uint32_t compVectorSize;
Element() {
diff --git a/libs/rs/scriptc/rs_cl.rsh b/libs/rs/scriptc/rs_cl.rsh
new file mode 100644
index 0000000..c84cdff
--- /dev/null
+++ b/libs/rs/scriptc/rs_cl.rsh
@@ -0,0 +1,785 @@
+#ifndef __RS_CL_RSH__
+#define __RS_CL_RSH__
+
+#define M_PI 3.14159265358979323846264338327950288f /* pi */
+
+
+// Conversions
+#define CVT_FUNC_2(typeout, typein) \
+static typeout##2 __attribute__((overloadable)) convert_##typeout##2(typein##2 v) { \
+ typeout##2 r = {v.x, v.y}; \
+ return r; \
+} \
+static typeout##3 __attribute__((overloadable)) convert_##typeout##3(typein##3 v) { \
+ typeout##3 r = {v.x, v.y, v.z}; \
+ return r; \
+} \
+static typeout##4 __attribute__((overloadable)) convert_##typeout##4(typein##4 v) { \
+ typeout##4 r = {v.x, v.y, v.z, v.w}; \
+ return r; \
+}
+
+#define CVT_FUNC(type) CVT_FUNC_2(type, uchar) \
+ CVT_FUNC_2(type, char) \
+ CVT_FUNC_2(type, ushort) \
+ CVT_FUNC_2(type, short) \
+ CVT_FUNC_2(type, int) \
+ CVT_FUNC_2(type, uint) \
+ CVT_FUNC_2(type, float)
+
+CVT_FUNC(char)
+CVT_FUNC(uchar)
+CVT_FUNC(short)
+CVT_FUNC(ushort)
+CVT_FUNC(int)
+CVT_FUNC(uint)
+CVT_FUNC(float)
+
+
+
+// Float ops, 6.11.2
+
+#define DEF_FUNC_1(fnc) \
+static float2 __attribute__((overloadable)) fnc(float2 v) { \
+ float2 r; \
+ r.x = fnc(v.x); \
+ r.y = fnc(v.y); \
+ return r; \
+} \
+static float3 __attribute__((overloadable)) fnc(float3 v) { \
+ float3 r; \
+ r.x = fnc(v.x); \
+ r.y = fnc(v.y); \
+ r.z = fnc(v.z); \
+ return r; \
+} \
+static float4 __attribute__((overloadable)) fnc(float4 v) { \
+ float4 r; \
+ r.x = fnc(v.x); \
+ r.y = fnc(v.y); \
+ r.z = fnc(v.z); \
+ r.w = fnc(v.w); \
+ return r; \
+}
+
+#define DEF_FUNC_2(fnc) \
+static float2 __attribute__((overloadable)) fnc(float2 v1, float2 v2) { \
+ float2 r; \
+ r.x = fnc(v1.x, v2.x); \
+ r.y = fnc(v1.y, v2.y); \
+ return r; \
+} \
+static float3 __attribute__((overloadable)) fnc(float3 v1, float3 v2) { \
+ float3 r; \
+ r.x = fnc(v1.x, v2.x); \
+ r.y = fnc(v1.y, v2.y); \
+ r.z = fnc(v1.z, v2.z); \
+ return r; \
+} \
+static float4 __attribute__((overloadable)) fnc(float4 v1, float4 v2) { \
+ float4 r; \
+ r.x = fnc(v1.x, v2.x); \
+ r.y = fnc(v1.y, v2.y); \
+ r.z = fnc(v1.z, v2.z); \
+ r.w = fnc(v1.w, v2.z); \
+ return r; \
+}
+
+#define DEF_FUNC_2F(fnc) \
+static float2 __attribute__((overloadable)) fnc(float2 v1, float v2) { \
+ float2 r; \
+ r.x = fnc(v1.x, v2); \
+ r.y = fnc(v1.y, v2); \
+ return r; \
+} \
+static float3 __attribute__((overloadable)) fnc(float3 v1, float v2) { \
+ float3 r; \
+ r.x = fnc(v1.x, v2); \
+ r.y = fnc(v1.y, v2); \
+ r.z = fnc(v1.z, v2); \
+ return r; \
+} \
+static float4 __attribute__((overloadable)) fnc(float4 v1, float v2) { \
+ float4 r; \
+ r.x = fnc(v1.x, v2); \
+ r.y = fnc(v1.y, v2); \
+ r.z = fnc(v1.z, v2); \
+ r.w = fnc(v1.w, v2); \
+ return r; \
+}
+
+
+extern float __attribute__((overloadable)) acos(float);
+DEF_FUNC_1(acos)
+
+extern float __attribute__((overloadable)) acosh(float);
+DEF_FUNC_1(acosh)
+
+static float __attribute__((overloadable)) acospi(float v) {
+ return acos(v) / M_PI;
+}
+DEF_FUNC_1(acospi)
+
+extern float __attribute__((overloadable)) asin(float);
+DEF_FUNC_1(asin)
+
+extern float __attribute__((overloadable)) asinh(float);
+DEF_FUNC_1(asinh)
+
+static float __attribute__((overloadable)) asinpi(float v) {
+ return asin(v) / M_PI;
+}
+DEF_FUNC_1(asinpi)
+
+extern float __attribute__((overloadable)) atan(float);
+DEF_FUNC_1(atan)
+
+extern float __attribute__((overloadable)) atan2(float, float);
+DEF_FUNC_2(atan2)
+
+extern float __attribute__((overloadable)) atanh(float);
+DEF_FUNC_1(atanh)
+
+static float __attribute__((overloadable)) atanpi(float v) {
+ return atan(v) / M_PI;
+}
+DEF_FUNC_1(atanpi)
+
+static float __attribute__((overloadable)) atan2pi(float y, float x) {
+ return atan2(y, x) / M_PI;
+}
+DEF_FUNC_2(atan2pi)
+
+extern float __attribute__((overloadable)) cbrt(float);
+DEF_FUNC_1(cbrt)
+
+extern float __attribute__((overloadable)) ceil(float);
+DEF_FUNC_1(ceil)
+
+extern float __attribute__((overloadable)) copysign(float, float);
+DEF_FUNC_2(copysign)
+
+extern float __attribute__((overloadable)) cos(float);
+DEF_FUNC_1(cos)
+
+extern float __attribute__((overloadable)) cosh(float);
+DEF_FUNC_1(cosh)
+
+static float __attribute__((overloadable)) cospi(float v) {
+ return cos(v * M_PI);
+}
+DEF_FUNC_1(cospi)
+
+extern float __attribute__((overloadable)) erfc(float);
+DEF_FUNC_1(erfc)
+
+extern float __attribute__((overloadable)) erf(float);
+DEF_FUNC_1(erf)
+
+extern float __attribute__((overloadable)) exp(float);
+DEF_FUNC_1(exp)
+
+extern float __attribute__((overloadable)) exp2(float);
+DEF_FUNC_1(exp2)
+
+extern float __attribute__((overloadable)) pow(float, float);
+static float __attribute__((overloadable)) exp10(float v) {
+ return pow(10.f, v);
+}
+DEF_FUNC_1(exp10)
+
+extern float __attribute__((overloadable)) expm1(float);
+DEF_FUNC_1(expm1)
+
+extern float __attribute__((overloadable)) fabs(float);
+DEF_FUNC_1(fabs)
+
+extern float __attribute__((overloadable)) fdim(float, float);
+DEF_FUNC_2(fdim)
+
+extern float __attribute__((overloadable)) floor(float);
+DEF_FUNC_1(floor)
+
+extern float __attribute__((overloadable)) fma(float, float, float);
+extern float2 __attribute__((overloadable)) fma(float2, float2, float2);
+extern float3 __attribute__((overloadable)) fma(float3, float3, float3);
+extern float4 __attribute__((overloadable)) fma(float4, float4, float4);
+
+extern float __attribute__((overloadable)) fmax(float, float);
+DEF_FUNC_2(fmax);
+DEF_FUNC_2F(fmax);
+
+extern float __attribute__((overloadable)) fmin(float, float);
+DEF_FUNC_2(fmin);
+DEF_FUNC_2F(fmin);
+
+extern float __attribute__((overloadable)) fmod(float, float);
+DEF_FUNC_2(fmod)
+
+static float __attribute__((overloadable)) fract(float v, float *iptr) {
+ int i = (int)floor(v);
+ iptr[0] = i;
+ return fmin(v - i, 0x1.fffffep-1f);
+}
+static float2 __attribute__((overloadable)) fract(float2 v, float2 *iptr) {
+ float t[2];
+ float2 r;
+ r.x = fract(v.x, &t[0]);
+ r.y = fract(v.y, &t[1]);
+ iptr[0] = t[0];
+ iptr[1] = t[1];
+ return r;
+}
+static float3 __attribute__((overloadable)) fract(float3 v, float3 *iptr) {
+ float t[3];
+ float3 r;
+ r.x = fract(v.x, &t[0]);
+ r.y = fract(v.y, &t[1]);
+ r.z = fract(v.z, &t[2]);
+ iptr[0] = t[0];
+ iptr[1] = t[1];
+ iptr[2] = t[2];
+ return r;
+}
+static float4 __attribute__((overloadable)) fract(float4 v, float4 *iptr) {
+ float t[4];
+ float4 r;
+ r.x = fract(v.x, &t[0]);
+ r.y = fract(v.y, &t[1]);
+ r.z = fract(v.z, &t[2]);
+ r.w = fract(v.w, &t[3]);
+ iptr[0] = t[0];
+ iptr[1] = t[1];
+ iptr[2] = t[2];
+ iptr[3] = t[3];
+ return r;
+}
+
+extern float __attribute__((overloadable)) frexp(float, float *);
+extern float2 __attribute__((overloadable)) frexp(float2, float2 *);
+extern float3 __attribute__((overloadable)) frexp(float3, float3 *);
+extern float4 __attribute__((overloadable)) frexp(float4, float4 *);
+
+extern float __attribute__((overloadable)) hypot(float, float);
+DEF_FUNC_2(hypot)
+
+extern int __attribute__((overloadable)) ilogb(float);
+DEF_FUNC_1(ilogb)
+
+extern float __attribute__((overloadable)) ldexp(float, int);
+extern float2 __attribute__((overloadable)) ldexp(float2, int2);
+extern float3 __attribute__((overloadable)) ldexp(float3, int3);
+extern float4 __attribute__((overloadable)) ldexp(float4, int4);
+extern float2 __attribute__((overloadable)) ldexp(float2, int);
+extern float3 __attribute__((overloadable)) ldexp(float3, int);
+extern float4 __attribute__((overloadable)) ldexp(float4, int);
+
+extern float __attribute__((overloadable)) lgamma(float);
+DEF_FUNC_1(lgamma)
+extern float __attribute__((overloadable)) lgamma(float, float *);
+extern float2 __attribute__((overloadable)) lgamma(float2, float2 *);
+extern float3 __attribute__((overloadable)) lgamma(float3, float3 *);
+extern float4 __attribute__((overloadable)) lgamma(float4, float4 *);
+
+extern float __attribute__((overloadable)) log(float);
+DEF_FUNC_1(log)
+
+
+extern float __attribute__((overloadable)) log10(float);
+DEF_FUNC_1(log10)
+
+static float __attribute__((overloadable)) log2(float v) {
+ return log10(v) / log10(2.f);
+}
+DEF_FUNC_1(log2)
+
+extern float __attribute__((overloadable)) log1p(float);
+DEF_FUNC_1(log1p)
+
+extern float __attribute__((overloadable)) logb(float);
+DEF_FUNC_1(logb)
+
+extern float __attribute__((overloadable)) mad(float, float, float);
+extern float2 __attribute__((overloadable)) mad(float2, float2, float2);
+extern float3 __attribute__((overloadable)) mad(float3, float3, float3);
+extern float4 __attribute__((overloadable)) mad(float4, float4, float4);
+
+extern float __attribute__((overloadable)) modf(float, float *);
+extern float2 __attribute__((overloadable)) modf(float2, float2 *);
+extern float3 __attribute__((overloadable)) modf(float3, float3 *);
+extern float4 __attribute__((overloadable)) modf(float4, float4 *);
+
+//extern float __attribute__((overloadable)) nan(uint);
+
+extern float __attribute__((overloadable)) nextafter(float, float);
+DEF_FUNC_2(nextafter)
+
+DEF_FUNC_2(pow)
+
+static float __attribute__((overloadable)) pown(float v, int p) {
+ return pow(v, (float)p);
+}
+static float2 __attribute__((overloadable)) pown(float2 v, int2 p) {
+ return pow(v, (float2)p);
+}
+static float3 __attribute__((overloadable)) pown(float3 v, int3 p) {
+ return pow(v, (float3)p);
+}
+static float4 __attribute__((overloadable)) pown(float4 v, int4 p) {
+ return pow(v, (float4)p);
+}
+
+static float __attribute__((overloadable)) powr(float v, float p) {
+ return pow(v, p);
+}
+static float2 __attribute__((overloadable)) powr(float2 v, float2 p) {
+ return pow(v, p);
+}
+static float3 __attribute__((overloadable)) powr(float3 v, float3 p) {
+ return pow(v, p);
+}
+static float4 __attribute__((overloadable)) powr(float4 v, float4 p) {
+ return pow(v, p);
+}
+
+extern float __attribute__((overloadable)) remainder(float, float);
+DEF_FUNC_2(remainder)
+
+extern float __attribute__((overloadable)) remquo(float, float, float *);
+extern float2 __attribute__((overloadable)) remquo(float2, float2, float2 *);
+extern float3 __attribute__((overloadable)) remquo(float3, float3, float3 *);
+extern float4 __attribute__((overloadable)) remquo(float4, float4, float4 *);
+
+extern float __attribute__((overloadable)) rint(float);
+DEF_FUNC_1(rint)
+
+static float __attribute__((overloadable)) rootn(float v, int r) {
+ return pow(v, 1.f / r);
+}
+static float2 __attribute__((overloadable)) rootn(float2 v, int2 r) {
+ float2 t = {1.f / r.x, 1.f / r.y};
+ return pow(v, t);
+}
+static float3 __attribute__((overloadable)) rootn(float3 v, int3 r) {
+ float3 t = {1.f / r.x, 1.f / r.y, 1.f / r.z};
+ return pow(v, t);
+}
+static float4 __attribute__((overloadable)) rootn(float4 v, int4 r) {
+ float4 t = {1.f / r.x, 1.f / r.y, 1.f / r.z, 1.f / r.w};
+ return pow(v, t);
+}
+
+extern float __attribute__((overloadable)) round(float);
+DEF_FUNC_1(round)
+
+extern float __attribute__((overloadable)) sqrt(float);
+static float __attribute__((overloadable)) rsqrt(float v) {
+ return 1.f / sqrt(v);
+}
+DEF_FUNC_1(rsqrt)
+
+extern float __attribute__((overloadable)) sin(float);
+DEF_FUNC_1(sin)
+
+static float __attribute__((overloadable)) sincos(float v, float *cosptr) {
+ *cosptr = cos(v);
+ return sin(v);
+}
+static float2 __attribute__((overloadable)) sincos(float2 v, float2 *cosptr) {
+ *cosptr = cos(v);
+ return sin(v);
+}
+static float3 __attribute__((overloadable)) sincos(float3 v, float3 *cosptr) {
+ *cosptr = cos(v);
+ return sin(v);
+}
+static float4 __attribute__((overloadable)) sincos(float4 v, float4 *cosptr) {
+ *cosptr = cos(v);
+ return sin(v);
+}
+
+extern float __attribute__((overloadable)) sinh(float);
+DEF_FUNC_1(sinh)
+
+static float __attribute__((overloadable)) sinpi(float v) {
+ return sin(v * M_PI);
+}
+DEF_FUNC_1(sinpi)
+
+DEF_FUNC_1(sqrt)
+
+extern float __attribute__((overloadable)) tan(float);
+DEF_FUNC_1(tan)
+
+extern float __attribute__((overloadable)) tanh(float);
+DEF_FUNC_1(tanh)
+
+static float __attribute__((overloadable)) tanpi(float v) {
+ return tan(v * M_PI);
+}
+DEF_FUNC_1(tanpi)
+
+extern float __attribute__((overloadable)) tgamma(float);
+DEF_FUNC_1(tgamma)
+
+extern float __attribute__((overloadable)) trunc(float);
+DEF_FUNC_1(trunc)
+
+// Int ops (partial), 6.11.3
+extern uint __attribute__((overloadable)) abs(int);
+extern ushort __attribute__((overloadable)) abs(short);
+extern uchar __attribute__((overloadable)) abs(char);
+
+extern uint __attribute__((overloadable)) clz(uint);
+extern int __attribute__((overloadable)) clz(int);
+extern ushort __attribute__((overloadable)) clz(ushort);
+extern short __attribute__((overloadable)) clz(short);
+extern uchar __attribute__((overloadable)) clz(uchar);
+extern char __attribute__((overloadable)) clz(char);
+
+static uint __attribute__((overloadable)) min(uint v1, uint v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static int __attribute__((overloadable)) min(int v1, int v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static ushort __attribute__((overloadable)) min(ushort v1, ushort v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static short __attribute__((overloadable)) min(short v1, short v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static uchar __attribute__((overloadable)) min(uchar v1, uchar v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static char __attribute__((overloadable)) min(char v1, char v2) {
+ return v1 < v2 ? v1 : v2;
+}
+
+static uint __attribute__((overloadable)) max(uint v1, uint v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static int __attribute__((overloadable)) max(int v1, int v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static ushort __attribute__((overloadable)) max(ushort v1, ushort v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static short __attribute__((overloadable)) max(short v1, short v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static uchar __attribute__((overloadable)) max(uchar v1, uchar v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static char __attribute__((overloadable)) max(char v1, char v2) {
+ return v1 > v2 ? v1 : v2;
+}
+
+
+
+
+// 6.11.4
+
+static float __attribute__((overloadable)) clamp(float amount, float low, float high) {
+ return amount < low ? low : (amount > high ? high : amount);
+}
+static float2 __attribute__((overloadable)) clamp(float2 amount, float2 low, float2 high) {
+ float2 r;
+ r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x);
+ r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y);
+ return r;
+}
+static float3 __attribute__((overloadable)) clamp(float3 amount, float3 low, float3 high) {
+ float3 r;
+ r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x);
+ r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y);
+ r.z = amount.z < low.z ? low.z : (amount.z > high.z ? high.z : amount.z);
+ return r;
+}
+static float4 __attribute__((overloadable)) clamp(float4 amount, float4 low, float4 high) {
+ float4 r;
+ r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x);
+ r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y);
+ r.z = amount.z < low.z ? low.z : (amount.z > high.z ? high.z : amount.z);
+ r.w = amount.w < low.w ? low.w : (amount.w > high.w ? high.w : amount.w);
+ return r;
+}
+static float2 __attribute__((overloadable)) clamp(float2 amount, float low, float high) {
+ float2 r;
+ r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
+ r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
+ return r;
+}
+static float3 __attribute__((overloadable)) clamp(float3 amount, float low, float high) {
+ float3 r;
+ r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
+ r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
+ r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
+ return r;
+}
+static float4 __attribute__((overloadable)) clamp(float4 amount, float low, float high) {
+ float4 r;
+ r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
+ r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
+ r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
+ r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);
+ return r;
+}
+
+static float __attribute__((overloadable)) degrees(float radians) {
+ return radians * (180.f / M_PI);
+}
+DEF_FUNC_1(degrees)
+
+static float __attribute__((overloadable)) max(float v1, float v2) {
+ return v1 > v2 ? v1 : v2;
+}
+static float2 __attribute__((overloadable)) max(float2 v1, float2 v2) {
+ float2 r;
+ r.x = v1.x > v2.x ? v1.x : v2.x;
+ r.y = v1.y > v2.y ? v1.y : v2.y;
+ return r;
+}
+static float3 __attribute__((overloadable)) max(float3 v1, float3 v2) {
+ float3 r;
+ r.x = v1.x > v2.x ? v1.x : v2.x;
+ r.y = v1.y > v2.y ? v1.y : v2.y;
+ r.z = v1.z > v2.z ? v1.z : v2.z;
+ return r;
+}
+static float4 __attribute__((overloadable)) max(float4 v1, float4 v2) {
+ float4 r;
+ r.x = v1.x > v2.x ? v1.x : v2.x;
+ r.y = v1.y > v2.y ? v1.y : v2.y;
+ r.z = v1.z > v2.z ? v1.z : v2.z;
+ r.w = v1.w > v2.w ? v1.w : v2.w;
+ return r;
+}
+static float2 __attribute__((overloadable)) max(float2 v1, float v2) {
+ float2 r;
+ r.x = v1.x > v2 ? v1.x : v2;
+ r.y = v1.y > v2 ? v1.y : v2;
+ return r;
+}
+static float3 __attribute__((overloadable)) max(float3 v1, float v2) {
+ float3 r;
+ r.x = v1.x > v2 ? v1.x : v2;
+ r.y = v1.y > v2 ? v1.y : v2;
+ r.z = v1.z > v2 ? v1.z : v2;
+ return r;
+}
+static float4 __attribute__((overloadable)) max(float4 v1, float v2) {
+ float4 r;
+ r.x = v1.x > v2 ? v1.x : v2;
+ r.y = v1.y > v2 ? v1.y : v2;
+ r.z = v1.z > v2 ? v1.z : v2;
+ r.w = v1.w > v2 ? v1.w : v2;
+ return r;
+}
+
+static float __attribute__((overloadable)) min(float v1, float v2) {
+ return v1 < v2 ? v1 : v2;
+}
+static float2 __attribute__((overloadable)) min(float2 v1, float2 v2) {
+ float2 r;
+ r.x = v1.x < v2.x ? v1.x : v2.x;
+ r.y = v1.y < v2.y ? v1.y : v2.y;
+ return r;
+}
+static float3 __attribute__((overloadable)) min(float3 v1, float3 v2) {
+ float3 r;
+ r.x = v1.x < v2.x ? v1.x : v2.x;
+ r.y = v1.y < v2.y ? v1.y : v2.y;
+ r.z = v1.z < v2.z ? v1.z : v2.z;
+ return r;
+}
+static float4 __attribute__((overloadable)) min(float4 v1, float4 v2) {
+ float4 r;
+ r.x = v1.x < v2.x ? v1.x : v2.x;
+ r.y = v1.y < v2.y ? v1.y : v2.y;
+ r.z = v1.z < v2.z ? v1.z : v2.z;
+ r.w = v1.w < v2.w ? v1.w : v2.w;
+ return r;
+}
+static float2 __attribute__((overloadable)) min(float2 v1, float v2) {
+ float2 r;
+ r.x = v1.x < v2 ? v1.x : v2;
+ r.y = v1.y < v2 ? v1.y : v2;
+ return r;
+}
+static float3 __attribute__((overloadable)) min(float3 v1, float v2) {
+ float3 r;
+ r.x = v1.x < v2 ? v1.x : v2;
+ r.y = v1.y < v2 ? v1.y : v2;
+ r.z = v1.z < v2 ? v1.z : v2;
+ return r;
+}
+static float4 __attribute__((overloadable)) min(float4 v1, float v2) {
+ float4 r;
+ r.x = v1.x < v2 ? v1.x : v2;
+ r.y = v1.y < v2 ? v1.y : v2;
+ r.z = v1.z < v2 ? v1.z : v2;
+ r.w = v1.w < v2 ? v1.w : v2;
+ return r;
+}
+
+static float __attribute__((overloadable)) mix(float start, float stop, float amount) {
+ return start + (stop - start) * amount;
+}
+static float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float2 amount) {
+ return start + (stop - start) * amount;
+}
+static float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float3 amount) {
+ return start + (stop - start) * amount;
+}
+static float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float4 amount) {
+ return start + (stop - start) * amount;
+}
+static float2 __attribute__((overloadable)) mix(float2 start, float2 stop, float amount) {
+ return start + (stop - start) * amount;
+}
+static float3 __attribute__((overloadable)) mix(float3 start, float3 stop, float amount) {
+ return start + (stop - start) * amount;
+}
+static float4 __attribute__((overloadable)) mix(float4 start, float4 stop, float amount) {
+ return start + (stop - start) * amount;
+}
+
+static float __attribute__((overloadable)) radians(float degrees) {
+ return degrees * (M_PI / 180.f);
+}
+DEF_FUNC_1(radians)
+
+static float __attribute__((overloadable)) step(float edge, float v) {
+ return (v < edge) ? 0.f : 1.f;
+}
+static float2 __attribute__((overloadable)) step(float2 edge, float2 v) {
+ float2 r;
+ r.x = (v.x < edge.x) ? 0.f : 1.f;
+ r.y = (v.y < edge.y) ? 0.f : 1.f;
+ return r;
+}
+static float3 __attribute__((overloadable)) step(float3 edge, float3 v) {
+ float3 r;
+ r.x = (v.x < edge.x) ? 0.f : 1.f;
+ r.y = (v.y < edge.y) ? 0.f : 1.f;
+ r.z = (v.z < edge.z) ? 0.f : 1.f;
+ return r;
+}
+static float4 __attribute__((overloadable)) step(float4 edge, float4 v) {
+ float4 r;
+ r.x = (v.x < edge.x) ? 0.f : 1.f;
+ r.y = (v.y < edge.y) ? 0.f : 1.f;
+ r.z = (v.z < edge.z) ? 0.f : 1.f;
+ r.w = (v.w < edge.w) ? 0.f : 1.f;
+ return r;
+}
+static float2 __attribute__((overloadable)) step(float2 edge, float v) {
+ float2 r;
+ r.x = (v < edge.x) ? 0.f : 1.f;
+ r.y = (v < edge.y) ? 0.f : 1.f;
+ return r;
+}
+static float3 __attribute__((overloadable)) step(float3 edge, float v) {
+ float3 r;
+ r.x = (v < edge.x) ? 0.f : 1.f;
+ r.y = (v < edge.y) ? 0.f : 1.f;
+ r.z = (v < edge.z) ? 0.f : 1.f;
+ return r;
+}
+static float4 __attribute__((overloadable)) step(float4 edge, float v) {
+ float4 r;
+ r.x = (v < edge.x) ? 0.f : 1.f;
+ r.y = (v < edge.y) ? 0.f : 1.f;
+ r.z = (v < edge.z) ? 0.f : 1.f;
+ r.w = (v < edge.w) ? 0.f : 1.f;
+ return r;
+}
+
+extern float __attribute__((overloadable)) smoothstep(float, float, float);
+extern float2 __attribute__((overloadable)) smoothstep(float2, float2, float2);
+extern float3 __attribute__((overloadable)) smoothstep(float3, float3, float3);
+extern float4 __attribute__((overloadable)) smoothstep(float4, float4, float4);
+extern float2 __attribute__((overloadable)) smoothstep(float, float, float2);
+extern float3 __attribute__((overloadable)) smoothstep(float, float, float3);
+extern float4 __attribute__((overloadable)) smoothstep(float, float, float4);
+
+static float __attribute__((overloadable)) sign(float v) {
+ if (v > 0) return 1.f;
+ if (v < 0) return -1.f;
+ return v;
+}
+DEF_FUNC_1(sign)
+
+// 6.11.5
+static float3 __attribute__((overloadable)) cross(float3 lhs, float3 rhs) {
+ float3 r;
+ r.x = lhs.y * rhs.z - lhs.z * rhs.y;
+ r.y = lhs.z * rhs.x - lhs.x * rhs.z;
+ r.z = lhs.x * rhs.y - lhs.y * rhs.x;
+ return r;
+}
+
+static float4 __attribute__((overloadable)) cross(float4 lhs, float4 rhs) {
+ float4 r;
+ r.x = lhs.y * rhs.z - lhs.z * rhs.y;
+ r.y = lhs.z * rhs.x - lhs.x * rhs.z;
+ r.z = lhs.x * rhs.y - lhs.y * rhs.x;
+ r.w = 0.f;
+ return r;
+}
+
+static float __attribute__((overloadable)) dot(float lhs, float rhs) {
+ return lhs * rhs;
+}
+static float __attribute__((overloadable)) dot(float2 lhs, float2 rhs) {
+ return lhs.x*rhs.x + lhs.y*rhs.y;
+}
+static float __attribute__((overloadable)) dot(float3 lhs, float3 rhs) {
+ return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z;
+}
+static float __attribute__((overloadable)) dot(float4 lhs, float4 rhs) {
+ return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z + lhs.w*rhs.w;
+}
+
+static float __attribute__((overloadable)) length(float v) {
+ return v;
+}
+static float __attribute__((overloadable)) length(float2 v) {
+ return sqrt(v.x*v.x + v.y*v.y);
+}
+static float __attribute__((overloadable)) length(float3 v) {
+ return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
+}
+static float __attribute__((overloadable)) length(float4 v) {
+ return sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w);
+}
+
+static float __attribute__((overloadable)) distance(float lhs, float rhs) {
+ return length(lhs - rhs);
+}
+static float __attribute__((overloadable)) distance(float2 lhs, float2 rhs) {
+ return length(lhs - rhs);
+}
+static float __attribute__((overloadable)) distance(float3 lhs, float3 rhs) {
+ return length(lhs - rhs);
+}
+static float __attribute__((overloadable)) distance(float4 lhs, float4 rhs) {
+ return length(lhs - rhs);
+}
+
+static float __attribute__((overloadable)) normalize(float v) {
+ return 1.f;
+}
+static float2 __attribute__((overloadable)) normalize(float2 v) {
+ return v / length(v);
+}
+static float3 __attribute__((overloadable)) normalize(float3 v) {
+ return v / length(v);
+}
+static float4 __attribute__((overloadable)) normalize(float4 v) {
+ return v / length(v);
+}
+
+
+#endif
diff --git a/libs/rs/scriptc/rs_core.rsh b/libs/rs/scriptc/rs_core.rsh
new file mode 100644
index 0000000..ebf6876
--- /dev/null
+++ b/libs/rs/scriptc/rs_core.rsh
@@ -0,0 +1,54 @@
+#ifndef __RS_CORE_RSH__
+#define __RS_CORE_RSH__
+
+
+static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b)
+{
+ uchar4 c;
+ c.x = (uchar)(r * 255.f);
+ c.y = (uchar)(g * 255.f);
+ c.z = (uchar)(b * 255.f);
+ c.w = 255;
+ return c;
+}
+
+static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float r, float g, float b, float a)
+{
+ uchar4 c;
+ c.x = (uchar)(r * 255.f);
+ c.y = (uchar)(g * 255.f);
+ c.z = (uchar)(b * 255.f);
+ c.w = (uchar)(a * 255.f);
+ return c;
+}
+
+static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float3 color)
+{
+ color *= 255.f;
+ uchar4 c = {color.x, color.y, color.z, 255};
+ return c;
+}
+
+static uchar4 __attribute__((overloadable)) rsPackColorTo8888(float4 color)
+{
+ color *= 255.f;
+ uchar4 c = {color.x, color.y, color.z, color.w};
+ return c;
+}
+
+static float4 rsUnpackColor8888(uchar4 c)
+{
+ float4 ret = (float4)0.0039156862745f;
+ ret *= convert_float4(c);
+ return ret;
+}
+
+//extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float r, float g, float b);
+//extern uchar4 __attribute__((overloadable)) rsPackColorTo565(float3);
+//extern float4 rsUnpackColor565(uchar4);
+
+
+
+
+#endif
+
diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh
index 70cd562..fe2c549 100644
--- a/libs/rs/scriptc/rs_graphics.rsh
+++ b/libs/rs/scriptc/rs_graphics.rsh
@@ -1,65 +1,48 @@
+#ifndef __RS_GRAPHICS_RSH__
+#define __RS_GRAPHICS_RSH__
+#include "rs_math.rsh"
-extern float2 vec2Rand(float len);
-extern float3 float3Norm(float3);
-extern float float3Length(float3);
-extern float3 float3Add(float3 lhs, float3 rhs);
-extern float3 float3Sub(float3 lhs, float3 rhs);
-extern float3 float3Cross(float3 lhs, float3 rhs);
-extern float float3Dot(float3 lhs, float3 rhs);
-extern float3 float3Scale(float3 v, float scale);
+// context
+extern void rsgBindProgramFragment(rs_program_fragment);
+extern void rsgBindProgramStore(rs_program_store);
+extern void rsgBindProgramVertex(rs_program_vertex);
+extern void rsgBindProgramRaster(rs_program_raster);
-extern float4 float4Add(float4 lhs, float4 rhs);
-extern float4 float4Sub(float4 lhs, float4 rhs);
-extern float4 float4Cross(float4 lhs, float4 rhs);
-extern float float4Dot(float4 lhs, float4 rhs);
-extern float4 float4Scale(float4 v, float scale);
+extern void rsgBindSampler(rs_program_fragment, int slot, rs_sampler);
+extern void rsgBindTexture(rs_program_fragment, int slot, rs_allocation);
- // context
-extern void bindProgramFragment(rs_program_fragment);
-extern void bindProgramStore(rs_program_store);
-extern void bindProgramVertex(rs_program_vertex);
+extern void rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 *);
+extern void rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 *);
-extern void bindSampler(rs_program_fragment, int slot, rs_sampler);
-extern void bindSampler(rs_program_fragment, int slot, rs_allocation);
+extern int rsgGetWidth();
+extern int rsgGetHeight();
-extern void vpLoadModelMatrix(const float *);
-extern void vpLoadTextureMatrix(const float *);
+extern void __attribute__((overloadable)) rsgUploadToTexture(rs_allocation);
+extern void __attribute__((overloadable)) rsgUploadToTexture(rs_allocation, int mipLevel);
+extern void rsgUploadToBufferObject(rs_allocation);
+//extern void rsgUploadMesh(rs_mesh);
+extern void rsgDrawRect(float x1, float y1, float x2, float y2, float z);
+extern void rsgDrawQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4);
+extern void rsgDrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4);
+//extern void rsgDrawSprite(float x, float y, float z, float w, float h);
+extern void rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h);
+extern void rsgDrawLine(float x1, float y1, float z1, float x2, float y2, float z2);
+extern void rsgDrawPoint(float x1, float y1, float z1);
+extern void __attribute__((overloadable)) rsgDrawSimpleMesh(rs_mesh ism);
+extern void __attribute__((overloadable)) rsgDrawSimpleMesh(rs_mesh ism, int start, int len);
-// drawing
-extern void drawRect(float x1, float y1, float x2, float y2, float z);
-extern void drawQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4);
-extern void drawQuadTexCoords(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4);
-extern void drawSprite(float x, float y, float z, float w, float h);
-extern void drawSpriteScreenspace(float x, float y, float z, float w, float h);
-extern void drawLine(float x1, float y1, float z1, float x2, float y2, float z2);
-extern void drawPoint(float x1, float y1, float z1);
-extern void drawSimpleMesh(int ism);
-extern void drawSimpleMeshRange(int ism, int start, int len);
+extern void rsgClearColor(float, float, float, float);
+extern void rsgClearDepth(float);
+///////////////////////////////////////////////////////
// misc
-extern void pfClearColor(float, float, float, float);
extern void color(float, float, float, float);
extern void hsb(float, float, float, float);
extern void hsbToRgb(float, float, float, float*);
extern int hsbToAbgr(float, float, float, float);
-extern void uploadToTexture(int, int);
-extern void uploadToBufferObject(int);
-
-extern int colorFloatRGBAtoUNorm8(float, float, float, float);
-extern int colorFloatRGBto565(float, float, float);
-
-extern int getWidth();
-extern int getHeight();
-
-extern int sendToClient(void *data, int cmdID, int len, int waitForSpace);
-
-extern void debugF(const char *, float);
-extern void debugI32(const char *, int);
-extern void debugHexI32(const char *, int);
-
-
+#endif
diff --git a/libs/rs/scriptc/rs_math.rsh b/libs/rs/scriptc/rs_math.rsh
index 613c7ca..a26491f 100644
--- a/libs/rs/scriptc/rs_math.rsh
+++ b/libs/rs/scriptc/rs_math.rsh
@@ -1,287 +1,87 @@
-// Float ops
-
-extern float __attribute__((overloadable)) abs(float);
-extern float2 __attribute__((overloadable)) abs(float2);
-extern float3 __attribute__((overloadable)) abs(float3);
-extern float4 __attribute__((overloadable)) abs(float4);
-extern float8 __attribute__((overloadable)) abs(float8);
-extern float16 __attribute__((overloadable)) abs(float16);
-
-extern float __attribute__((overloadable)) acos(float);
-extern float2 __attribute__((overloadable)) acos(float2);
-extern float3 __attribute__((overloadable)) acos(float3);
-extern float4 __attribute__((overloadable)) acos(float4);
-extern float8 __attribute__((overloadable)) acos(float8);
-extern float16 __attribute__((overloadable)) acos(float16);
-
-extern float __attribute__((overloadable)) asin(float);
-extern float2 __attribute__((overloadable)) asin(float2);
-extern float3 __attribute__((overloadable)) asin(float3);
-extern float4 __attribute__((overloadable)) asin(float4);
-extern float8 __attribute__((overloadable)) asin(float8);
-extern float16 __attribute__((overloadable)) asin(float16);
-
-extern float __attribute__((overloadable)) atan(float);
-extern float2 __attribute__((overloadable)) atan(float2);
-extern float3 __attribute__((overloadable)) atan(float3);
-extern float4 __attribute__((overloadable)) atan(float4);
-extern float8 __attribute__((overloadable)) atan(float8);
-extern float16 __attribute__((overloadable)) atan(float16);
-
-extern float __attribute__((overloadable)) atan2(float, float);
-extern float2 __attribute__((overloadable)) atan2(float2, float2);
-extern float3 __attribute__((overloadable)) atan2(float3, float3);
-extern float4 __attribute__((overloadable)) atan2(float4, float4);
-extern float8 __attribute__((overloadable)) atan2(float8, float8);
-extern float16 __attribute__((overloadable)) atan2(float16, float16);
-
-extern float __attribute__((overloadable)) ceil(float);
-extern float2 __attribute__((overloadable)) ceil(float2);
-extern float3 __attribute__((overloadable)) ceil(float3);
-extern float4 __attribute__((overloadable)) ceil(float4);
-extern float8 __attribute__((overloadable)) ceil(float8);
-extern float16 __attribute__((overloadable)) ceil(float16);
-
-extern float __attribute__((overloadable)) clamp(float, float, float);
-extern float2 __attribute__((overloadable)) clamp(float2, float2, float2);
-extern float3 __attribute__((overloadable)) clamp(float3, float3, float3);
-extern float4 __attribute__((overloadable)) clamp(float4, float4, float4);
-extern float8 __attribute__((overloadable)) clamp(float8, float8, float8);
-extern float16 __attribute__((overloadable)) clamp(float16, float16, float16);
-extern float __attribute__((overloadable)) clamp(float, float, float);
-extern float2 __attribute__((overloadable)) clamp(float2, float, float);
-extern float3 __attribute__((overloadable)) clamp(float3, float, float);
-extern float4 __attribute__((overloadable)) clamp(float4, float, float);
-extern float8 __attribute__((overloadable)) clamp(float8, float, float);
-extern float16 __attribute__((overloadable)) clamp(float16, float, float);
-
-extern float __attribute__((overloadable)) copysign(float, float);
-extern float2 __attribute__((overloadable)) copysign(float2, float2);
-extern float3 __attribute__((overloadable)) copysign(float3, float3);
-extern float4 __attribute__((overloadable)) copysign(float4, float4);
-extern float8 __attribute__((overloadable)) copysign(float8, float8);
-extern float16 __attribute__((overloadable)) copysign(float16, float16);
-
-extern float __attribute__((overloadable)) cos(float);
-extern float2 __attribute__((overloadable)) cos(float2);
-extern float3 __attribute__((overloadable)) cos(float3);
-extern float4 __attribute__((overloadable)) cos(float4);
-extern float8 __attribute__((overloadable)) cos(float8);
-extern float16 __attribute__((overloadable)) cos(float16);
-
-extern float __attribute__((overloadable)) degrees(float);
-extern float2 __attribute__((overloadable)) degrees(float2);
-extern float3 __attribute__((overloadable)) degrees(float3);
-extern float4 __attribute__((overloadable)) degrees(float4);
-extern float8 __attribute__((overloadable)) degrees(float8);
-extern float16 __attribute__((overloadable)) degrees(float16);
-
-extern float __attribute__((overloadable)) exp(float);
-extern float2 __attribute__((overloadable)) exp(float2);
-extern float3 __attribute__((overloadable)) exp(float3);
-extern float4 __attribute__((overloadable)) exp(float4);
-extern float8 __attribute__((overloadable)) exp(float8);
-extern float16 __attribute__((overloadable)) exp(float16);
-
-extern float __attribute__((overloadable)) exp2(float);
-extern float2 __attribute__((overloadable)) exp2(float2);
-extern float3 __attribute__((overloadable)) exp2(float3);
-extern float4 __attribute__((overloadable)) exp2(float4);
-extern float8 __attribute__((overloadable)) exp2(float8);
-extern float16 __attribute__((overloadable)) exp2(float16);
-
-extern float __attribute__((overloadable)) exp10(float);
-extern float2 __attribute__((overloadable)) exp10(float2);
-extern float3 __attribute__((overloadable)) exp10(float3);
-extern float4 __attribute__((overloadable)) exp10(float4);
-extern float8 __attribute__((overloadable)) exp10(float8);
-extern float16 __attribute__((overloadable)) exp10(float16);
-
-extern float __attribute__((overloadable)) fabs(float);
-extern float2 __attribute__((overloadable)) fabs(float2);
-extern float3 __attribute__((overloadable)) fabs(float3);
-extern float4 __attribute__((overloadable)) fabs(float4);
-extern float8 __attribute__((overloadable)) fabs(float8);
-extern float16 __attribute__((overloadable)) fabs(float16);
-
-extern float __attribute__((overloadable)) floor(float);
-extern float2 __attribute__((overloadable)) floor(float2);
-extern float3 __attribute__((overloadable)) floor(float3);
-extern float4 __attribute__((overloadable)) floor(float4);
-extern float8 __attribute__((overloadable)) floor(float8);
-extern float16 __attribute__((overloadable)) floor(float16);
-
-extern float __attribute__((overloadable)) fmax(float, float);
-extern float2 __attribute__((overloadable)) fmax(float2, float2);
-extern float3 __attribute__((overloadable)) fmax(float3, float3);
-extern float4 __attribute__((overloadable)) fmax(float4, float4);
-extern float8 __attribute__((overloadable)) fmax(float8, float8);
-extern float16 __attribute__((overloadable)) fmax(float16, float16);
-extern float2 __attribute__((overloadable)) fmax(float2, float);
-extern float3 __attribute__((overloadable)) fmax(float3, float);
-extern float4 __attribute__((overloadable)) fmax(float4, float);
-extern float8 __attribute__((overloadable)) fmax(float8, float);
-extern float16 __attribute__((overloadable)) fmax(float16, float);
-
-extern float __attribute__((overloadable)) fmin(float, float);
-extern float2 __attribute__((overloadable)) fmin(float2, float2);
-extern float3 __attribute__((overloadable)) fmin(float3, float3);
-extern float4 __attribute__((overloadable)) fmin(float4, float4);
-extern float8 __attribute__((overloadable)) fmin(float8, float8);
-extern float16 __attribute__((overloadable)) fmin(float16, float16);
-extern float2 __attribute__((overloadable)) fmin(float2, float);
-extern float3 __attribute__((overloadable)) fmin(float3, float);
-extern float4 __attribute__((overloadable)) fmin(float4, float);
-extern float8 __attribute__((overloadable)) fmin(float8, float);
-extern float16 __attribute__((overloadable)) fmin(float16, float);
-
-extern float __attribute__((overloadable)) fmod(float, float);
-extern float2 __attribute__((overloadable)) fmod(float2, float2);
-extern float3 __attribute__((overloadable)) fmod(float3, float3);
-extern float4 __attribute__((overloadable)) fmod(float4, float4);
-extern float8 __attribute__((overloadable)) fmod(float8, float8);
-extern float16 __attribute__((overloadable)) fmod(float16, float16);
-
-extern float __attribute__((overloadable)) log(float);
-extern float2 __attribute__((overloadable)) log(float2);
-extern float3 __attribute__((overloadable)) log(float3);
-extern float4 __attribute__((overloadable)) log(float4);
-extern float8 __attribute__((overloadable)) log(float8);
-extern float16 __attribute__((overloadable)) log(float16);
-
-extern float __attribute__((overloadable)) log2(float);
-extern float2 __attribute__((overloadable)) log2(float2);
-extern float3 __attribute__((overloadable)) log2(float3);
-extern float4 __attribute__((overloadable)) log2(float4);
-extern float8 __attribute__((overloadable)) log2(float8);
-extern float16 __attribute__((overloadable)) log2(float16);
-
-extern float __attribute__((overloadable)) log10(float);
-extern float2 __attribute__((overloadable)) log10(float2);
-extern float3 __attribute__((overloadable)) log10(float3);
-extern float4 __attribute__((overloadable)) log10(float4);
-extern float8 __attribute__((overloadable)) log10(float8);
-extern float16 __attribute__((overloadable)) log10(float16);
-
-extern float __attribute__((overloadable)) max(float, float);
-extern float2 __attribute__((overloadable)) max(float2, float2);
-extern float3 __attribute__((overloadable)) max(float3, float3);
-extern float4 __attribute__((overloadable)) max(float4, float4);
-extern float8 __attribute__((overloadable)) max(float8, float8);
-extern float16 __attribute__((overloadable)) max(float16, float16);
-
-extern float __attribute__((overloadable)) min(float, float);
-extern float2 __attribute__((overloadable)) min(float2, float2);
-extern float3 __attribute__((overloadable)) min(float3, float3);
-extern float4 __attribute__((overloadable)) min(float4, float4);
-extern float8 __attribute__((overloadable)) min(float8, float8);
-extern float16 __attribute__((overloadable)) min(float16, float16);
-
-extern float __attribute__((overloadable)) mix(float, float, float);
-extern float2 __attribute__((overloadable)) mix(float2, float2, float2);
-extern float3 __attribute__((overloadable)) mix(float3, float3, float3);
-extern float4 __attribute__((overloadable)) mix(float4, float4, float4);
-extern float8 __attribute__((overloadable)) mix(float8, float8, float8);
-extern float16 __attribute__((overloadable)) mix(float16, float16, float16);
-extern float __attribute__((overloadable)) mix(float, float, float);
-extern float2 __attribute__((overloadable)) mix(float2, float2, float);
-extern float3 __attribute__((overloadable)) mix(float3, float3, float);
-extern float4 __attribute__((overloadable)) mix(float4, float4, float);
-extern float8 __attribute__((overloadable)) mix(float8, float8, float);
-extern float16 __attribute__((overloadable)) mix(float16, float16, float);
-
-extern float __attribute__((overloadable)) pow(float, float);
-extern float2 __attribute__((overloadable)) pow(float2, float2);
-extern float3 __attribute__((overloadable)) pow(float3, float3);
-extern float4 __attribute__((overloadable)) pow(float4, float4);
-extern float8 __attribute__((overloadable)) pow(float8, float8);
-extern float16 __attribute__((overloadable)) pow(float16, float16);
-
-extern float __attribute__((overloadable)) radians(float);
-extern float2 __attribute__((overloadable)) radians(float2);
-extern float3 __attribute__((overloadable)) radians(float3);
-extern float4 __attribute__((overloadable)) radians(float4);
-extern float8 __attribute__((overloadable)) radians(float8);
-extern float16 __attribute__((overloadable)) radians(float16);
-
-extern float __attribute__((overloadable)) rint(float);
-extern float2 __attribute__((overloadable)) rint(float2);
-extern float3 __attribute__((overloadable)) rint(float3);
-extern float4 __attribute__((overloadable)) rint(float4);
-extern float8 __attribute__((overloadable)) rint(float8);
-extern float16 __attribute__((overloadable)) rint(float16);
-
-extern float __attribute__((overloadable)) round(float);
-extern float2 __attribute__((overloadable)) round(float2);
-extern float3 __attribute__((overloadable)) round(float3);
-extern float4 __attribute__((overloadable)) round(float4);
-extern float8 __attribute__((overloadable)) round(float8);
-extern float16 __attribute__((overloadable)) round(float16);
-
-extern float __attribute__((overloadable)) rsqrt(float);
-extern float2 __attribute__((overloadable)) rsqrt(float2);
-extern float3 __attribute__((overloadable)) rsqrt(float3);
-extern float4 __attribute__((overloadable)) rsqrt(float4);
-extern float8 __attribute__((overloadable)) rsqrt(float8);
-extern float16 __attribute__((overloadable)) rsqrt(float16);
-
-extern float __attribute__((overloadable)) sign(float);
-extern float2 __attribute__((overloadable)) sign(float2);
-extern float3 __attribute__((overloadable)) sign(float3);
-extern float4 __attribute__((overloadable)) sign(float4);
-extern float8 __attribute__((overloadable)) sign(float8);
-extern float16 __attribute__((overloadable)) sign(float16);
-
-extern float __attribute__((overloadable)) sin(float);
-extern float2 __attribute__((overloadable)) sin(float2);
-extern float3 __attribute__((overloadable)) sin(float3);
-extern float4 __attribute__((overloadable)) sin(float4);
-extern float8 __attribute__((overloadable)) sin(float8);
-extern float16 __attribute__((overloadable)) sin(float16);
-
-extern float __attribute__((overloadable)) sqrt(float);
-extern float2 __attribute__((overloadable)) sqrt(float2);
-extern float3 __attribute__((overloadable)) sqrt(float3);
-extern float4 __attribute__((overloadable)) sqrt(float4);
-extern float8 __attribute__((overloadable)) sqrt(float8);
-extern float16 __attribute__((overloadable)) sqrt(float16);
-
-extern float __attribute__((overloadable)) tan(float);
-extern float2 __attribute__((overloadable)) tan(float2);
-extern float3 __attribute__((overloadable)) tan(float3);
-extern float4 __attribute__((overloadable)) tan(float4);
-extern float8 __attribute__((overloadable)) tan(float8);
-extern float16 __attribute__((overloadable)) tan(float16);
-
-extern float __attribute__((overloadable)) trunc(float);
-extern float2 __attribute__((overloadable)) trunc(float2);
-extern float3 __attribute__((overloadable)) trunc(float3);
-extern float4 __attribute__((overloadable)) trunc(float4);
-extern float8 __attribute__((overloadable)) trunc(float8);
-extern float16 __attribute__((overloadable)) trunc(float16);
-
-
-
-
-
-
-// Int ops
-
-extern int __attribute__((overloadable)) abs(int);
-extern int2 __attribute__((overloadable)) abs(int2);
-extern int3 __attribute__((overloadable)) abs(int3);
-extern int4 __attribute__((overloadable)) abs(int4);
-extern int8 __attribute__((overloadable)) abs(int8);
-extern int16 __attribute__((overloadable)) abs(int16);
-
-
+#include "rs_cl.rsh"
+#include "rs_core.rsh"
+
+
+
+// Allocations
+extern rs_allocation rsGetAllocation(const void *);
+extern uint32_t rsAllocationGetDimX(rs_allocation);
+extern uint32_t rsAllocationGetDimY(rs_allocation);
+extern uint32_t rsAllocationGetDimZ(rs_allocation);
+extern uint32_t rsAllocationGetDimLOD(rs_allocation);
+extern uint32_t rsAllocationGetDimFaces(rs_allocation);
+
+
+
+// Debugging
+extern void __attribute__((overloadable))rsDebug(const char *, float);
+extern void __attribute__((overloadable))rsDebug(const char *, float2);
+extern void __attribute__((overloadable))rsDebug(const char *, float3);
+extern void __attribute__((overloadable))rsDebug(const char *, float4);
+extern void __attribute__((overloadable))rsDebug(const char *, int);
+extern void __attribute__((overloadable))rsDebug(const char *, const void *);
+#define RS_DEBUG(a) rsDebug(#a, a)
+#define RS_DEBUG_MARKER rsDebug(__FILE__, __LINE__)
+
+// RS Math
+extern int __attribute__((overloadable)) rsRand(int);
+extern int __attribute__((overloadable)) rsRand(int, int);
+extern float __attribute__((overloadable)) rsRand(float);
+extern float __attribute__((overloadable)) rsRand(float, float);
+
+extern float __attribute__((overloadable)) rsFrac(float);
+
+// time
+extern int32_t rsSecond();
+extern int32_t rsMinute();
+extern int32_t rsHour();
+extern int32_t rsDay();
+extern int32_t rsMonth();
+extern int32_t rsYear();
+extern int64_t rsUptimeMillis();
+extern int64_t rsStartTimeMillis();
+extern int64_t rsElapsedTimeMillis();
+
+extern int rsSendToClient(void *data, int cmdID, int len, int waitForSpace);
+
+extern void rsMatrixLoadIdentity(rs_matrix4x4 *mat);
+extern void rsMatrixLoadFloat(rs_matrix4x4 *mat, const float *f);
+extern void rsMatrixLoadMat(rs_matrix4x4 *mat, const rs_matrix4x4 *newmat);
+extern void rsMatrixLoadRotate(rs_matrix4x4 *mat, float rot, float x, float y, float z);
+extern void rsMatrixLoadScale(rs_matrix4x4*mat, float x, float y, float z);
+extern void rsMatrixLoadTranslate(rs_matrix4x4 *mat, float x, float y, float z);
+extern void rsMatrixLoadMultiply(rs_matrix4x4 *mat, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs);
+extern void rsMatrixMultiply(rs_matrix4x4 *mat, const rs_matrix4x4 *rhs);
+extern void rsMatrixRotate(rs_matrix4x4 *mat, float rot, float x, float y, float z);
+extern void rsMatrixScale(rs_matrix4x4 *mat, float x, float y, float z);
+extern void rsMatrixTranslate(rs_matrix4x4 *mat, float x, float y, float z);
+
+// Script to Script
+extern void __attribute__((overloadable))rsForEach(rs_script, rs_allocation input);
+extern void __attribute__((overloadable))rsForEach(rs_script, rs_allocation input, rs_allocation output);
+extern void __attribute__((overloadable))rsForEach(rs_script, rs_allocation input, int xStart, int xEnd);
+extern void __attribute__((overloadable))rsForEach(rs_script, rs_allocation input, rs_allocation output, int xStart, int xEnd);
+extern void __attribute__((overloadable))rsForEach(rs_script, rs_allocation input, int xStart, int yStart, int xEnd, int yEnd);
+extern void __attribute__((overloadable))rsForEach(rs_script, rs_allocation input, rs_allocation output, int xStart, int yStart, int xEnd, int yEnd);
+
+
+///////////////////////////////////////////////////////////////////
+// non update funcs
/*
-extern float modf(float, float);
-extern float randf(float);
-extern float randf2(float, float);
-extern float fracf(float);
-extern float lerpf(float, float, float);
-extern float mapf(float, float, float, float, float);
+extern float3 float3Norm(float3);
+extern float float3Length(float3);
+extern float3 float3Add(float3 lhs, float3 rhs);
+extern float3 float3Sub(float3 lhs, float3 rhs);
+extern float3 float3Cross(float3 lhs, float3 rhs);
+extern float float3Dot(float3 lhs, float3 rhs);
+extern float3 float3Scale(float3 v, float scale);
+
+extern float4 float4Add(float4 lhs, float4 rhs);
+extern float4 float4Sub(float4 lhs, float4 rhs);
+extern float4 float4Cross(float4 lhs, float4 rhs);
+extern float float4Dot(float4 lhs, float4 rhs);
+extern float4 float4Scale(float4 v, float scale);
*/
+
diff --git a/libs/rs/scriptc/rs_types.rsh b/libs/rs/scriptc/rs_types.rsh
index 4198a74..9984a1d 100644
--- a/libs/rs/scriptc/rs_types.rsh
+++ b/libs/rs/scriptc/rs_types.rsh
@@ -2,17 +2,17 @@
typedef char int8_t;
typedef short int16_t;
typedef int int32_t;
-//typedef long int64_t;
+typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
-//typedef long uint64_t;
+typedef unsigned long long uint64_t;
typedef uint8_t uchar;
typedef uint16_t ushort;
typedef uint32_t uint;
-//typedef uint64_t ulong;
+typedef uint64_t ulong;
typedef int rs_element;
typedef int rs_type;
@@ -28,44 +28,33 @@ typedef int rs_program_store;
typedef float float2 __attribute__((ext_vector_type(2)));
typedef float float3 __attribute__((ext_vector_type(3)));
typedef float float4 __attribute__((ext_vector_type(4)));
-typedef float float8 __attribute__((ext_vector_type(8)));
-typedef float float16 __attribute__((ext_vector_type(16)));
typedef uchar uchar2 __attribute__((ext_vector_type(2)));
typedef uchar uchar3 __attribute__((ext_vector_type(3)));
typedef uchar uchar4 __attribute__((ext_vector_type(4)));
-typedef uchar uchar8 __attribute__((ext_vector_type(8)));
-typedef uchar uchar16 __attribute__((ext_vector_type(16)));
typedef ushort ushort2 __attribute__((ext_vector_type(2)));
typedef ushort ushort3 __attribute__((ext_vector_type(3)));
typedef ushort ushort4 __attribute__((ext_vector_type(4)));
-typedef ushort ushort8 __attribute__((ext_vector_type(8)));
-typedef ushort ushort16 __attribute__((ext_vector_type(16)));
typedef uint uint2 __attribute__((ext_vector_type(2)));
typedef uint uint3 __attribute__((ext_vector_type(3)));
typedef uint uint4 __attribute__((ext_vector_type(4)));
-typedef uint uint8 __attribute__((ext_vector_type(8)));
-typedef uint uint16 __attribute__((ext_vector_type(16)));
typedef char char2 __attribute__((ext_vector_type(2)));
typedef char char3 __attribute__((ext_vector_type(3)));
typedef char char4 __attribute__((ext_vector_type(4)));
-typedef char char8 __attribute__((ext_vector_type(8)));
-typedef char char16 __attribute__((ext_vector_type(16)));
typedef short short2 __attribute__((ext_vector_type(2)));
typedef short short3 __attribute__((ext_vector_type(3)));
typedef short short4 __attribute__((ext_vector_type(4)));
-typedef short short8 __attribute__((ext_vector_type(8)));
-typedef short short16 __attribute__((ext_vector_type(16)));
typedef int int2 __attribute__((ext_vector_type(2)));
typedef int int3 __attribute__((ext_vector_type(3)));
typedef int int4 __attribute__((ext_vector_type(4)));
-typedef int int8 __attribute__((ext_vector_type(8)));
-typedef int int16 __attribute__((ext_vector_type(16)));
+typedef struct {
+ float m[16];
+} rs_matrix4x4;