blob: 6ba7fd450fbb2a0328071cafad8ae924fd99068c [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 Shalamanov1a6e3682020-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 Shalamanov1a6e3682020-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 -080035class SkBitmap;
36
37namespace android {
38
Mathias Agopian8335f1c2012-02-25 18:48:35 -080039class Surface;
40class SurfaceComposerClient;
41class SurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43// ---------------------------------------------------------------------------
44
Mathias Agopianbc726112009-09-23 15:44:05 -070045class BootAnimation : public Thread, public IBinder::DeathRecipient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046{
47public:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 struct Texture {
49 GLint w;
50 GLint h;
51 GLuint name;
52 };
53
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070054 struct Font {
55 FileMap* map;
56 Texture texture;
57 int char_width;
58 int char_height;
59 };
60
Mathias Agopiana8826d62009-10-01 03:10:14 -070061 struct Animation {
62 struct Frame {
63 String8 name;
64 FileMap* map;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040065 int trimX;
66 int trimY;
67 int trimWidth;
68 int trimHeight;
Mathias Agopiana8826d62009-10-01 03:10:14 -070069 mutable GLuint tid;
70 bool operator < (const Frame& rhs) const {
71 return name < rhs.name;
72 }
73 };
74 struct Part {
Damien Bargiacchia704b7d2016-02-16 16:55:49 -080075 int count; // The number of times this part should repeat, 0 for infinite
76 int pause; // The number of frames to pause for at the end of this part
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070077 int clockPosX; // The x position of the clock, in pixels. Positive values offset from
78 // the left of the screen, negative values offset from the right.
79 int clockPosY; // The y position of the clock, in pixels. Positive values offset from
80 // the bottom of the screen, negative values offset from the top.
81 // If either of the above are INT_MIN the clock is disabled, if INT_MAX
82 // the clock is centred on that axis.
Mathias Agopiana8826d62009-10-01 03:10:14 -070083 String8 path;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040084 String8 trimData;
Mathias Agopiana8826d62009-10-01 03:10:14 -070085 SortedVector<Frame> frames;
Kevin Hesterd3782b22012-04-26 10:38:55 -070086 bool playUntilComplete;
Jesse Hall083b84c2014-09-22 10:51:09 -070087 float backgroundColor[3];
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -070088 uint8_t* audioData;
89 int audioLength;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -070090 Animation* animation;
Mathias Agopiana8826d62009-10-01 03:10:14 -070091 };
92 int fps;
93 int width;
94 int height;
95 Vector<Part> parts;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -070096 String8 audioConf;
97 String8 fileName;
98 ZipFileRO* zip;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070099 Font clockFont;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700100 };
101
Ed Coyne7464ac92017-06-08 12:26:48 -0700102 // All callbacks will be called from this class's internal thread.
103 class Callbacks : public RefBase {
104 public:
105 // Will be called during initialization after we have loaded
106 // the animation and be provided with all parts in animation.
107 virtual void init(const Vector<Animation::Part>& /*parts*/) {}
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700108
Ed Coyne7464ac92017-06-08 12:26:48 -0700109 // Will be called while animation is playing before each part is
110 // played. It will be provided with the part and play count for it.
111 // It will be provided with the partNumber for the part about to be played,
112 // as well as a reference to the part itself. It will also be provided with
113 // which play of that part is about to start, some parts are repeated
114 // multiple times.
115 virtual void playPart(int /*partNumber*/, const Animation::Part& /*part*/,
116 int /*playNumber*/) {}
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700117
Ed Coyne7464ac92017-06-08 12:26:48 -0700118 // Will be called when animation is done and thread is shutting down.
119 virtual void shutdown() {}
120 };
121
Chih-Hung Hsieha08d2c22018-12-20 13:39:40 -0800122 explicit BootAnimation(sp<Callbacks> callbacks);
Huihong Luo50a2f362018-08-11 09:27:57 -0700123 virtual ~BootAnimation();
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700124
125 sp<SurfaceComposerClient> session() const;
126
127private:
128 virtual bool threadLoop();
129 virtual status_t readyToRun();
130 virtual void onFirstRef();
131 virtual void binderDied(const wp<IBinder>& who);
132
133 bool updateIsTimeAccurate();
134
135 class TimeCheckThread : public Thread {
136 public:
Chih-Hung Hsieha08d2c22018-12-20 13:39:40 -0800137 explicit TimeCheckThread(BootAnimation* bootAnimation);
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700138 virtual ~TimeCheckThread();
139 private:
140 virtual status_t readyToRun();
141 virtual bool threadLoop();
142 bool doThreadLoop();
143 void addTimeDirWatch();
144
145 int mInotifyFd;
146 int mSystemWd;
147 int mTimeWd;
148 BootAnimation* mBootAnimation;
149 };
150
Marin Shalamanov1a6e3682020-05-18 19:05:17 +0200151 // Display event handling
152 class DisplayEventCallback;
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 Shalamanov1a6e3682020-05-18 19:05:17 +0200172 EGLConfig getEglConfig(const EGLDisplay&);
Marin Shalamanov047802d2020-05-19 23:55:12 +0200173 ui::Size limitSurfaceSize(int width, int height) const;
Marin Shalamanov1a6e3682020-05-18 19:05:17 +0200174 void resizeSurface(int newWidth, int newHeight);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175
Kevin Hesterd3782b22012-04-26 10:38:55 -0700176 void checkExit();
177
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200178 void handleViewport(nsecs_t timestep);
179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 sp<SurfaceComposerClient> mSession;
181 AssetManager mAssets;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700182 Texture mAndroid[2];
183 int mWidth;
184 int mHeight;
Marin Shalamanov047802d2020-05-19 23:55:12 +0200185 int mMaxWidth = 0;
186 int mMaxHeight = 0;
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200187 int mCurrentInset;
188 int mTargetInset;
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530189 bool mUseNpotTextures = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 EGLDisplay mDisplay;
191 EGLDisplay mContext;
192 EGLDisplay mSurface;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800193 sp<IBinder> mDisplayToken;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700194 sp<SurfaceControl> mFlingerSurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 sp<Surface> mFlingerSurface;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800196 bool mClockEnabled;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700197 bool mTimeIsAccurate;
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700198 bool mTimeFormat12Hour;
Keun-young Parkb5938422017-03-23 13:46:24 -0700199 bool mShuttingDown;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700200 String8 mZipFileName;
201 SortedVector<String8> mLoadedFiles;
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400202 sp<TimeCheckThread> mTimeCheckThread = nullptr;
Ed Coyne7464ac92017-06-08 12:26:48 -0700203 sp<Callbacks> mCallbacks;
Huihong Luo50a2f362018-08-11 09:27:57 -0700204 Animation* mAnimation = nullptr;
Marin Shalamanov1a6e3682020-05-18 19:05:17 +0200205 std::unique_ptr<DisplayEventReceiver> mDisplayEventReceiver;
206 sp<Looper> mLooper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207};
208
209// ---------------------------------------------------------------------------
210
211}; // namespace android
212
213#endif // ANDROID_BOOTANIMATION_H