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