Skip to content

Commit a545db3

Browse files
pixelflingerAndroid (Google) Code Review
authored andcommitted
Merge "fix BootAnimation timing" into jb-dev
2 parents 11fd02f + db7dd2a commit a545db3

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

cmds/bootanimation/BootAnimation.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
#define SYSTEM_BOOTANIMATION_FILE "/system/media/bootanimation.zip"
5656
#define SYSTEM_ENCRYPTED_BOOTANIMATION_FILE "/system/media/bootanimation-encrypted.zip"
5757

58+
extern "C" int clock_nanosleep(clockid_t clock_id, int flags,
59+
const struct timespec *request,
60+
struct timespec *remain);
61+
5862
namespace android {
5963

6064
// ---------------------------------------------------------------------------
@@ -476,6 +480,7 @@ bool BootAnimation::movie()
476480
for (int r=0 ; !part.count || r<part.count ; r++) {
477481
for (int j=0 ; j<fcount && !exitPending(); j++) {
478482
const Animation::Frame& frame(part.frames[j]);
483+
nsecs_t lastFrame = systemTime();
479484

480485
if (r > 0) {
481486
glBindTexture(GL_TEXTURE_2D, frame.tid);
@@ -508,10 +513,18 @@ bool BootAnimation::movie()
508513

509514
nsecs_t now = systemTime();
510515
nsecs_t delay = frameDuration - (now - lastFrame);
516+
//ALOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay));
511517
lastFrame = now;
512-
long wait = ns2us(delay);
513-
if (wait > 0)
514-
usleep(wait);
518+
519+
if (delay > 0) {
520+
struct timespec spec;
521+
spec.tv_sec = (now + delay) / 1000000000;
522+
spec.tv_nsec = (now + delay) % 1000000000;
523+
int err;
524+
do {
525+
err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL);
526+
} while (err<0 && errno == EINTR);
527+
}
515528
}
516529
usleep(part.pause * ns2us(frameDuration));
517530
}

0 commit comments

Comments
 (0)