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> |
Wei Wang | a90c54c | 2017-02-02 11:35:21 -0800 | [diff] [blame] | 21 | #include <inttypes.h> |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 22 | #include <sys/inotify.h> |
| 23 | #include <sys/poll.h> |
| 24 | #include <sys/stat.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | #include <math.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <utils/misc.h> |
Mathias Agopian | b4d5a72 | 2009-09-23 17:05:19 -0700 | [diff] [blame] | 29 | #include <signal.h> |
Elliott Hughes | bb94f31 | 2014-10-21 10:41:33 -0700 | [diff] [blame] | 30 | #include <time.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
Steven Moreland | fb7952f | 2018-02-23 14:58:50 -0800 | [diff] [blame] | 32 | #include <cutils/atomic.h> |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 33 | #include <cutils/properties.h> |
| 34 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 35 | #include <androidfw/AssetManager.h> |
Mathias Agopian | ac31a3b | 2009-05-21 19:59:24 -0700 | [diff] [blame] | 36 | #include <binder/IPCThreadState.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | #include <utils/Errors.h> |
| 38 | #include <utils/Log.h> |
Wei Wang | a90c54c | 2017-02-02 11:35:21 -0800 | [diff] [blame] | 39 | #include <utils/SystemClock.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 41 | #include <android-base/properties.h> |
| 42 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | #include <ui/PixelFormat.h> |
| 44 | #include <ui/Rect.h> |
| 45 | #include <ui/Region.h> |
| 46 | #include <ui/DisplayInfo.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 48 | #include <gui/ISurfaceComposer.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 49 | #include <gui/Surface.h> |
| 50 | #include <gui/SurfaceComposerClient.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 51 | |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 52 | // TODO: Fix Skia. |
| 53 | #pragma GCC diagnostic push |
| 54 | #pragma GCC diagnostic ignored "-Wunused-parameter" |
Derek Sollenberger | eece0dd | 2014-02-27 14:31:29 -0500 | [diff] [blame] | 55 | #include <SkBitmap.h> |
Matt Sarett | 8898c16 | 2016-03-24 16:11:01 -0400 | [diff] [blame] | 56 | #include <SkImage.h> |
Derek Sollenberger | eece0dd | 2014-02-27 14:31:29 -0500 | [diff] [blame] | 57 | #include <SkStream.h> |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 58 | #pragma GCC diagnostic pop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
| 60 | #include <GLES/gl.h> |
| 61 | #include <GLES/glext.h> |
| 62 | #include <EGL/eglext.h> |
| 63 | |
| 64 | #include "BootAnimation.h" |
| 65 | |
Kyeongkab.Nam | 35a8a11 | 2019-07-17 16:41:48 +0900 | [diff] [blame] | 66 | #define ANIM_PATH_MAX 255 |
| 67 | #define STR(x) #x |
| 68 | #define STRTO(x) STR(x) |
| 69 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | namespace android { |
| 71 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 72 | static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip"; |
Beverly | 34ffe25 | 2019-05-17 11:03:54 -0400 | [diff] [blame] | 73 | static const char PRODUCT_BOOTANIMATION_DARK_FILE[] = "/product/media/bootanimation-dark.zip"; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 74 | static const char PRODUCT_BOOTANIMATION_FILE[] = "/product/media/bootanimation.zip"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 75 | static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip"; |
Anders Fridlund | e0b4d23 | 2018-11-06 14:23:25 +0100 | [diff] [blame] | 76 | static const char APEX_BOOTANIMATION_FILE[] = "/apex/com.android.bootanimation/etc/bootanimation.zip"; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 77 | static const char PRODUCT_ENCRYPTED_BOOTANIMATION_FILE[] = "/product/media/bootanimation-encrypted.zip"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 78 | static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip"; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 79 | static const char OEM_SHUTDOWNANIMATION_FILE[] = "/oem/media/shutdownanimation.zip"; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 80 | static const char PRODUCT_SHUTDOWNANIMATION_FILE[] = "/product/media/shutdownanimation.zip"; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 81 | static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip"; |
| 82 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 83 | static const char SYSTEM_DATA_DIR_PATH[] = "/data/system"; |
| 84 | static const char SYSTEM_TIME_DIR_NAME[] = "time"; |
| 85 | static const char SYSTEM_TIME_DIR_PATH[] = "/data/system/time"; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 86 | static const char CLOCK_FONT_ASSET[] = "images/clock_font.png"; |
| 87 | static const char CLOCK_FONT_ZIP_NAME[] = "clock_font.png"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 88 | static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change"; |
| 89 | static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/system/time/last_time_change"; |
| 90 | static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate"; |
| 91 | static const char ACCURATE_TIME_FLAG_FILE_PATH[] = "/data/system/time/time_is_accurate"; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 92 | static const char TIME_FORMAT_12_HOUR_FLAG_FILE_PATH[] = "/data/system/time/time_format_12_hour"; |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 93 | // Java timestamp format. Don't show the clock if the date is before 2000-01-01 00:00:00. |
| 94 | static const long long ACCURATE_TIME_EPOCH = 946684800000; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 95 | static constexpr char FONT_BEGIN_CHAR = ' '; |
| 96 | static constexpr char FONT_END_CHAR = '~' + 1; |
| 97 | static constexpr size_t FONT_NUM_CHARS = FONT_END_CHAR - FONT_BEGIN_CHAR + 1; |
| 98 | static constexpr size_t FONT_NUM_COLS = 16; |
| 99 | static constexpr size_t FONT_NUM_ROWS = FONT_NUM_CHARS / FONT_NUM_COLS; |
| 100 | static const int TEXT_CENTER_VALUE = INT_MAX; |
| 101 | static const int TEXT_MISSING_VALUE = INT_MIN; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 102 | static const char EXIT_PROP_NAME[] = "service.bootanim.exit"; |
Kyeongkab.Nam | 35a8a11 | 2019-07-17 16:41:48 +0900 | [diff] [blame] | 103 | static const int ANIM_ENTRY_NAME_MAX = ANIM_PATH_MAX + 1; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 104 | static constexpr size_t TEXT_POS_LEN_MAX = 16; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | // --------------------------------------------------------------------------- |
| 107 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 108 | BootAnimation::BootAnimation(sp<Callbacks> callbacks) |
Ed Coyne | 2c9e94a | 2017-05-31 10:08:28 -0700 | [diff] [blame] | 109 | : Thread(false), mClockEnabled(true), mTimeIsAccurate(false), |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 110 | mTimeFormat12Hour(false), mTimeCheckThread(nullptr), mCallbacks(callbacks) { |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 111 | mSession = new SurfaceComposerClient(); |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 112 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 113 | std::string powerCtl = android::base::GetProperty("sys.powerctl", ""); |
| 114 | if (powerCtl.empty()) { |
| 115 | mShuttingDown = false; |
| 116 | } else { |
| 117 | mShuttingDown = true; |
| 118 | } |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 119 | ALOGD("%sAnimationStartTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
| 120 | elapsedRealtime()); |
| 121 | } |
| 122 | |
| 123 | BootAnimation::~BootAnimation() { |
| 124 | if (mAnimation != nullptr) { |
| 125 | releaseAnimation(mAnimation); |
| 126 | mAnimation = nullptr; |
| 127 | } |
| 128 | ALOGD("%sAnimationStopTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
| 129 | elapsedRealtime()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | } |
| 131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | void BootAnimation::onFirstRef() { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 133 | status_t err = mSession->linkToComposerDeath(this); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 134 | SLOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err)); |
Mathias Agopian | 8434c53 | 2009-09-23 18:52:49 -0700 | [diff] [blame] | 135 | if (err == NO_ERROR) { |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 136 | // Load the animation content -- this can be slow (eg 200ms) |
| 137 | // called before waitForSurfaceFlinger() in main() to avoid wait |
| 138 | ALOGD("%sAnimationPreloadTiming start time: %" PRId64 "ms", |
| 139 | mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime()); |
| 140 | preloadAnimation(); |
| 141 | ALOGD("%sAnimationPreloadStopTiming start time: %" PRId64 "ms", |
| 142 | mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime()); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 143 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 146 | sp<SurfaceComposerClient> BootAnimation::session() const { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | return mSession; |
| 148 | } |
| 149 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 150 | void BootAnimation::binderDied(const wp<IBinder>&) |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 151 | { |
| 152 | // woah, surfaceflinger died! |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 153 | SLOGD("SurfaceFlinger died, exiting..."); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 154 | |
| 155 | // calling requestExit() is not enough here because the Surface code |
| 156 | // might be blocked on a condition variable that will never be updated. |
| 157 | kill( getpid(), SIGKILL ); |
| 158 | requestExit(); |
| 159 | } |
| 160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, |
| 162 | const char* name) { |
| 163 | Asset* asset = assets.open(name, Asset::ACCESS_BUFFER); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 164 | if (asset == nullptr) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | return NO_INIT; |
| 166 | SkBitmap bitmap; |
Matt Sarett | 8898c16 | 2016-03-24 16:11:01 -0400 | [diff] [blame] | 167 | sk_sp<SkData> data = SkData::MakeWithoutCopy(asset->getBuffer(false), |
| 168 | asset->getLength()); |
| 169 | sk_sp<SkImage> image = SkImage::MakeFromEncoded(data); |
| 170 | image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | asset->close(); |
| 172 | delete asset; |
| 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | const int w = bitmap.width(); |
| 175 | const int h = bitmap.height(); |
| 176 | const void* p = bitmap.getPixels(); |
| 177 | |
| 178 | GLint crop[4] = { 0, h, w, -h }; |
| 179 | texture->w = w; |
| 180 | texture->h = h; |
| 181 | |
| 182 | glGenTextures(1, &texture->name); |
| 183 | glBindTexture(GL_TEXTURE_2D, texture->name); |
| 184 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 185 | switch (bitmap.colorType()) { |
| 186 | case kAlpha_8_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, |
| 188 | GL_UNSIGNED_BYTE, p); |
| 189 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 190 | case kARGB_4444_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 192 | GL_UNSIGNED_SHORT_4_4_4_4, p); |
| 193 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 194 | case kN32_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 196 | GL_UNSIGNED_BYTE, p); |
| 197 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 198 | case kRGB_565_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
| 200 | GL_UNSIGNED_SHORT_5_6_5, p); |
| 201 | break; |
| 202 | default: |
| 203 | break; |
| 204 | } |
| 205 | |
| 206 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 207 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 208 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 209 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 210 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | return NO_ERROR; |
| 213 | } |
| 214 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 215 | status_t BootAnimation::initTexture(FileMap* map, int* width, int* height) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 216 | { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 217 | SkBitmap bitmap; |
Damien Bargiacchi | f67b317 | 2016-09-07 20:17:14 -0700 | [diff] [blame] | 218 | sk_sp<SkData> data = SkData::MakeWithoutCopy(map->getDataPtr(), |
| 219 | map->getDataLength()); |
Matt Sarett | 8898c16 | 2016-03-24 16:11:01 -0400 | [diff] [blame] | 220 | sk_sp<SkImage> image = SkImage::MakeFromEncoded(data); |
| 221 | image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 222 | |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 223 | // FileMap memory is never released until application exit. |
| 224 | // Release it now as the texture is already loaded and the memory used for |
| 225 | // the packed resource can be released. |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 226 | delete map; |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 227 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 228 | const int w = bitmap.width(); |
| 229 | const int h = bitmap.height(); |
| 230 | const void* p = bitmap.getPixels(); |
| 231 | |
| 232 | GLint crop[4] = { 0, h, w, -h }; |
| 233 | int tw = 1 << (31 - __builtin_clz(w)); |
| 234 | int th = 1 << (31 - __builtin_clz(h)); |
| 235 | if (tw < w) tw <<= 1; |
| 236 | if (th < h) th <<= 1; |
| 237 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 238 | switch (bitmap.colorType()) { |
| 239 | case kN32_SkColorType: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 240 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 241 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 242 | GL_UNSIGNED_BYTE, nullptr); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 243 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 244 | 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p); |
| 245 | } else { |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 246 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 247 | GL_UNSIGNED_BYTE, p); |
| 248 | } |
| 249 | break; |
| 250 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 251 | case kRGB_565_SkColorType: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 252 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 253 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 254 | GL_UNSIGNED_SHORT_5_6_5, nullptr); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 255 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 256 | 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p); |
| 257 | } else { |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 258 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 259 | GL_UNSIGNED_SHORT_5_6_5, p); |
| 260 | } |
| 261 | break; |
| 262 | default: |
| 263 | break; |
| 264 | } |
| 265 | |
| 266 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 267 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 268 | *width = w; |
| 269 | *height = h; |
| 270 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 271 | return NO_ERROR; |
| 272 | } |
| 273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | status_t BootAnimation::readyToRun() { |
| 275 | mAssets.addDefaultAssets(); |
| 276 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 277 | mDisplayToken = SurfaceComposerClient::getInternalDisplayToken(); |
| 278 | if (mDisplayToken == nullptr) |
| 279 | return -1; |
| 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | DisplayInfo dinfo; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 282 | status_t status = SurfaceComposerClient::getDisplayInfo(mDisplayToken, &dinfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | if (status) |
| 284 | return -1; |
| 285 | |
| 286 | // create the native surface |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 287 | sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"), |
| 288 | dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 289 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 290 | SurfaceComposerClient::Transaction t; |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 291 | |
| 292 | // this guest property specifies multi-display IDs to show the boot animation |
| 293 | // multiple ids can be set with comma (,) as separator, for example: |
| 294 | // setprop boot.animation.displays 19260422155234049,19261083906282754 |
| 295 | Vector<uint64_t> physicalDisplayIds; |
| 296 | char displayValue[PROPERTY_VALUE_MAX] = ""; |
| 297 | property_get("boot.animation.displays", displayValue, ""); |
| 298 | bool isValid = displayValue[0] != '\0'; |
| 299 | if (isValid) { |
| 300 | char *p = displayValue; |
| 301 | while (*p) { |
| 302 | if (!isdigit(*p) && *p != ',') { |
| 303 | isValid = false; |
| 304 | break; |
| 305 | } |
| 306 | p ++; |
| 307 | } |
| 308 | if (!isValid) |
| 309 | SLOGE("Invalid syntax for the value of system prop: boot.animation.displays"); |
| 310 | } |
| 311 | if (isValid) { |
| 312 | std::istringstream stream(displayValue); |
| 313 | for (PhysicalDisplayId id; stream >> id; ) { |
| 314 | physicalDisplayIds.add(id); |
| 315 | if (stream.peek() == ',') |
| 316 | stream.ignore(); |
| 317 | } |
| 318 | |
| 319 | // In the case of multi-display, boot animation shows on the specified displays |
| 320 | // in addition to the primary display |
| 321 | auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); |
| 322 | constexpr uint32_t LAYER_STACK = 0; |
| 323 | for (auto id : physicalDisplayIds) { |
| 324 | if (std::find(ids.begin(), ids.end(), id) != ids.end()) { |
| 325 | sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(id); |
| 326 | if (token != nullptr) |
| 327 | t.setDisplayLayerStack(token, LAYER_STACK); |
| 328 | } |
| 329 | } |
| 330 | t.setLayerStack(control, LAYER_STACK); |
| 331 | } |
| 332 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 333 | t.setLayer(control, 0x40000000) |
| 334 | .apply(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 336 | sp<Surface> s = control->getSurface(); |
| 337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | // initialize opengl and egl |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 339 | const EGLint attribs[] = { |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 340 | EGL_RED_SIZE, 8, |
| 341 | EGL_GREEN_SIZE, 8, |
| 342 | EGL_BLUE_SIZE, 8, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 343 | EGL_DEPTH_SIZE, 0, |
| 344 | EGL_NONE |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 345 | }; |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 346 | EGLint w, h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | EGLint numConfigs; |
| 348 | EGLConfig config; |
| 349 | EGLSurface surface; |
| 350 | EGLContext context; |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 353 | |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 354 | eglInitialize(display, nullptr, nullptr); |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 355 | eglChooseConfig(display, attribs, &config, 1, &numConfigs); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 356 | surface = eglCreateWindowSurface(display, config, s.get(), nullptr); |
| 357 | context = eglCreateContext(display, config, nullptr, nullptr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | eglQuerySurface(display, surface, EGL_WIDTH, &w); |
| 359 | eglQuerySurface(display, surface, EGL_HEIGHT, &h); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 360 | |
Mathias Agopian | abac010 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 361 | if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) |
| 362 | return NO_INIT; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | mDisplay = display; |
| 365 | mContext = context; |
| 366 | mSurface = surface; |
| 367 | mWidth = w; |
| 368 | mHeight = h; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 369 | mFlingerSurfaceControl = control; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | mFlingerSurface = s; |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 371 | mTargetInset = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 373 | return NO_ERROR; |
| 374 | } |
| 375 | |
| 376 | bool BootAnimation::preloadAnimation() { |
| 377 | findBootAnimationFile(); |
| 378 | if (!mZipFileName.isEmpty()) { |
| 379 | mAnimation = loadAnimation(mZipFileName); |
| 380 | return (mAnimation != nullptr); |
| 381 | } |
| 382 | |
| 383 | return false; |
| 384 | } |
| 385 | |
| 386 | void BootAnimation::findBootAnimationFile() { |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 387 | // If the device has encryption turned on or is in process |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 388 | // of being encrypted we show the encrypted boot animation. |
| 389 | char decrypt[PROPERTY_VALUE_MAX]; |
| 390 | property_get("vold.decrypt", decrypt, ""); |
| 391 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 392 | bool encryptedAnimation = atoi(decrypt) != 0 || |
| 393 | !strcmp("trigger_restart_min_framework", decrypt); |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 394 | |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 395 | if (!mShuttingDown && encryptedAnimation) { |
| 396 | static const char* encryptedBootFiles[] = |
| 397 | {PRODUCT_ENCRYPTED_BOOTANIMATION_FILE, SYSTEM_ENCRYPTED_BOOTANIMATION_FILE}; |
| 398 | for (const char* f : encryptedBootFiles) { |
| 399 | if (access(f, R_OK) == 0) { |
| 400 | mZipFileName = f; |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 401 | return; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 402 | } |
| 403 | } |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 404 | } |
Beverly | 34ffe25 | 2019-05-17 11:03:54 -0400 | [diff] [blame] | 405 | |
| 406 | const bool playDarkAnim = android::base::GetIntProperty("ro.boot.theme", 0) == 1; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 407 | static const char* bootFiles[] = |
Anders Fridlund | e0b4d23 | 2018-11-06 14:23:25 +0100 | [diff] [blame] | 408 | {APEX_BOOTANIMATION_FILE, playDarkAnim ? PRODUCT_BOOTANIMATION_DARK_FILE : PRODUCT_BOOTANIMATION_FILE, |
Beverly | 34ffe25 | 2019-05-17 11:03:54 -0400 | [diff] [blame] | 409 | OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE}; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 410 | static const char* shutdownFiles[] = |
Anders Fridlund | e0b4d23 | 2018-11-06 14:23:25 +0100 | [diff] [blame] | 411 | {PRODUCT_SHUTDOWNANIMATION_FILE, OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE, ""}; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 412 | |
| 413 | for (const char* f : (!mShuttingDown ? bootFiles : shutdownFiles)) { |
| 414 | if (access(f, R_OK) == 0) { |
| 415 | mZipFileName = f; |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 416 | return; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 417 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 418 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 421 | bool BootAnimation::threadLoop() |
| 422 | { |
| 423 | bool r; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 424 | // We have no bootanimation file, so we use the stock android logo |
| 425 | // animation. |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 426 | if (mZipFileName.isEmpty()) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 427 | r = android(); |
| 428 | } else { |
| 429 | r = movie(); |
| 430 | } |
| 431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 433 | eglDestroyContext(mDisplay, mContext); |
| 434 | eglDestroySurface(mDisplay, mSurface); |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 435 | mFlingerSurface.clear(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 436 | mFlingerSurfaceControl.clear(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 437 | eglTerminate(mDisplay); |
Sai Kiran Korwar | 3eee9fb | 2015-06-16 17:13:35 +0530 | [diff] [blame] | 438 | eglReleaseThread(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 439 | IPCThreadState::self()->stopProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | return r; |
| 441 | } |
| 442 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 443 | bool BootAnimation::android() |
| 444 | { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 445 | SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
Keun-young Park | d1794cd | 2017-04-04 12:21:19 -0700 | [diff] [blame] | 446 | elapsedRealtime()); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 447 | initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); |
| 448 | initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 450 | mCallbacks->init({}); |
| 451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | // clear screen |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 453 | glShadeModel(GL_FLAT); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 454 | glDisable(GL_DITHER); |
| 455 | glDisable(GL_SCISSOR_TEST); |
Mathias Agopian | 59f19e4 | 2011-05-06 19:22:12 -0700 | [diff] [blame] | 456 | glClearColor(0,0,0,1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | glClear(GL_COLOR_BUFFER_BIT); |
| 458 | eglSwapBuffers(mDisplay, mSurface); |
| 459 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 460 | glEnable(GL_TEXTURE_2D); |
| 461 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 462 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 463 | const GLint xc = (mWidth - mAndroid[0].w) / 2; |
| 464 | const GLint yc = (mHeight - mAndroid[0].h) / 2; |
| 465 | 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] | 466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(), |
| 468 | updateRect.height()); |
| 469 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 470 | // Blend state |
| 471 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 472 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | const nsecs_t startTime = systemTime(); |
| 475 | do { |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 476 | nsecs_t now = systemTime(); |
| 477 | double time = now - startTime; |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 478 | float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w; |
| 479 | GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w; |
| 480 | GLint x = xc - offset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | |
Mathias Agopian | 8166864 | 2009-07-28 11:41:30 -0700 | [diff] [blame] | 482 | glDisable(GL_SCISSOR_TEST); |
| 483 | glClear(GL_COLOR_BUFFER_BIT); |
| 484 | |
| 485 | glEnable(GL_SCISSOR_TEST); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | glDisable(GL_BLEND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | glBindTexture(GL_TEXTURE_2D, mAndroid[1].name); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 488 | glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h); |
| 489 | 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] | 490 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 491 | glEnable(GL_BLEND); |
| 492 | glBindTexture(GL_TEXTURE_2D, mAndroid[0].name); |
| 493 | 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] | 494 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 495 | EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); |
| 496 | if (res == EGL_FALSE) |
| 497 | break; |
| 498 | |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 499 | // 12fps: don't animate too fast to preserve CPU |
| 500 | const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); |
| 501 | if (sleepTime > 0) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 502 | usleep(sleepTime); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 503 | |
| 504 | checkExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | } while (!exitPending()); |
| 506 | |
| 507 | glDeleteTextures(1, &mAndroid[0].name); |
| 508 | glDeleteTextures(1, &mAndroid[1].name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | return false; |
| 510 | } |
| 511 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 512 | void BootAnimation::checkExit() { |
| 513 | // Allow surface flinger to gracefully request shutdown |
| 514 | char value[PROPERTY_VALUE_MAX]; |
| 515 | property_get(EXIT_PROP_NAME, value, "0"); |
| 516 | int exitnow = atoi(value); |
| 517 | if (exitnow) { |
| 518 | requestExit(); |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 519 | mCallbacks->shutdown(); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 523 | bool BootAnimation::validClock(const Animation::Part& part) { |
| 524 | return part.clockPosX != TEXT_MISSING_VALUE && part.clockPosY != TEXT_MISSING_VALUE; |
| 525 | } |
| 526 | |
| 527 | bool parseTextCoord(const char* str, int* dest) { |
| 528 | if (strcmp("c", str) == 0) { |
| 529 | *dest = TEXT_CENTER_VALUE; |
| 530 | return true; |
| 531 | } |
| 532 | |
| 533 | char* end; |
| 534 | int val = (int) strtol(str, &end, 0); |
| 535 | if (end == str || *end != '\0' || val == INT_MAX || val == INT_MIN) { |
| 536 | return false; |
| 537 | } |
| 538 | *dest = val; |
| 539 | return true; |
| 540 | } |
| 541 | |
| 542 | // Parse two position coordinates. If only string is non-empty, treat it as the y value. |
| 543 | void parsePosition(const char* str1, const char* str2, int* x, int* y) { |
| 544 | bool success = false; |
| 545 | if (strlen(str1) == 0) { // No values were specified |
| 546 | // success = false |
| 547 | } else if (strlen(str2) == 0) { // we have only one value |
| 548 | if (parseTextCoord(str1, y)) { |
| 549 | *x = TEXT_CENTER_VALUE; |
| 550 | success = true; |
| 551 | } |
| 552 | } else { |
| 553 | if (parseTextCoord(str1, x) && parseTextCoord(str2, y)) { |
| 554 | success = true; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | if (!success) { |
| 559 | *x = TEXT_MISSING_VALUE; |
| 560 | *y = TEXT_MISSING_VALUE; |
| 561 | } |
| 562 | } |
| 563 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 564 | // Parse a color represented as an HTML-style 'RRGGBB' string: each pair of |
| 565 | // characters in str is a hex number in [0, 255], which are converted to |
| 566 | // floating point values in the range [0.0, 1.0] and placed in the |
| 567 | // corresponding elements of color. |
| 568 | // |
| 569 | // If the input string isn't valid, parseColor returns false and color is |
| 570 | // left unchanged. |
| 571 | static bool parseColor(const char str[7], float color[3]) { |
| 572 | float tmpColor[3]; |
| 573 | for (int i = 0; i < 3; i++) { |
| 574 | int val = 0; |
| 575 | for (int j = 0; j < 2; j++) { |
| 576 | val *= 16; |
| 577 | char c = str[2*i + j]; |
| 578 | if (c >= '0' && c <= '9') val += c - '0'; |
| 579 | else if (c >= 'A' && c <= 'F') val += (c - 'A') + 10; |
| 580 | else if (c >= 'a' && c <= 'f') val += (c - 'a') + 10; |
| 581 | else return false; |
| 582 | } |
| 583 | tmpColor[i] = static_cast<float>(val) / 255.0f; |
| 584 | } |
| 585 | memcpy(color, tmpColor, sizeof(tmpColor)); |
| 586 | return true; |
| 587 | } |
| 588 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 589 | |
| 590 | static bool readFile(ZipFileRO* zip, const char* name, String8& outString) |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 591 | { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 592 | ZipEntryRO entry = zip->findEntryByName(name); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 593 | SLOGE_IF(!entry, "couldn't find %s", name); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 594 | if (!entry) { |
| 595 | return false; |
| 596 | } |
| 597 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 598 | FileMap* entryMap = zip->createEntryFileMap(entry); |
| 599 | zip->releaseEntry(entry); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 600 | SLOGE_IF(!entryMap, "entryMap is null"); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 601 | if (!entryMap) { |
| 602 | return false; |
| 603 | } |
| 604 | |
| 605 | outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength()); |
Narayan Kamath | 688ff4c | 2015-02-23 15:47:54 +0000 | [diff] [blame] | 606 | delete entryMap; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 607 | return true; |
| 608 | } |
| 609 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 610 | // The font image should be a 96x2 array of character images. The |
| 611 | // columns are the printable ASCII characters 0x20 - 0x7f. The |
| 612 | // top row is regular text; the bottom row is bold. |
| 613 | status_t BootAnimation::initFont(Font* font, const char* fallback) { |
| 614 | status_t status = NO_ERROR; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 615 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 616 | if (font->map != nullptr) { |
| 617 | glGenTextures(1, &font->texture.name); |
| 618 | glBindTexture(GL_TEXTURE_2D, font->texture.name); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 619 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 620 | status = initTexture(font->map, &font->texture.w, &font->texture.h); |
| 621 | |
| 622 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 623 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 624 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 625 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 626 | } else if (fallback != nullptr) { |
| 627 | status = initTexture(&font->texture, mAssets, fallback); |
| 628 | } else { |
| 629 | return NO_INIT; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 630 | } |
| 631 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 632 | if (status == NO_ERROR) { |
| 633 | font->char_width = font->texture.w / FONT_NUM_COLS; |
| 634 | font->char_height = font->texture.h / FONT_NUM_ROWS / 2; // There are bold and regular rows |
| 635 | } |
| 636 | |
| 637 | return status; |
| 638 | } |
| 639 | |
| 640 | void BootAnimation::drawText(const char* str, const Font& font, bool bold, int* x, int* y) { |
| 641 | glEnable(GL_BLEND); // Allow us to draw on top of the animation |
| 642 | glBindTexture(GL_TEXTURE_2D, font.texture.name); |
| 643 | |
| 644 | const int len = strlen(str); |
| 645 | const int strWidth = font.char_width * len; |
| 646 | |
| 647 | if (*x == TEXT_CENTER_VALUE) { |
| 648 | *x = (mWidth - strWidth) / 2; |
| 649 | } else if (*x < 0) { |
| 650 | *x = mWidth + *x - strWidth; |
| 651 | } |
| 652 | if (*y == TEXT_CENTER_VALUE) { |
| 653 | *y = (mHeight - font.char_height) / 2; |
| 654 | } else if (*y < 0) { |
| 655 | *y = mHeight + *y - font.char_height; |
| 656 | } |
| 657 | |
| 658 | int cropRect[4] = { 0, 0, font.char_width, -font.char_height }; |
| 659 | |
| 660 | for (int i = 0; i < len; i++) { |
| 661 | char c = str[i]; |
| 662 | |
| 663 | if (c < FONT_BEGIN_CHAR || c > FONT_END_CHAR) { |
| 664 | c = '?'; |
| 665 | } |
| 666 | |
| 667 | // Crop the texture to only the pixels in the current glyph |
| 668 | const int charPos = (c - FONT_BEGIN_CHAR); // Position in the list of valid characters |
| 669 | const int row = charPos / FONT_NUM_COLS; |
| 670 | const int col = charPos % FONT_NUM_COLS; |
| 671 | cropRect[0] = col * font.char_width; // Left of column |
| 672 | cropRect[1] = row * font.char_height * 2; // Top of row |
| 673 | // Move down to bottom of regular (one char_heigh) or bold (two char_heigh) line |
| 674 | cropRect[1] += bold ? 2 * font.char_height : font.char_height; |
| 675 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); |
| 676 | |
| 677 | glDrawTexiOES(*x, *y, 0, font.char_width, font.char_height); |
| 678 | |
| 679 | *x += font.char_width; |
| 680 | } |
| 681 | |
| 682 | glDisable(GL_BLEND); // Return to the animation's default behaviour |
| 683 | glBindTexture(GL_TEXTURE_2D, 0); |
| 684 | } |
| 685 | |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 686 | // We render 12 or 24 hour time. |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 687 | void BootAnimation::drawClock(const Font& font, const int xPos, const int yPos) { |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 688 | static constexpr char TIME_FORMAT_12[] = "%l:%M"; |
| 689 | static constexpr char TIME_FORMAT_24[] = "%H:%M"; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 690 | static constexpr int TIME_LENGTH = 6; |
| 691 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 692 | time_t rawtime; |
| 693 | time(&rawtime); |
| 694 | struct tm* timeInfo = localtime(&rawtime); |
| 695 | |
| 696 | char timeBuff[TIME_LENGTH]; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 697 | const char* timeFormat = mTimeFormat12Hour ? TIME_FORMAT_12 : TIME_FORMAT_24; |
| 698 | size_t length = strftime(timeBuff, TIME_LENGTH, timeFormat, timeInfo); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 699 | |
| 700 | if (length != TIME_LENGTH - 1) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 701 | SLOGE("Couldn't format time; abandoning boot animation clock"); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 702 | mClockEnabled = false; |
| 703 | return; |
| 704 | } |
| 705 | |
Damien Bargiacchi | 45a7644 | 2016-12-05 18:02:18 -0800 | [diff] [blame] | 706 | char* out = timeBuff[0] == ' ' ? &timeBuff[1] : &timeBuff[0]; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 707 | int x = xPos; |
| 708 | int y = yPos; |
Damien Bargiacchi | 45a7644 | 2016-12-05 18:02:18 -0800 | [diff] [blame] | 709 | drawText(out, font, false, &x, &y); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 710 | } |
| 711 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 712 | bool BootAnimation::parseAnimationDesc(Animation& animation) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 713 | { |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 714 | String8 desString; |
| 715 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 716 | if (!readFile(animation.zip, "desc.txt", desString)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 717 | return false; |
| 718 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 719 | char const* s = desString.string(); |
| 720 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 721 | // Parse the description file |
| 722 | for (;;) { |
| 723 | const char* endl = strstr(s, "\n"); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 724 | if (endl == nullptr) break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 725 | String8 line(s, endl - s); |
| 726 | const char* l = line.string(); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 727 | int fps = 0; |
| 728 | int width = 0; |
| 729 | int height = 0; |
| 730 | int count = 0; |
| 731 | int pause = 0; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 732 | char path[ANIM_ENTRY_NAME_MAX]; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 733 | char color[7] = "000000"; // default to black if unspecified |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 734 | char clockPos1[TEXT_POS_LEN_MAX + 1] = ""; |
| 735 | char clockPos2[TEXT_POS_LEN_MAX + 1] = ""; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 736 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 737 | char pathType; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 738 | if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 739 | // SLOGD("> w=%d, h=%d, fps=%d", width, height, fps); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 740 | animation.width = width; |
| 741 | animation.height = height; |
| 742 | animation.fps = fps; |
Kyeongkab.Nam | 35a8a11 | 2019-07-17 16:41:48 +0900 | [diff] [blame] | 743 | } else if (sscanf(l, " %c %d %d %" STRTO(ANIM_PATH_MAX) "s #%6s %16s %16s", |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 744 | &pathType, &count, &pause, path, color, clockPos1, clockPos2) >= 4) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 745 | //SLOGD("> type=%c, count=%d, pause=%d, path=%s, color=%s, clockPos1=%s, clockPos2=%s", |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 746 | // pathType, count, pause, path, color, clockPos1, clockPos2); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 747 | Animation::Part part; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 748 | part.playUntilComplete = pathType == 'c'; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 749 | part.count = count; |
| 750 | part.pause = pause; |
| 751 | part.path = path; |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 752 | part.audioData = nullptr; |
| 753 | part.animation = nullptr; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 754 | if (!parseColor(color, part.backgroundColor)) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 755 | SLOGE("> invalid color '#%s'", color); |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 756 | part.backgroundColor[0] = 0.0f; |
| 757 | part.backgroundColor[1] = 0.0f; |
| 758 | part.backgroundColor[2] = 0.0f; |
| 759 | } |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 760 | parsePosition(clockPos1, clockPos2, &part.clockPosX, &part.clockPosY); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 761 | animation.parts.add(part); |
| 762 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 763 | else if (strcmp(l, "$SYSTEM") == 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 764 | // SLOGD("> SYSTEM"); |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 765 | Animation::Part part; |
| 766 | part.playUntilComplete = false; |
| 767 | part.count = 1; |
| 768 | part.pause = 0; |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 769 | part.audioData = nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 770 | part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE)); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 771 | if (part.animation != nullptr) |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 772 | animation.parts.add(part); |
| 773 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 774 | s = ++endl; |
| 775 | } |
| 776 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 777 | return true; |
| 778 | } |
| 779 | |
| 780 | bool BootAnimation::preloadZip(Animation& animation) |
| 781 | { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 782 | // read all the data structures |
| 783 | const size_t pcount = animation.parts.size(); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 784 | void *cookie = nullptr; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 785 | ZipFileRO* zip = animation.zip; |
| 786 | if (!zip->startIteration(&cookie)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 787 | return false; |
| 788 | } |
| 789 | |
| 790 | ZipEntryRO entry; |
| 791 | char name[ANIM_ENTRY_NAME_MAX]; |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 792 | while ((entry = zip->nextEntry(cookie)) != nullptr) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 793 | const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 794 | if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 795 | SLOGE("Error fetching entry file name"); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 796 | continue; |
| 797 | } |
| 798 | |
| 799 | const String8 entryName(name); |
| 800 | const String8 path(entryName.getPathDir()); |
| 801 | const String8 leaf(entryName.getPathLeaf()); |
| 802 | if (leaf.size() > 0) { |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 803 | if (entryName == CLOCK_FONT_ZIP_NAME) { |
| 804 | FileMap* map = zip->createEntryFileMap(entry); |
| 805 | if (map) { |
| 806 | animation.clockFont.map = map; |
| 807 | } |
| 808 | continue; |
| 809 | } |
| 810 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 811 | for (size_t j = 0; j < pcount; j++) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 812 | if (path == animation.parts[j].path) { |
Narayan Kamath | 4600dd0 | 2015-06-16 12:02:57 +0100 | [diff] [blame] | 813 | uint16_t method; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 814 | // supports only stored png files |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 815 | if (zip->getEntryInfo(entry, &method, nullptr, nullptr, nullptr, nullptr, nullptr)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 816 | if (method == ZipFileRO::kCompressStored) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 817 | FileMap* map = zip->createEntryFileMap(entry); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 818 | if (map) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 819 | Animation::Part& part(animation.parts.editItemAt(j)); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 820 | if (leaf == "audio.wav") { |
| 821 | // a part may have at most one audio file |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 822 | part.audioData = (uint8_t *)map->getDataPtr(); |
| 823 | part.audioLength = map->getDataLength(); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 824 | } else if (leaf == "trim.txt") { |
| 825 | part.trimData.setTo((char const*)map->getDataPtr(), |
| 826 | map->getDataLength()); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 827 | } else { |
| 828 | Animation::Frame frame; |
| 829 | frame.name = leaf; |
| 830 | frame.map = map; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 831 | frame.trimWidth = animation.width; |
| 832 | frame.trimHeight = animation.height; |
| 833 | frame.trimX = 0; |
| 834 | frame.trimY = 0; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 835 | part.frames.add(frame); |
| 836 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 837 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 838 | } else { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 839 | SLOGE("bootanimation.zip is compressed; must be only stored"); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | } |
| 846 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 847 | // If there is trimData present, override the positioning defaults. |
| 848 | for (Animation::Part& part : animation.parts) { |
| 849 | const char* trimDataStr = part.trimData.string(); |
| 850 | for (size_t frameIdx = 0; frameIdx < part.frames.size(); frameIdx++) { |
| 851 | const char* endl = strstr(trimDataStr, "\n"); |
| 852 | // No more trimData for this part. |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 853 | if (endl == nullptr) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 854 | break; |
| 855 | } |
| 856 | String8 line(trimDataStr, endl - trimDataStr); |
| 857 | const char* lineStr = line.string(); |
| 858 | trimDataStr = ++endl; |
| 859 | int width = 0, height = 0, x = 0, y = 0; |
| 860 | if (sscanf(lineStr, "%dx%d+%d+%d", &width, &height, &x, &y) == 4) { |
| 861 | Animation::Frame& frame(part.frames.editItemAt(frameIdx)); |
| 862 | frame.trimWidth = width; |
| 863 | frame.trimHeight = height; |
| 864 | frame.trimX = x; |
| 865 | frame.trimY = y; |
| 866 | } else { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 867 | SLOGE("Error parsing trim.txt, line: %s", lineStr); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 868 | break; |
| 869 | } |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | zip->endIteration(cookie); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 874 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 875 | return true; |
| 876 | } |
| 877 | |
| 878 | bool BootAnimation::movie() |
| 879 | { |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 880 | if (mAnimation == nullptr) { |
| 881 | mAnimation = loadAnimation(mZipFileName); |
| 882 | } |
| 883 | |
| 884 | if (mAnimation == nullptr) |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 885 | return false; |
| 886 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 887 | // mCallbacks->init() may get called recursively, |
| 888 | // this loop is needed to get the same results |
| 889 | for (const Animation::Part& part : mAnimation->parts) { |
| 890 | if (part.animation != nullptr) { |
| 891 | mCallbacks->init(part.animation->parts); |
| 892 | } |
| 893 | } |
| 894 | mCallbacks->init(mAnimation->parts); |
| 895 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 896 | bool anyPartHasClock = false; |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 897 | for (size_t i=0; i < mAnimation->parts.size(); i++) { |
| 898 | if(validClock(mAnimation->parts[i])) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 899 | anyPartHasClock = true; |
| 900 | break; |
| 901 | } |
| 902 | } |
| 903 | if (!anyPartHasClock) { |
| 904 | mClockEnabled = false; |
| 905 | } |
| 906 | |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 907 | // Check if npot textures are supported |
| 908 | mUseNpotTextures = false; |
| 909 | String8 gl_extensions; |
| 910 | const char* exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
| 911 | if (!exts) { |
| 912 | glGetError(); |
| 913 | } else { |
| 914 | gl_extensions.setTo(exts); |
| 915 | if ((gl_extensions.find("GL_ARB_texture_non_power_of_two") != -1) || |
| 916 | (gl_extensions.find("GL_OES_texture_npot") != -1)) { |
| 917 | mUseNpotTextures = true; |
| 918 | } |
| 919 | } |
| 920 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 921 | // Blend required to draw time on top of animation frames. |
| 922 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 923 | glShadeModel(GL_FLAT); |
| 924 | glDisable(GL_DITHER); |
| 925 | glDisable(GL_SCISSOR_TEST); |
| 926 | glDisable(GL_BLEND); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 927 | |
| 928 | glBindTexture(GL_TEXTURE_2D, 0); |
| 929 | glEnable(GL_TEXTURE_2D); |
| 930 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 931 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 932 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 933 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 934 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 935 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 936 | bool clockFontInitialized = false; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 937 | if (mClockEnabled) { |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 938 | clockFontInitialized = |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 939 | (initFont(&mAnimation->clockFont, CLOCK_FONT_ASSET) == NO_ERROR); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 940 | mClockEnabled = clockFontInitialized; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 941 | } |
| 942 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 943 | if (mClockEnabled && !updateIsTimeAccurate()) { |
| 944 | mTimeCheckThread = new TimeCheckThread(this); |
| 945 | mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL); |
| 946 | } |
| 947 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 948 | playAnimation(*mAnimation); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 949 | |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 950 | if (mTimeCheckThread != nullptr) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 951 | mTimeCheckThread->requestExit(); |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 952 | mTimeCheckThread = nullptr; |
| 953 | } |
| 954 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 955 | if (clockFontInitialized) { |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 956 | glDeleteTextures(1, &mAnimation->clockFont.texture.name); |
Andriy Naborskyy | 815e51d | 2016-03-24 16:43:34 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 959 | releaseAnimation(mAnimation); |
| 960 | mAnimation = nullptr; |
Damien Bargiacchi | 1a8a213 | 2018-07-24 15:20:26 -0700 | [diff] [blame] | 961 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 962 | return false; |
| 963 | } |
| 964 | |
| 965 | bool BootAnimation::playAnimation(const Animation& animation) |
| 966 | { |
| 967 | const size_t pcount = animation.parts.size(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 968 | nsecs_t frameDuration = s2ns(1) / animation.fps; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 969 | const int animationX = (mWidth - animation.width) / 2; |
| 970 | const int animationY = (mHeight - animation.height) / 2; |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 971 | |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 972 | SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
Keun-young Park | d1794cd | 2017-04-04 12:21:19 -0700 | [diff] [blame] | 973 | elapsedRealtime()); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 974 | for (size_t i=0 ; i<pcount ; i++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 975 | const Animation::Part& part(animation.parts[i]); |
| 976 | const size_t fcount = part.frames.size(); |
| 977 | glBindTexture(GL_TEXTURE_2D, 0); |
| 978 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 979 | // Handle animation package |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 980 | if (part.animation != nullptr) { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 981 | playAnimation(*part.animation); |
| 982 | if (exitPending()) |
| 983 | break; |
| 984 | continue; //to next part |
| 985 | } |
| 986 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 987 | for (int r=0 ; !part.count || r<part.count ; r++) { |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 988 | // Exit any non playuntil complete parts immediately |
| 989 | if(exitPending() && !part.playUntilComplete) |
| 990 | break; |
| 991 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 992 | mCallbacks->playPart(i, part, r); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 993 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 994 | glClearColor( |
| 995 | part.backgroundColor[0], |
| 996 | part.backgroundColor[1], |
| 997 | part.backgroundColor[2], |
| 998 | 1.0f); |
| 999 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1000 | for (size_t j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1001 | const Animation::Frame& frame(part.frames[j]); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 1002 | nsecs_t lastFrame = systemTime(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1003 | |
| 1004 | if (r > 0) { |
| 1005 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 1006 | } else { |
| 1007 | if (part.count != 1) { |
| 1008 | glGenTextures(1, &frame.tid); |
| 1009 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 1010 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1011 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1012 | } |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1013 | int w, h; |
| 1014 | initTexture(frame.map, &w, &h); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1017 | const int xc = animationX + frame.trimX; |
| 1018 | const int yc = animationY + frame.trimY; |
| 1019 | Region clearReg(Rect(mWidth, mHeight)); |
| 1020 | clearReg.subtractSelf(Rect(xc, yc, xc+frame.trimWidth, yc+frame.trimHeight)); |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 1021 | if (!clearReg.isEmpty()) { |
| 1022 | Region::const_iterator head(clearReg.begin()); |
| 1023 | Region::const_iterator tail(clearReg.end()); |
| 1024 | glEnable(GL_SCISSOR_TEST); |
| 1025 | while (head != tail) { |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 1026 | const Rect& r2(*head++); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1027 | glScissor(r2.left, mHeight - r2.bottom, r2.width(), r2.height()); |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 1028 | glClear(GL_COLOR_BUFFER_BIT); |
| 1029 | } |
| 1030 | glDisable(GL_SCISSOR_TEST); |
| 1031 | } |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1032 | // specify the y center as ceiling((mHeight - frame.trimHeight) / 2) |
| 1033 | // which is equivalent to mHeight - (yc + frame.trimHeight) |
| 1034 | glDrawTexiOES(xc, mHeight - (yc + frame.trimHeight), |
| 1035 | 0, frame.trimWidth, frame.trimHeight); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1036 | if (mClockEnabled && mTimeIsAccurate && validClock(part)) { |
| 1037 | drawClock(animation.clockFont, part.clockPosX, part.clockPosY); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1038 | } |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1039 | handleViewport(frameDuration); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1040 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1041 | eglSwapBuffers(mDisplay, mSurface); |
| 1042 | |
| 1043 | nsecs_t now = systemTime(); |
| 1044 | nsecs_t delay = frameDuration - (now - lastFrame); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1045 | //SLOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay)); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1046 | lastFrame = now; |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 1047 | |
| 1048 | if (delay > 0) { |
| 1049 | struct timespec spec; |
| 1050 | spec.tv_sec = (now + delay) / 1000000000; |
| 1051 | spec.tv_nsec = (now + delay) % 1000000000; |
| 1052 | int err; |
| 1053 | do { |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1054 | err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, nullptr); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 1055 | } while (err<0 && errno == EINTR); |
| 1056 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1057 | |
| 1058 | checkExit(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1059 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1060 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1061 | usleep(part.pause * ns2us(frameDuration)); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1062 | |
| 1063 | // For infinite parts, we've now played them at least once, so perhaps exit |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1064 | if(exitPending() && !part.count && mCurrentInset >= mTargetInset) |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1065 | break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | // Free textures created for looping parts now that the animation is done. |
| 1071 | for (const Animation::Part& part : animation.parts) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1072 | if (part.count != 1) { |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 1073 | const size_t fcount = part.frames.size(); |
| 1074 | for (size_t j = 0; j < fcount; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1075 | const Animation::Frame& frame(part.frames[j]); |
| 1076 | glDeleteTextures(1, &frame.tid); |
| 1077 | } |
| 1078 | } |
| 1079 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 1080 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1081 | return true; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1084 | void BootAnimation::handleViewport(nsecs_t timestep) { |
| 1085 | if (mShuttingDown || !mFlingerSurfaceControl || mTargetInset == 0) { |
| 1086 | return; |
| 1087 | } |
| 1088 | if (mTargetInset < 0) { |
| 1089 | // Poll the amount for the top display inset. This will return -1 until persistent properties |
| 1090 | // have been loaded. |
| 1091 | mTargetInset = android::base::GetIntProperty("persist.sys.displayinset.top", |
| 1092 | -1 /* default */, -1 /* min */, mHeight / 2 /* max */); |
| 1093 | } |
| 1094 | if (mTargetInset <= 0) { |
| 1095 | return; |
| 1096 | } |
| 1097 | |
| 1098 | if (mCurrentInset < mTargetInset) { |
| 1099 | // After the device boots, the inset will effectively be cropped away. We animate this here. |
| 1100 | float fraction = static_cast<float>(mCurrentInset) / mTargetInset; |
| 1101 | int interpolatedInset = (cosf((fraction + 1) * M_PI) / 2.0f + 0.5f) * mTargetInset; |
| 1102 | |
| 1103 | SurfaceComposerClient::Transaction() |
| 1104 | .setCrop(mFlingerSurfaceControl, Rect(0, interpolatedInset, mWidth, mHeight)) |
| 1105 | .apply(); |
| 1106 | } else { |
| 1107 | // At the end of the animation, we switch to the viewport that DisplayManager will apply |
| 1108 | // later. This changes the coordinate system, and means we must move the surface up by |
| 1109 | // the inset amount. |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1110 | Rect layerStackRect(0, 0, mWidth, mHeight - mTargetInset); |
| 1111 | Rect displayRect(0, mTargetInset, mWidth, mHeight); |
| 1112 | |
| 1113 | SurfaceComposerClient::Transaction t; |
| 1114 | t.setPosition(mFlingerSurfaceControl, 0, -mTargetInset) |
| 1115 | .setCrop(mFlingerSurfaceControl, Rect(0, mTargetInset, mWidth, mHeight)); |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 1116 | t.setDisplayProjection(mDisplayToken, 0 /* orientation */, layerStackRect, displayRect); |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1117 | t.apply(); |
| 1118 | |
| 1119 | mTargetInset = mCurrentInset = 0; |
| 1120 | } |
| 1121 | |
| 1122 | int delta = timestep * mTargetInset / ms2ns(200); |
| 1123 | mCurrentInset += delta; |
| 1124 | } |
| 1125 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1126 | void BootAnimation::releaseAnimation(Animation* animation) const |
| 1127 | { |
| 1128 | for (Vector<Animation::Part>::iterator it = animation->parts.begin(), |
| 1129 | e = animation->parts.end(); it != e; ++it) { |
| 1130 | if (it->animation) |
| 1131 | releaseAnimation(it->animation); |
| 1132 | } |
| 1133 | if (animation->zip) |
| 1134 | delete animation->zip; |
| 1135 | delete animation; |
| 1136 | } |
| 1137 | |
| 1138 | BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn) |
| 1139 | { |
| 1140 | if (mLoadedFiles.indexOf(fn) >= 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1141 | SLOGE("File \"%s\" is already loaded. Cyclic ref is not allowed", |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1142 | fn.string()); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1143 | return nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1144 | } |
| 1145 | ZipFileRO *zip = ZipFileRO::open(fn); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1146 | if (zip == nullptr) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1147 | SLOGE("Failed to open animation zip \"%s\": %s", |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1148 | fn.string(), strerror(errno)); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1149 | return nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | Animation *animation = new Animation; |
| 1153 | animation->fileName = fn; |
| 1154 | animation->zip = zip; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1155 | animation->clockFont.map = nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1156 | mLoadedFiles.add(animation->fileName); |
| 1157 | |
| 1158 | parseAnimationDesc(*animation); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 1159 | if (!preloadZip(*animation)) { |
Greg Kaiser | 7426ec8 | 2019-09-11 14:34:27 -0700 | [diff] [blame] | 1160 | releaseAnimation(animation); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1161 | return nullptr; |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1164 | mLoadedFiles.remove(fn); |
| 1165 | return animation; |
| 1166 | } |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1167 | |
| 1168 | bool BootAnimation::updateIsTimeAccurate() { |
| 1169 | static constexpr long long MAX_TIME_IN_PAST = 60000LL * 60LL * 24LL * 30LL; // 30 days |
| 1170 | static constexpr long long MAX_TIME_IN_FUTURE = 60000LL * 90LL; // 90 minutes |
| 1171 | |
| 1172 | if (mTimeIsAccurate) { |
| 1173 | return true; |
| 1174 | } |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 1175 | if (mShuttingDown) return true; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1176 | struct stat statResult; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 1177 | |
| 1178 | if(stat(TIME_FORMAT_12_HOUR_FLAG_FILE_PATH, &statResult) == 0) { |
| 1179 | mTimeFormat12Hour = true; |
| 1180 | } |
| 1181 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1182 | if(stat(ACCURATE_TIME_FLAG_FILE_PATH, &statResult) == 0) { |
| 1183 | mTimeIsAccurate = true; |
| 1184 | return true; |
| 1185 | } |
| 1186 | |
| 1187 | FILE* file = fopen(LAST_TIME_CHANGED_FILE_PATH, "r"); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1188 | if (file != nullptr) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1189 | long long lastChangedTime = 0; |
| 1190 | fscanf(file, "%lld", &lastChangedTime); |
| 1191 | fclose(file); |
| 1192 | if (lastChangedTime > 0) { |
| 1193 | struct timespec now; |
| 1194 | clock_gettime(CLOCK_REALTIME, &now); |
| 1195 | // Match the Java timestamp format |
| 1196 | long long rtcNow = (now.tv_sec * 1000LL) + (now.tv_nsec / 1000000LL); |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 1197 | if (ACCURATE_TIME_EPOCH < rtcNow |
| 1198 | && lastChangedTime > (rtcNow - MAX_TIME_IN_PAST) |
| 1199 | && lastChangedTime < (rtcNow + MAX_TIME_IN_FUTURE)) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1200 | mTimeIsAccurate = true; |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | return mTimeIsAccurate; |
| 1206 | } |
| 1207 | |
| 1208 | BootAnimation::TimeCheckThread::TimeCheckThread(BootAnimation* bootAnimation) : Thread(false), |
| 1209 | mInotifyFd(-1), mSystemWd(-1), mTimeWd(-1), mBootAnimation(bootAnimation) {} |
| 1210 | |
| 1211 | BootAnimation::TimeCheckThread::~TimeCheckThread() { |
| 1212 | // mInotifyFd may be -1 but that's ok since we're not at risk of attempting to close a valid FD. |
| 1213 | close(mInotifyFd); |
| 1214 | } |
| 1215 | |
| 1216 | bool BootAnimation::TimeCheckThread::threadLoop() { |
| 1217 | bool shouldLoop = doThreadLoop() && !mBootAnimation->mTimeIsAccurate |
| 1218 | && mBootAnimation->mClockEnabled; |
| 1219 | if (!shouldLoop) { |
| 1220 | close(mInotifyFd); |
| 1221 | mInotifyFd = -1; |
| 1222 | } |
| 1223 | return shouldLoop; |
| 1224 | } |
| 1225 | |
| 1226 | bool BootAnimation::TimeCheckThread::doThreadLoop() { |
| 1227 | static constexpr int BUFF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1)); |
| 1228 | |
| 1229 | // Poll instead of doing a blocking read so the Thread can exit if requested. |
| 1230 | struct pollfd pfd = { mInotifyFd, POLLIN, 0 }; |
| 1231 | ssize_t pollResult = poll(&pfd, 1, 1000); |
| 1232 | |
| 1233 | if (pollResult == 0) { |
| 1234 | return true; |
| 1235 | } else if (pollResult < 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1236 | SLOGE("Could not poll inotify events"); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1237 | return false; |
| 1238 | } |
| 1239 | |
| 1240 | char buff[BUFF_LEN] __attribute__ ((aligned(__alignof__(struct inotify_event))));; |
| 1241 | ssize_t length = read(mInotifyFd, buff, BUFF_LEN); |
| 1242 | if (length == 0) { |
| 1243 | return true; |
| 1244 | } else if (length < 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1245 | SLOGE("Could not read inotify events"); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1246 | return false; |
| 1247 | } |
| 1248 | |
| 1249 | const struct inotify_event *event; |
| 1250 | for (char* ptr = buff; ptr < buff + length; ptr += sizeof(struct inotify_event) + event->len) { |
| 1251 | event = (const struct inotify_event *) ptr; |
| 1252 | if (event->wd == mSystemWd && strcmp(SYSTEM_TIME_DIR_NAME, event->name) == 0) { |
| 1253 | addTimeDirWatch(); |
| 1254 | } else if (event->wd == mTimeWd && (strcmp(LAST_TIME_CHANGED_FILE_NAME, event->name) == 0 |
| 1255 | || strcmp(ACCURATE_TIME_FLAG_FILE_NAME, event->name) == 0)) { |
| 1256 | return !mBootAnimation->updateIsTimeAccurate(); |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | return true; |
| 1261 | } |
| 1262 | |
| 1263 | void BootAnimation::TimeCheckThread::addTimeDirWatch() { |
| 1264 | mTimeWd = inotify_add_watch(mInotifyFd, SYSTEM_TIME_DIR_PATH, |
| 1265 | IN_CLOSE_WRITE | IN_MOVED_TO | IN_ATTRIB); |
| 1266 | if (mTimeWd > 0) { |
| 1267 | // No need to watch for the time directory to be created if it already exists |
| 1268 | inotify_rm_watch(mInotifyFd, mSystemWd); |
| 1269 | mSystemWd = -1; |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | status_t BootAnimation::TimeCheckThread::readyToRun() { |
| 1274 | mInotifyFd = inotify_init(); |
| 1275 | if (mInotifyFd < 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1276 | SLOGE("Could not initialize inotify fd"); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1277 | return NO_INIT; |
| 1278 | } |
| 1279 | |
| 1280 | mSystemWd = inotify_add_watch(mInotifyFd, SYSTEM_DATA_DIR_PATH, IN_CREATE | IN_ATTRIB); |
| 1281 | if (mSystemWd < 0) { |
| 1282 | close(mInotifyFd); |
| 1283 | mInotifyFd = -1; |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1284 | SLOGE("Could not add watch for %s", SYSTEM_DATA_DIR_PATH); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1285 | return NO_INIT; |
| 1286 | } |
| 1287 | |
| 1288 | addTimeDirWatch(); |
| 1289 | |
| 1290 | if (mBootAnimation->updateIsTimeAccurate()) { |
| 1291 | close(mInotifyFd); |
| 1292 | mInotifyFd = -1; |
| 1293 | return ALREADY_EXISTS; |
| 1294 | } |
| 1295 | |
| 1296 | return NO_ERROR; |
| 1297 | } |
| 1298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | // --------------------------------------------------------------------------- |
| 1300 | |
| 1301 | } |
| 1302 | ; // namespace android |