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