blob: 181ef1c596d1529ea2e20bb2959a33ca16abcde2 [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:
Geoffrey Pitscha9173532016-07-19 14:56:39 -040042 BootAnimation();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
Mathias Agopianbc726112009-09-23 15:44:05 -070044 sp<SurfaceComposerClient> session() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
46private:
47 virtual bool threadLoop();
48 virtual status_t readyToRun();
49 virtual void onFirstRef();
Mathias Agopianbc726112009-09-23 15:44:05 -070050 virtual void binderDied(const wp<IBinder>& who);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051
Damien Bargiacchi97480862016-03-29 14:55:55 -070052 bool updateIsTimeAccurate();
53
54 class TimeCheckThread : public Thread {
55 public:
56 TimeCheckThread(BootAnimation* bootAnimation);
57 virtual ~TimeCheckThread();
58 private:
59 virtual status_t readyToRun();
60 virtual bool threadLoop();
61 bool doThreadLoop();
62 void addTimeDirWatch();
63
64 int mInotifyFd;
65 int mSystemWd;
66 int mTimeWd;
67 BootAnimation* mBootAnimation;
68 };
69
Geoffrey Pitscha9173532016-07-19 14:56:39 -040070 class InitAudioThread : public Thread {
71 public:
72 InitAudioThread(uint8_t* exampleAudioData, int mExampleAudioLength);
73 private:
74 virtual bool threadLoop();
75
76 uint8_t* mExampleAudioData;
77 int mExampleAudioLength;
78 };
79
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 struct Texture {
81 GLint w;
82 GLint h;
83 GLuint name;
84 };
85
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070086 struct Font {
87 FileMap* map;
88 Texture texture;
89 int char_width;
90 int char_height;
91 };
92
Mathias Agopiana8826d62009-10-01 03:10:14 -070093 struct Animation {
94 struct Frame {
95 String8 name;
96 FileMap* map;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -040097 int trimX;
98 int trimY;
99 int trimWidth;
100 int trimHeight;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700101 mutable GLuint tid;
102 bool operator < (const Frame& rhs) const {
103 return name < rhs.name;
104 }
105 };
106 struct Part {
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800107 int count; // The number of times this part should repeat, 0 for infinite
108 int pause; // The number of frames to pause for at the end of this part
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700109 int clockPosX; // The x position of the clock, in pixels. Positive values offset from
110 // the left of the screen, negative values offset from the right.
111 int clockPosY; // The y position of the clock, in pixels. Positive values offset from
112 // the bottom of the screen, negative values offset from the top.
113 // If either of the above are INT_MIN the clock is disabled, if INT_MAX
114 // the clock is centred on that axis.
Mathias Agopiana8826d62009-10-01 03:10:14 -0700115 String8 path;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400116 String8 trimData;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700117 SortedVector<Frame> frames;
Kevin Hesterd3782b22012-04-26 10:38:55 -0700118 bool playUntilComplete;
Jesse Hall083b84c2014-09-22 10:51:09 -0700119 float backgroundColor[3];
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700120 uint8_t* audioData;
121 int audioLength;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700122 Animation* animation;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700123 };
124 int fps;
125 int width;
126 int height;
127 Vector<Part> parts;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700128 String8 audioConf;
129 String8 fileName;
130 ZipFileRO* zip;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700131 Font clockFont;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700132 };
133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700135 status_t initTexture(FileMap* map, int* width, int* height);
136 status_t initFont(Font* font, const char* fallback);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 bool android();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700138 bool movie();
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700139 void drawText(const char* str, const Font& font, bool bold, int* x, int* y);
140 void drawClock(const Font& font, const int xPos, const int yPos);
141 bool validClock(const Animation::Part& part);
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700142 Animation* loadAnimation(const String8&);
143 bool playAnimation(const Animation&);
144 void releaseAnimation(Animation*) const;
145 bool parseAnimationDesc(Animation&);
146 bool preloadZip(Animation &animation);
Geoffrey Pitsch290c4352016-08-09 14:35:10 -0400147 bool playSoundsAllowed() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148
Kevin Hesterd3782b22012-04-26 10:38:55 -0700149 void checkExit();
150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 sp<SurfaceComposerClient> mSession;
152 AssetManager mAssets;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700153 Texture mAndroid[2];
154 int mWidth;
155 int mHeight;
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530156 bool mUseNpotTextures = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 EGLDisplay mDisplay;
158 EGLDisplay mContext;
159 EGLDisplay mSurface;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700160 sp<SurfaceControl> mFlingerSurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 sp<Surface> mFlingerSurface;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800162 bool mClockEnabled;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700163 bool mTimeIsAccurate;
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700164 bool mTimeFormat12Hour;
Geoffrey Pitsch290c4352016-08-09 14:35:10 -0400165 bool mSystemBoot;
Keun-young Parkb5938422017-03-23 13:46:24 -0700166 bool mShuttingDown;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700167 String8 mZipFileName;
168 SortedVector<String8> mLoadedFiles;
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400169 sp<TimeCheckThread> mTimeCheckThread = nullptr;
170 sp<InitAudioThread> mInitAudioThread = nullptr;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171};
172
173// ---------------------------------------------------------------------------
174
175}; // namespace android
176
177#endif // ANDROID_BOOTANIMATION_H