diff options
author | Dima Zavin <dima@android.com> | 2012-12-05 14:59:22 -0800 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2015-07-07 13:14:21 +0200 |
commit | 3cf433dd0844a96bf36a10eb115b2031a2c8ff39 (patch) | |
tree | fd2d03c403cf85140265605b4a36096c981b6f95 /gralloc | |
parent | 03d2cf828a69f3e540c1f95138938d8e7eb778c9 (diff) | |
download | android_hardware_samsung_slsi_exynos5430-3cf433dd0844a96bf36a10eb115b2031a2c8ff39.tar.gz android_hardware_samsung_slsi_exynos5430-3cf433dd0844a96bf36a10eb115b2031a2c8ff39.tar.xz android_hardware_samsung_slsi_exynos5430-3cf433dd0844a96bf36a10eb115b2031a2c8ff39.zip |
gralloc: read the screen res from the framebuffer modes list
Change-Id: Icd69c79b85ec5ce4a4ff444a98afc0da4e5c0a87
Signed-off-by: Dima Zavin <dima@android.com>
Diffstat (limited to 'gralloc')
-rw-r--r-- | gralloc/framebuffer.cpp | 73 |
1 files changed, 56 insertions, 17 deletions
diff --git a/gralloc/framebuffer.cpp b/gralloc/framebuffer.cpp index f025d9a..c44da5b 100644 --- a/gralloc/framebuffer.cpp +++ b/gralloc/framebuffer.cpp @@ -129,6 +129,53 @@ static int fb_close(struct hw_device_t *dev) return 0; } +static void get_screen_res(const char *fbname, int32_t *xres, int32_t *yres, + int32_t *refresh) +{ + char *path = NULL; + int fd; + char buf[128]; + int ret; + unsigned int _x, _y, _r; + + asprintf(&path, "/sys/class/graphics/%s/modes", fbname); + if (path == NULL) + goto err_asprintf; + + fd = open(path, O_RDONLY); + if (fd < 0) + goto err_open; + ret = read(fd, buf, sizeof(buf)); + if (ret <= 0) + goto err_read; + buf[sizeof(buf)-1] = '\0'; + + ret = sscanf(buf, "U:%ux%up-%u", &_x, &_y, &_r); + if (ret != 3) + goto err_sscanf; + + ALOGI("Using %ux%u %uHz resolution for '%s' from modes list\n", + _x, _y, _r, fbname); + + *xres = (int32_t)_x; + *yres = (int32_t)_y; + *refresh = (int32_t)_r; + + close(fd); + free(path); + return; + +err_sscanf: +err_read: + close(fd); +err_open: + free(path); +err_asprintf: + *xres = 2560; + *yres = 1600; + *refresh = 60; +} + int init_fb(struct private_module_t* module) { char const * const device_template[] = { @@ -160,19 +207,13 @@ int init_fb(struct private_module_t* module) return -errno; } - int refreshRate = 1000000000000000LLU / - ( - uint64_t( info.upper_margin + info.lower_margin + info.yres ) - * ( info.left_margin + info.right_margin + info.xres ) - * info.pixclock - ); - + int32_t refreshRate = 0; + get_screen_res("fb0", &module->xres, &module->yres, &refreshRate); if (refreshRate == 0) - refreshRate = 60*1000; /* 60 Hz */ + refreshRate = 60; /* 60 Hz */ - float xdpi = (info.xres * 25.4f) / info.width; - float ydpi = (info.yres * 25.4f) / info.height; - float fps = refreshRate / 1000.0f; + float xdpi = (module->xres * 25.4f) / info.width; + float ydpi = (module->yres * 25.4f) / info.height; ALOGI("using (id=%s)\n" "xres = %d px\n" @@ -180,15 +221,13 @@ int init_fb(struct private_module_t* module) "width = %d mm (%f dpi)\n" "height = %d mm (%f dpi)\n" "refresh rate = %.2f Hz\n", - finfo.id, info.xres, info.yres, info.width, xdpi, info.height, ydpi, - fps); + finfo.id, module->xres, module->yres, info.width, xdpi, info.height, + ydpi, (float)refreshRate); - module->xres = info.xres; - module->yres = info.yres; - module->line_length = info.xres; + module->line_length = module->xres * 4; module->xdpi = xdpi; module->ydpi = ydpi; - module->fps = fps; + module->fps = (float)refreshRate; module->info = info; module->finfo = finfo; |