OSDN Git Service

Improve Grass' performance, add thumbnails for all wallpapers, better previews.
authorRomain Guy <romainguy@android.com>
Wed, 14 Oct 2009 22:43:27 +0000 (15:43 -0700)
committerRomain Guy <romainguy@android.com>
Wed, 14 Oct 2009 22:43:27 +0000 (15:43 -0700)
Change-Id: I2a02a74ec2df628f77de2536e875941a796ad5de

14 files changed:
res/drawable-hdpi/galaxy_thumb.jpg [new file with mode: 0644]
res/drawable-hdpi/grass_thumb.jpg [new file with mode: 0644]
res/drawable-hdpi/polarclock_thumb.jpg [new file with mode: 0644]
res/drawable-hdpi/polarclock_thumb.png [deleted file]
res/drawable-hdpi/water_thumb.jpg [new file with mode: 0644]
res/raw/fall.rs
res/raw/grass.rs
res/xml/fall.xml
res/xml/galaxy.xml
res/xml/grass.xml
res/xml/polar_clock.xml
src/com/android/wallpaper/fall/FallRS.java
src/com/android/wallpaper/grass/GrassRS.java
src/com/android/wallpaper/polarclock/PolarClockWallpaper.java

diff --git a/res/drawable-hdpi/galaxy_thumb.jpg b/res/drawable-hdpi/galaxy_thumb.jpg
new file mode 100644 (file)
index 0000000..70c38a1
Binary files /dev/null and b/res/drawable-hdpi/galaxy_thumb.jpg differ
diff --git a/res/drawable-hdpi/grass_thumb.jpg b/res/drawable-hdpi/grass_thumb.jpg
new file mode 100644 (file)
index 0000000..0383053
Binary files /dev/null and b/res/drawable-hdpi/grass_thumb.jpg differ
diff --git a/res/drawable-hdpi/polarclock_thumb.jpg b/res/drawable-hdpi/polarclock_thumb.jpg
new file mode 100644 (file)
index 0000000..c568bc6
Binary files /dev/null and b/res/drawable-hdpi/polarclock_thumb.jpg differ
diff --git a/res/drawable-hdpi/polarclock_thumb.png b/res/drawable-hdpi/polarclock_thumb.png
deleted file mode 100644 (file)
index 7994f4f..0000000
Binary files a/res/drawable-hdpi/polarclock_thumb.png and /dev/null differ
diff --git a/res/drawable-hdpi/water_thumb.jpg b/res/drawable-hdpi/water_thumb.jpg
new file mode 100644 (file)
index 0000000..56be4bc
Binary files /dev/null and b/res/drawable-hdpi/water_thumb.jpg differ
index c60711d..b6984dd 100644 (file)
@@ -34,6 +34,8 @@
 float skyOffsetX;
 float skyOffsetY;
 
