summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-08-21 21:49:45 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-08-21 21:49:45 +0000
commit00ca97ecf6364e374862263b0f25cf18754d2e2a (patch)
tree7d874308db2eb5440546aa24f012e57174a26f2a
parentc7d009160547ff5ca41cea7c489cd9c5744c7539 (diff)
parent48f0dbe005bf28c1dcc12b900aa39e6e0a0f0b97 (diff)
downloadandroid_packages_wallpapers_Basic-00ca97ecf6364e374862263b0f25cf18754d2e2a.tar.gz
android_packages_wallpapers_Basic-00ca97ecf6364e374862263b0f25cf18754d2e2a.tar.bz2
android_packages_wallpapers_Basic-00ca97ecf6364e374862263b0f25cf18754d2e2a.zip
Merge "Remove live wallpapers." into lmp-dev
-rw-r--r--src/com/android/wallpaper/fall/Fall.java46
-rw-r--r--src/com/android/wallpaper/fall/FallRS.java385
-rw-r--r--src/com/android/wallpaper/fall/FallView.java61
-rw-r--r--src/com/android/wallpaper/fall/FallWallpaper.java26
-rw-r--r--src/com/android/wallpaper/fall/fall.rs382
-rw-r--r--src/com/android/wallpaper/galaxy/Galaxy.java47
-rw-r--r--src/com/android/wallpaper/galaxy/GalaxyRS.java234
-rw-r--r--src/com/android/wallpaper/galaxy/GalaxyView.java44
-rw-r--r--src/com/android/wallpaper/galaxy/GalaxyWallpaper.java25
-rw-r--r--src/com/android/wallpaper/galaxy/galaxy.rs220
-rw-r--r--src/com/android/wallpaper/grass/Grass.java47
-rw-r--r--src/com/android/wallpaper/grass/GrassRS.java380
-rw-r--r--src/com/android/wallpaper/grass/GrassView.java43
-rw-r--r--src/com/android/wallpaper/grass/GrassWallpaper.java27
-rw-r--r--src/com/android/wallpaper/grass/SunCalculator.java307
-rw-r--r--src/com/android/wallpaper/grass/grass.rs465
-rw-r--r--src/com/android/wallpaper/nexus/NexusRS.java198
-rw-r--r--src/com/android/wallpaper/nexus/NexusWallpaper.java26
-rw-r--r--src/com/android/wallpaper/nexus/nexus.rs327
19 files changed, 0 insertions, 3290 deletions
diff --git a/src/com/android/wallpaper/fall/Fall.java b/src/com/android/wallpaper/fall/Fall.java
deleted file mode 100644
index 8813cbf..0000000
--- a/src/com/android/wallpaper/fall/Fall.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.wallpaper.fall;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class Fall extends Activity {
- private FallView mView;
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- mView = new FallView(this);
- setContentView(mView);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mView.resume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mView.pause();
-
- Runtime.getRuntime().exit(0);
- }
-} \ No newline at end of file
diff --git a/src/com/android/wallpaper/fall/FallRS.java b/src/com/android/wallpaper/fall/FallRS.java
deleted file mode 100644
index f527e18..0000000
--- a/src/com/android/wallpaper/fall/FallRS.java
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- * 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.wallpaper.fall;
-
-import android.os.Bundle;
-import android.renderscript.*;
-import static android.renderscript.Sampler.Value.LINEAR;
-import static android.renderscript.Sampler.Value.CLAMP;
-import static android.renderscript.ProgramStore.DepthFunc.*;
-import static android.renderscript.ProgramStore.BlendDstFunc;
-import static android.renderscript.ProgramStore.BlendSrcFunc;
-import static android.renderscript.Element.*;
-
-import android.util.Log;
-
-import android.app.WallpaperManager;
-import android.graphics.BitmapFactory;
-import android.graphics.Bitmap;
-import static android.util.MathUtils.*;
-
-import java.util.TimeZone;
-
-import com.android.wallpaper.R;
-import com.android.wallpaper.RenderScriptScene;
-
-class FallRS extends RenderScriptScene {
- private static final int MESH_RESOLUTION = 48;
-
- private static final int RSID_STATE = 0;
- private static final int RSID_CONSTANTS = 1;
- private static final int RSID_DROP = 2;
-
- private static final int TEXTURES_COUNT = 2;
- private static final int RSID_TEXTURE_RIVERBED = 0;
- private static final int RSID_TEXTURE_LEAVES = 1;
-
- private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
-
- @SuppressWarnings({"FieldCanBeLocal"})
- private ProgramFragment mPfBackground;
- @SuppressWarnings({"FieldCanBeLocal"})
- private ProgramFragment mPfSky;
- @SuppressWarnings({"FieldCanBeLocal"})
- private ProgramStore mPfsBackground;
- @SuppressWarnings({"FieldCanBeLocal"})
- private ProgramStore mPfsLeaf;
- @SuppressWarnings({"FieldCanBeLocal"})
- private ProgramVertex mPvSky;
- @SuppressWarnings({"FieldCanBeLocal"})
- private ProgramVertex mPvWater;
- private ProgramVertexFixedFunction.Constants mPvOrthoAlloc;
- @SuppressWarnings({"FieldCanBeLocal"})
- private Sampler mSampler;
-
- private int mMeshWidth;
- private Allocation mUniformAlloc;
-
- private int mMeshHeight;
- @SuppressWarnings({"FieldCanBeLocal"})
- private Mesh mMesh;
- private WorldState mWorldState;
-
- private ScriptC_fall mScript;
-
- private ScriptField_Constants mConstants;
-
- private float mGlHeight;
-
- public FallRS(int width, int height) {
- super(width, height);
-
- mOptionsARGB.inScaled = false;
- mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
- }
-
- @Override
- public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) {
- mWorldState.xOffset = xOffset;
- mScript.set_g_xOffset(mWorldState.xOffset);
- }
-
- @Override
- public Bundle onCommand(String action, int x, int y, int z, Bundle extras,
- boolean resultRequested) {
- if (WallpaperManager.COMMAND_TAP.equals(action)
- || WallpaperManager.COMMAND_SECONDARY_TAP.equals(action)
- || WallpaperManager.COMMAND_DROP.equals(action)) {
- addDrop(x + (mWorldState.rotate == 0 ? (mWorldState.width * mWorldState.xOffset) : 0), y);
- }
- return null;
- }
-
- @Override
- public void start() {
- super.start();
- final WorldState worldState = mWorldState;
- final int width = worldState.width;
- final int x = width / 4 + (int)(Math.random() * (width / 2));
- final int y = worldState.height / 4 + (int)(Math.random() * (worldState.height / 2));
- addDrop(x + (mWorldState.rotate == 0 ? (width * worldState.xOffset) : 0), y);
- }
-
- @Override
- public void resize(int width, int height) {
- super.resize(width, height);
-
- mWorldState.width = width;
- mWorldState.height = height;
- mWorldState.rotate = width > height ? 1 : 0;
-
- mScript.set_g_glWidth(mWorldState.width);
- mScript.set_g_glHeight(mWorldState.height);
- mScript.set_g_rotate(mWorldState.rotate);
-
- mScript.invoke_initLeaves();
-
- Matrix4f proj = new Matrix4f();
- proj.loadProjectionNormalized(mWidth, mHeight);
- mPvOrthoAlloc.setProjection(proj);
- }
-
- @Override
- protected ScriptC createScript() {
- mScript = new ScriptC_fall(mRS, mResources, R.raw.fall);
-
- createMesh();
- createState();
- createProgramVertex();
- createProgramFragmentStore();
- createProgramFragment();
- loadTextures();
-
- mScript.setTimeZone(TimeZone.getDefault().getID());
-
- mScript.bind_g_Constants(mConstants);
-
- return mScript;
- }
-
- private void createMesh() {
- Mesh.TriangleMeshBuilder tmb = new Mesh.TriangleMeshBuilder(mRS, 2, 0);
-
- final int width = mWidth > mHeight ? mHeight : mWidth;
- final int height = mWidth > mHeight ? mWidth : mHeight;
-
- int wResolution = MESH_RESOLUTION;
- int hResolution = (int) (MESH_RESOLUTION * height / (float) width);
-
- mGlHeight = 2.0f * height / (float) width;
-
- wResolution += 2;
- hResolution += 2;
-
- for (int y = 0; y <= hResolution; y++) {
- final float yOffset = (((float)y / hResolution) * 2.f - 1.f) * height / width;
- for (int x = 0; x <= wResolution; x++) {
- tmb.addVertex(((float)x / wResolution) * 2.f - 1.f, yOffset);
- }
- }
-
- for (int y = 0; y < hResolution; y++) {
- final boolean shift = (y & 0x1) == 0;
- final int yOffset = y * (wResolution + 1);
- for (int x = 0; x < wResolution; x++) {
- final int index = yOffset + x;
- final int iWR1 = index + wResolution + 1;
- if (shift) {
- tmb.addTriangle(index, index + 1, iWR1);
- tmb.addTriangle(index + 1, iWR1 + 1, iWR1);
- } else {
- tmb.addTriangle(index, iWR1 + 1, iWR1);
- tmb.addTriangle(index, index + 1, iWR1 + 1);
- }
- }
- }
-
- mMesh = tmb.create(true);
-
- mMeshWidth = wResolution + 1;
- mMeshHeight = hResolution + 1;
-
- mScript.set_g_WaterMesh(mMesh);
- }
-
- static class WorldState {
- public int frameCount;
- public int width;
- public int height;
- public int meshWidth;
- public int meshHeight;
- public int rippleIndex;
- public float glWidth;
- public float glHeight;
- public float skySpeedX;
- public float skySpeedY;
- public int rotate;
- public int isPreview;
- public float xOffset;
- }
-
- private void createState() {
- mWorldState = new WorldState();
- mWorldState.width = mWidth;
- mWorldState.height = mHeight;
- mWorldState.meshWidth = mMeshWidth;
- mWorldState.meshHeight = mMeshHeight;
- mWorldState.rippleIndex = 0;
- mWorldState.glWidth = 2.0f;
- mWorldState.glHeight = mGlHeight;
- mWorldState.skySpeedX = random(-0.001f, 0.001f);
- mWorldState.skySpeedY = random(0.00008f, 0.0002f);
- mWorldState.rotate = mWidth > mHeight ? 1 : 0;
- mWorldState.isPreview = isPreview() ? 1 : 0;
-
- mScript.set_g_glWidth(mWorldState.glWidth);
- mScript.set_g_glHeight(mWorldState.glHeight);
- mScript.set_g_meshWidth(mWorldState.meshWidth);
- mScript.set_g_meshHeight(mWorldState.meshHeight);
- mScript.set_g_xOffset(0);
- mScript.set_g_rotate(mWorldState.rotate);
- }
-
- private void loadTextures() {
- mScript.set_g_TLeaves(loadTextureARGB(R.drawable.leaves));
- mScript.set_g_TRiverbed(loadTexture(R.drawable.pond));
- }
-
- private Allocation loadTexture(int id) {
- final Allocation allocation = Allocation.createFromBitmapResource(mRS, mResources, id,
- Allocation.MipmapControl.MIPMAP_NONE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
- return allocation;
- }
-
- private Allocation loadTextureARGB(int id) {
- Bitmap b = BitmapFactory.decodeResource(mResources, id, mOptionsARGB);
- final Allocation allocation = Allocation.createFromBitmap(mRS, b,
- Allocation.MipmapControl.MIPMAP_NONE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
- return allocation;
- }
-
- private void createProgramFragment() {
- Sampler.Builder sampleBuilder = new Sampler.Builder(mRS);
- sampleBuilder.setMinification(LINEAR);
- sampleBuilder.setMagnification(LINEAR);
- sampleBuilder.setWrapS(CLAMP);
- sampleBuilder.setWrapT(CLAMP);
- mSampler = sampleBuilder.create();
-
- ProgramFragmentFixedFunction.Builder builder = new ProgramFragmentFixedFunction.Builder(mRS);
- builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
- ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
- mPfBackground = builder.create();
- mPfBackground.bindSampler(mSampler, 0);
-
- mScript.set_g_PFBackground(mPfBackground);
-
- builder = new ProgramFragmentFixedFunction.Builder(mRS);
- builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
- ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
- mPfSky = builder.create();
- mPfSky.bindSampler(mSampler, 0);
-
- mScript.set_g_PFSky(mPfSky);
- }
-
- private void createProgramFragmentStore() {
- ProgramStore.Builder builder = new ProgramStore.Builder(mRS);
- builder.setDepthFunc(ALWAYS);
- builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
- builder.setDitherEnabled(false);
- builder.setDepthMaskEnabled(true);
- mPfsBackground = builder.create();
-
- builder = new ProgramStore.Builder(mRS);
- builder.setDepthFunc(ALWAYS);
- builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
- builder.setDitherEnabled(false);
- builder.setDepthMaskEnabled(true);
- mPfsLeaf = builder.create();
-
- mScript.set_g_PFSLeaf(mPfsLeaf);
- mScript.set_g_PFSBackground(mPfsBackground);
- }
-
- private void createProgramVertex() {
- mPvOrthoAlloc = new ProgramVertexFixedFunction.Constants(mRS);
- Matrix4f proj = new Matrix4f();
- proj.loadProjectionNormalized(mWidth, mHeight);
- mPvOrthoAlloc.setProjection(proj);
-
-
- ProgramVertexFixedFunction.Builder builder = new ProgramVertexFixedFunction.Builder(mRS);
- mPvSky = builder.create();
- ((ProgramVertexFixedFunction)mPvSky).bindConstants(mPvOrthoAlloc);
-
- mScript.set_g_PVSky(mPvSky);
-
- mConstants = new ScriptField_Constants(mRS, 1);
- mUniformAlloc = mConstants.getAllocation();
-
- ProgramVertex.Builder sb = new ProgramVertex.Builder(mRS);
-
- String t = "\n" +
- "varying vec4 varColor;\n" +
- "varying vec2 varTex0;\n" +
-
- "vec2 addDrop(vec4 d, vec2 pos, float dxMul) {\n" +
- " vec2 ret = vec2(0.0, 0.0);\n" +
- " vec2 delta = d.xy - pos;\n" +
- " delta.x *= dxMul;\n" +
- " float dist = length(delta);\n" +
- " if (dist < d.w) { \n" +
- " float amp = d.z * dist;\n" +
- " amp /= d.w * d.w;\n" +
- " amp *= sin(d.w - dist);\n" +
- " ret = delta * amp;\n" +
- " }\n" +
- " return ret;\n" +
- "}\n" +
-
- "void main() {\n" +
- " vec2 pos = ATTRIB_position.xy;\n" +
- " gl_Position = vec4(pos.x, pos.y, 0.0, 1.0);\n" +
- " float dxMul = 1.0;\n" +
-
- " varTex0 = vec2((pos.x + 1.0), (pos.y + 1.6666));\n" +
-
- " if (UNI_Rotate < 0.9) {\n" +
- " varTex0.xy *= vec2(0.25, 0.33);\n" +
- " varTex0.x += UNI_Offset.x * 0.5;\n" +
- " pos.x += UNI_Offset.x * 2.0;\n" +
- " } else {\n" +
- " varTex0.xy *= vec2(0.5, 0.3125);\n" +
- " dxMul = 2.5;\n" +
- " }\n" +
-
- " varColor = vec4(1.0, 1.0, 1.0, 1.0);\n" +
- " pos.xy += vec2(1.0, 1.0);\n" +
- " pos.xy *= vec2(25.0, 42.0);\n" +
-
- " varTex0.xy += addDrop(UNI_Drop01, pos, dxMul);\n" +
- " varTex0.xy += addDrop(UNI_Drop02, pos, dxMul);\n" +
- " varTex0.xy += addDrop(UNI_Drop03, pos, dxMul);\n" +
- " varTex0.xy += addDrop(UNI_Drop04, pos, dxMul);\n" +
- " varTex0.xy += addDrop(UNI_Drop05, pos, dxMul);\n" +
- " varTex0.xy += addDrop(UNI_Drop06, pos, dxMul);\n" +
- " varTex0.xy += addDrop(UNI_Drop07, pos, dxMul);\n" +
- " varTex0.xy += addDrop(UNI_Drop08, pos, dxMul);\n" +
- " varTex0.xy += addDrop(UNI_Drop09, pos, dxMul);\n" +
- " varTex0.xy += addDrop(UNI_Drop10, pos, dxMul);\n" +
- "}\n";
-
- sb.setShader(t);
- sb.addConstant(mUniformAlloc.getType());
- sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
- mPvWater = sb.create();
- mPvWater.bindConstants(mUniformAlloc, 0);
-
- mScript.set_g_PVWater(mPvWater);
-
- }
-
- void addDrop(float x, float y) {
- int dropX = (int) ((x / mWidth) * mMeshWidth);
- int dropY = (int) ((y / mHeight) * mMeshHeight);
-
- mScript.invoke_addDrop(dropX, dropY);
- }
-}
diff --git a/src/com/android/wallpaper/fall/FallView.java b/src/com/android/wallpaper/fall/FallView.java
deleted file mode 100644
index 25f2215..0000000
--- a/src/com/android/wallpaper/fall/FallView.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.wallpaper.fall;
-
-import android.content.Context;
-import android.view.SurfaceHolder;
-import android.view.MotionEvent;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScriptGL;
-import android.renderscript.RSSurfaceView;
-
-class FallView extends RSSurfaceView {
- private FallRS mRender;
-
- public FallView(Context context) {
- super(context);
- setFocusable(true);
- setFocusableInTouchMode(true);
- }
-
- public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- super.surfaceChanged(holder, format, w, h);
-
- RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
- RenderScriptGL RS = createRenderScriptGL(sc);
- mRender = new FallRS(w, h);
- mRender.init(RS, getResources(), false);
- mRender.start();
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- //case MotionEvent.ACTION_MOVE:
- mRender.addDrop(event.getX(), event.getY());
- try {
- Thread.sleep(16);
- } catch (InterruptedException e) {
- // Ignore
- }
- break;
- }
- return true;
- }
-} \ No newline at end of file
diff --git a/src/com/android/wallpaper/fall/FallWallpaper.java b/src/com/android/wallpaper/fall/FallWallpaper.java
deleted file mode 100644
index e96fc0c..0000000
--- a/src/com/android/wallpaper/fall/FallWallpaper.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.wallpaper.fall;
-
-import com.android.wallpaper.RenderScriptWallpaper;
-import com.android.wallpaper.RenderScriptScene;
-
-public class FallWallpaper extends RenderScriptWallpaper {
- protected RenderScriptScene createScene(int width, int height) {
- return new FallRS(width, height);
- }
-}
diff --git a/src/com/android/wallpaper/fall/fall.rs b/src/com/android/wallpaper/fall/fall.rs
deleted file mode 100644
index d1e3446..0000000
--- a/src/com/android/wallpaper/fall/fall.rs
+++ /dev/null
@@ -1,382 +0,0 @@
-// 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)
-
-#pragma rs java_package_name(com.android.wallpaper.fall)
-
-#include "rs_graphics.rsh"
-
-#define LEAVES_TEXTURES_COUNT 8
-#define LEAF_SIZE 0.55f
-#define LEAVES_COUNT 14
-
-// Things we need to set from the application
-float g_glWidth;
-float g_glHeight;
-float g_meshWidth;
-float g_meshHeight;
-float g_xOffset;
-float g_rotate;
-
-rs_program_vertex g_PVWater;
-rs_program_vertex g_PVSky;
-
-rs_program_fragment g_PFSky;
-rs_program_store g_PFSLeaf;
-rs_program_fragment g_PFBackground;
-
-rs_allocation g_TLeaves;
-rs_allocation g_TRiverbed;
-
-rs_mesh g_WaterMesh;
-
-typedef struct Constants {
- float4 Drop01;
- float4 Drop02;
- float4 Drop03;
- float4 Drop04;
- float4 Drop05;
- float4 Drop06;
- float4 Drop07;
- float4 Drop08;
- float4 Drop09;
- float4 Drop10;
- float4 Offset;
- float Rotate;
-} Constants_t;
-
-Constants_t *g_Constants;
-rs_program_store g_PFSBackground;
-
-//float skyOffsetX;
-//float skyOffsetY;
-static float g_DT;
-static int64_t g_LastTime;
-
-typedef struct Drop {
- float ampS;
- float ampE;
- float spread;
- float x;
- float y;
-} Drop_t;
-static Drop_t gDrops[10];
-static int gMaxDrops;
-
-typedef struct Leaves {
- float x;
- float y;
- float scale;
- float angle;
- float spin;
- float u1;
- float u2;
- float altitude;
- float rippled;
- float deltaX;
- float deltaY;
- int newLeaf;
-} Leaves_t;
-
-static Leaves_t gLeavesStore[LEAVES_COUNT];
-static Leaves_t* gLeaves[LEAVES_COUNT];
-static Leaves_t* gNextLeaves[LEAVES_COUNT];
-
-void initLeaves() {
- Leaves_t *leaf = gLeavesStore;
- // globals haven't been set at this point yet. We need to find the correct
- // function index to call this, we can wait until reflection works
- float width = 2; //g_glWidth;
- float height = 3.333; //g_glHeight;
-
- int i;
- for (i = 0; i < LEAVES_COUNT; i ++) {
- gLeaves[i] = leaf;
- int sprite = rsRand(LEAVES_TEXTURES_COUNT);
- leaf->x = rsRand(-width, width);
- leaf->y = rsRand(-height * 0.5f, height * 0.5f);
- leaf->scale = rsRand(0.4f, 0.5f);
- leaf->angle = rsRand(0.0f, 360.0f);
- leaf->spin = degrees(rsRand(-0.02f, 0.02f)) * 0.25f;
- leaf->u1 = (float)sprite / (float) LEAVES_TEXTURES_COUNT;
- leaf->u2 = (float)(sprite + 1) / (float) LEAVES_TEXTURES_COUNT;
- leaf->altitude = -1.0f;
- leaf->rippled = 1.0f;
- leaf->deltaX = rsRand(-0.01f, 0.01f);
- leaf->deltaY = -rsRand(0.036f, 0.044f);
- leaf++;
- }
-}
-
-void init() {
- int ct;
- gMaxDrops = 10;
- for (ct=0; ct<gMaxDrops; ct++) {
- gDrops[ct].ampS = 0;
- gDrops[ct].ampE = 0;
- gDrops[ct].spread = 1;
- }
-
- initLeaves();
- g_LastTime = rsUptimeMillis();
- g_DT = 0.1f;
-}
-
-static void updateDrop(int ct) {
- gDrops[ct].spread += 30.f * g_DT;
- gDrops[ct].ampE = gDrops[ct].ampS / gDrops[ct].spread;
-}
-
-static void drop(int x, int y, float s) {
- int ct;
- int iMin = 0;
- float minAmp = 10000.f;
- for (ct = 0; ct < gMaxDrops; ct++) {
- if (gDrops[ct].ampE < minAmp) {
- iMin = ct;
- minAmp = gDrops[ct].ampE;
- }
- }
- gDrops[iMin].ampS = s;
- gDrops[iMin].spread = 0;
- gDrops[iMin].x = x;
- gDrops[iMin].y = g_meshHeight - y - 1;
- updateDrop(iMin);
-}
-
-static void generateRipples() {
- int ct;
- for (ct = 0; ct < gMaxDrops; ct++) {
- Drop_t * d = &gDrops[ct];
- float *v = (float*)&g_Constants->Drop01;
- v += ct*4;
- *(v++) = d->x;
- *(v++) = d->y;
- *(v++) = d->ampE * 0.12f;
- *(v++) = d->spread;
- }
- g_Constants->Offset.x = g_xOffset;
-
- for (ct = 0; ct < gMaxDrops; ct++) {
- updateDrop(ct);
- }
-}
-
-static void genLeafDrop(Leaves_t *leaf, float amp) {
- float nx = (leaf->x + g_glWidth * 0.5f) / g_glWidth;
- float ny = (leaf->y + g_glHeight * 0.5f) / g_glHeight;
- drop(nx * g_meshWidth, g_meshHeight - ny * g_meshHeight, amp);
-}
-
-static int drawLeaf(Leaves_t *leaf) {
-
- float x = leaf->x;
- float y = leaf->y;
-
- float u1 = leaf->u1;
- float u2 = leaf->u2;
-
- float a = leaf->altitude;
- float s = leaf->scale;
- float r = leaf->angle;
-
- float tz = 0.0f;
- if (a > 0.0f) {
- tz = -a;
- }
-
- rs_matrix4x4 matrix;
- if (a > 0.0f) {
-
- float alpha = 1.0f;
- if (a >= 0.4f) alpha = 1.0f - (a - 0.4f) / 0.1f;
-
- rsgProgramFragmentConstantColor(g_PFSky, 0.0f, 0.0f, 0.0f, alpha * 0.15f);
-
- rsMatrixLoadIdentity(&matrix);
- if (!g_rotate) {
- rsMatrixTranslate(&matrix, x - g_xOffset * 2, y, 0);
- } else {
- rsMatrixTranslate(&matrix, x, y, 0);
- rsMatrixRotate(&matrix, 90.0f, 0.0f, 0.0f, 1.0f);
- }
-
- float shadowOffet = a * 0.2f;
-
- rsMatrixScale(&matrix, s, s, 1.0f);
- rsMatrixRotate(&matrix, r, 0.0f, 0.0f, 1.0f);
- rsgProgramVertexLoadModelMatrix(&matrix);
-
- rsgDrawQuadTexCoords(-LEAF_SIZE, -LEAF_SIZE, 0, u1, 1.0f,
- LEAF_SIZE, -LEAF_SIZE, 0, u2, 1.0f,
- LEAF_SIZE, LEAF_SIZE, 0, u2, 0.0f,
- -LEAF_SIZE, LEAF_SIZE, 0, u1, 0.0f);
-
- rsgProgramFragmentConstantColor(g_PFSky, 1.0f, 1.0f, 1.0f, alpha);
- } else {
- rsgProgramFragmentConstantColor(g_PFSky, 1.0f, 1.0f, 1.0f, 1.0f);
- }
-
- rsMatrixLoadIdentity(&matrix);
- if (!g_rotate) {
- rsMatrixTranslate(&matrix, x - g_xOffset * 2, y, tz);
- } else {
- rsMatrixTranslate(&matrix, x, y, tz);
- rsMatrixRotate(&matrix, 90.0f, 0.0f, 0.0f, 1.0f);
- }
- rsMatrixScale(&matrix, s, s, 1.0f);
- rsMatrixRotate(&matrix, r, 0.0f, 0.0f, 1.0f);
- rsgProgramVertexLoadModelMatrix(&matrix);
-
- rsgDrawQuadTexCoords(-LEAF_SIZE, -LEAF_SIZE, 0, u1, 1.0f,
- LEAF_SIZE, -LEAF_SIZE, 0, u2, 1.0f,
- LEAF_SIZE, LEAF_SIZE, 0, u2, 0.0f,
- -LEAF_SIZE, LEAF_SIZE, 0, u1, 0.0f);
-
- float spin = leaf->spin;
- if (a <= 0.0f) {
- float rippled = leaf->rippled;
- if (rippled < 0.0f) {
- genLeafDrop(leaf, 1.5f);
- //drop(((x + g_glWidth * 0.5f) / g_glWidth) * meshWidth,
- // meshHeight - ((y + g_glHeight * 0.5f) / g_glHeight) * meshHeight, 1);
- spin *= 0.25f;
- leaf->spin = spin;
- leaf->rippled = 1.0f;
- }
- leaf->x = x + leaf->deltaX * g_DT;
- leaf->y = y + leaf->deltaY * g_DT;
- r += spin;
- leaf->angle = r;
- } else {
- a -= 0.15f * g_DT;
- leaf->altitude = a;
- r += spin * 2.0f;
- leaf->angle = r;
- }
-
- int newLeaf = 0;
- if (-LEAF_SIZE * s + x > g_glWidth || LEAF_SIZE * s + x < -g_glWidth ||
- LEAF_SIZE * s + y < -g_glHeight * 0.5f) {
-
- int sprite = rsRand(LEAVES_TEXTURES_COUNT);
-
- leaf->x = rsRand(-g_glWidth, g_glWidth);
- leaf->y = rsRand(-g_glHeight * 0.5f, g_glHeight * 0.5f);
-
- leaf->scale = rsRand(0.4f, 0.5f);
- leaf->spin = degrees(rsRand(-0.02f, 0.02f)) * 0.35f;
- leaf->u1 = sprite / (float) LEAVES_TEXTURES_COUNT;
- leaf->u2 = (sprite + 1) / (float) LEAVES_TEXTURES_COUNT;
- leaf->altitude = 0.7f;
- leaf->rippled = -1.0f;
- leaf->deltaX = rsRand(-0.01f, 0.01f);
- leaf->deltaY = -rsRand(0.036f, 0.044f);
- leaf->newLeaf = 1;
- newLeaf = 1;
- }
- return newLeaf;
-}
-
-static void drawLeaves() {
- rsgBindProgramFragment(g_PFSky);
- rsgBindProgramStore(g_PFSLeaf);
- rsgBindProgramVertex(g_PVSky);
- rsgBindTexture(g_PFSky, 0, g_TLeaves);
-
- int newLeaves = 0;
- int i = 0;
- for ( ; i < LEAVES_COUNT; i += 1) {
- if (drawLeaf(gLeaves[i])) {
- newLeaves = 1;
-
- }
- }
-
- if (newLeaves > 0) {
- int index = 0;
-
- // Copy all the old leaves to the beginning of gNextLeaves
- for (i=0; i < LEAVES_COUNT; i++) {
- if (gLeaves[i]->newLeaf == 0) {
- gNextLeaves[index] = gLeaves[i];
- index++;
- }
- }
-
- // Now copy all the newly falling leaves to the end of gNextLeaves
- for (i=0; i < LEAVES_COUNT; i++) {
- if (gLeaves[i]->newLeaf > 0) {
- gNextLeaves[index] = gLeaves[i];
- gNextLeaves[index]->newLeaf = 0;
- index++;
- }
- }
-
- // And move everything in gNextLeaves back to gLeaves
- for (i=0; i < LEAVES_COUNT; i++) {
- gLeaves[i] = gNextLeaves[i];
- }
- }
-
- rs_matrix4x4 matrix;
- rsMatrixLoadIdentity(&matrix);
- rsgProgramVertexLoadModelMatrix(&matrix);
-}
-
-static void drawRiverbed() {
- rsgBindProgramFragment(g_PFBackground);
- rsgBindProgramStore(g_PFSBackground);
- rsgBindTexture(g_PFBackground, 0, g_TRiverbed);
- rsgDrawMesh(g_WaterMesh);
-}
-
-void addDrop(int x, int y) {
- drop(x, y, 2);
-}
-
-int root(void) {
- rsgClearColor(0.f, 0.f, 0.f, 1.f);
-
- // Compute dt in seconds.
- int64_t newTime = rsUptimeMillis();
- g_DT = (newTime - g_LastTime) * 0.001f;
- g_DT = min(g_DT, 0.2f);
- g_LastTime = newTime;
-
- g_Constants->Rotate = (float) g_rotate;
-
- int ct;
- int add = 0;
- for (ct = 0; ct < gMaxDrops; ct++) {
- if (gDrops[ct].ampE < 0.005f) {
- add = 1;
- }
- }
-
- if (add) {
- int i = (int)rsRand(LEAVES_COUNT);
- genLeafDrop(gLeaves[i], rsRand(0.3f) + 0.1f);
- }
-
- rsgBindProgramVertex(g_PVWater);
- generateRipples();
- rsgAllocationSyncAll(rsGetAllocation(g_Constants));
- drawRiverbed();
-
- drawLeaves();
-
- return 50;
-}
diff --git a/src/com/android/wallpaper/galaxy/Galaxy.java b/src/com/android/wallpaper/galaxy/Galaxy.java
deleted file mode 100644
index 03255f1..0000000
--- a/src/com/android/wallpaper/galaxy/Galaxy.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.wallpaper.galaxy;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class Galaxy extends Activity {
- private GalaxyView mView;
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- mView = new GalaxyView(this);
- setContentView(mView);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mView.resume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mView.pause();
-
- Runtime.getRuntime().exit(0);
- }
-}
diff --git a/src/com/android/wallpaper/galaxy/GalaxyRS.java b/src/com/android/wallpaper/galaxy/GalaxyRS.java
deleted file mode 100644
index 9fba820..0000000
--- a/src/com/android/wallpaper/galaxy/GalaxyRS.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * 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.wallpaper.galaxy;
-
-import android.renderscript.*;
-import android.renderscript.Mesh.Primitive;
-import static android.renderscript.ProgramStore.DepthFunc.*;
-import static android.renderscript.ProgramStore.BlendDstFunc;
-import static android.renderscript.ProgramStore.BlendSrcFunc;
-import static android.renderscript.Element.*;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-
-import java.util.TimeZone;
-
-import com.android.wallpaper.R;
-import com.android.wallpaper.RenderScriptScene;
-
-class GalaxyRS extends RenderScriptScene {
- private static final int PARTICLES_COUNT = 12000;
- private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
- private ProgramVertexFixedFunction.Constants mPvOrthoAlloc;
- private ProgramVertexFixedFunction.Constants mPvProjectionAlloc;
- private ScriptField_VpConsts mPvStarAlloc;
- private Mesh mParticlesMesh;
- private ScriptC_galaxy mScript;
-
- GalaxyRS(int width, int height) {
- super(width, height);
-
- mOptionsARGB.inScaled = false;
- mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
- }
-
- @Override
- protected ScriptC createScript() {
- mScript = new ScriptC_galaxy(mRS, mResources, R.raw.galaxy);
- mScript.set_gIsPreview(isPreview() ? 1 : 0);
- if (isPreview()) {
- mScript.set_gXOffset(0.5f);
- }
-
-
- createParticlesMesh();
- createProgramVertex();
- createProgramRaster();
- createProgramFragmentStore();
- createProgramFragment();
- loadTextures();
-
- mScript.setTimeZone(TimeZone.getDefault().getID());
- return mScript;
- }
-
- private void createParticlesMesh() {
- ScriptField_Particle p = new ScriptField_Particle(mRS, PARTICLES_COUNT);
-
- final Mesh.AllocationBuilder meshBuilder = new Mesh.AllocationBuilder(mRS);
- meshBuilder.addVertexAllocation(p.getAllocation());
- final int vertexSlot = meshBuilder.getCurrentVertexTypeIndex();
- meshBuilder.addIndexSetType(Primitive.POINT);
- mParticlesMesh = meshBuilder.create();
-
- mScript.set_gParticlesMesh(mParticlesMesh);
- mScript.bind_Particles(p);
- }
-
- private Matrix4f getProjectionNormalized(int w, int h) {
- // range -1,1 in the narrow axis at z = 0.
- Matrix4f m1 = new Matrix4f();
- Matrix4f m2 = new Matrix4f();
-
- 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);
- return m1;
- }
-
- private void updateProjectionMatrices() {
- Matrix4f proj = new Matrix4f();
- proj.loadOrthoWindow(mWidth, mHeight);
- mPvOrthoAlloc.setProjection(proj);
-
- Matrix4f projNorm = getProjectionNormalized(mWidth, mHeight);
- ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
- i.Proj = projNorm;
- i.MVP = projNorm;
- mPvStarAlloc.set(i, 0, true);
- mPvProjectionAlloc.setProjection(projNorm);
- }
-
- @Override
- public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) {
- mScript.set_gXOffset(xOffset);
- }
-
- @Override
- public void resize(int width, int height) {
- super.resize(width, height);
-
- updateProjectionMatrices();
- }
-
- private void loadTextures() {
- mScript.set_gTSpace(loadTexture(R.drawable.space));
- mScript.set_gTLight1(loadTexture(R.drawable.light1));
- mScript.set_gTFlares(loadTextureARGB(R.drawable.flares));
- }
-
- private Allocation loadTexture(int id) {
- final Allocation allocation = Allocation.createFromBitmapResource(mRS, mResources, id,
- Allocation.MipmapControl.MIPMAP_NONE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
- return allocation;
- }
-
- // TODO: Fix Allocation.createFromBitmapResource() to do this when RGBA_8888 is specified
- private Allocation loadTextureARGB(int id) {
- Bitmap b = BitmapFactory.decodeResource(mResources, id, mOptionsARGB);
- final Allocation allocation = Allocation.createFromBitmap(mRS, b,
- Allocation.MipmapControl.MIPMAP_NONE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
- return allocation;
- }
-
- private void createProgramFragment() {
- ProgramFragmentFixedFunction.Builder builder = new ProgramFragmentFixedFunction.Builder(mRS);
- builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
- ProgramFragmentFixedFunction.Builder.Format.RGB, 0);
- ProgramFragment pfb = builder.create();
- pfb.bindSampler(Sampler.WRAP_NEAREST(mRS), 0);
- mScript.set_gPFBackground(pfb);
-
- builder = new ProgramFragmentFixedFunction.Builder(mRS);
- builder.setPointSpriteTexCoordinateReplacement(true);
- builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
- ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
- builder.setVaryingColor(true);
- ProgramFragment pfs = builder.create();
- pfs.bindSampler(Sampler.WRAP_LINEAR(mRS), 0);
- mScript.set_gPFStars(pfs);
- }
-
- private void createProgramFragmentStore() {
- ProgramStore.Builder builder = new ProgramStore.Builder(mRS);
- builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ZERO);
- mRS.bindProgramStore(builder.create());
-
- builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE);
- mScript.set_gPSLights(builder.create());
- }
-
- private void createProgramVertex() {
- mPvOrthoAlloc = new ProgramVertexFixedFunction.Constants(mRS);
-
- ProgramVertexFixedFunction.Builder builder = new ProgramVertexFixedFunction.Builder(mRS);
- ProgramVertex pvbo = builder.create();
- ((ProgramVertexFixedFunction)pvbo).bindConstants(mPvOrthoAlloc);
- mRS.bindProgramVertex(pvbo);
-
- mPvStarAlloc = new ScriptField_VpConsts(mRS, 1);
- mScript.bind_vpConstants(mPvStarAlloc);
- mPvProjectionAlloc = new ProgramVertexFixedFunction.Constants(mRS);
- updateProjectionMatrices();
-
- builder = new ProgramVertexFixedFunction.Builder(mRS);
- ProgramVertex pvbp = builder.create();
- ((ProgramVertexFixedFunction)pvbp).bindConstants(mPvProjectionAlloc);
- mScript.set_gPVBkProj(pvbp);
-
- ProgramVertex.Builder sb = new ProgramVertex.Builder(mRS);
- String t = "varying vec4 varColor;\n" +
- "varying vec2 varTex0;\n" +
- "void main() {\n" +
- " float dist = ATTRIB_position.y;\n" +
- " float angle = ATTRIB_position.x;\n" +
- " float x = dist * sin(angle);\n" +
- " float y = dist * cos(angle) * 0.892;\n" +
- " float p = dist * 5.5;\n" +
- " float s = cos(p);\n" +
- " float t = sin(p);\n" +
- " vec4 pos;\n" +
- " pos.x = t * x + s * y;\n" +
- " pos.y = s * x - t * y;\n" +
- " pos.z = ATTRIB_position.z;\n" +
- " pos.w = 1.0;\n" +
- " gl_Position = UNI_MVP * pos;\n" +
- " gl_PointSize = ATTRIB_color.a * 10.0;\n" +
- " varColor.rgb = ATTRIB_color.rgb;\n" +
- " varColor.a = 1.0;\n" +
- "}\n";
- sb.setShader(t);
- sb.addInput(mParticlesMesh.getVertexAllocation(0).getType().getElement());
- sb.addConstant(mPvStarAlloc.getType());
- ProgramVertex pvs = sb.create();
- pvs.bindConstants(mPvStarAlloc.getAllocation(), 0);
- mScript.set_gPVStars(pvs);
- }
-
- private void createProgramRaster() {
- ProgramRaster.Builder b = new ProgramRaster.Builder(mRS);
- b.setPointSpriteEnabled(true);
- ProgramRaster pr = b.create();
- mRS.bindProgramRaster(pr);
- }
-
-}
diff --git a/src/com/android/wallpaper/galaxy/GalaxyView.java b/src/com/android/wallpaper/galaxy/GalaxyView.java
deleted file mode 100644
index 38c4e5e..0000000
--- a/src/com/android/wallpaper/galaxy/GalaxyView.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.wallpaper.galaxy;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScriptGL;
-import android.content.Context;
-import android.view.SurfaceHolder;
-
-class GalaxyView extends RSSurfaceView {
-
- public GalaxyView(Context context) {
- super(context);
- setFocusable(true);
- setFocusableInTouchMode(true);
- }
-
- public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- super.surfaceChanged(holder, format, w, h);
-
- RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
- RenderScriptGL RS = createRenderScriptGL(sc);
- GalaxyRS render = new GalaxyRS(w, h);
- render.init(RS, getResources(), false);
- render.setOffset(0.5f, 0.0f, 0, 0);
- render.start();
- }
-}
-
diff --git a/src/com/android/wallpaper/galaxy/GalaxyWallpaper.java b/src/com/android/wallpaper/galaxy/GalaxyWallpaper.java
deleted file mode 100644
index 1c86eea..0000000
--- a/src/com/android/wallpaper/galaxy/GalaxyWallpaper.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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.wallpaper.galaxy;
-
-import com.android.wallpaper.RenderScriptWallpaper;
-
-public class GalaxyWallpaper extends RenderScriptWallpaper<GalaxyRS> {
- protected GalaxyRS createScene(int width, int height) {
- return new GalaxyRS(width, height);
- }
-}
diff --git a/src/com/android/wallpaper/galaxy/galaxy.rs b/src/com/android/wallpaper/galaxy/galaxy.rs
deleted file mode 100644
index 7f78aa8..0000000
--- a/src/com/android/wallpaper/galaxy/galaxy.rs
+++ /dev/null
@@ -1,220 +0,0 @@
-// 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)
-
-#pragma rs java_package_name(com.android.wallpaper.galaxy)
-
-#include "rs_graphics.rsh"
-
-#pragma stateVertex(parent);
-#pragma stateStore(parent);
-
-#define ELLIPSE_RATIO 0.892f
-#define PI 3.1415f
-#define TWO_PI 6.283f
-#define ELLIPSE_TWIST 0.023333333f
-
-static float angle = 50.f;
-static int gOldWidth;
-static int gOldHeight;
-static int gWidth;
-static int gHeight;
-static float gSpeed[12000];
-static int gGalaxyRadius = 300;
-static rs_allocation gParticlesBuffer;
-
-float gXOffset;
-int gIsPreview;
-
-rs_program_fragment gPFBackground;
-rs_program_fragment gPFStars;
-rs_program_vertex gPVStars;
-rs_program_vertex gPVBkProj;
-rs_program_store gPSLights;
-
-rs_allocation gTSpace;
-rs_allocation gTFlares;
-rs_allocation gTLight1;
-rs_mesh gParticlesMesh;
-
-typedef struct __attribute__((packed, aligned(4))) Particle {
- uchar4 color;
- float3 position;
-} Particle_t;
-Particle_t *Particles;
-
-typedef struct VpConsts {
- rs_matrix4x4 Proj;
- rs_matrix4x4 MVP;
-} VpConsts_t;
-VpConsts_t *vpConstants;
-
-static float mapf(float minStart, float minStop, float maxStart, float maxStop, float value) {
- return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
-}
-
-/**
- * Helper function to generate the stars.
- */
-static float randomGauss() {
- float x1;
- float x2;
- float w = 2.f;
-
- while (w >= 1.0f) {
- x1 = rsRand(2.0f) - 1.0f;
- x2 = rsRand(2.0f) - 1.0f;
- w = x1 * x1 + x2 * x2;
- }
-
- w = sqrt(-2.0f * log(w) / w);
- return x1 * w;
-}
-
-/**
- * Generates the properties for a given star.
- */
-static void createParticle(Particle_t *part, int idx, float scale) {
- float d = fabs(randomGauss()) * gGalaxyRadius * 0.5f + rsRand(64.0f);
- float id = d / gGalaxyRadius;
- float z = randomGauss() * 0.4f * (1.0f - id);
- float p = -d * ELLIPSE_TWIST;
-
- if (d < gGalaxyRadius * 0.33f) {
- part->color.x = (uchar) (220 + id * 35);
- part->color.y = 220;
- part->color.z = 220;
- } else {
- part->color.x = 180;
- part->color.y = 180;
- part->color.z = (uchar) clamp(140.f + id * 115.f, 140.f, 255.f);
- }
- // Stash point size * 10 in Alpha
- part->color.w = (uchar) (rsRand(1.2f, 2.1f) * 60);
-
- if (d > gGalaxyRadius * 0.15f) {
- z *= 0.6f * (1.0f - id);
- } else {
- z *= 0.72f;
- }
-
- // Map to the projection coordinates (viewport.x = -1.0 -> 1.0)
- d = mapf(-4.0f, gGalaxyRadius + 4.0f, 0.0f, scale, d);
-
- part->position.x = rsRand(TWO_PI);
- part->position.y = d;
- gSpeed[idx] = rsRand(0.0015f, 0.0025f) * (0.5f + (scale / d)) * 0.8f;
-
- part->position.z = z / 5.0f;
-}
-
-/**
- * Initialize all the stars. Called from Java.
- */
-void initParticles() {
- if (gIsPreview == 1) {
- angle = 0.0f;
- }
-
- Particle_t *part = Particles;
- float scale = gGalaxyRadius / (gWidth * 0.5f);
- int count = rsAllocationGetDimX(gParticlesBuffer);
- for (int i = 0; i < count; i ++) {
- createParticle(part, i, scale);
- part++;
- }
-}
-
-static void drawSpace() {
- rsgBindProgramFragment(gPFBackground);
- rsgBindTexture(gPFBackground, 0, gTSpace);
- rsgDrawQuadTexCoords(
- 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
- gWidth, 0.0f, 0.0f, 2.0f, 1.0f,
- gWidth, gHeight, 0.0f, 2.0f, 0.0f,
- 0.0f, gHeight, 0.0f, 0.0f, 0.0f);
-}
-
-static void calcMatrix(rs_matrix4x4 *out, float offset) {
- float a = offset * angle;
- float absoluteAngle = fabs(a);
-
- rsMatrixLoadTranslate(out, 0.0f, 0.0f, 10.0f - 6.0f * absoluteAngle / 50.0f);
- if (gHeight > gWidth) {
- rsMatrixScale(out, 6.6f, 6.0f, 1.0f);
- } else {
- rsMatrixScale(out, 12.6f, 12.0f, 1.0f);
- }
- rsMatrixRotate(out, absoluteAngle, 1.0f, 0.0f, 0.0f);
- rsMatrixRotate(out, a, 0.0f, 0.4f, 0.1f);
-}
-
-static void drawLights(const rs_matrix4x4 *m) {
- rsgBindProgramVertex(gPVBkProj);
- rsgBindProgramFragment(gPFBackground);
- rsgBindTexture(gPFBackground, 0, gTLight1);
- rsgProgramVertexLoadModelMatrix(m);
-
- float sx = (512.0f / gWidth) * 1.1f;
- float sy = (512.0f / gWidth) * 1.2f;
- rsgDrawQuad(-sx, -sy, 0.0f,
- sx, -sy, 0.0f,
- sx, sy, 0.0f,
- -sx, sy, 0.0f);
-}
-
-static void drawParticles(const rs_matrix4x4 *m) {
- rsMatrixLoad(&vpConstants->MVP, &vpConstants->Proj);
- rsMatrixMultiply(&vpConstants->MVP, m);
- rsgAllocationSyncAll(rsGetAllocation(vpConstants));
-
- rsgBindProgramVertex(gPVStars);
- rsgBindProgramFragment(gPFStars);
- rsgBindProgramStore(gPSLights);
- rsgBindTexture(gPFStars, 0, gTFlares);
-
- Particle_t *vtx = Particles;
- int count = rsAllocationGetDimX(gParticlesBuffer);
- for (int i = 0; i < count; i++) {
- vtx->position.x = vtx->position.x + gSpeed[i];
- vtx++;
- }
-
- rsgDrawMesh(gParticlesMesh);
-}
-
-int root() {
- rsgClearColor(0.f, 0.f, 0.f, 1.f);
-
- gParticlesBuffer = rsGetAllocation(Particles);
- rsgBindProgramFragment(gPFBackground);
-
- gWidth = rsgGetWidth();
- gHeight = rsgGetHeight();
- if ((gWidth != gOldWidth) || (gHeight != gOldHeight)) {
- initParticles();
- gOldWidth = gWidth;
- gOldHeight = gHeight;
- }
-
- drawSpace();
-
- rs_matrix4x4 matrix;
- calcMatrix(&matrix, mix(-0.5f, 0.5f, gXOffset));
- drawParticles(&matrix);
- drawLights(&matrix);
-
- return 45;
-}
diff --git a/src/com/android/wallpaper/grass/Grass.java b/src/com/android/wallpaper/grass/Grass.java
deleted file mode 100644
index 5083b27..0000000
--- a/src/com/android/wallpaper/grass/Grass.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.wallpaper.grass;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class Grass extends Activity {
- private GrassView mView;
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- mView = new GrassView(this);
- setContentView(mView);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mView.resume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mView.pause();
-
- Runtime.getRuntime().exit(0);
- }
-} \ No newline at end of file
diff --git a/src/com/android/wallpaper/grass/GrassRS.java b/src/com/android/wallpaper/grass/GrassRS.java
deleted file mode 100644
index 30bc851..0000000
--- a/src/com/android/wallpaper/grass/GrassRS.java
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * 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.wallpaper.grass;
-
-import android.renderscript.Sampler;
-import static android.renderscript.ProgramStore.DepthFunc.*;
-import static android.renderscript.ProgramStore.BlendSrcFunc;
-import static android.renderscript.ProgramStore.BlendDstFunc;
-import android.renderscript.*;
-import static android.renderscript.Element.*;
-import static android.util.MathUtils.*;
-import android.renderscript.Mesh.Primitive;
-import static android.renderscript.Sampler.Value.*;
-import android.content.Context;
-import android.content.IntentFilter;
-import android.content.Intent;
-import android.content.BroadcastReceiver;
-import android.location.LocationManager;
-import android.location.LocationListener;
-import android.location.Location;
-import android.os.Bundle;
-import android.text.format.Time;
-import com.android.wallpaper.R;
-import com.android.wallpaper.RenderScriptScene;
-
-import java.util.TimeZone;
-import java.util.Calendar;
-
-class GrassRS extends RenderScriptScene {
- @SuppressWarnings({"UnusedDeclaration"})
- private static final String LOG_TAG = "Grass";
- private static final boolean DEBUG = false;
-
- private static final int LOCATION_UPDATE_MIN_TIME = DEBUG ? 5 * 60 * 1000 : 60 * 60 * 1000; // 1 hour
- private static final int LOCATION_UPDATE_MIN_DISTANCE = DEBUG ? 10 : 150 * 1000; // 150 km
- private static final float TESSELATION = 0.5f;
- private static final int TEXTURES_COUNT = 5;
- private static final int BLADES_COUNT = 200;
-
- private ScriptField_Blade mBlades;
- private ScriptField_Vertex mVertexBuffer;
- private ProgramVertexFixedFunction.Constants mPvOrthoAlloc;
-
- //private Allocation mBladesBuffer;
- private Allocation mBladesIndicies;
- private Mesh mBladesMesh;
-
- private ScriptC_grass mScript;
-
- private int mVerticies;
- private int mIndicies;
- private int[] mBladeSizes;
-
- private final Context mContext;
- private final LocationManager mLocationManager;
-
- private LocationUpdater mLocationUpdater;
- private GrassRS.TimezoneTracker mTimezoneTracker;
-
- GrassRS(Context context, int width, int height) {
- super(width, height);
-
- mContext = context;
- mLocationManager = (LocationManager)
- context.getSystemService(Context.LOCATION_SERVICE);
- }
-
- @Override
- public void start() {
- super.start();
-
- if (mTimezoneTracker == null) {
- mTimezoneTracker = new TimezoneTracker();
- IntentFilter filter = new IntentFilter();
- filter.addAction(Intent.ACTION_DATE_CHANGED);
- filter.addAction(Intent.ACTION_TIME_CHANGED);
- filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
-
- mContext.registerReceiver(mTimezoneTracker, filter);
- }
-
- if (mLocationUpdater == null) {
- mLocationUpdater = new LocationUpdater();
- try {
- mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
- LOCATION_UPDATE_MIN_TIME, LOCATION_UPDATE_MIN_DISTANCE, mLocationUpdater);
- } catch (java.lang.IllegalArgumentException e) {
- if (!e.getMessage().equals("provider=network")) {
- throw e;
- }
- }
- }
-
- updateLocation();
- }
-
- @Override
- public void stop() {
- super.stop();
-
- if (mTimezoneTracker != null) {
- mContext.unregisterReceiver(mTimezoneTracker);
- mTimezoneTracker = null;
- }
-
- if (mLocationUpdater != null) {
- mLocationManager.removeUpdates(mLocationUpdater);
- mLocationUpdater = null;
- }
- }
-
- @Override
- public void resize(int width, int height) {
- super.resize(width, height);
-
- mScript.set_gWidth(width);
- mScript.set_gHeight(height);
- mScript.invoke_updateBlades();
- Matrix4f proj = new Matrix4f();
- proj.loadOrthoWindow(width, height);
- mPvOrthoAlloc.setProjection(proj);
- }
-
- @Override
- protected ScriptC createScript() {
- mScript = new ScriptC_grass(mRS, mResources, R.raw.grass);
-
- final boolean isPreview = isPreview();
- createProgramVertex();
- createProgramFragmentStore();
- loadTextures();
- createProgramFragment();
- createBlades();
-
- mScript.set_gBladesCount(BLADES_COUNT);
- mScript.set_gIndexCount(mIndicies);
- mScript.set_gWidth(mWidth);
- mScript.set_gHeight(mHeight);
- mScript.set_gXOffset(isPreview ? 0.5f : 0.f);
- mScript.set_gIsPreview(isPreview ? 1 : 0);
- mScript.set_gBladesMesh(mBladesMesh);
-
- mScript.setTimeZone(TimeZone.getDefault().getID());
- mScript.bind_Blades(mBlades);
- mScript.bind_Verticies(mVertexBuffer);
-
- // set these to reasonable defaults.
- mScript.set_gDawn(6.f / 24.f);
- mScript.set_gDusk(18.f / 24.f);
- mScript.set_gMorning(8.f / 24.f); // 2 hours for sunrise
- mScript.set_gAfternoon(16.f / 24.f); // 2 hours for sunset
-
- return mScript;
- }
-
- @Override
- public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) {
- mScript.set_gXOffset(xOffset);
- }
-
- private void createBlades() {
- mVerticies = 0;
- mIndicies = 0;
-
- mBlades = new ScriptField_Blade(mRS, BLADES_COUNT);
-
- mBladeSizes = new int[BLADES_COUNT];
- for (int i = 0; i < BLADES_COUNT; i++) {
- ScriptField_Blade.Item item = new ScriptField_Blade.Item();
- createBlade(item);
- mBlades.set(item, i, false);
-
- mIndicies += item.size * 2 * 3;
- mVerticies += item.size + 2;
- mBladeSizes[i] = item.size;
- }
- mBlades.copyAll();
-
- createMesh();
- }
-
- private void createMesh() {
- mVertexBuffer = new ScriptField_Vertex(mRS, mVerticies * 2);
-
- final Mesh.AllocationBuilder meshBuilder = new Mesh.AllocationBuilder(mRS);
- meshBuilder.addVertexAllocation(mVertexBuffer.getAllocation());
-
- mBladesIndicies = Allocation.createSized(mRS, Element.U16(mRS), mIndicies);
- meshBuilder.addIndexSetAllocation(mBladesIndicies, Primitive.TRIANGLE);
-
- mBladesMesh = meshBuilder.create();
-
- short[] idx = new short[mIndicies];
- int idxIdx = 0;
- int vtxIdx = 0;
- for (int i = 0; i < mBladeSizes.length; i++) {
- for (int ct = 0; ct < mBladeSizes[i]; ct ++) {
- idx[idxIdx + 0] = (short)(vtxIdx + 0);
- idx[idxIdx + 1] = (short)(vtxIdx + 1);
- idx[idxIdx + 2] = (short)(vtxIdx + 2);
- idx[idxIdx + 3] = (short)(vtxIdx + 1);
- idx[idxIdx + 4] = (short)(vtxIdx + 3);
- idx[idxIdx + 5] = (short)(vtxIdx + 2);
- idxIdx += 6;
- vtxIdx += 2;
- }
- vtxIdx += 2;
- }
-
- mBladesIndicies.copyFrom(idx);
- }
-
- private void createBlade(ScriptField_Blade.Item blades) {
- final float size = random(4.0f) + 4.0f;
- final int xpos = random(-mWidth, mWidth);
-
- //noinspection PointlessArithmeticExpression
- blades.angle = 0.0f;
- blades.size = (int)(size / TESSELATION);
- blades.xPos = xpos;
- blades.yPos = mHeight;
- blades.offset = random(0.2f) - 0.1f;
- blades.scale = 4.0f / (size / TESSELATION) + (random(0.6f) + 0.2f) * TESSELATION;
- blades.lengthX = (random(4.5f) + 3.0f) * TESSELATION * size;
- blades.lengthY = (random(5.5f) + 2.0f) * TESSELATION * size;
- blades.hardness = (random(1.0f) + 0.2f) * TESSELATION;
- blades.h = random(0.02f) + 0.2f;
- blades.s = random(0.22f) + 0.78f;
- blades.b = random(0.65f) + 0.35f;
- blades.turbulencex = xpos * 0.006f;
- }
-
- private void loadTextures() {
- mScript.set_gTNight(loadTexture(R.drawable.night));
- mScript.set_gTSunrise(loadTexture(R.drawable.sunrise));
- mScript.set_gTSky(loadTexture(R.drawable.sky));
- mScript.set_gTSunset(loadTexture(R.drawable.sunset));
- mScript.set_gTAa(generateTextureAlpha());
- }
-
- private Allocation generateTextureAlpha() {
- final Type.Builder builder = new Type.Builder(mRS, A_8(mRS));
- builder.setX(4);
- builder.setY(1);
- builder.setMipmaps(true);
-
- final Allocation allocation = Allocation.createTyped(mRS, builder.create(),
- Allocation.USAGE_GRAPHICS_TEXTURE);
- byte[] mip0 = new byte[] {0, -1, -1, 0};
- byte[] mip1 = new byte[] {64, 64};
- byte[] mip2 = new byte[] {0};
-
- AllocationAdapter a = AllocationAdapter.create2D(mRS, allocation);
- a.setLOD(0);
- a.copyFrom(mip0);
- a.setLOD(1);
- a.copyFrom(mip1);
- a.setLOD(2);
- a.copyFrom(mip2);
-
- return allocation;
- }
-
- private Allocation loadTexture(int id) {
- return Allocation.createFromBitmapResource(mRS, mResources, id,
- Allocation.MipmapControl.MIPMAP_NONE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
- }
-
- private void createProgramFragment() {
- Sampler.Builder samplerBuilder = new Sampler.Builder(mRS);
- samplerBuilder.setMinification(LINEAR_MIP_LINEAR);
- samplerBuilder.setMagnification(LINEAR);
- samplerBuilder.setWrapS(WRAP);
- samplerBuilder.setWrapT(WRAP);
- Sampler sl = samplerBuilder.create();
-
- samplerBuilder.setMinification(NEAREST);
- samplerBuilder.setMagnification(NEAREST);
- Sampler sn = samplerBuilder.create();
-
- ProgramFragmentFixedFunction.Builder builder = new ProgramFragmentFixedFunction.Builder(mRS);
- builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
- ProgramFragmentFixedFunction.Builder.Format.ALPHA, 0);
- builder.setVaryingColor(true);
- ProgramFragment pf = builder.create();
- mScript.set_gPFGrass(pf);
- pf.bindSampler(sl, 0);
-
- builder = new ProgramFragmentFixedFunction.Builder(mRS);
- builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
- ProgramFragmentFixedFunction.Builder.Format.RGB, 0);
- pf = builder.create();
- mScript.set_gPFBackground(pf);
- pf.bindSampler(sn, 0);
- }
-
- private void createProgramFragmentStore() {
- ProgramStore.Builder builder = new ProgramStore.Builder(mRS);
- builder.setDepthFunc(ALWAYS);
- builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
- builder.setDitherEnabled(false);
- builder.setDepthMaskEnabled(false);
- mScript.set_gPSBackground(builder.create());
- }
-
- private void createProgramVertex() {
- mPvOrthoAlloc = new ProgramVertexFixedFunction.Constants(mRS);
- Matrix4f proj = new Matrix4f();
- proj.loadOrthoWindow(mWidth, mHeight);
- mPvOrthoAlloc.setProjection(proj);
-
- ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
- ProgramVertex pv = pvb.create();
- ((ProgramVertexFixedFunction)pv).bindConstants(mPvOrthoAlloc);
- mScript.set_gPVBackground(pv);
- }
-
- private void updateLocation() {
- updateLocation(mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
- }
-
- private void updateLocation(Location location) {
- float dawn = 0.3f;
- float dusk = 0.75f;
-
- if (location != null) {
- final String timeZone = Time.getCurrentTimezone();
- final SunCalculator calculator = new SunCalculator(location, timeZone);
- final Calendar now = Calendar.getInstance();
-
- final double sunrise = calculator.computeSunriseTime(SunCalculator.ZENITH_CIVIL, now);
- dawn = SunCalculator.timeToDayFraction(sunrise);
-
- final double sunset = calculator.computeSunsetTime(SunCalculator.ZENITH_CIVIL, now);
- dusk = SunCalculator.timeToDayFraction(sunset);
- }
-
- mScript.set_gDawn(dawn);
- mScript.set_gDusk(dusk);
- mScript.set_gMorning(dawn + 1.0f / 12.0f); // 2 hours for sunrise
- mScript.set_gAfternoon(dusk - 1.0f / 12.0f); // 2 hours for sunset
- }
-
- private class LocationUpdater implements LocationListener {
- public void onLocationChanged(Location location) {
- updateLocation(location);
- }
-
- public void onStatusChanged(String provider, int status, Bundle extras) {
- }
-
- public void onProviderEnabled(String provider) {
- }
-
- public void onProviderDisabled(String provider) {
- }
- }
-
- private class TimezoneTracker extends BroadcastReceiver {
- public void onReceive(Context context, Intent intent) {
- getScript().setTimeZone(Time.getCurrentTimezone());
- updateLocation();
- }
- }
-}
diff --git a/src/com/android/wallpaper/grass/GrassView.java b/src/com/android/wallpaper/grass/GrassView.java
deleted file mode 100644
index bd920ce..0000000
--- a/src/com/android/wallpaper/grass/GrassView.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.wallpaper.grass;
-
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScriptGL;
-import android.content.Context;
-import android.view.SurfaceHolder;
-
-class GrassView extends RSSurfaceView {
-
- public GrassView(Context context) {
- super(context);
- setFocusable(true);
- setFocusableInTouchMode(true);
- }
-
- public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- super.surfaceChanged(holder, format, w, h);
-
- RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
- RenderScriptGL RS = createRenderScriptGL(sc);
- GrassRS render = new GrassRS(getContext(), w, h);
- render.init(RS, getResources(), false);
- render.setOffset(0.5f, 0.0f, 0, 0);
- render.start();
- }
-} \ No newline at end of file
diff --git a/src/com/android/wallpaper/grass/GrassWallpaper.java b/src/com/android/wallpaper/grass/GrassWallpaper.java
deleted file mode 100644
index 01329a8..0000000
--- a/src/com/android/wallpaper/grass/GrassWallpaper.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.wallpaper.grass;
-
-import com.android.wallpaper.RenderScriptWallpaper;
-import com.android.wallpaper.RenderScriptScene;
-
-public class GrassWallpaper extends RenderScriptWallpaper {
- protected RenderScriptScene createScene(int width, int height) {
- return new GrassRS(this, width, height);
- }
-}
-
diff --git a/src/com/android/wallpaper/grass/SunCalculator.java b/src/com/android/wallpaper/grass/SunCalculator.java
deleted file mode 100644
index 7bf730c..0000000
--- a/src/com/android/wallpaper/grass/SunCalculator.java
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Based on sunrisesunsetlib-java:
- * Copyright 2008-2009 Mike Reedell / LuckyCatLabs.
- *
- * Original project and source can be found at:
- * http://mikereedell.github.com/sunrisesunsetlib-java/
- *
- * 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.wallpaper.grass;
-
-import java.util.Calendar;
-import java.util.TimeZone;
-
-import android.location.Location;
-
-class SunCalculator {
- /** Astronomical sunrise/set is when the sun is 18 degrees below the horizon. */
- static final double ZENITH_ASTRONOMICAL = 108;
-
- /** Nautical sunrise/set is when the sun is 12 degrees below the horizon. */
- static final double ZENITH_NAUTICAL = 102;
-
- /** Civil sunrise/set (dawn/dusk) is when the sun is 6 degrees below the horizon. */
- static final double ZENITH_CIVIL = 96;
-
- /** Official sunrise/set is when the sun is 50' below the horizon. */
- static final double ZENITH_OFFICIAL = 90.8333;
-
- private Location mLocation;
- private TimeZone mTimeZone;
-
- SunCalculator(Location location, String timeZoneIdentifier) {
- mLocation = location;
- mTimeZone = TimeZone.getTimeZone(timeZoneIdentifier);
- }
-
- public void setLocation(Location location) {
- mLocation = location;
- }
-
- /**
- * Computes the sunrise time for the given zenith at the given date.
- *
- * @param solarZenith <code>Zenith</code> enum corresponding to the type
- * of sunrise to compute.
- * @param date <code>Calendar</code> object representing the date to
- * compute the sunrise for.
- * @return the sunrise time
- */
- public double computeSunriseTime(double solarZenith, Calendar date) {
- return computeSolarEventTime(solarZenith, date, true);
- }
-
- /**
- * Computes the sunset time for the given zenith at the given date.
- *
- * @param solarZenith <code>Zenith</code> enum corresponding to the type of
- * sunset to compute.
- * @param date <code>Calendar</code> object representing the date to compute
- * the sunset for.
- * @return the sunset time
- */
- public double computeSunsetTime(double solarZenith, Calendar date) {
- return computeSolarEventTime(solarZenith, date, false);
- }
-
- public static int timeToHours(double time) {
- int hour = (int) Math.floor(time);
- int minute = (int) Math.round((time - hour) * 60);
- if (minute == 60) {
- hour++;
- }
- return hour;
- }
-
- public static int timeToMinutes(double time) {
- int hour = (int) Math.floor(time);
- int minute = (int) Math.round((time - hour) * 60);
- if (minute == 60) {
- minute = 0;
- }
- return minute;
- }
-
- public static float timeToDayFraction(double time) {
- int hour = (int) Math.floor(time);
- int minute = (int) Math.round((time - hour) * 60);
- if (minute == 60) {
- minute = 0;
- hour++;
- }
- return (hour * 60 + minute) / 1440.0f;
- }
-
- public static String timeToString(double time) {
- StringBuffer buffer = new StringBuffer();
- int hour = (int) Math.floor(time);
- int minute = (int) Math.round((time - hour) * 60);
- if (minute == 60) {
- minute = 0;
- hour++;
- }
- buffer.append(hour).append(':').append(minute < 10 ? "0" + minute : minute);
- return buffer.toString();
- }
-
- private double computeSolarEventTime(double solarZenith, Calendar date, boolean isSunrise) {
- date.setTimeZone(mTimeZone);
- double longitudeHour = getLongitudeHour(date, isSunrise);
- double meanAnomaly = getMeanAnomaly(longitudeHour);
- double sunTrueLong = getSunTrueLongitude(meanAnomaly);
- double cosineSunLocalHour = getCosineSunLocalHour(sunTrueLong, solarZenith);
- if ((cosineSunLocalHour < -1.0) || (cosineSunLocalHour > 1.0)) {
- return 0;
- }
-
- double sunLocalHour = getSunLocalHour(cosineSunLocalHour, isSunrise);
- double localMeanTime = getLocalMeanTime(sunTrueLong, longitudeHour, sunLocalHour);
- return getLocalTime(localMeanTime, date);
- }
-
- /**
- * Computes the base longitude hour, lngHour in the algorithm.
- *
- * @return the longitude of the location of the solar event divided by 15 (deg/hour), in
- * <code>double</code> form.
- */
- private double getBaseLongitudeHour() {
- return mLocation.getLongitude() / 15.0;
- }
-
- /**
- * Computes the longitude time, t in the algorithm.
- *
- * @return longitudinal time in <code>double</code> form.
- */
- private double getLongitudeHour(Calendar date, Boolean isSunrise) {
- int offset = 18;
- if (isSunrise) {
- offset = 6;
- }
- double dividend = offset - getBaseLongitudeHour();
- double addend = dividend / 24.0;
- return getDayOfYear(date) + addend;
- }
-
- /**
- * Computes the mean anomaly of the Sun, M in the algorithm.
- *
- * @return the suns mean anomaly, M, in <code>double</code> form.
- */
- private static double getMeanAnomaly(double longitudeHour) {
- return 0.9856 * longitudeHour - 3.289;
- }
-
- /**
- * Computes the true longitude of the sun, L in the algorithm, at the given
- * location, adjusted to fit in the range [0-360].
- *
- * @param meanAnomaly the suns mean anomaly.
- * @return the suns true longitude, in <code>double</code> form.
- */
- private static double getSunTrueLongitude(double meanAnomaly) {
- final double meanRadians = Math.toRadians(meanAnomaly);
- double sinMeanAnomaly = Math.sin(meanRadians);
- double sinDoubleMeanAnomaly = Math.sin((meanRadians * 2.0));
-
- double firstPart = meanAnomaly + sinMeanAnomaly * 1.916;
- double secondPart = sinDoubleMeanAnomaly * 0.020 + 282.634;
- double trueLongitude = firstPart + secondPart;
-
- if (trueLongitude > 360) {
- trueLongitude = trueLongitude - 360.0;
- }
- return trueLongitude;
- }
-
- /**
- * Computes the suns right ascension, RA in the algorithm, adjusting for
- * the quadrant of L and turning it into degree-hours. Will be in the
- * range [0,360].
- *
- * @param sunTrueLong Suns true longitude, in <code>double</code>
- * @return suns right ascension in degree-hours, in <code>double</code> form.
- */
- private static double getRightAscension(double sunTrueLong) {
- double tanL = Math.tan(Math.toRadians(sunTrueLong));
-
- double innerParens = Math.toDegrees(tanL) * 0.91764;
- double rightAscension = Math.atan(Math.toRadians(innerParens));
- rightAscension = Math.toDegrees(rightAscension);
-
- if (rightAscension < 0.0) {
- rightAscension = rightAscension + 360.0;
- } else if (rightAscension > 360.0) {
- rightAscension = rightAscension - 360.0;
- }
-
- double ninety = 90.0;
- double longitudeQuadrant = (int) (sunTrueLong / ninety);
- longitudeQuadrant = longitudeQuadrant * ninety;
-
- double rightAscensionQuadrant = (int) (rightAscension / ninety);
- rightAscensionQuadrant = rightAscensionQuadrant * ninety;
-
- double augend = longitudeQuadrant - rightAscensionQuadrant;
- return (rightAscension + augend) / 15.0;
- }
-
- private double getCosineSunLocalHour(double sunTrueLong, double zenith) {
- double sinSunDeclination = getSinOfSunDeclination(sunTrueLong);
- double cosineSunDeclination = getCosineOfSunDeclination(sinSunDeclination);
-
- final double zenithInRads = Math.toRadians(zenith);
- final double latitude = Math.toRadians(mLocation.getLatitude());
-
- double cosineZenith = Math.cos(zenithInRads);
- double sinLatitude = Math.sin(latitude);
- double cosLatitude = Math.cos(latitude);
-
- double sinDeclinationTimesSinLat = sinSunDeclination * sinLatitude;
- double dividend = cosineZenith - sinDeclinationTimesSinLat;
- double divisor = cosineSunDeclination * cosLatitude;
-
- return dividend / divisor;
- }
-
- private static double getSinOfSunDeclination(double sunTrueLong) {
- double sinTrueLongitude = Math.sin(Math.toRadians(sunTrueLong));
- return sinTrueLongitude * 0.39782;
- }
-
- private static double getCosineOfSunDeclination(double sinSunDeclination) {
- double arcSinOfSinDeclination = Math.asin(sinSunDeclination);
- return Math.cos(arcSinOfSinDeclination);
- }
-
- private static double getSunLocalHour(double cosineSunLocalHour, Boolean isSunrise) {
- double arcCosineOfCosineHourAngle = Math.acos(cosineSunLocalHour);
- double localHour = Math.toDegrees(arcCosineOfCosineHourAngle);
- if (isSunrise) {
- localHour = 360.0 - localHour;
- }
- return localHour / 15.0;
- }
-
- private static double getLocalMeanTime(double sunTrueLong, double longitudeHour,
- double sunLocalHour) {
-
- double rightAscension = getRightAscension(sunTrueLong);
- double innerParens = longitudeHour * 0.06571;
- double localMeanTime = sunLocalHour + rightAscension - innerParens;
- localMeanTime = localMeanTime - 6.622;
-
- if (localMeanTime < 0.0) {
- localMeanTime = localMeanTime + 24.0;
- } else if (localMeanTime > 24.0) {
- localMeanTime = localMeanTime - 24.0;
- }
- return localMeanTime;
- }
-
- private double getLocalTime(double localMeanTime, Calendar date) {
- double utcTime = localMeanTime - getBaseLongitudeHour();
- double utcOffSet = getUTCOffSet(date);
- double utcOffSetTime = utcTime + utcOffSet;
- return adjustForDST(utcOffSetTime, date);
- }
-
- private double adjustForDST(double localMeanTime, Calendar date) {
- double localTime = localMeanTime;
- if (mTimeZone.inDaylightTime(date.getTime())) {
- localTime++;
- }
- if (localTime > 24.0) {
- localTime = localTime - 24.0;
- }
- return localTime;
- }
-
- /**
- * ****** UTILITY METHODS (Should probably go somewhere else. *****************
- */
-
- private static double getDayOfYear(Calendar date) {
- return date.get(Calendar.DAY_OF_YEAR);
- }
-
- private static double getUTCOffSet(Calendar date) {
- int offSetInMillis = date.get(Calendar.ZONE_OFFSET);
- return offSetInMillis / 3600000;
- }
-} \ No newline at end of file
diff --git a/src/com/android/wallpaper/grass/grass.rs b/src/com/android/wallpaper/grass/grass.rs
deleted file mode 100644
index b03f19c..0000000
--- a/src/com/android/wallpaper/grass/grass.rs
+++ /dev/null
@@ -1,465 +0,0 @@
-// 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)
-
-#pragma rs java_package_name(com.android.wallpaper.grass)
-
-#include "rs_graphics.rsh"
-
-#define RSID_BLADES_BUFFER 2
-
-#define TESSELATION 0.5f
-#define HALF_TESSELATION 0.25f
-#define MAX_BEND 0.09f
-#define SECONDS_IN_DAY 86400.0f
-#define PI 3.1415926f
-#define HALF_PI 1.570796326f
-#define REAL_TIME 1
-
-int gBladesCount;
-int gIndexCount;
-int gWidth;
-int gHeight;
-float gXOffset;
-float gDawn;
-float gMorning;
-float gAfternoon;
-float gDusk;
-int gIsPreview;
-rs_program_vertex gPVBackground;
-rs_program_fragment gPFBackground;
-rs_program_fragment gPFGrass;
-rs_program_store gPSBackground;
-rs_allocation gTNight;
-rs_allocation gTSunset;
-rs_allocation gTSunrise;
-rs_allocation gTSky;
-rs_allocation gTAa;
-rs_mesh gBladesMesh;
-
-
-typedef struct Blade {
- float angle;
- int size;
- float xPos;
- float yPos;
- float offset;
- float scale;
- float lengthX;
- float lengthY;
- float hardness;
- float h;
- float s;
- float b;
- float turbulencex;
-} Blade_t;
-Blade_t *Blades;
-
-typedef struct RS_PACKED Vertex {
- uchar4 color;
- float2 position;
- float2 texture0;
-} __attribute__((packed,aligned(4))) Vertex_t;
-Vertex_t *Verticies;
-
-#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 float noise_sCurve(float t)
-{
- return t * t * (3.0f - 2.0f * t);
-}
-
-static void normalizef2(float v[])
-{
- float s = (float)sqrt(v[0] * v[0] + v[1] * v[1]);
- v[0] = v[0] / s;
- v[1] = v[1] / s;
-}
-
-static void normalizef3(float v[])
-{
- float s = (float)sqrt(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;
-}
-
-void init()
-{
- int i, j, k;
-
- for (i = 0; i < B; i++) {
- p[i] = i;
-
- g1[i] = (float)(rsRand(B * 2) - B) / B;
-
- for (j = 0; j < 2; j++)
- g2[i][j] = (float)(rsRand(B * 2) - B) / B;
- normalizef2(g2[i]);
-
- for (j = 0; j < 3; j++)
- g3[i][j] = (float)(rsRand(B * 2) - B) / B;
- normalizef3(g3[i]);
- }
-
- for (i = B-1; i >= 0; i--) {
- k = p[i];
- p[i] = p[j = rsRand(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];
- }
-}
-
-static float noisef(float x)
-{
- int bx0, bx1;
- float rx0, rx1, sx, t, u, v;
-
- 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 * mix(u, v, sx);
-}
-
-static float noisef2(float x, float y)
-{
- 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;
-
- 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 = mix(u, v, sx);
-
- q = g2[b01]; u = rx0 * q[0] + ry1 * q[1];
- q = g2[b11]; v = rx1 * q[0] + ry1 * q[1];
- b = mix(u, v, sx);
-
- return 1.5f * mix(a, b, sy);
-}
-
-static float turbulencef2(float x, float y, float octaves)
-{
- float t = 0.0f;
-
- for (float f = 1.0f; f <= octaves; f *= 2)
- t += fabs(noisef2(f * x, f * y)) / f;
- return t;
-}
-
-void updateBlades()
-{
- Blade_t *bladeStruct = Blades;
- for (int i = 0; i < gBladesCount; i ++) {
- float xpos = rsRand(-gWidth, gWidth);
- bladeStruct->xPos = xpos;
- bladeStruct->turbulencex = xpos * 0.006f;
- bladeStruct->yPos = gHeight;
- bladeStruct++;
- }
-}
-
-static float time(int isPreview) {
- if (REAL_TIME && !isPreview) {
- rs_time_t currentTime = rsTime(0);
- rs_tm localTime;
- rsLocaltime(&localTime, &currentTime);
- return (localTime.tm_hour * 3600.0f +
- localTime.tm_min * 60.0f +
- localTime.tm_sec) / SECONDS_IN_DAY;
- }
- float t = rsUptimeMillis() / 30000.0f;
- return t - (int) t;
-}
-
-static void alpha(float a) {
- rsgProgramFragmentConstantColor(gPFBackground, 1.0f, 1.0f, 1.0f, a);
-}
-
-static float normf(float start, float stop, float value) {
- return (value - start) / (stop - start);
-}
-
-static void drawNight(int width, int height) {
- rsgBindTexture(gPFBackground, 0, gTNight);
- rsgDrawQuadTexCoords(
- 0.0f, -32.0f, 0.0f,
- 0.0f, 1.0f,
- 0.0f, height, 0.0f,
- 0.0f, 0.0f,
- width, height, 0.0f,
- 2.0f, 0.0f,
- width, -32.0f, 0.0f,
- 2.0f, 1.0f);
-}
-
-static void drawSunrise(int width, int height) {
- rsgBindTexture(gPFBackground, 0, gTSunrise);
- rsgDrawRect(0.0f, 0.0f, width, height, 0.0f);
-}
-
-static void drawNoon(int width, int height) {
- rsgBindTexture(gPFBackground, 0, gTSky);
- rsgDrawRect(0.0f, 0.0f, width, height, 0.0f);
-}
-
-static void drawSunset(int width, int height) {
- rsgBindTexture(gPFBackground, 0, gTSunset);
- rsgDrawRect(0.0f, 0.0f, width, height, 0.0f);
-}
-
-
-static uchar4 hsbToRgb(float h, float s, float b)
-{
- 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;
- }
-
- return rsPackColorTo8888(red, green, blue);
-}
-
-static int drawBlade(Blade_t *bladeStruct, Vertex_t *v,
- float brightness, float xOffset, float now) {
-
- float scale = bladeStruct->scale;
- float angle = bladeStruct->angle;
- float xpos = bladeStruct->xPos + xOffset;
- int size = bladeStruct->size;
-
- uchar4 color = hsbToRgb(bladeStruct->h, bladeStruct->s,
- mix(0.f, bladeStruct->b, brightness));
-
- float newAngle = (turbulencef2(bladeStruct->turbulencex, now, 4.0f) - 0.5f) * 0.5f;
- angle = clamp(angle + (newAngle + bladeStruct->offset - angle) * 0.15f, -MAX_BEND, MAX_BEND);
-
- float currentAngle = HALF_PI;
-
- float bottomX = xpos;
- float bottomY = bladeStruct->yPos;
-
- float d = angle * bladeStruct->hardness;
-
-
- float si = size * scale;
- float bottomLeft = bottomX - si;
- float bottomRight = bottomX + si;
- float bottom = bottomY + HALF_TESSELATION;
-
- v[0].color = color; // V1.ABGR
- v[0].position.x = bottomLeft; // V1.X
- v[0].position.y = bottom; // V1.Y
- v[0].texture0.x = 0.f; // V1.s
- v[0].texture0.y = 0.f; // V1.t
- //
- v[1].color = color; // V2.ABGR
- v[1].position.x = bottomRight; // V2.X
- v[1].position.y = bottom; // V2.Y
- v[1].texture0.x = 1.f; // V2.s
- v[1].texture0.y = 0.f; // V2.t
- v += 2;
-
- for ( ; size > 0; size -= 1) {
- float topX = bottomX - cos(currentAngle) * bladeStruct->lengthX;
- float topY = bottomY - sin(currentAngle) * bladeStruct->lengthY;
-
- si = (float)size * scale;
- float spi = si - scale;
-
- float topLeft = topX - spi;
- float topRight = topX + spi;
-
- v[0].color = color; // V1.ABGR
- v[0].position.x = topLeft; // V1.X
- v[0].position.y = topY; // V1.Y
- v[0].texture0.x = 0.f; // V1.s
- v[0].texture0.y = 0.f; // V1.t
-
- v[1].color = color; // V2.ABGR
- v[1].position.x = topRight; // V2.X
- v[1].position.y = topY; // V2.Y
- v[1].texture0.x = 1.f; // V2.s
- v[1].texture0.y = 0.f; // V2.t
-
- v += 2;
- bottomX = topX;
- bottomY = topY;
- currentAngle += d;
- }
-
- bladeStruct->angle = angle;
-
- // 2 vertices per triangle, 5 properties per vertex (RGBA, X, Y, S, T)
- return bladeStruct->size * 2 + 2;
-}
-
-static void drawBlades(float brightness, float xOffset) {
- // For anti-aliasing
- rsgBindTexture(gPFGrass, 0, gTAa);
-
- Blade_t *bladeStruct = Blades;
- Vertex_t *vtx = Verticies;
- float now = rsUptimeMillis() * 0.00004f;
-
- for (int i = 0; i < gBladesCount; i += 1) {
- int offset = drawBlade(bladeStruct, vtx, brightness, xOffset, now);
- vtx += offset;
- bladeStruct ++;
- }
-
- rsgDrawMesh(gBladesMesh, 0, 0, gIndexCount);
-}
-
-int root(void) {
- float x = mix((float)gWidth, 0.f, gXOffset);
-
- float now = time(gIsPreview);
-
- rsgBindProgramVertex(gPVBackground);
- rsgBindProgramFragment(gPFBackground);
- rsgBindProgramStore(gPSBackground);
- alpha(1.0f);
-
- float newB = 1.0f;
- if (now >= 0.0f && now < gDawn) { // Draw night
- drawNight(gWidth, gHeight);
- newB = 0.0f;
- } else if (now >= gDawn && now <= gMorning) { // Draw sunrise
- float half = gDawn + (gMorning - gDawn) * 0.5f;
- if (now <= half) { // Draw night->sunrise
- drawNight(gWidth, gHeight);
- newB = normf(gDawn, half, now);
- alpha(newB);
- drawSunrise(gWidth, gHeight);
- } else { // Draw sunrise->day
- drawSunrise(gWidth, gHeight);
- alpha(normf(half, gMorning, now));
- drawNoon(gWidth, gHeight);
- }
- } else if (now > gMorning && now < gAfternoon) { // Draw day
- drawNoon(gWidth, gHeight);
- } else if (now >= gAfternoon && now <= gDusk) { // Draw sunset
- float half = gAfternoon + (gDusk - gAfternoon) * 0.5f;
- if (now <= half) { // Draw day->sunset
- drawNoon(gWidth, gHeight);
- newB = normf(gAfternoon, half, now);
- alpha(newB);
- newB = 1.0f - newB;
- drawSunset(gWidth, gHeight);
- } else { // Draw sunset->night
- drawSunset(gWidth, gHeight);
- alpha(normf(half, gDusk, now));
- drawNight(gWidth, gHeight);
- newB = 0.0f;
- }
- } else if (now > gDusk) { // Draw night
- drawNight(gWidth, gHeight);
- newB = 0.0f;
- }
-
- rsgBindProgramFragment(gPFGrass);
- drawBlades(newB, x);
-
- return 50;
-}
diff --git a/src/com/android/wallpaper/nexus/NexusRS.java b/src/com/android/wallpaper/nexus/NexusRS.java
deleted file mode 100644
index c59fdef..0000000
--- a/src/com/android/wallpaper/nexus/NexusRS.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * 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.wallpaper.nexus;
-
-import static android.renderscript.Element.RGBA_8888;
-import static android.renderscript.Element.RGB_565;
-import static android.renderscript.ProgramStore.DepthFunc.ALWAYS;
-import static android.renderscript.Sampler.Value.LINEAR;
-import static android.renderscript.Sampler.Value.CLAMP;
-import static android.renderscript.Sampler.Value.WRAP;
-
-import com.android.wallpaper.R;
-import com.android.wallpaper.RenderScriptScene;
-
-import android.app.WallpaperManager;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Rect;
-import android.os.Bundle;
-import android.renderscript.*;
-import android.renderscript.ProgramStore.BlendDstFunc;
-import android.renderscript.ProgramStore.BlendSrcFunc;
-import android.view.SurfaceHolder;
-
-import java.util.TimeZone;
-
-class NexusRS extends RenderScriptScene {
- private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
-
- private ProgramVertexFixedFunction.Constants mPvOrthoAlloc;
-
- private int mInitialWidth;
- private int mInitialHeight;
- private float mWorldScaleX;
- private float mWorldScaleY;
- private float mXOffset;
- private ScriptC_nexus mScript;
-
- public NexusRS(int width, int height) {
- super(width, height);
-
- mInitialWidth = width;
- mInitialHeight = height;
- mWorldScaleX = 1.0f;
- mWorldScaleY = 1.0f;
-
- mOptionsARGB.inScaled = false;
- mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
- }
-
- @Override
- public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) {
- mXOffset = xOffset;
- mScript.set_gXOffset(xOffset);
- }
-
- @Override
- public void start() {
- super.start();
- }
-
- @Override
- public void resize(int width, int height) {
- super.resize(width, height); // updates mWidth, mHeight
-
- // android.util.Log.d("NexusRS", String.format("resize(%d, %d)", width, height));
-
- mWorldScaleX = (float)mInitialWidth / width;
- mWorldScaleY = (float)mInitialHeight / height;
- mScript.set_gWorldScaleX(mWorldScaleX);
- mScript.set_gWorldScaleY(mWorldScaleY);
- }
-
- @Override
- protected ScriptC createScript() {
- mScript = new ScriptC_nexus(mRS, mResources, R.raw.nexus);
-
- createProgramFragmentStore();
- createProgramFragment();
- createProgramVertex();
- createState();
-
- mScript.set_gTBackground(loadTexture(R.drawable.pyramid_background));
- mScript.set_gTPulse(loadTextureARGB(R.drawable.pulse));
- mScript.set_gTGlow(loadTextureARGB(R.drawable.glow));
- mScript.setTimeZone(TimeZone.getDefault().getID());
- mScript.invoke_initPulses();
- return mScript;
- }
-
- private void createState() {
- int mode;
- try {
- mode = mResources.getInteger(R.integer.nexus_mode);
- } catch (Resources.NotFoundException exc) {
- mode = 0; // standard nexus mode
- }
-
- mScript.set_gIsPreview(isPreview() ? 1 : 0);
- mScript.set_gMode(mode);
- mScript.set_gXOffset(0.f);
- mScript.set_gWorldScaleX(mWorldScaleX);
- mScript.set_gWorldScaleY(mWorldScaleY);
- }
-
- private Allocation loadTexture(int id) {
- return Allocation.createFromBitmapResource(mRS, mResources, id,
- Allocation.MipmapControl.MIPMAP_NONE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
- }
-
- private Allocation loadTextureARGB(int id) {
- Bitmap b = BitmapFactory.decodeResource(mResources, id, mOptionsARGB);
- return Allocation.createFromBitmap(mRS, b,
- Allocation.MipmapControl.MIPMAP_NONE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
- }
-
-
- private void createProgramFragment() {
- // sampler and program fragment for pulses
- ProgramFragmentFixedFunction.Builder builder = new ProgramFragmentFixedFunction.Builder(mRS);
- builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
- ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
- ProgramFragment pft = builder.create();
- pft.bindSampler(Sampler.WRAP_LINEAR(mRS), 0);
- mScript.set_gPFTexture(pft);
-
- // sampler and program fragment for background image
- builder = new ProgramFragmentFixedFunction.Builder(mRS);
- builder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
- ProgramFragmentFixedFunction.Builder.Format.RGB, 0);
- ProgramFragment pft565 = builder.create();
- pft565.bindSampler(Sampler.CLAMP_NEAREST(mRS), 0);
- mScript.set_gPFTexture565(pft565);
- }
-
- private void createProgramFragmentStore() {
- ProgramStore.Builder builder = new ProgramStore.Builder(mRS);
- builder.setDepthFunc(ALWAYS);
- builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE);
- builder.setDitherEnabled(false);
- ProgramStore solid = builder.create();
- mRS.bindProgramStore(solid);
-
- builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE);
- mScript.set_gPSBlend(builder.create());
- }
-
- private void createProgramVertex() {
- mPvOrthoAlloc = new ProgramVertexFixedFunction.Constants(mRS);
- Matrix4f proj = new Matrix4f();
- proj.loadOrthoWindow(mWidth, mHeight);
- mPvOrthoAlloc.setProjection(proj);
-
- ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
- pvb.setTextureMatrixEnable(true);
- ProgramVertex pv = pvb.create();
- ((ProgramVertexFixedFunction)pv).bindConstants(mPvOrthoAlloc);
- mRS.bindProgramVertex(pv);
- }
-
- @Override
- public Bundle onCommand(String action, int x, int y, int z, Bundle extras,
- boolean resultRequested) {
-
- if (mWidth < mHeight) {
- // nexus.rs ignores the xOffset when rotated; we shall endeavor to do so as well
- x = (int) (x + mXOffset * mWidth / mWorldScaleX);
- }
-
- // android.util.Log.d("NexusRS", String.format(
- // "dw=%d, bw=%d, xOffset=%g, x=%d",
- // dw, bw, mWorldState.xOffset, x));
-
- if (WallpaperManager.COMMAND_TAP.equals(action)
- || WallpaperManager.COMMAND_SECONDARY_TAP.equals(action)
- || WallpaperManager.COMMAND_DROP.equals(action)) {
- mScript.invoke_addTap(x, y);
- }
- return null;
- }
-}
diff --git a/src/com/android/wallpaper/nexus/NexusWallpaper.java b/src/com/android/wallpaper/nexus/NexusWallpaper.java
deleted file mode 100644
index ce84bf5..0000000
--- a/src/com/android/wallpaper/nexus/NexusWallpaper.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.wallpaper.nexus;
-
-import com.android.wallpaper.RenderScriptWallpaper;
-import com.android.wallpaper.RenderScriptScene;
-
-public class NexusWallpaper extends RenderScriptWallpaper {
- protected RenderScriptScene createScene(int width, int height) {
- return new NexusRS(width, height);
- }
-}
diff --git a/src/com/android/wallpaper/nexus/nexus.rs b/src/com/android/wallpaper/nexus/nexus.rs
deleted file mode 100644
index ef1788e..0000000
--- a/src/com/android/wallpaper/nexus/nexus.rs
+++ /dev/null
@@ -1,327 +0,0 @@
-// 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)
-
-#pragma rs java_package_name(com.android.wallpaper.nexus)
-
-#include "rs_graphics.rsh"
-#pragma stateVertex(parent)
-
-#define MAX_PULSES 20
-#define MAX_EXTRAS 40
-#define PULSE_SIZE 14 // Size in pixels of a cell
-#define HALF_PULSE_SIZE 7
-#define GLOW_SIZE 64 // Size of the leading glow in pixels
-#define HALF_GLOW_SIZE 32
-#define SPEED 0.2f // (200 / 1000) Pixels per ms
-#define SPEED_DELTA_MIN 0.7f
-#define SPEED_DELTA_MAX 1.7f
-#define PULSE_NORMAL 0
-#define PULSE_EXTRA 1
-#define TRAIL_SIZE 40 // Number of cells in a trail
-#define MAX_DELAY 2000 // Delay between a pulse going offscreen and restarting
-
-typedef struct pulse_s {
- int pulseType;
- float originX;
- float originY;
- int color;
- int startTime;
- float dx;
- float dy;
- float scale;
- int active;
-} pulse_t;
-
-static pulse_t gPulses[MAX_PULSES];
-static pulse_t gExtras[MAX_EXTRAS];
-static int gNow;
-static int gWidth;
-static int gHeight;
-static int gRotate;
-
-float gWorldScaleX;
-float gWorldScaleY;
-float gXOffset;
-int gIsPreview;
-int gMode;
-
-rs_program_fragment gPFTexture;
-rs_program_store gPSBlend;
-rs_program_fragment gPFTexture565;
-
-rs_allocation gTBackground;
-rs_allocation gTPulse;
-rs_allocation gTGlow;
-
-static void setColor(int c) {
- if (gMode == 1) {
- // sholes red
- rsgProgramFragmentConstantColor(gPFTexture, 0.9f, 0.1f, 0.1f, 0.8f);
- } else if (c == 0) {
- // red
- rsgProgramFragmentConstantColor(gPFTexture, 1.0f, 0.0f, 0.0f, 0.8f);
- } else if (c == 1) {
- // green
- rsgProgramFragmentConstantColor(gPFTexture, 0.0f, 0.8f, 0.0f, 0.8f);
- } else if (c == 2) {
- // blue
- rsgProgramFragmentConstantColor(gPFTexture, 0.0f, 0.4f, 0.9f, 0.8f);
- } else if (c == 3) {
- // yellow
- rsgProgramFragmentConstantColor(gPFTexture, 1.0f, 0.8f, 0.0f, 0.8f);
- }
-}
-
-static void initPulse(struct pulse_s * pulse, int pulseType) {
- float scale = rsRand(SPEED_DELTA_MIN, SPEED_DELTA_MAX);
- pulse->scale = scale;
- gWidth = rsgGetWidth();
- gHeight = rsgGetHeight();
- if (rsRand(1.f) > 0.5f) {
- pulse->originX = rsRand(gWidth * 2 / PULSE_SIZE) * PULSE_SIZE;
- pulse->dx = 0;
- if (rsRand(1.f) > 0.5f) {
- // Top
- pulse->originY = 0;
- pulse->dy = scale;
- } else {
- // Bottom
- pulse->originY = gHeight / scale;
- pulse->dy = -scale;
- }
- } else {
- pulse->originY = rsRand(gHeight / PULSE_SIZE) * PULSE_SIZE;
- pulse->dy = 0;
- if (rsRand(1.f) > 0.5f) {
- // Left
- pulse->originX = 0;
- pulse->dx = scale;
- } else {
- // Right
- pulse->originX = gWidth * 2 / scale;
- pulse->dx = -scale;
- }
- }
- pulse->startTime = gNow + rsRand(MAX_DELAY);
-
- pulse->color = rsRand(4);
-
- pulse->pulseType = pulseType;
- if (pulseType == PULSE_EXTRA) {
- pulse->active = 0;
- } else {
- pulse->active = 1;
- }
-}
-
-void initPulses() {
- gNow = (int)rsUptimeMillis();
- int i;
- for (i=0; i<MAX_PULSES; i++) {
- initPulse(&gPulses[i], PULSE_NORMAL);
- }
- for (i=0; i<MAX_EXTRAS; i++) {
- struct pulse_s * p = &gExtras[i];
- p->pulseType = PULSE_EXTRA;
- p->active = 0;
- }
-}
-
-static void drawBackground() {
- rsgBindProgramFragment(gPFTexture565);
- rsgBindTexture(gPFTexture565, 0, gTBackground);
- if (gRotate) {
- rsgDrawRect(0.0f, 0.0f, gHeight*2, gWidth, 0.0f);
- } else {
- rsgDrawRect(0.0f, 0.0f, gWidth*2, gHeight, 0.0f);
- }
-}
-
-static void drawPulses(pulse_t * pulseSet, int setSize) {
- rsgBindProgramFragment(gPFTexture);
- rsgBindProgramStore(gPSBlend);
-
- rs_matrix4x4 matrix;
- rs_matrix4x4 modelMatrix;
- for (int i=0; i<setSize; i++) {
- struct pulse_s * p = &pulseSet[i];
- int delta = gNow - p->startTime;
-
- if (p->active != 0 && delta >= 0) {
-
- rsMatrixLoadIdentity(&modelMatrix);
- if (gRotate) {
- //matrixLoadRotate(modelMatrix, 90.0f, 0.0f, 0.0f, 1.0f);
- //matrixTranslate(modelMatrix, 0.0f, -height, 1.0f);
- // XXX: HAX: do not slide display in landscape
- } else {
- rsMatrixTranslate(&modelMatrix, -(gXOffset * gWidth), 0, 0);
- }
- rsMatrixScale(&modelMatrix, p->scale * gWorldScaleX, p->scale * gWorldScaleY, 1.0f);
- rsgProgramVertexLoadModelMatrix(&modelMatrix);
-
- float x = p->originX + (p->dx * SPEED * delta);
- float y = p->originY + (p->dy * SPEED * delta);
-
- rsMatrixLoadIdentity(&matrix);
- if (p->dx < 0) {
- rsgProgramVertexLoadTextureMatrix(&matrix);
- float xx = x + (TRAIL_SIZE * PULSE_SIZE);
- if (xx <= 0) {
- initPulse(p, p->pulseType);
- } else {
- setColor(p->color);
- rsgBindTexture(gPFTexture, 0, gTPulse);
- rsgDrawRect(x, y, xx, y + PULSE_SIZE, 0.0f);
- rsgBindTexture(gPFTexture, 0, gTGlow);
- rsgDrawRect(x + HALF_PULSE_SIZE - HALF_GLOW_SIZE,
- y + HALF_PULSE_SIZE - HALF_GLOW_SIZE,
- x + HALF_PULSE_SIZE + HALF_GLOW_SIZE,
- y + HALF_PULSE_SIZE + HALF_GLOW_SIZE,
- 0.0f);
- }
- } else if (p->dx > 0) {
- x += PULSE_SIZE; // need to start on the other side of this cell
- rsMatrixRotate(&matrix, 180.0f, 0.0f, 0.0f, 1.0f);
- rsgProgramVertexLoadTextureMatrix(&matrix);
- float xx = x - (TRAIL_SIZE * PULSE_SIZE);
- if (xx >= gWidth * 2) {
- initPulse(p, p->pulseType);
- } else {
- setColor(p->color);
- rsgBindTexture(gPFTexture, 0, gTPulse);
- rsgDrawRect(xx, y, x, y + PULSE_SIZE, 0.0f);
- rsgBindTexture(gPFTexture, 0, gTGlow);
- rsgDrawRect(x - HALF_PULSE_SIZE - HALF_GLOW_SIZE,
- y + HALF_PULSE_SIZE - HALF_GLOW_SIZE,
- x - HALF_PULSE_SIZE + HALF_GLOW_SIZE,
- y + HALF_PULSE_SIZE + HALF_GLOW_SIZE,
- 0.0f);
- }
- } else if (p->dy < 0) {
- rsMatrixRotate(&matrix, -90.0f, 0.0f, 0.0f, 1.0f);
- rsgProgramVertexLoadTextureMatrix(&matrix);
- float yy = y + (TRAIL_SIZE * PULSE_SIZE);
- if (yy <= 0) {
- initPulse(p, p->pulseType);
- } else {
- setColor(p->color);
- rsgBindTexture(gPFTexture, 0, gTPulse);
- rsgDrawRect(x, y, x + PULSE_SIZE, yy, 0.0f);
- rsgBindTexture(gPFTexture, 0, gTGlow);
- rsgDrawRect(x + HALF_PULSE_SIZE - HALF_GLOW_SIZE,
- y + HALF_PULSE_SIZE - HALF_GLOW_SIZE,
- x + HALF_PULSE_SIZE + HALF_GLOW_SIZE,
- y + HALF_PULSE_SIZE + HALF_GLOW_SIZE,
- 0.0f);
- }
- } else if (p->dy > 0) {
- y += PULSE_SIZE; // need to start on the other side of this cell
- rsMatrixRotate(&matrix, 90.0f, 0.0f, 0.0f, 1.0f);
- rsgProgramVertexLoadTextureMatrix(&matrix);
- float yy = y - (TRAIL_SIZE * PULSE_SIZE);
- if (yy >= gHeight) {
- initPulse(p, p->pulseType);
- } else {
- setColor(p->color);
- rsgBindTexture(gPFTexture, 0, gTPulse);
- rsgDrawRect(x, yy, x + PULSE_SIZE, y, 0.0f);
- rsgBindTexture(gPFTexture, 0, gTGlow);
- rsgDrawRect(x + HALF_PULSE_SIZE - HALF_GLOW_SIZE,
- y - HALF_PULSE_SIZE - HALF_GLOW_SIZE,
- x + HALF_PULSE_SIZE + HALF_GLOW_SIZE,
- y - HALF_PULSE_SIZE + HALF_GLOW_SIZE,
- 0.0f);
- }
- }
- }
- }
-
- rsMatrixLoadIdentity(&matrix);
- rsgProgramVertexLoadTextureMatrix(&matrix);
-}
-
-void addTap(int x, int y) {
- int count = 0;
- int color = rsRand(4);
- float scale = rsRand(0.9f, 1.9f);
- x = (x / PULSE_SIZE) * PULSE_SIZE;
- y = (y / PULSE_SIZE) * PULSE_SIZE;
- for (int i=0; i<MAX_EXTRAS; i++) {
- struct pulse_s * p = &gExtras[i];
- if (p->active == 0) {
- p->originX = x/scale;
- p->originY = y/scale;
- p->scale = scale;
-
- if (count == 0) {
- p->dx = scale;
- p->dy = 0.0f;
- } else if (count == 1) {
- p->dx = -scale;
- p->dy = 0.0f;
- } else if (count == 2) {
- p->dx = 0.0f;
- p->dy = scale;
- } else if (count == 3) {
- p->dx = 0.0f;
- p->dy = -scale;
- }
-
- p->active = 1;
- p->color = color;
- color++;
- if (color >= 4) {
- color = 0;
- }
- p->startTime = gNow;
- count++;
- if (count == 4) {
- break;
- }
- }
- }
-}
-
-int root() {
- rsgClearColor(0.f, 0.f, 0.f, 1.f);
-
- gWidth = rsgGetWidth();
- gHeight = rsgGetHeight();
- gRotate = gWidth > gHeight ? 1 : 0;
-
- gNow = (int)rsUptimeMillis();
-
- rs_matrix4x4 matrix;
- rsMatrixLoadIdentity(&matrix);
- rsMatrixScale(&matrix, gWorldScaleX, gWorldScaleY, 1.0f);
-
- if (gRotate) {
- //matrixLoadRotate(matrix, 90.0f, 0.0f, 0.0f, 1.0f);
- //matrixTranslate(matrix, 0.0f, -height, 1.0f);
- // XXX: HAX: do not slide display in landscape
- } else {
- rsMatrixTranslate(&matrix, -(gXOffset * gWidth), 0, 0);
- }
-
- rsgProgramVertexLoadModelMatrix(&matrix);
-
- drawBackground();
- drawPulses(gPulses, MAX_PULSES);
- drawPulses(gExtras, MAX_EXTRAS);
-
- return 45;
-}