• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
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

修订版9e6f2347087ab40539b4c4b76f4b050f02184436 (tree)
时间2009-08-25 10:40:21
作者Romain Guy <romainguy@andr...>
CommiterRomain Guy

Log Message

Provide better support for orientation change. Very much work in progress still.

Change-Id: I73cdd43d25ccbb200d0fd91f70202a80d0e90d77

更改概述

差异

--- a/res/raw/galaxy.c
+++ b/res/raw/galaxy.rs
@@ -37,10 +37,10 @@
3737 void drawSpace(float xOffset, int width, int height) {
3838 bindTexture(NAMED_PFBackground, 0, NAMED_TSpace);
3939 drawQuadTexCoords(
40- xOffset, 0.0f, 0.0f, 0.0f, 1.0f,
41- xOffset + width, 0.0f, 0.0f, 2.0f, 1.0f,
42- xOffset + width, height, 0.0f, 2.0f, 0.0f,
43- xOffset, height, 0.0f, 0.0f, 0.0f);
40+ 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
41+ width, 0.0f, 0.0f, 2.0f, 1.0f,
42+ width, height, 0.0f, 2.0f, 0.0f,
43+ 0.0f, height, 0.0f, 0.0f, 0.0f);
4444 }
4545
4646 void drawLights(float xOffset, int width, int height) {
--- a/src/com/android/wallpaper/galaxy/GalaxyRS.java
+++ b/src/com/android/wallpaper/galaxy/GalaxyRS.java
@@ -72,8 +72,8 @@ class GalaxyRS {
7272
7373 private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options();
7474
75- private final int mWidth;
76- private final int mHeight;
75+ private int mWidth;
76+ private int mHeight;
7777
7878 @SuppressWarnings({"FieldCanBeLocal"})
7979 private ScriptC mScript;
@@ -120,6 +120,14 @@ class GalaxyRS {
120120 initRS();
121121 }
122122
123+ void stop() {
124+ mRS.contextBindRootScript(null);
125+ }
126+
127+ void start() {
128+ mRS.contextBindRootScript(mScript);
129+ }
130+
123131 private void initRS() {
124132 createProgramVertex();
125133 createProgramFragmentStore();
@@ -133,14 +141,12 @@ class GalaxyRS {
133141 sb.setRoot(true);
134142
135143 mScript = sb.create();
136- mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
144+ mScript.setClearColor(1.0f, 0.0f, 0.0f, 1.0f);
137145 mScript.setTimeZone(TimeZone.getDefault().getID());
138146
139147 mScript.bindAllocation(mState, RSID_STATE);
140148 mScript.bindAllocation(mParticles, RSID_PARTICLES);
141149 mScript.bindAllocation(mParticlesBuffer, RSID_PARTICLES_BUFFER);
142-
143- mRS.contextBindRootScript(mScript);
144150 }
145151
146152 private void createScriptStructures() {
@@ -170,7 +176,18 @@ class GalaxyRS {
170176 void setOffsetX(float xOffset) {
171177 mGalaxyState.xOffset = xOffset;
172178 mState.data(mGalaxyState);
173- }
179+ }
180+
181+ void resize(int width, int height) {
182+ mWidth = width;
183+ mHeight = height;
184+
185+ mGalaxyState.width = width;
186+ mGalaxyState.height = height;
187+ mState.data(mGalaxyState);
188+
189+ mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
190+ }
174191
175192 static class GalaxyState {
176193 public int width;
@@ -344,8 +361,7 @@ class GalaxyRS {
344361
345362 private void createProgramVertex() {
346363 mPvOrthoAlloc = new ProgramVertex.MatrixAllocation(mRS);
347- //mPvOrthoAlloc.setupProjectionNormalized(mWidth, mHeight);
348- mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
364+ mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
349365
350366 ProgramVertex.Builder builder = new ProgramVertex.Builder(mRS, null, null);
351367 mPvBackground = builder.create();
--- a/src/com/android/wallpaper/galaxy/GalaxyWallpaper.java
+++ b/src/com/android/wallpaper/galaxy/GalaxyWallpaper.java
@@ -39,18 +39,36 @@ public class GalaxyWallpaper extends WallpaperService {
3939 @Override
4040 public void onDestroy() {
4141 super.onDestroy();
42+ destroyRenderer();
43+ }
44+
45+ private void destroyRenderer() {
46+ if (mRenderer != null) {
47+ mRenderer.stop();
48+ mRenderer = null;
49+ }
4250 }
4351
4452 @Override
4553 public void onVisibilityChanged(boolean visible) {
4654 super.onVisibilityChanged(visible);
55+ if (visible) {
56+ mRenderer.start();
57+ } else {
58+ mRenderer.stop();
59+ }
4760 }
4861
4962 @Override
5063 public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
5164 super.onSurfaceChanged(holder, format, width, height);
52- mRenderer = new GalaxyRS(width, height);
53- mRenderer.init(mRs, getResources());
65+ if (mRenderer == null) {
66+ mRenderer = new GalaxyRS(width, height);
67+ mRenderer.init(mRs, getResources());
68+ mRenderer.start();
69+ } else {
70+ mRenderer.resize(width, height);
71+ }
5472 }
5573
5674 @Override
@@ -72,6 +90,7 @@ public class GalaxyWallpaper extends WallpaperService {
7290 @Override
7391 public void onSurfaceDestroyed(SurfaceHolder holder) {
7492 super.onSurfaceDestroyed(holder);
93+ destroyRenderer();
7594 }
7695 }
7796 }
\ No newline at end of file
--- a/src/com/android/wallpaper/grass/GrassRS.java
+++ b/src/com/android/wallpaper/grass/GrassRS.java
@@ -69,8 +69,8 @@ class GrassRS {
6969 private Resources mResources;
7070 private RenderScript mRS;
7171
72- private final int mWidth;
73- private final int mHeight;
72+ private int mWidth;
73+ private int mHeight;
7474
7575 @SuppressWarnings({ "FieldCanBeLocal" })
7676 private ScriptC mScript;
@@ -98,6 +98,7 @@ class GrassRS {
9898
9999 private int mTriangles;
100100 private final float[] mFloatData5 = new float[5];
101+ private WorldState mWorldState;
101102
102103 public GrassRS(int width, int height) {
103104 mWidth = width;
@@ -109,7 +110,28 @@ class GrassRS {
109110 mResources = res;
110111 initRS();
111112 }
113+
114+ void stop() {
115+ mRS.contextBindRootScript(null);
116+ }
117+
118+ void start() {
119+ mRS.contextBindRootScript(mScript);
120+ }
121+
122+ void resize(int width, int height) {
123+ mWidth = width;
124+ mHeight = height;
112125
126+ mWorldState.width = width;
127+ mWorldState.height = height;
128+ mState.data(mWorldState);
129+
130+ mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
131+
132+ // TODO: REPOSITION BLADES
133+ }
134+
113135 private void initRS() {
114136 createProgramVertex();
115137 createProgramFragmentStore();
@@ -129,8 +151,6 @@ class GrassRS {
129151 mScript.bindAllocation(mState, RSID_STATE);
130152 mScript.bindAllocation(mBlades, RSID_BLADES);
131153 mScript.bindAllocation(mBladesBuffer, RSID_BLADES_BUFFER);
132-
133- mRS.contextBindRootScript(mScript);
134154 }
135155
136156 private void createScriptStructures() {
@@ -147,15 +167,15 @@ class GrassRS {
147167 }
148168
149169 private void createState() {
150- WorldState state = new WorldState();
151- state.width = mWidth;
152- state.height = mHeight;
153- state.bladesCount = BLADES_COUNT;
154- state.trianglesCount = mTriangles;
170+ mWorldState = new WorldState();
171+ mWorldState.width = mWidth;
172+ mWorldState.height = mHeight;
173+ mWorldState.bladesCount = BLADES_COUNT;
174+ mWorldState.trianglesCount = mTriangles;
155175
156176 mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
157177 mState = Allocation.createTyped(mRS, mStateType);
158- mState.data(state);
178+ mState.data(mWorldState);
159179 }
160180
161181 private void createBlades() {
--- a/src/com/android/wallpaper/grass/GrassWallpaper.java
+++ b/src/com/android/wallpaper/grass/GrassWallpaper.java
@@ -38,18 +38,36 @@ public class GrassWallpaper extends WallpaperService {
3838 @Override
3939 public void onDestroy() {
4040 super.onDestroy();
41+ destroyRenderer();
42+ }
43+
44+ private void destroyRenderer() {
45+ if (mRenderer != null) {
46+ mRenderer.stop();
47+ mRenderer = null;
48+ }
4149 }
4250
4351 @Override
4452 public void onVisibilityChanged(boolean visible) {
4553 super.onVisibilityChanged(visible);
54+ if (visible) {
55+ mRenderer.start();
56+ } else {
57+ mRenderer.stop();
58+ }
4659 }
4760
4861 @Override
4962 public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
5063 super.onSurfaceChanged(holder, format, width, height);
51- mRenderer = new GrassRS(width, height);
52- mRenderer.init(mRs, getResources());
64+ if (mRenderer == null) {
65+ mRenderer = new GrassRS(width, height);
66+ mRenderer.init(mRs, getResources());
67+ mRenderer.start();
68+ } else {
69+ mRenderer.resize(width, height);
70+ }
5371 }
5472
5573 @Override
@@ -66,6 +84,7 @@ public class GrassWallpaper extends WallpaperService {
6684 @Override
6785 public void onSurfaceDestroyed(SurfaceHolder holder) {
6886 super.onSurfaceDestroyed(holder);
87+ destroyRenderer();
6988 }
7089 }
7190 }