+int lastDrop;
+
 struct vert_s {
     float x;
     float y;
@@ -50,18 +52,21 @@ int offset(int x, int y, int width) {
 }
 
 void initLeaves() {
+    if (State->isPreview) lastDrop = uptimeMillis();
+
     struct Leaves_s *leaf = Leaves;
     int leavesCount = State->leavesCount;
+    float width = State->glWidth;
     float height = State->glHeight;
 
     int i;
     for (i = 0; i < leavesCount; i ++) {
         int sprite = randf(LEAVES_TEXTURES_COUNT);
-        leaf->x = randf2(-1.0f, 1.0f);
-        leaf->y = randf2(-height / 2.0f, height / 2.0f);
+        leaf->x = randf2(-width * 0.5f, width * 0.5f);
+        leaf->y = randf2(-height * 0.5f, height * 0.5f);
         leaf->scale = randf2(0.4f, 0.5f);
         leaf->angle = randf2(0.0f, 360.0f);
-        leaf->spin = degf(randf2(-0.02f, 0.02f)) / 4.0f;
+        leaf->spin = degf(randf2(-0.02f, 0.02f)) * 0.25f;
         leaf->u1 = sprite / (float) LEAVES_TEXTURES_COUNT;
         leaf->u2 = (sprite + 1) / (float) LEAVES_TEXTURES_COUNT;
         leaf->altitude = -1.0f;
@@ -332,10 +337,10 @@ void drawLeaf(struct Leaves_s *leaf, int meshWidth, int meshHeight, float glWidt
             LEAF_SIZE * s + y < -glHeight / 2.0f) {
 
         int sprite = randf(LEAVES_TEXTURES_COUNT);
-        leaf->x = randf2(-1.0f, 1.0f);
-        leaf->y = randf2(-glHeight / 2.0f, glHeight / 2.0f);
+        leaf->x = randf2(-glWidth * 0.5f, glWidth * 0.5f);
+        leaf->y = randf2(-glHeight * 0.5f, glHeight * 0.5f);
         leaf->scale = randf2(0.4f, 0.5f);
-        leaf->spin = degf(randf2(-0.02f, 0.02f)) / 4.0f;
+        leaf->spin = degf(randf2(-0.02f, 0.02f)) * 0.25f;
         leaf->u1 = sprite / (float) LEAVES_TEXTURES_COUNT;
         leaf->u2 = (sprite + 1) / (float) LEAVES_TEXTURES_COUNT;
         leaf->altitude = 0.6f;
@@ -453,6 +458,18 @@ int main(int index) {
         Drop->dropX = -1;
         Drop->dropY = -1;
     }
+    
+    if (State->isPreview) {
+        int now = uptimeMillis();
+        if (now - lastDrop > 2000) {
+            float x = randf(State->meshWidth);
+            float y = randf(State->meshHeight);
+
+            drop(x, y, DROP_RADIUS);
+
+            lastDrop = now;
+        }
+    }    
 
     updateRipples();
     generateRipples();
index 56405b8..1d34ac2 100644 (file)
 
 #define REAL_TIME 1
 
-float time() {
-    if (REAL_TIME) {
+float time(int isPreview) {
+    if (REAL_TIME && !isPreview) {
         return (hour() * 3600.0f + minute() * 60.0f + second()) / SECONDS_IN_DAY;
     }
-    float t = uptimeMillis() / 40000.0f;
+    float t = uptimeMillis() / 30000.0f;
     return t - (int) t;
 }
 
@@ -89,7 +89,7 @@ void drawSunset(int width, int height) {
 }
 
 int drawBlade(float *bladeStruct, float *bladeBuffer, int *bladeColor,
-        float brightness, float xOffset) {
+        float brightness, float xOffset, float now) {
 
     float offset = bladeStruct[BLADE_STRUCT_OFFSET];
     float scale = bladeStruct[BLADE_STRUCT_SCALE];
@@ -111,8 +111,7 @@ int drawBlade(float *bladeStruct, float *bladeBuffer, int *bladeColor,
 
     int color = hsbToAbgr(h, s, lerpf(0, b, brightness), 1.0f);
 
-    float newAngle = turbulencef2(turbulenceX, uptimeMillis() * 0.00004f, 4.0f) - 0.5f;
-    newAngle *= 0.5f;
+    float newAngle = (turbulencef2(turbulenceX, now, 4.0f) - 0.5f) * 0.5f;
     angle = clampf(angle + (newAngle + offset - angle) * 0.15f, -MAX_BEND, MAX_BEND);
 
     float currentAngle = HALF_PI;
@@ -198,9 +197,11 @@ void drawBlades(float brightness, float xOffset) {
     float *bladeStruct = loadArrayF(RSID_BLADES, 0);
     float *bladeBuffer = loadArrayF(RSID_BLADES_BUFFER, 0);
     int *bladeColor = loadArrayI32(RSID_BLADES_BUFFER, 0);
+    
+    float now = uptimeMillis() * 0.00004f;
 
     for ( ; i < bladesCount; i += 1) {
-        int offset = drawBlade(bladeStruct, bladeBuffer, bladeColor, brightness, xOffset);
+        int offset = drawBlade(bladeStruct, bladeBuffer, bladeColor, brightness, xOffset, now);
         bladeBuffer += offset;
         bladeColor += offset;
         bladeStruct += BLADE_STRUCT_FIELDS_COUNT;
@@ -216,7 +217,7 @@ int main(int launchID) {
 
     float x = lerpf(width, 0, State->xOffset);
 
-    float now = time();
+    float now = time(State->isPreview);
     alpha(1.0f);
 
     float newB = 1.0f;
index fedfa7e..9c1b0d3 100644 (file)
@@ -21,4 +21,4 @@
 <!-- about the fall wallpaper. -->
 
 <wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
-/>
+    android:thumbnail="@drawable/water_thumb" />
index 2fc7e70..b88eec5 100644 (file)
@@ -21,4 +21,4 @@
 <!-- about the galaxy wallpaper. -->
 
 <wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
-/>
+    android:thumbnail="@drawable/galaxy_thumb" />
\ No newline at end of file
index d1d6f1b..9c88e67 100644 (file)
@@ -21,4 +21,4 @@
 <!-- about the grass wallpaper. -->
 
 <wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
-/>
+    android:thumbnail="@drawable/grass_thumb" />
index 56702ac..4066968 100644 (file)
@@ -21,6 +21,5 @@
 <!-- about the polar clock. -->
 
 <wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
-               android:thumbnail="@drawable/polarclock_thumb"
-        android:settingsActivity="com.android.wallpaper.polarclock.PolarClockSettings"
-/>
+    android:thumbnail="@drawable/polarclock_thumb"
+    android:settingsActivity="com.android.wallpaper.polarclock.PolarClockSettings" />
index 06bf97b..cdb1384 100644 (file)
@@ -262,6 +262,7 @@ class FallRS extends RenderScriptScene {
         public float skySpeedX;
         public float skySpeedY;
         public int rotate;
+        public int isPreview;
     }
 
     static class DropState {
@@ -283,6 +284,7 @@ class FallRS extends RenderScriptScene {
         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;
 
         mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
         mState = Allocation.createTyped(mRS, mStateType);
index e824d7e..7ce391b 100644 (file)
@@ -217,14 +217,21 @@ class GrassRS extends RenderScriptScene {
         public float morning;
         public float afternoon;
         public float dusk;
+        public int isPreview;
     }
 
     private void createState() {
+        final boolean isPreview = isPreview();
+
         mWorldState = new WorldState();
         mWorldState.width = mWidth;
         mWorldState.height = mHeight;
         mWorldState.bladesCount = BLADES_COUNT;
         mWorldState.trianglesCount = mTriangles;
+        mWorldState.isPreview = isPreview ? 1 : 0;
+        if (isPreview) {
+            mWorldState.xOffset = 0.5f;
+        }
 
         mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
         mState = Allocation.createTyped(mRS, mStateType);
index ab0452a..507ba70 100644 (file)
@@ -34,6 +34,7 @@ import android.os.Handler;
 import android.os.SystemClock;
 import android.text.format.Time;
 import android.util.MathUtils;
+import android.util.Log;
 
 import java.util.HashMap;
 import java.util.TimeZone;
@@ -45,13 +46,15 @@ import static org.xmlpull.v1.XmlPullParser.*;
 import com.android.wallpaper.R;
 
 public class PolarClockWallpaper extends WallpaperService {
-    public static final String SHARED_PREFS_NAME = "polar_clock_settings";
+    private static final String LOG_TAG = "PolarClock";
+    
+    static final String SHARED_PREFS_NAME = "polar_clock_settings";
 
-    public static final String PREF_SHOW_SECONDS = "show_seconds";
-    public static final String PREF_VARIABLE_LINE_WIDTH = "variable_line_width";
-    public static final String PREF_PALETTE = "palette";
+    static final String PREF_SHOW_SECONDS = "show_seconds";
+    static final String PREF_VARIABLE_LINE_WIDTH = "variable_line_width";
+    static final String PREF_PALETTE = "palette";
 
-    public static final int BACKGROUND_COLOR = 0xffffffff;
+    static final int BACKGROUND_COLOR = 0xffffffff;
 
     static abstract class ClockPalette {
         public static ClockPalette parseXmlPaletteTag(XmlResourceParser xrp) {
@@ -271,8 +274,7 @@ public class PolarClockWallpaper extends WallpaperService {
         return new ClockEngine();
     }
 
-    class ClockEngine extends Engine
-            implements SharedPreferences.OnSharedPreferenceChangeListener {
+    class ClockEngine extends Engine implements SharedPreferences.OnSharedPreferenceChangeListener {
         private static final float SMALL_RING_THICKNESS = 8.0f;
         private static final float MEDIUM_RING_THICKNESS = 16.0f;
         private static final float LARGE_RING_THICKNESS = 32.0f;
@@ -329,9 +331,9 @@ public class PolarClockWallpaper extends WallpaperService {
                     what = xrp.next();
                 }
             } catch (IOException e) {
-                // XXX: Log?
+                Log.e(LOG_TAG, "An error occured during wallpaper configuration:", e);
             } catch (XmlPullParserException e) {
-                // XXX: Log?
+                Log.e(LOG_TAG, "An error occured during wallpaper configuration:", e);
             } finally {
                 xrp.close();
             }
@@ -358,6 +360,10 @@ public class PolarClockWallpaper extends WallpaperService {
             paint.setStrokeWidth(DEFAULT_RING_THICKNESS);
             paint.setStrokeCap(Paint.Cap.ROUND);
             paint.setStyle(Paint.Style.STROKE);
+
+            if (isPreview()) {
+                mOffsetX = 0.5f;            
+            }
         }
 
         @Override
@@ -446,7 +452,7 @@ public class PolarClockWallpaper extends WallpaperService {
 
         void drawFrame() {
             if (mPalette == null) {
-                android.util.Log.w("PolarClockWallpaper", "no palette?!");
+                Log.w("PolarClockWallpaper", "no palette?!");
                 return;
             }