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> |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 21 | #include <sys/inotify.h> |
| 22 | #include <sys/poll.h> |
| 23 | #include <sys/stat.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <sys/types.h> |
| 25 | #include <math.h> |
| 26 | #include <fcntl.h> |
| 27 | #include <utils/misc.h> |
Mathias Agopian | b4d5a72 | 2009-09-23 17:05:19 -0700 | [diff] [blame] | 28 | #include <signal.h> |
Elliott Hughes | bb94f31 | 2014-10-21 10:41:33 -0700 | [diff] [blame] | 29 | #include <time.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 31 | #include <cutils/properties.h> |
| 32 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 33 | #include <androidfw/AssetManager.h> |
Mathias Agopian | ac31a3b | 2009-05-21 19:59:24 -0700 | [diff] [blame] | 34 | #include <binder/IPCThreadState.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | #include <utils/Atomic.h> |
| 36 | #include <utils/Errors.h> |
| 37 | #include <utils/Log.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
| 39 | #include <ui/PixelFormat.h> |
| 40 | #include <ui/Rect.h> |
| 41 | #include <ui/Region.h> |
| 42 | #include <ui/DisplayInfo.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 44 | #include <gui/ISurfaceComposer.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 45 | #include <gui/Surface.h> |
| 46 | #include <gui/SurfaceComposerClient.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 47 | |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 48 | // TODO: Fix Skia. |
| 49 | #pragma GCC diagnostic push |
| 50 | #pragma GCC diagnostic ignored "-Wunused-parameter" |
Derek Sollenberger | eece0dd | 2014-02-27 14:31:29 -0500 | [diff] [blame] | 51 | #include <SkBitmap.h> |
| 52 | #include <SkStream.h> |
| 53 | #include <SkImageDecoder.h> |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 54 | #pragma GCC diagnostic pop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
| 56 | #include <GLES/gl.h> |
| 57 | #include <GLES/glext.h> |
| 58 | #include <EGL/eglext.h> |
| 59 | |
| 60 | #include "BootAnimation.h" |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 61 | #include "audioplay.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | |
| 63 | namespace android { |
| 64 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 65 | static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip"; |
| 66 | static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip"; |
| 67 | static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip"; |
| 68 | static const char SYSTEM_DATA_DIR_PATH[] = "/data/system"; |
| 69 | static const char SYSTEM_TIME_DIR_NAME[] = "time"; |
| 70 | static const char SYSTEM_TIME_DIR_PATH[] = "/data/system/time"; |
| 71 | static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change"; |
| 72 | static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/system/time/last_time_change"; |
| 73 | static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate"; |
| 74 | static const char ACCURATE_TIME_FLAG_FILE_PATH[] = "/data/system/time/time_is_accurate"; |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 75 | // Java timestamp format. Don't show the clock if the date is before 2000-01-01 00:00:00. |
| 76 | static const long long ACCURATE_TIME_EPOCH = 946684800000; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 77 | static const char EXIT_PROP_NAME[] = "service.bootanim.exit"; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 78 | static const int ANIM_ENTRY_NAME_MAX = 256; |
| 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | // --------------------------------------------------------------------------- |
| 81 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 82 | BootAnimation::BootAnimation() : Thread(false), mClockEnabled(true), mTimeIsAccurate(false), |
| 83 | mTimeCheckThread(NULL) { |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 84 | mSession = new SurfaceComposerClient(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 87 | BootAnimation::~BootAnimation() {} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | |
| 89 | void BootAnimation::onFirstRef() { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 90 | status_t err = mSession->linkToComposerDeath(this); |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 91 | ALOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err)); |
Mathias Agopian | 8434c53 | 2009-09-23 18:52:49 -0700 | [diff] [blame] | 92 | if (err == NO_ERROR) { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 93 | run("BootAnimation", PRIORITY_DISPLAY); |
| 94 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 97 | sp<SurfaceComposerClient> BootAnimation::session() const { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | return mSession; |
| 99 | } |
| 100 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 101 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 102 | void BootAnimation::binderDied(const wp<IBinder>&) |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 103 | { |
| 104 | // woah, surfaceflinger died! |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 105 | ALOGD("SurfaceFlinger died, exiting..."); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 106 | |
| 107 | // calling requestExit() is not enough here because the Surface code |
| 108 | // might be blocked on a condition variable that will never be updated. |
| 109 | kill( getpid(), SIGKILL ); |
| 110 | requestExit(); |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 111 | audioplay::destroy(); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 112 | } |
| 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, |
| 115 | const char* name) { |
| 116 | Asset* asset = assets.open(name, Asset::ACCESS_BUFFER); |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 117 | if (asset == NULL) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | return NO_INIT; |
| 119 | SkBitmap bitmap; |
| 120 | SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(), |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 121 | &bitmap, kUnknown_SkColorType, SkImageDecoder::kDecodePixels_Mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | asset->close(); |
| 123 | delete asset; |
| 124 | |
| 125 | // ensure we can call getPixels(). No need to call unlock, since the |
| 126 | // bitmap will go out of scope when we return from this method. |
| 127 | bitmap.lockPixels(); |
| 128 | |
| 129 | const int w = bitmap.width(); |
| 130 | const int h = bitmap.height(); |
| 131 | const void* p = bitmap.getPixels(); |
| 132 | |
| 133 | GLint crop[4] = { 0, h, w, -h }; |
| 134 | texture->w = w; |
| 135 | texture->h = h; |
| 136 | |
| 137 | glGenTextures(1, &texture->name); |
| 138 | glBindTexture(GL_TEXTURE_2D, texture->name); |
| 139 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 140 | switch (bitmap.colorType()) { |
| 141 | case kAlpha_8_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, |
| 143 | GL_UNSIGNED_BYTE, p); |
| 144 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 145 | case kARGB_4444_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 147 | GL_UNSIGNED_SHORT_4_4_4_4, p); |
| 148 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 149 | case kN32_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 151 | GL_UNSIGNED_BYTE, p); |
| 152 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 153 | case kRGB_565_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
| 155 | GL_UNSIGNED_SHORT_5_6_5, p); |
| 156 | break; |
| 157 | default: |
| 158 | break; |
| 159 | } |
| 160 | |
| 161 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 162 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 163 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 164 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 165 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 166 | return NO_ERROR; |
| 167 | } |
| 168 | |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 169 | status_t BootAnimation::initTexture(const Animation::Frame& frame) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 170 | { |
| 171 | //StopWatch watch("blah"); |
| 172 | |
| 173 | SkBitmap bitmap; |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 174 | SkMemoryStream stream(frame.map->getDataPtr(), frame.map->getDataLength()); |
Mathias Agopian | 2b99e55 | 2011-11-10 15:59:07 -0800 | [diff] [blame] | 175 | SkImageDecoder* codec = SkImageDecoder::Factory(&stream); |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 176 | if (codec != NULL) { |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 177 | codec->setDitherImage(false); |
Mathias Agopian | 2b99e55 | 2011-11-10 15:59:07 -0800 | [diff] [blame] | 178 | codec->decode(&stream, &bitmap, |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 179 | kN32_SkColorType, |
Mathias Agopian | 2b99e55 | 2011-11-10 15:59:07 -0800 | [diff] [blame] | 180 | SkImageDecoder::kDecodePixels_Mode); |
| 181 | delete codec; |
| 182 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 183 | |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 184 | // FileMap memory is never released until application exit. |
| 185 | // Release it now as the texture is already loaded and the memory used for |
| 186 | // the packed resource can be released. |
Narayan Kamath | 688ff4c | 2015-02-23 15:47:54 +0000 | [diff] [blame] | 187 | delete frame.map; |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 188 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 189 | // ensure we can call getPixels(). No need to call unlock, since the |
| 190 | // bitmap will go out of scope when we return from this method. |
| 191 | bitmap.lockPixels(); |
| 192 | |
| 193 | const int w = bitmap.width(); |
| 194 | const int h = bitmap.height(); |
| 195 | const void* p = bitmap.getPixels(); |
| 196 | |
| 197 | GLint crop[4] = { 0, h, w, -h }; |
| 198 | int tw = 1 << (31 - __builtin_clz(w)); |
| 199 | int th = 1 << (31 - __builtin_clz(h)); |
| 200 | if (tw < w) tw <<= 1; |
| 201 | if (th < h) th <<= 1; |
| 202 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 203 | switch (bitmap.colorType()) { |
| 204 | case kN32_SkColorType: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 205 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 206 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, |
| 207 | GL_UNSIGNED_BYTE, 0); |
| 208 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 209 | 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p); |
| 210 | } else { |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 211 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 212 | GL_UNSIGNED_BYTE, p); |
| 213 | } |
| 214 | break; |
| 215 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 216 | case kRGB_565_SkColorType: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 217 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 218 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, |
| 219 | GL_UNSIGNED_SHORT_5_6_5, 0); |
| 220 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 221 | 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p); |
| 222 | } else { |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 223 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 224 | GL_UNSIGNED_SHORT_5_6_5, p); |
| 225 | } |
| 226 | break; |
| 227 | default: |
| 228 | break; |
| 229 | } |
| 230 | |
| 231 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 232 | |
| 233 | return NO_ERROR; |
| 234 | } |
| 235 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | status_t BootAnimation::readyToRun() { |
| 237 | mAssets.addDefaultAssets(); |
| 238 | |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 239 | sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay( |
| 240 | ISurfaceComposer::eDisplayIdMain)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | DisplayInfo dinfo; |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 242 | status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | if (status) |
| 244 | return -1; |
| 245 | |
| 246 | // create the native surface |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 247 | sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"), |
| 248 | dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 249 | |
| 250 | SurfaceComposerClient::openGlobalTransaction(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 251 | control->setLayer(0x40000000); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 252 | SurfaceComposerClient::closeGlobalTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 254 | sp<Surface> s = control->getSurface(); |
| 255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | // initialize opengl and egl |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 257 | const EGLint attribs[] = { |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 258 | EGL_RED_SIZE, 8, |
| 259 | EGL_GREEN_SIZE, 8, |
| 260 | EGL_BLUE_SIZE, 8, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 261 | EGL_DEPTH_SIZE, 0, |
| 262 | EGL_NONE |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 263 | }; |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 264 | EGLint w, h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | EGLint numConfigs; |
| 266 | EGLConfig config; |
| 267 | EGLSurface surface; |
| 268 | EGLContext context; |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 271 | |
| 272 | eglInitialize(display, 0, 0); |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 273 | eglChooseConfig(display, attribs, &config, 1, &numConfigs); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 274 | surface = eglCreateWindowSurface(display, config, s.get(), NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | context = eglCreateContext(display, config, NULL, NULL); |
| 276 | eglQuerySurface(display, surface, EGL_WIDTH, &w); |
| 277 | eglQuerySurface(display, surface, EGL_HEIGHT, &h); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 278 | |
Mathias Agopian | abac010 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 279 | if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) |
| 280 | return NO_INIT; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | mDisplay = display; |
| 283 | mContext = context; |
| 284 | mSurface = surface; |
| 285 | mWidth = w; |
| 286 | mHeight = h; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 287 | mFlingerSurfaceControl = control; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | mFlingerSurface = s; |
| 289 | |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 290 | // If the device has encryption turned on or is in process |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 291 | // of being encrypted we show the encrypted boot animation. |
| 292 | char decrypt[PROPERTY_VALUE_MAX]; |
| 293 | property_get("vold.decrypt", decrypt, ""); |
| 294 | |
| 295 | bool encryptedAnimation = atoi(decrypt) != 0 || !strcmp("trigger_restart_min_framework", decrypt); |
| 296 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 297 | if (encryptedAnimation && (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0)) { |
| 298 | mZipFileName = SYSTEM_ENCRYPTED_BOOTANIMATION_FILE; |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 299 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 300 | else if (access(OEM_BOOTANIMATION_FILE, R_OK) == 0) { |
| 301 | mZipFileName = OEM_BOOTANIMATION_FILE; |
| 302 | } |
| 303 | else if (access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) { |
| 304 | mZipFileName = SYSTEM_BOOTANIMATION_FILE; |
| 305 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | return NO_ERROR; |
| 307 | } |
| 308 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 309 | bool BootAnimation::threadLoop() |
| 310 | { |
| 311 | bool r; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 312 | // We have no bootanimation file, so we use the stock android logo |
| 313 | // animation. |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 314 | if (mZipFileName.isEmpty()) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 315 | r = android(); |
| 316 | } else { |
| 317 | r = movie(); |
| 318 | } |
| 319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 321 | eglDestroyContext(mDisplay, mContext); |
| 322 | eglDestroySurface(mDisplay, mSurface); |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 323 | mFlingerSurface.clear(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 324 | mFlingerSurfaceControl.clear(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 325 | eglTerminate(mDisplay); |
| 326 | IPCThreadState::self()->stopProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | return r; |
| 328 | } |
| 329 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 330 | bool BootAnimation::android() |
| 331 | { |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 332 | initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); |
| 333 | initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | |
| 335 | // clear screen |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 336 | glShadeModel(GL_FLAT); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 337 | glDisable(GL_DITHER); |
| 338 | glDisable(GL_SCISSOR_TEST); |
Mathias Agopian | 59f19e4 | 2011-05-06 19:22:12 -0700 | [diff] [blame] | 339 | glClearColor(0,0,0,1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | glClear(GL_COLOR_BUFFER_BIT); |
| 341 | eglSwapBuffers(mDisplay, mSurface); |
| 342 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 343 | glEnable(GL_TEXTURE_2D); |
| 344 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 345 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 346 | const GLint xc = (mWidth - mAndroid[0].w) / 2; |
| 347 | const GLint yc = (mHeight - mAndroid[0].h) / 2; |
| 348 | 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] | 349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(), |
| 351 | updateRect.height()); |
| 352 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 353 | // Blend state |
| 354 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 355 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | const nsecs_t startTime = systemTime(); |
| 358 | do { |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 359 | nsecs_t now = systemTime(); |
| 360 | double time = now - startTime; |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 361 | float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w; |
| 362 | GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w; |
| 363 | GLint x = xc - offset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | |
Mathias Agopian | 8166864 | 2009-07-28 11:41:30 -0700 | [diff] [blame] | 365 | glDisable(GL_SCISSOR_TEST); |
| 366 | glClear(GL_COLOR_BUFFER_BIT); |
| 367 | |
| 368 | glEnable(GL_SCISSOR_TEST); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | glDisable(GL_BLEND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | glBindTexture(GL_TEXTURE_2D, mAndroid[1].name); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 371 | glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h); |
| 372 | 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] | 373 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 374 | glEnable(GL_BLEND); |
| 375 | glBindTexture(GL_TEXTURE_2D, mAndroid[0].name); |
| 376 | 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] | 377 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 378 | EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); |
| 379 | if (res == EGL_FALSE) |
| 380 | break; |
| 381 | |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 382 | // 12fps: don't animate too fast to preserve CPU |
| 383 | const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); |
| 384 | if (sleepTime > 0) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 385 | usleep(sleepTime); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 386 | |
| 387 | checkExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | } while (!exitPending()); |
| 389 | |
| 390 | glDeleteTextures(1, &mAndroid[0].name); |
| 391 | glDeleteTextures(1, &mAndroid[1].name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | return false; |
| 393 | } |
| 394 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 395 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 396 | void BootAnimation::checkExit() { |
| 397 | // Allow surface flinger to gracefully request shutdown |
| 398 | char value[PROPERTY_VALUE_MAX]; |
| 399 | property_get(EXIT_PROP_NAME, value, "0"); |
| 400 | int exitnow = atoi(value); |
| 401 | if (exitnow) { |
| 402 | requestExit(); |
| 403 | } |
| 404 | } |
| 405 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 406 | // Parse a color represented as an HTML-style 'RRGGBB' string: each pair of |
| 407 | // characters in str is a hex number in [0, 255], which are converted to |
| 408 | // floating point values in the range [0.0, 1.0] and placed in the |
| 409 | // corresponding elements of color. |
| 410 | // |
| 411 | // If the input string isn't valid, parseColor returns false and color is |
| 412 | // left unchanged. |
| 413 | static bool parseColor(const char str[7], float color[3]) { |
| 414 | float tmpColor[3]; |
| 415 | for (int i = 0; i < 3; i++) { |
| 416 | int val = 0; |
| 417 | for (int j = 0; j < 2; j++) { |
| 418 | val *= 16; |
| 419 | char c = str[2*i + j]; |
| 420 | if (c >= '0' && c <= '9') val += c - '0'; |
| 421 | else if (c >= 'A' && c <= 'F') val += (c - 'A') + 10; |
| 422 | else if (c >= 'a' && c <= 'f') val += (c - 'a') + 10; |
| 423 | else return false; |
| 424 | } |
| 425 | tmpColor[i] = static_cast<float>(val) / 255.0f; |
| 426 | } |
| 427 | memcpy(color, tmpColor, sizeof(tmpColor)); |
| 428 | return true; |
| 429 | } |
| 430 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 431 | |
| 432 | static bool readFile(ZipFileRO* zip, const char* name, String8& outString) |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 433 | { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 434 | ZipEntryRO entry = zip->findEntryByName(name); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 435 | ALOGE_IF(!entry, "couldn't find %s", name); |
| 436 | if (!entry) { |
| 437 | return false; |
| 438 | } |
| 439 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 440 | FileMap* entryMap = zip->createEntryFileMap(entry); |
| 441 | zip->releaseEntry(entry); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 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 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 515 | bool BootAnimation::parseAnimationDesc(Animation& animation) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 516 | { |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 517 | String8 desString; |
| 518 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 519 | if (!readFile(animation.zip, "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 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 524 | // Parse the description file |
| 525 | for (;;) { |
| 526 | const char* endl = strstr(s, "\n"); |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 527 | if (endl == NULL) break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 528 | String8 line(s, endl - s); |
| 529 | const char* l = line.string(); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 530 | int fps = 0; |
| 531 | int width = 0; |
| 532 | int height = 0; |
| 533 | int count = 0; |
| 534 | int pause = 0; |
| 535 | int clockPosY = -1; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 536 | char path[ANIM_ENTRY_NAME_MAX]; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 537 | char color[7] = "000000"; // default to black if unspecified |
| 538 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 539 | char pathType; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 540 | if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) { |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 541 | // ALOGD("> w=%d, h=%d, fps=%d", width, height, fps); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 542 | animation.width = width; |
| 543 | animation.height = height; |
| 544 | animation.fps = fps; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 545 | } else if (sscanf(l, " %c %d %d %s #%6s %d", |
| 546 | &pathType, &count, &pause, path, color, &clockPosY) >= 4) { |
| 547 | // 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] | 548 | Animation::Part part; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 549 | part.playUntilComplete = pathType == 'c'; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 550 | part.count = count; |
| 551 | part.pause = pause; |
| 552 | part.path = path; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 553 | part.clockPosY = clockPosY; |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 554 | part.audioData = NULL; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 555 | part.animation = NULL; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 556 | if (!parseColor(color, part.backgroundColor)) { |
| 557 | ALOGE("> invalid color '#%s'", color); |
| 558 | part.backgroundColor[0] = 0.0f; |
| 559 | part.backgroundColor[1] = 0.0f; |
| 560 | part.backgroundColor[2] = 0.0f; |
| 561 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 562 | animation.parts.add(part); |
| 563 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 564 | else if (strcmp(l, "$SYSTEM") == 0) { |
| 565 | // ALOGD("> SYSTEM"); |
| 566 | Animation::Part part; |
| 567 | part.playUntilComplete = false; |
| 568 | part.count = 1; |
| 569 | part.pause = 0; |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 570 | part.audioData = NULL; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 571 | part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE)); |
| 572 | if (part.animation != NULL) |
| 573 | animation.parts.add(part); |
| 574 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 575 | s = ++endl; |
| 576 | } |
| 577 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 578 | return true; |
| 579 | } |
| 580 | |
| 581 | bool BootAnimation::preloadZip(Animation& animation) |
| 582 | { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 583 | // read all the data structures |
| 584 | const size_t pcount = animation.parts.size(); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 585 | void *cookie = NULL; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 586 | ZipFileRO* zip = animation.zip; |
| 587 | if (!zip->startIteration(&cookie)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 588 | return false; |
| 589 | } |
| 590 | |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 591 | Animation::Part* partWithAudio = NULL; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 592 | ZipEntryRO entry; |
| 593 | char name[ANIM_ENTRY_NAME_MAX]; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 594 | while ((entry = zip->nextEntry(cookie)) != NULL) { |
| 595 | const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 596 | if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) { |
| 597 | ALOGE("Error fetching entry file name"); |
| 598 | continue; |
| 599 | } |
| 600 | |
| 601 | const String8 entryName(name); |
| 602 | const String8 path(entryName.getPathDir()); |
| 603 | const String8 leaf(entryName.getPathLeaf()); |
| 604 | if (leaf.size() > 0) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 605 | for (size_t j = 0; j < pcount; j++) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 606 | if (path == animation.parts[j].path) { |
Narayan Kamath | 4600dd0 | 2015-06-16 12:02:57 +0100 | [diff] [blame] | 607 | uint16_t method; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 608 | // supports only stored png files |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 609 | if (zip->getEntryInfo(entry, &method, NULL, NULL, NULL, NULL, NULL)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 610 | if (method == ZipFileRO::kCompressStored) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 611 | FileMap* map = zip->createEntryFileMap(entry); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 612 | if (map) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 613 | Animation::Part& part(animation.parts.editItemAt(j)); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 614 | if (leaf == "audio.wav") { |
| 615 | // a part may have at most one audio file |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 616 | part.audioData = (uint8_t *)map->getDataPtr(); |
| 617 | part.audioLength = map->getDataLength(); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 618 | partWithAudio = ∂ |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 619 | } else if (leaf == "trim.txt") { |
| 620 | part.trimData.setTo((char const*)map->getDataPtr(), |
| 621 | map->getDataLength()); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 622 | } else { |
| 623 | Animation::Frame frame; |
| 624 | frame.name = leaf; |
| 625 | frame.map = map; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 626 | frame.trimWidth = animation.width; |
| 627 | frame.trimHeight = animation.height; |
| 628 | frame.trimX = 0; |
| 629 | frame.trimY = 0; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 630 | part.frames.add(frame); |
| 631 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 632 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 633 | } else { |
| 634 | ALOGE("bootanimation.zip is compressed; must be only stored"); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 642 | // If there is trimData present, override the positioning defaults. |
| 643 | for (Animation::Part& part : animation.parts) { |
| 644 | const char* trimDataStr = part.trimData.string(); |
| 645 | for (size_t frameIdx = 0; frameIdx < part.frames.size(); frameIdx++) { |
| 646 | const char* endl = strstr(trimDataStr, "\n"); |
| 647 | // No more trimData for this part. |
| 648 | if (endl == NULL) { |
| 649 | break; |
| 650 | } |
| 651 | String8 line(trimDataStr, endl - trimDataStr); |
| 652 | const char* lineStr = line.string(); |
| 653 | trimDataStr = ++endl; |
| 654 | int width = 0, height = 0, x = 0, y = 0; |
| 655 | if (sscanf(lineStr, "%dx%d+%d+%d", &width, &height, &x, &y) == 4) { |
| 656 | Animation::Frame& frame(part.frames.editItemAt(frameIdx)); |
| 657 | frame.trimWidth = width; |
| 658 | frame.trimHeight = height; |
| 659 | frame.trimX = x; |
| 660 | frame.trimY = y; |
| 661 | } else { |
| 662 | ALOGE("Error parsing trim.txt, line: %s", lineStr); |
| 663 | break; |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 668 | // Create and initialize audioplay if there is a wav file in any of the animations. |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 669 | if (partWithAudio != NULL) { |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 670 | ALOGD("found audio.wav, creating playback engine"); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 671 | if (!audioplay::create(partWithAudio->audioData, partWithAudio->audioLength)) { |
| 672 | return false; |
| 673 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 676 | zip->endIteration(cookie); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 677 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 678 | return true; |
| 679 | } |
| 680 | |
| 681 | bool BootAnimation::movie() |
| 682 | { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 683 | Animation* animation = loadAnimation(mZipFileName); |
| 684 | if (animation == NULL) |
| 685 | return false; |
| 686 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 687 | bool anyPartHasClock = false; |
| 688 | for (size_t i=0; i < animation->parts.size(); i++) { |
| 689 | if(animation->parts[i].clockPosY >= 0) { |
| 690 | anyPartHasClock = true; |
| 691 | break; |
| 692 | } |
| 693 | } |
| 694 | if (!anyPartHasClock) { |
| 695 | mClockEnabled = false; |
| 696 | } |
| 697 | |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 698 | // Check if npot textures are supported |
| 699 | mUseNpotTextures = false; |
| 700 | String8 gl_extensions; |
| 701 | const char* exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
| 702 | if (!exts) { |
| 703 | glGetError(); |
| 704 | } else { |
| 705 | gl_extensions.setTo(exts); |
| 706 | if ((gl_extensions.find("GL_ARB_texture_non_power_of_two") != -1) || |
| 707 | (gl_extensions.find("GL_OES_texture_npot") != -1)) { |
| 708 | mUseNpotTextures = true; |
| 709 | } |
| 710 | } |
| 711 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 712 | // Blend required to draw time on top of animation frames. |
| 713 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 714 | glShadeModel(GL_FLAT); |
| 715 | glDisable(GL_DITHER); |
| 716 | glDisable(GL_SCISSOR_TEST); |
| 717 | glDisable(GL_BLEND); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 718 | |
| 719 | glBindTexture(GL_TEXTURE_2D, 0); |
| 720 | glEnable(GL_TEXTURE_2D); |
| 721 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 722 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 723 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 724 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 725 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 726 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 727 | bool clockTextureInitialized = false; |
| 728 | if (mClockEnabled) { |
| 729 | clockTextureInitialized = (initTexture(&mClock, mAssets, "images/clock64.png") == NO_ERROR); |
| 730 | mClockEnabled = clockTextureInitialized; |
| 731 | } |
| 732 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 733 | if (mClockEnabled && !updateIsTimeAccurate()) { |
| 734 | mTimeCheckThread = new TimeCheckThread(this); |
| 735 | mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL); |
| 736 | } |
| 737 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 738 | playAnimation(*animation); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 739 | |
| 740 | if (mTimeCheckThread != NULL) { |
| 741 | mTimeCheckThread->requestExit(); |
| 742 | mTimeCheckThread = NULL; |
| 743 | } |
| 744 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 745 | releaseAnimation(animation); |
| 746 | |
Andriy Naborskyy | 815e51d | 2016-03-24 16:43:34 -0700 | [diff] [blame] | 747 | if (clockTextureInitialized) { |
| 748 | glDeleteTextures(1, &mClock.name); |
| 749 | } |
| 750 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 751 | return false; |
| 752 | } |
| 753 | |
| 754 | bool BootAnimation::playAnimation(const Animation& animation) |
| 755 | { |
| 756 | const size_t pcount = animation.parts.size(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 757 | nsecs_t frameDuration = s2ns(1) / animation.fps; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 758 | const int animationX = (mWidth - animation.width) / 2; |
| 759 | const int animationY = (mHeight - animation.height) / 2; |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 760 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 761 | for (size_t i=0 ; i<pcount ; i++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 762 | const Animation::Part& part(animation.parts[i]); |
| 763 | const size_t fcount = part.frames.size(); |
| 764 | glBindTexture(GL_TEXTURE_2D, 0); |
| 765 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 766 | // Handle animation package |
| 767 | if (part.animation != NULL) { |
| 768 | playAnimation(*part.animation); |
| 769 | if (exitPending()) |
| 770 | break; |
| 771 | continue; //to next part |
| 772 | } |
| 773 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 774 | for (int r=0 ; !part.count || r<part.count ; r++) { |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 775 | // Exit any non playuntil complete parts immediately |
| 776 | if(exitPending() && !part.playUntilComplete) |
| 777 | break; |
| 778 | |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 779 | // only play audio file the first time we animate the part |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 780 | if (r == 0 && part.audioData) { |
| 781 | ALOGD("playing clip for part%d, size=%d", (int) i, part.audioLength); |
| 782 | audioplay::playClip(part.audioData, part.audioLength); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 785 | glClearColor( |
| 786 | part.backgroundColor[0], |
| 787 | part.backgroundColor[1], |
| 788 | part.backgroundColor[2], |
| 789 | 1.0f); |
| 790 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 791 | for (size_t j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 792 | const Animation::Frame& frame(part.frames[j]); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 793 | nsecs_t lastFrame = systemTime(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 794 | |
| 795 | if (r > 0) { |
| 796 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 797 | } else { |
| 798 | if (part.count != 1) { |
| 799 | glGenTextures(1, &frame.tid); |
| 800 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 801 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 802 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 803 | } |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 804 | initTexture(frame); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 807 | const int xc = animationX + frame.trimX; |
| 808 | const int yc = animationY + frame.trimY; |
| 809 | Region clearReg(Rect(mWidth, mHeight)); |
| 810 | clearReg.subtractSelf(Rect(xc, yc, xc+frame.trimWidth, yc+frame.trimHeight)); |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 811 | if (!clearReg.isEmpty()) { |
| 812 | Region::const_iterator head(clearReg.begin()); |
| 813 | Region::const_iterator tail(clearReg.end()); |
| 814 | glEnable(GL_SCISSOR_TEST); |
| 815 | while (head != tail) { |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 816 | const Rect& r2(*head++); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 817 | glScissor(r2.left, mHeight - r2.bottom, r2.width(), r2.height()); |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 818 | glClear(GL_COLOR_BUFFER_BIT); |
| 819 | } |
| 820 | glDisable(GL_SCISSOR_TEST); |
| 821 | } |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 822 | // specify the y center as ceiling((mHeight - frame.trimHeight) / 2) |
| 823 | // which is equivalent to mHeight - (yc + frame.trimHeight) |
| 824 | glDrawTexiOES(xc, mHeight - (yc + frame.trimHeight), |
| 825 | 0, frame.trimWidth, frame.trimHeight); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 826 | if (mClockEnabled && mTimeIsAccurate && part.clockPosY >= 0) { |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 827 | drawTime(mClock, part.clockPosY); |
| 828 | } |
| 829 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 830 | eglSwapBuffers(mDisplay, mSurface); |
| 831 | |
| 832 | nsecs_t now = systemTime(); |
| 833 | nsecs_t delay = frameDuration - (now - lastFrame); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 834 | //ALOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay)); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 835 | lastFrame = now; |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 836 | |
| 837 | if (delay > 0) { |
| 838 | struct timespec spec; |
| 839 | spec.tv_sec = (now + delay) / 1000000000; |
| 840 | spec.tv_nsec = (now + delay) % 1000000000; |
| 841 | int err; |
| 842 | do { |
| 843 | err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL); |
| 844 | } while (err<0 && errno == EINTR); |
| 845 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 846 | |
| 847 | checkExit(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 848 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 849 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 850 | usleep(part.pause * ns2us(frameDuration)); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 851 | |
| 852 | // For infinite parts, we've now played them at least once, so perhaps exit |
| 853 | if(exitPending() && !part.count) |
| 854 | break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | // Free textures created for looping parts now that the animation is done. |
| 860 | for (const Animation::Part& part : animation.parts) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 861 | if (part.count != 1) { |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 862 | const size_t fcount = part.frames.size(); |
| 863 | for (size_t j = 0; j < fcount; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 864 | const Animation::Frame& frame(part.frames[j]); |
| 865 | glDeleteTextures(1, &frame.tid); |
| 866 | } |
| 867 | } |
| 868 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 869 | |
| 870 | // we've finally played everything we're going to play |
| 871 | audioplay::setPlaying(false); |
| 872 | audioplay::destroy(); |
| 873 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 874 | return true; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 877 | void BootAnimation::releaseAnimation(Animation* animation) const |
| 878 | { |
| 879 | for (Vector<Animation::Part>::iterator it = animation->parts.begin(), |
| 880 | e = animation->parts.end(); it != e; ++it) { |
| 881 | if (it->animation) |
| 882 | releaseAnimation(it->animation); |
| 883 | } |
| 884 | if (animation->zip) |
| 885 | delete animation->zip; |
| 886 | delete animation; |
| 887 | } |
| 888 | |
| 889 | BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn) |
| 890 | { |
| 891 | if (mLoadedFiles.indexOf(fn) >= 0) { |
| 892 | ALOGE("File \"%s\" is already loaded. Cyclic ref is not allowed", |
| 893 | fn.string()); |
| 894 | return NULL; |
| 895 | } |
| 896 | ZipFileRO *zip = ZipFileRO::open(fn); |
| 897 | if (zip == NULL) { |
| 898 | ALOGE("Failed to open animation zip \"%s\": %s", |
| 899 | fn.string(), strerror(errno)); |
| 900 | return NULL; |
| 901 | } |
| 902 | |
| 903 | Animation *animation = new Animation; |
| 904 | animation->fileName = fn; |
| 905 | animation->zip = zip; |
| 906 | mLoadedFiles.add(animation->fileName); |
| 907 | |
| 908 | parseAnimationDesc(*animation); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 909 | if (!preloadZip(*animation)) { |
| 910 | return NULL; |
| 911 | } |
| 912 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 913 | |
| 914 | mLoadedFiles.remove(fn); |
| 915 | return animation; |
| 916 | } |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 917 | |
| 918 | bool BootAnimation::updateIsTimeAccurate() { |
| 919 | static constexpr long long MAX_TIME_IN_PAST = 60000LL * 60LL * 24LL * 30LL; // 30 days |
| 920 | static constexpr long long MAX_TIME_IN_FUTURE = 60000LL * 90LL; // 90 minutes |
| 921 | |
| 922 | if (mTimeIsAccurate) { |
| 923 | return true; |
| 924 | } |
| 925 | |
| 926 | struct stat statResult; |
| 927 | if(stat(ACCURATE_TIME_FLAG_FILE_PATH, &statResult) == 0) { |
| 928 | mTimeIsAccurate = true; |
| 929 | return true; |
| 930 | } |
| 931 | |
| 932 | FILE* file = fopen(LAST_TIME_CHANGED_FILE_PATH, "r"); |
| 933 | if (file != NULL) { |
| 934 | long long lastChangedTime = 0; |
| 935 | fscanf(file, "%lld", &lastChangedTime); |
| 936 | fclose(file); |
| 937 | if (lastChangedTime > 0) { |
| 938 | struct timespec now; |
| 939 | clock_gettime(CLOCK_REALTIME, &now); |
| 940 | // Match the Java timestamp format |
| 941 | long long rtcNow = (now.tv_sec * 1000LL) + (now.tv_nsec / 1000000LL); |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 942 | if (ACCURATE_TIME_EPOCH < rtcNow |
| 943 | && lastChangedTime > (rtcNow - MAX_TIME_IN_PAST) |
| 944 | && lastChangedTime < (rtcNow + MAX_TIME_IN_FUTURE)) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 945 | mTimeIsAccurate = true; |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | return mTimeIsAccurate; |
| 951 | } |
| 952 | |
| 953 | BootAnimation::TimeCheckThread::TimeCheckThread(BootAnimation* bootAnimation) : Thread(false), |
| 954 | mInotifyFd(-1), mSystemWd(-1), mTimeWd(-1), mBootAnimation(bootAnimation) {} |
| 955 | |
| 956 | BootAnimation::TimeCheckThread::~TimeCheckThread() { |
| 957 | // mInotifyFd may be -1 but that's ok since we're not at risk of attempting to close a valid FD. |
| 958 | close(mInotifyFd); |
| 959 | } |
| 960 | |
| 961 | bool BootAnimation::TimeCheckThread::threadLoop() { |
| 962 | bool shouldLoop = doThreadLoop() && !mBootAnimation->mTimeIsAccurate |
| 963 | && mBootAnimation->mClockEnabled; |
| 964 | if (!shouldLoop) { |
| 965 | close(mInotifyFd); |
| 966 | mInotifyFd = -1; |
| 967 | } |
| 968 | return shouldLoop; |
| 969 | } |
| 970 | |
| 971 | bool BootAnimation::TimeCheckThread::doThreadLoop() { |
| 972 | static constexpr int BUFF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1)); |
| 973 | |
| 974 | // Poll instead of doing a blocking read so the Thread can exit if requested. |
| 975 | struct pollfd pfd = { mInotifyFd, POLLIN, 0 }; |
| 976 | ssize_t pollResult = poll(&pfd, 1, 1000); |
| 977 | |
| 978 | if (pollResult == 0) { |
| 979 | return true; |
| 980 | } else if (pollResult < 0) { |
| 981 | ALOGE("Could not poll inotify events"); |
| 982 | return false; |
| 983 | } |
| 984 | |
| 985 | char buff[BUFF_LEN] __attribute__ ((aligned(__alignof__(struct inotify_event))));; |
| 986 | ssize_t length = read(mInotifyFd, buff, BUFF_LEN); |
| 987 | if (length == 0) { |
| 988 | return true; |
| 989 | } else if (length < 0) { |
| 990 | ALOGE("Could not read inotify events"); |
| 991 | return false; |
| 992 | } |
| 993 | |
| 994 | const struct inotify_event *event; |
| 995 | for (char* ptr = buff; ptr < buff + length; ptr += sizeof(struct inotify_event) + event->len) { |
| 996 | event = (const struct inotify_event *) ptr; |
| 997 | if (event->wd == mSystemWd && strcmp(SYSTEM_TIME_DIR_NAME, event->name) == 0) { |
| 998 | addTimeDirWatch(); |
| 999 | } else if (event->wd == mTimeWd && (strcmp(LAST_TIME_CHANGED_FILE_NAME, event->name) == 0 |
| 1000 | || strcmp(ACCURATE_TIME_FLAG_FILE_NAME, event->name) == 0)) { |
| 1001 | return !mBootAnimation->updateIsTimeAccurate(); |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | return true; |
| 1006 | } |
| 1007 | |
| 1008 | void BootAnimation::TimeCheckThread::addTimeDirWatch() { |
| 1009 | mTimeWd = inotify_add_watch(mInotifyFd, SYSTEM_TIME_DIR_PATH, |
| 1010 | IN_CLOSE_WRITE | IN_MOVED_TO | IN_ATTRIB); |
| 1011 | if (mTimeWd > 0) { |
| 1012 | // No need to watch for the time directory to be created if it already exists |
| 1013 | inotify_rm_watch(mInotifyFd, mSystemWd); |
| 1014 | mSystemWd = -1; |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | status_t BootAnimation::TimeCheckThread::readyToRun() { |
| 1019 | mInotifyFd = inotify_init(); |
| 1020 | if (mInotifyFd < 0) { |
| 1021 | ALOGE("Could not initialize inotify fd"); |
| 1022 | return NO_INIT; |
| 1023 | } |
| 1024 | |
| 1025 | mSystemWd = inotify_add_watch(mInotifyFd, SYSTEM_DATA_DIR_PATH, IN_CREATE | IN_ATTRIB); |
| 1026 | if (mSystemWd < 0) { |
| 1027 | close(mInotifyFd); |
| 1028 | mInotifyFd = -1; |
| 1029 | ALOGE("Could not add watch for %s", SYSTEM_DATA_DIR_PATH); |
| 1030 | return NO_INIT; |
| 1031 | } |
| 1032 | |
| 1033 | addTimeDirWatch(); |
| 1034 | |
| 1035 | if (mBootAnimation->updateIsTimeAccurate()) { |
| 1036 | close(mInotifyFd); |
| 1037 | mInotifyFd = -1; |
| 1038 | return ALREADY_EXISTS; |
| 1039 | } |
| 1040 | |
| 1041 | return NO_ERROR; |
| 1042 | } |
| 1043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | // --------------------------------------------------------------------------- |
| 1045 | |
| 1046 | } |
| 1047 | ; // namespace android |