blob: 875819d3c6eff9d5812205980998770595bbe8cc [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Ioffe06c986e2020-01-27 17:16:03 +000020#include <vector>
Marin Shalamanov9070c052020-05-18 19:05:17 +020021#include <queue>
Nikita Ioffe06c986e2020-01-27 17:16:03 +000022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023#include <stdint.h>
24#include <sys/types.h>
25
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080026#include <androidfw/AssetManager.h>
Marin Shalamanov9070c052020-05-18 19:05:17 +020027#include <gui/DisplayEventReceiver.h>
28#include <utils/Looper.h>
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -070029#include <utils/Thread.h>
Ed Coyne33f4b7d2018-04-10 13:39:09 -070030#include <binder/IBinder.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032#include <EGL/egl.h>
33#include <GLES/gl.h>
34
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035namespace android {
36
Mathias Agopian8335f1c2012-02-25 18:48:35 -080037class Surface;
38class SurfaceComposerClient;
39class SurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
41// ---------------------------------------------------------------------------
42
Mathias Agopianbc726112009-09-23 15:44:05 -070043class BootAnimation : public Thread, public IBinder::DeathRecipient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044{
45public:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 struct Texture {
47 GLint w;
48 GLint h;
49 GLuint name;
50 };
51
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070052 struct Font {
53 FileMap* map;
54 Texture texture;
55 int char_width;
56 int char_height;
57 };
58
Mathias Agopiana8826d62009-10-01 03:10:14 -070059 struct Animation {
60 struct Frame {
61 String8 name;
62 FileMap* map;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040063 int trimX;
64 int trimY;
65 int trimWidth;
66 int trimHeight;
Mathias Agopiana8826d62009-10-01 03:10:14 -070067 mutable GLuint tid;
68 bool operator < (const Frame& rhs) const {
69 return name < rhs.name;
70 }
71 };
72 struct Part {
Damien Bargiacchia704b7d2016-02-16 16:55:49 -080073 int count; // The number of times this part should repeat, 0 for infinite
74 int pause; // The number of frames to pause for at the end of this part
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070075 int clockPosX; // The x position of the clock, in pixels. Positive values offset from
76 // the left of the screen, negative values offset from the right.
77 int clockPosY; // The y position of the clock, in pixels. Positive values offset from
78 // the bottom of the screen, negative values offset from the top.
79 // If either of the above are INT_MIN the clock is disabled, if INT_MAX
80 // the clock is centred on that axis.
Mathias Agopiana8826d62009-10-01 03:10:14 -070081 String8 path;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040082 String8 trimData;
Mathias Agopiana8826d62009-10-01 03:10:14 -070083 SortedVector<Frame> frames;
Kevin Hesterd3782b22012-04-26 10:38:55 -070084 bool playUntilComplete;
Jesse Hall083b84c2014-09-22 10:51:09 -070085 float backgroundColor[3];
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -070086 uint8_t* audioData;
87 int audioLength;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -070088 Animation* animation;
Mathias Agopiana8826d62009-10-01 03:10:14 -070089 };
90 int fps;
91 int width;
92 int height;
93 Vector<Part> parts;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -070094 String8 audioConf;
95 String8 fileName;
96 ZipFileRO* zip;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070097 Font clockFont;
Mathias Agopiana8826d62009-10-01 03:10:14 -070098 };
99
Ed Coyne7464ac92017-06-08 12:26:48 -0700100 // All callbacks will be called from this class's internal thread.
101 class Callbacks : public RefBase {
102 public:
103 // Will be called during initialization after we have loaded
104 // the animation and be provided with all parts in animation.
105 virtual void init(const Vector<Animation::Part>& /*parts*/) {}
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700106
Ed Coyne7464ac92017-06-08 12:26:48 -0700107 // Will be called while animation is playing before each part is
108 // played. It will be provided with the part and play count for it.
109 // It will be provided with the partNumber for the part about to be played,
110 // as well as a reference to the part itself. It will also be provided with
111 // which play of that part is about to start, some parts are repeated
112 // multiple times.
113 virtual void playPart(int /*partNumber*/, const Animation::Part& /*part*/,
114 int /*playNumber*/) {}
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700115
Ed Coyne7464ac92017-06-08 12:26:48 -0700116 // Will be called when animation is done and thread is shutting down.
117 virtual void shutdown() {}
118 };
119
Chih-Hung Hsieha08d2c22018-12-20 13:39:40 -0800120 explicit BootAnimation(sp<Callbacks> callbacks);
Huihong Luo50a2f362018-08-11 09:27:57 -0700121 virtual ~BootAnimation();
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700122
123 sp<SurfaceComposerClient> session() const;
124
125private:
126 virtual bool threadLoop();
127 virtual status_t readyToRun();
128 virtual void onFirstRef();
129 virtual void binderDied(const wp<IBinder>& who);
130
131 bool updateIsTimeAccurate();
132
133 class TimeCheckThread : public Thread {
134 public:
Chih-Hung Hsieha08d2c22018-12-20 13:39:40 -0800135 explicit TimeCheckThread(BootAnimation* bootAnimation);
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700136 virtual ~TimeCheckThread();
137 private:
138 virtual status_t readyToRun();
139 virtual bool threadLoop();
140 bool doThreadLoop();
141 void addTimeDirWatch();
142
143 int mInotifyFd;
144 int mSystemWd;
145 int mTimeWd;
146 BootAnimation* mBootAnimation;
147 };
148
Marin Shalamanov9070c052020-05-18 19:05:17 +0200149 // Display event handling
150 class DisplayEventCallback;
151 std::unique_ptr<DisplayEventReceiver> mDisplayEventReceiver;
152 sp<Looper> mLooper;
153 int displayEventCallback(int fd, int events, void* data);
154 void processDisplayEvents();
155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700157 status_t initTexture(FileMap* map, int* width, int* height);
158 status_t initFont(Font* font, const char* fallback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 bool android();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700160 bool movie();
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700161 void drawText(const char* str, const Font& font, bool bold, int* x, int* y);
162 void drawClock(const Font& font, const int xPos, const int yPos);
163 bool validClock(const Animation::Part& part);
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700164 Animation* loadAnimation(const String8&);
165 bool playAnimation(const Animation&);
166 void releaseAnimation(Animation*) const;
167 bool parseAnimationDesc(Animation&);
168 bool preloadZip(Animation &animation);
Huihong Luo50a2f362018-08-11 09:27:57 -0700169 void findBootAnimationFile();
Nikita Ioffe06c986e2020-01-27 17:16:03 +0000170 bool findBootAnimationFileInternal(const std::vector<std::string>& files);
Huihong Luo50a2f362018-08-11 09:27:57 -0700171 bool preloadAnimation();
Marin Shalamanov9070c052020-05-18 19:05:17 +0200172 EGLConfig getEglConfig(const EGLDisplay&);
173 void resizeSurface(int newWidth, int newHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174
Kevin Hesterd3782b22012-04-26 10:38:55 -0700175 void checkExit();
176
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200177 void handleViewport(nsecs_t timestep);
178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 sp<SurfaceComposerClient> mSession;
180 AssetManager mAssets;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700181 Texture mAndroid[2];
182 int mWidth;
183 int mHeight;
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200184 int mCurrentInset;
185 int mTargetInset;
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530186 bool mUseNpotTextures = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 EGLDisplay mDisplay;
188 EGLDisplay mContext;
189 EGLDisplay mSurface;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800190 sp<IBinder> mDisplayToken;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700191 sp<SurfaceControl> mFlingerSurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 sp<Surface> mFlingerSurface;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800193 bool mClockEnabled;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700194 bool mTimeIsAccurate;
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700195 bool mTimeFormat12Hour;
Keun-young Parkb5938422017-03-23 13:46:24 -0700196 bool mShuttingDown;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700197 String8 mZipFileName;
198 SortedVector<String8> mLoadedFiles;
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400199 sp<TimeCheckThread> mTimeCheckThread = nullptr;
Ed Coyne7464ac92017-06-08 12:26:48 -0700200 sp<Callbacks> mCallbacks;
Huihong Luo50a2f362018-08-11 09:27:57 -0700201 Animation* mAnimation = nullptr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202};
203
204// ---------------------------------------------------------------------------
205
206}; // namespace android
207
208#endif // ANDROID_BOOTANIMATION_H