blob: f4b48b693555f0bae851ea26d60a791b4f83e219 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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
Mathias Agopianbc726112009-09-23 15:44:05 -070017#define LOG_TAG "BootAnimation"
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019#include <stdint.h>
20#include <sys/types.h>
21#include <math.h>
22#include <fcntl.h>
23#include <utils/misc.h>
Mathias Agopianb4d5a722009-09-23 17:05:19 -070024#include <signal.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
Mathias Agopianac31a3b2009-05-21 19:59:24 -070026#include <binder/IPCThreadState.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <utils/threads.h>
28#include <utils/Atomic.h>
29#include <utils/Errors.h>
30#include <utils/Log.h>
31#include <utils/AssetManager.h>
32
33#include <ui/PixelFormat.h>
34#include <ui/Rect.h>
35#include <ui/Region.h>
36#include <ui/DisplayInfo.h>
Mathias Agopiandff8e582009-05-04 14:17:04 -070037#include <ui/FramebufferNativeWindow.h>
Mathias Agopian738b9a42009-08-06 16:41:02 -070038#include <ui/EGLUtils.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
Mathias Agopian000479f2010-02-09 17:46:37 -080040#include <surfaceflinger/ISurfaceComposer.h>
41#include <surfaceflinger/ISurfaceFlingerClient.h>
42
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043#include <core/SkBitmap.h>
44#include <images/SkImageDecoder.h>
45
46#include <GLES/gl.h>
47#include <GLES/glext.h>
48#include <EGL/eglext.h>
49
50#include "BootAnimation.h"
51
Jim Huangc11f4622010-08-10 03:12:15 +080052#define USER_BOOTANIMATION_FILE "/data/local/bootanimation.zip"
53#define SYSTEM_BOOTANIMATION_FILE "/system/media/bootanimation.zip"
54
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055namespace android {
56
57// ---------------------------------------------------------------------------
58
Mathias Agopian627e7b52009-05-21 19:21:59 -070059BootAnimation::BootAnimation() : Thread(false)
Mathias Agopiana8826d62009-10-01 03:10:14 -070060{
Mathias Agopian627e7b52009-05-21 19:21:59 -070061 mSession = new SurfaceComposerClient();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062}
63
64BootAnimation::~BootAnimation() {
65}
66
67void BootAnimation::onFirstRef() {
Mathias Agopianbc726112009-09-23 15:44:05 -070068 status_t err = mSession->linkToComposerDeath(this);
69 LOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err));
Mathias Agopian8434c532009-09-23 18:52:49 -070070 if (err == NO_ERROR) {
Mathias Agopianbc726112009-09-23 15:44:05 -070071 run("BootAnimation", PRIORITY_DISPLAY);
72 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073}
74
Mathias Agopianbc726112009-09-23 15:44:05 -070075sp<SurfaceComposerClient> BootAnimation::session() const {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 return mSession;
77}
78
Mathias Agopianbc726112009-09-23 15:44:05 -070079
80void BootAnimation::binderDied(const wp<IBinder>& who)
81{
82 // woah, surfaceflinger died!
83 LOGD("SurfaceFlinger died, exiting...");
84
85 // calling requestExit() is not enough here because the Surface code
86 // might be blocked on a condition variable that will never be updated.
87 kill( getpid(), SIGKILL );
88 requestExit();
89}
90
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets,
92 const char* name) {
93 Asset* asset = assets.open(name, Asset::ACCESS_BUFFER);
94 if (!asset)
95 return NO_INIT;
96 SkBitmap bitmap;
97 SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(),
98 &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode);
99 asset->close();
100 delete asset;
101
102 // ensure we can call getPixels(). No need to call unlock, since the
103 // bitmap will go out of scope when we return from this method.
104 bitmap.lockPixels();
105
106 const int w = bitmap.width();
107 const int h = bitmap.height();
108 const void* p = bitmap.getPixels();
109
110 GLint crop[4] = { 0, h, w, -h };
111 texture->w = w;
112 texture->h = h;
113
114 glGenTextures(1, &texture->name);
115 glBindTexture(GL_TEXTURE_2D, texture->name);
116
117 switch (bitmap.getConfig()) {
118 case SkBitmap::kA8_Config:
119 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA,
120 GL_UNSIGNED_BYTE, p);
121 break;
122 case SkBitmap::kARGB_4444_Config:
123 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
124 GL_UNSIGNED_SHORT_4_4_4_4, p);
125 break;
126 case SkBitmap::kARGB_8888_Config:
127 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
128 GL_UNSIGNED_BYTE, p);
129 break;
130 case SkBitmap::kRGB_565_Config:
131 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB,
132 GL_UNSIGNED_SHORT_5_6_5, p);
133 break;
134 default:
135 break;
136 }
137
138 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
139 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
140 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
141 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
142 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
143 return NO_ERROR;
144}
145
Mathias Agopiana8826d62009-10-01 03:10:14 -0700146status_t BootAnimation::initTexture(void* buffer, size_t len)
147{
148 //StopWatch watch("blah");
149
150 SkBitmap bitmap;
151 SkImageDecoder::DecodeMemory(buffer, len,
152 &bitmap, SkBitmap::kRGB_565_Config,
153 SkImageDecoder::kDecodePixels_Mode);
154
155 // ensure we can call getPixels(). No need to call unlock, since the
156 // bitmap will go out of scope when we return from this method.
157 bitmap.lockPixels();
158
159 const int w = bitmap.width();
160 const int h = bitmap.height();
161 const void* p = bitmap.getPixels();
162
163 GLint crop[4] = { 0, h, w, -h };
164 int tw = 1 << (31 - __builtin_clz(w));
165 int th = 1 << (31 - __builtin_clz(h));
166 if (tw < w) tw <<= 1;
167 if (th < h) th <<= 1;
168
169 switch (bitmap.getConfig()) {
170 case SkBitmap::kARGB_8888_Config:
171 if (tw != w || th != h) {
172 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
173 GL_UNSIGNED_BYTE, 0);
174 glTexSubImage2D(GL_TEXTURE_2D, 0,
175 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p);
176 } else {
177 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
178 GL_UNSIGNED_BYTE, p);
179 }
180 break;
181
182 case SkBitmap::kRGB_565_Config:
183 if (tw != w || th != h) {
184 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB,
185 GL_UNSIGNED_SHORT_5_6_5, 0);
186 glTexSubImage2D(GL_TEXTURE_2D, 0,
187 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p);
188 } else {
189 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB,
190 GL_UNSIGNED_SHORT_5_6_5, p);
191 }
192 break;
193 default:
194 break;
195 }
196
197 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
198
199 return NO_ERROR;
200}
201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202status_t BootAnimation::readyToRun() {
203 mAssets.addDefaultAssets();
204
205 DisplayInfo dinfo;
206 status_t status = session()->getDisplayInfo(0, &dinfo);
207 if (status)
208 return -1;
209
210 // create the native surface
Mathias Agopian17f638b2009-04-16 20:04:08 -0700211 sp<SurfaceControl> control = session()->createSurface(
Mathias Agopian317a6282009-08-13 17:29:02 -0700212 getpid(), 0, dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 session()->openTransaction();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700214 control->setLayer(0x40000000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 session()->closeTransaction();
216
Mathias Agopian17f638b2009-04-16 20:04:08 -0700217 sp<Surface> s = control->getSurface();
218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 // initialize opengl and egl
Mathias Agopian738b9a42009-08-06 16:41:02 -0700220 const EGLint attribs[] = {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700221 EGL_DEPTH_SIZE, 0,
222 EGL_NONE
Mathias Agopian738b9a42009-08-06 16:41:02 -0700223 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 EGLint w, h, dummy;
225 EGLint numConfigs;
226 EGLConfig config;
227 EGLSurface surface;
228 EGLContext context;
Mathias Agopian627e7b52009-05-21 19:21:59 -0700229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Mathias Agopian627e7b52009-05-21 19:21:59 -0700231
232 eglInitialize(display, 0, 0);
Mathias Agopian738b9a42009-08-06 16:41:02 -0700233 EGLUtils::selectConfigForNativeWindow(display, attribs, s.get(), &config);
Mathias Agopian1473f462009-04-10 14:24:30 -0700234 surface = eglCreateWindowSurface(display, config, s.get(), NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 context = eglCreateContext(display, config, NULL, NULL);
236 eglQuerySurface(display, surface, EGL_WIDTH, &w);
237 eglQuerySurface(display, surface, EGL_HEIGHT, &h);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700238
Mathias Agopianabac0102009-07-31 14:47:00 -0700239 if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE)
240 return NO_INIT;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 mDisplay = display;
243 mContext = context;
244 mSurface = surface;
245 mWidth = w;
246 mHeight = h;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700247 mFlingerSurfaceControl = control;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 mFlingerSurface = s;
249
Jim Huangc11f4622010-08-10 03:12:15 +0800250 mAndroidAnimation = true;
251 if ((access(USER_BOOTANIMATION_FILE, R_OK) == 0) ||
252 (access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0)) {
253 if ((mZip.open(USER_BOOTANIMATION_FILE) != NO_ERROR) ||
254 (mZip.open(SYSTEM_BOOTANIMATION_FILE) != NO_ERROR)) {
255 mAndroidAnimation = false;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700256 }
257 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258
259 return NO_ERROR;
260}
261
Mathias Agopiana8826d62009-10-01 03:10:14 -0700262bool BootAnimation::threadLoop()
263{
264 bool r;
265 if (mAndroidAnimation) {
266 r = android();
267 } else {
268 r = movie();
269 }
270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
272 eglDestroyContext(mDisplay, mContext);
273 eglDestroySurface(mDisplay, mSurface);
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700274 mFlingerSurface.clear();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700275 mFlingerSurfaceControl.clear();
Mathias Agopian627e7b52009-05-21 19:21:59 -0700276 eglTerminate(mDisplay);
277 IPCThreadState::self()->stopProcess();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 return r;
279}
280
Mathias Agopiana8826d62009-10-01 03:10:14 -0700281bool BootAnimation::android()
282{
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700283 initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
284 initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285
286 // clear screen
Mathias Agopiana8826d62009-10-01 03:10:14 -0700287 glShadeModel(GL_FLAT);
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700288 glDisable(GL_DITHER);
289 glDisable(GL_SCISSOR_TEST);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 glClear(GL_COLOR_BUFFER_BIT);
291 eglSwapBuffers(mDisplay, mSurface);
292
Mathias Agopiana8826d62009-10-01 03:10:14 -0700293 glEnable(GL_TEXTURE_2D);
294 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
295
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700296 const GLint xc = (mWidth - mAndroid[0].w) / 2;
297 const GLint yc = (mHeight - mAndroid[0].h) / 2;
298 const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299
300 // draw and update only what we need
Mathias Agopian1473f462009-04-10 14:24:30 -0700301 mFlingerSurface->setSwapRectangle(updateRect);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
304 updateRect.height());
305
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700306 // Blend state
307 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
308 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 const nsecs_t startTime = systemTime();
311 do {
Mathias Agopian13796652009-03-24 22:49:21 -0700312 nsecs_t now = systemTime();
313 double time = now - startTime;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700314 float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w;
315 GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w;
316 GLint x = xc - offset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317
Mathias Agopian81668642009-07-28 11:41:30 -0700318 glDisable(GL_SCISSOR_TEST);
319 glClear(GL_COLOR_BUFFER_BIT);
320
321 glEnable(GL_SCISSOR_TEST);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 glDisable(GL_BLEND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 glBindTexture(GL_TEXTURE_2D, mAndroid[1].name);
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700324 glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h);
325 glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700327 glEnable(GL_BLEND);
328 glBindTexture(GL_TEXTURE_2D, mAndroid[0].name);
329 glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330
Mathias Agopian627e7b52009-05-21 19:21:59 -0700331 EGLBoolean res = eglSwapBuffers(mDisplay, mSurface);
332 if (res == EGL_FALSE)
333 break;
334
Mathias Agopian13796652009-03-24 22:49:21 -0700335 // 12fps: don't animate too fast to preserve CPU
336 const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now);
337 if (sleepTime > 0)
Mathias Agopiana8826d62009-10-01 03:10:14 -0700338 usleep(sleepTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 } while (!exitPending());
340
341 glDeleteTextures(1, &mAndroid[0].name);
342 glDeleteTextures(1, &mAndroid[1].name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 return false;
344}
345
Mathias Agopiana8826d62009-10-01 03:10:14 -0700346
347bool BootAnimation::movie()
348{
349 ZipFileRO& zip(mZip);
350
351 size_t numEntries = zip.getNumEntries();
352 ZipEntryRO desc = zip.findEntryByName("desc.txt");
353 FileMap* descMap = zip.createEntryFileMap(desc);
354 LOGE_IF(!descMap, "descMap is null");
355 if (!descMap) {
356 return false;
357 }
358
359 String8 desString((char const*)descMap->getDataPtr(),
360 descMap->getDataLength());
361 char const* s = desString.string();
362
363 Animation animation;
364
365 // Parse the description file
366 for (;;) {
367 const char* endl = strstr(s, "\n");
368 if (!endl) break;
369 String8 line(s, endl - s);
370 const char* l = line.string();
371 int fps, width, height, count, pause;
372 char path[256];
373 if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) {
374 //LOGD("> w=%d, h=%d, fps=%d", fps, width, height);
375 animation.width = width;
376 animation.height = height;
377 animation.fps = fps;
378 }
379 if (sscanf(l, "p %d %d %s", &count, &pause, path) == 3) {
380 //LOGD("> count=%d, pause=%d, path=%s", count, pause, path);
381 Animation::Part part;
382 part.count = count;
383 part.pause = pause;
384 part.path = path;
385 animation.parts.add(part);
386 }
387 s = ++endl;
388 }
389
390 // read all the data structures
391 const size_t pcount = animation.parts.size();
392 for (size_t i=0 ; i<numEntries ; i++) {
393 char name[256];
394 ZipEntryRO entry = zip.findEntryByIndex(i);
395 if (zip.getEntryFileName(entry, name, 256) == 0) {
396 const String8 entryName(name);
397 const String8 path(entryName.getPathDir());
398 const String8 leaf(entryName.getPathLeaf());
399 if (leaf.size() > 0) {
400 for (int j=0 ; j<pcount ; j++) {
401 if (path == animation.parts[j].path) {
402 int method;
403 // supports only stored png files
404 if (zip.getEntryInfo(entry, &method, 0, 0, 0, 0, 0)) {
405 if (method == ZipFileRO::kCompressStored) {
406 FileMap* map = zip.createEntryFileMap(entry);
407 if (map) {
408 Animation::Frame frame;
409 frame.name = leaf;
410 frame.map = map;
411 Animation::Part& part(animation.parts.editItemAt(j));
412 part.frames.add(frame);
413 }
414 }
415 }
416 }
417 }
418 }
419 }
420 }
421
422 // clear screen
423 glShadeModel(GL_FLAT);
424 glDisable(GL_DITHER);
425 glDisable(GL_SCISSOR_TEST);
426 glDisable(GL_BLEND);
427 glClear(GL_COLOR_BUFFER_BIT);
428
429 eglSwapBuffers(mDisplay, mSurface);
430
431 glBindTexture(GL_TEXTURE_2D, 0);
432 glEnable(GL_TEXTURE_2D);
433 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
434 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
435 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
436 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
437 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
438
439 const int xc = (mWidth - animation.width) / 2;
440 const int yc = ((mHeight - animation.height) / 2);
441 nsecs_t lastFrame = systemTime();
442 nsecs_t frameDuration = s2ns(1) / animation.fps;
443
Mathias Agopian9f3020d2009-11-06 16:30:18 -0800444 Region clearReg(Rect(mWidth, mHeight));
445 clearReg.subtractSelf(Rect(xc, yc, xc+animation.width, yc+animation.height));
446
Mathias Agopiana8826d62009-10-01 03:10:14 -0700447 for (int i=0 ; i<pcount && !exitPending() ; i++) {
448 const Animation::Part& part(animation.parts[i]);
449 const size_t fcount = part.frames.size();
450 glBindTexture(GL_TEXTURE_2D, 0);
451
452 for (int r=0 ; !part.count || r<part.count ; r++) {
453 for (int j=0 ; j<fcount && !exitPending(); j++) {
454 const Animation::Frame& frame(part.frames[j]);
455
456 if (r > 0) {
457 glBindTexture(GL_TEXTURE_2D, frame.tid);
458 } else {
459 if (part.count != 1) {
460 glGenTextures(1, &frame.tid);
461 glBindTexture(GL_TEXTURE_2D, frame.tid);
462 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
463 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
464 }
465 initTexture(
466 frame.map->getDataPtr(),
467 frame.map->getDataLength());
468 }
469
Mathias Agopian9f3020d2009-11-06 16:30:18 -0800470 if (!clearReg.isEmpty()) {
471 Region::const_iterator head(clearReg.begin());
472 Region::const_iterator tail(clearReg.end());
473 glEnable(GL_SCISSOR_TEST);
474 while (head != tail) {
475 const Rect& r(*head++);
476 glScissor(r.left, mHeight - r.bottom,
477 r.width(), r.height());
478 glClear(GL_COLOR_BUFFER_BIT);
479 }
480 glDisable(GL_SCISSOR_TEST);
481 }
Mathias Agopiana8826d62009-10-01 03:10:14 -0700482 glDrawTexiOES(xc, yc, 0, animation.width, animation.height);
483 eglSwapBuffers(mDisplay, mSurface);
484
485 nsecs_t now = systemTime();
486 nsecs_t delay = frameDuration - (now - lastFrame);
487 lastFrame = now;
488 long wait = ns2us(frameDuration);
489 if (wait > 0)
490 usleep(wait);
491 }
492 usleep(part.pause * ns2us(frameDuration));
493 }
494
495 // free the textures for this part
496 if (part.count != 1) {
497 for (int j=0 ; j<fcount ; j++) {
498 const Animation::Frame& frame(part.frames[j]);
499 glDeleteTextures(1, &frame.tid);
500 }
501 }
502 }
503
504 return false;
505}
506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507// ---------------------------------------------------------------------------
508
509}
510; // namespace android