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