From 36445e454be2faf6992270cdba72107d4b0932a4 Mon Sep 17 00:00:00 2001 From: Steve Kondik Date: Tue, 25 Sep 2012 17:29:38 -0700 Subject: [PATCH] hwc: Support VSYNC notification via sysfs * Poll on FB0 sysfs for VSYNC events. This requires kernel support to call sysfs_notify instead of sending a uevent. Change-Id: I48734d8ffdd59dc1de7064fa004af1332ceb7623 --- libhwcomposer/hwc_uevents.cpp | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/libhwcomposer/hwc_uevents.cpp b/libhwcomposer/hwc_uevents.cpp index dc94eac..931b8d6 100644 --- a/libhwcomposer/hwc_uevents.cpp +++ b/libhwcomposer/hwc_uevents.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "hwc_utils.h" #include "hwc_external.h" @@ -102,11 +103,48 @@ static void *uevent_loop(void *param) return NULL; } +static void *vsync_loop(void *param) +{ + static char buf[4096]; + int fb0_vsync_fd; + fd_set exceptfds; + int res; + int64_t timestamp = 0; + hwc_context_t * ctx = reinterpret_cast(param); + hwc_procs* proc = (hwc_procs*)ctx->device.reserved_proc[0]; + + fb0_vsync_fd = open("/sys/devices/virtual/graphics/fb0/vsync_time", O_RDONLY); + if (!fb0_vsync_fd) + return NULL; + + char thread_name[64] = "hwcVsyncThread"; + prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0); + setpriority(PRIO_PROCESS, 0, -20); + memset(buf, 0, sizeof(buf)); + + ALOGI("Using sysfs mechanism for VSYNC notification"); + + FD_ZERO(&exceptfds); + FD_SET(fb0_vsync_fd, &exceptfds); + + do { + ssize_t len = read(fb0_vsync_fd, buf, sizeof(buf)); + timestamp = strtoull(buf, NULL, 0); + proc->vsync(proc, 0, timestamp); + select(fb0_vsync_fd + 1, NULL, NULL, &exceptfds, NULL); + lseek(fb0_vsync_fd, 0, SEEK_SET); + } while (1); + + return NULL; +} + void init_uevent_thread(hwc_context_t* ctx) { pthread_t uevent_thread; + pthread_t vsync_thread; ALOGI("Initializing UEvent Listener Thread"); pthread_create(&uevent_thread, NULL, uevent_loop, (void*) ctx); + pthread_create(&vsync_thread, NULL, vsync_loop, (void*) ctx); } }; //namespace