• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
23 #include <androidfw/AssetManager.h>
24 #include <utils/Thread.h>
25 
26 #include <EGL/egl.h>
27 #include <GLES/gl.h>
28 
29 class SkBitmap;
30 
31 namespace android {
32 
33 class Surface;
34 class SurfaceComposerClient;
35 class SurfaceControl;
36 
37 // ---------------------------------------------------------------------------
38 
39 class BootAnimation : public Thread, public IBinder::DeathRecipient
40 {
41 public:
42     struct Texture {
43         GLint   w;
44         GLint   h;
45         GLuint  name;
46     };
47 
48     struct Font {
49         FileMap* map;
50         Texture texture;
51         int char_width;
52         int char_height;
53     };
54 
55     struct Animation {
56         struct Frame {
57             String8 name;
58             FileMap* map;
59             int trimX;
60             int trimY;
61             int trimWidth;
62             int trimHeight;
63             mutable GLuint tid;
64             bool operator < (const Frame& rhs) const {
65                 return name < rhs.name;
66             }
67         };
68         struct Part {
69             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
71             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.
77             String8 path;
78             String8 trimData;
79             SortedVector<Frame> frames;
80             bool playUntilComplete;
81             float backgroundColor[3];
82             uint8_t* audioData;
83             int audioLength;
84             Animation* animation;
85         };
86         int fps;
87         int width;
88         int height;
89         Vector<Part> parts;
90         String8 audioConf;
91         String8 fileName;
92         ZipFileRO* zip;
93         Font clockFont;
94     };
95 
96     // 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.
init(const Vector<Animation::Part> &)101         virtual void init(const Vector<Animation::Part>& /*parts*/) {}
102 
103         // 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.
playPart(int,const Animation::Part &,int)109         virtual void playPart(int /*partNumber*/, const Animation::Part& /*part*/,
110                               int /*playNumber*/) {}
111 
112         // Will be called when animation is done and thread is shutting down.
shutdown()113         virtual void shutdown() {}
114     };
115 
116     BootAnimation(sp<Callbacks> callbacks);
117 
118     sp<SurfaceComposerClient> session() const;
119 
120 private:
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 
144     status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
145     status_t initTexture(FileMap* map, int* width, int* height);
146     status_t initFont(Font* font, const char* fallback);
147     bool android();
148     bool movie();
149     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);
152     Animation* loadAnimation(const String8&);
153     bool playAnimation(const Animation&);
154     void releaseAnimation(Animation*) const;
155     bool parseAnimationDesc(Animation&);
156     bool preloadZip(Animation &animation);
157 
158     void checkExit();
159 
160     sp<SurfaceComposerClient>       mSession;
161     AssetManager mAssets;
162     Texture     mAndroid[2];
163     int         mWidth;
164     int         mHeight;
165     bool        mUseNpotTextures = false;
166     EGLDisplay  mDisplay;
167     EGLDisplay  mContext;
168     EGLDisplay  mSurface;
169     sp<SurfaceControl> mFlingerSurfaceControl;
170     sp<Surface> mFlingerSurface;
171     bool        mClockEnabled;
172     bool        mTimeIsAccurate;
173     bool        mTimeFormat12Hour;
174     bool        mShuttingDown;
175     String8     mZipFileName;
176     SortedVector<String8> mLoadedFiles;
177     sp<TimeCheckThread> mTimeCheckThread = nullptr;
178     sp<Callbacks> mCallbacks;
179 };
180 
181 // ---------------------------------------------------------------------------
182 
183 }; // namespace android
184 
185 #endif // ANDROID_BOOTANIMATION_H
186