Merge "resolve merge conflicts of 0c7535b to nyc-dev" into nyc-dev

This commit is contained in:
Andriy Naborskyy
2016-03-25 01:06:47 +00:00
committed by Android (Google) Code Review
2 changed files with 116 additions and 35 deletions

View File

@@ -68,14 +68,11 @@ static const int ANIM_ENTRY_NAME_MAX = 256;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
BootAnimation::BootAnimation() : Thread(false), mZip(NULL), mClockEnabled(true) { BootAnimation::BootAnimation() : Thread(false), mClockEnabled(true) {
mSession = new SurfaceComposerClient(); mSession = new SurfaceComposerClient();
} }
BootAnimation::~BootAnimation() { BootAnimation::~BootAnimation() {
if (mZip != NULL) {
delete mZip;
}
} }
void BootAnimation::onFirstRef() { void BootAnimation::onFirstRef() {
@@ -288,19 +285,15 @@ status_t BootAnimation::readyToRun() {
bool encryptedAnimation = atoi(decrypt) != 0 || !strcmp("trigger_restart_min_framework", decrypt); bool encryptedAnimation = atoi(decrypt) != 0 || !strcmp("trigger_restart_min_framework", decrypt);
ZipFileRO* zipFile = NULL; if (encryptedAnimation && (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0)) {
if ((encryptedAnimation && mZipFileName = SYSTEM_ENCRYPTED_BOOTANIMATION_FILE;
(access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0) && }
((zipFile = ZipFileRO::open(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE)) != NULL)) || else if (access(OEM_BOOTANIMATION_FILE, R_OK) == 0) {
mZipFileName = OEM_BOOTANIMATION_FILE;
((access(OEM_BOOTANIMATION_FILE, R_OK) == 0) && }
((zipFile = ZipFileRO::open(OEM_BOOTANIMATION_FILE)) != NULL)) || else if (access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) {
mZipFileName = SYSTEM_BOOTANIMATION_FILE;
((access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) &&
((zipFile = ZipFileRO::open(SYSTEM_BOOTANIMATION_FILE)) != NULL))) {
mZip = zipFile;
} }
return NO_ERROR; return NO_ERROR;
} }
@@ -309,7 +302,7 @@ bool BootAnimation::threadLoop()
bool r; bool r;
// We have no bootanimation file, so we use the stock android logo // We have no bootanimation file, so we use the stock android logo
// animation. // animation.
if (mZip == NULL) { if (mZipFileName.isEmpty()) {
r = android(); r = android();
} else { } else {
r = movie(); r = movie();
@@ -429,16 +422,17 @@ static bool parseColor(const char str[7], float color[3]) {
return true; return true;
} }
bool BootAnimation::readFile(const char* name, String8& outString)
static bool readFile(ZipFileRO* zip, const char* name, String8& outString)
{ {
ZipEntryRO entry = mZip->findEntryByName(name); ZipEntryRO entry = zip->findEntryByName(name);
ALOGE_IF(!entry, "couldn't find %s", name); ALOGE_IF(!entry, "couldn't find %s", name);
if (!entry) { if (!entry) {
return false; return false;
} }
FileMap* entryMap = mZip->createEntryFileMap(entry); FileMap* entryMap = zip->createEntryFileMap(entry);
mZip->releaseEntry(entry); zip->releaseEntry(entry);
ALOGE_IF(!entryMap, "entryMap is null"); ALOGE_IF(!entryMap, "entryMap is null");
if (!entryMap) { if (!entryMap) {
return false; return false;
@@ -512,18 +506,18 @@ void BootAnimation::drawTime(const Texture& clockTex, const int yPos) {
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
} }
bool BootAnimation::movie() bool BootAnimation::parseAnimationDesc(Animation& animation)
{ {
String8 desString; String8 desString;
if (!readFile("desc.txt", desString)) { if (!readFile(animation.zip, "desc.txt", desString)) {
return false; return false;
} }
char const* s = desString.string(); char const* s = desString.string();
// Create and initialize an AudioPlayer if we have an audio_conf.txt file // Create and initialize an AudioPlayer if we have an audio_conf.txt file
String8 audioConf; String8 audioConf;
if (readFile("audio_conf.txt", audioConf)) { if (readFile(animation.zip, "audio_conf.txt", audioConf)) {
mAudioPlayer = new AudioPlayer; mAudioPlayer = new AudioPlayer;
if (!mAudioPlayer->init(audioConf.string())) { if (!mAudioPlayer->init(audioConf.string())) {
ALOGE("mAudioPlayer.init failed"); ALOGE("mAudioPlayer.init failed");
@@ -531,8 +525,6 @@ bool BootAnimation::movie()
} }
} }
Animation animation;
// Parse the description file // Parse the description file
for (;;) { for (;;) {
const char* endl = strstr(s, "\n"); const char* endl = strstr(s, "\n");
@@ -564,6 +556,7 @@ bool BootAnimation::movie()
part.path = path; part.path = path;
part.clockPosY = clockPosY; part.clockPosY = clockPosY;
part.audioFile = NULL; part.audioFile = NULL;
part.animation = NULL;
if (!parseColor(color, part.backgroundColor)) { if (!parseColor(color, part.backgroundColor)) {
ALOGE("> invalid color '#%s'", color); ALOGE("> invalid color '#%s'", color);
part.backgroundColor[0] = 0.0f; part.backgroundColor[0] = 0.0f;
@@ -572,13 +565,29 @@ bool BootAnimation::movie()
} }
animation.parts.add(part); animation.parts.add(part);
} }
else if (strcmp(l, "$SYSTEM") == 0) {
// ALOGD("> SYSTEM");
Animation::Part part;
part.playUntilComplete = false;
part.count = 1;
part.pause = 0;
part.audioFile = NULL;
part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE));
if (part.animation != NULL)
animation.parts.add(part);
}
s = ++endl; s = ++endl;
} }
return true;
}
bool BootAnimation::preloadZip(Animation& animation)
{
// read all the data structures // read all the data structures
const size_t pcount = animation.parts.size(); const size_t pcount = animation.parts.size();
void *cookie = NULL; void *cookie = NULL;
ZipFileRO* mZip = animation.zip;
if (!mZip->startIteration(&cookie)) { if (!mZip->startIteration(&cookie)) {
return false; return false;
} }
@@ -624,6 +633,16 @@ bool BootAnimation::movie()
mZip->endIteration(cookie); mZip->endIteration(cookie);
return true;
}
bool BootAnimation::movie()
{
Animation* animation = loadAnimation(mZipFileName);
if (animation == NULL)
return false;
// Blend required to draw time on top of animation frames. // Blend required to draw time on top of animation frames.
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_FLAT); glShadeModel(GL_FLAT);
@@ -645,6 +664,19 @@ bool BootAnimation::movie()
mClockEnabled = clockTextureInitialized; mClockEnabled = clockTextureInitialized;
} }
playAnimation(*animation);
releaseAnimation(animation);
if (clockTextureInitialized) {
glDeleteTextures(1, &mClock.name);
}
return false;
}
bool BootAnimation::playAnimation(const Animation& animation)
{
const size_t pcount = animation.parts.size();
const int xc = (mWidth - animation.width) / 2; const int xc = (mWidth - animation.width) / 2;
const int yc = ((mHeight - animation.height) / 2); const int yc = ((mHeight - animation.height) / 2);
nsecs_t frameDuration = s2ns(1) / animation.fps; nsecs_t frameDuration = s2ns(1) / animation.fps;
@@ -657,6 +689,14 @@ bool BootAnimation::movie()
const size_t fcount = part.frames.size(); const size_t fcount = part.frames.size();
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
// Handle animation package
if (part.animation != NULL) {
playAnimation(*part.animation);
if (exitPending())
break;
continue; //to next part
}
for (int r=0 ; !part.count || r<part.count ; r++) { for (int r=0 ; !part.count || r<part.count ; r++) {
// Exit any non playuntil complete parts immediately // Exit any non playuntil complete parts immediately
if(exitPending() && !part.playUntilComplete) if(exitPending() && !part.playUntilComplete)
@@ -744,14 +784,46 @@ bool BootAnimation::movie()
} }
} }
} }
return true;
if (clockTextureInitialized) {
glDeleteTextures(1, &mClock.name);
}
return false;
} }
void BootAnimation::releaseAnimation(Animation* animation) const
{
for (Vector<Animation::Part>::iterator it = animation->parts.begin(),
e = animation->parts.end(); it != e; ++it) {
if (it->animation)
releaseAnimation(it->animation);
}
if (animation->zip)
delete animation->zip;
delete animation;
}
BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn)
{
if (mLoadedFiles.indexOf(fn) >= 0) {
ALOGE("File \"%s\" is already loaded. Cyclic ref is not allowed",
fn.string());
return NULL;
}
ZipFileRO *zip = ZipFileRO::open(fn);
if (zip == NULL) {
ALOGE("Failed to open animation zip \"%s\": %s",
fn.string(), strerror(errno));
return NULL;
}
Animation *animation = new Animation;
animation->fileName = fn;
animation->zip = zip;
mLoadedFiles.add(animation->fileName);
parseAnimationDesc(*animation);
preloadZip(*animation);
mLoadedFiles.remove(fn);
return animation;
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
} }

