diff options
author | Romain Guy <romainguy@android.com> | 2009-07-30 22:39:21 -0700 |
---|---|---|
committer | Romain Guy <romainguy@android.com> | 2009-07-30 22:39:21 -0700 |
commit | 8c76cef0c8ca87e1e642a8351e1713007898c764 (patch) | |
tree | 16136d91f55637b15cc28df2abea9830f053af63 /libs | |
parent | 584a375df68ed7d62b38389078c6804edf228f9c (diff) | |
download | frameworks_base-8c76cef0c8ca87e1e642a8351e1713007898c764.zip frameworks_base-8c76cef0c8ca87e1e642a8351e1713007898c764.tar.gz frameworks_base-8c76cef0c8ca87e1e642a8351e1713007898c764.tar.bz2 |
Smoother transitions in GrassRS
Diffstat (limited to 'libs')
-rw-r--r-- | libs/rs/java/Grass/res/raw/grass.c | 40 | ||||
-rw-r--r-- | libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java | 16 |
2 files changed, 46 insertions, 10 deletions
diff --git a/libs/rs/java/Grass/res/raw/grass.c b/libs/rs/java/Grass/res/raw/grass.c index 50c7675..b1b89f0 100644 --- a/libs/rs/java/Grass/res/raw/grass.c +++ b/libs/rs/java/Grass/res/raw/grass.c @@ -1,5 +1,19 @@ -// Grass live wallpaper - +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #pragma version(1) #pragma stateVertex(default) #pragma stateFragment(PFBackground) @@ -8,7 +22,10 @@ #define WVGA_PORTRAIT_WIDTH 480.0f #define WVGA_PORTRAIT_HEIGHT 762.0f -#define RSID_SKY_TEXTURES 0 +#define RSID_STATE 0 +#define RSID_FRAMECOUNT 0 + +#define RSID_SKY_TEXTURES 1 #define RSID_SKY_TEXTURE_NIGHT 0 #define RSID_SKY_TEXTURE_SUNRISE 1 #define RSID_SKY_TEXTURE_NOON 2 @@ -19,8 +36,15 @@ #define AFTERNOON 0.6f #define DUSK 0.8f -float time() { - return (second() % 60) / 60.0f; +#define SECONDS_IN_DAY 24.0f * 3600.0f + +#define REAL_TIME 0 + +float time(int frameCount) { + if (REAL_TIME) { + return (hour() * 3600.0f + minute() * 60.0f + second()) / SECONDS_IN_DAY; + } + return (frameCount % 180) / 180.0f; } void alpha(float a) { @@ -53,7 +77,8 @@ void drawSunset() { } int main(int launchID) { - float now = time(); + int frameCount = loadI32(RSID_STATE, RSID_FRAMECOUNT); + float now = time(frameCount); alpha(1.0f); if (now >= MIDNIGHT && now < MORNING) { @@ -80,5 +105,8 @@ int main(int launchID) { drawNight(); } + frameCount++; + storeI32(RSID_STATE, RSID_FRAMECOUNT, frameCount); + return 1; } diff --git a/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java b/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java index 9ca7173..bb13051 100644 --- a/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java +++ b/libs/rs/java/Grass/src/com/android/grass/rs/GrassRS.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 The Android Open Source Project + * 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. @@ -25,13 +25,12 @@ import static android.renderscript.RenderScript.EnvMode.*; import static android.renderscript.RenderScript.DepthFunc.*; import static android.renderscript.RenderScript.BlendSrcFunc; import static android.renderscript.RenderScript.BlendDstFunc; -import android.graphics.BitmapFactory; -import android.graphics.Bitmap; import java.util.TimeZone; class GrassRS { - private static final int RSID_SKY_TEXTURES = 0; + private static final int RSID_STATE = 0; + private static final int RSID_SKY_TEXTURES = 1; private static final int SKY_TEXTURES_COUNT = 4; private Resources mResources; @@ -52,6 +51,8 @@ class GrassRS { private RenderScript.Allocation[] mSkyTextures; @SuppressWarnings({"FieldCanBeLocal"}) private int[] mSkyBufferIDs; + @SuppressWarnings({"FieldCanBeLocal"}) + private RenderScript.Allocation mState; public GrassRS() { } @@ -66,6 +67,7 @@ class GrassRS { createProgramVertex(); createProgramFragmentStore(); createProgramFragment(); + createScriptStructures(); mRS.scriptCBegin(); mRS.scriptCSetClearColor(0.0f, 0.0f, 0.0f, 1.0f); @@ -76,11 +78,17 @@ class GrassRS { mScript = mRS.scriptCCreate(); loadSkyTextures(); + mScript.bindAllocation(mState, RSID_STATE); mScript.bindAllocation(mSkyTexturesIDs, RSID_SKY_TEXTURES); mRS.contextBindRootScript(mScript); } + private void createScriptStructures() { + mState = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, 1); + mState.data(new int[1]); + } + private void loadSkyTextures() { mSkyBufferIDs = new int[SKY_TEXTURES_COUNT]; mSkyTextures = new RenderScript.Allocation[SKY_TEXTURES_COUNT]; |