diff options
author | Huihong Luo <huisinro@google.com> | 2018-08-11 09:27:57 -0700 |
---|---|---|
committer | Huihong Luo <huisinro@google.com> | 2019-02-14 13:37:34 -0800 |
commit | 50a2f36f73902e77776f4ee9921f62054dd8a72a (patch) | |
tree | b8e197c86d0132edc85016b715b100a33b910c84 | |
parent | dbc9708897b7043a3ea7d8fe8db48da0fdd4cc0d (diff) |
Preload zip before waiting for surface flinger
This saves about 200 msec by preloading media zip file before waiting
for surface flinger becomes ready.
Android Auto results:
BootAnimation: BootAnimationPreloadTiming start time: 8261ms
BootAnimation: BootAnimationPreloadStopTiming start time: 8508ms
Bug: 62056504
Test: adb logcat -s BootAnimation
Change-Id: Iaedf774983a66c2838452c45a04b3a1f4c728f17
-rw-r--r-- | cmds/bootanimation/BootAnimation.cpp | 69 | ||||
-rw-r--r-- | cmds/bootanimation/BootAnimation.h | 4 | ||||
-rw-r--r-- | cmds/bootanimation/bootanimation_main.cpp | 8 |
3 files changed, 64 insertions, 17 deletions
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp index 46917e4f6062..a6c7cae9bdb6 100644 --- a/cmds/bootanimation/BootAnimation.cpp +++ b/cmds/bootanimation/BootAnimation.cpp @@ -110,13 +110,30 @@ BootAnimation::BootAnimation(sp<Callbacks> callbacks) } else { mShuttingDown = true; } + ALOGD("%sAnimationStartTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", + elapsedRealtime()); +} + +BootAnimation::~BootAnimation() { + if (mAnimation != nullptr) { + releaseAnimation(mAnimation); + mAnimation = nullptr; + } + ALOGD("%sAnimationStopTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", + elapsedRealtime()); } void BootAnimation::onFirstRef() { status_t err = mSession->linkToComposerDeath(this); SLOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err)); if (err == NO_ERROR) { - run("BootAnimation", PRIORITY_DISPLAY); + // Load the animation content -- this can be slow (eg 200ms) + // called before waitForSurfaceFlinger() in main() to avoid wait + ALOGD("%sAnimationPreloadTiming start time: %" PRId64 "ms", + mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime()); + preloadAnimation(); + ALOGD("%sAnimationPreloadStopTiming start time: %" PRId64 "ms", + mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime()); } } @@ -306,6 +323,20 @@ status_t BootAnimation::readyToRun() { mFlingerSurface = s; mTargetInset = -1; + return NO_ERROR; +} + +bool BootAnimation::preloadAnimation() { + findBootAnimationFile(); + if (!mZipFileName.isEmpty()) { + mAnimation = loadAnimation(mZipFileName); + return (mAnimation != nullptr); + } + + return false; +} + +void BootAnimation::findBootAnimationFile() { // If the device has encryption turned on or is in process // of being encrypted we show the encrypted boot animation. char decrypt[PROPERTY_VALUE_MAX]; @@ -320,7 +351,7 @@ status_t BootAnimation::readyToRun() { for (const char* f : encryptedBootFiles) { if (access(f, R_OK) == 0) { mZipFileName = f; - return NO_ERROR; + return; } } } @@ -332,10 +363,9 @@ status_t BootAnimation::readyToRun() { for (const char* f : (!mShuttingDown ? bootFiles : shutdownFiles)) { if (access(f, R_OK) == 0) { mZipFileName = f; - return NO_ERROR; + return; } } - return NO_ERROR; } bool BootAnimation::threadLoop() @@ -790,8 +820,6 @@ bool BootAnimation::preloadZip(Animation& animation) } } - mCallbacks->init(animation.parts); - zip->endIteration(cookie); return true; @@ -799,13 +827,25 @@ bool BootAnimation::preloadZip(Animation& animation) bool BootAnimation::movie() { - Animation* animation = loadAnimation(mZipFileName); - if (animation == NULL) + if (mAnimation == nullptr) { + mAnimation = loadAnimation(mZipFileName); + } + + if (mAnimation == nullptr) return false; + // mCallbacks->init() may get called recursively, + // this loop is needed to get the same results + for (const Animation::Part& part : mAnimation->parts) { + if (part.animation != nullptr) { + mCallbacks->init(part.animation->parts); + } + } + mCallbacks->init(mAnimation->parts); + bool anyPartHasClock = false; - for (size_t i=0; i < animation->parts.size(); i++) { - if(validClock(animation->parts[i])) { + for (size_t i=0; i < mAnimation->parts.size(); i++) { + if(validClock(mAnimation->parts[i])) { anyPartHasClock = true; break; } @@ -846,7 +886,7 @@ bool BootAnimation::movie() bool clockFontInitialized = false; if (mClockEnabled) { clockFontInitialized = - (initFont(&animation->clockFont, CLOCK_FONT_ASSET) == NO_ERROR); + (initFont(&mAnimation->clockFont, CLOCK_FONT_ASSET) == NO_ERROR); mClockEnabled = clockFontInitialized; } @@ -855,7 +895,7 @@ bool BootAnimation::movie() mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL); } - playAnimation(*animation); + playAnimation(*mAnimation); if (mTimeCheckThread != nullptr) { mTimeCheckThread->requestExit(); @@ -863,10 +903,11 @@ bool BootAnimation::movie() } if (clockFontInitialized) { - glDeleteTextures(1, &animation->clockFont.texture.name); + glDeleteTextures(1, &mAnimation->clockFont.texture.name); } - releaseAnimation(animation); + releaseAnimation(mAnimation); + mAnimation = nullptr; return false; } diff --git a/cmds/bootanimation/BootAnimation.h b/cmds/bootanimation/BootAnimation.h index 19616cb790c7..dc19fb09ef1d 100644 --- a/cmds/bootanimation/BootAnimation.h +++ b/cmds/bootanimation/BootAnimation.h @@ -115,6 +115,7 @@ public: }; explicit BootAnimation(sp<Callbacks> callbacks); + virtual ~BootAnimation(); sp<SurfaceComposerClient> session() const; @@ -155,6 +156,8 @@ private: void releaseAnimation(Animation*) const; bool parseAnimationDesc(Animation&); bool preloadZip(Animation &animation); + void findBootAnimationFile(); + bool preloadAnimation(); void checkExit(); @@ -182,6 +185,7 @@ private: SortedVector<String8> mLoadedFiles; sp<TimeCheckThread> mTimeCheckThread = nullptr; sp<Callbacks> mCallbacks; + Animation* mAnimation = nullptr; }; // --------------------------------------------------------------------------- diff --git a/cmds/bootanimation/bootanimation_main.cpp b/cmds/bootanimation/bootanimation_main.cpp index a52a5e92a840..6c7b3e51ff8d 100644 --- a/cmds/bootanimation/bootanimation_main.cpp +++ b/cmds/bootanimation/bootanimation_main.cpp @@ -44,14 +44,16 @@ int main() sp<ProcessState> proc(ProcessState::self()); ProcessState::self()->startThreadPool(); + // create the boot animation object (may take up to 200ms for 2MB zip) + sp<BootAnimation> boot = new BootAnimation(audioplay::createAnimationCallbacks()); + waitForSurfaceFlinger(); - // create the boot animation object - sp<BootAnimation> boot = new BootAnimation(audioplay::createAnimationCallbacks()); + boot->run("BootAnimation", PRIORITY_DISPLAY); + ALOGV("Boot animation set up. Joining pool."); IPCThreadState::self()->joinThreadPool(); } - ALOGV("Boot animation exit"); return 0; } |