blob: 56e131523bcbb3e3801914037226b21efdb18098 [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>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026#include <EGL/egl.h>
27#include <GLES/gl.h>
28
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029class SkBitmap;
30
31namespace android {
32
Mathias Agopian8335f1c2012-02-25 18:48:35 -080033class Surface;
34class SurfaceComposerClient;
35class SurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37// ---------------------------------------------------------------------------
38
Mathias Agopianbc726112009-09-23 15:44:05 -070039class BootAnimation : public Thread, public IBinder::DeathRecipient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040{
41public:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 struct Texture {
43 GLint w;
44 GLint h;
45 GLuint name;
46 };
47
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070048 struct Font {
49 FileMap* map;
50 Texture texture;
51 int char_width;
52 int char_height;
53 };
54
Mathias Agopiana8826d62009-10-01 03:10:14 -070055 struct Animation {
56 struct Frame {
57 String8 name;
58 FileMap* map;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040059 int trimX;
60 int trimY;
61 int trimWidth;
62 int trimHeight;
Mathias Agopiana8826d62009-10-01 03:10:14 -070063 mutable GLuint tid;
64 bool operator < (const Frame& rhs) const {
65 return name < rhs.name;
66 }
67 };
68 struct Part {
Damien Bargiacchia704b7d2016-02-16 16:55:49 -080069 int count; // The number of times this part should repeat, 0 for infinite
70 int pause; // The number of frames to pause for at the end of this part
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070071 int clockPosX; // The x position of the clock, in pixels. Positive values offset from
72 // the left of the screen, negative values offset from the right.
73 int clockPosY; // The y position of the clock, in pixels. Positive values offset from
74 // the bottom of the screen, negative values offset from the top.
75 // If either of the above are INT_MIN the clock is disabled, if INT_MAX
76 // the clock is centred on that axis.
Mathias Agopiana8826d62009-10-01 03:10:14 -070077 String8 path;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040078 String8 trimData;
Mathias Agopiana8826d62009-10-01 03:10:14 -070079 SortedVector<Frame> frames;
Kevin Hesterd3782b22012-04-26 10:38:55 -070080 bool playUntilComplete;
Jesse Hall083b84c2014-09-22 10:51:09 -070081 float backgroundColor[3];
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -070082 uint8_t* audioData;
83 int audioLength;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -070084 Animation* animation;
Mathias Agopiana8826d62009-10-01 03:10:14 -070085 };
86 int fps;
87 int width;
88 int height;
89 Vector<Part> parts;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -070090 String8 audioConf;
91 String8 fileName;
92 ZipFileRO* zip;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070093 Font clockFont;
Mathias Agopiana8826d62009-10-01 03:10:14 -070094 };
95
Ed Coyne7464ac92017-06-08 12:26:48 -070096 // All callbacks will be called from this class's internal thread.
97 class Callbacks : public RefBase {
98 public:
99 // Will be called during initialization after we have loaded
100 // the animation and be provided with all parts in animation.
101 virtual void init(const Vector<Animation::Part>& /*parts*/) {}
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700102
Ed Coyne7464ac92017-06-08 12:26:48 -0700103 // Will be called while animation is playing before each part is
104 // played. It will be provided with the part and play count for it.
105 // It will be provided with the partNumber for the part about to be played,
106 // as well as a reference to the part itself. It will also be provided with
107 // which play of that part is about to start, some parts are repeated
108 // multiple times.
109 virtual void playPart(int /*partNumber*/, const Animation::Part& /*part*/,
110 int /*playNumber*/) {}
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700111
Ed Coyne7464ac92017-06-08 12:26:48 -0700112 // Will be called when animation is done and thread is shutting down.
113 virtual void shutdown() {}
114 };
115
116 BootAnimation(sp<Callbacks> callbacks);
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700117
118 sp<SurfaceComposerClient> session() const;
119
120private:
121 virtual bool threadLoop();
122 virtual status_t readyToRun();
123 virtual void onFirstRef();
124 virtual void binderDied(const wp<IBinder>& who);
125
126 bool updateIsTimeAccurate();
127
128 class TimeCheckThread : public Thread {
129 public:
130 TimeCheckThread(BootAnimation* bootAnimation);
131 virtual ~TimeCheckThread();
132 private:
133 virtual status_t readyToRun();
134 virtual bool threadLoop();
135 bool doThreadLoop();
136 void addTimeDirWatch();
137
138 int mInotifyFd;
139 int mSystemWd;
140 int mTimeWd;
141 BootAnimation* mBootAnimation;
142 };
143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700145 status_t initTexture(FileMap* map, int* width, int* height);
146 status_t initFont(Font* font, const char* fallback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 bool android();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700148 bool movie();
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700149 void drawText(const char* str, const Font& font, bool bold, int* x, int* y);
150 void drawClock(const Font& font, const int xPos, const int yPos);
151 bool validClock(const Animation::Part& part);
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700152 Animation* loadAnimation(const String8&);
153 bool playAnimation(const Animation&);
154 void releaseAnimation(Animation*) const;
155 bool parseAnimationDesc(Animation&);
156 bool preloadZip(Animation &animation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157
Kevin Hesterd3782b22012-04-26 10:38:55 -0700158 void checkExit();
159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 sp<SurfaceComposerClient> mSession;
161 AssetManager mAssets;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700162 Texture mAndroid[2];
163 int mWidth;
164 int mHeight;
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530165 bool mUseNpotTextures = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 EGLDisplay mDisplay;
167 EGLDisplay mContext;
168 EGLDisplay mSurface;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700169 sp<SurfaceControl> mFlingerSurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 sp<Surface> mFlingerSurface;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800171 bool mClockEnabled;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700172 bool mTimeIsAccurate;
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700173 bool mTimeFormat12Hour;
Keun-young Parkb5938422017-03-23 13:46:24 -0700174 bool mShuttingDown;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700175 String8 mZipFileName;
176 SortedVector<String8> mLoadedFiles;
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400177 sp<TimeCheckThread> mTimeCheckThread = nullptr;
Ed Coyne7464ac92017-06-08 12:26:48 -0700178 sp<Callbacks> mCallbacks;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179};
180
181// ---------------------------------------------------------------------------
182
183}; // namespace android
184
185#endif // ANDROID_BOOTANIMATION_H