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 | |
| 17 | #ifndef ANDROID_BOOTANIMATION_H |
| 18 | #define ANDROID_BOOTANIMATION_H |
| 19 | |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 20 | #include <vector> |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 21 | #include <queue> |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 22 | #include <climits> |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 23 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <stdint.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 27 | #include <androidfw/AssetManager.h> |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 28 | #include <gui/DisplayEventReceiver.h> |
| 29 | #include <utils/Looper.h> |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 30 | #include <utils/Thread.h> |
Ed Coyne | 33f4b7d | 2018-04-10 13:39:09 -0700 | [diff] [blame] | 31 | #include <binder/IBinder.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
Mariia Sandrikova | a166f01 | 2022-12-10 02:32:14 +0000 | [diff] [blame] | 33 | #include <ui/Rotation.h> |
| 34 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | #include <EGL/egl.h> |
Lucas Dupin | dd7ed60 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 36 | #include <GLES2/gl2.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | namespace android { |
| 39 | |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 40 | class Surface; |
| 41 | class SurfaceComposerClient; |
| 42 | class SurfaceControl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
| 44 | // --------------------------------------------------------------------------- |
| 45 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 46 | class BootAnimation : public Thread, public IBinder::DeathRecipient |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | { |
| 48 | public: |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 49 | static constexpr int MAX_FADED_FRAMES_COUNT = std::numeric_limits<int>::max(); |
| 50 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | struct Texture { |
| 52 | GLint w; |
| 53 | GLint h; |
| 54 | GLuint name; |
| 55 | }; |
| 56 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 57 | struct Font { |
Shan Huang | 8996500 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 58 | FileMap* map = nullptr; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 59 | Texture texture; |
| 60 | int char_width; |
| 61 | int char_height; |
| 62 | }; |
| 63 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 64 | struct Animation { |
| 65 | struct Frame { |
| 66 | String8 name; |
Shan Huang | 8996500 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 67 | FileMap* map = nullptr; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 68 | int trimX; |
| 69 | int trimY; |
| 70 | int trimWidth; |
| 71 | int trimHeight; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 72 | mutable GLuint tid; |
| 73 | bool operator < (const Frame& rhs) const { |
| 74 | return name < rhs.name; |
| 75 | } |
| 76 | }; |
| 77 | struct Part { |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 78 | int count; // The number of times this part should repeat, 0 for infinite |
| 79 | int pause; // The number of frames to pause for at the end of this part |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 80 | int clockPosX; // The x position of the clock, in pixels. Positive values offset from |
| 81 | // the left of the screen, negative values offset from the right. |
| 82 | int clockPosY; // The y position of the clock, in pixels. Positive values offset from |
| 83 | // the bottom of the screen, negative values offset from the top. |
| 84 | // If either of the above are INT_MIN the clock is disabled, if INT_MAX |
| 85 | // the clock is centred on that axis. |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 86 | String8 path; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 87 | String8 trimData; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 88 | SortedVector<Frame> frames; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 89 | bool playUntilComplete; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 90 | int framesToFadeCount; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 91 | float backgroundColor[3]; |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 92 | uint8_t* audioData; |
| 93 | int audioLength; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 94 | Animation* animation; |
Shan Huang | 8996500 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 95 | // Controls if dynamic coloring is enabled for this part. |
| 96 | bool useDynamicColoring = false; |
| 97 | // Defines if this part is played after the dynamic coloring part. |
| 98 | bool postDynamicColoring = false; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 99 | |
| 100 | bool hasFadingPhase() const { |
| 101 | return !playUntilComplete && framesToFadeCount > 0; |
| 102 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 103 | }; |
| 104 | int fps; |
| 105 | int width; |
| 106 | int height; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 107 | bool progressEnabled; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 108 | Vector<Part> parts; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 109 | String8 audioConf; |
| 110 | String8 fileName; |
| 111 | ZipFileRO* zip; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 112 | Font clockFont; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 113 | Font progressFont; |
Shan Huang | 8996500 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 114 | // Controls if dynamic coloring is enabled for the whole animation. |
| 115 | bool dynamicColoringEnabled = false; |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 116 | int colorTransitionStart = 0; // Start frame of dynamic color transition. |
| 117 | int colorTransitionEnd = 0; // End frame of dynamic color transition. |
Shan Huang | 8996500 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 118 | float startColors[4][3]; // Start colors of dynamic color transition. |
| 119 | float endColors[4][3]; // End colors of dynamic color transition. |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 122 | // All callbacks will be called from this class's internal thread. |
| 123 | class Callbacks : public RefBase { |
| 124 | public: |
| 125 | // Will be called during initialization after we have loaded |
| 126 | // the animation and be provided with all parts in animation. |
| 127 | virtual void init(const Vector<Animation::Part>& /*parts*/) {} |
Ed Coyne | 2c9e94a | 2017-05-31 10:08:28 -0700 | [diff] [blame] | 128 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 129 | // Will be called while animation is playing before each part is |
| 130 | // played. It will be provided with the part and play count for it. |
| 131 | // It will be provided with the partNumber for the part about to be played, |
| 132 | // as well as a reference to the part itself. It will also be provided with |
| 133 | // which play of that part is about to start, some parts are repeated |
| 134 | // multiple times. |
| 135 | virtual void playPart(int /*partNumber*/, const Animation::Part& /*part*/, |
| 136 | int /*playNumber*/) {} |
Ed Coyne | 2c9e94a | 2017-05-31 10:08:28 -0700 | [diff] [blame] | 137 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 138 | // Will be called when animation is done and thread is shutting down. |
| 139 | virtual void shutdown() {} |
| 140 | }; |
| 141 | |
Chih-Hung Hsieh | a08d2c2 | 2018-12-20 13:39:40 -0800 | [diff] [blame] | 142 | explicit BootAnimation(sp<Callbacks> callbacks); |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 143 | virtual ~BootAnimation(); |
Ed Coyne | 2c9e94a | 2017-05-31 10:08:28 -0700 | [diff] [blame] | 144 | |
| 145 | sp<SurfaceComposerClient> session() const; |
| 146 | |
| 147 | private: |
| 148 | virtual bool threadLoop(); |
| 149 | virtual status_t readyToRun(); |
| 150 | virtual void onFirstRef(); |
| 151 | virtual void binderDied(const wp<IBinder>& who); |
| 152 | |
| 153 | bool updateIsTimeAccurate(); |
| 154 | |
| 155 | class TimeCheckThread : public Thread { |
| 156 | public: |
Chih-Hung Hsieh | a08d2c2 | 2018-12-20 13:39:40 -0800 | [diff] [blame] | 157 | explicit TimeCheckThread(BootAnimation* bootAnimation); |
Ed Coyne | 2c9e94a | 2017-05-31 10:08:28 -0700 | [diff] [blame] | 158 | virtual ~TimeCheckThread(); |
| 159 | private: |
| 160 | virtual status_t readyToRun(); |
| 161 | virtual bool threadLoop(); |
| 162 | bool doThreadLoop(); |
| 163 | void addTimeDirWatch(); |
| 164 | |
| 165 | int mInotifyFd; |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 166 | int mBootAnimWd; |
Ed Coyne | 2c9e94a | 2017-05-31 10:08:28 -0700 | [diff] [blame] | 167 | int mTimeWd; |
| 168 | BootAnimation* mBootAnimation; |
| 169 | }; |
| 170 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 171 | // Display event handling |
| 172 | class DisplayEventCallback; |
| 173 | std::unique_ptr<DisplayEventReceiver> mDisplayEventReceiver; |
| 174 | sp<Looper> mLooper; |
| 175 | int displayEventCallback(int fd, int events, void* data); |
| 176 | void processDisplayEvents(); |
| 177 | |
Shan Huang | 8996500 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 178 | status_t initTexture(Texture* texture, AssetManager& asset, const char* name, |
| 179 | bool premultiplyAlpha = true); |
| 180 | status_t initTexture(FileMap* map, int* width, int* height, |
| 181 | bool premultiplyAlpha = true); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 182 | status_t initFont(Font* font, const char* fallback); |
Lucas Dupin | dd7ed60 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 183 | void initShaders(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | bool android(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 185 | bool movie(); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 186 | void drawText(const char* str, const Font& font, bool bold, int* x, int* y); |
| 187 | void drawClock(const Font& font, const int xPos, const int yPos); |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 188 | void drawProgress(int percent, const Font& font, const int xPos, const int yPos); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 189 | void fadeFrame(int frameLeft, int frameBottom, int frameWidth, int frameHeight, |
| 190 | const Animation::Part& part, int fadedFramesCount); |
Lucas Dupin | dd7ed60 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 191 | void drawTexturedQuad(float xStart, float yStart, float width, float height); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 192 | bool validClock(const Animation::Part& part); |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 193 | Animation* loadAnimation(const String8&); |
| 194 | bool playAnimation(const Animation&); |
| 195 | void releaseAnimation(Animation*) const; |
| 196 | bool parseAnimationDesc(Animation&); |
| 197 | bool preloadZip(Animation &animation); |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 198 | void findBootAnimationFile(); |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 199 | bool findBootAnimationFileInternal(const std::vector<std::string>& files); |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 200 | bool preloadAnimation(); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 201 | EGLConfig getEglConfig(const EGLDisplay&); |
Marin Shalamanov | 047802d | 2020-05-19 23:55:12 +0200 | [diff] [blame] | 202 | ui::Size limitSurfaceSize(int width, int height) const; |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 203 | void resizeSurface(int newWidth, int newHeight); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 204 | void projectSceneToWindow(); |
Mariia Sandrikova | a166f01 | 2022-12-10 02:32:14 +0000 | [diff] [blame] | 205 | void rotateAwayFromNaturalOrientationIfNeeded(); |
| 206 | ui::Rotation parseOrientationProperty(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 208 | bool shouldStopPlayingPart(const Animation::Part& part, int fadedFramesCount, |
| 209 | int lastDisplayedProgress); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 210 | void checkExit(); |
| 211 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 212 | void handleViewport(nsecs_t timestep); |
Shan Huang | a1f7a71c2 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 213 | void initDynamicColors(); |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | sp<SurfaceComposerClient> mSession; |
| 216 | AssetManager mAssets; |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 217 | Texture mAndroid[2]; |
| 218 | int mWidth; |
| 219 | int mHeight; |
joenchen | 764ea04 | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 220 | int mInitWidth; |
| 221 | int mInitHeight; |
Marin Shalamanov | 047802d | 2020-05-19 23:55:12 +0200 | [diff] [blame] | 222 | int mMaxWidth = 0; |
| 223 | int mMaxHeight = 0; |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 224 | int mCurrentInset; |
| 225 | int mTargetInset; |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 226 | bool mUseNpotTextures = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | EGLDisplay mDisplay; |
| 228 | EGLDisplay mContext; |
| 229 | EGLDisplay mSurface; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 230 | sp<IBinder> mDisplayToken; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 231 | sp<SurfaceControl> mFlingerSurfaceControl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | sp<Surface> mFlingerSurface; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 233 | bool mClockEnabled; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 234 | bool mTimeIsAccurate; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 235 | bool mTimeFormat12Hour; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 236 | bool mShuttingDown; |
Lucas Dupin | cd25684 | 2022-03-29 15:46:36 -0700 | [diff] [blame] | 237 | bool mDynamicColorsApplied = false; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 238 | String8 mZipFileName; |
| 239 | SortedVector<String8> mLoadedFiles; |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 240 | sp<TimeCheckThread> mTimeCheckThread = nullptr; |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 241 | sp<Callbacks> mCallbacks; |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 242 | Animation* mAnimation = nullptr; |
Lucas Dupin | dd7ed60 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 243 | GLuint mImageShader; |
| 244 | GLuint mTextShader; |
| 245 | GLuint mImageFadeLocation; |
| 246 | GLuint mImageTextureLocation; |
| 247 | GLuint mTextCropAreaLocation; |
| 248 | GLuint mTextTextureLocation; |
Shan Huang | 8996500 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 249 | GLuint mImageColorProgressLocation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | }; |
| 251 | |
| 252 | // --------------------------------------------------------------------------- |
| 253 | |
| 254 | }; // namespace android |
| 255 | |
| 256 | #endif // ANDROID_BOOTANIMATION_H |