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

Commit e6b54405 authored by Emilio López's avatar Emilio López Committed by Steve Kondik
Browse files

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
parent 14f9eecd
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -21,6 +21,18 @@ 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

LOCAL_MODULE:= bootanimation


+40 −2
Original line number Diff line number Diff line
@@ -286,6 +286,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 {
            LOGW("Unable to allocate memory to preload the animation");
        }
        fclose(fd);
    }
#endif

    return NO_ERROR;
}

@@ -443,7 +475,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
@@ -494,8 +526,14 @@ 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);

@@ -567,7 +605,7 @@ bool BootAnimation::movie()

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