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