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 | |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 17 | #define LOG_NDEBUG 0 |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 18 | #define LOG_TAG "BootAnimation" |
| 19 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <math.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <utils/misc.h> |
Mathias Agopian | b4d5a72 | 2009-09-23 17:05:19 -0700 | [diff] [blame] | 25 | #include <signal.h> |
Elliott Hughes | bb94f31 | 2014-10-21 10:41:33 -0700 | [diff] [blame] | 26 | #include <time.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 28 | #include <cutils/properties.h> |
| 29 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 30 | #include <androidfw/AssetManager.h> |
Mathias Agopian | ac31a3b | 2009-05-21 19:59:24 -0700 | [diff] [blame] | 31 | #include <binder/IPCThreadState.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include <utils/Atomic.h> |
| 33 | #include <utils/Errors.h> |
| 34 | #include <utils/Log.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
| 36 | #include <ui/PixelFormat.h> |
| 37 | #include <ui/Rect.h> |
| 38 | #include <ui/Region.h> |
| 39 | #include <ui/DisplayInfo.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 | |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 45 | // TODO: Fix Skia. |
| 46 | #pragma GCC diagnostic push |
| 47 | #pragma GCC diagnostic ignored "-Wunused-parameter" |
Derek Sollenberger | eece0dd | 2014-02-27 14:31:29 -0500 | [diff] [blame] | 48 | #include <SkBitmap.h> |
| 49 | #include <SkStream.h> |
| 50 | #include <SkImageDecoder.h> |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 51 | #pragma GCC diagnostic pop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
| 53 | #include <GLES/gl.h> |
| 54 | #include <GLES/glext.h> |
| 55 | #include <EGL/eglext.h> |
| 56 | |
| 57 | #include "BootAnimation.h" |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 58 | #include "AudioPlayer.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 60 | #define OEM_BOOTANIMATION_FILE "/oem/media/bootanimation.zip" |
Jim Huang | c11f462 | 2010-08-10 03:12:15 +0800 | [diff] [blame] | 61 | #define SYSTEM_BOOTANIMATION_FILE "/system/media/bootanimation.zip" |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 62 | #define SYSTEM_ENCRYPTED_BOOTANIMATION_FILE "/system/media/bootanimation-encrypted.zip" |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 63 | #define EXIT_PROP_NAME "service.bootanim.exit" |
Jim Huang | c11f462 | 2010-08-10 03:12:15 +0800 | [diff] [blame] | 64 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | namespace android { |
| 66 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 67 | static const int ANIM_ENTRY_NAME_MAX = 256; |
| 68 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | // --------------------------------------------------------------------------- |
| 70 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 71 | BootAnimation::BootAnimation() : Thread(false) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 72 | { |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 73 | mSession = new SurfaceComposerClient(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | BootAnimation::~BootAnimation() { |
| 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 | afd31e0 | 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(); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 101 | if (mAudioPlayer != NULL) { |
| 102 | mAudioPlayer->requestExit(); |
| 103 | } |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 104 | } |
| 105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, |
| 107 | const char* name) { |
| 108 | Asset* asset = assets.open(name, Asset::ACCESS_BUFFER); |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 109 | if (asset == NULL) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | return NO_INIT; |
| 111 | SkBitmap bitmap; |
| 112 | SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(), |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 113 | &bitmap, kUnknown_SkColorType, SkImageDecoder::kDecodePixels_Mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | asset->close(); |
| 115 | delete asset; |
| 116 | |
| 117 | // ensure we can call getPixels(). No need to call unlock, since the |
| 118 | // bitmap will go out of scope when we return from this method. |
| 119 | bitmap.lockPixels(); |
| 120 | |
| 121 | const int w = bitmap.width(); |
| 122 | const int h = bitmap.height(); |
| 123 | const void* p = bitmap.getPixels(); |
| 124 | |
| 125 | GLint crop[4] = { 0, h, w, -h }; |
| 126 | texture->w = w; |
| 127 | texture->h = h; |
| 128 | |
| 129 | glGenTextures(1, &texture->name); |
| 130 | glBindTexture(GL_TEXTURE_2D, texture->name); |
| 131 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 132 | switch (bitmap.colorType()) { |
| 133 | case kAlpha_8_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, |
| 135 | GL_UNSIGNED_BYTE, p); |
| 136 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 137 | case kARGB_4444_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 139 | GL_UNSIGNED_SHORT_4_4_4_4, p); |
| 140 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 141 | case kN32_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 143 | GL_UNSIGNED_BYTE, p); |
| 144 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 145 | case kRGB_565_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
| 147 | GL_UNSIGNED_SHORT_5_6_5, p); |
| 148 | break; |
| 149 | default: |
| 150 | break; |
| 151 | } |
| 152 | |
| 153 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 154 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 155 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 156 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 157 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 158 | return NO_ERROR; |
| 159 | } |
| 160 | |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 161 | status_t BootAnimation::initTexture(const Animation::Frame& frame) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 162 | { |
| 163 | //StopWatch watch("blah"); |
| 164 | |
| 165 | SkBitmap bitmap; |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 166 | SkMemoryStream stream(frame.map->getDataPtr(), frame.map->getDataLength()); |
Mathias Agopian | 2b99e55 | 2011-11-10 15:59:07 -0800 | [diff] [blame] | 167 | SkImageDecoder* codec = SkImageDecoder::Factory(&stream); |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 168 | if (codec != NULL) { |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 169 | codec->setDitherImage(false); |
Mathias Agopian | 2b99e55 | 2011-11-10 15:59:07 -0800 | [diff] [blame] | 170 | codec->decode(&stream, &bitmap, |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 171 | kN32_SkColorType, |
Mathias Agopian | 2b99e55 | 2011-11-10 15:59:07 -0800 | [diff] [blame] | 172 | SkImageDecoder::kDecodePixels_Mode); |
| 173 | delete codec; |
| 174 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 175 | |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 176 | // FileMap memory is never released until application exit. |
| 177 | // Release it now as the texture is already loaded and the memory used for |
| 178 | // the packed resource can be released. |
Narayan Kamath | 688ff4c | 2015-02-23 15:47:54 +0000 | [diff] [blame] | 179 | delete frame.map; |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 180 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 181 | // ensure we can call getPixels(). No need to call unlock, since the |
| 182 | // bitmap will go out of scope when we return from this method. |
| 183 | bitmap.lockPixels(); |
| 184 | |
| 185 | const int w = bitmap.width(); |
| 186 | const int h = bitmap.height(); |
| 187 | const void* p = bitmap.getPixels(); |
| 188 | |
| 189 | GLint crop[4] = { 0, h, w, -h }; |
| 190 | int tw = 1 << (31 - __builtin_clz(w)); |
| 191 | int th = 1 << (31 - __builtin_clz(h)); |
| 192 | if (tw < w) tw <<= 1; |
| 193 | if (th < h) th <<= 1; |
| 194 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 195 | switch (bitmap.colorType()) { |
| 196 | case kN32_SkColorType: |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 197 | if (tw != w || th != h) { |
| 198 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, |
| 199 | GL_UNSIGNED_BYTE, 0); |
| 200 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 201 | 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p); |
| 202 | } else { |
| 203 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, |
| 204 | GL_UNSIGNED_BYTE, p); |
| 205 | } |
| 206 | break; |
| 207 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 208 | case kRGB_565_SkColorType: |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 209 | if (tw != w || th != h) { |
| 210 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, |
| 211 | GL_UNSIGNED_SHORT_5_6_5, 0); |
| 212 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 213 | 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p); |
| 214 | } else { |
| 215 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, |
| 216 | GL_UNSIGNED_SHORT_5_6_5, p); |
| 217 | } |
| 218 | break; |
| 219 | default: |
| 220 | break; |
| 221 | } |
| 222 | |
| 223 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 224 | |
| 225 | return NO_ERROR; |
| 226 | } |
| 227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | status_t BootAnimation::readyToRun() { |
| 229 | mAssets.addDefaultAssets(); |
| 230 | |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 231 | sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay( |
| 232 | ISurfaceComposer::eDisplayIdMain)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | DisplayInfo dinfo; |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 234 | status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | if (status) |
| 236 | return -1; |
| 237 | |
| 238 | // create the native surface |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 239 | sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"), |
| 240 | dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 241 | |
| 242 | SurfaceComposerClient::openGlobalTransaction(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 243 | control->setLayer(0x40000000); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 244 | SurfaceComposerClient::closeGlobalTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 246 | sp<Surface> s = control->getSurface(); |
| 247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | // initialize opengl and egl |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 249 | const EGLint attribs[] = { |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 250 | EGL_RED_SIZE, 8, |
| 251 | EGL_GREEN_SIZE, 8, |
| 252 | EGL_BLUE_SIZE, 8, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 253 | EGL_DEPTH_SIZE, 0, |
| 254 | EGL_NONE |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 255 | }; |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 256 | EGLint w, h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | EGLint numConfigs; |
| 258 | EGLConfig config; |
| 259 | EGLSurface surface; |
| 260 | EGLContext context; |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 263 | |
| 264 | eglInitialize(display, 0, 0); |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 265 | eglChooseConfig(display, attribs, &config, 1, &numConfigs); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 266 | surface = eglCreateWindowSurface(display, config, s.get(), NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | context = eglCreateContext(display, config, NULL, NULL); |
| 268 | eglQuerySurface(display, surface, EGL_WIDTH, &w); |
| 269 | eglQuerySurface(display, surface, EGL_HEIGHT, &h); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 270 | |
Mathias Agopian | abac010 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 271 | if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) |
| 272 | return NO_INIT; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | mDisplay = display; |
| 275 | mContext = context; |
| 276 | mSurface = surface; |
| 277 | mWidth = w; |
| 278 | mHeight = h; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 279 | mFlingerSurfaceControl = control; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | mFlingerSurface = s; |
| 281 | |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 282 | // If the device has encryption turned on or is in process |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 283 | // of being encrypted we show the encrypted boot animation. |
| 284 | char decrypt[PROPERTY_VALUE_MAX]; |
| 285 | property_get("vold.decrypt", decrypt, ""); |
| 286 | |
| 287 | bool encryptedAnimation = atoi(decrypt) != 0 || !strcmp("trigger_restart_min_framework", decrypt); |
| 288 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 289 | if (encryptedAnimation && (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0)) { |
| 290 | mZipFileName = SYSTEM_ENCRYPTED_BOOTANIMATION_FILE; |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 291 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 292 | else if (access(OEM_BOOTANIMATION_FILE, R_OK) == 0) { |
| 293 | mZipFileName = OEM_BOOTANIMATION_FILE; |
| 294 | } |
| 295 | else if (access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) { |
| 296 | mZipFileName = SYSTEM_BOOTANIMATION_FILE; |
| 297 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | return NO_ERROR; |
| 299 | } |
| 300 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 301 | bool BootAnimation::threadLoop() |
| 302 | { |
| 303 | bool r; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 304 | // We have no bootanimation file, so we use the stock android logo |
| 305 | // animation. |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 306 | if (mZipFileName.isEmpty()) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 307 | r = android(); |
| 308 | } else { |
| 309 | r = movie(); |
| 310 | } |
| 311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 313 | eglDestroyContext(mDisplay, mContext); |
| 314 | eglDestroySurface(mDisplay, mSurface); |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 315 | mFlingerSurface.clear(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 316 | mFlingerSurfaceControl.clear(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 317 | eglTerminate(mDisplay); |
| 318 | IPCThreadState::self()->stopProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | return r; |
| 320 | } |
| 321 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 322 | bool BootAnimation::android() |
| 323 | { |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 324 | initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); |
| 325 | initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | |
| 327 | // clear screen |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 328 | glShadeModel(GL_FLAT); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 329 | glDisable(GL_DITHER); |
| 330 | glDisable(GL_SCISSOR_TEST); |
Mathias Agopian | 59f19e4 | 2011-05-06 19:22:12 -0700 | [diff] [blame] | 331 | glClearColor(0,0,0,1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | glClear(GL_COLOR_BUFFER_BIT); |
| 333 | eglSwapBuffers(mDisplay, mSurface); |
| 334 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 335 | glEnable(GL_TEXTURE_2D); |
| 336 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 337 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 338 | const GLint xc = (mWidth - mAndroid[0].w) / 2; |
| 339 | const GLint yc = (mHeight - mAndroid[0].h) / 2; |
| 340 | 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] | 341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(), |
| 343 | updateRect.height()); |
| 344 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 345 | // Blend state |
| 346 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 347 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | const nsecs_t startTime = systemTime(); |
| 350 | do { |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 351 | nsecs_t now = systemTime(); |
| 352 | double time = now - startTime; |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 353 | float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w; |
| 354 | GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w; |
| 355 | GLint x = xc - offset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | |
Mathias Agopian | 8166864 | 2009-07-28 11:41:30 -0700 | [diff] [blame] | 357 | glDisable(GL_SCISSOR_TEST); |
| 358 | glClear(GL_COLOR_BUFFER_BIT); |
| 359 | |
| 360 | glEnable(GL_SCISSOR_TEST); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | glDisable(GL_BLEND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | glBindTexture(GL_TEXTURE_2D, mAndroid[1].name); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 363 | glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h); |
| 364 | 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] | 365 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 366 | glEnable(GL_BLEND); |
| 367 | glBindTexture(GL_TEXTURE_2D, mAndroid[0].name); |
| 368 | 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] | 369 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 370 | EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); |
| 371 | if (res == EGL_FALSE) |
| 372 | break; |
| 373 | |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 374 | // 12fps: don't animate too fast to preserve CPU |
| 375 | const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); |
| 376 | if (sleepTime > 0) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 377 | usleep(sleepTime); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 378 | |
| 379 | checkExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | } while (!exitPending()); |
| 381 | |
| 382 | glDeleteTextures(1, &mAndroid[0].name); |
| 383 | glDeleteTextures(1, &mAndroid[1].name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | return false; |
| 385 | } |
| 386 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 387 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 388 | void BootAnimation::checkExit() { |
| 389 | // Allow surface flinger to gracefully request shutdown |
| 390 | char value[PROPERTY_VALUE_MAX]; |
| 391 | property_get(EXIT_PROP_NAME, value, "0"); |
| 392 | int exitnow = atoi(value); |
| 393 | if (exitnow) { |
| 394 | requestExit(); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 395 | if (mAudioPlayer != NULL) { |
| 396 | mAudioPlayer->requestExit(); |
| 397 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 401 | // Parse a color represented as an HTML-style 'RRGGBB' string: each pair of |
| 402 | // characters in str is a hex number in [0, 255], which are converted to |
| 403 | // floating point values in the range [0.0, 1.0] and placed in the |
| 404 | // corresponding elements of color. |
| 405 | // |
| 406 | // If the input string isn't valid, parseColor returns false and color is |
| 407 | // left unchanged. |
| 408 | static bool parseColor(const char str[7], float color[3]) { |
| 409 | float tmpColor[3]; |
| 410 | for (int i = 0; i < 3; i++) { |
| 411 | int val = 0; |
| 412 | for (int j = 0; j < 2; j++) { |
| 413 | val *= 16; |
| 414 | char c = str[2*i + j]; |
| 415 | if (c >= '0' && c <= '9') val += c - '0'; |
| 416 | else if (c >= 'A' && c <= 'F') val += (c - 'A') + 10; |
| 417 | else if (c >= 'a' && c <= 'f') val += (c - 'a') + 10; |
| 418 | else return false; |
| 419 | } |
| 420 | tmpColor[i] = static_cast<float>(val) / 255.0f; |
| 421 | } |
| 422 | memcpy(color, tmpColor, sizeof(tmpColor)); |
| 423 | return true; |
| 424 | } |
| 425 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 426 | |
| 427 | static bool readFile(ZipFileRO* zip, const char* name, String8& outString) |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 428 | { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 429 | ZipEntryRO entry = zip->findEntryByName(name); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 430 | ALOGE_IF(!entry, "couldn't find %s", name); |
| 431 | if (!entry) { |
| 432 | return false; |
| 433 | } |
| 434 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 435 | FileMap* entryMap = zip->createEntryFileMap(entry); |
| 436 | zip->releaseEntry(entry); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 437 | ALOGE_IF(!entryMap, "entryMap is null"); |
| 438 | if (!entryMap) { |
| 439 | return false; |
| 440 | } |
| 441 | |
| 442 | outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength()); |
Narayan Kamath | 688ff4c | 2015-02-23 15:47:54 +0000 | [diff] [blame] | 443 | delete entryMap; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 444 | return true; |
| 445 | } |
| 446 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 447 | bool BootAnimation::parseAnimationDesc(Animation& animation) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 448 | { |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 449 | String8 desString; |
| 450 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 451 | if (!readFile(animation.zip, "desc.txt", desString)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 452 | return false; |
| 453 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 454 | char const* s = desString.string(); |
| 455 | |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 456 | // Create and initialize an AudioPlayer if we have an audio_conf.txt file |
| 457 | String8 audioConf; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 458 | if (readFile(animation.zip, "audio_conf.txt", audioConf)) { |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 459 | mAudioPlayer = new AudioPlayer; |
| 460 | if (!mAudioPlayer->init(audioConf.string())) { |
| 461 | ALOGE("mAudioPlayer.init failed"); |
| 462 | mAudioPlayer = NULL; |
| 463 | } |
| 464 | } |
| 465 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 466 | // Parse the description file |
| 467 | for (;;) { |
| 468 | const char* endl = strstr(s, "\n"); |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 469 | if (endl == NULL) break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 470 | String8 line(s, endl - s); |
| 471 | const char* l = line.string(); |
| 472 | int fps, width, height, count, pause; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 473 | char path[ANIM_ENTRY_NAME_MAX]; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 474 | char color[7] = "000000"; // default to black if unspecified |
| 475 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 476 | char pathType; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 477 | if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) { |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 478 | // ALOGD("> w=%d, h=%d, fps=%d", width, height, fps); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 479 | animation.width = width; |
| 480 | animation.height = height; |
| 481 | animation.fps = fps; |
| 482 | } |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 483 | else if (sscanf(l, " %c %d %d %s #%6s", &pathType, &count, &pause, path, color) >= 4) { |
| 484 | // ALOGD("> type=%c, count=%d, pause=%d, path=%s, color=%s", pathType, count, pause, path, color); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 485 | Animation::Part part; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 486 | part.playUntilComplete = pathType == 'c'; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 487 | part.count = count; |
| 488 | part.pause = pause; |
| 489 | part.path = path; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 490 | part.audioFile = NULL; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 491 | part.animation = NULL; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 492 | if (!parseColor(color, part.backgroundColor)) { |
| 493 | ALOGE("> invalid color '#%s'", color); |
| 494 | part.backgroundColor[0] = 0.0f; |
| 495 | part.backgroundColor[1] = 0.0f; |
| 496 | part.backgroundColor[2] = 0.0f; |
| 497 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 498 | animation.parts.add(part); |
| 499 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 500 | else if (strcmp(l, "$SYSTEM") == 0) { |
| 501 | // ALOGD("> SYSTEM"); |
| 502 | Animation::Part part; |
| 503 | part.playUntilComplete = false; |
| 504 | part.count = 1; |
| 505 | part.pause = 0; |
| 506 | part.audioFile = NULL; |
| 507 | part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE)); |
| 508 | if (part.animation != NULL) |
| 509 | animation.parts.add(part); |
| 510 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 511 | s = ++endl; |
| 512 | } |
| 513 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 514 | return true; |
| 515 | } |
| 516 | |
| 517 | bool BootAnimation::preloadZip(Animation& animation) |
| 518 | { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 519 | // read all the data structures |
| 520 | const size_t pcount = animation.parts.size(); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 521 | void *cookie = NULL; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 522 | ZipFileRO* mZip = animation.zip; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 523 | if (!mZip->startIteration(&cookie)) { |
| 524 | return false; |
| 525 | } |
| 526 | |
| 527 | ZipEntryRO entry; |
| 528 | char name[ANIM_ENTRY_NAME_MAX]; |
| 529 | while ((entry = mZip->nextEntry(cookie)) != NULL) { |
| 530 | const int foundEntryName = mZip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX); |
| 531 | if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) { |
| 532 | ALOGE("Error fetching entry file name"); |
| 533 | continue; |
| 534 | } |
| 535 | |
| 536 | const String8 entryName(name); |
| 537 | const String8 path(entryName.getPathDir()); |
| 538 | const String8 leaf(entryName.getPathLeaf()); |
| 539 | if (leaf.size() > 0) { |
| 540 | for (size_t j=0 ; j<pcount ; j++) { |
| 541 | if (path == animation.parts[j].path) { |
Narayan Kamath | 4600dd0 | 2015-06-16 12:02:57 +0100 | [diff] [blame] | 542 | uint16_t method; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 543 | // supports only stored png files |
| 544 | if (mZip->getEntryInfo(entry, &method, NULL, NULL, NULL, NULL, NULL)) { |
| 545 | if (method == ZipFileRO::kCompressStored) { |
| 546 | FileMap* map = mZip->createEntryFileMap(entry); |
| 547 | if (map) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 548 | Animation::Part& part(animation.parts.editItemAt(j)); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 549 | if (leaf == "audio.wav") { |
| 550 | // a part may have at most one audio file |
| 551 | part.audioFile = map; |
| 552 | } else { |
| 553 | Animation::Frame frame; |
| 554 | frame.name = leaf; |
| 555 | frame.map = map; |
| 556 | part.frames.add(frame); |
| 557 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 558 | } |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 566 | mZip->endIteration(cookie); |
| 567 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 568 | return true; |
| 569 | } |
| 570 | |
| 571 | bool BootAnimation::movie() |
| 572 | { |
| 573 | |
| 574 | Animation* animation = loadAnimation(mZipFileName); |
| 575 | if (animation == NULL) |
| 576 | return false; |
| 577 | |
| 578 | // clear screen |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 579 | glShadeModel(GL_FLAT); |
| 580 | glDisable(GL_DITHER); |
| 581 | glDisable(GL_SCISSOR_TEST); |
| 582 | glDisable(GL_BLEND); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 583 | |
| 584 | glBindTexture(GL_TEXTURE_2D, 0); |
| 585 | glEnable(GL_TEXTURE_2D); |
| 586 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 587 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 588 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 589 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 590 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 591 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 592 | playAnimation(*animation); |
| 593 | releaseAnimation(animation); |
| 594 | |
| 595 | return false; |
| 596 | } |
| 597 | |
| 598 | bool BootAnimation::playAnimation(const Animation& animation) |
| 599 | { |
| 600 | const size_t pcount = animation.parts.size(); |
| 601 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 602 | const int xc = (mWidth - animation.width) / 2; |
| 603 | const int yc = ((mHeight - animation.height) / 2); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 604 | nsecs_t frameDuration = s2ns(1) / animation.fps; |
| 605 | |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 606 | Region clearReg(Rect(mWidth, mHeight)); |
| 607 | clearReg.subtractSelf(Rect(xc, yc, xc+animation.width, yc+animation.height)); |
| 608 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 609 | for (size_t i=0 ; i<pcount ; i++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 610 | const Animation::Part& part(animation.parts[i]); |
| 611 | const size_t fcount = part.frames.size(); |
| 612 | glBindTexture(GL_TEXTURE_2D, 0); |
| 613 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 614 | // Handle animation package |
| 615 | if (part.animation != NULL) { |
| 616 | playAnimation(*part.animation); |
| 617 | if (exitPending()) |
| 618 | break; |
| 619 | continue; //to next part |
| 620 | } |
| 621 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 622 | for (int r=0 ; !part.count || r<part.count ; r++) { |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 623 | // Exit any non playuntil complete parts immediately |
| 624 | if(exitPending() && !part.playUntilComplete) |
| 625 | break; |
| 626 | |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 627 | // only play audio file the first time we animate the part |
| 628 | if (r == 0 && mAudioPlayer != NULL && part.audioFile) { |
| 629 | mAudioPlayer->playFile(part.audioFile); |
| 630 | } |
| 631 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 632 | glClearColor( |
| 633 | part.backgroundColor[0], |
| 634 | part.backgroundColor[1], |
| 635 | part.backgroundColor[2], |
| 636 | 1.0f); |
| 637 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 638 | for (size_t j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 639 | const Animation::Frame& frame(part.frames[j]); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 640 | nsecs_t lastFrame = systemTime(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 641 | |
| 642 | if (r > 0) { |
| 643 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 644 | } else { |
| 645 | if (part.count != 1) { |
| 646 | glGenTextures(1, &frame.tid); |
| 647 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 648 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 649 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 650 | } |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 651 | initTexture(frame); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 654 | if (!clearReg.isEmpty()) { |
| 655 | Region::const_iterator head(clearReg.begin()); |
| 656 | Region::const_iterator tail(clearReg.end()); |
| 657 | glEnable(GL_SCISSOR_TEST); |
| 658 | while (head != tail) { |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 659 | const Rect& r2(*head++); |
| 660 | glScissor(r2.left, mHeight - r2.bottom, |
| 661 | r2.width(), r2.height()); |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 662 | glClear(GL_COLOR_BUFFER_BIT); |
| 663 | } |
| 664 | glDisable(GL_SCISSOR_TEST); |
| 665 | } |
Chris Elliott | d13d504 | 2015-05-04 15:24:12 -0700 | [diff] [blame] | 666 | // specify the y center as ceiling((mHeight - animation.height) / 2) |
| 667 | // which is equivalent to mHeight - (yc + animation.height) |
| 668 | glDrawTexiOES(xc, mHeight - (yc + animation.height), |
| 669 | 0, animation.width, animation.height); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 670 | eglSwapBuffers(mDisplay, mSurface); |
| 671 | |
| 672 | nsecs_t now = systemTime(); |
| 673 | nsecs_t delay = frameDuration - (now - lastFrame); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 674 | //ALOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay)); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 675 | lastFrame = now; |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 676 | |
| 677 | if (delay > 0) { |
| 678 | struct timespec spec; |
| 679 | spec.tv_sec = (now + delay) / 1000000000; |
| 680 | spec.tv_nsec = (now + delay) % 1000000000; |
| 681 | int err; |
| 682 | do { |
| 683 | err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL); |
| 684 | } while (err<0 && errno == EINTR); |
| 685 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 686 | |
| 687 | checkExit(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 688 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 689 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 690 | usleep(part.pause * ns2us(frameDuration)); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 691 | |
| 692 | // For infinite parts, we've now played them at least once, so perhaps exit |
| 693 | if(exitPending() && !part.count) |
| 694 | break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | // free the textures for this part |
| 698 | if (part.count != 1) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 699 | for (size_t j=0 ; j<fcount ; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 700 | const Animation::Frame& frame(part.frames[j]); |
| 701 | glDeleteTextures(1, &frame.tid); |
| 702 | } |
| 703 | } |
| 704 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 705 | return true; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame^] | 708 | void BootAnimation::releaseAnimation(Animation* animation) const |
| 709 | { |
| 710 | for (Vector<Animation::Part>::iterator it = animation->parts.begin(), |
| 711 | e = animation->parts.end(); it != e; ++it) { |
| 712 | if (it->animation) |
| 713 | releaseAnimation(it->animation); |
| 714 | } |
| 715 | if (animation->zip) |
| 716 | delete animation->zip; |
| 717 | delete animation; |
| 718 | } |
| 719 | |
| 720 | BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn) |
| 721 | { |
| 722 | if (mLoadedFiles.indexOf(fn) >= 0) { |
| 723 | ALOGE("File \"%s\" is already loaded. Cyclic ref is not allowed", |
| 724 | fn.string()); |
| 725 | return NULL; |
| 726 | } |
| 727 | ZipFileRO *zip = ZipFileRO::open(fn); |
| 728 | if (zip == NULL) { |
| 729 | ALOGE("Failed to open animation zip \"%s\": %s", |
| 730 | fn.string(), strerror(errno)); |
| 731 | return NULL; |
| 732 | } |
| 733 | |
| 734 | Animation *animation = new Animation; |
| 735 | animation->fileName = fn; |
| 736 | animation->zip = zip; |
| 737 | mLoadedFiles.add(animation->fileName); |
| 738 | |
| 739 | parseAnimationDesc(*animation); |
| 740 | preloadZip(*animation); |
| 741 | |
| 742 | mLoadedFiles.remove(fn); |
| 743 | return animation; |
| 744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | // --------------------------------------------------------------------------- |
| 746 | |
| 747 | } |
| 748 | ; // namespace android |