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 Surface; 34class SurfaceComposerClient; 35class SurfaceControl; 36 37// --------------------------------------------------------------------------- 38 39class BootAnimation : public Thread, public IBinder::DeathRecipient 40{ 41public: 42 BootAnimation(); 43 44 sp<SurfaceComposerClient> session() const; 45 46private: 47 virtual bool threadLoop(); 48 virtual status_t readyToRun(); 49 virtual void onFirstRef(); 50 virtual void binderDied(const wp<IBinder>& who); 51 52 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 70 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 80 struct Texture { 81 GLint w; 82 GLint h; 83 GLuint name; 84 }; 85 86 struct Font { 87 FileMap* map; 88 Texture texture; 89 int char_width; 90 int char_height; 91 }; 92 93 struct Animation { 94 struct Frame { 95 String8 name; 96 FileMap* map; 97 int trimX; 98 int trimY; 99 int trimWidth; 100 int trimHeight; 101 mutable GLuint tid; 102 bool operator < (const Frame& rhs) const { 103 return name < rhs.name; 104 } 105 }; 106 struct Part { 107 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 109 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. 115 String8 path; 116 String8 trimData; 117 SortedVector<Frame> frames; 118 bool playUntilComplete; 119 float backgroundColor[3]; 120 uint8_t* audioData; 121 int audioLength; 122 Animation* animation; 123 }; 124 int fps; 125 int width; 126 int height; 127 Vector<Part> parts; 128 String8 audioConf; 129 String8 fileName; 130 ZipFileRO* zip; 131 Font clockFont; 132 }; 133 134 status_t initTexture(Texture* texture, AssetManager& asset, const char* name); 135 status_t initTexture(FileMap* map, int* width, int* height); 136 status_t initFont(Font* font, const char* fallback); 137 bool android(); 138 bool movie(); 139 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); 142 Animation* loadAnimation(const String8&); 143 bool playAnimation(const Animation&); 144 void releaseAnimation(Animation*) const; 145 bool parseAnimationDesc(Animation&); 146 bool preloadZip(Animation &animation); 147 bool playSoundsAllowed() const; 148 149 void checkExit(); 150 151 sp<SurfaceComposerClient> mSession; 152 AssetManager mAssets; 153 Texture mAndroid[2]; 154 int mWidth; 155 int mHeight; 156 bool mUseNpotTextures = false; 157 EGLDisplay mDisplay; 158 EGLDisplay mContext; 159 EGLDisplay mSurface; 160 sp<SurfaceControl> mFlingerSurfaceControl; 161 sp<Surface> mFlingerSurface; 162 bool mClockEnabled; 163 bool mTimeIsAccurate; 164 bool mTimeFormat12Hour; 165 bool mSystemBoot; 166 bool mShuttingDown; 167 String8 mZipFileName; 168 SortedVector<String8> mLoadedFiles; 169 sp<TimeCheckThread> mTimeCheckThread = nullptr; 170 sp<InitAudioThread> mInitAudioThread = nullptr; 171}; 172 173// --------------------------------------------------------------------------- 174 175}; // namespace android 176 177#endif // ANDROID_BOOTANIMATION_H 178