View File

@@ -76,19 +76,27 @@ private:
bool playUntilComplete; bool playUntilComplete;
float backgroundColor[3]; float backgroundColor[3];
FileMap* audioFile; FileMap* audioFile;
Animation* animation;
}; };
int fps; int fps;
int width; int width;
int height; int height;
Vector<Part> parts; Vector<Part> parts;
String8 audioConf;
String8 fileName;
ZipFileRO* zip;
}; };
status_t initTexture(Texture* texture, AssetManager& asset, const char* name); status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
status_t initTexture(const Animation::Frame& frame); status_t initTexture(const Animation::Frame& frame);
bool android(); bool android();
bool readFile(const char* name, String8& outString);
bool movie(); bool movie();
void drawTime(const Texture& clockTex, const int yPos); void drawTime(const Texture& clockTex, const int yPos);
Animation* loadAnimation(const String8&);
bool playAnimation(const Animation&);
void releaseAnimation(Animation*) const;
bool parseAnimationDesc(Animation&);
bool preloadZip(Animation &animation);
void checkExit(); void checkExit();
@@ -104,8 +112,9 @@ private:
EGLDisplay mSurface; EGLDisplay mSurface;
sp<SurfaceControl> mFlingerSurfaceControl; sp<SurfaceControl> mFlingerSurfaceControl;
sp<Surface> mFlingerSurface; sp<Surface> mFlingerSurface;
ZipFileRO *mZip;
bool mClockEnabled; bool mClockEnabled;
String8 mZipFileName;
SortedVector<String8> mLoadedFiles;
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------