blob: 3ebe7d6e4dffde92414867ebe9cff2da0a166d96 [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 Coyne2c9e94a2017-05-31 10:08:28 -070096 // Callback will be called during initialization after we have loaded
97 // the animation and be provided with all parts in animation.
98 typedef std::function<void(const Vector<Animation::Part>& parts)> InitCallback;
99
100 // Callback will be called while animation is playing before each part is
101 // played. It will be provided with the part and play count for it.
102 // It will be provided with the partNumber for the part about to be played,
103 // as well as a reference to the part itself. It will also be provided with
104 // which play of that part is about to start, some parts are repeated
105 // multiple times.
106 typedef std::function<void(int partNumber, const Animation::Part& part, int playNumber)>
107 PlayPartCallback;
108
109 // Callbacks may be null and will be called from this class's internal
110 // thread.
111 BootAnimation(InitCallback initCallback, PlayPartCallback partCallback);
112
113 sp<SurfaceComposerClient> session() const;
114
115private:
116 virtual bool threadLoop();
117 virtual status_t readyToRun();
118 virtual void onFirstRef();
119 virtual void binderDied(const wp<IBinder>& who);
120
121 bool updateIsTimeAccurate();
122
123 class TimeCheckThread : public Thread {
124 public:
125 TimeCheckThread(BootAnimation* bootAnimation);
126 virtual ~TimeCheckThread();
127 private:
128 virtual status_t readyToRun();
129 virtual bool threadLoop();
130 bool doThreadLoop();
131 void addTimeDirWatch();
132
133 int mInotifyFd;
134 int mSystemWd;
135 int mTimeWd;
136 BootAnimation* mBootAnimation;
137 };
138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700140 status_t initTexture(FileMap* map, int* width, int* height);
141 status_t initFont(Font* font, const char* fallback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 bool android();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700143 bool movie();
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700144 void drawText(const char* str, const Font& font, bool bold, int* x, int* y);
145 void drawClock(const Font& font, const int xPos, const int yPos);
146 bool validClock(const Animation::Part& part);
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700147 Animation* loadAnimation(const String8&);
148 bool playAnimation(const Animation&);
149 void releaseAnimation(Animation*) const;
150 bool parseAnimationDesc(Animation&);
151 bool preloadZip(Animation &animation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152
Kevin Hesterd3782b22012-04-26 10:38:55 -0700153 void checkExit();
154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 sp<SurfaceComposerClient> mSession;
156 AssetManager mAssets;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700157 Texture mAndroid[2];
158 int mWidth;
159 int mHeight;
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530160 bool mUseNpotTextures = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 EGLDisplay mDisplay;
162 EGLDisplay mContext;
163 EGLDisplay mSurface;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700164 sp<SurfaceControl> mFlingerSurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 sp<Surface> mFlingerSurface;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800166 bool mClockEnabled;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700167 bool mTimeIsAccurate;
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700168 bool mTimeFormat12Hour;
Keun-young Parkb5938422017-03-23 13:46:24 -0700169 bool mShuttingDown;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700170 String8 mZipFileName;
171 SortedVector<String8> mLoadedFiles;
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400172 sp<TimeCheckThread> mTimeCheckThread = nullptr;
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700173 InitCallback mInitCallback = nullptr;
174 PlayPartCallback mPlayPartCallback = nullptr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175};
176
177// ---------------------------------------------------------------------------
178
179}; // namespace android
180
181#endif // ANDROID_BOOTANIMATION_H