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 | |
Tomasz Wasilczyk | 9dcea57 | 2023-08-22 20:39:20 +0000 | [diff] [blame] | 20 | #include <filesystem> |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <stdint.h> |
Wei Wang | a90c54c | 2017-02-02 11:35:21 -0800 | [diff] [blame] | 24 | #include <inttypes.h> |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 25 | #include <sys/inotify.h> |
| 26 | #include <sys/poll.h> |
| 27 | #include <sys/stat.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <sys/types.h> |
| 29 | #include <math.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <utils/misc.h> |
Mathias Agopian | b4d5a72 | 2009-09-23 17:05:19 -0700 | [diff] [blame] | 32 | #include <signal.h> |
Elliott Hughes | bb94f31 | 2014-10-21 10:41:33 -0700 | [diff] [blame] | 33 | #include <time.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Steven Moreland | fb7952f | 2018-02-23 14:58:50 -0800 | [diff] [blame] | 35 | #include <cutils/atomic.h> |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 36 | #include <cutils/properties.h> |
| 37 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 38 | #include <android/imagedecoder.h> |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 39 | #include <androidfw/AssetManager.h> |
Mathias Agopian | ac31a3b | 2009-05-21 19:59:24 -0700 | [diff] [blame] | 40 | #include <binder/IPCThreadState.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | #include <utils/Errors.h> |
| 42 | #include <utils/Log.h> |
Wei Wang | a90c54c | 2017-02-02 11:35:21 -0800 | [diff] [blame] | 43 | #include <utils/SystemClock.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 45 | #include <android-base/properties.h> |
| 46 | |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 47 | #include <ui/DisplayMode.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | #include <ui/PixelFormat.h> |
| 49 | #include <ui/Rect.h> |
| 50 | #include <ui/Region.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 52 | #include <gui/ISurfaceComposer.h> |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 53 | #include <gui/DisplayEventReceiver.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 54 | #include <gui/Surface.h> |
| 55 | #include <gui/SurfaceComposerClient.h> |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 56 | #include <GLES2/gl2.h> |
| 57 | #include <GLES2/gl2ext.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | #include <EGL/eglext.h> |
| 59 | |
| 60 | #include "BootAnimation.h" |
| 61 | |
Kyeongkab.Nam | 35a8a11 | 2019-07-17 16:41:48 +0900 | [diff] [blame] | 62 | #define ANIM_PATH_MAX 255 |
| 63 | #define STR(x) #x |
| 64 | #define STRTO(x) STR(x) |
| 65 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | namespace android { |
| 67 | |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 68 | using ui::DisplayMode; |
| 69 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 70 | static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip"; |
Beverly | 34ffe25 | 2019-05-17 11:03:54 -0400 | [diff] [blame] | 71 | static const char PRODUCT_BOOTANIMATION_DARK_FILE[] = "/product/media/bootanimation-dark.zip"; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 72 | static const char PRODUCT_BOOTANIMATION_FILE[] = "/product/media/bootanimation.zip"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 73 | static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip"; |
Anders Fridlund | e0b4d23 | 2018-11-06 14:23:25 +0100 | [diff] [blame] | 74 | 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] | 75 | static const char PRODUCT_ENCRYPTED_BOOTANIMATION_FILE[] = "/product/media/bootanimation-encrypted.zip"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 76 | 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] | 77 | static const char OEM_SHUTDOWNANIMATION_FILE[] = "/oem/media/shutdownanimation.zip"; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 78 | static const char PRODUCT_SHUTDOWNANIMATION_FILE[] = "/product/media/shutdownanimation.zip"; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 79 | static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip"; |
| 80 | |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 81 | static constexpr const char* PRODUCT_USERSPACE_REBOOT_ANIMATION_FILE = "/product/media/userspace-reboot.zip"; |
| 82 | static constexpr const char* OEM_USERSPACE_REBOOT_ANIMATION_FILE = "/oem/media/userspace-reboot.zip"; |
| 83 | static constexpr const char* SYSTEM_USERSPACE_REBOOT_ANIMATION_FILE = "/system/media/userspace-reboot.zip"; |
| 84 | |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 85 | static const char BOOTANIM_DATA_DIR_PATH[] = "/data/bootanim"; |
| 86 | static const char BOOTANIM_TIME_DIR_NAME[] = "time"; |
| 87 | static const char BOOTANIM_TIME_DIR_PATH[] = "/data/bootanim/time"; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 88 | static const char CLOCK_FONT_ASSET[] = "images/clock_font.png"; |
| 89 | static const char CLOCK_FONT_ZIP_NAME[] = "clock_font.png"; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 90 | static const char PROGRESS_FONT_ASSET[] = "images/progress_font.png"; |
| 91 | static const char PROGRESS_FONT_ZIP_NAME[] = "progress_font.png"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 92 | static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change"; |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 93 | static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/bootanim/time/last_time_change"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 94 | static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate"; |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 95 | static const char ACCURATE_TIME_FLAG_FILE_PATH[] = "/data/bootanim/time/time_is_accurate"; |
| 96 | static const char TIME_FORMAT_12_HOUR_FLAG_FILE_PATH[] = "/data/bootanim/time/time_format_12_hour"; |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 97 | // Java timestamp format. Don't show the clock if the date is before 2000-01-01 00:00:00. |
| 98 | static const long long ACCURATE_TIME_EPOCH = 946684800000; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 99 | static constexpr char FONT_BEGIN_CHAR = ' '; |
| 100 | static constexpr char FONT_END_CHAR = '~' + 1; |
| 101 | static constexpr size_t FONT_NUM_CHARS = FONT_END_CHAR - FONT_BEGIN_CHAR + 1; |
| 102 | static constexpr size_t FONT_NUM_COLS = 16; |
| 103 | static constexpr size_t FONT_NUM_ROWS = FONT_NUM_CHARS / FONT_NUM_COLS; |
| 104 | static const int TEXT_CENTER_VALUE = INT_MAX; |
| 105 | static const int TEXT_MISSING_VALUE = INT_MIN; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 106 | static const char EXIT_PROP_NAME[] = "service.bootanim.exit"; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 107 | static const char PROGRESS_PROP_NAME[] = "service.bootanim.progress"; |
Huihong Luo | d4a217e | 2020-01-16 15:56:33 -0800 | [diff] [blame] | 108 | static const char DISPLAYS_PROP_NAME[] = "persist.service.bootanim.displays"; |
Thiébaud Weksteen | 08de443 | 2021-11-18 13:25:59 +1100 | [diff] [blame] | 109 | static const char CLOCK_ENABLED_PROP_NAME[] = "persist.sys.bootanim.clock.enabled"; |
Kyeongkab.Nam | 35a8a11 | 2019-07-17 16:41:48 +0900 | [diff] [blame] | 110 | static const int ANIM_ENTRY_NAME_MAX = ANIM_PATH_MAX + 1; |
niuwenchao | 9cd6ac8 | 2022-12-23 17:34:22 +0800 | [diff] [blame] | 111 | static const int MAX_CHECK_EXIT_INTERVAL_US = 50000; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 112 | static constexpr size_t TEXT_POS_LEN_MAX = 16; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 113 | static const int DYNAMIC_COLOR_COUNT = 4; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 114 | static const char U_TEXTURE[] = "uTexture"; |
| 115 | static const char U_FADE[] = "uFade"; |
| 116 | static const char U_CROP_AREA[] = "uCropArea"; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 117 | static const char U_START_COLOR_PREFIX[] = "uStartColor"; |
| 118 | static const char U_END_COLOR_PREFIX[] = "uEndColor"; |
| 119 | static const char U_COLOR_PROGRESS[] = "uColorProgress"; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 120 | static const char A_UV[] = "aUv"; |
| 121 | static const char A_POSITION[] = "aPosition"; |
| 122 | static const char VERTEX_SHADER_SOURCE[] = R"( |
| 123 | precision mediump float; |
| 124 | attribute vec4 aPosition; |
| 125 | attribute highp vec2 aUv; |
| 126 | varying highp vec2 vUv; |
| 127 | void main() { |
| 128 | gl_Position = aPosition; |
| 129 | vUv = aUv; |
| 130 | })"; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 131 | static const char IMAGE_FRAG_DYNAMIC_COLORING_SHADER_SOURCE[] = R"( |
| 132 | precision mediump float; |
Shan Huang | 81846ba | 2021-09-07 19:07:47 +0000 | [diff] [blame] | 133 | const float cWhiteMaskThreshold = 0.05; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 134 | uniform sampler2D uTexture; |
| 135 | uniform float uFade; |
| 136 | uniform float uColorProgress; |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 137 | uniform vec3 uStartColor0; |
| 138 | uniform vec3 uStartColor1; |
| 139 | uniform vec3 uStartColor2; |
| 140 | uniform vec3 uStartColor3; |
| 141 | uniform vec3 uEndColor0; |
| 142 | uniform vec3 uEndColor1; |
| 143 | uniform vec3 uEndColor2; |
| 144 | uniform vec3 uEndColor3; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 145 | varying highp vec2 vUv; |
| 146 | void main() { |
| 147 | vec4 mask = texture2D(uTexture, vUv); |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 148 | float r = mask.r; |
| 149 | float g = mask.g; |
| 150 | float b = mask.b; |
| 151 | float a = mask.a; |
| 152 | // If all channels have values, render pixel as a shade of white. |
| 153 | float useWhiteMask = step(cWhiteMaskThreshold, r) |
| 154 | * step(cWhiteMaskThreshold, g) |
| 155 | * step(cWhiteMaskThreshold, b) |
| 156 | * step(cWhiteMaskThreshold, a); |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 157 | vec3 color = r * mix(uStartColor0, uEndColor0, uColorProgress) |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 158 | + g * mix(uStartColor1, uEndColor1, uColorProgress) |
| 159 | + b * mix(uStartColor2, uEndColor2, uColorProgress) |
| 160 | + a * mix(uStartColor3, uEndColor3, uColorProgress); |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 161 | color = mix(color, vec3((r + g + b + a) * 0.25), useWhiteMask); |
| 162 | gl_FragColor = vec4(color.x, color.y, color.z, (1.0 - uFade)); |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 163 | })"; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 164 | static const char IMAGE_FRAG_SHADER_SOURCE[] = R"( |
| 165 | precision mediump float; |
| 166 | uniform sampler2D uTexture; |
| 167 | uniform float uFade; |
| 168 | varying highp vec2 vUv; |
| 169 | void main() { |
| 170 | vec4 color = texture2D(uTexture, vUv); |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 171 | gl_FragColor = vec4(color.x, color.y, color.z, (1.0 - uFade)) * color.a; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 172 | })"; |
| 173 | static const char TEXT_FRAG_SHADER_SOURCE[] = R"( |
| 174 | precision mediump float; |
| 175 | uniform sampler2D uTexture; |
| 176 | uniform vec4 uCropArea; |
| 177 | varying highp vec2 vUv; |
| 178 | void main() { |
| 179 | vec2 uv = vec2(mix(uCropArea.x, uCropArea.z, vUv.x), |
| 180 | mix(uCropArea.y, uCropArea.w, vUv.y)); |
| 181 | gl_FragColor = texture2D(uTexture, uv); |
| 182 | })"; |
| 183 | |
| 184 | static GLfloat quadPositions[] = { |
| 185 | -0.5f, -0.5f, |
| 186 | +0.5f, -0.5f, |
| 187 | +0.5f, +0.5f, |
| 188 | +0.5f, +0.5f, |
| 189 | -0.5f, +0.5f, |
| 190 | -0.5f, -0.5f |
| 191 | }; |
| 192 | static GLfloat quadUVs[] = { |
| 193 | 0.0f, 1.0f, |
| 194 | 1.0f, 1.0f, |
| 195 | 1.0f, 0.0f, |
| 196 | 1.0f, 0.0f, |
| 197 | 0.0f, 0.0f, |
| 198 | 0.0f, 1.0f |
| 199 | }; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | // --------------------------------------------------------------------------- |
| 202 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 203 | BootAnimation::BootAnimation(sp<Callbacks> callbacks) |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 204 | : Thread(false), mLooper(new Looper(false)), mClockEnabled(true), mTimeIsAccurate(false), |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 205 | mTimeFormat12Hour(false), mTimeCheckThread(nullptr), mCallbacks(callbacks) { |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 206 | mSession = new SurfaceComposerClient(); |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 207 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 208 | std::string powerCtl = android::base::GetProperty("sys.powerctl", ""); |
| 209 | if (powerCtl.empty()) { |
| 210 | mShuttingDown = false; |
| 211 | } else { |
| 212 | mShuttingDown = true; |
| 213 | } |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 214 | ALOGD("%sAnimationStartTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
| 215 | elapsedRealtime()); |
| 216 | } |
| 217 | |
| 218 | BootAnimation::~BootAnimation() { |
| 219 | if (mAnimation != nullptr) { |
| 220 | releaseAnimation(mAnimation); |
| 221 | mAnimation = nullptr; |
| 222 | } |
| 223 | ALOGD("%sAnimationStopTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
| 224 | elapsedRealtime()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | } |
| 226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | void BootAnimation::onFirstRef() { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 228 | status_t err = mSession->linkToComposerDeath(this); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 229 | SLOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err)); |
Mathias Agopian | 8434c53 | 2009-09-23 18:52:49 -0700 | [diff] [blame] | 230 | if (err == NO_ERROR) { |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 231 | // Load the animation content -- this can be slow (eg 200ms) |
| 232 | // called before waitForSurfaceFlinger() in main() to avoid wait |
| 233 | ALOGD("%sAnimationPreloadTiming start time: %" PRId64 "ms", |
| 234 | mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime()); |
| 235 | preloadAnimation(); |
| 236 | ALOGD("%sAnimationPreloadStopTiming start time: %" PRId64 "ms", |
| 237 | mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime()); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 241 | sp<SurfaceComposerClient> BootAnimation::session() const { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | return mSession; |
| 243 | } |
| 244 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 245 | void BootAnimation::binderDied(const wp<IBinder>&) { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 246 | // woah, surfaceflinger died! |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 247 | SLOGD("SurfaceFlinger died, exiting..."); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 248 | |
| 249 | // calling requestExit() is not enough here because the Surface code |
| 250 | // might be blocked on a condition variable that will never be updated. |
| 251 | kill( getpid(), SIGKILL ); |
| 252 | requestExit(); |
| 253 | } |
| 254 | |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 255 | static void* decodeImage(const void* encodedData, size_t dataLength, AndroidBitmapInfo* outInfo, |
| 256 | bool premultiplyAlpha) { |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 257 | AImageDecoder* decoder = nullptr; |
| 258 | AImageDecoder_createFromBuffer(encodedData, dataLength, &decoder); |
| 259 | if (!decoder) { |
| 260 | return nullptr; |
| 261 | } |
| 262 | |
| 263 | const AImageDecoderHeaderInfo* info = AImageDecoder_getHeaderInfo(decoder); |
| 264 | outInfo->width = AImageDecoderHeaderInfo_getWidth(info); |
| 265 | outInfo->height = AImageDecoderHeaderInfo_getHeight(info); |
| 266 | outInfo->format = AImageDecoderHeaderInfo_getAndroidBitmapFormat(info); |
| 267 | outInfo->stride = AImageDecoder_getMinimumStride(decoder); |
| 268 | outInfo->flags = 0; |
| 269 | |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 270 | if (!premultiplyAlpha) { |
| 271 | AImageDecoder_setUnpremultipliedRequired(decoder, true); |
| 272 | } |
| 273 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 274 | const size_t size = outInfo->stride * outInfo->height; |
| 275 | void* pixels = malloc(size); |
| 276 | int result = AImageDecoder_decodeImage(decoder, pixels, outInfo->stride, size); |
| 277 | AImageDecoder_delete(decoder); |
| 278 | |
| 279 | if (result != ANDROID_IMAGE_DECODER_SUCCESS) { |
| 280 | free(pixels); |
| 281 | return nullptr; |
| 282 | } |
| 283 | return pixels; |
| 284 | } |
| 285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 287 | const char* name, bool premultiplyAlpha) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | Asset* asset = assets.open(name, Asset::ACCESS_BUFFER); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 289 | if (asset == nullptr) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | return NO_INIT; |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 291 | |
| 292 | AndroidBitmapInfo bitmapInfo; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 293 | void* pixels = decodeImage(asset->getBuffer(false), asset->getLength(), &bitmapInfo, |
| 294 | premultiplyAlpha); |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 295 | auto pixelDeleter = std::unique_ptr<void, decltype(free)*>{ pixels, free }; |
| 296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | asset->close(); |
| 298 | delete asset; |
| 299 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 300 | if (!pixels) { |
| 301 | return NO_INIT; |
| 302 | } |
| 303 | |
| 304 | const int w = bitmapInfo.width; |
| 305 | const int h = bitmapInfo.height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | texture->w = w; |
| 308 | texture->h = h; |
| 309 | |
| 310 | glGenTextures(1, &texture->name); |
| 311 | glBindTexture(GL_TEXTURE_2D, texture->name); |
| 312 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 313 | switch (bitmapInfo.format) { |
| 314 | case ANDROID_BITMAP_FORMAT_A_8: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 316 | GL_UNSIGNED_BYTE, pixels); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | break; |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 318 | case ANDROID_BITMAP_FORMAT_RGBA_4444: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 320 | GL_UNSIGNED_SHORT_4_4_4_4, pixels); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | break; |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 322 | case ANDROID_BITMAP_FORMAT_RGBA_8888: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 324 | GL_UNSIGNED_BYTE, pixels); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | break; |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 326 | case ANDROID_BITMAP_FORMAT_RGB_565: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 328 | GL_UNSIGNED_SHORT_5_6_5, pixels); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | break; |
| 330 | default: |
| 331 | break; |
| 332 | } |
| 333 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 334 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 335 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 336 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 337 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | return NO_ERROR; |
| 340 | } |
| 341 | |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 342 | status_t BootAnimation::initTexture(FileMap* map, int* width, int* height, |
| 343 | bool premultiplyAlpha) { |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 344 | AndroidBitmapInfo bitmapInfo; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 345 | void* pixels = decodeImage(map->getDataPtr(), map->getDataLength(), &bitmapInfo, |
| 346 | premultiplyAlpha); |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 347 | auto pixelDeleter = std::unique_ptr<void, decltype(free)*>{ pixels, free }; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 348 | |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 349 | // FileMap memory is never released until application exit. |
| 350 | // Release it now as the texture is already loaded and the memory used for |
| 351 | // the packed resource can be released. |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 352 | delete map; |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 353 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 354 | if (!pixels) { |
| 355 | return NO_INIT; |
| 356 | } |
| 357 | |
| 358 | const int w = bitmapInfo.width; |
| 359 | const int h = bitmapInfo.height; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 360 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 361 | int tw = 1 << (31 - __builtin_clz(w)); |
| 362 | int th = 1 << (31 - __builtin_clz(h)); |
| 363 | if (tw < w) tw <<= 1; |
| 364 | if (th < h) th <<= 1; |
| 365 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 366 | switch (bitmapInfo.format) { |
| 367 | case ANDROID_BITMAP_FORMAT_RGBA_8888: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 368 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 369 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 370 | GL_UNSIGNED_BYTE, nullptr); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 371 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 372 | 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 373 | } else { |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 374 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 375 | GL_UNSIGNED_BYTE, pixels); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 376 | } |
| 377 | break; |
| 378 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 379 | case ANDROID_BITMAP_FORMAT_RGB_565: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 380 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 381 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 382 | GL_UNSIGNED_SHORT_5_6_5, nullptr); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 383 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 384 | 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] | 385 | } else { |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 386 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 387 | GL_UNSIGNED_SHORT_5_6_5, pixels); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 388 | } |
| 389 | break; |
| 390 | default: |
| 391 | break; |
| 392 | } |
| 393 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 394 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 395 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 396 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 397 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 398 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 399 | *width = w; |
| 400 | *height = h; |
| 401 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 402 | return NO_ERROR; |
| 403 | } |
| 404 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 405 | class BootAnimation::DisplayEventCallback : public LooperCallback { |
| 406 | BootAnimation* mBootAnimation; |
| 407 | |
| 408 | public: |
| 409 | DisplayEventCallback(BootAnimation* bootAnimation) { |
| 410 | mBootAnimation = bootAnimation; |
| 411 | } |
| 412 | |
| 413 | int handleEvent(int /* fd */, int events, void* /* data */) { |
| 414 | if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) { |
| 415 | ALOGE("Display event receiver pipe was closed or an error occurred. events=0x%x", |
| 416 | events); |
| 417 | return 0; // remove the callback |
| 418 | } |
| 419 | |
| 420 | if (!(events & Looper::EVENT_INPUT)) { |
| 421 | ALOGW("Received spurious callback for unhandled poll event. events=0x%x", events); |
| 422 | return 1; // keep the callback |
| 423 | } |
| 424 | |
| 425 | constexpr int kBufferSize = 100; |
| 426 | DisplayEventReceiver::Event buffer[kBufferSize]; |
| 427 | ssize_t numEvents; |
| 428 | do { |
| 429 | numEvents = mBootAnimation->mDisplayEventReceiver->getEvents(buffer, kBufferSize); |
| 430 | for (size_t i = 0; i < static_cast<size_t>(numEvents); i++) { |
| 431 | const auto& event = buffer[i]; |
| 432 | if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG) { |
| 433 | SLOGV("Hotplug received"); |
| 434 | |
| 435 | if (!event.hotplug.connected) { |
| 436 | // ignore hotplug disconnect |
| 437 | continue; |
| 438 | } |
| 439 | auto token = SurfaceComposerClient::getPhysicalDisplayToken( |
| 440 | event.header.displayId); |
| 441 | |
| 442 | if (token != mBootAnimation->mDisplayToken) { |
| 443 | // ignore hotplug of a secondary display |
| 444 | continue; |
| 445 | } |
| 446 | |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 447 | DisplayMode displayMode; |
| 448 | const status_t error = SurfaceComposerClient::getActiveDisplayMode( |
| 449 | mBootAnimation->mDisplayToken, &displayMode); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 450 | if (error != NO_ERROR) { |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 451 | SLOGE("Can't get active display mode."); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 452 | } |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 453 | mBootAnimation->resizeSurface(displayMode.resolution.getWidth(), |
| 454 | displayMode.resolution.getHeight()); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | } while (numEvents > 0); |
| 458 | |
| 459 | return 1; // keep the callback |
| 460 | } |
| 461 | }; |
| 462 | |
| 463 | EGLConfig BootAnimation::getEglConfig(const EGLDisplay& display) { |
| 464 | const EGLint attribs[] = { |
Andrii Chepurnyi | d93f7b2 | 2023-03-15 11:22:07 +0200 | [diff] [blame] | 465 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 466 | EGL_RED_SIZE, 8, |
| 467 | EGL_GREEN_SIZE, 8, |
| 468 | EGL_BLUE_SIZE, 8, |
| 469 | EGL_DEPTH_SIZE, 0, |
| 470 | EGL_NONE |
| 471 | }; |
| 472 | EGLint numConfigs; |
| 473 | EGLConfig config; |
| 474 | eglChooseConfig(display, attribs, &config, 1, &numConfigs); |
| 475 | return config; |
| 476 | } |
| 477 | |
Marin Shalamanov | 047802d | 2020-05-19 23:55:12 +0200 | [diff] [blame] | 478 | ui::Size BootAnimation::limitSurfaceSize(int width, int height) const { |
| 479 | ui::Size limited(width, height); |
| 480 | bool wasLimited = false; |
| 481 | const float aspectRatio = float(width) / float(height); |
| 482 | if (mMaxWidth != 0 && width > mMaxWidth) { |
| 483 | limited.height = mMaxWidth / aspectRatio; |
| 484 | limited.width = mMaxWidth; |
| 485 | wasLimited = true; |
| 486 | } |
| 487 | if (mMaxHeight != 0 && limited.height > mMaxHeight) { |
| 488 | limited.height = mMaxHeight; |
| 489 | limited.width = mMaxHeight * aspectRatio; |
| 490 | wasLimited = true; |
| 491 | } |
| 492 | SLOGV_IF(wasLimited, "Surface size has been limited to [%dx%d] from [%dx%d]", |
| 493 | limited.width, limited.height, width, height); |
| 494 | return limited; |
| 495 | } |
| 496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | status_t BootAnimation::readyToRun() { |
| 498 | mAssets.addDefaultAssets(); |
| 499 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 500 | mDisplayToken = SurfaceComposerClient::getInternalDisplayToken(); |
| 501 | if (mDisplayToken == nullptr) |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 502 | return NAME_NOT_FOUND; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 503 | |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 504 | DisplayMode displayMode; |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 505 | const status_t error = |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 506 | SurfaceComposerClient::getActiveDisplayMode(mDisplayToken, &displayMode); |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 507 | if (error != NO_ERROR) |
| 508 | return error; |
| 509 | |
Marin Shalamanov | 047802d | 2020-05-19 23:55:12 +0200 | [diff] [blame] | 510 | mMaxWidth = android::base::GetIntProperty("ro.surface_flinger.max_graphics_width", 0); |
| 511 | mMaxHeight = android::base::GetIntProperty("ro.surface_flinger.max_graphics_height", 0); |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 512 | ui::Size resolution = displayMode.resolution; |
Marin Shalamanov | 047802d | 2020-05-19 23:55:12 +0200 | [diff] [blame] | 513 | resolution = limitSurfaceSize(resolution.width, resolution.height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | // create the native surface |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 515 | sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"), |
xi yu | c341544 | 2022-05-09 08:58:02 +0000 | [diff] [blame] | 516 | resolution.getWidth(), resolution.getHeight(), PIXEL_FORMAT_RGB_565, |
| 517 | ISurfaceComposerClient::eOpaque); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 518 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 519 | SurfaceComposerClient::Transaction t; |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 520 | |
| 521 | // this guest property specifies multi-display IDs to show the boot animation |
| 522 | // multiple ids can be set with comma (,) as separator, for example: |
Huihong Luo | d4a217e | 2020-01-16 15:56:33 -0800 | [diff] [blame] | 523 | // setprop persist.boot.animation.displays 19260422155234049,19261083906282754 |
Marin Shalamanov | 11599ee | 2020-07-27 21:31:48 +0200 | [diff] [blame] | 524 | Vector<PhysicalDisplayId> physicalDisplayIds; |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 525 | char displayValue[PROPERTY_VALUE_MAX] = ""; |
Huihong Luo | d4a217e | 2020-01-16 15:56:33 -0800 | [diff] [blame] | 526 | property_get(DISPLAYS_PROP_NAME, displayValue, ""); |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 527 | bool isValid = displayValue[0] != '\0'; |
| 528 | if (isValid) { |
| 529 | char *p = displayValue; |
| 530 | while (*p) { |
| 531 | if (!isdigit(*p) && *p != ',') { |
| 532 | isValid = false; |
| 533 | break; |
| 534 | } |
| 535 | p ++; |
| 536 | } |
| 537 | if (!isValid) |
Huihong Luo | d4a217e | 2020-01-16 15:56:33 -0800 | [diff] [blame] | 538 | 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] | 539 | } |
| 540 | if (isValid) { |
| 541 | std::istringstream stream(displayValue); |
Marin Shalamanov | 11599ee | 2020-07-27 21:31:48 +0200 | [diff] [blame] | 542 | for (PhysicalDisplayId id; stream >> id.value; ) { |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 543 | physicalDisplayIds.add(id); |
| 544 | if (stream.peek() == ',') |
| 545 | stream.ignore(); |
| 546 | } |
| 547 | |
| 548 | // In the case of multi-display, boot animation shows on the specified displays |
| 549 | // in addition to the primary display |
Dominik Laskowski | 989de3d | 2021-07-27 21:09:34 -0700 | [diff] [blame] | 550 | const auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); |
| 551 | for (const auto id : physicalDisplayIds) { |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 552 | if (std::find(ids.begin(), ids.end(), id) != ids.end()) { |
Dominik Laskowski | 989de3d | 2021-07-27 21:09:34 -0700 | [diff] [blame] | 553 | if (const auto token = SurfaceComposerClient::getPhysicalDisplayToken(id)) { |
| 554 | t.setDisplayLayerStack(token, ui::DEFAULT_LAYER_STACK); |
| 555 | } |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 556 | } |
| 557 | } |
Dominik Laskowski | 989de3d | 2021-07-27 21:09:34 -0700 | [diff] [blame] | 558 | t.setLayerStack(control, ui::DEFAULT_LAYER_STACK); |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 561 | t.setLayer(control, 0x40000000) |
| 562 | .apply(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 564 | sp<Surface> s = control->getSurface(); |
| 565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | // initialize opengl and egl |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 568 | eglInitialize(display, nullptr, nullptr); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 569 | EGLConfig config = getEglConfig(display); |
| 570 | EGLSurface surface = eglCreateWindowSurface(display, config, s.get(), nullptr); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 571 | // Initialize egl context with client version number 2.0. |
| 572 | EGLint contextAttributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; |
| 573 | EGLContext context = eglCreateContext(display, config, nullptr, contextAttributes); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 574 | EGLint w, h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | eglQuerySurface(display, surface, EGL_WIDTH, &w); |
| 576 | eglQuerySurface(display, surface, EGL_HEIGHT, &h); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 577 | |
Mathias Agopian | abac010 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 578 | if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) |
| 579 | return NO_INIT; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | mDisplay = display; |
| 582 | mContext = context; |
| 583 | mSurface = surface; |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 584 | mInitWidth = mWidth = w; |
| 585 | mInitHeight = mHeight = h; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 586 | mFlingerSurfaceControl = control; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | mFlingerSurface = s; |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 588 | mTargetInset = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | |
Mariia Sandrikova | a166f01 | 2022-12-10 02:32:14 +0000 | [diff] [blame] | 590 | // Rotate the boot animation according to the value specified in the sysprop |
| 591 | // ro.bootanim.set_orientation_<display_id>. Four values are supported: ORIENTATION_0, |
| 592 | // ORIENTATION_90, ORIENTATION_180 and ORIENTATION_270. |
| 593 | // If the value isn't specified or is ORIENTATION_0, nothing will be changed. |
| 594 | // This is needed to support having boot animation in orientations different from the natural |
| 595 | // device orientation. For example, on tablets that may want to keep natural orientation |
| 596 | // portrait for applications compatibility and to have the boot animation in landscape. |
| 597 | rotateAwayFromNaturalOrientationIfNeeded(); |
| 598 | |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 599 | projectSceneToWindow(); |
| 600 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 601 | // Register a display event receiver |
| 602 | mDisplayEventReceiver = std::make_unique<DisplayEventReceiver>(); |
| 603 | status_t status = mDisplayEventReceiver->initCheck(); |
| 604 | SLOGE_IF(status != NO_ERROR, "Initialization of DisplayEventReceiver failed with status: %d", |
| 605 | status); |
| 606 | mLooper->addFd(mDisplayEventReceiver->getFd(), 0, Looper::EVENT_INPUT, |
| 607 | new DisplayEventCallback(this), nullptr); |
| 608 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 609 | return NO_ERROR; |
| 610 | } |
| 611 | |
Mariia Sandrikova | a166f01 | 2022-12-10 02:32:14 +0000 | [diff] [blame] | 612 | void BootAnimation::rotateAwayFromNaturalOrientationIfNeeded() { |
| 613 | const auto orientation = parseOrientationProperty(); |
| 614 | |
| 615 | if (orientation == ui::ROTATION_0) { |
| 616 | // Do nothing if the sysprop isn't set or is set to ROTATION_0. |
| 617 | return; |
| 618 | } |
| 619 | |
| 620 | if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) { |
| 621 | std::swap(mWidth, mHeight); |
| 622 | std::swap(mInitWidth, mInitHeight); |
| 623 | mFlingerSurfaceControl->updateDefaultBufferSize(mWidth, mHeight); |
| 624 | } |
| 625 | |
| 626 | Rect displayRect(0, 0, mWidth, mHeight); |
| 627 | Rect layerStackRect(0, 0, mWidth, mHeight); |
| 628 | |
| 629 | SurfaceComposerClient::Transaction t; |
| 630 | t.setDisplayProjection(mDisplayToken, orientation, layerStackRect, displayRect); |
| 631 | t.apply(); |
| 632 | } |
| 633 | |
| 634 | ui::Rotation BootAnimation::parseOrientationProperty() { |
| 635 | const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds(); |
| 636 | if (displayIds.size() == 0) { |
| 637 | return ui::ROTATION_0; |
| 638 | } |
| 639 | const auto displayId = displayIds[0]; |
| 640 | const auto syspropName = [displayId] { |
| 641 | std::stringstream ss; |
| 642 | ss << "ro.bootanim.set_orientation_" << displayId.value; |
| 643 | return ss.str(); |
| 644 | }(); |
| 645 | const auto syspropValue = android::base::GetProperty(syspropName, "ORIENTATION_0"); |
| 646 | if (syspropValue == "ORIENTATION_90") { |
| 647 | return ui::ROTATION_90; |
| 648 | } else if (syspropValue == "ORIENTATION_180") { |
| 649 | return ui::ROTATION_180; |
| 650 | } else if (syspropValue == "ORIENTATION_270") { |
| 651 | return ui::ROTATION_270; |
| 652 | } |
| 653 | return ui::ROTATION_0; |
| 654 | } |
| 655 | |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 656 | void BootAnimation::projectSceneToWindow() { |
| 657 | glViewport(0, 0, mWidth, mHeight); |
| 658 | glScissor(0, 0, mWidth, mHeight); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 659 | } |
| 660 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 661 | void BootAnimation::resizeSurface(int newWidth, int newHeight) { |
| 662 | // We assume this function is called on the animation thread. |
| 663 | if (newWidth == mWidth && newHeight == mHeight) { |
| 664 | return; |
| 665 | } |
| 666 | SLOGV("Resizing the boot animation surface to %d %d", newWidth, newHeight); |
| 667 | |
| 668 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 669 | eglDestroySurface(mDisplay, mSurface); |
| 670 | |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 671 | mFlingerSurfaceControl->updateDefaultBufferSize(newWidth, newHeight); |
Marin Shalamanov | 047802d | 2020-05-19 23:55:12 +0200 | [diff] [blame] | 672 | const auto limitedSize = limitSurfaceSize(newWidth, newHeight); |
| 673 | mWidth = limitedSize.width; |
| 674 | mHeight = limitedSize.height; |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 675 | |
| 676 | SurfaceComposerClient::Transaction t; |
| 677 | t.setSize(mFlingerSurfaceControl, mWidth, mHeight); |
| 678 | t.apply(); |
| 679 | |
| 680 | EGLConfig config = getEglConfig(mDisplay); |
| 681 | EGLSurface surface = eglCreateWindowSurface(mDisplay, config, mFlingerSurface.get(), nullptr); |
| 682 | if (eglMakeCurrent(mDisplay, surface, surface, mContext) == EGL_FALSE) { |
| 683 | SLOGE("Can't make the new surface current. Error %d", eglGetError()); |
| 684 | return; |
| 685 | } |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 686 | |
| 687 | projectSceneToWindow(); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 688 | |
| 689 | mSurface = surface; |
| 690 | } |
| 691 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 692 | bool BootAnimation::preloadAnimation() { |
| 693 | findBootAnimationFile(); |
Tomasz Wasilczyk | e8fb3c7 | 2023-08-24 19:11:22 +0000 | [diff] [blame] | 694 | if (!mZipFileName.empty()) { |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 695 | mAnimation = loadAnimation(mZipFileName); |
| 696 | return (mAnimation != nullptr); |
| 697 | } |
| 698 | |
| 699 | return false; |
| 700 | } |
| 701 | |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 702 | bool BootAnimation::findBootAnimationFileInternal(const std::vector<std::string> &files) { |
| 703 | for (const std::string& f : files) { |
| 704 | if (access(f.c_str(), R_OK) == 0) { |
| 705 | mZipFileName = f.c_str(); |
| 706 | return true; |
| 707 | } |
| 708 | } |
| 709 | return false; |
| 710 | } |
| 711 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 712 | void BootAnimation::findBootAnimationFile() { |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 713 | // If the device has encryption turned on or is in process |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 714 | // of being encrypted we show the encrypted boot animation. |
| 715 | char decrypt[PROPERTY_VALUE_MAX]; |
| 716 | property_get("vold.decrypt", decrypt, ""); |
| 717 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 718 | bool encryptedAnimation = atoi(decrypt) != 0 || |
| 719 | !strcmp("trigger_restart_min_framework", decrypt); |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 720 | |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 721 | if (!mShuttingDown && encryptedAnimation) { |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 722 | static const std::vector<std::string> encryptedBootFiles = { |
| 723 | PRODUCT_ENCRYPTED_BOOTANIMATION_FILE, SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, |
| 724 | }; |
| 725 | if (findBootAnimationFileInternal(encryptedBootFiles)) { |
| 726 | return; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 727 | } |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 728 | } |
Beverly | 34ffe25 | 2019-05-17 11:03:54 -0400 | [diff] [blame] | 729 | |
| 730 | const bool playDarkAnim = android::base::GetIntProperty("ro.boot.theme", 0) == 1; |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 731 | static const std::vector<std::string> bootFiles = { |
| 732 | APEX_BOOTANIMATION_FILE, playDarkAnim ? PRODUCT_BOOTANIMATION_DARK_FILE : PRODUCT_BOOTANIMATION_FILE, |
| 733 | OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE |
| 734 | }; |
| 735 | static const std::vector<std::string> shutdownFiles = { |
| 736 | PRODUCT_SHUTDOWNANIMATION_FILE, OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE, "" |
| 737 | }; |
| 738 | static const std::vector<std::string> userspaceRebootFiles = { |
| 739 | PRODUCT_USERSPACE_REBOOT_ANIMATION_FILE, OEM_USERSPACE_REBOOT_ANIMATION_FILE, |
| 740 | SYSTEM_USERSPACE_REBOOT_ANIMATION_FILE, |
| 741 | }; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 742 | |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 743 | if (android::base::GetBoolProperty("sys.init.userspace_reboot.in_progress", false)) { |
| 744 | findBootAnimationFileInternal(userspaceRebootFiles); |
| 745 | } else if (mShuttingDown) { |
| 746 | findBootAnimationFileInternal(shutdownFiles); |
| 747 | } else { |
| 748 | findBootAnimationFileInternal(bootFiles); |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 749 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | } |
| 751 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 752 | GLuint compileShader(GLenum shaderType, const GLchar *source) { |
| 753 | GLuint shader = glCreateShader(shaderType); |
| 754 | glShaderSource(shader, 1, &source, 0); |
| 755 | glCompileShader(shader); |
| 756 | GLint isCompiled = 0; |
| 757 | glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled); |
| 758 | if (isCompiled == GL_FALSE) { |
| 759 | SLOGE("Compile shader failed. Shader type: %d", shaderType); |
Shan Huang | 81846ba | 2021-09-07 19:07:47 +0000 | [diff] [blame] | 760 | GLint maxLength = 0; |
| 761 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); |
| 762 | std::vector<GLchar> errorLog(maxLength); |
| 763 | glGetShaderInfoLog(shader, maxLength, &maxLength, &errorLog[0]); |
| 764 | SLOGE("Shader compilation error: %s", &errorLog[0]); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 765 | return 0; |
| 766 | } |
| 767 | return shader; |
| 768 | } |
| 769 | |
| 770 | GLuint linkShader(GLuint vertexShader, GLuint fragmentShader) { |
| 771 | GLuint program = glCreateProgram(); |
| 772 | glAttachShader(program, vertexShader); |
| 773 | glAttachShader(program, fragmentShader); |
| 774 | glLinkProgram(program); |
| 775 | GLint isLinked = 0; |
| 776 | glGetProgramiv(program, GL_LINK_STATUS, (int *)&isLinked); |
| 777 | if (isLinked == GL_FALSE) { |
| 778 | SLOGE("Linking shader failed. Shader handles: vert %d, frag %d", |
| 779 | vertexShader, fragmentShader); |
| 780 | return 0; |
| 781 | } |
| 782 | return program; |
| 783 | } |
| 784 | |
| 785 | void BootAnimation::initShaders() { |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 786 | bool dynamicColoringEnabled = mAnimation != nullptr && mAnimation->dynamicColoringEnabled; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 787 | GLuint vertexShader = compileShader(GL_VERTEX_SHADER, (const GLchar *)VERTEX_SHADER_SOURCE); |
| 788 | GLuint imageFragmentShader = |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 789 | compileShader(GL_FRAGMENT_SHADER, dynamicColoringEnabled |
| 790 | ? (const GLchar *)IMAGE_FRAG_DYNAMIC_COLORING_SHADER_SOURCE |
| 791 | : (const GLchar *)IMAGE_FRAG_SHADER_SOURCE); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 792 | GLuint textFragmentShader = |
| 793 | compileShader(GL_FRAGMENT_SHADER, (const GLchar *)TEXT_FRAG_SHADER_SOURCE); |
| 794 | |
| 795 | // Initialize image shader. |
| 796 | mImageShader = linkShader(vertexShader, imageFragmentShader); |
| 797 | GLint positionLocation = glGetAttribLocation(mImageShader, A_POSITION); |
| 798 | GLint uvLocation = glGetAttribLocation(mImageShader, A_UV); |
| 799 | mImageTextureLocation = glGetUniformLocation(mImageShader, U_TEXTURE); |
| 800 | mImageFadeLocation = glGetUniformLocation(mImageShader, U_FADE); |
| 801 | glEnableVertexAttribArray(positionLocation); |
| 802 | glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, quadPositions); |
| 803 | glVertexAttribPointer(uvLocation, 2, GL_FLOAT, GL_FALSE, 0, quadUVs); |
| 804 | glEnableVertexAttribArray(uvLocation); |
| 805 | |
| 806 | // Initialize text shader. |
| 807 | mTextShader = linkShader(vertexShader, textFragmentShader); |
| 808 | positionLocation = glGetAttribLocation(mTextShader, A_POSITION); |
| 809 | uvLocation = glGetAttribLocation(mTextShader, A_UV); |
| 810 | mTextTextureLocation = glGetUniformLocation(mTextShader, U_TEXTURE); |
| 811 | mTextCropAreaLocation = glGetUniformLocation(mTextShader, U_CROP_AREA); |
| 812 | glEnableVertexAttribArray(positionLocation); |
| 813 | glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, quadPositions); |
| 814 | glVertexAttribPointer(uvLocation, 2, GL_FLOAT, GL_FALSE, 0, quadUVs); |
| 815 | glEnableVertexAttribArray(uvLocation); |
| 816 | } |
| 817 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 818 | bool BootAnimation::threadLoop() { |
| 819 | bool result; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 820 | initShaders(); |
| 821 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 822 | // We have no bootanimation file, so we use the stock android logo |
| 823 | // animation. |
Tomasz Wasilczyk | e8fb3c7 | 2023-08-24 19:11:22 +0000 | [diff] [blame] | 824 | if (mZipFileName.empty()) { |
Yoshiaki Maruoka | 9ef19b8 | 2017-10-25 13:55:49 +0900 | [diff] [blame] | 825 | ALOGD("No animation file"); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 826 | result = android(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 827 | } else { |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 828 | result = movie(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Philip Junker | 6060056 | 2020-11-25 18:16:16 +0100 | [diff] [blame] | 831 | mCallbacks->shutdown(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 833 | eglDestroyContext(mDisplay, mContext); |
| 834 | eglDestroySurface(mDisplay, mSurface); |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 835 | mFlingerSurface.clear(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 836 | mFlingerSurfaceControl.clear(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 837 | eglTerminate(mDisplay); |
Sai Kiran Korwar | 3eee9fb | 2015-06-16 17:13:35 +0530 | [diff] [blame] | 838 | eglReleaseThread(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 839 | IPCThreadState::self()->stopProcess(); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 840 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | } |
| 842 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 843 | bool BootAnimation::android() { |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 844 | glActiveTexture(GL_TEXTURE0); |
| 845 | |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 846 | SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
Keun-young Park | d1794cd | 2017-04-04 12:21:19 -0700 | [diff] [blame] | 847 | elapsedRealtime()); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 848 | initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); |
| 849 | initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 851 | mCallbacks->init({}); |
| 852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | // clear screen |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 854 | glDisable(GL_DITHER); |
| 855 | glDisable(GL_SCISSOR_TEST); |
Shan Huang | bfd2d3c | 2021-09-09 23:19:04 +0000 | [diff] [blame] | 856 | glUseProgram(mImageShader); |
| 857 | |
Mathias Agopian | 59f19e4 | 2011-05-06 19:22:12 -0700 | [diff] [blame] | 858 | glClearColor(0,0,0,1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 859 | glClear(GL_COLOR_BUFFER_BIT); |
| 860 | eglSwapBuffers(mDisplay, mSurface); |
| 861 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 862 | // Blend state |
| 863 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 865 | const nsecs_t startTime = systemTime(); |
| 866 | do { |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 867 | processDisplayEvents(); |
| 868 | const GLint xc = (mWidth - mAndroid[0].w) / 2; |
| 869 | const GLint yc = (mHeight - mAndroid[0].h) / 2; |
| 870 | const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h); |
| 871 | glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(), |
| 872 | updateRect.height()); |
| 873 | |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 874 | nsecs_t now = systemTime(); |
| 875 | double time = now - startTime; |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 876 | float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w; |
| 877 | GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w; |
| 878 | GLint x = xc - offset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | |
Mathias Agopian | 8166864 | 2009-07-28 11:41:30 -0700 | [diff] [blame] | 880 | glDisable(GL_SCISSOR_TEST); |
| 881 | glClear(GL_COLOR_BUFFER_BIT); |
| 882 | |
| 883 | glEnable(GL_SCISSOR_TEST); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | glDisable(GL_BLEND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | glBindTexture(GL_TEXTURE_2D, mAndroid[1].name); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 886 | drawTexturedQuad(x, yc, mAndroid[1].w, mAndroid[1].h); |
| 887 | drawTexturedQuad(x + mAndroid[1].w, yc, mAndroid[1].w, mAndroid[1].h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 889 | glEnable(GL_BLEND); |
| 890 | glBindTexture(GL_TEXTURE_2D, mAndroid[0].name); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 891 | drawTexturedQuad(xc, yc, mAndroid[0].w, mAndroid[0].h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 893 | EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); |
| 894 | if (res == EGL_FALSE) |
| 895 | break; |
| 896 | |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 897 | // 12fps: don't animate too fast to preserve CPU |
| 898 | const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); |
| 899 | if (sleepTime > 0) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 900 | usleep(sleepTime); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 901 | |
| 902 | checkExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | } while (!exitPending()); |
| 904 | |
| 905 | glDeleteTextures(1, &mAndroid[0].name); |
| 906 | glDeleteTextures(1, &mAndroid[1].name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | return false; |
| 908 | } |
| 909 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 910 | void BootAnimation::checkExit() { |
| 911 | // Allow surface flinger to gracefully request shutdown |
| 912 | char value[PROPERTY_VALUE_MAX]; |
| 913 | property_get(EXIT_PROP_NAME, value, "0"); |
| 914 | int exitnow = atoi(value); |
| 915 | if (exitnow) { |
| 916 | requestExit(); |
| 917 | } |
| 918 | } |
| 919 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 920 | bool BootAnimation::validClock(const Animation::Part& part) { |
| 921 | return part.clockPosX != TEXT_MISSING_VALUE && part.clockPosY != TEXT_MISSING_VALUE; |
| 922 | } |
| 923 | |
| 924 | bool parseTextCoord(const char* str, int* dest) { |
| 925 | if (strcmp("c", str) == 0) { |
| 926 | *dest = TEXT_CENTER_VALUE; |
| 927 | return true; |
| 928 | } |
| 929 | |
| 930 | char* end; |
| 931 | int val = (int) strtol(str, &end, 0); |
| 932 | if (end == str || *end != '\0' || val == INT_MAX || val == INT_MIN) { |
| 933 | return false; |
| 934 | } |
| 935 | *dest = val; |
| 936 | return true; |
| 937 | } |
| 938 | |
| 939 | // Parse two position coordinates. If only string is non-empty, treat it as the y value. |
| 940 | void parsePosition(const char* str1, const char* str2, int* x, int* y) { |
| 941 | bool success = false; |
| 942 | if (strlen(str1) == 0) { // No values were specified |
| 943 | // success = false |
| 944 | } else if (strlen(str2) == 0) { // we have only one value |
| 945 | if (parseTextCoord(str1, y)) { |
| 946 | *x = TEXT_CENTER_VALUE; |
| 947 | success = true; |
| 948 | } |
| 949 | } else { |
| 950 | if (parseTextCoord(str1, x) && parseTextCoord(str2, y)) { |
| 951 | success = true; |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | if (!success) { |
| 956 | *x = TEXT_MISSING_VALUE; |
| 957 | *y = TEXT_MISSING_VALUE; |
| 958 | } |
| 959 | } |
| 960 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 961 | // Parse a color represented as an HTML-style 'RRGGBB' string: each pair of |
| 962 | // characters in str is a hex number in [0, 255], which are converted to |
| 963 | // floating point values in the range [0.0, 1.0] and placed in the |
| 964 | // corresponding elements of color. |
| 965 | // |
| 966 | // If the input string isn't valid, parseColor returns false and color is |
| 967 | // left unchanged. |
| 968 | static bool parseColor(const char str[7], float color[3]) { |
| 969 | float tmpColor[3]; |
| 970 | for (int i = 0; i < 3; i++) { |
| 971 | int val = 0; |
| 972 | for (int j = 0; j < 2; j++) { |
| 973 | val *= 16; |
| 974 | char c = str[2*i + j]; |
| 975 | if (c >= '0' && c <= '9') val += c - '0'; |
| 976 | else if (c >= 'A' && c <= 'F') val += (c - 'A') + 10; |
| 977 | else if (c >= 'a' && c <= 'f') val += (c - 'a') + 10; |
| 978 | else return false; |
| 979 | } |
| 980 | tmpColor[i] = static_cast<float>(val) / 255.0f; |
| 981 | } |
| 982 | memcpy(color, tmpColor, sizeof(tmpColor)); |
| 983 | return true; |
| 984 | } |
| 985 | |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 986 | // Parse a color represented as a signed decimal int string. |
| 987 | // E.g. "-2757722" (whose hex 2's complement is 0xFFD5EBA6). |
| 988 | // If the input color string is empty, set color with values in defaultColor. |
| 989 | static void parseColorDecimalString(const std::string& colorString, |
| 990 | float color[3], float defaultColor[3]) { |
| 991 | if (colorString == "") { |
| 992 | memcpy(color, defaultColor, sizeof(float) * 3); |
| 993 | return; |
| 994 | } |
| 995 | int colorInt = atoi(colorString.c_str()); |
| 996 | color[0] = ((float)((colorInt >> 16) & 0xFF)) / 0xFF; // r |
| 997 | color[1] = ((float)((colorInt >> 8) & 0xFF)) / 0xFF; // g |
| 998 | color[2] = ((float)(colorInt & 0xFF)) / 0xFF; // b |
| 999 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1000 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1001 | static bool readFile(ZipFileRO* zip, const char* name, String8& outString) { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1002 | ZipEntryRO entry = zip->findEntryByName(name); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1003 | SLOGE_IF(!entry, "couldn't find %s", name); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1004 | if (!entry) { |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1008 | FileMap* entryMap = zip->createEntryFileMap(entry); |
| 1009 | zip->releaseEntry(entry); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1010 | SLOGE_IF(!entryMap, "entryMap is null"); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1011 | if (!entryMap) { |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength()); |
Narayan Kamath | 688ff4c | 2015-02-23 15:47:54 +0000 | [diff] [blame] | 1016 | delete entryMap; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1017 | return true; |
| 1018 | } |
| 1019 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1020 | // The font image should be a 96x2 array of character images. The |
| 1021 | // columns are the printable ASCII characters 0x20 - 0x7f. The |
| 1022 | // top row is regular text; the bottom row is bold. |
| 1023 | status_t BootAnimation::initFont(Font* font, const char* fallback) { |
| 1024 | status_t status = NO_ERROR; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1025 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1026 | if (font->map != nullptr) { |
| 1027 | glGenTextures(1, &font->texture.name); |
| 1028 | glBindTexture(GL_TEXTURE_2D, font->texture.name); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1029 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1030 | status = initTexture(font->map, &font->texture.w, &font->texture.h); |
| 1031 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1032 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1033 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1034 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1035 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1036 | } else if (fallback != nullptr) { |
| 1037 | status = initTexture(&font->texture, mAssets, fallback); |
| 1038 | } else { |
| 1039 | return NO_INIT; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1040 | } |
| 1041 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1042 | if (status == NO_ERROR) { |
| 1043 | font->char_width = font->texture.w / FONT_NUM_COLS; |
| 1044 | font->char_height = font->texture.h / FONT_NUM_ROWS / 2; // There are bold and regular rows |
| 1045 | } |
| 1046 | |
| 1047 | return status; |
| 1048 | } |
| 1049 | |
| 1050 | void BootAnimation::drawText(const char* str, const Font& font, bool bold, int* x, int* y) { |
| 1051 | glEnable(GL_BLEND); // Allow us to draw on top of the animation |
| 1052 | glBindTexture(GL_TEXTURE_2D, font.texture.name); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1053 | glUseProgram(mTextShader); |
| 1054 | glUniform1i(mTextTextureLocation, 0); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1055 | |
| 1056 | const int len = strlen(str); |
| 1057 | const int strWidth = font.char_width * len; |
| 1058 | |
| 1059 | if (*x == TEXT_CENTER_VALUE) { |
| 1060 | *x = (mWidth - strWidth) / 2; |
| 1061 | } else if (*x < 0) { |
| 1062 | *x = mWidth + *x - strWidth; |
| 1063 | } |
| 1064 | if (*y == TEXT_CENTER_VALUE) { |
| 1065 | *y = (mHeight - font.char_height) / 2; |
| 1066 | } else if (*y < 0) { |
| 1067 | *y = mHeight + *y - font.char_height; |
| 1068 | } |
| 1069 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1070 | for (int i = 0; i < len; i++) { |
| 1071 | char c = str[i]; |
| 1072 | |
| 1073 | if (c < FONT_BEGIN_CHAR || c > FONT_END_CHAR) { |
| 1074 | c = '?'; |
| 1075 | } |
| 1076 | |
| 1077 | // Crop the texture to only the pixels in the current glyph |
| 1078 | const int charPos = (c - FONT_BEGIN_CHAR); // Position in the list of valid characters |
| 1079 | const int row = charPos / FONT_NUM_COLS; |
| 1080 | const int col = charPos % FONT_NUM_COLS; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1081 | // Bold fonts are expected in the second half of each row. |
| 1082 | float v0 = (row + (bold ? 0.5f : 0.0f)) / FONT_NUM_ROWS; |
| 1083 | float u0 = ((float)col) / FONT_NUM_COLS; |
| 1084 | float v1 = v0 + 1.0f / FONT_NUM_ROWS / 2; |
| 1085 | float u1 = u0 + 1.0f / FONT_NUM_COLS; |
| 1086 | glUniform4f(mTextCropAreaLocation, u0, v0, u1, v1); |
| 1087 | drawTexturedQuad(*x, *y, font.char_width, font.char_height); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1088 | |
| 1089 | *x += font.char_width; |
| 1090 | } |
| 1091 | |
| 1092 | glDisable(GL_BLEND); // Return to the animation's default behaviour |
| 1093 | glBindTexture(GL_TEXTURE_2D, 0); |
| 1094 | } |
| 1095 | |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 1096 | // We render 12 or 24 hour time. |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1097 | void BootAnimation::drawClock(const Font& font, const int xPos, const int yPos) { |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 1098 | static constexpr char TIME_FORMAT_12[] = "%l:%M"; |
| 1099 | static constexpr char TIME_FORMAT_24[] = "%H:%M"; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1100 | static constexpr int TIME_LENGTH = 6; |
| 1101 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1102 | time_t rawtime; |
| 1103 | time(&rawtime); |
| 1104 | struct tm* timeInfo = localtime(&rawtime); |
| 1105 | |
| 1106 | char timeBuff[TIME_LENGTH]; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 1107 | const char* timeFormat = mTimeFormat12Hour ? TIME_FORMAT_12 : TIME_FORMAT_24; |
| 1108 | size_t length = strftime(timeBuff, TIME_LENGTH, timeFormat, timeInfo); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1109 | |
| 1110 | if (length != TIME_LENGTH - 1) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1111 | SLOGE("Couldn't format time; abandoning boot animation clock"); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1112 | mClockEnabled = false; |
| 1113 | return; |
| 1114 | } |
| 1115 | |
Damien Bargiacchi | 45a7644 | 2016-12-05 18:02:18 -0800 | [diff] [blame] | 1116 | char* out = timeBuff[0] == ' ' ? &timeBuff[1] : &timeBuff[0]; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1117 | int x = xPos; |
| 1118 | int y = yPos; |
Damien Bargiacchi | 45a7644 | 2016-12-05 18:02:18 -0800 | [diff] [blame] | 1119 | drawText(out, font, false, &x, &y); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1120 | } |
| 1121 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1122 | void BootAnimation::drawProgress(int percent, const Font& font, const int xPos, const int yPos) { |
| 1123 | static constexpr int PERCENT_LENGTH = 5; |
| 1124 | |
| 1125 | char percentBuff[PERCENT_LENGTH]; |
| 1126 | // ';' has the ascii code just after ':', and the font resource contains '%' |
| 1127 | // for that ascii code. |
| 1128 | sprintf(percentBuff, "%d;", percent); |
| 1129 | int x = xPos; |
| 1130 | int y = yPos; |
| 1131 | drawText(percentBuff, font, false, &x, &y); |
| 1132 | } |
| 1133 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1134 | bool BootAnimation::parseAnimationDesc(Animation& animation) { |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1135 | String8 desString; |
| 1136 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1137 | if (!readFile(animation.zip, "desc.txt", desString)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1138 | return false; |
| 1139 | } |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame] | 1140 | char const* s = desString.c_str(); |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1141 | std::string dynamicColoringPartName = ""; |
| 1142 | bool postDynamicColoring = false; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1143 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1144 | // Parse the description file |
| 1145 | for (;;) { |
| 1146 | const char* endl = strstr(s, "\n"); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1147 | if (endl == nullptr) break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1148 | String8 line(s, endl - s); |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame] | 1149 | const char* l = line.c_str(); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1150 | int fps = 0; |
| 1151 | int width = 0; |
| 1152 | int height = 0; |
| 1153 | int count = 0; |
| 1154 | int pause = 0; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1155 | int progress = 0; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1156 | int framesToFadeCount = 0; |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1157 | int colorTransitionStart = 0; |
| 1158 | int colorTransitionEnd = 0; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1159 | char path[ANIM_ENTRY_NAME_MAX]; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 1160 | char color[7] = "000000"; // default to black if unspecified |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1161 | char clockPos1[TEXT_POS_LEN_MAX + 1] = ""; |
| 1162 | char clockPos2[TEXT_POS_LEN_MAX + 1] = ""; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1163 | char dynamicColoringPartNameBuffer[ANIM_ENTRY_NAME_MAX]; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1164 | char pathType; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1165 | // start colors default to black if unspecified |
| 1166 | char start_color_0[7] = "000000"; |
| 1167 | char start_color_1[7] = "000000"; |
| 1168 | char start_color_2[7] = "000000"; |
| 1169 | char start_color_3[7] = "000000"; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1170 | |
| 1171 | int nextReadPos; |
| 1172 | |
yidong zhang | 87bb346 | 2022-12-07 15:55:31 +0800 | [diff] [blame] | 1173 | if (strlen(l) == 0) { |
| 1174 | s = ++endl; |
| 1175 | continue; |
| 1176 | } |
| 1177 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1178 | int topLineNumbers = sscanf(l, "%d %d %d %d", &width, &height, &fps, &progress); |
| 1179 | if (topLineNumbers == 3 || topLineNumbers == 4) { |
| 1180 | // SLOGD("> w=%d, h=%d, fps=%d, progress=%d", width, height, fps, progress); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1181 | animation.width = width; |
| 1182 | animation.height = height; |
| 1183 | animation.fps = fps; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1184 | if (topLineNumbers == 4) { |
| 1185 | animation.progressEnabled = (progress != 0); |
| 1186 | } else { |
| 1187 | animation.progressEnabled = false; |
| 1188 | } |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1189 | } else if (sscanf(l, "dynamic_colors %" STRTO(ANIM_PATH_MAX) "s #%6s #%6s #%6s #%6s %d %d", |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1190 | dynamicColoringPartNameBuffer, |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1191 | start_color_0, start_color_1, start_color_2, start_color_3, |
| 1192 | &colorTransitionStart, &colorTransitionEnd)) { |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1193 | animation.dynamicColoringEnabled = true; |
| 1194 | parseColor(start_color_0, animation.startColors[0]); |
| 1195 | parseColor(start_color_1, animation.startColors[1]); |
| 1196 | parseColor(start_color_2, animation.startColors[2]); |
| 1197 | parseColor(start_color_3, animation.startColors[3]); |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1198 | animation.colorTransitionStart = colorTransitionStart; |
| 1199 | animation.colorTransitionEnd = colorTransitionEnd; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1200 | dynamicColoringPartName = std::string(dynamicColoringPartNameBuffer); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1201 | } else if (sscanf(l, "%c %d %d %" STRTO(ANIM_PATH_MAX) "s%n", |
| 1202 | &pathType, &count, &pause, path, &nextReadPos) >= 4) { |
| 1203 | if (pathType == 'f') { |
| 1204 | sscanf(l + nextReadPos, " %d #%6s %16s %16s", &framesToFadeCount, color, clockPos1, |
| 1205 | clockPos2); |
| 1206 | } else { |
| 1207 | sscanf(l + nextReadPos, " #%6s %16s %16s", color, clockPos1, clockPos2); |
| 1208 | } |
| 1209 | // SLOGD("> type=%c, count=%d, pause=%d, path=%s, framesToFadeCount=%d, color=%s, " |
| 1210 | // "clockPos1=%s, clockPos2=%s", |
| 1211 | // pathType, count, pause, path, framesToFadeCount, color, clockPos1, clockPos2); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1212 | Animation::Part part; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1213 | if (path == dynamicColoringPartName) { |
| 1214 | // Part is specified to use dynamic coloring. |
| 1215 | part.useDynamicColoring = true; |
| 1216 | part.postDynamicColoring = false; |
| 1217 | postDynamicColoring = true; |
| 1218 | } else { |
| 1219 | // Part does not use dynamic coloring. |
| 1220 | part.useDynamicColoring = false; |
| 1221 | part.postDynamicColoring = postDynamicColoring; |
| 1222 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1223 | part.playUntilComplete = pathType == 'c'; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1224 | part.framesToFadeCount = framesToFadeCount; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1225 | part.count = count; |
| 1226 | part.pause = pause; |
| 1227 | part.path = path; |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1228 | part.audioData = nullptr; |
| 1229 | part.animation = nullptr; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 1230 | if (!parseColor(color, part.backgroundColor)) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1231 | SLOGE("> invalid color '#%s'", color); |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 1232 | part.backgroundColor[0] = 0.0f; |
| 1233 | part.backgroundColor[1] = 0.0f; |
| 1234 | part.backgroundColor[2] = 0.0f; |
| 1235 | } |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1236 | parsePosition(clockPos1, clockPos2, &part.clockPosX, &part.clockPosY); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1237 | animation.parts.add(part); |
| 1238 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1239 | else if (strcmp(l, "$SYSTEM") == 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1240 | // SLOGD("> SYSTEM"); |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1241 | Animation::Part part; |
| 1242 | part.playUntilComplete = false; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1243 | part.framesToFadeCount = 0; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1244 | part.count = 1; |
| 1245 | part.pause = 0; |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1246 | part.audioData = nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1247 | part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE)); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1248 | if (part.animation != nullptr) |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1249 | animation.parts.add(part); |
| 1250 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1251 | s = ++endl; |
| 1252 | } |
| 1253 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1254 | return true; |
| 1255 | } |
| 1256 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1257 | bool BootAnimation::preloadZip(Animation& animation) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1258 | // read all the data structures |
| 1259 | const size_t pcount = animation.parts.size(); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1260 | void *cookie = nullptr; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1261 | ZipFileRO* zip = animation.zip; |
| 1262 | if (!zip->startIteration(&cookie)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1263 | return false; |
| 1264 | } |
| 1265 | |
| 1266 | ZipEntryRO entry; |
| 1267 | char name[ANIM_ENTRY_NAME_MAX]; |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1268 | while ((entry = zip->nextEntry(cookie)) != nullptr) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1269 | const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1270 | if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1271 | SLOGE("Error fetching entry file name"); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1272 | continue; |
| 1273 | } |
| 1274 | |
Tomasz Wasilczyk | 9dcea57 | 2023-08-22 20:39:20 +0000 | [diff] [blame] | 1275 | const std::filesystem::path entryName(name); |
| 1276 | const std::filesystem::path path(entryName.parent_path()); |
| 1277 | const std::filesystem::path leaf(entryName.filename()); |
| 1278 | if (!leaf.empty()) { |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1279 | if (entryName == CLOCK_FONT_ZIP_NAME) { |
| 1280 | FileMap* map = zip->createEntryFileMap(entry); |
| 1281 | if (map) { |
| 1282 | animation.clockFont.map = map; |
| 1283 | } |
| 1284 | continue; |
| 1285 | } |
| 1286 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1287 | if (entryName == PROGRESS_FONT_ZIP_NAME) { |
| 1288 | FileMap* map = zip->createEntryFileMap(entry); |
| 1289 | if (map) { |
| 1290 | animation.progressFont.map = map; |
| 1291 | } |
| 1292 | continue; |
| 1293 | } |
| 1294 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1295 | for (size_t j = 0; j < pcount; j++) { |
Tomasz Wasilczyk | 9dcea57 | 2023-08-22 20:39:20 +0000 | [diff] [blame] | 1296 | if (path.string() == animation.parts[j].path.c_str()) { |
Narayan Kamath | 4600dd0 | 2015-06-16 12:02:57 +0100 | [diff] [blame] | 1297 | uint16_t method; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1298 | // supports only stored png files |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1299 | if (zip->getEntryInfo(entry, &method, nullptr, nullptr, nullptr, nullptr, nullptr)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1300 | if (method == ZipFileRO::kCompressStored) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1301 | FileMap* map = zip->createEntryFileMap(entry); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1302 | if (map) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1303 | Animation::Part& part(animation.parts.editItemAt(j)); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1304 | if (leaf == "audio.wav") { |
| 1305 | // a part may have at most one audio file |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 1306 | part.audioData = (uint8_t *)map->getDataPtr(); |
| 1307 | part.audioLength = map->getDataLength(); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1308 | } else if (leaf == "trim.txt") { |
| 1309 | part.trimData.setTo((char const*)map->getDataPtr(), |
| 1310 | map->getDataLength()); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1311 | } else { |
| 1312 | Animation::Frame frame; |
Tomasz Wasilczyk | 9dcea57 | 2023-08-22 20:39:20 +0000 | [diff] [blame] | 1313 | frame.name = leaf.c_str(); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1314 | frame.map = map; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1315 | frame.trimWidth = animation.width; |
| 1316 | frame.trimHeight = animation.height; |
| 1317 | frame.trimX = 0; |
| 1318 | frame.trimY = 0; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1319 | part.frames.add(frame); |
| 1320 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1321 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 1322 | } else { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1323 | SLOGE("bootanimation.zip is compressed; must be only stored"); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1331 | // If there is trimData present, override the positioning defaults. |
| 1332 | for (Animation::Part& part : animation.parts) { |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame] | 1333 | const char* trimDataStr = part.trimData.c_str(); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1334 | for (size_t frameIdx = 0; frameIdx < part.frames.size(); frameIdx++) { |
| 1335 | const char* endl = strstr(trimDataStr, "\n"); |
| 1336 | // No more trimData for this part. |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1337 | if (endl == nullptr) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1338 | break; |
| 1339 | } |
| 1340 | String8 line(trimDataStr, endl - trimDataStr); |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame] | 1341 | const char* lineStr = line.c_str(); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1342 | trimDataStr = ++endl; |
| 1343 | int width = 0, height = 0, x = 0, y = 0; |
| 1344 | if (sscanf(lineStr, "%dx%d+%d+%d", &width, &height, &x, &y) == 4) { |
| 1345 | Animation::Frame& frame(part.frames.editItemAt(frameIdx)); |
| 1346 | frame.trimWidth = width; |
| 1347 | frame.trimHeight = height; |
| 1348 | frame.trimX = x; |
| 1349 | frame.trimY = y; |
| 1350 | } else { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1351 | SLOGE("Error parsing trim.txt, line: %s", lineStr); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1352 | break; |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | zip->endIteration(cookie); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1358 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1359 | return true; |
| 1360 | } |
| 1361 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1362 | bool BootAnimation::movie() { |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1363 | if (mAnimation == nullptr) { |
| 1364 | mAnimation = loadAnimation(mZipFileName); |
| 1365 | } |
| 1366 | |
| 1367 | if (mAnimation == nullptr) |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1368 | return false; |
| 1369 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1370 | // mCallbacks->init() may get called recursively, |
| 1371 | // this loop is needed to get the same results |
| 1372 | for (const Animation::Part& part : mAnimation->parts) { |
| 1373 | if (part.animation != nullptr) { |
| 1374 | mCallbacks->init(part.animation->parts); |
| 1375 | } |
| 1376 | } |
| 1377 | mCallbacks->init(mAnimation->parts); |
| 1378 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1379 | bool anyPartHasClock = false; |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1380 | for (size_t i=0; i < mAnimation->parts.size(); i++) { |
| 1381 | if(validClock(mAnimation->parts[i])) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1382 | anyPartHasClock = true; |
| 1383 | break; |
| 1384 | } |
| 1385 | } |
| 1386 | if (!anyPartHasClock) { |
| 1387 | mClockEnabled = false; |
Thiébaud Weksteen | 08de443 | 2021-11-18 13:25:59 +1100 | [diff] [blame] | 1388 | } else if (!android::base::GetBoolProperty(CLOCK_ENABLED_PROP_NAME, false)) { |
| 1389 | mClockEnabled = false; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 1392 | // Check if npot textures are supported |
| 1393 | mUseNpotTextures = false; |
| 1394 | String8 gl_extensions; |
| 1395 | const char* exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
| 1396 | if (!exts) { |
| 1397 | glGetError(); |
| 1398 | } else { |
| 1399 | gl_extensions.setTo(exts); |
| 1400 | if ((gl_extensions.find("GL_ARB_texture_non_power_of_two") != -1) || |
| 1401 | (gl_extensions.find("GL_OES_texture_npot") != -1)) { |
| 1402 | mUseNpotTextures = true; |
| 1403 | } |
| 1404 | } |
| 1405 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1406 | // Blend required to draw time on top of animation frames. |
| 1407 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1408 | glDisable(GL_DITHER); |
| 1409 | glDisable(GL_SCISSOR_TEST); |
| 1410 | glDisable(GL_BLEND); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1411 | |
Greg Kaiser | 2ded800 | 2021-07-19 17:03:27 +0000 | [diff] [blame] | 1412 | glEnable(GL_TEXTURE_2D); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1413 | glBindTexture(GL_TEXTURE_2D, 0); |
| 1414 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1415 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1416 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1417 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1418 | bool clockFontInitialized = false; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1419 | if (mClockEnabled) { |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1420 | clockFontInitialized = |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1421 | (initFont(&mAnimation->clockFont, CLOCK_FONT_ASSET) == NO_ERROR); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1422 | mClockEnabled = clockFontInitialized; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1423 | } |
| 1424 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1425 | initFont(&mAnimation->progressFont, PROGRESS_FONT_ASSET); |
| 1426 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1427 | if (mClockEnabled && !updateIsTimeAccurate()) { |
| 1428 | mTimeCheckThread = new TimeCheckThread(this); |
| 1429 | mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL); |
| 1430 | } |
| 1431 | |
George Burgess IV | 0f8e811 | 2021-08-23 17:32:23 -0700 | [diff] [blame] | 1432 | if (mAnimation->dynamicColoringEnabled) { |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1433 | initDynamicColors(); |
| 1434 | } |
| 1435 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1436 | playAnimation(*mAnimation); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1437 | |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 1438 | if (mTimeCheckThread != nullptr) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1439 | mTimeCheckThread->requestExit(); |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 1440 | mTimeCheckThread = nullptr; |
| 1441 | } |
| 1442 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1443 | if (clockFontInitialized) { |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1444 | glDeleteTextures(1, &mAnimation->clockFont.texture.name); |
Andriy Naborskyy | 815e51d | 2016-03-24 16:43:34 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1447 | releaseAnimation(mAnimation); |
| 1448 | mAnimation = nullptr; |
Damien Bargiacchi | 1a8a213 | 2018-07-24 15:20:26 -0700 | [diff] [blame] | 1449 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1450 | return false; |
| 1451 | } |
| 1452 | |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 1453 | bool BootAnimation::shouldStopPlayingPart(const Animation::Part& part, |
| 1454 | const int fadedFramesCount, |
| 1455 | const int lastDisplayedProgress) { |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1456 | // stop playing only if it is time to exit and it's a partial part which has been faded out |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 1457 | return exitPending() && !part.playUntilComplete && fadedFramesCount >= part.framesToFadeCount && |
| 1458 | (lastDisplayedProgress == 0 || lastDisplayedProgress == 100); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1459 | } |
| 1460 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1461 | // Linear mapping from range <a1, a2> to range <b1, b2> |
| 1462 | float mapLinear(float x, float a1, float a2, float b1, float b2) { |
| 1463 | return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 ); |
| 1464 | } |
| 1465 | |
| 1466 | void BootAnimation::drawTexturedQuad(float xStart, float yStart, float width, float height) { |
| 1467 | // Map coordinates from screen space to world space. |
| 1468 | float x0 = mapLinear(xStart, 0, mWidth, -1, 1); |
| 1469 | float y0 = mapLinear(yStart, 0, mHeight, -1, 1); |
| 1470 | float x1 = mapLinear(xStart + width, 0, mWidth, -1, 1); |
| 1471 | float y1 = mapLinear(yStart + height, 0, mHeight, -1, 1); |
| 1472 | // Update quad vertex positions. |
| 1473 | quadPositions[0] = x0; |
| 1474 | quadPositions[1] = y0; |
| 1475 | quadPositions[2] = x1; |
| 1476 | quadPositions[3] = y0; |
| 1477 | quadPositions[4] = x1; |
| 1478 | quadPositions[5] = y1; |
| 1479 | quadPositions[6] = x1; |
| 1480 | quadPositions[7] = y1; |
| 1481 | quadPositions[8] = x0; |
| 1482 | quadPositions[9] = y1; |
| 1483 | quadPositions[10] = x0; |
| 1484 | quadPositions[11] = y0; |
| 1485 | glDrawArrays(GL_TRIANGLES, 0, |
| 1486 | sizeof(quadPositions) / sizeof(quadPositions[0]) / 2); |
| 1487 | } |
| 1488 | |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1489 | void BootAnimation::initDynamicColors() { |
| 1490 | for (int i = 0; i < DYNAMIC_COLOR_COUNT; i++) { |
Lucas Dupin | cd25684 | 2022-03-29 15:46:36 -0700 | [diff] [blame] | 1491 | const auto syspropName = "persist.bootanim.color" + std::to_string(i + 1); |
| 1492 | const auto syspropValue = android::base::GetProperty(syspropName, ""); |
| 1493 | if (syspropValue != "") { |
| 1494 | SLOGI("Loaded dynamic color: %s -> %s", syspropName.c_str(), syspropValue.c_str()); |
| 1495 | mDynamicColorsApplied = true; |
| 1496 | } |
| 1497 | parseColorDecimalString(syspropValue, |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1498 | mAnimation->endColors[i], mAnimation->startColors[i]); |
| 1499 | } |
| 1500 | glUseProgram(mImageShader); |
Lucas Dupin | cd25684 | 2022-03-29 15:46:36 -0700 | [diff] [blame] | 1501 | SLOGI("Dynamically coloring boot animation. Sysprops loaded? %i", mDynamicColorsApplied); |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1502 | for (int i = 0; i < DYNAMIC_COLOR_COUNT; i++) { |
| 1503 | float *startColor = mAnimation->startColors[i]; |
| 1504 | float *endColor = mAnimation->endColors[i]; |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 1505 | glUniform3f(glGetUniformLocation(mImageShader, |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1506 | (U_START_COLOR_PREFIX + std::to_string(i)).c_str()), |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 1507 | startColor[0], startColor[1], startColor[2]); |
| 1508 | glUniform3f(glGetUniformLocation(mImageShader, |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1509 | (U_END_COLOR_PREFIX + std::to_string(i)).c_str()), |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 1510 | endColor[0], endColor[1], endColor[2]); |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1511 | } |
| 1512 | mImageColorProgressLocation = glGetUniformLocation(mImageShader, U_COLOR_PROGRESS); |
| 1513 | } |
| 1514 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1515 | bool BootAnimation::playAnimation(const Animation& animation) { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1516 | const size_t pcount = animation.parts.size(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1517 | nsecs_t frameDuration = s2ns(1) / animation.fps; |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 1518 | |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1519 | SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
Keun-young Park | d1794cd | 2017-04-04 12:21:19 -0700 | [diff] [blame] | 1520 | elapsedRealtime()); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1521 | |
| 1522 | int fadedFramesCount = 0; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1523 | int lastDisplayedProgress = 0; |
Lucas Dupin | bfd1812 | 2022-04-25 11:26:08 -0700 | [diff] [blame] | 1524 | int colorTransitionStart = animation.colorTransitionStart; |
| 1525 | int colorTransitionEnd = animation.colorTransitionEnd; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1526 | for (size_t i=0 ; i<pcount ; i++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1527 | const Animation::Part& part(animation.parts[i]); |
| 1528 | const size_t fcount = part.frames.size(); |
Oleg Lyovin | 6a4b84d | 2023-07-01 14:39:59 +0300 | [diff] [blame] | 1529 | glBindTexture(GL_TEXTURE_2D, 0); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1530 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1531 | // Handle animation package |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1532 | if (part.animation != nullptr) { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1533 | playAnimation(*part.animation); |
| 1534 | if (exitPending()) |
| 1535 | break; |
| 1536 | continue; //to next part |
| 1537 | } |
| 1538 | |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1539 | // process the part not only while the count allows but also if already fading |
| 1540 | for (int r=0 ; !part.count || r<part.count || fadedFramesCount > 0 ; r++) { |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 1541 | if (shouldStopPlayingPart(part, fadedFramesCount, lastDisplayedProgress)) break; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1542 | |
Lucas Dupin | bfd1812 | 2022-04-25 11:26:08 -0700 | [diff] [blame] | 1543 | // It's possible that the sysprops were not loaded yet at this boot phase. |
| 1544 | // If that's the case, then we should keep trying until they are available. |
| 1545 | if (animation.dynamicColoringEnabled && !mDynamicColorsApplied |
| 1546 | && (part.useDynamicColoring || part.postDynamicColoring)) { |
| 1547 | SLOGD("Trying to load dynamic color sysprops."); |
| 1548 | initDynamicColors(); |
| 1549 | if (mDynamicColorsApplied) { |
| 1550 | // Sysprops were loaded. Next step is to adjust the animation if we loaded |
| 1551 | // the colors after the animation should have started. |
| 1552 | const int transitionLength = colorTransitionEnd - colorTransitionStart; |
| 1553 | if (part.postDynamicColoring) { |
| 1554 | colorTransitionStart = 0; |
| 1555 | colorTransitionEnd = fmin(transitionLength, fcount - 1); |
| 1556 | } |
| 1557 | } |
| 1558 | } |
| 1559 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 1560 | mCallbacks->playPart(i, part, r); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1561 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 1562 | glClearColor( |
| 1563 | part.backgroundColor[0], |
| 1564 | part.backgroundColor[1], |
| 1565 | part.backgroundColor[2], |
| 1566 | 1.0f); |
| 1567 | |
Yoshiaki Maruoka | 9ef19b8 | 2017-10-25 13:55:49 +0900 | [diff] [blame] | 1568 | ALOGD("Playing files = %s/%s, Requested repeat = %d, playUntilComplete = %s", |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame] | 1569 | animation.fileName.c_str(), part.path.c_str(), part.count, |
Yoshiaki Maruoka | 9ef19b8 | 2017-10-25 13:55:49 +0900 | [diff] [blame] | 1570 | part.playUntilComplete ? "true" : "false"); |
| 1571 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1572 | // For the last animation, if we have progress indicator from |
| 1573 | // the system, display it. |
| 1574 | int currentProgress = android::base::GetIntProperty(PROGRESS_PROP_NAME, 0); |
| 1575 | bool displayProgress = animation.progressEnabled && |
| 1576 | (i == (pcount -1)) && currentProgress != 0; |
| 1577 | |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1578 | for (size_t j=0 ; j<fcount ; j++) { |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 1579 | if (shouldStopPlayingPart(part, fadedFramesCount, lastDisplayedProgress)) break; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1580 | |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1581 | // Color progress is |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1582 | // - the animation progress, normalized from |
| 1583 | // [colorTransitionStart,colorTransitionEnd] to [0, 1] for the dynamic coloring |
| 1584 | // part. |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1585 | // - 0 for parts that come before, |
| 1586 | // - 1 for parts that come after. |
| 1587 | float colorProgress = part.useDynamicColoring |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1588 | ? fmin(fmax( |
Lucas Dupin | bfd1812 | 2022-04-25 11:26:08 -0700 | [diff] [blame] | 1589 | ((float)j - colorTransitionStart) / |
| 1590 | fmax(colorTransitionEnd - colorTransitionStart, 1.0f), 0.0f), 1.0f) |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1591 | : (part.postDynamicColoring ? 1 : 0); |
| 1592 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1593 | processDisplayEvents(); |
| 1594 | |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 1595 | const double ratio_w = static_cast<double>(mWidth) / mInitWidth; |
| 1596 | const double ratio_h = static_cast<double>(mHeight) / mInitHeight; |
| 1597 | const int animationX = (mWidth - animation.width * ratio_w) / 2; |
| 1598 | const int animationY = (mHeight - animation.height * ratio_h) / 2; |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1599 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1600 | const Animation::Frame& frame(part.frames[j]); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 1601 | nsecs_t lastFrame = systemTime(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1602 | |
| 1603 | if (r > 0) { |
| 1604 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 1605 | } else { |
Oleg Lyovin | 6a4b84d | 2023-07-01 14:39:59 +0300 | [diff] [blame] | 1606 | if (part.count != 1) { |
| 1607 | glGenTextures(1, &frame.tid); |
| 1608 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 1609 | } |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1610 | int w, h; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1611 | // Set decoding option to alpha unpremultiplied so that the R, G, B channels |
| 1612 | // of transparent pixels are preserved. |
| 1613 | initTexture(frame.map, &w, &h, false /* don't premultiply alpha */); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 1616 | const int trimWidth = frame.trimWidth * ratio_w; |
| 1617 | const int trimHeight = frame.trimHeight * ratio_h; |
| 1618 | const int trimX = frame.trimX * ratio_w; |
| 1619 | const int trimY = frame.trimY * ratio_h; |
| 1620 | const int xc = animationX + trimX; |
| 1621 | const int yc = animationY + trimY; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1622 | glClear(GL_COLOR_BUFFER_BIT); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1623 | // specify the y center as ceiling((mHeight - frame.trimHeight) / 2) |
| 1624 | // which is equivalent to mHeight - (yc + frame.trimHeight) |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 1625 | const int frameDrawY = mHeight - (yc + trimHeight); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1626 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1627 | float fade = 0; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1628 | // if the part hasn't been stopped yet then continue fading if necessary |
| 1629 | if (exitPending() && part.hasFadingPhase()) { |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1630 | fade = static_cast<float>(++fadedFramesCount) / part.framesToFadeCount; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1631 | if (fadedFramesCount >= part.framesToFadeCount) { |
| 1632 | fadedFramesCount = MAX_FADED_FRAMES_COUNT; // no more fading |
| 1633 | } |
| 1634 | } |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1635 | glUseProgram(mImageShader); |
| 1636 | glUniform1i(mImageTextureLocation, 0); |
| 1637 | glUniform1f(mImageFadeLocation, fade); |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1638 | if (animation.dynamicColoringEnabled) { |
| 1639 | glUniform1f(mImageColorProgressLocation, colorProgress); |
| 1640 | } |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1641 | glEnable(GL_BLEND); |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 1642 | drawTexturedQuad(xc, frameDrawY, trimWidth, trimHeight); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1643 | glDisable(GL_BLEND); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1644 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1645 | if (mClockEnabled && mTimeIsAccurate && validClock(part)) { |
| 1646 | drawClock(animation.clockFont, part.clockPosX, part.clockPosY); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1647 | } |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1648 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1649 | if (displayProgress) { |
| 1650 | int newProgress = android::base::GetIntProperty(PROGRESS_PROP_NAME, 0); |
| 1651 | // In case the new progress jumped suddenly, still show an |
| 1652 | // increment of 1. |
| 1653 | if (lastDisplayedProgress != 100) { |
| 1654 | // Artificially sleep 1/10th a second to slow down the animation. |
| 1655 | usleep(100000); |
| 1656 | if (lastDisplayedProgress < newProgress) { |
| 1657 | lastDisplayedProgress++; |
| 1658 | } |
| 1659 | } |
| 1660 | // Put the progress percentage right below the animation. |
| 1661 | int posY = animation.height / 3; |
| 1662 | int posX = TEXT_CENTER_VALUE; |
| 1663 | drawProgress(lastDisplayedProgress, animation.progressFont, posX, posY); |
| 1664 | } |
| 1665 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1666 | handleViewport(frameDuration); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1667 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1668 | eglSwapBuffers(mDisplay, mSurface); |
| 1669 | |
| 1670 | nsecs_t now = systemTime(); |
| 1671 | nsecs_t delay = frameDuration - (now - lastFrame); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1672 | //SLOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay)); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1673 | lastFrame = now; |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 1674 | |
| 1675 | if (delay > 0) { |
| 1676 | struct timespec spec; |
| 1677 | spec.tv_sec = (now + delay) / 1000000000; |
| 1678 | spec.tv_nsec = (now + delay) % 1000000000; |
| 1679 | int err; |
| 1680 | do { |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1681 | err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, nullptr); |
Keith Mok | 0f2e668 | 2021-11-15 05:50:32 +0000 | [diff] [blame] | 1682 | } while (err == EINTR); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 1683 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1684 | |
| 1685 | checkExit(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1686 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1687 | |
niuwenchao | 9cd6ac8 | 2022-12-23 17:34:22 +0800 | [diff] [blame] | 1688 | int pauseDuration = part.pause * ns2us(frameDuration); |
| 1689 | while(pauseDuration > 0 && !exitPending()){ |
| 1690 | if (pauseDuration > MAX_CHECK_EXIT_INTERVAL_US) { |
| 1691 | usleep(MAX_CHECK_EXIT_INTERVAL_US); |
| 1692 | pauseDuration -= MAX_CHECK_EXIT_INTERVAL_US; |
| 1693 | } else { |
| 1694 | usleep(pauseDuration); |
| 1695 | break; |
| 1696 | } |
| 1697 | checkExit(); |
| 1698 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1699 | |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1700 | if (exitPending() && !part.count && mCurrentInset >= mTargetInset && |
| 1701 | !part.hasFadingPhase()) { |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 1702 | if (lastDisplayedProgress != 0 && lastDisplayedProgress != 100) { |
| 1703 | android::base::SetProperty(PROGRESS_PROP_NAME, "100"); |
| 1704 | continue; |
| 1705 | } |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1706 | break; // exit the infinite non-fading part when it has been played at least once |
| 1707 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1708 | } |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | // Free textures created for looping parts now that the animation is done. |
| 1712 | for (const Animation::Part& part : animation.parts) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1713 | if (part.count != 1) { |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 1714 | const size_t fcount = part.frames.size(); |
| 1715 | for (size_t j = 0; j < fcount; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1716 | const Animation::Frame& frame(part.frames[j]); |
| 1717 | glDeleteTextures(1, &frame.tid); |
| 1718 | } |
| 1719 | } |
| 1720 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 1721 | |
Yoshiaki Maruoka | 9ef19b8 | 2017-10-25 13:55:49 +0900 | [diff] [blame] | 1722 | ALOGD("%sAnimationShownTiming End time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
| 1723 | elapsedRealtime()); |
| 1724 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1725 | return true; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1728 | void BootAnimation::processDisplayEvents() { |
| 1729 | // This will poll mDisplayEventReceiver and if there are new events it'll call |
| 1730 | // displayEventCallback synchronously. |
| 1731 | mLooper->pollOnce(0); |
| 1732 | } |
| 1733 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1734 | void BootAnimation::handleViewport(nsecs_t timestep) { |
| 1735 | if (mShuttingDown || !mFlingerSurfaceControl || mTargetInset == 0) { |
| 1736 | return; |
| 1737 | } |
| 1738 | if (mTargetInset < 0) { |
| 1739 | // Poll the amount for the top display inset. This will return -1 until persistent properties |
| 1740 | // have been loaded. |
| 1741 | mTargetInset = android::base::GetIntProperty("persist.sys.displayinset.top", |
| 1742 | -1 /* default */, -1 /* min */, mHeight / 2 /* max */); |
| 1743 | } |
| 1744 | if (mTargetInset <= 0) { |
| 1745 | return; |
| 1746 | } |
| 1747 | |
| 1748 | if (mCurrentInset < mTargetInset) { |
| 1749 | // After the device boots, the inset will effectively be cropped away. We animate this here. |
| 1750 | float fraction = static_cast<float>(mCurrentInset) / mTargetInset; |
| 1751 | int interpolatedInset = (cosf((fraction + 1) * M_PI) / 2.0f + 0.5f) * mTargetInset; |
| 1752 | |
| 1753 | SurfaceComposerClient::Transaction() |
| 1754 | .setCrop(mFlingerSurfaceControl, Rect(0, interpolatedInset, mWidth, mHeight)) |
| 1755 | .apply(); |
| 1756 | } else { |
| 1757 | // At the end of the animation, we switch to the viewport that DisplayManager will apply |
| 1758 | // later. This changes the coordinate system, and means we must move the surface up by |
| 1759 | // the inset amount. |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1760 | Rect layerStackRect(0, 0, mWidth, mHeight - mTargetInset); |
| 1761 | Rect displayRect(0, mTargetInset, mWidth, mHeight); |
| 1762 | |
| 1763 | SurfaceComposerClient::Transaction t; |
| 1764 | t.setPosition(mFlingerSurfaceControl, 0, -mTargetInset) |
| 1765 | .setCrop(mFlingerSurfaceControl, Rect(0, mTargetInset, mWidth, mHeight)); |
Dominik Laskowski | 2a3d9aa | 2019-11-18 20:26:39 -0800 | [diff] [blame] | 1766 | t.setDisplayProjection(mDisplayToken, ui::ROTATION_0, layerStackRect, displayRect); |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1767 | t.apply(); |
| 1768 | |
| 1769 | mTargetInset = mCurrentInset = 0; |
| 1770 | } |
| 1771 | |
| 1772 | int delta = timestep * mTargetInset / ms2ns(200); |
| 1773 | mCurrentInset += delta; |
| 1774 | } |
| 1775 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1776 | void BootAnimation::releaseAnimation(Animation* animation) const { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1777 | for (Vector<Animation::Part>::iterator it = animation->parts.begin(), |
| 1778 | e = animation->parts.end(); it != e; ++it) { |
| 1779 | if (it->animation) |
| 1780 | releaseAnimation(it->animation); |
| 1781 | } |
| 1782 | if (animation->zip) |
| 1783 | delete animation->zip; |
| 1784 | delete animation; |
| 1785 | } |
| 1786 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1787 | BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn) { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1788 | if (mLoadedFiles.indexOf(fn) >= 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1789 | SLOGE("File \"%s\" is already loaded. Cyclic ref is not allowed", |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame] | 1790 | fn.c_str()); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1791 | return nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1792 | } |
| 1793 | ZipFileRO *zip = ZipFileRO::open(fn); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1794 | if (zip == nullptr) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1795 | SLOGE("Failed to open animation zip \"%s\": %s", |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame] | 1796 | fn.c_str(), strerror(errno)); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1797 | return nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
Tomasz Wasilczyk | 3815d34 | 2023-08-10 23:54:44 +0000 | [diff] [blame] | 1800 | ALOGD("%s is loaded successfully", fn.c_str()); |
Yoshiaki Maruoka | 9ef19b8 | 2017-10-25 13:55:49 +0900 | [diff] [blame] | 1801 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1802 | Animation *animation = new Animation; |
| 1803 | animation->fileName = fn; |
| 1804 | animation->zip = zip; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1805 | animation->clockFont.map = nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1806 | mLoadedFiles.add(animation->fileName); |
| 1807 | |
| 1808 | parseAnimationDesc(*animation); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 1809 | if (!preloadZip(*animation)) { |
Greg Kaiser | 7426ec8 | 2019-09-11 14:34:27 -0700 | [diff] [blame] | 1810 | releaseAnimation(animation); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1811 | return nullptr; |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1814 | mLoadedFiles.remove(fn); |
| 1815 | return animation; |
| 1816 | } |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1817 | |
| 1818 | bool BootAnimation::updateIsTimeAccurate() { |
| 1819 | static constexpr long long MAX_TIME_IN_PAST = 60000LL * 60LL * 24LL * 30LL; // 30 days |
| 1820 | static constexpr long long MAX_TIME_IN_FUTURE = 60000LL * 90LL; // 90 minutes |
| 1821 | |
| 1822 | if (mTimeIsAccurate) { |
| 1823 | return true; |
| 1824 | } |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 1825 | if (mShuttingDown) return true; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1826 | struct stat statResult; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 1827 | |
| 1828 | if(stat(TIME_FORMAT_12_HOUR_FLAG_FILE_PATH, &statResult) == 0) { |
| 1829 | mTimeFormat12Hour = true; |
| 1830 | } |
| 1831 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1832 | if(stat(ACCURATE_TIME_FLAG_FILE_PATH, &statResult) == 0) { |
| 1833 | mTimeIsAccurate = true; |
| 1834 | return true; |
| 1835 | } |
| 1836 | |
| 1837 | FILE* file = fopen(LAST_TIME_CHANGED_FILE_PATH, "r"); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1838 | if (file != nullptr) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1839 | long long lastChangedTime = 0; |
| 1840 | fscanf(file, "%lld", &lastChangedTime); |
| 1841 | fclose(file); |
| 1842 | if (lastChangedTime > 0) { |
| 1843 | struct timespec now; |
| 1844 | clock_gettime(CLOCK_REALTIME, &now); |
| 1845 | // Match the Java timestamp format |
| 1846 | long long rtcNow = (now.tv_sec * 1000LL) + (now.tv_nsec / 1000000LL); |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 1847 | if (ACCURATE_TIME_EPOCH < rtcNow |
| 1848 | && lastChangedTime > (rtcNow - MAX_TIME_IN_PAST) |
| 1849 | && lastChangedTime < (rtcNow + MAX_TIME_IN_FUTURE)) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1850 | mTimeIsAccurate = true; |
| 1851 | } |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | return mTimeIsAccurate; |
| 1856 | } |
| 1857 | |
| 1858 | BootAnimation::TimeCheckThread::TimeCheckThread(BootAnimation* bootAnimation) : Thread(false), |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1859 | mInotifyFd(-1), mBootAnimWd(-1), mTimeWd(-1), mBootAnimation(bootAnimation) {} |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1860 | |
| 1861 | BootAnimation::TimeCheckThread::~TimeCheckThread() { |
| 1862 | // mInotifyFd may be -1 but that's ok since we're not at risk of attempting to close a valid FD. |
| 1863 | close(mInotifyFd); |
| 1864 | } |
| 1865 | |
| 1866 | bool BootAnimation::TimeCheckThread::threadLoop() { |
| 1867 | bool shouldLoop = doThreadLoop() && !mBootAnimation->mTimeIsAccurate |
| 1868 | && mBootAnimation->mClockEnabled; |
| 1869 | if (!shouldLoop) { |
| 1870 | close(mInotifyFd); |
| 1871 | mInotifyFd = -1; |
| 1872 | } |
| 1873 | return shouldLoop; |
| 1874 | } |
| 1875 | |
| 1876 | bool BootAnimation::TimeCheckThread::doThreadLoop() { |
| 1877 | static constexpr int BUFF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1)); |
| 1878 | |
| 1879 | // Poll instead of doing a blocking read so the Thread can exit if requested. |
| 1880 | struct pollfd pfd = { mInotifyFd, POLLIN, 0 }; |
| 1881 | ssize_t pollResult = poll(&pfd, 1, 1000); |
| 1882 | |
| 1883 | if (pollResult == 0) { |
| 1884 | return true; |
| 1885 | } else if (pollResult < 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1886 | SLOGE("Could not poll inotify events"); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1887 | return false; |
| 1888 | } |
| 1889 | |
| 1890 | char buff[BUFF_LEN] __attribute__ ((aligned(__alignof__(struct inotify_event))));; |
| 1891 | ssize_t length = read(mInotifyFd, buff, BUFF_LEN); |
| 1892 | if (length == 0) { |
| 1893 | return true; |
| 1894 | } else if (length < 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1895 | SLOGE("Could not read inotify events"); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1896 | return false; |
| 1897 | } |
| 1898 | |
| 1899 | const struct inotify_event *event; |
| 1900 | for (char* ptr = buff; ptr < buff + length; ptr += sizeof(struct inotify_event) + event->len) { |
| 1901 | event = (const struct inotify_event *) ptr; |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1902 | if (event->wd == mBootAnimWd && strcmp(BOOTANIM_TIME_DIR_NAME, event->name) == 0) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1903 | addTimeDirWatch(); |
| 1904 | } else if (event->wd == mTimeWd && (strcmp(LAST_TIME_CHANGED_FILE_NAME, event->name) == 0 |
| 1905 | || strcmp(ACCURATE_TIME_FLAG_FILE_NAME, event->name) == 0)) { |
| 1906 | return !mBootAnimation->updateIsTimeAccurate(); |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | return true; |
| 1911 | } |
| 1912 | |
| 1913 | void BootAnimation::TimeCheckThread::addTimeDirWatch() { |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1914 | mTimeWd = inotify_add_watch(mInotifyFd, BOOTANIM_TIME_DIR_PATH, |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1915 | IN_CLOSE_WRITE | IN_MOVED_TO | IN_ATTRIB); |
| 1916 | if (mTimeWd > 0) { |
| 1917 | // No need to watch for the time directory to be created if it already exists |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1918 | inotify_rm_watch(mInotifyFd, mBootAnimWd); |
| 1919 | mBootAnimWd = -1; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | status_t BootAnimation::TimeCheckThread::readyToRun() { |
| 1924 | mInotifyFd = inotify_init(); |
| 1925 | if (mInotifyFd < 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1926 | SLOGE("Could not initialize inotify fd"); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1927 | return NO_INIT; |
| 1928 | } |
| 1929 | |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1930 | mBootAnimWd = inotify_add_watch(mInotifyFd, BOOTANIM_DATA_DIR_PATH, IN_CREATE | IN_ATTRIB); |
| 1931 | if (mBootAnimWd < 0) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1932 | close(mInotifyFd); |
| 1933 | mInotifyFd = -1; |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1934 | SLOGE("Could not add watch for %s: %s", BOOTANIM_DATA_DIR_PATH, strerror(errno)); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1935 | return NO_INIT; |
| 1936 | } |
| 1937 | |
| 1938 | addTimeDirWatch(); |
| 1939 | |
| 1940 | if (mBootAnimation->updateIsTimeAccurate()) { |
| 1941 | close(mInotifyFd); |
| 1942 | mInotifyFd = -1; |
| 1943 | return ALREADY_EXISTS; |
| 1944 | } |
| 1945 | |
| 1946 | return NO_ERROR; |
| 1947 | } |
| 1948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | // --------------------------------------------------------------------------- |
| 1950 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1951 | } // namespace android |