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