summaryrefslogtreecommitdiffstats
path: root/cmds/bootanimation/BootAnimation.h
diff options
context:
space:
mode:
authorScott Mertz <scott@cyngn.com>2016-08-02 11:06:46 -0700
committerSteve Kondik <shade@chemlab.org>2016-08-04 23:57:52 -0700
commit66af012f8b1e8adb18132a669d2ed2e81d7bdf42 (patch)
tree9cef29c0a0cea664e746208446018f1c4cf2f102 /cmds/bootanimation/BootAnimation.h
parent88e7a6c7fcaf71d6dae2b9067db19aaeba7de39b (diff)
downloadframeworks_base-66af012f8b1e8adb18132a669d2ed2e81d7bdf42.zip
frameworks_base-66af012f8b1e8adb18132a669d2ed2e81d7bdf42.tar.gz
frameworks_base-66af012f8b1e8adb18132a669d2ed2e81d7bdf42.tar.bz2
bootanimation: add multithreaded decode
Some devices can't keep up on a single thread trying to decode & display the frames at a high frame rate. This is observed if the sleep delay between frames is negative: 01-02 04:29:25.114 530 542 D BootAnimation: 63, -22 01-02 04:29:25.176 530 542 D BootAnimation: 61, -20 01-02 04:29:25.248 530 542 D BootAnimation: 72, -30 01-02 04:29:25.315 530 542 D BootAnimation: 66, -24 01-02 04:29:25.381 530 542 D BootAnimation: 66, -24 To mitigate this, take advantage of multiple cores by decoding on n cores and caching up to m images. This keeps the memory footprint small(ish) while still giving the best chance to maintain a constant frame rate. I measured boot time and fps for each animation part before and after the change on an msm8909 with 1.5 GB RAM: single thread: 01-02 04:40:45.826 540 556 I BootAnimation: fps = 22.40 01-02 04:40:49.457 540 556 I BootAnimation: fps = 13.22 01-02 04:40:51.464 540 556 I BootAnimation: fps = 23.92 01-02 04:41:19.375 540 556 I BootAnimation: fps = 22.89 01-02 04:41:23.942 540 556 I BootAnimation: fps = 15.55 boot time: 51.05s multi thread: 01-02 04:38:55.148 526 551 I BootAnimation: fps = 22.56 01-02 04:38:57.205 526 551 I BootAnimation: fps = 23.39 01-02 04:38:59.249 526 551 I BootAnimation: fps = 23.92 01-02 04:39:29.196 526 551 I BootAnimation: fps = 23.16 01-02 04:39:32.186 526 551 I BootAnimation: fps = 23.79 boot time: 50.50s Need to test the affect on boot time with an animation that doesn't cache the textures as much as this to see the real effect. Change-Id: If7464dc063b08a0bc33ee3f094028247b39650c1
Diffstat (limited to 'cmds/bootanimation/BootAnimation.h')
-rw-r--r--cmds/bootanimation/BootAnimation.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/cmds/bootanimation/BootAnimation.h b/cmds/bootanimation/BootAnimation.h
index a0f84da..090894f 100644
--- a/cmds/bootanimation/BootAnimation.h
+++ b/cmds/bootanimation/BootAnimation.h
@@ -26,6 +26,8 @@
#include <EGL/egl.h>
#include <GLES/gl.h>
+#include <utils/Thread.h>
+
class SkBitmap;
namespace android {
@@ -34,11 +36,17 @@ class AudioPlayer;
class Surface;
class SurfaceComposerClient;
class SurfaceControl;
+#ifdef MULTITHREAD_DECODE
+class FrameManager;
+#endif
// ---------------------------------------------------------------------------
class BootAnimation : public Thread, public IBinder::DeathRecipient
{
+#ifdef MULTITHREAD_DECODE
+ friend class FrameManager;
+#endif
public:
enum {
eOrientationDefault = 0,
@@ -89,6 +97,7 @@ private:
status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
status_t initTexture(const Animation::Frame& frame);
+ status_t initTexture(SkBitmap *bitmap);
bool android();
bool readFile(const char* name, String8& outString);
bool movie();
@@ -101,6 +110,8 @@ private:
void checkExit();
void checkShowAndroid();
+ static SkBitmap *decode(const Animation::Frame& frame);
+
sp<SurfaceComposerClient> mSession;
sp<AudioPlayer> mAudioPlayer;
AssetManager mAssets;
@@ -115,6 +126,50 @@ private:
ZipFileRO *mZip;
};
+#ifdef MULTITHREAD_DECODE
+
+class FrameManager {
+public:
+ struct DecodeWork {
+ const BootAnimation::Animation::Frame *frame;
+ SkBitmap *bitmap;
+ size_t idx;
+ };
+
+ FrameManager(int numThreads, size_t maxSize, const SortedVector<BootAnimation::Animation::Frame>& frames);
+ virtual ~FrameManager();
+
+ SkBitmap* next();
+
+protected:
+ DecodeWork getWork();
+ void completeWork(DecodeWork work);
+
+private:
+
+ class DecodeThread : public Thread {
+ public:
+ DecodeThread(FrameManager* manager);
+ virtual ~DecodeThread() {}
+ private:
+ virtual bool threadLoop();
+ FrameManager *mManager;
+ };
+
+ size_t mMaxSize;
+ size_t mFrameCounter;
+ size_t mNextIdx;
+ const SortedVector<BootAnimation::Animation::Frame>& mFrames;
+ Vector<DecodeWork> mDecodedFrames;
+ pthread_mutex_t mBitmapsMutex;
+ pthread_cond_t mSpaceAvailableCondition;
+ pthread_cond_t mBitmapReadyCondition;
+ bool mExit;
+ Vector<sp<DecodeThread> > mThreads;
+};
+
+#endif
+
// ---------------------------------------------------------------------------
}; // namespace android