Skip to content

Commit

Permalink
TEMP: Revert "bootanimation: performance/speedup enhancements"
Browse files Browse the repository at this point in the history
Let's temporarily revert this until it can be fixed.

This reverts commit af0e2d4.

Change-Id: I82151fa2350b8934148c2fda00b1bc7c6b38c6e1
  • Loading branch information
mikecriggs authored and xlxfoxxlx committed Jun 16, 2017
1 parent 2f53d68 commit 81a877f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 130 deletions.
16 changes: 0 additions & 16 deletions cmds/bootanimation/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ LOCAL_SHARED_LIBRARIES := \
libOpenSLES \
libtinyalsa

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

LOCAL_INIT_RC := bootanim.rc
Expand Down
121 changes: 7 additions & 114 deletions cmds/bootanimation/BootAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <utils/misc.h>
#include <signal.h>
#include <time.h>
#include <sys/syscall.h>

#include <cutils/properties.h>

Expand Down Expand Up @@ -102,57 +101,6 @@ static const std::vector<std::string> PLAY_SOUND_BOOTREASON_BLACKLIST {

// ---------------------------------------------------------------------------

static unsigned long getFreeMemory(void)
{
int fd = open("/proc/meminfo", O_RDONLY);
const char* const sums[] = { "MemFree:", "Cached:", NULL };
const size_t sumsLen[] = { strlen("MemFree:"), strlen("Cached:"), 0 };
unsigned int num = 2;

if (fd < 0) {
ALOGW("Unable to open /proc/meminfo");
return -1;
}

char buffer[256];
const int len = read(fd, buffer, sizeof(buffer)-1);
close(fd);

if (len < 0) {
ALOGW("Unable to read /proc/meminfo");
return -1;
}
buffer[len] = 0;

size_t numFound = 0;
unsigned long mem = 0;

char* p = buffer;
while (*p && numFound < num) {
int i = 0;
while (sums[i]) {
if (strncmp(p, sums[i], sumsLen[i]) == 0) {
p += sumsLen[i];
while (*p == ' ') p++;
char* num = p;
while (*p >= '0' && *p <= '9') p++;
if (*p != 0) {
*p = 0;
p++;
if (*p == 0) p--;
}
mem += atoll(num);
numFound++;
break;
}
i++;
}
p++;
}

return numFound > 0 ? mem : -1;
}

BootAnimation::BootAnimation() : Thread(false), mClockEnabled(true), mTimeIsAccurate(false),
mTimeFormat12Hour(false), mTimeCheckThread(NULL) {
mSession = new SurfaceComposerClient();
Expand Down Expand Up @@ -252,15 +200,16 @@ status_t BootAnimation::initTexture(FileMap* map, int* width, int* height)
if (codec != NULL) {
codec->setDitherImage(false);
codec->decode(&stream, &bitmap,
#ifdef USE_565
kRGB_565_SkColorType,
#else
kN32_SkColorType,
#endif
SkImageDecoder::kDecodePixels_Mode);
delete codec;
}

// FileMap memory is never released until application exit.
// Release it now as the texture is already loaded and the memory used for
// the packed resource can be released.
delete map;

// ensure we can call getPixels(). No need to call unlock, since the
// bitmap will go out of scope when we return from this method.
bitmap.lockPixels();
Expand Down Expand Up @@ -384,33 +333,6 @@ status_t BootAnimation::readyToRun() {
else if (access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) {
mZipFileName = SYSTEM_BOOTANIMATION_FILE;
}

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

if (fd != NULL) {
// Since including fcntl.h doesn't give us the wrapper, use the syscall.
// 32 bits takes LO/HI offset (we don't care about endianness of 0).
#if defined(__aarch64__) || defined(__x86_64__)
if (syscall(__NR_readahead, fd, 0, INT_MAX))
#else
if (syscall(__NR_readahead, fd, 0, 0, INT_MAX))
#endif
ALOGW("Unable to cache the animation");
fclose(fd);
}
#endif

return NO_ERROR;
}

Expand Down Expand Up @@ -959,34 +881,8 @@ bool BootAnimation::playAnimation(const Animation& animation)
for (size_t 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);

// Calculate if we need to save memory by disabling texture cache
// If free memory is less than the max texture size, cache will be disabled
GLint mMaxTextureSize;
bool needSaveMem = false;
GLuint mTextureid;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
ALOGD("Free memory: %ld, max texture size: %d", getFreeMemory(), mMaxTextureSize);
if (getFreeMemory() < mMaxTextureSize * mMaxTextureSize * fcount / 1024 ||
noTextureCache) {
ALOGD("Disabled bootanimation texture cache, FPS drops might occur.");
needSaveMem = true;
glGenTextures(1, &mTextureid);
glBindTexture(GL_TEXTURE_2D, mTextureid);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

// Handle animation package
if (part.animation != NULL) {
playAnimation(*part.animation);
Expand Down Expand Up @@ -1016,10 +912,10 @@ bool BootAnimation::playAnimation(const Animation& animation)
const Animation::Frame& frame(part.frames[j]);
nsecs_t lastFrame = systemTime();

if (r > 0 && !needSaveMem) {
if (r > 0) {
glBindTexture(GL_TEXTURE_2D, frame.tid);
} else {
if (!needSaveMem && part.count != 1) {
if (part.count != 1) {
glGenTextures(1, &frame.tid);
glBindTexture(GL_TEXTURE_2D, frame.tid);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Expand Down Expand Up @@ -1079,9 +975,6 @@ bool BootAnimation::playAnimation(const Animation& animation)
break;
}

if (needSaveMem) {
glDeleteTextures(1, &mTextureid);
}
}

// Free textures created for looping parts now that the animation is done.
Expand Down

0 comments on commit 81a877f

Please sign in to comment.