• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/wallpapers/Basic


Commit MetaInfo

Revision55a384c62528636190cfe0762228d4c2795c6883 (tree)
Time2009-08-13 02:58:02
AuthorRomain Guy <romainguy@andr...>
CommiterRomain Guy

Log Message

Add packags/wallpapers/Basic to hold Android's live wallpapers.

Change Summary

Incremental Difference

--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,27 @@
1+#
2+# Copyright (C) 2008 The Android Open Source Project
3+#
4+# Licensed under the Apache License, Version 2.0 (the "License");
5+# you may not use this file except in compliance with the License.
6+# You may obtain a copy of the License at
7+#
8+# http://www.apache.org/licenses/LICENSE-2.0
9+#
10+# Unless required by applicable law or agreed to in writing, software
11+# distributed under the License is distributed on an "AS IS" BASIS,
12+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+# See the License for the specific language governing permissions and
14+# limitations under the License.
15+#
16+
17+LOCAL_PATH := $(call my-dir)
18+include $(CLEAR_VARS)
19+
20+# LOCAL_MODULE_TAGS := user
21+
22+LOCAL_SRC_FILES := $(call all-subdir-java-files)
23+
24+LOCAL_PACKAGE_NAME := LiveWallpapers
25+LOCAL_CERTIFICATE := shared
26+
27+include $(BUILD_PACKAGE)
--- /dev/null
+++ b/AndroidManifest.xml
@@ -0,0 +1,39 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!--
3+/*
4+**
5+** Copyright 2008, The Android Open Source Project
6+**
7+** Licensed under the Apache License, Version 2.0 (the "License");
8+** you may not use this file except in compliance with the License.
9+** You may obtain a copy of the License at
10+**
11+** http://www.apache.org/licenses/LICENSE-2.0
12+**
13+** Unless required by applicable law or agreed to in writing, software
14+** distributed under the License is distributed on an "AS IS" BASIS,
15+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+** See the License for the specific language governing permissions and
17+** limitations under the License.
18+*/
19+-->
20+<manifest
21+ xmlns:android="http://schemas.android.com/apk/res/android"
22+ package="com.android.wallpaper">
23+
24+ <application
25+ android:label="@string/wallpapers"
26+ android:icon="@drawable/ic_launcher_wallpaper">
27+
28+ <service
29+ android:label="@string/wallpaper_grass"
30+ android:name="com.android.wallpaper.grass.GrassWallpaper"
31+ android:permission="android.permission.BIND_WALLPAPER">
32+ <intent-filter>
33+ <action android:name="android.service.wallpaper.WallpaperService" />
34+ </intent-filter>
35+ </service>
36+
37+ </application>
38+
39+</manifest>
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,190 @@
1+
2+ Copyright (c) 2005-2008, The Android Open Source Project
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+
7+ Unless required by applicable law or agreed to in writing, software
8+ distributed under the License is distributed on an "AS IS" BASIS,
9+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+ See the License for the specific language governing permissions and
11+ limitations under the License.
12+
13+
14+ Apache License
15+ Version 2.0, January 2004
16+ http://www.apache.org/licenses/
17+
18+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
19+
20+ 1. Definitions.
21+
22+ "License" shall mean the terms and conditions for use, reproduction,
23+ and distribution as defined by Sections 1 through 9 of this document.
24+
25+ "Licensor" shall mean the copyright owner or entity authorized by
26+ the copyright owner that is granting the License.
27+
28+ "Legal Entity" shall mean the union of the acting entity and all
29+ other entities that control, are controlled by, or are under common
30+ control with that entity. For the purposes of this definition,
31+ "control" means (i) the power, direct or indirect, to cause the
32+ direction or management of such entity, whether by contract or
33+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
34+ outstanding shares, or (iii) beneficial ownership of such entity.
35+
36+ "You" (or "Your") shall mean an individual or Legal Entity
37+ exercising permissions granted by this License.
38+
39+ "Source" form shall mean the preferred form for making modifications,
40+ including but not limited to software source code, documentation
41+ source, and configuration files.
42+
43+ "Object" form shall mean any form resulting from mechanical
44+ transformation or translation of a Source form, including but
45+ not limited to compiled object code, generated documentation,
46+ and conversions to other media types.
47+
48+ "Work" shall mean the work of authorship, whether in Source or
49+ Object form, made available under the License, as indicated by a
50+ copyright notice that is included in or attached to the work
51+ (an example is provided in the Appendix below).
52+
53+ "Derivative Works" shall mean any work, whether in Source or Object
54+ form, that is based on (or derived from) the Work and for which the
55+ editorial revisions, annotations, elaborations, or other modifications
56+ represent, as a whole, an original work of authorship. For the purposes
57+ of this License, Derivative Works shall not include works that remain
58+ separable from, or merely link (or bind by name) to the interfaces of,
59+ the Work and Derivative Works thereof.
60+
61+ "Contribution" shall mean any work of authorship, including
62+ the original version of the Work and any modifications or additions
63+ to that Work or Derivative Works thereof, that is intentionally
64+ submitted to Licensor for inclusion in the Work by the copyright owner
65+ or by an individual or Legal Entity authorized to submit on behalf of
66+ the copyright owner. For the purposes of this definition, "submitted"
67+ means any form of electronic, verbal, or written communication sent
68+ to the Licensor or its representatives, including but not limited to
69+ communication on electronic mailing lists, source code control systems,
70+ and issue tracking systems that are managed by, or on behalf of, the
71+ Licensor for the purpose of discussing and improving the Work, but
72+ excluding communication that is conspicuously marked or otherwise
73+ designated in writing by the copyright owner as "Not a Contribution."
74+
75+ "Contributor" shall mean Licensor and any individual or Legal Entity
76+ on behalf of whom a Contribution has been received by Licensor and
77+ subsequently incorporated within the Work.
78+
79+ 2. Grant of Copyright License. Subject to the terms and conditions of
80+ this License, each Contributor hereby grants to You a perpetual,
81+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
82+ copyright license to reproduce, prepare Derivative Works of,
83+ publicly display, publicly perform, sublicense, and distribute the
84+ Work and such Derivative Works in Source or Object form.
85+
86+ 3. Grant of Patent License. Subject to the terms and conditions of
87+ this License, each Contributor hereby grants to You a perpetual,
88+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
89+ (except as stated in this section) patent license to make, have made,
90+ use, offer to sell, sell, import, and otherwise transfer the Work,
91+ where such license applies only to those patent claims licensable
92+ by such Contributor that are necessarily infringed by their
93+ Contribution(s) alone or by combination of their Contribution(s)
94+ with the Work to which such Contribution(s) was submitted. If You
95+ institute patent litigation against any entity (including a
96+ cross-claim or counterclaim in a lawsuit) alleging that the Work
97+ or a Contribution incorporated within the Work constitutes direct
98+ or contributory patent infringement, then any patent licenses
99+ granted to You under this License for that Work shall terminate
100+ as of the date such litigation is filed.
101+
102+ 4. Redistribution. You may reproduce and distribute copies of the
103+ Work or Derivative Works thereof in any medium, with or without
104+ modifications, and in Source or Object form, provided that You
105+ meet the following conditions:
106+
107+ (a) You must give any other recipients of the Work or
108+ Derivative Works a copy of this License; and
109+
110+ (b) You must cause any modified files to carry prominent notices
111+ stating that You changed the files; and
112+
113+ (c) You must retain, in the Source form of any Derivative Works
114+ that You distribute, all copyright, patent, trademark, and
115+ attribution notices from the Source form of the Work,
116+ excluding those notices that do not pertain to any part of
117+ the Derivative Works; and
118+
119+ (d) If the Work includes a "NOTICE" text file as part of its
120+ distribution, then any Derivative Works that You distribute must
121+ include a readable copy of the attribution notices contained
122+ within such NOTICE file, excluding those notices that do not
123+ pertain to any part of the Derivative Works, in at least one
124+ of the following places: within a NOTICE text file distributed
125+ as part of the Derivative Works; within the Source form or
126+ documentation, if provided along with the Derivative Works; or,
127+ within a display generated by the Derivative Works, if and
128+ wherever such third-party notices normally appear. The contents
129+ of the NOTICE file are for informational purposes only and
130+ do not modify the License. You may add Your own attribution
131+ notices within Derivative Works that You distribute, alongside
132+ or as an addendum to the NOTICE text from the Work, provided
133+ that such additional attribution notices cannot be construed
134+ as modifying the License.
135+
136+ You may add Your own copyright statement to Your modifications and
137+ may provide additional or different license terms and conditions
138+ for use, reproduction, or distribution of Your modifications, or
139+ for any such Derivative Works as a whole, provided Your use,
140+ reproduction, and distribution of the Work otherwise complies with
141+ the conditions stated in this License.
142+
143+ 5. Submission of Contributions. Unless You explicitly state otherwise,
144+ any Contribution intentionally submitted for inclusion in the Work
145+ by You to the Licensor shall be under the terms and conditions of
146+ this License, without any additional terms or conditions.
147+ Notwithstanding the above, nothing herein shall supersede or modify
148+ the terms of any separate license agreement you may have executed
149+ with Licensor regarding such Contributions.
150+
151+ 6. Trademarks. This License does not grant permission to use the trade
152+ names, trademarks, service marks, or product names of the Licensor,
153+ except as required for reasonable and customary use in describing the
154+ origin of the Work and reproducing the content of the NOTICE file.
155+
156+ 7. Disclaimer of Warranty. Unless required by applicable law or
157+ agreed to in writing, Licensor provides the Work (and each
158+ Contributor provides its Contributions) on an "AS IS" BASIS,
159+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
160+ implied, including, without limitation, any warranties or conditions
161+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
162+ PARTICULAR PURPOSE. You are solely responsible for determining the
163+ appropriateness of using or redistributing the Work and assume any
164+ risks associated with Your exercise of permissions under this License.
165+
166+ 8. Limitation of Liability. In no event and under no legal theory,
167+ whether in tort (including negligence), contract, or otherwise,
168+ unless required by applicable law (such as deliberate and grossly
169+ negligent acts) or agreed to in writing, shall any Contributor be
170+ liable to You for damages, including any direct, indirect, special,
171+ incidental, or consequential damages of any character arising as a
172+ result of this License or out of the use or inability to use the
173+ Work (including but not limited to damages for loss of goodwill,
174+ work stoppage, computer failure or malfunction, or any and all
175+ other commercial damages or losses), even if such Contributor
176+ has been advised of the possibility of such damages.
177+
178+ 9. Accepting Warranty or Additional Liability. While redistributing
179+ the Work or Derivative Works thereof, You may choose to offer,
180+ and charge a fee for, acceptance of support, warranty, indemnity,
181+ or other liability obligations and/or rights consistent with this
182+ License. However, in accepting such obligations, You may act only
183+ on Your own behalf and on Your sole responsibility, not on behalf
184+ of any other Contributor, and only if You agree to indemnify,
185+ defend, and hold each Contributor harmless for any liability
186+ incurred by, or claims asserted against, such Contributor by reason
187+ of your accepting any such warranty or additional liability.
188+
189+ END OF TERMS AND CONDITIONS
190+
Binary files /dev/null and b/res/drawable-hdpi/night.jpg differ
Binary files /dev/null and b/res/drawable-hdpi/sky.jpg differ
Binary files /dev/null and b/res/drawable-hdpi/sunrise.jpg differ
Binary files /dev/null and b/res/drawable-hdpi/sunset.jpg differ
Binary files /dev/null and b/res/drawable/ic_launcher_wallpaper.png differ
--- /dev/null
+++ b/res/raw/grass.c
@@ -0,0 +1,212 @@
1+// Copyright (C) 2009 The Android Open Source Project
2+//
3+// Licensed under the Apache License, Version 2.0 (the "License");
4+// you may not use this file except in compliance with the License.
5+// You may obtain a copy of the License at
6+//
7+// http://www.apache.org/licenses/LICENSE-2.0
8+//
9+// Unless required by applicable law or agreed to in writing, software
10+// distributed under the License is distributed on an "AS IS" BASIS,
11+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+// See the License for the specific language governing permissions and
13+// limitations under the License.
14+
15+#pragma version(1)
16+#pragma stateVertex(PVBackground)
17+#pragma stateFragment(PFBackground)
18+#pragma stateFragmentStore(PFSBackground)
19+
20+#define RSID_STATE 0
21+#define RSID_FRAME_COUNT 0
22+#define RSID_BLADES_COUNT 1
23+#define RSID_WIDTH 2
24+#define RSID_HEIGHT 3
25+
26+#define RSID_BLADES 1
27+#define BLADE_STRUCT_FIELDS_COUNT 12
28+#define BLADE_STRUCT_ANGLE 0
29+#define BLADE_STRUCT_SIZE 1
30+#define BLADE_STRUCT_XPOS 2
31+#define BLADE_STRUCT_YPOS 3
32+#define BLADE_STRUCT_OFFSET 4
33+#define BLADE_STRUCT_SCALE 5
34+#define BLADE_STRUCT_LENGTHX 6
35+#define BLADE_STRUCT_LENGTHY 7
36+#define BLADE_STRUCT_HARDNESS 8
37+#define BLADE_STRUCT_H 9
38+#define BLADE_STRUCT_S 10
39+#define BLADE_STRUCT_B 11
40+
41+#define TESSELATION 2.0f
42+
43+#define MAX_BEND 0.09f
44+
45+#define MIDNIGHT 0.0f
46+#define MORNING 0.375f
47+#define AFTERNOON 0.6f
48+#define DUSK 0.8f
49+
50+#define SECONDS_IN_DAY 24.0f * 3600.0f
51+
52+#define PI 3.1415926f
53+
54+#define REAL_TIME 0
55+
56+float time(int frameCount) {
57+ if (REAL_TIME) {
58+ return (hour() * 3600.0f + minute() * 60.0f + second()) / SECONDS_IN_DAY;
59+ }
60+ return (frameCount % 180) / 180.0f;
61+}
62+
63+void alpha(float a) {
64+ color(1.0f, 1.0f, 1.0f, a);
65+}
66+
67+void drawNight(int width, int height) {
68+ bindProgramFragment(NAMED_PFNight);
69+ bindTexture(NAMED_PFNight, 0, NAMED_TNight);
70+ drawQuadTexCoords(
71+ 0.0f, -32.0f, 0.0f,
72+ 0.0f, 1.0f,
73+ width, -32.0f, 0.0f,
74+ 2.0f, 1.0f,
75+ width, 1024.0f - 32.0f, 0.0f,
76+ 2.0f, 0.0f,
77+ 0.0f, 1024.0f - 32.0f, 0.0f,
78+ 0.0f, 0.0f);
79+ bindProgramFragment(NAMED_PFBackground);
80+}
81+
82+void drawSunrise(int width, int height) {
83+ bindTexture(NAMED_PFBackground, 0, NAMED_TSunrise);
84+ drawRect(0.0f, 0.0f, width, height, 0.0f);
85+}
86+
87+void drawNoon(int width, int height) {
88+ bindTexture(NAMED_PFBackground, 0, NAMED_TSky);
89+ drawRect(0.0f, 0.0f, width, height, 0.0f);
90+}
91+
92+void drawSunset(int width, int height) {
93+ bindTexture(NAMED_PFBackground, 0, NAMED_TSunset);
94+ drawRect(0.0f, 0.0f, width, height, 0.0f);
95+}
96+
97+void drawBlade(int index, float now, int frameCount) {
98+ float *bladeStruct = loadArrayF(RSID_BLADES, index);
99+ float offset = bladeStruct[BLADE_STRUCT_OFFSET];
100+ float scale = bladeStruct[BLADE_STRUCT_SCALE];
101+ float angle = bladeStruct[BLADE_STRUCT_ANGLE];
102+ float hardness = bladeStruct[BLADE_STRUCT_HARDNESS];
103+
104+ float xpos = bladeStruct[BLADE_STRUCT_XPOS];
105+ float ypos = bladeStruct[BLADE_STRUCT_YPOS];
106+
107+ float lengthX = bladeStruct[BLADE_STRUCT_LENGTHX];
108+ float lengthY = bladeStruct[BLADE_STRUCT_LENGTHY];
109+
110+ int size = bladeStruct[BLADE_STRUCT_SIZE];
111+
112+ float h = bladeStruct[BLADE_STRUCT_H];
113+ float s = bladeStruct[BLADE_STRUCT_S];
114+ float b = bladeStruct[BLADE_STRUCT_B];
115+
116+ float newB = 1.0f;
117+ if (now >= MIDNIGHT && now < MORNING) {
118+ newB = now / MORNING;
119+ }
120+
121+ if (now >= AFTERNOON && now < DUSK) {
122+ newB = 1.0f - normf(AFTERNOON, DUSK, now);
123+ }
124+
125+ if (now >= DUSK) {
126+ newB = 0.0f;
127+ }
128+
129+ hsb(h, s, lerpf(0, b, newB), 1.0f);
130+
131+ float newAngle = turbulencef2(xpos * 0.006f, frameCount * 0.006f, 4.0f) - 0.5f;
132+ newAngle /= 2.0f;
133+ angle = clampf(angle + (newAngle + offset - angle) * 0.15f, -MAX_BEND, MAX_BEND);
134+
135+ float currentAngle = PI / 2.0f;
136+
137+ float bottomX = xpos;
138+ float bottomY = ypos;
139+
140+ int i = size * TESSELATION;
141+ float lx = lengthX / TESSELATION;
142+ float ly = lengthY / TESSELATION;
143+ float ss = 4.0f / i + scale / TESSELATION;
144+ float sh = 0.5f / TESSELATION;
145+ float d = angle * hardness / TESSELATION;
146+
147+ for ( ; i > 0; i--) {
148+ float topX = bottomX - cosf(currentAngle) * size * lx;
149+ float topY = bottomY - sinf(currentAngle) * size * ly;
150+ currentAngle += d;
151+
152+ float spi = (i - 1) * ss;
153+ float si = i * ss;
154+
155+ drawQuad(topX + spi, topY, 0.0f,
156+ topX - spi, topY, 0.0f,
157+ bottomX - si, bottomY + sh, 0.0f,
158+ bottomX + si, bottomY + sh, 0.0f);
159+
160+ bottomX = topX;
161+ bottomY = topY;
162+ }
163+
164+ storeF(RSID_BLADES, index + BLADE_STRUCT_ANGLE, angle);
165+}
166+
167+void drawBlades(float now, int frameCount) {
168+ // For anti-aliasing
169+ bindTexture(NAMED_PFBackground, 0, NAMED_TAa);
170+
171+ int bladesCount = loadI32(RSID_STATE, RSID_BLADES_COUNT);
172+ int count = bladesCount * BLADE_STRUCT_FIELDS_COUNT;
173+
174+ int i = 0;
175+ for ( ; i < count; i += BLADE_STRUCT_FIELDS_COUNT) {
176+ drawBlade(i, now, frameCount);
177+ }
178+}
179+
180+int main(int launchID) {
181+ int width = loadI32(RSID_STATE, RSID_WIDTH);
182+ int height = loadI32(RSID_STATE, RSID_HEIGHT);
183+
184+ int frameCount = loadI32(RSID_STATE, RSID_FRAME_COUNT);
185+ float now = time(frameCount);
186+ alpha(1.0f);
187+
188+ if (now >= MIDNIGHT && now < MORNING) {
189+ drawNight(width, height);
190+ alpha(normf(MIDNIGHT, MORNING, now));
191+ drawSunrise(width, height);
192+ } else if (now >= MORNING && now < AFTERNOON) {
193+ drawSunrise(width, height);
194+ alpha(normf(MORNING, AFTERNOON, now));
195+ drawNoon(width, height);
196+ } else if (now >= AFTERNOON && now < DUSK) {
197+ drawNoon(width, height);
198+ alpha(normf(AFTERNOON, DUSK, now));
199+ drawSunset(width, height);
200+ } else if (now >= DUSK) {
201+ drawNight(width, height);
202+ alpha(1.0f - normf(DUSK, 1.0f, now));
203+ drawSunset(width, height);
204+ }
205+
206+ drawBlades(now, frameCount);
207+
208+ frameCount++;
209+ storeI32(RSID_STATE, RSID_FRAME_COUNT, frameCount);
210+
211+ return 1;
212+}
--- /dev/null
+++ b/res/values/strings.xml
@@ -0,0 +1,31 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!--
3+/*
4+* Copyright (C) 2008 The Android Open Source Project
5+*
6+* Licensed under the Apache License, Version 2.0 (the "License");
7+* you may not use this file except in compliance with the License.
8+* You may obtain a copy of the License at
9+*
10+* http://www.apache.org/licenses/LICENSE-2.0
11+*
12+* Unless required by applicable law or agreed to in writing, software
13+* distributed under the License is distributed on an "AS IS" BASIS,
14+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+* See the License for the specific language governing permissions and
16+* limitations under the License.
17+*/
18+-->
19+
20+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
21+ <!-- General -->
22+ <skip />
23+ <!-- Application name -->
24+ <string name="wallpapers">Android Live Wallpapers</string>
25+
26+ <!-- Wallpapers: -->
27+ <skip />
28+
29+ <!-- Wallpaper showing grass and the sky -->
30+ <string name="wallpaper_grass">Grass</string>
31+</resources>
--- /dev/null
+++ b/src/com/android/wallpaper/grass/GrassRS.java
@@ -0,0 +1,262 @@
1+/*
2+ * Copyright (C) 2009 The Android Open Source Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+package com.android.wallpaper.grass;
18+
19+import android.content.res.Resources;
20+import android.renderscript.Sampler;
21+import static android.renderscript.ProgramFragment.EnvMode.*;
22+import static android.renderscript.ProgramStore.DepthFunc.*;
23+import static android.renderscript.ProgramStore.BlendSrcFunc;
24+import static android.renderscript.ProgramStore.BlendDstFunc;
25+import android.renderscript.RenderScript;
26+import android.renderscript.ProgramFragment;
27+import android.renderscript.ProgramStore;
28+import android.renderscript.Allocation;
29+import android.renderscript.ProgramVertex;
30+import static android.renderscript.Element.*;
31+import static android.util.MathUtils.*;
32+import android.renderscript.ScriptC;
33+import android.renderscript.Type;
34+import android.renderscript.Dimension;
35+import static android.renderscript.Sampler.Value.*;
36+import com.android.wallpaper.R;
37+
38+import java.util.TimeZone;
39+
40+class GrassRS {
41+ private static final int RSID_STATE = 0;
42+ private static final int RSID_STATE_FRAMECOUNT = 0;
43+ private static final int RSID_STATE_BLADES_COUNT = 1;
44+ private static final int RSID_STATE_WIDTH = 2;
45+ private static final int RSID_STATE_HEIGHT = 3;
46+
47+ private static final int TEXTURES_COUNT = 5;
48+
49+ private static final int RSID_BLADES = 1;
50+ private static final int BLADES_COUNT = 200;
51+ private static final int BLADE_STRUCT_FIELDS_COUNT = 12;
52+ private static final int BLADE_STRUCT_ANGLE = 0;
53+ private static final int BLADE_STRUCT_SIZE = 1;
54+ private static final int BLADE_STRUCT_XPOS = 2;
55+ private static final int BLADE_STRUCT_YPOS = 3;
56+ private static final int BLADE_STRUCT_OFFSET = 4;
57+ private static final int BLADE_STRUCT_SCALE = 5;
58+ private static final int BLADE_STRUCT_LENGTHX = 6;
59+ private static final int BLADE_STRUCT_LENGTHY = 7;
60+ private static final int BLADE_STRUCT_HARDNESS = 8;
61+ private static final int BLADE_STRUCT_H = 9;
62+ private static final int BLADE_STRUCT_S = 10;
63+ private static final int BLADE_STRUCT_B = 11;
64+
65+ private Resources mResources;
66+ private RenderScript mRS;
67+
68+ private final int mWidth;
69+ private final int mHeight;
70+
71+ private ScriptC mScript;
72+ private Sampler mSampler;
73+ private Sampler mNightSampler;
74+ private ProgramFragment mPfBackground;
75+ private ProgramFragment mPfNight;
76+ private ProgramStore mPfsBackground;
77+ private ProgramVertex mPvBackground;
78+ private ProgramVertex.MatrixAllocation mPvOrthoAlloc;
79+
80+ private Allocation[] mTextures;
81+
82+ private Allocation mState;
83+ private Allocation mBlades;
84+
85+ public GrassRS(int width, int height) {
86+ mWidth = width;
87+ mHeight = height;
88+ }
89+
90+ public void init(RenderScript rs, Resources res) {
91+ mRS = rs;
92+ mResources = res;
93+ initRS();
94+ }
95+
96+ public void destroy() {
97+ mScript.destroy();
98+ mSampler.destroy();
99+ mPfBackground.destroy();
100+ mPfsBackground.destroy();
101+ mPvBackground.destroy();
102+ mPvOrthoAlloc.mAlloc.destroy();
103+ for (Allocation a : mTextures) {
104+ a.destroy();
105+ }
106+ mState.destroy();
107+ mBlades.destroy();
108+ mNightSampler.destroy();
109+ mPfNight.destroy();
110+ }
111+
112+ @Override
113+ protected void finalize() throws Throwable {
114+ try {
115+ destroy();
116+ } finally {
117+ super.finalize();
118+ }
119+ }
120+
121+ private void initRS() {
122+ createProgramVertex();
123+ createProgramFragmentStore();
124+ createProgramFragment();
125+ createScriptStructures();
126+ loadTextures();
127+
128+ ScriptC.Builder sb = new ScriptC.Builder(mRS);
129+ sb.setScript(mResources, R.raw.grass);
130+ sb.setRoot(true);
131+ mScript = sb.create();
132+ mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
133+ mScript.setTimeZone(TimeZone.getDefault().getID());
134+
135+ mScript.bindAllocation(mState, RSID_STATE);
136+ mScript.bindAllocation(mBlades, RSID_BLADES);
137+
138+ mRS.contextBindRootScript(mScript);
139+ }
140+
141+ private void createScriptStructures() {
142+ final int[] data = new int[4];
143+ mState = Allocation.createSized(mRS, USER_I32, data.length);
144+ data[RSID_STATE_FRAMECOUNT] = 0;
145+ data[RSID_STATE_BLADES_COUNT] = BLADES_COUNT;
146+ data[RSID_STATE_WIDTH] = mWidth;
147+ data[RSID_STATE_HEIGHT] = mHeight;
148+ mState.data(data);
149+
150+ final float[] blades = new float[BLADES_COUNT * BLADE_STRUCT_FIELDS_COUNT];
151+ mBlades = Allocation.createSized(mRS, USER_FLOAT, blades.length);
152+ for (int i = 0; i < blades.length; i+= BLADE_STRUCT_FIELDS_COUNT) {
153+ createBlade(blades, i);
154+ }
155+ mBlades.data(blades);
156+ }
157+
158+ private void createBlade(float[] blades, int index) {
159+ //noinspection PointlessArithmeticExpression
160+ blades[index + BLADE_STRUCT_ANGLE] = 0.0f;
161+ blades[index + BLADE_STRUCT_SIZE] = random(4.0f) + 4.0f;
162+ blades[index + BLADE_STRUCT_XPOS] = random(mWidth);
163+ blades[index + BLADE_STRUCT_YPOS] = mHeight;
164+ blades[index + BLADE_STRUCT_OFFSET] = random(0.2f) - 0.1f;
165+ blades[index + BLADE_STRUCT_SCALE] = random(0.6f) + 0.2f;
166+ blades[index + BLADE_STRUCT_LENGTHX] = random(4.5f) + 3.0f;
167+ blades[index + BLADE_STRUCT_LENGTHY] = random(5.5f) + 2.0f;
168+ blades[index + BLADE_STRUCT_HARDNESS] = random(1.0f) + 0.2f;
169+ blades[index + BLADE_STRUCT_H] = random(0.02f) + 0.2f;
170+ blades[index + BLADE_STRUCT_S] = random(0.22f) + 0.78f;
171+ blades[index + BLADE_STRUCT_B] = random(0.65f) + 0.35f;
172+ }
173+
174+ private void loadTextures() {
175+ mTextures = new Allocation[TEXTURES_COUNT];
176+
177+ final Allocation[] textures = mTextures;
178+ textures[0] = loadTexture(R.drawable.night, "TNight");
179+ textures[1] = loadTexture(R.drawable.sunrise, "TSunrise");
180+ textures[2] = loadTexture(R.drawable.sky, "TSky");
181+ textures[3] = loadTexture(R.drawable.sunset, "TSunset");
182+ textures[4] = generateTextureAlpha(4, 1, new int[] { 0x00FFFF00 }, "TAa");
183+
184+ final int count = textures.length;
185+ for (int i = 0; i < count; i++) {
186+ final Allocation texture = textures[i];
187+ texture.uploadToTexture(0);
188+ }
189+ }
190+
191+ private Allocation generateTextureAlpha(int width, int height, int[] data, String name) {
192+ final Type.Builder builder = new Type.Builder(mRS, A_8);
193+ builder.add(Dimension.X, width);
194+ builder.add(Dimension.Y, height);
195+
196+ final Allocation allocation = Allocation.createTyped(mRS, builder.create());
197+ allocation.data(data);
198+ allocation.setName(name);
199+ return allocation;
200+ }
201+
202+ private Allocation loadTexture(int id, String name) {
203+ final Allocation allocation = Allocation.createFromBitmapResource(mRS, mResources,
204+ id, RGB_565, false);
205+ allocation.setName(name);
206+ return allocation;
207+ }
208+
209+ private void createProgramFragment() {
210+ Sampler.Builder bs = new Sampler.Builder(mRS);
211+ bs.setMin(LINEAR);
212+ bs.setMag(LINEAR);
213+ bs.setWrapS(CLAMP);
214+ bs.setWrapT(CLAMP);
215+ mSampler = bs.create();
216+
217+ ProgramFragment.Builder b;
218+ b = new ProgramFragment.Builder(mRS, null, null);
219+ b.setTexEnable(true, 0);
220+ b.setTexEnvMode(REPLACE, 0);
221+ mPfBackground = b.create();
222+ mPfBackground.setName("PFBackground");
223+ mPfBackground.bindSampler(mSampler, 0);
224+
225+ bs = new Sampler.Builder(mRS);
226+ bs.setMin(LINEAR);
227+ bs.setMag(LINEAR);
228+ bs.setWrapS(WRAP);
229+ bs.setWrapT(WRAP);
230+ mNightSampler = bs.create();
231+
232+ b = new ProgramFragment.Builder(mRS, null, null);
233+ b.setTexEnable(true, 0);
234+ b.setTexEnvMode(REPLACE, 0);
235+ mPfNight = b.create();
236+ mPfNight.setName("PFNight");
237+ mPfNight.bindSampler(mNightSampler, 0);
238+ }
239+
240+ private void createProgramFragmentStore() {
241+ ProgramStore.Builder b;
242+ b = new ProgramStore.Builder(mRS, null, null);
243+
244+ b.setDepthFunc(ALWAYS);
245+ b.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
246+ b.setDitherEnable(true);
247+ b.setDepthMask(false);
248+ mPfsBackground = b.create();
249+ mPfsBackground.setName("PFSBackground");
250+ }
251+
252+ private void createProgramVertex() {
253+ mPvOrthoAlloc = new ProgramVertex.MatrixAllocation(mRS);
254+ mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
255+
256+ ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
257+ pvb.setTextureMatrixEnable(true);
258+ mPvBackground = pvb.create();
259+ mPvBackground.bindAllocation(mPvOrthoAlloc);
260+ mPvBackground.setName("PVBackground");
261+ }
262+}
--- /dev/null
+++ b/src/com/android/wallpaper/grass/GrassWallpaper.java
@@ -0,0 +1,73 @@
1+/*
2+ * Copyright (C) 2009 The Android Open Source Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+package com.android.wallpaper.grass;
18+
19+import android.service.wallpaper.WallpaperService;
20+import android.view.SurfaceHolder;
21+import android.view.Surface;
22+import android.renderscript.RenderScript;
23+
24+public class GrassWallpaper extends WallpaperService {
25+ public Engine onCreateEngine() {
26+ return new RenderScriptEngine();
27+ }
28+
29+ private class RenderScriptEngine extends Engine {
30+ private RenderScript mRs;
31+ private GrassRS mRenderer;
32+
33+ @Override
34+ public void onCreate(SurfaceHolder surfaceHolder) {
35+ super.onCreate(surfaceHolder);
36+ surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
37+ }
38+
39+ @Override
40+ public void onDestroy() {
41+ super.onDestroy();
42+ }
43+
44+ @Override
45+ public void onVisibilityChanged(boolean visible) {
46+ super.onVisibilityChanged(visible);
47+ }
48+
49+ @Override
50+ public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
51+ super.onSurfaceChanged(holder, format, width, height);
52+ mRenderer = new GrassRS(width, height);
53+ mRenderer.init(mRs, getResources());
54+ }
55+
56+ @Override
57+ public void onSurfaceCreated(SurfaceHolder holder) {
58+ super.onSurfaceCreated(holder);
59+
60+ Surface surface = null;
61+ while (surface == null) {
62+ surface = holder.getSurface();
63+ }
64+ mRs = new RenderScript(surface);
65+ }
66+
67+ @Override
68+ public void onSurfaceDestroyed(SurfaceHolder holder) {
69+ super.onSurfaceDestroyed(holder);
70+ mRenderer.destroy();
71+ }
72+ }
73+}