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