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