Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit df09f053 authored by Prashant Somashekar's avatar Prashant Somashekar
Browse files

bootanimation: performance/speedup enhancements (squashed from CM10)

bootanim: Don't cache textures if they're expected to use a lot of VRAM (rmcc)
https://github.com/CyanogenMod/android_frameworks_base/commit/14f9eecd3f543a25c4a2053d6155a9396a777a3a#cmds/bootanimation

bootanimation: performance enhancements (turl)
https://github.com/CyanogenMod/android_frameworks_base/commit/e6b54405aa70d7503a114d9c90ef7518abdd7133#cmds/bootanimation

bootanimation: fix usage of LOGW (intervigilium)
https://github.com/CyanogenMod/android_frameworks_base/commit/e45cf7d232490f44aecf8f2447220a8b5ace4c10#cmds/bootanimation

bootanimation: allow using RGB565 instead of ARGB8888 (tpruvot)
https://github.com/CyanogenMod/android_frameworks_base/commit/204282870a9c69b04ad5ddecd73fafbd7996cbc0#cmds/bootanimation

Change-Id: I203fa23f77d1349fb822a7662e2cd3998ba4c814

bootanim: Don't cache textures if they're expected to use a lot of VRAM

bootanimation cached all the textures generated until the animation
was completed.
For Hi-res animations with lots of frames (like the new CM9 anim on
xhdpi devices), this implied using large amounts of video RAM, more
than most devices actually have available, causing the animation to
stall (and in some cases, gralloc to lock up); so if an animation is
expected to use a lot of RAM (rough estimation based on frame size
and number of frames), disable cache entirely and generate the textures
on demand

Change-Id: I157e5cdde2aab1d82d980d77cbedd9f127c83a1d

Conflicts:

	cmds/bootanimation/BootAnimation.cpp

bootanimation: performance enhancements

This patch implements two simple performance enhancements, which
might benefit devices. They are completely opt-in by setting
the following variables.

  * TARGET_BOOTANIMATION_PRELOAD: will preload the bootanimation
    zip to memory; this is handy on devices where the storage
    might be slow. By preloading it, we get quick access to the
    zip file, and the animation doesn't stutter.

  * TARGET_BOOTANIMATION_TEXTURE_CACHE: allows maintainers to
    force texture cache on/off.

Also fixes the sign warnings related to int / size_t comparison

Change-Id: Ie92d1b0aa90b43ba39c368a2a33657a60c3a64b5

Conflicts:

	cmds/bootanimation/BootAnimation.cpp

bootanimation: fix usage of LOGW

Change-Id: I1d59df9f44f414d80058a532644cbbb40e22c701

bootanimation: allow using RGB565 instead of ARGB8888

RGB565 uses considerably less memory, and together with texture
cache, it allows us to offer a really smooth bootanimation on
not so powerful devices.

Change-Id: I9da8fd7e6a587b5895519dd0983ec9b8f676771b
parent 0588df9b
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -21,6 +21,22 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_C_INCLUDES := \
	$(call include-path-for, corecg graphics)

ifeq ($(TARGET_BOOTANIMATION_PRELOAD),true)
    LOCAL_CFLAGS += -DPRELOAD_BOOTANIMATION
endif

ifeq ($(TARGET_BOOTANIMATION_TEXTURE_CACHE),true)
    LOCAL_CFLAGS += -DNO_TEXTURE_CACHE=0
endif

ifeq ($(TARGET_BOOTANIMATION_TEXTURE_CACHE),false)
    LOCAL_CFLAGS += -DNO_TEXTURE_CACHE=1
endif

ifeq ($(TARGET_BOOTANIMATION_USE_RGB565),true)
    LOCAL_CFLAGS += -DUSE_565
endif

LOCAL_MODULE:= bootanimation


+52 −4
Original line number Diff line number Diff line
@@ -162,7 +162,11 @@ status_t BootAnimation::initTexture(void* buffer, size_t len)
    codec->setDitherImage(false);
    if (codec) {
        codec->decode(&stream, &bitmap,
                #ifdef USE_565
                SkBitmap::kRGB_565_Config,
                #else
                SkBitmap::kARGB_8888_Config,
                #endif
                SkImageDecoder::kDecodePixels_Mode);
        delete codec;
    }
@@ -289,6 +293,38 @@ status_t BootAnimation::readyToRun() {
        mAndroidAnimation = false;
    }


#ifdef PRELOAD_BOOTANIMATION
    // Preload the bootanimation zip on memory, so we don't stutter
    // when showing the animation
    FILE* fd;
    if (encryptedAnimation && access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0)
        fd = fopen(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, "r");
    else if (access(USER_BOOTANIMATION_FILE, R_OK) == 0)
        fd = fopen(USER_BOOTANIMATION_FILE, "r");
    else if (access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0)
        fd = fopen(SYSTEM_BOOTANIMATION_FILE, "r");
    else
        return NO_ERROR;

    if (fd != NULL) {
        // We could use readahead..
        // ... if bionic supported it :(
        //readahead(fd, 0, INT_MAX);
        void *crappyBuffer = malloc(2*1024*1024);
        if (crappyBuffer != NULL) {
            // Read all the zip
            while (!feof(fd))
                fread(crappyBuffer, 1024, 2*1024, fd);

            free(crappyBuffer);
        } else {
            ALOGW("Unable to allocate memory to preload the animation");
        }
        fclose(fd);
    }
#endif

    return NO_ERROR;
}

@@ -446,7 +482,7 @@ bool BootAnimation::movie()
            const String8 path(entryName.getPathDir());
            const String8 leaf(entryName.getPathLeaf());
            if (leaf.size() > 0) {
                for (int j=0 ; j<pcount ; j++) {
                for (size_t j=0 ; j<pcount ; j++) {
                    if (path == animation.parts[j].path) {
                        int method;
                        // supports only stored png files
@@ -497,6 +533,15 @@ bool BootAnimation::movie()
    for (int i=0 ; i<pcount ; i++) {
        const Animation::Part& part(animation.parts[i]);
        const size_t fcount = part.frames.size();

        // can be 1, 0, or not set
        #ifdef NO_TEXTURE_CACHE
        const int noTextureCache = NO_TEXTURE_CACHE;
        #else
        const int noTextureCache = ((animation.width * animation.height * fcount) >
                                 48 * 1024 * 1024) ? 1 : 0;
        #endif

        glBindTexture(GL_TEXTURE_2D, 0);

        for (int r=0 ; !part.count || r<part.count ; r++) {
@@ -508,7 +553,7 @@ bool BootAnimation::movie()
                const Animation::Frame& frame(part.frames[j]);
                nsecs_t lastFrame = systemTime();

                if (r > 0) {
                if (r > 0 && !noTextureCache) {
                    glBindTexture(GL_TEXTURE_2D, frame.tid);
                } else {
                    if (part.count != 1) {
@@ -553,6 +598,9 @@ bool BootAnimation::movie()
                }

                checkExit();

                if (noTextureCache)
                    glDeleteTextures(1, &frame.tid);
            }

            usleep(part.pause * ns2us(frameDuration));
@@ -563,8 +611,8 @@ bool BootAnimation::movie()
        }

        // free the textures for this part
        if (part.count != 1) {
            for (int j=0 ; j<fcount ; j++) {
        if (part.count != 1 && !noTextureCache) {
            for (size_t j=0 ; j<fcount ; j++) {
                const Animation::Frame& frame(part.frames[j]);
                glDeleteTextures(1, &frame.tid);
            }