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