blob: dc19fb09ef1dee955791b7f1d043842eb96e1094 [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
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080023#include <androidfw/AssetManager.h>
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -070024#include <utils/Thread.h>
Ed Coyne33f4b7d2018-04-10 13:39:09 -070025#include <binder/IBinder.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <EGL/egl.h>
28#include <GLES/gl.h>
29
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030class SkBitmap;
31
32namespace android {
33
Mathias Agopian8335f1c2012-02-25 18:48:35 -080034class Surface;
35class SurfaceComposerClient;
36class SurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
38// ---------------------------------------------------------------------------
39
Mathias Agopianbc726112009-09-23 15:44:05 -070040class BootAnimation : public Thread, public IBinder::DeathRecipient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041{
42public:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 struct Texture {
44 GLint w;
45 GLint h;
46 GLuint name;
47 };
48
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070049 struct Font {
50 FileMap* map;
51 Texture texture;
52 int char_width;
53 int char_height;
54 };
55
Mathias Agopiana8826d62009-10-01 03:10:14 -070056 struct Animation {
57 struct Frame {
58 String8 name;
59 FileMap* map;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040060 int trimX;
61 int trimY;
62 int trimWidth;
63 int trimHeight;
Mathias Agopiana8826d62009-10-01 03:10:14 -070064 mutable GLuint tid;
65 bool operator < (const Frame& rhs) const {
66 return name < rhs.name;
67 }
68 };
69 struct Part {
Damien Bargiacchia704b7d2016-02-16 16:55:49 -080070 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 Bargiacchi0e3d2ab2016-08-29 04:11:19 -070072 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 Agopiana8826d62009-10-01 03:10:14 -070078 String8 path;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040079 String8 trimData;
Mathias Agopiana8826d62009-10-01 03:10:14 -070080 SortedVector<Frame> frames;
Kevin Hesterd3782b22012-04-26 10:38:55 -070081 bool playUntilComplete;
Jesse Hall083b84c2014-09-22 10:51:09 -070082 float backgroundColor[3];
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -070083 uint8_t* audioData;
84 int audioLength;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -070085 Animation* animation;
Mathias Agopiana8826d62009-10-01 03:10:14 -070086 };
87 int fps;
88 int width;
89 int height;
90 Vector<Part> parts;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -070091 String8 audioConf;
92 String8 fileName;
93 ZipFileRO* zip;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070094 Font clockFont;
Mathias Agopiana8826d62009-10-01 03:10:14 -070095 };
96
Ed Coyne7464ac92017-06-08 12:26:48 -070097 // 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 Coyne2c9e94a2017-05-31 10:08:28 -0700103
Ed Coyne7464ac92017-06-08 12:26:48 -0700104 // 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 Coyne2c9e94a2017-05-31 10:08:28 -0700112
Ed Coyne7464ac92017-06-08 12:26:48 -0700113 // Will be called when animation is done and thread is shutting down.
114 virtual void shutdown() {}
115 };
116
Chih-Hung Hsieha08d2c22018-12-20 13:39:40 -0800117 explicit BootAnimation(sp<Callbacks> callbacks);
Huihong Luo50a2f362018-08-11 09:27:57 -0700118 virtual ~BootAnimation();
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700119
120 sp<SurfaceComposerClient> session() const;
121
122private:
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 Hsieha08d2c22018-12-20 13:39:40 -0800132 explicit TimeCheckThread(BootAnimation* bootAnimation);
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700133 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 Project9066cfe2009-03-03 19:31:44 -0800146 status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700147 status_t initTexture(FileMap* map, int* width, int* height);
148 status_t initFont(Font* font, const char* fallback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 bool android();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700150 bool movie();
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700151 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 Naborskyy39218ba2015-08-16 21:32:50 -0700154 Animation* loadAnimation(const String8&);
155 bool playAnimation(const Animation&);
156 void releaseAnimation(Animation*) const;
157 bool parseAnimationDesc(Animation&);
158 bool preloadZip(Animation &animation);
Huihong Luo50a2f362018-08-11 09:27:57 -0700159 void findBootAnimationFile();
160 bool preloadAnimation();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161
Kevin Hesterd3782b22012-04-26 10:38:55 -0700162 void checkExit();
163
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200164 void handleViewport(nsecs_t timestep);
165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 sp<SurfaceComposerClient> mSession;
167 AssetManager mAssets;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700168 Texture mAndroid[2];
169 int mWidth;
170 int mHeight;
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200171 int mCurrentInset;
172 int mTargetInset;
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530173 bool mUseNpotTextures = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 EGLDisplay mDisplay;
175 EGLDisplay mContext;
176 EGLDisplay mSurface;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800177 sp<IBinder> mDisplayToken;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700178 sp<SurfaceControl> mFlingerSurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 sp<Surface> mFlingerSurface;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800180 bool mClockEnabled;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700181 bool mTimeIsAccurate;
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700182 bool mTimeFormat12Hour;
Keun-young Parkb5938422017-03-23 13:46:24 -0700183 bool mShuttingDown;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700184 String8 mZipFileName;
185 SortedVector<String8> mLoadedFiles;
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400186 sp<TimeCheckThread> mTimeCheckThread = nullptr;
Ed Coyne7464ac92017-06-08 12:26:48 -0700187 sp<Callbacks> mCallbacks;
Huihong Luo50a2f362018-08-11 09:27:57 -0700188 Animation* mAnimation = nullptr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189};
190
191// ---------------------------------------------------------------------------
192
193}; // namespace android
194
195#endif // ANDROID_BOOTANIMATION_H