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