blob: 574d65e425cf2433974820cac6ff0e7ea67cd068 [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>
21
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022#include <stdint.h>
23#include <sys/types.h>
24
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080025#include <androidfw/AssetManager.h>
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -070026#include <utils/Thread.h>
Ed Coyne33f4b7d2018-04-10 13:39:09 -070027#include <binder/IBinder.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029#include <EGL/egl.h>
30#include <GLES/gl.h>
31
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032class SkBitmap;
33
34namespace android {
35
Mathias Agopian8335f1c2012-02-25 18:48:35 -080036class Surface;
37class SurfaceComposerClient;
38class SurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40// ---------------------------------------------------------------------------
41
Mathias Agopianbc726112009-09-23 15:44:05 -070042class BootAnimation : public Thread, public IBinder::DeathRecipient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043{
44public:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 struct Texture {
46 GLint w;
47 GLint h;
48 GLuint name;
49 };
50
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070051 struct Font {
52 FileMap* map;
53 Texture texture;
54 int char_width;
55 int char_height;
56 };
57
Mathias Agopiana8826d62009-10-01 03:10:14 -070058 struct Animation {
59 struct Frame {
60 String8 name;
61 FileMap* map;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040062 int trimX;
63 int trimY;
64 int trimWidth;
65 int trimHeight;
Mathias Agopiana8826d62009-10-01 03:10:14 -070066 mutable GLuint tid;
67 bool operator < (const Frame& rhs) const {
68 return name < rhs.name;
69 }
70 };
71 struct Part {
Damien Bargiacchia704b7d2016-02-16 16:55:49 -080072 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 Bargiacchi0e3d2ab2016-08-29 04:11:19 -070074 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 Agopiana8826d62009-10-01 03:10:14 -070080 String8 path;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040081 String8 trimData;
Mathias Agopiana8826d62009-10-01 03:10:14 -070082 SortedVector<Frame> frames;
Kevin Hesterd3782b22012-04-26 10:38:55 -070083 bool playUntilComplete;
Jesse Hall083b84c2014-09-22 10:51:09 -070084 float backgroundColor[3];
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -070085 uint8_t* audioData;
86 int audioLength;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -070087 Animation* animation;
Mathias Agopiana8826d62009-10-01 03:10:14 -070088 };
89 int fps;
90 int width;
91 int height;
92 Vector<Part> parts;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -070093 String8 audioConf;
94 String8 fileName;
95 ZipFileRO* zip;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070096 Font clockFont;
Mathias Agopiana8826d62009-10-01 03:10:14 -070097 };
98
Ed Coyne7464ac92017-06-08 12:26:48 -070099 // 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 Coyne2c9e94a2017-05-31 10:08:28 -0700105
Ed Coyne7464ac92017-06-08 12:26:48 -0700106 // 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 Coyne2c9e94a2017-05-31 10:08:28 -0700114
Ed Coyne7464ac92017-06-08 12:26:48 -0700115 // Will be called when animation is done and thread is shutting down.
116 virtual void shutdown() {}
117 };
118
Chih-Hung Hsieha08d2c22018-12-20 13:39:40 -0800119 explicit BootAnimation(sp<Callbacks> callbacks);
Huihong Luo50a2f362018-08-11 09:27:57 -0700120 virtual ~BootAnimation();
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700121
122 sp<SurfaceComposerClient> session() const;
123
124private:
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 Hsieha08d2c22018-12-20 13:39:40 -0800134 explicit TimeCheckThread(BootAnimation* bootAnimation);
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700135 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 Project9066cfe2009-03-03 19:31:44 -0800148 status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700149 status_t initTexture(FileMap* map, int* width, int* height);
150 status_t initFont(Font* font, const char* fallback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 bool android();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700152 bool movie();
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700153 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 Naborskyy39218ba2015-08-16 21:32:50 -0700156 Animation* loadAnimation(const String8&);
157 bool playAnimation(const Animation&);
158 void releaseAnimation(Animation*) const;
159 bool parseAnimationDesc(Animation&);
160 bool preloadZip(Animation &animation);
Huihong Luo50a2f362018-08-11 09:27:57 -0700161 void findBootAnimationFile();
Nikita Ioffe06c986e2020-01-27 17:16:03 +0000162 bool findBootAnimationFileInternal(const std::vector<std::string>& files);
Huihong Luo50a2f362018-08-11 09:27:57 -0700163 bool preloadAnimation();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164
Kevin Hesterd3782b22012-04-26 10:38:55 -0700165 void checkExit();
166
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200167 void handleViewport(nsecs_t timestep);
168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 sp<SurfaceComposerClient> mSession;
170 AssetManager mAssets;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700171 Texture mAndroid[2];
172 int mWidth;
173 int mHeight;
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200174 int mCurrentInset;
175 int mTargetInset;
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530176 bool mUseNpotTextures = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 EGLDisplay mDisplay;
178 EGLDisplay mContext;
179 EGLDisplay mSurface;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800180 sp<IBinder> mDisplayToken;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700181 sp<SurfaceControl> mFlingerSurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 sp<Surface> mFlingerSurface;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800183 bool mClockEnabled;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700184 bool mTimeIsAccurate;
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700185 bool mTimeFormat12Hour;
Keun-young Parkb5938422017-03-23 13:46:24 -0700186 bool mShuttingDown;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700187 String8 mZipFileName;
188 SortedVector<String8> mLoadedFiles;
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400189 sp<TimeCheckThread> mTimeCheckThread = nullptr;
Ed Coyne7464ac92017-06-08 12:26:48 -0700190 sp<Callbacks> mCallbacks;
Huihong Luo50a2f362018-08-11 09:27:57 -0700191 Animation* mAnimation = nullptr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192};
193
194// ---------------------------------------------------------------------------
195
196}; // namespace android
197
198#endif // ANDROID_BOOTANIMATION_H