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
29class SkBitmap;
30
31namespace android {
32
33class AudioPlayer;
34class Surface;
35class SurfaceComposerClient;
36class SurfaceControl;
37
38// ---------------------------------------------------------------------------
39
40class BootAnimation : public Thread, public IBinder::DeathRecipient
41{
42public:
43                BootAnimation();
44    virtual     ~BootAnimation();
45
46    sp<SurfaceComposerClient> session() const;
47
48private:
49    virtual bool        threadLoop();
50    virtual status_t    readyToRun();
51    virtual void        onFirstRef();
52    virtual void        binderDied(const wp<IBinder>& who);
53
54    struct Texture {
55        GLint   w;
56        GLint   h;
57        GLuint  name;
58    };
59
60    struct Animation {
61        struct Frame {
62            String8 name;
63            FileMap* map;
64            mutable GLuint tid;
65            bool operator < (const Frame& rhs) const {
66                return name < rhs.name;
67            }
68        };
69        struct Part {
70            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
72            int clockPosY;  // The y position of the clock, in pixels, from the bottom of the
73                            // display (the clock is centred horizontally). -1 to disable the clock
74            String8 path;
75            SortedVector<Frame> frames;
76            bool playUntilComplete;
77            float backgroundColor[3];
78            FileMap* audioFile;
79            Animation* animation;
80        };
81        int fps;
82        int width;
83        int height;
84        Vector<Part> parts;
85        String8 audioConf;
86        String8 fileName;
87        ZipFileRO* zip;
88    };
89
90    status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
91    status_t initTexture(const Animation::Frame& frame);
92    bool android();
93    bool movie();
94    void drawTime(const Texture& clockTex, const int yPos);
95    Animation* loadAnimation(const String8&);
96    bool playAnimation(const Animation&);
97    void releaseAnimation(Animation*) const;
98    bool parseAnimationDesc(Animation&);
99    bool preloadZip(Animation &animation);
100
101    void checkExit();
102
103    sp<SurfaceComposerClient>       mSession;
104    sp<AudioPlayer>                 mAudioPlayer;
105    AssetManager mAssets;
106    Texture     mAndroid[2];
107    Texture     mClock;
108    int         mWidth;
109    int         mHeight;
110    EGLDisplay  mDisplay;
111    EGLDisplay  mContext;
112    EGLDisplay  mSurface;
113    sp<SurfaceControl> mFlingerSurfaceControl;
114    sp<Surface> mFlingerSurface;
115    bool        mClockEnabled;
116    String8     mZipFileName;
117    SortedVector<String8> mLoadedFiles;
118};
119
120// ---------------------------------------------------------------------------
121
122}; // namespace android
123
124#endif // ANDROID_BOOTANIMATION_H
125