summaryrefslogtreecommitdiffstats
path: root/libs/rs
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2009-06-16 12:38:55 -0700
committerMathias Agopian <mathias@google.com>2009-06-16 12:38:55 -0700
commit69f066c8fc42b9f0acc5c41f8ffd972f8d6d0584 (patch)
tree3a8bc941200fa85a32a21657ac69ec9beb9a6463 /libs/rs
parent151e859e0fc3a930bdf6d270d275e69e9eba0cbf (diff)
parentb0b160ae50497966666bcdcaf974eca2643acfd3 (diff)
downloadframeworks_base-69f066c8fc42b9f0acc5c41f8ffd972f8d6d0584.zip
frameworks_base-69f066c8fc42b9f0acc5c41f8ffd972f8d6d0584.tar.gz
frameworks_base-69f066c8fc42b9f0acc5c41f8ffd972f8d6d0584.tar.bz2
Merge commit 'goog/master' into merge_master
Diffstat (limited to 'libs/rs')
-rw-r--r--libs/rs/Android.mk74
-rw-r--r--libs/rs/java/Fountain/Android.mk8
-rw-r--r--libs/rs/java/Fountain/res/raw/fountain.c12
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/Fountain.java3
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java137
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/FountainView.java114
-rw-r--r--libs/rs/java/RenderScript/Android.mk28
-rw-r--r--libs/rs/java/RenderScript/android/renderscript/Matrix.java188
-rw-r--r--libs/rs/java/RenderScript/android/renderscript/ProgramVertexAlloc.java112
-rw-r--r--libs/rs/java/RenderScript/android/renderscript/RSSurfaceView.java (renamed from libs/rs/java/Fountain/src/com/android/fountain/RSSurfaceView.java)2
-rw-r--r--libs/rs/java/RenderScript/android/renderscript/RenderScript.java (renamed from libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java)129
-rw-r--r--libs/rs/java/Rollo/Android.mk25
-rw-r--r--libs/rs/java/Rollo/AndroidManifest.xml13
-rw-r--r--libs/rs/java/Rollo/res/raw/rollo.c13
-rw-r--r--libs/rs/java/Rollo/src/com/android/rollo/Rollo.java90
-rw-r--r--libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java65
-rw-r--r--libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java150
-rw-r--r--libs/rs/java/Rollo/src/com/android/rollo/RolloView.java82
-rw-r--r--libs/rs/jni/Android.mk36
-rw-r--r--libs/rs/jni/RenderScript_jni.cpp163
-rw-r--r--libs/rs/rs.spec21
-rw-r--r--libs/rs/rsContext.cpp104
-rw-r--r--libs/rs/rsContext.h13
-rw-r--r--libs/rs/rsObjectBase.cpp22
-rw-r--r--libs/rs/rsObjectBase.h32
-rw-r--r--libs/rs/rsProgramFragment.cpp8
-rw-r--r--libs/rs/rsProgramFragment.h2
-rw-r--r--libs/rs/rsProgramFragmentStore.cpp13
-rw-r--r--libs/rs/rsProgramFragmentStore.h2
-rw-r--r--libs/rs/rsProgramVertex.cpp9
-rw-r--r--libs/rs/rsProgramVertex.h1
-rw-r--r--libs/rs/rsScript.cpp11
-rw-r--r--libs/rs/rsScript.h23
-rw-r--r--libs/rs/rsScriptC.cpp154
-rw-r--r--libs/rs/rsScriptC.h25
-rw-r--r--libs/rs/rsTriangleMesh.h2
36 files changed, 1592 insertions, 294 deletions
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 6ff39a4..06c0595 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -1,11 +1,11 @@
# Only build if BUILD_RENDERSCRIPT is defined to true in the environment.
ifeq ($(BUILD_RENDERSCRIPT),true)
-TOP_LOCAL_PATH:=$(call my-dir)
-include $(CLEAR_VARS)
-LOCAL_PATH:= $(TOP_LOCAL_PATH)
+LOCAL_PATH:=$(call my-dir)
+
-# Build rsg-generator
+# Build rsg-generator ====================
+include $(CLEAR_VARS)
LOCAL_MODULE := rsg-generator
@@ -14,7 +14,7 @@ LOCAL_MODULE := rsg-generator
LOCAL_IS_HOST_MODULE := true
LOCAL_MODULE_CLASS := EXECUTABLES
-intermediates:= $(local-intermediates-dir)
+intermediates := $(local-intermediates-dir)
GEN := $(addprefix $(intermediates)/, \
lex.yy.c \
@@ -28,21 +28,21 @@ $(LOCAL_PATH)/rsg_generator.c : $(intermediates)/lex.yy.c
LOCAL_SRC_FILES:= \
rsg_generator.c
-
+
include $(BUILD_HOST_EXECUTABLE)
+# TODO: This should go into build/core/config.mk
RSG_GENERATOR:=$(LOCAL_BUILT_MODULE)
-# Build render script lib
+
+# Build render script lib ====================
include $(CLEAR_VARS)
LOCAL_MODULE := libRS
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
intermediates:= $(local-intermediates-dir)
-RS_GENERATED_INCLUDE_DIR:=$(intermediates)
-
# Generate custom headers
GEN := $(addprefix $(intermediates)/, \
@@ -50,12 +50,14 @@ GEN := $(addprefix $(intermediates)/, \
rsgApiFuncDecl.h \
)
-$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(TOP_LOCAL_PATH)/rs.spec
+$(GEN) : PRIVATE_PATH := $(LOCAL_PATH)
+$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(PRIVATE_PATH)/rs.spec
$(GEN) : $(RSG_GENERATOR) $(LOCAL_PATH)/rs.spec
$(GEN): $(intermediates)/%.h : $(LOCAL_PATH)/%.h.rsg
$(transform-generated-source)
-RS_GENERATED_SOURCES += $(GEN)
+# used in jni/Android.mk
+rs_generated_source += $(GEN)
LOCAL_GENERATED_SOURCES += $(GEN)
# Generate custom source files
@@ -65,12 +67,15 @@ GEN := $(addprefix $(intermediates)/, \
rsgApiReplay.cpp \
)
-$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(TOP_LOCAL_PATH)/rs.spec
+$(GEN) : PRIVATE_PATH := $(LOCAL_PATH)
+$(GEN) : PRIVATE_CUSTOM_TOOL = $(RSG_GENERATOR) $< $@ <$(PRIVATE_PATH)/rs.spec
$(GEN) : $(RSG_GENERATOR) $(LOCAL_PATH)/rs.spec
$(GEN): $(intermediates)/%.cpp : $(LOCAL_PATH)/%.cpp.rsg
$(transform-generated-source)
-RS_GENERATED_SOURCES += $(GEN)
+# used in jni/Android.mk
+rs_generated_source += $(GEN)
+
LOCAL_GENERATED_SOURCES += $(GEN)
LOCAL_SRC_FILES:= \
@@ -99,45 +104,14 @@ LOCAL_LDLIBS := -lpthread -ldl
LOCAL_MODULE:= libRS
LOCAL_PRELINK_MODULE := false
-#LOCAL_MODULE_TAGS := tests
+LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
-# Build JNI library
-
-LOCAL_PATH:= $(TOP_LOCAL_PATH)/jni
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- RenderScript_jni.cpp
-
-LOCAL_SHARED_LIBRARIES := \
- libandroid_runtime \
- libacc \
- libnativehelper \
- libRS \
- libcutils \
- libsgl \
- libutils \
- libui
-
-LOCAL_STATIC_LIBRARIES :=
-
-LOCAL_C_INCLUDES += \
- $(JNI_H_INCLUDE) \
- $(RS_GENERATED_INCLUDE_DIR) \
- $(call include-path-for, corecg graphics)
-
-LOCAL_CFLAGS +=
-
-LOCAL_LDLIBS := -lpthread
-
-LOCAL_MODULE:= libRS_jni
-LOCAL_PRELINK_MODULE := false
-
-LOCAL_ADDITIONAL_DEPENDENCIES += $(RS_GENERATED_SOURCES)
-
-include $(BUILD_SHARED_LIBRARY)
+# Include the subdirectories ====================
+include $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk,\
+ jni \
+ java \
+ ))
-include $(call all-subdir-makefiles)
endif # BUILD_RENDERSCRIPT
diff --git a/libs/rs/java/Fountain/Android.mk b/libs/rs/java/Fountain/Android.mk
index cf08467..af3d5fc 100644
--- a/libs/rs/java/Fountain/Android.mk
+++ b/libs/rs/java/Fountain/Android.mk
@@ -18,14 +18,8 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
LOCAL_PACKAGE_NAME := Fountain
include $(BUILD_PACKAGE)
-##################################################
-include $(CLEAR_VARS)
-
-include $(BUILD_MULTI_PREBUILT)
-
-# Use the folloing include to make our test apk.
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
index 8b473ab..3bd9496 100644
--- a/libs/rs/java/Fountain/res/raw/fountain.c
+++ b/libs/rs/java/Fountain/res/raw/fountain.c
@@ -1,5 +1,12 @@
// Fountain test script
+#pragma version(1)
+#pragma stateVertex(orthoWindow)
+#pragma stateRaster(flat)
+#pragma stateFragment(PgmFragBackground)
+#pragma stateFragmentStore(MyBlend)
+
+
int main(void* con, int ft, int launchID) {
int count, touch, x, y, rate, maxLife, lifeShift;
int life;
@@ -28,9 +35,8 @@ int main(void* con, int ft, int launchID) {
}
}
- contextBindProgramFragment(con, loadI32(con, 0, 7));
drawRect(con, 0, 256, 0, 512);
- contextBindProgramFragment(con, loadI32(con, 0, 6));
+ contextBindProgramFragment(con, NAMED_PgmFragParts);
if (touch) {
newPart = loadI32(con, 2, 0);
@@ -99,6 +105,6 @@ int main(void* con, int ft, int launchID) {
}
}
- drawTriangleArray(con, loadI32(con, 0, 5), drawCount);
+ drawTriangleArray(con, NAMED_PartBuffer, drawCount);
return 1;
}
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java b/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java
index 0d66966..58c78fa 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java
@@ -16,6 +16,9 @@
package com.android.fountain;
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScript;
+
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
new file mode 100644
index 0000000..0a0b05a
--- /dev/null
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -0,0 +1,137 @@
+/*
+ * 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.fountain;
+
+import java.io.Writer;
+
+import android.renderscript.RenderScript;
+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.util.Log;
+
+public class FountainRS {
+
+ public FountainRS() {
+ }
+
+ public void init(RenderScript rs, Resources res, int width, int height) {
+ mRS = rs;
+ mRes = res;
+ initRS();
+ }
+
+ public void newTouchPosition(int x, int y) {
+ mParams[0] = 1;
+ mParams[1] = x;
+ mParams[2] = y;
+ mIntAlloc.subData1D(2, 3, mParams);
+ }
+
+
+ /////////////////////////////////////////
+
+ private Resources mRes;
+
+ private RenderScript mRS;
+ private RenderScript.Allocation mIntAlloc;
+ private RenderScript.Allocation mPartAlloc;
+ private RenderScript.Allocation mVertAlloc;
+ private RenderScript.Script mScript;
+ private RenderScript.ProgramFragmentStore mPFS;
+ private RenderScript.ProgramFragment mPF;
+ private RenderScript.ProgramFragment mPF2;
+ private RenderScript.Allocation mTexture;
+ private RenderScript.Sampler mSampler;
+
+ private Bitmap mBackground;
+
+ int mParams[] = new int[10];
+
+ private void initRS() {
+ int partCount = 1024;
+
+ mIntAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, 10);
+ mPartAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 3 * 3);
+ mPartAlloc.setName("PartBuffer");
+ mVertAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 5 + 1);
+
+ {
+ Drawable d = mRes.getDrawable(R.drawable.gadgets_clock_mp3);
+ BitmapDrawable bd = (BitmapDrawable)d;
+ Bitmap b = bd.getBitmap();
+ mTexture = mRS.allocationCreateFromBitmap(b,
+ RenderScript.ElementPredefined.RGB_565,
+ true);
+ mTexture.uploadToTexture(0);
+ }
+
+ mRS.programFragmentStoreBegin(null, null);
+ mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA, RenderScript.BlendDstFunc.ONE);
+ mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
+ mPFS = mRS.programFragmentStoreCreate();
+ mPFS.setName("MyBlend");
+ mRS.contextBindProgramFragmentStore(mPFS);
+
+ mRS.samplerBegin();
+ mRS.samplerSet(RenderScript.SamplerParam.FILTER_MAG, RenderScript.SamplerValue.LINEAR);
+ mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN, RenderScript.SamplerValue.LINEAR);
+ mSampler = mRS.samplerCreate();
+
+
+ mRS.programFragmentBegin(null, null);
+ mPF = mRS.programFragmentCreate();
+ mPF.setName("PgmFragParts");
+
+ mRS.programFragmentBegin(null, null);
+ mRS.programFragmentSetTexEnable(0, true);
+ mPF2 = mRS.programFragmentCreate();
+ mRS.contextBindProgramFragment(mPF2);
+ mPF2.bindTexture(mTexture, 0);
+ mPF2.bindSampler(mSampler, 0);
+ mPF2.setName("PgmFragBackground");
+
+ mParams[0] = 0;
+ mParams[1] = partCount;
+ mParams[2] = 0;
+ mParams[3] = 0;
+ mParams[4] = 0;
+ mIntAlloc.data(mParams);
+
+ int t2[] = new int[partCount * 4*3];
+ for (int ct=0; ct < t2.length; ct++) {
+ t2[ct] = 0;
+ }
+ mPartAlloc.data(t2);
+
+ mRS.scriptCBegin();
+ mRS.scriptCSetClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ mRS.scriptCSetScript(mRes, R.raw.fountain);
+ mRS.scriptCSetRoot(true);
+ mScript = mRS.scriptCCreate();
+
+ mScript.bindAllocation(mIntAlloc, 0);
+ mScript.bindAllocation(mPartAlloc, 1);
+ mScript.bindAllocation(mVertAlloc, 2);
+ mRS.contextBindRootScript(mScript);
+ }
+
+}
+
+
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
index 3381525..be8b24e 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
@@ -20,6 +20,9 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.concurrent.Semaphore;
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScript;
+
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -44,125 +47,26 @@ public class FountainView extends RSSurfaceView {
}
private RenderScript mRS;
- private RenderScript.Allocation mIntAlloc;
- private RenderScript.Allocation mPartAlloc;
- private RenderScript.Allocation mVertAlloc;
- private RenderScript.Script mScript;
- private RenderScript.ProgramFragmentStore mPFS;
- private RenderScript.ProgramFragment mPF;
- private RenderScript.ProgramFragment mPF2;
- private RenderScript.Allocation mTexture;
- private RenderScript.Sampler mSampler;
-
- private Bitmap mBackground;
-
- int mParams[] = new int[10];
-
- private void initRS() {
- mRS = createRenderScript();
-
- int partCount = 1024;
-
- mIntAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, 10);
- mPartAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 3 * 3);
- mVertAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 5 + 1);
-
- {
- Resources res = getResources();
- Drawable d = res.getDrawable(R.drawable.gadgets_clock_mp3);
- BitmapDrawable bd = (BitmapDrawable)d;
- Bitmap b = bd.getBitmap();
- mTexture = mRS.allocationCreateFromBitmap(b,
- RenderScript.ElementPredefined.RGB_565,
- true);
- mTexture.uploadToTexture(0);
- }
-
- mRS.programFragmentStoreBegin(null, null);
- mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA, RenderScript.BlendDstFunc.ONE);
- mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
- mPFS = mRS.programFragmentStoreCreate();
- mRS.contextBindProgramFragmentStore(mPFS);
-
- mRS.samplerBegin();
- mRS.samplerSet(RenderScript.SamplerParam.FILTER_MAG, RenderScript.SamplerValue.LINEAR);
- mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN, RenderScript.SamplerValue.LINEAR);
- mSampler = mRS.samplerCreate();
-
-
- mRS.programFragmentBegin(null, null);
- mPF = mRS.programFragmentCreate();
- //mRS.contextBindProgramFragment(mPF);
-
- mRS.programFragmentBegin(null, null);
- mRS.programFragmentSetTexEnable(0, true);
- mPF2 = mRS.programFragmentCreate();
- mRS.contextBindProgramFragment(mPF2);
- mPF2.bindTexture(mTexture, 0);
- mPF2.bindSampler(mSampler, 0);
-
- mParams[0] = 0;
- mParams[1] = partCount;
- mParams[2] = 0;
- mParams[3] = 0;
- mParams[4] = 0;
- mParams[5] = mPartAlloc.mID;
- mParams[6] = mPF.mID;
- mParams[7] = mPF2.mID;
- mIntAlloc.data(mParams);
-
- int t2[] = new int[partCount * 4*3];
- for (int ct=0; ct < t2.length; ct++) {
- t2[ct] = 0;
- }
- mPartAlloc.data(t2);
-
- mRS.scriptCBegin();
- mRS.scriptCSetClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- mRS.scriptCSetScript(getResources(), R.raw.fountain);
- mRS.scriptCSetRoot(true);
- mScript = mRS.scriptCCreate();
-
- mScript.bindAllocation(mIntAlloc, 0);
- mScript.bindAllocation(mPartAlloc, 1);
- mScript.bindAllocation(mVertAlloc, 2);
- mRS.contextBindRootScript(mScript);
-
- }
+ private FountainRS mRender;
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
- initRS();
- }
-
- @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);
+ mRS = createRenderScript();
+ mRender = new FountainRS();
+ mRender.init(mRS, getResources(), w, h);
}
- int mTouchAction;
@Override
public boolean onTouchEvent(MotionEvent ev)
{
- //Log.e("FountainView", ev.toString());
boolean ret = true;
int act = ev.getAction();
- mParams[1] = (int)ev.getX();
- mParams[2] = (int)ev.getY();
-
- if (act == ev.ACTION_DOWN) {
- mParams[0] = 1;
- } else if (act == ev.ACTION_UP) {
- //mParams[0] = 0;
+ if (act == ev.ACTION_UP) {
ret = false;
}
- mIntAlloc.subData1D(2, 3, mParams);
-
+ mRender.newTouchPosition((int)ev.getX(), (int)ev.getY());
return ret;
}
}
diff --git a/libs/rs/java/RenderScript/Android.mk b/libs/rs/java/RenderScript/Android.mk
new file mode 100644
index 0000000..616fbd2
--- /dev/null
+++ b/libs/rs/java/RenderScript/Android.mk
@@ -0,0 +1,28 @@
+#
+# Copyright (C) 2008 Esmertec AG.
+# 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)
+
+# the library
+# ============================================================
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ $(call all-subdir-java-files)
+
+LOCAL_MODULE:= android.renderscript
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/libs/rs/java/RenderScript/android/renderscript/Matrix.java b/libs/rs/java/RenderScript/android/renderscript/Matrix.java
new file mode 100644
index 0000000..03222aa
--- /dev/null
+++ b/libs/rs/java/RenderScript/android/renderscript/Matrix.java
@@ -0,0 +1,188 @@
+/*
+ * 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.
+ */
+
+package android.renderscript;
+
+import java.lang.Math;
+import android.util.Log;
+
+
+class Matrix {
+
+ public Matrix() {
+ mMat = new float[16];
+ loadIdentity();
+ }
+
+ public float get(int i, int j) {
+ return mMat[i*4 + j];
+ }
+
+ public void set(int i, int j, float v) {
+ mMat[i*4 + j] = v;
+ }
+
+ public void loadIdentity() {
+ mMat[0] = 1;
+ mMat[1] = 0;
+ mMat[2] = 0;
+ mMat[3] = 0;
+
+ mMat[4] = 0;
+ mMat[5] = 1;
+ mMat[6] = 0;
+ mMat[7] = 0;
+
+ mMat[8] = 0;
+ mMat[9] = 0;
+ mMat[10] = 1;
+ mMat[11] = 0;
+
+ mMat[12] = 0;
+ mMat[13] = 0;
+ mMat[14] = 0;
+ mMat[15] = 1;
+ }
+
+ public void load(Matrix src) {
+ mMat = src.mMat;
+ }
+
+ public void loadRotate(float rot, float x, float y, float z) {
+ float c, s;
+ mMat[3] = 0;
+ mMat[7] = 0;
+ mMat[11]= 0;
+ mMat[12]= 0;
+ mMat[13]= 0;
+ mMat[14]= 0;
+ mMat[15]= 1;
+ rot *= (float)(java.lang.Math.PI / 180.0f);
+ c = (float)java.lang.Math.cos(rot);
+ s = (float)java.lang.Math.sin(rot);
+
+ float len = (float)java.lang.Math.sqrt(x*x + y*y + z*z);
+ if (!(len != 1)) {
+ float recipLen = 1.f / len;
+ x *= recipLen;
+ y *= recipLen;
+ z *= recipLen;
+ }
+ float nc = 1.0f - c;
+ float xy = x * y;
+ float yz = y * z;
+ float zx = z * x;
+ float xs = x * s;
+ float ys = y * s;
+ float zs = z * s;
+ mMat[ 0] = x*x*nc + c;
+ mMat[ 4] = xy*nc - zs;
+ mMat[ 8] = zx*nc + ys;
+ mMat[ 1] = xy*nc + zs;
+ mMat[ 5] = y*y*nc + c;
+ mMat[ 9] = yz*nc - xs;
+ mMat[ 2] = zx*nc - ys;
+ mMat[ 6] = yz*nc + xs;
+ mMat[10] = z*z*nc + c;
+ }
+
+ public void loadScale(float x, float y, float z) {
+ loadIdentity();
+ mMat[0] = x;
+ mMat[5] = y;
+ mMat[10] = z;
+ }
+
+ public void loadTranslate(float x, float y, float z) {
+ loadIdentity();
+ mMat[12] = x;
+ mMat[13] = y;
+ mMat[14] = z;
+ }
+
+ public void loadMultiply(Matrix lhs, Matrix rhs) {
+ for (int i=0 ; i<4 ; i++) {
+ float ri0 = 0;
+ float ri1 = 0;
+ float ri2 = 0;
+ float ri3 = 0;
+ for (int j=0 ; j<4 ; j++) {
+ float rhs_ij = rhs.get(i,j);
+ ri0 += lhs.get(j,0) * rhs_ij;
+ ri1 += lhs.get(j,1) * rhs_ij;
+ ri2 += lhs.get(j,2) * rhs_ij;
+ ri3 += lhs.get(j,3) * rhs_ij;
+ }
+ set(i,0, ri0);
+ set(i,1, ri1);
+ set(i,2, ri2);
+ set(i,3, ri3);
+ }
+ }
+
+ public void loadOrtho(float l, float r, float b, float t, float n, float f) {
+ loadIdentity();
+ mMat[0] = 2 / (r - l);
+ mMat[5] = 2 / (t - b);
+ mMat[10]= -2 / (f - n);
+ mMat[12]= -(r + l) / (r - l);
+ mMat[12]= -(t + b) / (t - b);
+ mMat[12]= -(f + n) / (f - n);
+ }
+
+ public void loadFrustum(float l, float r, float b, float t, float n, float f) {
+ loadIdentity();
+ mMat[0] = 2 * n / (r - l);
+ mMat[5] = 2 * n / (t - b);
+ mMat[8] = (r + l) / (r - l);
+ mMat[9] = (t + b) / (t - b);
+ mMat[10]= -(f + n) / (f - n);
+ mMat[11]= -1;
+ mMat[14]= -2*f*n / (f - n);
+ mMat[15]= 0;
+ }
+
+ public void multiply(Matrix rhs) {
+ Matrix tmp = new Matrix();
+ tmp.loadMultiply(this, rhs);
+ load(tmp);
+ }
+ public void rotate(float rot, float x, float y, float z) {
+ Matrix tmp = new Matrix();
+ tmp.loadRotate(rot, x, y, z);
+ multiply(tmp);
+ }
+ public void scale(float x, float y, float z) {
+ Matrix tmp = new Matrix();
+ tmp.loadScale(x, y, z);
+ multiply(tmp);
+ }
+ public void translate(float x, float y, float z) {
+ Matrix tmp = new Matrix();
+ tmp.loadTranslate(x, y, z);
+ multiply(tmp);
+ }
+
+
+
+ float[] mMat;
+
+}
+
+
+
+
+
diff --git a/libs/rs/java/RenderScript/android/renderscript/ProgramVertexAlloc.java b/libs/rs/java/RenderScript/android/renderscript/ProgramVertexAlloc.java
new file mode 100644
index 0000000..020ddb2
--- /dev/null
+++ b/libs/rs/java/RenderScript/android/renderscript/ProgramVertexAlloc.java
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+
+package android.renderscript;
+
+import java.lang.Math;
+import android.util.Log;
+
+
+public class ProgramVertexAlloc {
+ public static final int MODELVIEW_OFFSET = 0;
+ public static final int PROJECTION_OFFSET = 16;
+ public static final int TEXTURE_OFFSET = 32;
+
+ Matrix mModel;
+ Matrix mProjection;
+ Matrix mTexture;
+
+ public RenderScript.Allocation mAlloc;
+
+ public ProgramVertexAlloc(RenderScript rs) {
+ mModel = new Matrix();
+ mProjection = new Matrix();
+ mTexture = new Matrix();
+
+ mAlloc = rs.allocationCreatePredefSized(
+ RenderScript.ElementPredefined.USER_FLOAT,
+ 48);
+
+ mAlloc.subData1D(MODELVIEW_OFFSET, 16, mModel.mMat);
+ mAlloc.subData1D(PROJECTION_OFFSET, 16, mProjection.mMat);
+ mAlloc.subData1D(TEXTURE_OFFSET, 16, mTexture.mMat);
+ }
+
+ public void loadModelview(Matrix m) {
+ mModel = m;
+ mAlloc.subData1D(MODELVIEW_OFFSET, 16, m.mMat);
+ }
+
+ public void loadProjection(Matrix m) {
+ mProjection = m;
+ mAlloc.subData1D(PROJECTION_OFFSET, 16, m.mMat);
+ }
+
+ public void loadTexture(Matrix m) {
+ mTexture = m;
+ mAlloc.subData1D(TEXTURE_OFFSET, 16, m.mMat);
+ }
+
+ public void setupOrthoWindow(int w, int h) {
+ mProjection.loadOrtho(0,w, h,0, -1,1);
+ mAlloc.subData1D(PROJECTION_OFFSET, 16, mProjection.mMat);
+ }
+
+ public void setupOrthoNormalized(int w, int h) {
+ // range -1,1 in the narrow axis.
+ if(w > h) {
+ float aspect = ((float)w) / h;
+ mProjection.loadOrtho(-aspect,aspect, -1,1, -1,1);
+ } else {
+ float aspect = ((float)h) / w;
+ mProjection.loadOrtho(-1,1, -aspect,aspect, -1,1);
+ }
+ mAlloc.subData1D(PROJECTION_OFFSET, 16, mProjection.mMat);
+ }
+
+ public void setupProjectionNormalized(int w, int h) {
+ // range -1,1 in the narrow axis at z = 0.
+ Matrix m1 = new Matrix();
+ Matrix m2 = new Matrix();
+
+ if(w > h) {
+ float aspect = ((float)w) / h;
+ m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
+ } else {
+ float aspect = ((float)h) / w;
+ m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
+ }
+
+ m2.loadRotate(180, 0, 1, 0);
+ m1.loadMultiply(m1, m2);
+
+ m2.loadScale(-2, 2, 1);
+ m1.loadMultiply(m1, m2);
+
+ m2.loadTranslate(0, 0, 2);
+ m1.loadMultiply(m1, m2);
+
+ mProjection = m1;
+ mAlloc.subData1D(PROJECTION_OFFSET, 16, mProjection.mMat);
+ }
+
+}
+
+
+
+
+
+
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/RSSurfaceView.java b/libs/rs/java/RenderScript/android/renderscript/RSSurfaceView.java
index a8b3bca..3d37c13 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/RSSurfaceView.java
+++ b/libs/rs/java/RenderScript/android/renderscript/RSSurfaceView.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.fountain;
+package android.renderscript;
import java.io.Writer;
import java.util.ArrayList;
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java b/libs/rs/java/RenderScript/android/renderscript/RenderScript.java
index 796fe35..afb4ae3 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/RenderScript.java
+++ b/libs/rs/java/RenderScript/android/renderscript/RenderScript.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.fountain;
+package android.renderscript;
import java.io.InputStream;
import java.io.IOException;
@@ -67,6 +67,9 @@ public class RenderScript {
native private void nContextBindSampler(int sampler, int slot);
native private void nContextBindProgramFragmentStore(int pfs);
native private void nContextBindProgramFragment(int pf);
+ native private void nContextBindProgramVertex(int pf);
+
+ native private void nAssignName(int obj, byte[] name);
native private void nElementBegin();
native private void nElementAddPredefined(int predef);
@@ -100,6 +103,7 @@ public class RenderScript {
native private void nTriangleMeshAddVertex_XYZ (float x, float y, float z);
native private void nTriangleMeshAddVertex_XY_ST (float x, float y, float s, float t);
native private void nTriangleMeshAddVertex_XYZ_ST (float x, float y, float z, float s, float t);
+ native private void nTriangleMeshAddVertex_XYZ_ST_NORM (float x, float y, float z, float s, float t, float nx, float ny, float nz);
native private void nTriangleMeshAddTriangle(int i1, int i2, int i3);
native private int nTriangleMeshCreate();
@@ -135,6 +139,7 @@ public class RenderScript {
native private void nProgramFragmentStoreBlendFunc(int src, int dst);
native private void nProgramFragmentStoreDither(boolean enable);
native private int nProgramFragmentStoreCreate();
+ native private void nProgramFragmentStoreDestroy(int pgm);
native private void nProgramFragmentBegin(int in, int out);
native private void nProgramFragmentBindTexture(int vpf, int slot, int a);
@@ -143,6 +148,17 @@ public class RenderScript {
native private void nProgramFragmentSetEnvMode(int slot, int env);
native private void nProgramFragmentSetTexEnable(int slot, boolean enable);
native private int nProgramFragmentCreate();
+ native private void nProgramFragmentDestroy(int pgm);
+
+ native private void nProgramVertexDestroy(int pv);
+ native private void nProgramVertexBindAllocation(int pv, int slot, int mID);
+ native private void nProgramVertexBegin(int inID, int outID);
+ native private void nProgramVertexSetType(int slot, int mID);
+ native private void nProgramVertexSetCameraMode(boolean isOrtho);
+ native private void nProgramVertexSetTextureMatrixEnable(boolean enable);
+ native private void nProgramVertexSetModelMatrixEnable(boolean enable);
+ native private void nProgramVertexSetProjectionMatrixEnable(boolean enable);
+ native private int nProgramVertexCreate();
private int mDev;
@@ -165,7 +181,31 @@ public class RenderScript {
mID = 0;
}
+ public int getID() {
+ return mID;
+ }
+
int mID;
+ String mName;
+
+ public void setName(String s) throws IllegalStateException, IllegalArgumentException
+ {
+ if(s.length() < 1) {
+ throw new IllegalArgumentException("setName does not accept a zero length string.");
+ }
+ if(mName != null) {
+ throw new IllegalArgumentException("setName object already has a name.");
+ }
+
+ try {
+ byte[] bytes = s.getBytes("UTF-8");
+ nAssignName(mID, bytes);
+ mName = s;
+ } catch (java.io.UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
protected void finalize() throws Throwable
{
if (mID != 0) {
@@ -191,17 +231,19 @@ public class RenderScript {
A_8 (7),
RGB_565 (8),
- RGB_888 (12),
+ RGB_888 (11),
RGBA_5551 (9),
RGBA_4444 (10),
- RGBA_8888 (13),
+ RGBA_8888 (12),
- INDEX_16 (16),
- INDEX_32 (17),
- XY_F32 (18),
- XYZ_F32 (19),
- ST_XY_F32 (20),
- ST_XYZ_F32 (21);
+ INDEX_16 (13),
+ INDEX_32 (14),
+ XY_F32 (15),
+ XYZ_F32 (16),
+ ST_XY_F32 (17),
+ ST_XYZ_F32 (18),
+ NORM_XYZ_F32 (19),
+ NORM_ST_XYZ_F32 (20);
int mID;
ElementPredefined(int id) {
@@ -554,6 +596,10 @@ public class RenderScript {
nTriangleMeshAddVertex_XYZ_ST(x, y, z, s, t);
}
+ public void triangleMeshAddVertex_XYZ_ST_NORM(float x, float y, float z, float s, float t, float nx, float ny, float nz) {
+ nTriangleMeshAddVertex_XYZ_ST_NORM(x, y, z, s, t, nx, ny, nz);
+ }
+
public void triangleMeshAddTriangle(int i1, int i2, int i3) {
nTriangleMeshAddTriangle(i1, i2, i3);
}
@@ -653,6 +699,63 @@ public class RenderScript {
}
//////////////////////////////////////////////////////////////////////////////////
+ // ProgramVertex
+
+ public class ProgramVertex extends BaseObj {
+ ProgramVertex(int id) {
+ mID = id;
+ }
+
+ public void destroy() {
+ nProgramVertexDestroy(mID);
+ mID = 0;
+ }
+
+ public void bindAllocation(int slot, Allocation va) {
+ nProgramVertexBindAllocation(mID, slot, va.mID);
+ }
+
+ }
+
+ public void programVertexBegin(Element in, Element out) {
+ int inID = 0;
+ int outID = 0;
+ if (in != null) {
+ inID = in.mID;
+ }
+ if (out != null) {
+ outID = out.mID;
+ }
+ nProgramVertexBegin(inID, outID);
+ }
+
+ public void programVertexSetType(int slot, Type t) {
+ nProgramVertexSetType(slot, t.mID);
+ }
+
+ public void programVertexSetCameraMode(boolean isOrtho) {
+ nProgramVertexSetCameraMode(isOrtho);
+ }
+
+ public void programVertexSetTextureMatrixEnable(boolean enable) {
+ nProgramVertexSetTextureMatrixEnable(enable);
+ }
+
+ public void programVertexSetModelMatrixEnable(boolean enable) {
+ nProgramVertexSetModelMatrixEnable(enable);
+ }
+
+ public void programVertexSetProjectionMatrixEnable(boolean enable) {
+ nProgramVertexSetProjectionMatrixEnable(enable);
+ }
+
+ public ProgramVertex programVertexCreate() {
+ int id = nProgramVertexCreate();
+ return new ProgramVertex(id);
+ }
+
+
+ //////////////////////////////////////////////////////////////////////////////////
// ProgramFragmentStore
public class ProgramFragmentStore extends BaseObj {
@@ -661,7 +764,7 @@ public class RenderScript {
}
public void destroy() {
- nScriptDestroy(mID);
+ nProgramFragmentStoreDestroy(mID);
mID = 0;
}
}
@@ -712,7 +815,7 @@ public class RenderScript {
}
public void destroy() {
- nScriptDestroy(mID);
+ nProgramFragmentDestroy(mID);
mID = 0;
}
@@ -801,6 +904,10 @@ public class RenderScript {
nContextBindProgramFragment(pf.mID);
}
+ public void contextBindProgramVertex(ProgramVertex pf) {
+ nContextBindProgramVertex(pf.mID);
+ }
+
/*
RsAdapter2D rsAdapter2DCreate ();
void rsAdapter2DBindAllocation (RsAdapter2D adapt, RsAllocation alloc);
diff --git a/libs/rs/java/Rollo/Android.mk b/libs/rs/java/Rollo/Android.mk
new file mode 100644
index 0000000..1c6dfdf
--- /dev/null
+++ b/libs/rs/java/Rollo/Android.mk
@@ -0,0 +1,25 @@
+#
+# 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_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript
+
+LOCAL_PACKAGE_NAME := Rollo
+
+include $(BUILD_PACKAGE)
diff --git a/libs/rs/java/Rollo/AndroidManifest.xml b/libs/rs/java/Rollo/AndroidManifest.xml
new file mode 100644
index 0000000..da160a3
--- /dev/null
+++ b/libs/rs/java/Rollo/AndroidManifest.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.rollo">
+ <application android:label="Rollo">
+ <activity android:name="Rollo"
+ 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/Rollo/res/raw/rollo.c b/libs/rs/java/Rollo/res/raw/rollo.c
new file mode 100644
index 0000000..b81c567
--- /dev/null
+++ b/libs/rs/java/Rollo/res/raw/rollo.c
@@ -0,0 +1,13 @@
+#pragma version(1)
+#pragma stateVertex(PV)
+#pragma stateFragment(PF)
+#pragma stateFragmentStore(PFSBackground)
+
+int main(void* con, int ft, int launchID)
+{
+ int x;
+
+ renderTriangleMesh(con, NAMED_MeshCard);
+ return 1;
+}
+
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/Rollo.java b/libs/rs/java/Rollo/src/com/android/rollo/Rollo.java
new file mode 100644
index 0000000..400d801
--- /dev/null
+++ b/libs/rs/java/Rollo/src/com/android/rollo/Rollo.java
@@ -0,0 +1,90 @@
+/*
+ * 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.rollo;
+
+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 Rollo extends Activity {
+ //EventListener mListener = new EventListener();
+
+ private static final String LOG_TAG = "libRS_jni";
+ private static final boolean DEBUG = false;
+ private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
+
+ private RolloView mView;
+
+ // get the current looper (from your Activity UI thread for instance
+
+
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ // Create our Preview view and set it as the content of our
+ // Activity
+ mView = new RolloView(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();
+
+ Runtime.getRuntime().exit(0);
+ }
+
+
+ static void log(String message) {
+ if (LOG_ENABLED) {
+ Log.v(LOG_TAG, message);
+ }
+ }
+
+
+}
+
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java
new file mode 100644
index 0000000..c44a817
--- /dev/null
+++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java
@@ -0,0 +1,65 @@
+ /*
+ * 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.
+ */
+
+
+package com.android.rollo;
+
+import java.io.Writer;
+import java.lang.Math;
+
+import android.renderscript.RenderScript;
+
+
+class RolloMesh {
+
+ static RenderScript.TriangleMesh createCard(RenderScript rs) {
+ RenderScript.Element vtx = rs.elementGetPredefined(
+ RenderScript.ElementPredefined.ST_XYZ_F32);
+ RenderScript.Element idx = rs.elementGetPredefined(
+ RenderScript.ElementPredefined.INDEX_16);
+
+ rs.triangleMeshBegin(vtx, idx);
+ rs.triangleMeshAddVertex_XYZ_ST(0, 0, 0, 0, 0);
+ rs.triangleMeshAddVertex_XYZ_ST(0, 1, 0, 0, 1);
+ rs.triangleMeshAddVertex_XYZ_ST(1, 1, 0, 1, 1);
+ rs.triangleMeshAddVertex_XYZ_ST(1, 0, 0, 1, 0);
+
+ rs.triangleMeshAddTriangle(0,1,2);
+ rs.triangleMeshAddTriangle(0,2,3);
+ return rs.triangleMeshCreate();
+ }
+
+ static RenderScript.TriangleMesh createTab(RenderScript rs) {
+ RenderScript.Element vtx = rs.elementGetPredefined(
+ RenderScript.ElementPredefined.ST_XYZ_F32);
+ RenderScript.Element idx = rs.elementGetPredefined(
+ RenderScript.ElementPredefined.INDEX_16);
+
+ rs.triangleMeshBegin(vtx, idx);
+ rs.triangleMeshAddVertex_XYZ_ST(0.0f, 0, 0, -1.0f, 0);
+ rs.triangleMeshAddVertex_XYZ_ST(0.2f, 1, 0, -0.8f, 1);
+ rs.triangleMeshAddVertex_XYZ_ST(1.8f, 1, 0, 0.8f, 1);
+ rs.triangleMeshAddVertex_XYZ_ST(2.0f, 0, 0, 1.0f, 0);
+ rs.triangleMeshAddTriangle(0,1,2);
+ rs.triangleMeshAddTriangle(0,2,3);
+ return rs.triangleMeshCreate();
+ }
+
+
+
+}
+
+
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java
new file mode 100644
index 0000000..aa9f338
--- /dev/null
+++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java
@@ -0,0 +1,150 @@
+/*
+ * 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.rollo;
+
+import java.io.Writer;
+
+import android.renderscript.RenderScript;
+import android.renderscript.ProgramVertexAlloc;
+
+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 RolloRS {
+
+ public RolloRS() {
+ }
+
+ public void init(RenderScript rs, Resources res, int width, int height) {
+ mRS = rs;
+ mRes = res;
+ initNamed();
+ initRS();
+ }
+
+
+ private Resources mRes;
+ private RenderScript mRS;
+
+
+ private RenderScript.Script mScript;
+
+ private RenderScript.Sampler mSampler;
+ private RenderScript.ProgramFragmentStore mPFSBackground;
+ private RenderScript.ProgramFragmentStore mPFSImages;
+ private RenderScript.ProgramFragment mPFBackground;
+ private RenderScript.ProgramFragment mPFImages;
+ private RenderScript.ProgramVertex mPV;
+ private ProgramVertexAlloc mPVAlloc;
+
+ private RenderScript.Allocation mAllocEnv;
+ private RenderScript.Allocation mAllocPos;
+ private RenderScript.Allocation mAllocState;
+ //private RenderScript.Allocation mAllocPV;
+ private RenderScript.TriangleMesh mMeshCard;
+ private RenderScript.TriangleMesh mMeshTab;
+
+ private float[] mBufferPos;
+ //private float[] mBufferPV;
+
+ private void initNamed() {
+ //mMeshTab = RolloMesh.createTab(mRS);
+ //mMeshTab.setName("MeshTab");
+ mMeshCard = RolloMesh.createCard(mRS);
+ mMeshCard.setName("MeshCard");
+ Log.e("rs", "Done loading strips");
+
+ mRS.samplerBegin();
+ mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN,
+ RenderScript.SamplerValue.LINEAR_MIP_LINEAR);
+ mRS.samplerSet(RenderScript.SamplerParam.WRAP_MODE_S,
+ RenderScript.SamplerValue.CLAMP);
+ mRS.samplerSet(RenderScript.SamplerParam.WRAP_MODE_T,
+ RenderScript.SamplerValue.CLAMP);
+ mSampler = mRS.samplerCreate();
+
+
+ mRS.programFragmentBegin(null, null);
+ mRS.programFragmentSetTexEnable(0, true);
+ //mRS.programFragmentSetEnvMode(0, RS_TEX_ENV_MODE_REPLACE);
+ mPFImages = mRS.programFragmentCreate();
+ mPFImages.setName("PF");
+ mPFImages.bindSampler(mSampler, 0);
+
+ mRS.programFragmentStoreBegin(null, null);
+ mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
+ mRS.programFragmentStoreDitherEnable(true);
+ mPFSBackground = mRS.programFragmentStoreCreate();
+ mPFSBackground.setName("PFSBackground");
+
+ /*
+ mRS.programFragmentStoreBegin(null, null);
+ mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.EQUAL);
+ mRS.programFragmentStoreDitherEnable(false);
+ mRS.programFragmentStoreDepthMask(false);
+ mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.ONE,
+ RenderScript.BlendDstFunc.ONE);
+ mPFSImages = mRS.programFragmentStoreCreate();
+ mPFSImages.setName("PFSImages");
+*/
+
+
+ mPVAlloc = new ProgramVertexAlloc(mRS);
+ mRS.programVertexBegin(null, null);
+ mRS.programVertexSetCameraMode(true);
+ mRS.programVertexSetTextureMatrixEnable(true);
+ mRS.programVertexSetModelMatrixEnable(true);
+ mRS.programVertexSetProjectionMatrixEnable(true);
+ mPV = mRS.programVertexCreate();
+ mPV.setName("PV");
+ mPV.bindAllocation(0, mPVAlloc.mAlloc);
+
+ mPVAlloc.setupProjectionNormalized(320, 480);
+ //mPVAlloc.setupOrthoNormalized(320, 480);
+ mRS.contextBindProgramVertex(mPV);
+
+
+ Log.e("rs", "Done loading named");
+ }
+
+
+ private void initRS() {
+ mRS.scriptCBegin();
+ mRS.scriptCSetClearColor(0.0f, 0.7f, 0.0f, 1.0f);
+ mRS.scriptCSetScript(mRes, R.raw.rollo);
+ mRS.scriptCSetRoot(true);
+ mScript = mRS.scriptCCreate();
+
+
+ mRS.contextBindRootScript(mScript);
+ }
+}
+
+
+
diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java
new file mode 100644
index 0000000..9a30aed
--- /dev/null
+++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java
@@ -0,0 +1,82 @@
+/*
+ * 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.rollo;
+
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.concurrent.Semaphore;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScript;
+
+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 RolloView extends RSSurfaceView {
+
+ public RolloView(Context context) {
+ super(context);
+
+ //setFocusable(true);
+ }
+
+ private RenderScript mRS;
+ private RolloRS mRender;
+
+ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+ super.surfaceChanged(holder, format, w, h);
+
+ mRS = createRenderScript();
+ mRender = new RolloRS();
+ mRender.init(mRS, getResources(), w, h);
+ }
+
+ @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;
+ }
+ //mRender.newTouchPosition((int)ev.getX(), (int)ev.getY());
+ return ret;
+ }
+}
+
+
diff --git a/libs/rs/jni/Android.mk b/libs/rs/jni/Android.mk
new file mode 100644
index 0000000..b3142ae
--- /dev/null
+++ b/libs/rs/jni/Android.mk
@@ -0,0 +1,36 @@
+LOCAL_PATH:=$(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ RenderScript_jni.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libandroid_runtime \
+ libacc \
+ libnativehelper \
+ libRS \
+ libcutils \
+ libsgl \
+ libutils \
+ libui
+
+LOCAL_STATIC_LIBRARIES :=
+
+rs_generated_include_dir := $(call intermediates-dir-for,SHARED_LIBRARIES,libRS,,)
+
+LOCAL_C_INCLUDES += \
+ $(JNI_H_INCLUDE) \
+ $(rs_generated_include_dir) \
+ $(call include-path-for, corecg graphics)
+
+LOCAL_CFLAGS +=
+
+LOCAL_LDLIBS := -lpthread
+
+LOCAL_MODULE:= libRS_jni
+LOCAL_PRELINK_MODULE := false
+
+LOCAL_ADDITIONAL_DEPENDENCIES += $(rs_generated_source)
+
+include $(BUILD_SHARED_LIBRARY)
+
diff --git a/libs/rs/jni/RenderScript_jni.cpp b/libs/rs/jni/RenderScript_jni.cpp
index 61866b7..7a3a7af 100644
--- a/libs/rs/jni/RenderScript_jni.cpp
+++ b/libs/rs/jni/RenderScript_jni.cpp
@@ -35,8 +35,6 @@
#include "../RenderScript.h"
#include "../RenderScriptEnv.h"
-#include "acc/acc.h"
-
//#define LOG_API LOGE
#define LOG_API(...)
@@ -64,6 +62,21 @@ static void _nInit(JNIEnv *_env, jclass _this)
// ---------------------------------------------------------------------------
+static void
+nAssignName(JNIEnv *_env, jobject _this, jint obj, jbyteArray str)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nAssignName, con(%p), obj(%p)", con, obj);
+
+ jint len = _env->GetArrayLength(str);
+ jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
+ rsAssignName((void *)obj, (const char *)cptr, len);
+ _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
+}
+
+
+// ---------------------------------------------------------------------------
+
static jint
nDeviceCreate(JNIEnv *_env, jobject _this)
{
@@ -398,6 +411,15 @@ nTriangleMeshAddVertex_XYZ_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, j
}
static void
+nTriangleMeshAddVertex_XYZ_ST_NORM(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t, jfloat nx, jfloat ny, jfloat nz)
+{
+ float v[] = {nx, ny, nz, s, t, x, y, z};
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
+ rsTriangleMeshAddVertex(v);
+}
+
+static void
nTriangleMeshAddTriangle(JNIEnv *_env, jobject _this, jint i1, jint i2, jint i3)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
@@ -567,8 +589,6 @@ nScriptCSetScript(JNIEnv *_env, jobject _this, jbyteArray scriptRef,
jint remaining;
jbyte* script_base = 0;
jbyte* script_ptr;
- ACCscript* script = 0;
- void* scriptEntry = 0;
if (!scriptRef) {
_exception = 1;
//_env->ThrowNew(IAEClass, "script == null");
@@ -594,22 +614,9 @@ nScriptCSetScript(JNIEnv *_env, jobject _this, jbyteArray scriptRef,
_env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
script_ptr = script_base + offset;
- {
- script = accCreateScript();
- const char* scriptSource[] = {(const char*) script_ptr};
- int scriptLength[] = {length} ;
- accScriptSource(script, 1, scriptSource, scriptLength);
- accCompileScript(script);
- accGetScriptLabel(script, "main", (ACCvoid**) &scriptEntry);
- }
- if (scriptEntry) {
- rsScriptCSetScript((void*) script, (void *)scriptEntry);
- script = 0;
- }
+ rsScriptCSetText((const char *)script_ptr, length);
+
exit:
- if (script) {
- accDeleteScript(script);
- }
if (script_base) {
_env->ReleasePrimitiveArrayCritical(scriptRef, script_base,
_exception ? JNI_ABORT: 0);
@@ -679,9 +686,18 @@ nProgramFragmentStoreCreate(JNIEnv *_env, jobject _this)
{
RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
LOG_API("nProgramFragmentStoreCreate, con(%p)", con);
+
return (jint)rsProgramFragmentStoreCreate();
}
+static void
+nProgramFragmentStoreDestroy(JNIEnv *_env, jobject _this, jint pgm)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramFragmentStoreDestroy, con(%p), pgm(%i)", con, pgm);
+ rsProgramFragmentStoreDestroy((RsProgramFragmentStore)pgm);
+}
+
// ---------------------------------------------------------------------------
static void
@@ -740,6 +756,90 @@ nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable)
return (jint)rsProgramFragmentCreate();
}
+static void
+nProgramFragmentDestroy(JNIEnv *_env, jobject _this, jint pgm)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm);
+ rsProgramFragmentDestroy((RsProgramFragment)pgm);
+}
+
+// ---------------------------------------------------------------------------
+
+static void
+nProgramVertexBegin(JNIEnv *_env, jobject _this, jint in, jint out)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramVertexBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out);
+ rsProgramVertexBegin((RsElement)in, (RsElement)out);
+}
+
+static void
+nProgramVertexBindAllocation(JNIEnv *_env, jobject _this, jint vpv, jint slot, jint a)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramVertexBindAllocation, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
+ rsProgramVertexBindAllocation((RsProgramFragment)vpv, slot, (RsAllocation)a);
+}
+
+static void
+nProgramVertexSetType(JNIEnv *_env, jobject _this, jint slot, jint t)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramVertexSetType, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsType)t);
+ rsProgramVertexSetType(slot, (RsType)t);
+}
+
+static void
+nProgramVertexSetCameraMode(JNIEnv *_env, jobject _this, jboolean isOrtho)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramVertexSetCameraMode, con(%p), isOrtho(%i)", con, isOrtho);
+ rsProgramVertexSetCameraMode(isOrtho);
+}
+
+static void
+nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramVertexSetTextureMatrixEnable, con(%p), enable(%i)", con, enable);
+ rsProgramVertexSetTextureMatrixEnable(enable);
+}
+
+static void
+nProgramVertexSetModelMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramVertexSetModelMatrixEnable, con(%p), enable(%i)", con, enable);
+ rsProgramVertexSetModelMatrixEnable(enable);
+}
+
+static void
+nProgramVertexSetProjectionMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramVertexSetProjectionMatrixEnable, con(%p), enable(%i)", con, enable);
+ rsProgramVertexSetProjectionMatrixEnable(enable);
+}
+
+static jint
+nProgramVertexCreate(JNIEnv *_env, jobject _this)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramVertexCreate, con(%p)", con);
+ return (jint)rsProgramVertexCreate();
+}
+
+static void
+nProgramVertexDestroy(JNIEnv *_env, jobject _this, jint pgm)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm);
+ rsProgramFragmentDestroy((RsProgramFragment)pgm);
+}
+
+
+
// ---------------------------------------------------------------------------
@@ -767,6 +867,14 @@ nContextBindProgramFragment(JNIEnv *_env, jobject _this, jint pf)
rsContextBindProgramFragment((RsProgramFragment)pf);
}
+static void
+nContextBindProgramVertex(JNIEnv *_env, jobject _this, jint pf)
+{
+ RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
+ LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf);
+ rsContextBindProgramVertex((RsProgramVertex)pf);
+}
+
// ---------------------------------------------------------------------------
static void
@@ -805,7 +913,7 @@ nSamplerCreate(JNIEnv *_env, jobject _this)
// ---------------------------------------------------------------------------
-static const char *classPathName = "com/android/fountain/RenderScript";
+static const char *classPathName = "android/renderscript/RenderScript";
static JNINativeMethod methods[] = {
{"_nInit", "()V", (void*)_nInit },
@@ -813,6 +921,7 @@ static JNINativeMethod methods[] = {
{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy },
{"nContextCreate", "(ILandroid/view/Surface;I)I", (void*)nContextCreate },
{"nContextDestroy", "(I)V", (void*)nContextDestroy },
+{"nAssignName", "(I[B)V", (void*)nAssignName },
{"nElementBegin", "()V", (void*)nElementBegin },
{"nElementAddPredefined", "(I)V", (void*)nElementAddPredefined },
@@ -845,6 +954,7 @@ static JNINativeMethod methods[] = {
{"nTriangleMeshAddVertex_XYZ", "(FFF)V", (void*)nTriangleMeshAddVertex_XYZ },
{"nTriangleMeshAddVertex_XY_ST", "(FFFF)V", (void*)nTriangleMeshAddVertex_XY_ST },
{"nTriangleMeshAddVertex_XYZ_ST", "(FFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST },
+{"nTriangleMeshAddVertex_XYZ_ST_NORM", "(FFFFFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST_NORM },
{"nTriangleMeshAddTriangle", "(III)V", (void*)nTriangleMeshAddTriangle },
{"nTriangleMeshCreate", "()I", (void*)nTriangleMeshCreate },
@@ -875,6 +985,7 @@ static JNINativeMethod methods[] = {
{"nProgramFragmentStoreBlendFunc", "(II)V", (void*)nProgramFragmentStoreBlendFunc },
{"nProgramFragmentStoreDither", "(Z)V", (void*)nProgramFragmentStoreDither },
{"nProgramFragmentStoreCreate", "()I", (void*)nProgramFragmentStoreCreate },
+{"nProgramFragmentStoreDestroy", "(I)V", (void*)nProgramFragmentStoreDestroy },
{"nProgramFragmentBegin", "(II)V", (void*)nProgramFragmentBegin },
{"nProgramFragmentBindTexture", "(III)V", (void*)nProgramFragmentBindTexture },
@@ -883,10 +994,22 @@ static JNINativeMethod methods[] = {
{"nProgramFragmentSetEnvMode", "(II)V", (void*)nProgramFragmentSetEnvMode },
{"nProgramFragmentSetTexEnable", "(IZ)V", (void*)nProgramFragmentSetTexEnable },
{"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate },
+{"nProgramFragmentDestroy", "(I)V", (void*)nProgramFragmentDestroy },
+
+{"nProgramVertexDestroy", "(I)V", (void*)nProgramVertexDestroy },
+{"nProgramVertexBindAllocation", "(III)V", (void*)nProgramVertexBindAllocation },
+{"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin },
+{"nProgramVertexSetType", "(II)V", (void*)nProgramVertexSetType },
+{"nProgramVertexSetCameraMode", "(Z)V", (void*)nProgramVertexSetCameraMode },
+{"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable },
+{"nProgramVertexSetModelMatrixEnable", "(Z)V", (void*)nProgramVertexSetModelMatrixEnable },
+{"nProgramVertexSetProjectionMatrixEnable", "(Z)V", (void*)nProgramVertexSetProjectionMatrixEnable },
+{"nProgramVertexCreate", "()I", (void*)nProgramVertexCreate },
{"nContextBindRootScript", "(I)V", (void*)nContextBindRootScript },
{"nContextBindProgramFragmentStore","(I)V", (void*)nContextBindProgramFragmentStore },
{"nContextBindProgramFragment", "(I)V", (void*)nContextBindProgramFragment },
+{"nContextBindProgramVertex", "(I)V", (void*)nContextBindProgramVertex },
{"nSamplerDestroy", "(I)V", (void*)nSamplerDestroy },
{"nSamplerBegin", "()V", (void*)nSamplerBegin },
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 090be32..107096f 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -16,6 +16,11 @@ ContextBindProgramVertex {
param RsProgramVertex pgm
}
+AssignName {
+ param void *obj
+ param const char *name
+ param size_t len
+ }
ElementBegin {
}
@@ -286,10 +291,14 @@ ScriptCSetOrtho {
}
ScriptCSetScript {
- param void * accScript
param void * codePtr
}
+ScriptCSetText {
+ param const char * text
+ param uint32_t length
+ }
+
ScriptCCreate {
ret RsScript
}
@@ -328,6 +337,9 @@ ProgramFragmentStoreCreate {
ret RsProgramFragmentStore
}
+ProgramFragmentStoreDestroy {
+ param RsProgramFragmentStore pfs
+ }
ProgramFragmentBegin {
@@ -366,6 +378,9 @@ ProgramFragmentCreate {
ret RsProgramFragment
}
+ProgramFragmentDestroy {
+ param RsProgramFragment pf
+ }
ProgramVertexBegin {
@@ -400,3 +415,7 @@ ProgramVertexSetModelMatrixEnable {
param bool enable
}
+ProgramVertexSetProjectionMatrixEnable {
+ param bool enable
+ }
+
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index ec4a309..266c455 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -17,7 +17,7 @@
#include "rsDevice.h"
#include "rsContext.h"
#include "rsThreadIO.h"
-
+#include "utils/String8.h"
using namespace android;
using namespace android::renderscript;
@@ -37,13 +37,9 @@ void Context::initEGL()
EGL_NONE
};
- LOGE("EGL 1");
mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- LOGE("EGL 2 %p", mDisplay);
eglInitialize(mDisplay, &mMajorVersion, &mMinorVersion);
- LOGE("EGL 3 %i %i", mMajorVersion, mMinorVersion);
eglChooseConfig(mDisplay, s_configAttribs, &mConfig, 1, &mNumConfigs);
- LOGE("EGL 4 %p", mConfig);
if (mWndSurface) {
mSurface = eglCreateWindowSurface(mDisplay, mConfig,
@@ -55,30 +51,43 @@ void Context::initEGL()
NULL);
}
- LOGE("EGL 5");
mContext = eglCreateContext(mDisplay, mConfig, NULL, NULL);
eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
eglQuerySurface(mDisplay, mSurface, EGL_WIDTH, &mWidth);
eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mHeight);
- LOGE("EGL 9");
+}
+
+bool Context::runScript(Script *s, uint32_t launchID)
+{
+ ObjectBaseRef<ProgramFragment> frag(mFragment);
+ ObjectBaseRef<ProgramVertex> vtx(mVertex);
+ ObjectBaseRef<ProgramFragmentStore> store(mFragmentStore);
+
+ bool ret = s->run(this, launchID);
+
+ mFragment.set(frag);
+ mVertex.set(vtx);
+ mFragmentStore.set(store);
+ return true;
}
+
bool Context::runRootScript()
{
- rsAssert(mRootScript->mIsRoot);
+ rsAssert(mRootScript->mEnviroment.mIsRoot);
glColor4f(1,1,1,1);
glEnable(GL_LIGHT0);
- glViewport(0, 0, 320, 480);
- float aspectH = 480.f / 320.f;
+ glViewport(0, 0, mWidth, mHeight);
- if(mRootScript->mIsOrtho) {
+ if(mRootScript->mEnviroment.mIsOrtho) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrthof(0, 320, 480, 0, 0, 1);
+ glOrthof(0, mWidth, mHeight, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
} else {
+ float aspectH = ((float)mWidth) / mHeight;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustumf(-1, 1, -aspectH, aspectH, 1, 100);
@@ -93,15 +102,15 @@ bool Context::runRootScript()
glDepthMask(GL_TRUE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glClearColor(mRootScript->mClearColor[0],
- mRootScript->mClearColor[1],
- mRootScript->mClearColor[2],
- mRootScript->mClearColor[3]);
- glClearDepthf(mRootScript->mClearDepth);
+ glClearColor(mRootScript->mEnviroment.mClearColor[0],
+ mRootScript->mEnviroment.mClearColor[1],
+ mRootScript->mEnviroment.mClearColor[2],
+ mRootScript->mEnviroment.mClearColor[3]);
+ glClearDepthf(mRootScript->mEnviroment.mClearDepth);
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
- return mRootScript->run(this, 0);
+ return runScript(mRootScript.get(), 0);
}
void Context::setupCheck()
@@ -123,16 +132,11 @@ void * Context::threadProc(void *vrsc)
{
Context *rsc = static_cast<Context *>(vrsc);
- LOGE("TP 1");
gIO = new ThreadIO();
-
rsc->mServerCommands.init(128);
rsc->mServerReturns.init(128);
rsc->initEGL();
-
- LOGE("TP 2");
-
rsc->mRunning = true;
bool mDraw = true;
while (!rsc->mExit) {
@@ -149,7 +153,6 @@ void * Context::threadProc(void *vrsc)
}
}
- LOGE("TP 6");
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(rsc->mDisplay, rsc->mSurface);
@@ -159,7 +162,6 @@ void * Context::threadProc(void *vrsc)
Context::Context(Device *dev, Surface *sur)
{
- LOGE("CC 1");
dev->addContext(this);
mDev = dev;
mRunning = false;
@@ -171,7 +173,6 @@ Context::Context(Device *dev, Surface *sur)
// see comment in header
gCon = this;
- LOGE("CC 2");
int status;
pthread_attr_t threadAttr;
@@ -185,17 +186,16 @@ Context::Context(Device *dev, Surface *sur)
sparam.sched_priority = ANDROID_PRIORITY_DISPLAY;
pthread_attr_setschedparam(&threadAttr, &sparam);
+ LOGE("RS Launching thread");
status = pthread_create(&mThreadId, &threadAttr, threadProc, this);
if (status) {
LOGE("Failed to start rs context thread.");
}
- LOGE("CC 3");
mWndSurface = sur;
while(!mRunning) {
sleep(1);
}
- LOGE("CC 4");
pthread_attr_destroy(&threadAttr);
}
@@ -205,14 +205,11 @@ Context::~Context()
mExit = true;
void *res;
- LOGE("DES 1");
int status = pthread_join(mThreadId, &res);
- LOGE("DES 2");
if (mDev) {
mDev->removeContext(this);
}
- LOGE("DES 3");
}
void Context::swapBuffers()
@@ -249,6 +246,46 @@ void Context::setVertex(ProgramVertex *pv)
pv->setupGL();
}
+void Context::assignName(ObjectBase *obj, const char *name, uint32_t len)
+{
+ rsAssert(!obj->getName());
+ obj->setName(name, len);
+ mNames.add(obj);
+}
+
+void Context::removeName(ObjectBase *obj)
+{
+ for(size_t ct=0; ct < mNames.size(); ct++) {
+ if (obj == mNames[ct]) {
+ mNames.removeAt(ct);
+ return;
+ }
+ }
+}
+
+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);
+ }
+}
+
+
///////////////////////////////////////////////////////////////////////////////////////////
//
@@ -292,6 +329,11 @@ void rsi_ContextBindProgramVertex(Context *rsc, RsProgramVertex vpv)
rsc->setVertex(pv);
}
+void rsi_AssignName(Context *rsc, void * obj, const char *name, uint32_t len)
+{
+ ObjectBase *ob = static_cast<ObjectBase *>(obj);
+ rsc->assignName(ob, name, len);
+}
}
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 64717e4..21ae8c5 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -42,7 +42,6 @@
namespace android {
namespace renderscript {
-
class Context
{
public:
@@ -77,6 +76,11 @@ public:
void setupCheck();
+ 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;
+
protected:
Device *mDev;
@@ -103,11 +107,16 @@ protected:
ObjectBaseRef<ProgramVertex> mVertex;
ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
+ ProgramFragment * mDefaultFragment;
+ ProgramVertex * mDefaultVertex;
+ ProgramFragmentStore * mDefaultFragmentStore;
+
private:
Context();
void initEGL();
+ bool runScript(Script *s, uint32_t launchID);
bool runRootScript();
static void * threadProc(void *);
@@ -115,6 +124,8 @@ private:
// todo: put in TLS
static Context *gCon;
Surface *mWndSurface;
+
+ Vector<ObjectBase *> mNames;
};
diff --git a/libs/rs/rsObjectBase.cpp b/libs/rs/rsObjectBase.cpp
index f9cb9c8..8f5232a 100644
--- a/libs/rs/rsObjectBase.cpp
+++ b/libs/rs/rsObjectBase.cpp
@@ -23,6 +23,7 @@ using namespace android::renderscript;
ObjectBase::ObjectBase()
{
mRefCount = 0;
+ mName = NULL;
}
ObjectBase::~ObjectBase()
@@ -46,3 +47,24 @@ void ObjectBase::decRef() const
}
}
+void ObjectBase::setName(const char *name)
+{
+ delete mName;
+ mName = NULL;
+ if (name) {
+ mName = new char[strlen(name) +1];
+ strcpy(mName, 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;
+ }
+}
+
diff --git a/libs/rs/rsObjectBase.h b/libs/rs/rsObjectBase.h
index 7761e49..b2c3338 100644
--- a/libs/rs/rsObjectBase.h
+++ b/libs/rs/rsObjectBase.h
@@ -33,7 +33,14 @@ public:
void incRef() const;
void decRef() const;
+ const char * getName() const {
+ return mName;
+ }
+ void setName(const char *);
+ void setName(const char *, uint32_t len);
+
private:
+ char * mName;
mutable int32_t mRefCount;
@@ -47,6 +54,20 @@ public:
mRef = NULL;
}
+ ObjectBaseRef(const ObjectBaseRef &ref) {
+ mRef = ref.get();
+ if (mRef) {
+ mRef->incRef();
+ }
+ }
+
+ ObjectBaseRef(T *ref) {
+ mRef = ref;
+ if (mRef) {
+ ref->incRef();
+ }
+ }
+
~ObjectBaseRef() {
clear();
}
@@ -55,10 +76,16 @@ public:
if (mRef != ref) {
clear();
mRef = ref;
- ref->incRef();
+ if (mRef) {
+ ref->incRef();
+ }
}
}
+ void set(const ObjectBaseRef &ref) {
+ set(ref.mRef);
+ }
+
void clear() {
if (mRef) {
mRef->decRef();
@@ -77,9 +104,6 @@ public:
protected:
T * mRef;
-private:
- ObjectBaseRef(const ObjectBaseRef &) {};
-
};
diff --git a/libs/rs/rsProgramFragment.cpp b/libs/rs/rsProgramFragment.cpp
index 3d316ea..316e791 100644
--- a/libs/rs/rsProgramFragment.cpp
+++ b/libs/rs/rsProgramFragment.cpp
@@ -212,6 +212,14 @@ RsProgramFragment rsi_ProgramFragmentCreate(Context *rsc)
return pf;
}
+void rsi_ProgramFragmentDestroy(Context *rsc, RsProgramFragment vpf)
+{
+ ProgramFragment *pf = (ProgramFragment *)vpf;
+ if (pf->getName()) {
+ rsc->removeName(pf);
+ }
+ pf->decRef();
+}
}
diff --git a/libs/rs/rsProgramFragment.h b/libs/rs/rsProgramFragment.h
index cc08aea..ed9c49b 100644
--- a/libs/rs/rsProgramFragment.h
+++ b/libs/rs/rsProgramFragment.h
@@ -85,7 +85,7 @@ public:
ObjectBaseRef<Type> mTextureTypes[ProgramFragment::MAX_TEXTURE];
-
+ Vector<ProgramFragment *> mPrograms;
};
diff --git a/libs/rs/rsProgramFragmentStore.cpp b/libs/rs/rsProgramFragmentStore.cpp
index 7f5d5f4..a1855a6 100644
--- a/libs/rs/rsProgramFragmentStore.cpp
+++ b/libs/rs/rsProgramFragmentStore.cpp
@@ -202,7 +202,6 @@ ProgramFragmentStoreState::~ProgramFragmentStoreState()
}
-
namespace android {
namespace renderscript {
@@ -238,7 +237,6 @@ RsProgramFragmentStore rsi_ProgramFragmentStoreCreate(Context *rsc)
ProgramFragmentStore *pfs = rsc->mStateFragmentStore.mPFS;
pfs->incRef();
rsc->mStateFragmentStore.mPFS = 0;
-
return pfs;
}
@@ -247,6 +245,17 @@ void rsi_ProgramFragmentStoreDither(Context *rsc, bool enable)
rsc->mStateFragmentStore.mPFS->setDitherEnable(enable);
}
+void rsi_ProgramFragmentStoreDestroy(Context *rsc, RsProgramFragmentStore vpfs)
+{
+ ProgramFragmentStore *pfs = (ProgramFragmentStore *)vpfs;
+ if (pfs->getName()) {
+ rsc->removeName(pfs);
+ }
+ pfs->decRef();
+}
+
+
+
}
}
diff --git a/libs/rs/rsProgramFragmentStore.h b/libs/rs/rsProgramFragmentStore.h
index bbd0f38..d862775 100644
--- a/libs/rs/rsProgramFragmentStore.h
+++ b/libs/rs/rsProgramFragmentStore.h
@@ -76,8 +76,6 @@ public:
~ProgramFragmentStoreState();
ProgramFragmentStore *mPFS;
-
-
};
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index 8e2b82d..fc26ab5 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -47,7 +47,7 @@ void ProgramVertex::setupGL()
glMatrixMode(GL_PROJECTION);
if (mProjectionEnable) {
- //glLoadMatrixf(&f[OFFSET_PROJECTION]);
+ glLoadMatrixf(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]);
} else {
}
@@ -57,7 +57,6 @@ void ProgramVertex::setupGL()
} else {
glLoadIdentity();
}
-
}
void ProgramVertex::setConstantType(uint32_t slot, const Type *t)
@@ -97,7 +96,6 @@ RsProgramVertex rsi_ProgramVertexCreate(Context *rsc)
ProgramVertex *pv = rsc->mStateVertex.mPV;
pv->incRef();
rsc->mStateVertex.mPV = 0;
-
return pv;
}
@@ -127,6 +125,11 @@ void rsi_ProgramVertexSetModelMatrixEnable(Context *rsc, bool enable)
rsc->mStateVertex.mPV->setTransformEnable(enable);
}
+void rsi_ProgramVertexSetProjectionMatrixEnable(Context *rsc, bool enable)
+{
+ rsc->mStateVertex.mPV->setProjectionEnable(enable);
+}
+
}
diff --git a/libs/rs/rsProgramVertex.h b/libs/rs/rsProgramVertex.h
index cd46900..677be6e 100644
--- a/libs/rs/rsProgramVertex.h
+++ b/libs/rs/rsProgramVertex.h
@@ -40,6 +40,7 @@ public:
void setTextureMatrixEnable(bool e) {mTextureMatrixEnable = e;}
void setProjectionEnabled(bool e) {mProjectionEnable = e;}
void setTransformEnable(bool e) {mTransformEnable = e;}
+ void setProjectionEnable(bool e) {mProjectionEnable = e;}
protected:
bool mDirty;
diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp
index 24a630c..ae85c9c 100644
--- a/libs/rs/rsScript.cpp
+++ b/libs/rs/rsScript.cpp
@@ -21,11 +21,12 @@ using namespace android::renderscript;
Script::Script()
{
- mClearColor[0] = 0;
- mClearColor[1] = 0;
- mClearColor[2] = 0;
- mClearColor[3] = 1;
- mClearDepth = 1;
+ memset(&mEnviroment, 0, sizeof(mEnviroment));
+ mEnviroment.mClearColor[0] = 0;
+ mEnviroment.mClearColor[1] = 0;
+ mEnviroment.mClearColor[2] = 0;
+ mEnviroment.mClearColor[3] = 1;
+ mEnviroment.mClearDepth = 1;
}
Script::~Script()
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index 0229860..d32f116 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -19,11 +19,15 @@
#include "rsAllocation.h"
+
// ---------------------------------------------------------------------------
namespace android {
namespace renderscript {
-
+class ProgramVertex;
+class ProgramFragment;
+class ProgramRaster;
+class ProgramFragmentStore;
class Script : public ObjectBase
{
@@ -33,13 +37,20 @@ public:
virtual ~Script();
- bool mIsRoot;
- bool mIsOrtho;
+ struct Enviroment_t {
+ bool mIsRoot;
+ bool mIsOrtho;
+ float mClearColor[4];
+ float mClearDepth;
+ uint32_t mClearStencil;
- float mClearColor[4];
- float mClearDepth;
- uint32_t mClearStencil;
+ ObjectBaseRef<ProgramVertex> mVertex;
+ ObjectBaseRef<ProgramFragment> mFragment;
+ //ObjectBaseRef<ProgramRaster> mRaster;
+ ObjectBaseRef<ProgramFragmentStore> mFragmentStore;
+ };
+ Enviroment_t mEnviroment;
const Type * mConstantBufferTypes;
uint32_t mCounstantBufferCount;
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 36019ab..d29eb9f 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -19,6 +19,7 @@
#include "rsMatrix.h"
#include "acc/acc.h"
+#include "utils/String8.h"
using namespace android;
using namespace android::renderscript;
@@ -27,7 +28,7 @@ using namespace android::renderscript;
ScriptC::ScriptC()
{
mAccScript = NULL;
- mScript = NULL;
+ memset(&mProgram, 0, sizeof(mProgram));
}
ScriptC::~ScriptC()
@@ -390,7 +391,15 @@ static rsc_FunctionTable scriptCPtrTable = {
bool ScriptC::run(Context *rsc, uint32_t launchID)
{
Env e = {rsc, this};
- return mScript(&e, &scriptCPtrTable, launchID) != 0;
+
+ if (mEnviroment.mFragmentStore.get()) {
+ rsc->setFragmentStore(mEnviroment.mFragmentStore.get());
+ }
+ if (mEnviroment.mFragment.get()) {
+ rsc->setFragment(mEnviroment.mFragment.get());
+ }
+
+ return mProgram.mScript(&e, &scriptCPtrTable, launchID) != 0;
}
ScriptCState::ScriptCState()
@@ -407,17 +416,96 @@ ScriptCState::~ScriptCState()
void ScriptCState::clear()
{
+ memset(&mProgram, 0, sizeof(mProgram));
+
mConstantBufferTypes.clear();
- mClearColor[0] = 0;
- mClearColor[1] = 0;
- mClearColor[2] = 0;
- mClearColor[3] = 1;
- mClearDepth = 1;
- mClearStencil = 0;
+
+ 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;
+ mEnviroment.mIsOrtho = true;
+
mAccScript = NULL;
- mScript = NULL;
- mIsRoot = false;
- mIsOrtho = true;
+
+}
+
+
+void ScriptCState::runCompiler(Context *rsc)
+{
+ mAccScript = accCreateScript();
+ String8 tmp;
+
+ rsc->appendNameDefines(&tmp);
+
+ const char* scriptSource[] = {tmp.string(), mProgram.mScriptText};
+ int scriptLength[] = {tmp.length(), mProgram.mScriptTextLength} ;
+ accScriptSource(mAccScript, sizeof(scriptLength) / sizeof(int), scriptSource, scriptLength);
+ accCompileScript(mAccScript);
+ accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript);
+ rsAssert(mProgram.mScript);
+
+
+ if (mProgram.mScript) {
+ const static int pragmaMax = 16;
+ ACCsizei pragmaCount;
+ ACCchar * str[pragmaMax];
+ accGetPragmas(mAccScript, &pragmaCount, pragmaMax, &str[0]);
+
+ for (int ct=0; ct < pragmaCount; ct+=2) {
+ LOGE("pragma %i %s %s", ct, str[ct], str[ct+1]);
+
+ if (!strcmp(str[ct], "version")) {
+ continue;
+
+ }
+
+
+ if (!strcmp(str[ct], "stateVertex")) {
+ LOGE("Unreconized value %s passed to stateVertex", str[ct+1]);
+ }
+
+ if (!strcmp(str[ct], "stateRaster")) {
+ LOGE("Unreconized value %s passed to stateRaster", str[ct+1]);
+ }
+
+ if (!strcmp(str[ct], "stateFragment")) {
+ ProgramFragment * pf =
+ (ProgramFragment *)rsc->lookupName(str[ct+1]);
+ if (pf != NULL) {
+ mEnviroment.mFragment.set(pf);
+ continue;
+ }
+ LOGE("Unreconized value %s passed to stateFragment", str[ct+1]);
+ }
+
+ if (!strcmp(str[ct], "stateFragmentStore")) {
+ ProgramFragmentStore * pfs =
+ (ProgramFragmentStore *)rsc->lookupName(str[ct+1]);
+ if (pfs != NULL) {
+ mEnviroment.mFragmentStore.set(pfs);
+ continue;
+ }
+
+ if (!strcmp(str[ct+1], "parent")) {
+ //mEnviroment.mStateFragmentStore =
+ //Script::Enviroment_t::FRAGMENT_STORE_PARENT;
+ continue;
+ }
+ LOGE("Unreconized value %s passed to stateFragmentStore", str[ct+1]);
+ }
+
+ }
+
+
+ } else {
+ // Deal with an error.
+ }
+
}
namespace android {
@@ -432,22 +520,22 @@ void rsi_ScriptCBegin(Context * rsc)
void rsi_ScriptCSetClearColor(Context * rsc, float r, float g, float b, float a)
{
ScriptCState *ss = &rsc->mScriptC;
- ss->mClearColor[0] = r;
- ss->mClearColor[1] = g;
- ss->mClearColor[2] = b;
- ss->mClearColor[3] = a;
+ ss->mEnviroment.mClearColor[0] = r;
+ ss->mEnviroment.mClearColor[1] = g;
+ ss->mEnviroment.mClearColor[2] = b;
+ ss->mEnviroment.mClearColor[3] = a;
}
void rsi_ScriptCSetClearDepth(Context * rsc, float v)
{
ScriptCState *ss = &rsc->mScriptC;
- ss->mClearDepth = v;
+ ss->mEnviroment.mClearDepth = v;
}
void rsi_ScriptCSetClearStencil(Context * rsc, uint32_t v)
{
ScriptCState *ss = &rsc->mScriptC;
- ss->mClearStencil = v;
+ ss->mEnviroment.mClearStencil = v;
}
void rsi_ScriptCAddType(Context * rsc, RsType vt)
@@ -456,41 +544,45 @@ void rsi_ScriptCAddType(Context * rsc, RsType vt)
ss->mConstantBufferTypes.add(static_cast<const Type *>(vt));
}
-void rsi_ScriptCSetScript(Context * rsc, void* accScript, void *vp)
+void rsi_ScriptCSetScript(Context * rsc, void *vp)
{
ScriptCState *ss = &rsc->mScriptC;
- ss->mAccScript = reinterpret_cast<ACCscript*>(accScript);
- ss->mScript = reinterpret_cast<rsc_RunScript>(vp);
+ ss->mProgram.mScript = reinterpret_cast<rsc_RunScript>(vp);
}
void rsi_ScriptCSetRoot(Context * rsc, bool isRoot)
{
ScriptCState *ss = &rsc->mScriptC;
- ss->mIsRoot = isRoot;
+ ss->mEnviroment.mIsRoot = isRoot;
}
void rsi_ScriptCSetOrtho(Context * rsc, bool isOrtho)
{
ScriptCState *ss = &rsc->mScriptC;
- ss->mIsOrtho = isOrtho;
+ ss->mEnviroment.mIsOrtho = isOrtho;
}
+void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len)
+{
+ ScriptCState *ss = &rsc->mScriptC;
+ ss->mProgram.mScriptText = text;
+ ss->mProgram.mScriptTextLength = len;
+}
+
+
RsScript rsi_ScriptCCreate(Context * rsc)
{
ScriptCState *ss = &rsc->mScriptC;
+ ss->runCompiler(rsc);
+
ScriptC *s = new ScriptC();
+ s->incRef();
s->mAccScript = ss->mAccScript;
ss->mAccScript = NULL;
- s->mScript = ss->mScript;
- s->mClearColor[0] = ss->mClearColor[0];
- s->mClearColor[1] = ss->mClearColor[1];
- s->mClearColor[2] = ss->mClearColor[2];
- s->mClearColor[3] = ss->mClearColor[3];
- s->mClearDepth = ss->mClearDepth;
- s->mClearStencil = ss->mClearStencil;
- s->mIsRoot = ss->mIsRoot;
- s->mIsOrtho = ss->mIsOrtho;
+ s->mEnviroment = ss->mEnviroment;
+ s->mProgram = ss->mProgram;
+ ss->clear();
return s;
}
diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h
index 283007e..55a2cc6 100644
--- a/libs/rs/rsScriptC.h
+++ b/libs/rs/rsScriptC.h
@@ -36,13 +36,22 @@ public:
ScriptC();
virtual ~ScriptC();
+ struct Program_t {
+ const char * mScriptText;
+ uint32_t mScriptTextLength;
- virtual bool run(Context *, uint32_t launchID);
+ int mVersionMajor;
+ int mVersionMinor;
+
+ rsc_RunScript mScript;
+ };
+
+ Program_t mProgram;
ACCscript* mAccScript;
- rsc_RunScript mScript;
+ virtual bool run(Context *, uint32_t launchID);
struct Env {
Context *mContext;
@@ -57,17 +66,15 @@ public:
ScriptCState();
~ScriptCState();
- ACCscript* mAccScript;
- rsc_RunScript mScript;
- float mClearColor[4];
- float mClearDepth;
- uint32_t mClearStencil;
- bool mIsRoot;
- bool mIsOrtho;
+ ACCscript* mAccScript;
+
+ ScriptC::Program_t mProgram;
+ Script::Enviroment_t mEnviroment;
Vector<const Type *> mConstantBufferTypes;
void clear();
+ void runCompiler(Context *rsc);
};
diff --git a/libs/rs/rsTriangleMesh.h b/libs/rs/rsTriangleMesh.h
index 67f964f..4e15d5a 100644
--- a/libs/rs/rsTriangleMesh.h
+++ b/libs/rs/rsTriangleMesh.h
@@ -35,7 +35,7 @@ namespace renderscript {
// An element is a group of Components that occupies one cell in a structure.
-class TriangleMesh
+class TriangleMesh : public ObjectBase
{
public:
TriangleMesh();