The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 17 | #define LOG_TAG "BootAnimation" |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <math.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <utils/misc.h> |
Mathias Agopian | b4d5a72 | 2009-09-23 17:05:19 -0700 | [diff] [blame] | 24 | #include <signal.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 26 | #include <cutils/properties.h> |
| 27 | |
Mathias Agopian | ac31a3b | 2009-05-21 19:59:24 -0700 | [diff] [blame] | 28 | #include <binder/IPCThreadState.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <utils/threads.h> |
| 30 | #include <utils/Atomic.h> |
| 31 | #include <utils/Errors.h> |
| 32 | #include <utils/Log.h> |
| 33 | #include <utils/AssetManager.h> |
| 34 | |
| 35 | #include <ui/PixelFormat.h> |
| 36 | #include <ui/Rect.h> |
| 37 | #include <ui/Region.h> |
| 38 | #include <ui/DisplayInfo.h> |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 39 | #include <ui/FramebufferNativeWindow.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 41 | #include <surfaceflinger/ISurfaceComposer.h> |
Mathias Agopian | 770492c | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 42 | #include <surfaceflinger/ISurfaceComposerClient.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 43 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | #include <core/SkBitmap.h> |
| 45 | #include <images/SkImageDecoder.h> |
| 46 | |
| 47 | #include <GLES/gl.h> |
| 48 | #include <GLES/glext.h> |
| 49 | #include <EGL/eglext.h> |
| 50 | |
| 51 | #include "BootAnimation.h" |
| 52 | |
Jim Huang | c11f462 | 2010-08-10 03:12:15 +0800 | [diff] [blame] | 53 | #define USER_BOOTANIMATION_FILE "/data/local/bootanimation.zip" |
| 54 | #define SYSTEM_BOOTANIMATION_FILE "/system/media/bootanimation.zip" |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 55 | #define SYSTEM_ENCRYPTED_BOOTANIMATION_FILE "/system/media/bootanimation-encrypted.zip" |
Jim Huang | c11f462 | 2010-08-10 03:12:15 +0800 | [diff] [blame] | 56 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | namespace android { |
| 58 | |
| 59 | // --------------------------------------------------------------------------- |
| 60 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 61 | BootAnimation::BootAnimation() : Thread(false) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 62 | { |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 63 | mSession = new SurfaceComposerClient(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | BootAnimation::~BootAnimation() { |
| 67 | } |
| 68 | |
| 69 | void BootAnimation::onFirstRef() { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 70 | status_t err = mSession->linkToComposerDeath(this); |
| 71 | LOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err)); |
Mathias Agopian | 8434c53 | 2009-09-23 18:52:49 -0700 | [diff] [blame] | 72 | if (err == NO_ERROR) { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 73 | run("BootAnimation", PRIORITY_DISPLAY); |
| 74 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 77 | sp<SurfaceComposerClient> BootAnimation::session() const { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | return mSession; |
| 79 | } |
| 80 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 81 | |
| 82 | void BootAnimation::binderDied(const wp<IBinder>& who) |
| 83 | { |
| 84 | // woah, surfaceflinger died! |
| 85 | LOGD("SurfaceFlinger died, exiting..."); |
| 86 | |
| 87 | // calling requestExit() is not enough here because the Surface code |
| 88 | // might be blocked on a condition variable that will never be updated. |
| 89 | kill( getpid(), SIGKILL ); |
| 90 | requestExit(); |
| 91 | } |
| 92 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, |
| 94 | const char* name) { |
| 95 | Asset* asset = assets.open(name, Asset::ACCESS_BUFFER); |
| 96 | if (!asset) |
| 97 | return NO_INIT; |
| 98 | SkBitmap bitmap; |
| 99 | SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(), |
| 100 | &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode); |
| 101 | asset->close(); |
| 102 | delete asset; |
| 103 | |
| 104 | // ensure we can call getPixels(). No need to call unlock, since the |
| 105 | // bitmap will go out of scope when we return from this method. |
| 106 | bitmap.lockPixels(); |
| 107 | |
| 108 | const int w = bitmap.width(); |
| 109 | const int h = bitmap.height(); |
| 110 | const void* p = bitmap.getPixels(); |
| 111 | |
| 112 | GLint crop[4] = { 0, h, w, -h }; |
| 113 | texture->w = w; |
| 114 | texture->h = h; |
| 115 | |
| 116 | glGenTextures(1, &texture->name); |
| 117 | glBindTexture(GL_TEXTURE_2D, texture->name); |
| 118 | |
| 119 | switch (bitmap.getConfig()) { |
| 120 | case SkBitmap::kA8_Config: |
| 121 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, |
| 122 | GL_UNSIGNED_BYTE, p); |
| 123 | break; |
| 124 | case SkBitmap::kARGB_4444_Config: |
| 125 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 126 | GL_UNSIGNED_SHORT_4_4_4_4, p); |
| 127 | break; |
| 128 | case SkBitmap::kARGB_8888_Config: |
| 129 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 130 | GL_UNSIGNED_BYTE, p); |
| 131 | break; |
| 132 | case SkBitmap::kRGB_565_Config: |
| 133 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
| 134 | GL_UNSIGNED_SHORT_5_6_5, p); |
| 135 | break; |
| 136 | default: |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 141 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 142 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 143 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 144 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 145 | return NO_ERROR; |
| 146 | } |
| 147 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 148 | status_t BootAnimation::initTexture(void* buffer, size_t len) |
| 149 | { |
| 150 | //StopWatch watch("blah"); |
| 151 | |
| 152 | SkBitmap bitmap; |
| 153 | SkImageDecoder::DecodeMemory(buffer, len, |
| 154 | &bitmap, SkBitmap::kRGB_565_Config, |
| 155 | SkImageDecoder::kDecodePixels_Mode); |
| 156 | |
| 157 | // ensure we can call getPixels(). No need to call unlock, since the |
| 158 | // bitmap will go out of scope when we return from this method. |
| 159 | bitmap.lockPixels(); |
| 160 | |
| 161 | const int w = bitmap.width(); |
| 162 | const int h = bitmap.height(); |
| 163 | const void* p = bitmap.getPixels(); |
| 164 | |
| 165 | GLint crop[4] = { 0, h, w, -h }; |
| 166 | int tw = 1 << (31 - __builtin_clz(w)); |
| 167 | int th = 1 << (31 - __builtin_clz(h)); |
| 168 | if (tw < w) tw <<= 1; |
| 169 | if (th < h) th <<= 1; |
| 170 | |
| 171 | switch (bitmap.getConfig()) { |
| 172 | case SkBitmap::kARGB_8888_Config: |
| 173 | if (tw != w || th != h) { |
| 174 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, |
| 175 | GL_UNSIGNED_BYTE, 0); |
| 176 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 177 | 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p); |
| 178 | } else { |
| 179 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, |
| 180 | GL_UNSIGNED_BYTE, p); |
| 181 | } |
| 182 | break; |
| 183 | |
| 184 | case SkBitmap::kRGB_565_Config: |
| 185 | if (tw != w || th != h) { |
| 186 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, |
| 187 | GL_UNSIGNED_SHORT_5_6_5, 0); |
| 188 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 189 | 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p); |
| 190 | } else { |
| 191 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, |
| 192 | GL_UNSIGNED_SHORT_5_6_5, p); |
| 193 | } |
| 194 | break; |
| 195 | default: |
| 196 | break; |
| 197 | } |
| 198 | |
| 199 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 200 | |
| 201 | return NO_ERROR; |
| 202 | } |
| 203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | status_t BootAnimation::readyToRun() { |
| 205 | mAssets.addDefaultAssets(); |
| 206 | |
| 207 | DisplayInfo dinfo; |
| 208 | status_t status = session()->getDisplayInfo(0, &dinfo); |
| 209 | if (status) |
| 210 | return -1; |
| 211 | |
| 212 | // create the native surface |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 213 | sp<SurfaceControl> control = session()->createSurface( |
Mathias Agopian | 9638e5c | 2011-04-20 14:19:32 -0700 | [diff] [blame] | 214 | 0, dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 215 | |
| 216 | SurfaceComposerClient::openGlobalTransaction(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 217 | control->setLayer(0x40000000); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 218 | SurfaceComposerClient::closeGlobalTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 220 | sp<Surface> s = control->getSurface(); |
| 221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | // initialize opengl and egl |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 223 | const EGLint attribs[] = { |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 224 | EGL_RED_SIZE, 8, |
| 225 | EGL_GREEN_SIZE, 8, |
| 226 | EGL_BLUE_SIZE, 8, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 227 | EGL_DEPTH_SIZE, 0, |
| 228 | EGL_NONE |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 229 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | EGLint w, h, dummy; |
| 231 | EGLint numConfigs; |
| 232 | EGLConfig config; |
| 233 | EGLSurface surface; |
| 234 | EGLContext context; |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 235 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 237 | |
| 238 | eglInitialize(display, 0, 0); |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 239 | eglChooseConfig(display, attribs, &config, 1, &numConfigs); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 240 | surface = eglCreateWindowSurface(display, config, s.get(), NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | context = eglCreateContext(display, config, NULL, NULL); |
| 242 | eglQuerySurface(display, surface, EGL_WIDTH, &w); |
| 243 | eglQuerySurface(display, surface, EGL_HEIGHT, &h); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 244 | |
Mathias Agopian | abac010 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 245 | if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) |
| 246 | return NO_INIT; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | mDisplay = display; |
| 249 | mContext = context; |
| 250 | mSurface = surface; |
| 251 | mWidth = w; |
| 252 | mHeight = h; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 253 | mFlingerSurfaceControl = control; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | mFlingerSurface = s; |
| 255 | |
Jim Huang | c11f462 | 2010-08-10 03:12:15 +0800 | [diff] [blame] | 256 | mAndroidAnimation = true; |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 257 | |
| 258 | // If the device has encryption turned on or is in process |
| 259 | // of being encrypted we show the encrypted boot animation. |
| 260 | char decrypt[PROPERTY_VALUE_MAX]; |
| 261 | property_get("vold.decrypt", decrypt, ""); |
| 262 | |
| 263 | bool encryptedAnimation = atoi(decrypt) != 0 || !strcmp("trigger_restart_min_framework", decrypt); |
| 264 | |
| 265 | if ((encryptedAnimation && |
| 266 | (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0) && |
| 267 | (mZip.open(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE) == NO_ERROR)) || |
| 268 | |
| 269 | ((access(USER_BOOTANIMATION_FILE, R_OK) == 0) && |
| 270 | (mZip.open(USER_BOOTANIMATION_FILE) == NO_ERROR)) || |
| 271 | |
| 272 | ((access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) && |
| 273 | (mZip.open(SYSTEM_BOOTANIMATION_FILE) == NO_ERROR))) { |
Chih-Wei Huang | 2978751 | 2010-11-03 15:33:00 +0800 | [diff] [blame] | 274 | mAndroidAnimation = false; |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 275 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | |
| 277 | return NO_ERROR; |
| 278 | } |
| 279 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 280 | bool BootAnimation::threadLoop() |
| 281 | { |
| 282 | bool r; |
| 283 | if (mAndroidAnimation) { |
| 284 | r = android(); |
| 285 | } else { |
| 286 | r = movie(); |
| 287 | } |
| 288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 290 | eglDestroyContext(mDisplay, mContext); |
| 291 | eglDestroySurface(mDisplay, mSurface); |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 292 | mFlingerSurface.clear(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 293 | mFlingerSurfaceControl.clear(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 294 | eglTerminate(mDisplay); |
| 295 | IPCThreadState::self()->stopProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | return r; |
| 297 | } |
| 298 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 299 | bool BootAnimation::android() |
| 300 | { |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 301 | initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); |
| 302 | initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | |
| 304 | // clear screen |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 305 | glShadeModel(GL_FLAT); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 306 | glDisable(GL_DITHER); |
| 307 | glDisable(GL_SCISSOR_TEST); |
Mathias Agopian | 59f19e4 | 2011-05-06 19:22:12 -0700 | [diff] [blame] | 308 | glClearColor(0,0,0,1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | glClear(GL_COLOR_BUFFER_BIT); |
| 310 | eglSwapBuffers(mDisplay, mSurface); |
| 311 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 312 | glEnable(GL_TEXTURE_2D); |
| 313 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 314 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 315 | const GLint xc = (mWidth - mAndroid[0].w) / 2; |
| 316 | const GLint yc = (mHeight - mAndroid[0].h) / 2; |
| 317 | const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(), |
| 320 | updateRect.height()); |
| 321 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 322 | // Blend state |
| 323 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 324 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | const nsecs_t startTime = systemTime(); |
| 327 | do { |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 328 | nsecs_t now = systemTime(); |
| 329 | double time = now - startTime; |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 330 | float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w; |
| 331 | GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w; |
| 332 | GLint x = xc - offset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | |
Mathias Agopian | 8166864 | 2009-07-28 11:41:30 -0700 | [diff] [blame] | 334 | glDisable(GL_SCISSOR_TEST); |
| 335 | glClear(GL_COLOR_BUFFER_BIT); |
| 336 | |
| 337 | glEnable(GL_SCISSOR_TEST); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | glDisable(GL_BLEND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | glBindTexture(GL_TEXTURE_2D, mAndroid[1].name); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 340 | glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h); |
| 341 | glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 343 | glEnable(GL_BLEND); |
| 344 | glBindTexture(GL_TEXTURE_2D, mAndroid[0].name); |
| 345 | glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 347 | EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); |
| 348 | if (res == EGL_FALSE) |
| 349 | break; |
| 350 | |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 351 | // 12fps: don't animate too fast to preserve CPU |
| 352 | const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); |
| 353 | if (sleepTime > 0) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 354 | usleep(sleepTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | } while (!exitPending()); |
| 356 | |
| 357 | glDeleteTextures(1, &mAndroid[0].name); |
| 358 | glDeleteTextures(1, &mAndroid[1].name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | return false; |
| 360 | } |
| 361 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 362 | |
| 363 | bool BootAnimation::movie() |
| 364 | { |
| 365 | ZipFileRO& zip(mZip); |
| 366 | |
| 367 | size_t numEntries = zip.getNumEntries(); |
| 368 | ZipEntryRO desc = zip.findEntryByName("desc.txt"); |
| 369 | FileMap* descMap = zip.createEntryFileMap(desc); |
| 370 | LOGE_IF(!descMap, "descMap is null"); |
| 371 | if (!descMap) { |
| 372 | return false; |
| 373 | } |
| 374 | |
| 375 | String8 desString((char const*)descMap->getDataPtr(), |
| 376 | descMap->getDataLength()); |
| 377 | char const* s = desString.string(); |
| 378 | |
| 379 | Animation animation; |
| 380 | |
| 381 | // Parse the description file |
| 382 | for (;;) { |
| 383 | const char* endl = strstr(s, "\n"); |
| 384 | if (!endl) break; |
| 385 | String8 line(s, endl - s); |
| 386 | const char* l = line.string(); |
| 387 | int fps, width, height, count, pause; |
| 388 | char path[256]; |
| 389 | if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) { |
| 390 | //LOGD("> w=%d, h=%d, fps=%d", fps, width, height); |
| 391 | animation.width = width; |
| 392 | animation.height = height; |
| 393 | animation.fps = fps; |
| 394 | } |
| 395 | if (sscanf(l, "p %d %d %s", &count, &pause, path) == 3) { |
| 396 | //LOGD("> count=%d, pause=%d, path=%s", count, pause, path); |
| 397 | Animation::Part part; |
| 398 | part.count = count; |
| 399 | part.pause = pause; |
| 400 | part.path = path; |
| 401 | animation.parts.add(part); |
| 402 | } |
| 403 | s = ++endl; |
| 404 | } |
| 405 | |
| 406 | // read all the data structures |
| 407 | const size_t pcount = animation.parts.size(); |
| 408 | for (size_t i=0 ; i<numEntries ; i++) { |
| 409 | char name[256]; |
| 410 | ZipEntryRO entry = zip.findEntryByIndex(i); |
| 411 | if (zip.getEntryFileName(entry, name, 256) == 0) { |
| 412 | const String8 entryName(name); |
| 413 | const String8 path(entryName.getPathDir()); |
| 414 | const String8 leaf(entryName.getPathLeaf()); |
| 415 | if (leaf.size() > 0) { |
| 416 | for (int j=0 ; j<pcount ; j++) { |
| 417 | if (path == animation.parts[j].path) { |
| 418 | int method; |
| 419 | // supports only stored png files |
| 420 | if (zip.getEntryInfo(entry, &method, 0, 0, 0, 0, 0)) { |
| 421 | if (method == ZipFileRO::kCompressStored) { |
| 422 | FileMap* map = zip.createEntryFileMap(entry); |
| 423 | if (map) { |
| 424 | Animation::Frame frame; |
| 425 | frame.name = leaf; |
| 426 | frame.map = map; |
| 427 | Animation::Part& part(animation.parts.editItemAt(j)); |
| 428 | part.frames.add(frame); |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | // clear screen |
| 439 | glShadeModel(GL_FLAT); |
| 440 | glDisable(GL_DITHER); |
| 441 | glDisable(GL_SCISSOR_TEST); |
| 442 | glDisable(GL_BLEND); |
Mathias Agopian | 59f19e4 | 2011-05-06 19:22:12 -0700 | [diff] [blame] | 443 | glClearColor(0,0,0,1); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 444 | glClear(GL_COLOR_BUFFER_BIT); |
| 445 | |
| 446 | eglSwapBuffers(mDisplay, mSurface); |
| 447 | |
| 448 | glBindTexture(GL_TEXTURE_2D, 0); |
| 449 | glEnable(GL_TEXTURE_2D); |
| 450 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 451 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 452 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 453 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 454 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 455 | |
| 456 | const int xc = (mWidth - animation.width) / 2; |
| 457 | const int yc = ((mHeight - animation.height) / 2); |
| 458 | nsecs_t lastFrame = systemTime(); |
| 459 | nsecs_t frameDuration = s2ns(1) / animation.fps; |
| 460 | |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 461 | Region clearReg(Rect(mWidth, mHeight)); |
| 462 | clearReg.subtractSelf(Rect(xc, yc, xc+animation.width, yc+animation.height)); |
| 463 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 464 | for (int i=0 ; i<pcount && !exitPending() ; i++) { |
| 465 | const Animation::Part& part(animation.parts[i]); |
| 466 | const size_t fcount = part.frames.size(); |
| 467 | glBindTexture(GL_TEXTURE_2D, 0); |
| 468 | |
| 469 | for (int r=0 ; !part.count || r<part.count ; r++) { |
| 470 | for (int j=0 ; j<fcount && !exitPending(); j++) { |
| 471 | const Animation::Frame& frame(part.frames[j]); |
| 472 | |
| 473 | if (r > 0) { |
| 474 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 475 | } else { |
| 476 | if (part.count != 1) { |
| 477 | glGenTextures(1, &frame.tid); |
| 478 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 479 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 480 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 481 | } |
| 482 | initTexture( |
| 483 | frame.map->getDataPtr(), |
| 484 | frame.map->getDataLength()); |
| 485 | } |
| 486 | |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 487 | if (!clearReg.isEmpty()) { |
| 488 | Region::const_iterator head(clearReg.begin()); |
| 489 | Region::const_iterator tail(clearReg.end()); |
| 490 | glEnable(GL_SCISSOR_TEST); |
| 491 | while (head != tail) { |
| 492 | const Rect& r(*head++); |
| 493 | glScissor(r.left, mHeight - r.bottom, |
| 494 | r.width(), r.height()); |
| 495 | glClear(GL_COLOR_BUFFER_BIT); |
| 496 | } |
| 497 | glDisable(GL_SCISSOR_TEST); |
| 498 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 499 | glDrawTexiOES(xc, yc, 0, animation.width, animation.height); |
| 500 | eglSwapBuffers(mDisplay, mSurface); |
| 501 | |
| 502 | nsecs_t now = systemTime(); |
| 503 | nsecs_t delay = frameDuration - (now - lastFrame); |
| 504 | lastFrame = now; |
| 505 | long wait = ns2us(frameDuration); |
| 506 | if (wait > 0) |
| 507 | usleep(wait); |
| 508 | } |
| 509 | usleep(part.pause * ns2us(frameDuration)); |
| 510 | } |
| 511 | |
| 512 | // free the textures for this part |
| 513 | if (part.count != 1) { |
| 514 | for (int j=0 ; j<fcount ; j++) { |
| 515 | const Animation::Frame& frame(part.frames[j]); |
| 516 | glDeleteTextures(1, &frame.tid); |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | return false; |
| 522 | } |
| 523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | // --------------------------------------------------------------------------- |
| 525 | |
| 526 | } |
| 527 | ; // namespace android |