packages/wallpapers/Basic
修订版 | 9e6f2347087ab40539b4c4b76f4b050f02184436 (tree) |
---|---|
时间 | 2009-08-25 10:40:21 |
作者 | Romain Guy <romainguy@andr...> |
Commiter | Romain Guy |
Provide better support for orientation change. Very much work in progress still.
Change-Id: I73cdd43d25ccbb200d0fd91f70202a80d0e90d77
@@ -37,10 +37,10 @@ | ||
37 | 37 | void drawSpace(float xOffset, int width, int height) { |
38 | 38 | bindTexture(NAMED_PFBackground, 0, NAMED_TSpace); |
39 | 39 | 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); | |
44 | 44 | } |
45 | 45 | |
46 | 46 | void drawLights(float xOffset, int width, int height) { |
@@ -72,8 +72,8 @@ class GalaxyRS { | ||
72 | 72 | |
73 | 73 | private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options(); |
74 | 74 | |
75 | - private final int mWidth; | |
76 | - private final int mHeight; | |
75 | + private int mWidth; | |
76 | + private int mHeight; | |
77 | 77 | |
78 | 78 | @SuppressWarnings({"FieldCanBeLocal"}) |
79 | 79 | private ScriptC mScript; |
@@ -120,6 +120,14 @@ class GalaxyRS { | ||
120 | 120 | initRS(); |
121 | 121 | } |
122 | 122 | |
123 | + void stop() { | |
124 | + mRS.contextBindRootScript(null); | |
125 | + } | |
126 | + | |
127 | + void start() { | |
128 | + mRS.contextBindRootScript(mScript); | |
129 | + } | |
130 | + | |
123 | 131 | private void initRS() { |
124 | 132 | createProgramVertex(); |
125 | 133 | createProgramFragmentStore(); |
@@ -133,14 +141,12 @@ class GalaxyRS { | ||
133 | 141 | sb.setRoot(true); |
134 | 142 | |
135 | 143 | 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); | |
137 | 145 | mScript.setTimeZone(TimeZone.getDefault().getID()); |
138 | 146 | |
139 | 147 | mScript.bindAllocation(mState, RSID_STATE); |
140 | 148 | mScript.bindAllocation(mParticles, RSID_PARTICLES); |
141 | 149 | mScript.bindAllocation(mParticlesBuffer, RSID_PARTICLES_BUFFER); |
142 | - | |
143 | - mRS.contextBindRootScript(mScript); | |
144 | 150 | } |
145 | 151 | |
146 | 152 | private void createScriptStructures() { |
@@ -170,7 +176,18 @@ class GalaxyRS { | ||
170 | 176 | void setOffsetX(float xOffset) { |
171 | 177 | mGalaxyState.xOffset = xOffset; |
172 | 178 | 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 | + } | |
174 | 191 | |
175 | 192 | static class GalaxyState { |
176 | 193 | public int width; |
@@ -344,8 +361,7 @@ class GalaxyRS { | ||
344 | 361 | |
345 | 362 | private void createProgramVertex() { |
346 | 363 | mPvOrthoAlloc = new ProgramVertex.MatrixAllocation(mRS); |
347 | - //mPvOrthoAlloc.setupProjectionNormalized(mWidth, mHeight); | |
348 | - mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight); | |
364 | + mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight); | |
349 | 365 | |
350 | 366 | ProgramVertex.Builder builder = new ProgramVertex.Builder(mRS, null, null); |
351 | 367 | mPvBackground = builder.create(); |
@@ -39,18 +39,36 @@ public class GalaxyWallpaper extends WallpaperService { | ||
39 | 39 | @Override |
40 | 40 | public void onDestroy() { |
41 | 41 | super.onDestroy(); |
42 | + destroyRenderer(); | |
43 | + } | |
44 | + | |
45 | + private void destroyRenderer() { | |
46 | + if (mRenderer != null) { | |
47 | + mRenderer.stop(); | |
48 | + mRenderer = null; | |
49 | + } | |
42 | 50 | } |
43 | 51 | |
44 | 52 | @Override |
45 | 53 | public void onVisibilityChanged(boolean visible) { |
46 | 54 | super.onVisibilityChanged(visible); |
55 | + if (visible) { | |
56 | + mRenderer.start(); | |
57 | + } else { | |
58 | + mRenderer.stop(); | |
59 | + } | |
47 | 60 | } |
48 | 61 | |
49 | 62 | @Override |
50 | 63 | public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
51 | 64 | 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 | + } | |
54 | 72 | } |
55 | 73 | |
56 | 74 | @Override |
@@ -72,6 +90,7 @@ public class GalaxyWallpaper extends WallpaperService { | ||
72 | 90 | @Override |
73 | 91 | public void onSurfaceDestroyed(SurfaceHolder holder) { |
74 | 92 | super.onSurfaceDestroyed(holder); |
93 | + destroyRenderer(); | |
75 | 94 | } |
76 | 95 | } |
77 | 96 | } |
\ No newline at end of file |
@@ -69,8 +69,8 @@ class GrassRS { | ||
69 | 69 | private Resources mResources; |
70 | 70 | private RenderScript mRS; |
71 | 71 | |
72 | - private final int mWidth; | |
73 | - private final int mHeight; | |
72 | + private int mWidth; | |
73 | + private int mHeight; | |
74 | 74 | |
75 | 75 | @SuppressWarnings({ "FieldCanBeLocal" }) |
76 | 76 | private ScriptC mScript; |
@@ -98,6 +98,7 @@ class GrassRS { | ||
98 | 98 | |
99 | 99 | private int mTriangles; |
100 | 100 | private final float[] mFloatData5 = new float[5]; |
101 | + private WorldState mWorldState; | |
101 | 102 | |
102 | 103 | public GrassRS(int width, int height) { |
103 | 104 | mWidth = width; |
@@ -109,7 +110,28 @@ class GrassRS { | ||
109 | 110 | mResources = res; |
110 | 111 | initRS(); |
111 | 112 | } |
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; | |
112 | 125 | |
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 | + | |
113 | 135 | private void initRS() { |
114 | 136 | createProgramVertex(); |
115 | 137 | createProgramFragmentStore(); |
@@ -129,8 +151,6 @@ class GrassRS { | ||
129 | 151 | mScript.bindAllocation(mState, RSID_STATE); |
130 | 152 | mScript.bindAllocation(mBlades, RSID_BLADES); |
131 | 153 | mScript.bindAllocation(mBladesBuffer, RSID_BLADES_BUFFER); |
132 | - | |
133 | - mRS.contextBindRootScript(mScript); | |
134 | 154 | } |
135 | 155 | |
136 | 156 | private void createScriptStructures() { |
@@ -147,15 +167,15 @@ class GrassRS { | ||
147 | 167 | } |
148 | 168 | |
149 | 169 | 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; | |
155 | 175 | |
156 | 176 | mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState"); |
157 | 177 | mState = Allocation.createTyped(mRS, mStateType); |
158 | - mState.data(state); | |
178 | + mState.data(mWorldState); | |
159 | 179 | } |
160 | 180 | |
161 | 181 | private void createBlades() { |
@@ -38,18 +38,36 @@ public class GrassWallpaper extends WallpaperService { | ||
38 | 38 | @Override |
39 | 39 | public void onDestroy() { |
40 | 40 | super.onDestroy(); |
41 | + destroyRenderer(); | |
42 | + } | |
43 | + | |
44 | + private void destroyRenderer() { | |
45 | + if (mRenderer != null) { | |
46 | + mRenderer.stop(); | |
47 | + mRenderer = null; | |
48 | + } | |
41 | 49 | } |
42 | 50 | |
43 | 51 | @Override |
44 | 52 | public void onVisibilityChanged(boolean visible) { |
45 | 53 | super.onVisibilityChanged(visible); |
54 | + if (visible) { | |
55 | + mRenderer.start(); | |
56 | + } else { | |
57 | + mRenderer.stop(); | |
58 | + } | |
46 | 59 | } |
47 | 60 | |
48 | 61 | @Override |
49 | 62 | public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
50 | 63 | 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 | + } | |
53 | 71 | } |
54 | 72 | |
55 | 73 | @Override |
@@ -66,6 +84,7 @@ public class GrassWallpaper extends WallpaperService { | ||
66 | 84 | @Override |
67 | 85 | public void onSurfaceDestroyed(SurfaceHolder holder) { |
68 | 86 | super.onSurfaceDestroyed(holder); |
87 | + destroyRenderer(); | |
69 | 88 | } |
70 | 89 | } |
71 | 90 | } |