diff options
author | Alex Sakhartchouk <alexst@google.com> | 2012-01-31 15:22:59 -0800 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2012-01-31 15:22:59 -0800 |
commit | f684c01b7af0229ac6d981c2ee3c14703ef64f76 (patch) | |
tree | 74219dc6ce16f41acffc793a1f55abae9db3a84a /tests/RenderScriptTests/SceneGraph/src | |
parent | 452889a29671e63114dc2ab873597bdc5701f97b (diff) | |
download | frameworks_base-f684c01b7af0229ac6d981c2ee3c14703ef64f76.zip frameworks_base-f684c01b7af0229ac6d981c2ee3c14703ef64f76.tar.gz frameworks_base-f684c01b7af0229ac6d981c2ee3c14703ef64f76.tar.bz2 |
Optimize camera updates from java. Remove duplicate constants.
Change-Id: I4302abc06b1afbfdbbf2f7749d3caa7294c982d1
Diffstat (limited to 'tests/RenderScriptTests/SceneGraph/src')
4 files changed, 65 insertions, 54 deletions
diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java index 55d0fda..b07cd08 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Camera.java @@ -32,40 +32,57 @@ import android.util.Log; public class Camera extends SceneGraphBase { Transform mTransform; - float mFOV; - float mNear; - float mFar; + ScriptField_Camera_s.Item mData; ScriptField_Camera_s mField; public Camera() { - mFOV = 60.0f; - mNear = 0.1f; - mFar = 100.0f; + mData = new ScriptField_Camera_s.Item(); + mData.near = 0.1f; + mData.far = 100.0f; + mData.horizontalFOV = 60.0f; + mData.aspect = 0; } public void setTransform(Transform t) { mTransform = t; - updateRSData(); + if (mField != null) { + mField.set_transformMatrix(0, mTransform.getRSData().getAllocation(), false); + mField.set_isDirty(0, 1, true); + } } public void setFOV(float fov) { - mFOV = fov; - updateRSData(); + mData.horizontalFOV = fov; + if (mField != null) { + mField.set_horizontalFOV(0, fov, false); + mField.set_isDirty(0, 1, true); + } } public void setNear(float n) { - mNear = n; - updateRSData(); + mData.near = n; + if (mField != null) { + mField.set_near(0, n, false); + mField.set_isDirty(0, 1, true); + } } public void setFar(float f) { - mFar = f; - updateRSData(); + mData.far = f; + if (mField != null) { + mField.set_far(0, f, false); + mField.set_isDirty(0, 1, true); + } } public void setName(String n) { super.setName(n); - updateRSData(); + if (mField != null) { + RenderScriptGL rs = SceneManager.getRS(); + mData.name = getNameAlloc(rs); + mField.set_name(0, mData.name, false); + mField.set_isDirty(0, 1, true); + } } ScriptField_Camera_s getRSData() { @@ -78,35 +95,20 @@ public class Camera extends SceneGraphBase { return null; } - mField = new ScriptField_Camera_s(rs, 1); - updateRSData(); - return mField; - } - - void updateRSData() { - if (mField == null) { - return; - } - RenderScriptGL rs = SceneManager.getRS(); - if (rs == null) { - return; - } - if (mTransform == null) { throw new RuntimeException("Cameras without transforms are invalid"); } - ScriptField_Camera_s.Item cam = new ScriptField_Camera_s.Item(); - cam.horizontalFOV = mFOV; - cam.near = mNear; - cam.far = mFar; - cam.aspect = 0; - cam.transformMatrix = mTransform.getRSData().getAllocation(); - cam.transformTimestamp = 1; - cam.timestamp = 1; - cam.isDirty = 1; - cam.name = getNameAlloc(rs); - mField.set(cam, 0, true); + mField = new ScriptField_Camera_s(rs, 1); + + mData.transformMatrix = mTransform.getRSData().getAllocation(); + mData.transformTimestamp = 1; + mData.timestamp = 1; + mData.isDirty = 1; + mData.name = getNameAlloc(rs); + mField.set(mData, 0, true); + + return mField; } } diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java index ad2990a..99dc41c 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/CompoundTransform.java @@ -37,9 +37,8 @@ public class CompoundTransform extends Transform { int mParentIndex; protected ScriptField_TransformComponent_s.Item mData; - Component(int type, String name) { + Component(String name) { mData = new ScriptField_TransformComponent_s.Item(); - mData.type = type; mName = name; } @@ -55,10 +54,7 @@ public class CompoundTransform extends Transform { } } - ScriptField_TransformComponent_s.Item getRSData() { - setNameAlloc(); - return mData; - } + abstract ScriptField_TransformComponent_s.Item getRSData(); protected void update() { if (mParent != null) { @@ -73,7 +69,7 @@ public class CompoundTransform extends Transform { public static class TranslateComponent extends Component { public TranslateComponent(String name, Float3 translate) { - super(RS_ID_TRANSLATE, name); + super(name); setValue(translate); } public Float3 getValue() { @@ -85,11 +81,16 @@ public class CompoundTransform extends Transform { mData.value.z = val.z; update(); } + ScriptField_TransformComponent_s.Item getRSData() { + setNameAlloc(); + mData.type = SceneManager.getConst().get_transform_TRANSLATE(); + return mData; + } } public static class RotateComponent extends Component { public RotateComponent(String name, Float3 axis, float angle) { - super(RS_ID_ROTATE, name); + super(name); setAxis(axis); setAngle(angle); } @@ -109,11 +110,16 @@ public class CompoundTransform extends Transform { mData.value.w = val; update(); } + ScriptField_TransformComponent_s.Item getRSData() { + setNameAlloc(); + mData.type = SceneManager.getConst().get_transform_ROTATE(); + return mData; + } } public static class ScaleComponent extends Component { public ScaleComponent(String name, Float3 scale) { - super(RS_ID_SCALE, name); + super(name); setValue(scale); } public Float3 getValue() { @@ -125,6 +131,11 @@ public class CompoundTransform extends Transform { mData.value.z = val.z; update(); } + ScriptField_TransformComponent_s.Item getRSData() { + setNameAlloc(); + mData.type = SceneManager.getConst().get_transform_SCALE(); + return mData; + } } ScriptField_TransformComponent_s mComponentField; diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java index b434365..8180bd0 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/Transform.java @@ -27,12 +27,6 @@ import android.util.Log; * @hide */ public abstract class Transform extends SceneGraphBase { - - static final int RS_ID_NONE = 0; - static final int RS_ID_TRANSLATE = 1; - static final int RS_ID_ROTATE = 2; - static final int RS_ID_SCALE = 3; - Transform mParent; ArrayList<Transform> mChildren; diff --git a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs index 9cbde61..b066eb7 100644 --- a/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs +++ b/tests/RenderScriptTests/SceneGraph/src/com/android/scenegraph/export.rs @@ -39,6 +39,10 @@ const int shaderParam_FLOAT4_LIGHT_DIR = SHADER_PARAM_FLOAT4_LIGHT_DIR; const int shaderParam_TEXTURE = SHADER_PARAM_TEXTURE; +const int transform_TRANSLATE = TRANSFORM_TRANSLATE; +const int transform_ROTATE = TRANSFORM_ROTATE; +const int transform_SCALE = TRANSFORM_SCALE; + SgTransform *exportPtr; SgTransformComponent *componentPtr; SgRenderState *sExport; |