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> |
| 21 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | #include <sys/types.h> |
| 24 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 25 | #include <androidfw/AssetManager.h> |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 26 | #include <utils/Thread.h> |
Ed Coyne | 33f4b7d | 2018-04-10 13:39:09 -0700 | [diff] [blame] | 27 | #include <binder/IBinder.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <EGL/egl.h> |
| 30 | #include <GLES/gl.h> |
| 31 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | class SkBitmap; |
| 33 | |
| 34 | namespace android { |
| 35 | |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 36 | class Surface; |
| 37 | class SurfaceComposerClient; |
| 38 | class SurfaceControl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
| 40 | // --------------------------------------------------------------------------- |
| 41 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 42 | class BootAnimation : public Thread, public IBinder::DeathRecipient |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | { |
| 44 | public: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | struct Texture { |
| 46 | GLint w; |
| 47 | GLint h; |
| 48 | GLuint name; |
| 49 | }; |
| 50 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 51 | struct Font { |
| 52 | FileMap* map; |
| 53 | Texture texture; |
| 54 | int char_width; |
| 55 | int char_height; |
| 56 | }; |
| 57 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 58 | struct Animation { |
| 59 | struct Frame { |
| 60 | String8 name; |
| 61 | FileMap* map; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 62 | int trimX; |
| 63 | int trimY; |
| 64 | int trimWidth; |
| 65 | int trimHeight; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 66 | mutable GLuint tid; |
| 67 | bool operator < (const Frame& rhs) const { |
| 68 | return name < rhs.name; |
| 69 | } |
| 70 | }; |
| 71 | struct Part { |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 72 | int count; // The number of times this part should repeat, 0 for infinite |
| 73 | 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] | 74 | int clockPosX; // The x position of the clock, in pixels. Positive values offset from |
| 75 | // the left of the screen, negative values offset from the right. |
| 76 | int clockPosY; // The y position of the clock, in pixels. Positive values offset from |
| 77 | // the bottom of the screen, negative values offset from the top. |
| 78 | // If either of the above are INT_MIN the clock is disabled, if INT_MAX |
| 79 | // the clock is centred on that axis. |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 80 | String8 path; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 81 | String8 trimData; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 82 | SortedVector<Frame> frames; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 83 | bool playUntilComplete; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 84 | float backgroundColor[3]; |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 85 | uint8_t* audioData; |
| 86 | int audioLength; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 87 | Animation* animation; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 88 | }; |
| 89 | int fps; |
| 90 | int width; |
| 91 | int height; |
| 92 | Vector<Part> parts; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 93 | String8 audioConf; |
| 94 | String8 fileName; |
| 95 | ZipFileRO* zip; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 96 | Font clockFont; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 99 | // All callbacks will be called from this class's internal thread. |
| 100 | class Callbacks : public RefBase { |
| 101 | public: |
| 102 | // Will be called during initialization after we have loaded |
| 103 | // the animation and be provided with all parts in animation. |
| 104 | virtual void init(const Vector<Animation::Part>& /*parts*/) {} |
Ed Coyne | 2c9e94a | 2017-05-31 10:08:28 -0700 | [diff] [blame] | 105 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 106 | // Will be called while animation is playing before each part is |
| 107 | // played. It will be provided with the part and play count for it. |
| 108 | // It will be provided with the partNumber for the part about to be played, |
| 109 | // as well as a reference to the part itself. It will also be provided with |
| 110 | // which play of that part is about to start, some parts are repeated |
| 111 | // multiple times. |
| 112 | virtual void playPart(int /*partNumber*/, const Animation::Part& /*part*/, |
| 113 | int /*playNumber*/) {} |
Ed Coyne | 2c9e94a | 2017-05-31 10:08:28 -0700 | [diff] [blame] | 114 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 115 | // Will be called when animation is done and thread is shutting down. |
| 116 | virtual void shutdown() {} |
| 117 | }; |
| 118 | |
Chih-Hung Hsieh | a08d2c2 | 2018-12-20 13:39:40 -0800 | [diff] [blame] | 119 | explicit BootAnimation(sp<Callbacks> callbacks); |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 120 | virtual ~BootAnimation(); |
Ed Coyne | 2c9e94a | 2017-05-31 10:08:28 -0700 | [diff] [blame] | 121 | |
| 122 | sp<SurfaceComposerClient> session() const; |
| 123 | |
| 124 | private: |
| 125 | virtual bool threadLoop(); |
| 126 | virtual status_t readyToRun(); |
| 127 | virtual void onFirstRef(); |
| 128 | virtual void binderDied(const wp<IBinder>& who); |
| 129 | |
| 130 | bool updateIsTimeAccurate(); |
| 131 | |
| 132 | class TimeCheckThread : public Thread { |
| 133 | public: |
Chih-Hung Hsieh | a08d2c2 | 2018-12-20 13:39:40 -0800 | [diff] [blame] | 134 | explicit TimeCheckThread(BootAnimation* bootAnimation); |
Ed Coyne | 2c9e94a | 2017-05-31 10:08:28 -0700 | [diff] [blame] | 135 | virtual ~TimeCheckThread(); |
| 136 | private: |
| 137 | virtual status_t readyToRun(); |
| 138 | virtual bool threadLoop(); |
| 139 | bool doThreadLoop(); |
| 140 | void addTimeDirWatch(); |
| 141 | |
| 142 | int mInotifyFd; |
| 143 | int mSystemWd; |
| 144 | int mTimeWd; |
| 145 | BootAnimation* mBootAnimation; |
| 146 | }; |
| 147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | status_t initTexture(Texture* texture, AssetManager& asset, const char* name); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 149 | status_t initTexture(FileMap* map, int* width, int* height); |
| 150 | status_t initFont(Font* font, const char* fallback); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | bool android(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 152 | bool movie(); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 153 | void drawText(const char* str, const Font& font, bool bold, int* x, int* y); |
| 154 | void drawClock(const Font& font, const int xPos, const int yPos); |
| 155 | bool validClock(const Animation::Part& part); |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 156 | Animation* loadAnimation(const String8&); |
| 157 | bool playAnimation(const Animation&); |
| 158 | void releaseAnimation(Animation*) const; |
| 159 | bool parseAnimationDesc(Animation&); |
| 160 | bool preloadZip(Animation &animation); |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 161 | void findBootAnimationFile(); |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame^] | 162 | bool findBootAnimationFileInternal(const std::vector<std::string>& files); |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 163 | bool preloadAnimation(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 165 | void checkExit(); |
| 166 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 167 | void handleViewport(nsecs_t timestep); |
| 168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | sp<SurfaceComposerClient> mSession; |
| 170 | AssetManager mAssets; |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 171 | Texture mAndroid[2]; |
| 172 | int mWidth; |
| 173 | int mHeight; |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 174 | int mCurrentInset; |
| 175 | int mTargetInset; |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 176 | bool mUseNpotTextures = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | EGLDisplay mDisplay; |
| 178 | EGLDisplay mContext; |
| 179 | EGLDisplay mSurface; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 180 | sp<IBinder> mDisplayToken; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 181 | sp<SurfaceControl> mFlingerSurfaceControl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | sp<Surface> mFlingerSurface; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 183 | bool mClockEnabled; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 184 | bool mTimeIsAccurate; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 185 | bool mTimeFormat12Hour; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 186 | bool mShuttingDown; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 187 | String8 mZipFileName; |
| 188 | SortedVector<String8> mLoadedFiles; |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 189 | sp<TimeCheckThread> mTimeCheckThread = nullptr; |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 190 | sp<Callbacks> mCallbacks; |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 191 | Animation* mAnimation = nullptr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | // --------------------------------------------------------------------------- |
| 195 | |
| 196 | }; // namespace android |
| 197 | |
| 198 | #endif // ANDROID_BOOTANIMATION_H |