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