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