From 352bd086b0b482a157770d4b6440164d3e742909 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 3 Apr 2015 04:07:04 +0200 Subject: [PATCH] (omap_gfx) Cleanups --- gfx/drivers/omap_gfx.c | 694 +++++++++++++++++++++-------------------- 1 file changed, 348 insertions(+), 346 deletions(-) diff --git a/gfx/drivers/omap_gfx.c b/gfx/drivers/omap_gfx.c index b1523eb98d..4fe49fac78 100644 --- a/gfx/drivers/omap_gfx.c +++ b/gfx/drivers/omap_gfx.c @@ -83,7 +83,7 @@ typedef struct omapfb_data } omapfb_data_t; -static const char *get_fb_device(void) +static const char *omapfb_get_fb_device(void) { static char fbname[12]; settings_t *settings = config_get_ptr(); @@ -93,11 +93,11 @@ static const char *get_fb_device(void) return "/dev/fb0"; snprintf(fbname, sizeof(fbname), "/dev/fb%d", fbidx - 1); - RARCH_LOG("video_omap: Using %s as framebuffer device\n", fbname); + RARCH_LOG("[video_omap]: Using %s as framebuffer device.\n", fbname); return fbname; } -static omapfb_page_t *get_page(omapfb_data_t *pdata) +static omapfb_page_t *omapfb_get_page(omapfb_data_t *pdata) { unsigned i; omapfb_page_t *page = NULL; @@ -119,7 +119,7 @@ static omapfb_page_t *get_page(omapfb_data_t *pdata) return page; } -static void page_flip(omapfb_data_t *pdata) +static void omapfb_page_flip(omapfb_data_t *pdata) { if (pdata->sync) ioctl(pdata->fd, OMAPFB_WAITFORGO); @@ -133,12 +133,12 @@ static void page_flip(omapfb_data_t *pdata) pdata->old_page->used = false; } -static int read_sysfs(const char *fname, char *buff, size_t size) +static int omapfb_read_sysfs(const char *fname, char *buff, size_t size) { int ret; FILE *f = fopen(fname, "r"); - if (f == NULL) + if (!f) return -1; ret = fread(buff, 1, size - 1, f); @@ -154,328 +154,333 @@ static int read_sysfs(const char *fname, char *buff, size_t size) return 0; } -static INLINE void put_pixel_rgb565(uint16_t *p, - unsigned r, unsigned g, unsigned b) +static INLINE void omapfb_put_pixel_rgb565( + uint16_t *p, unsigned r, unsigned g, unsigned b) { *p = (((r >> 3) & 0x1f) << 11) | (((g >> 2) & 0x3f) << 5) | ((b >> 3) & 0x1f); } -static INLINE void put_pixel_argb8888(uint32_t *p, - unsigned r, unsigned g, unsigned b) +static INLINE void omapfb_put_pixel_argb8888( + uint32_t *p, unsigned r, unsigned g, unsigned b) { *p = ((r << 16) & 0xff0000) | ((g << 8) & 0x00ff00) | ((b << 0) & 0x0000ff); } static int omapfb_detect_screen(omapfb_data_t *pdata) { - struct stat status; - int i, ret; - int w, h; - FILE *f; - int fb_id, overlay_id = -1, display_id = -1; - char buff[64], manager_name[64], display_name[64]; + struct stat status; + int i, ret; + int w, h; + FILE *f; + int fb_id, overlay_id = -1, display_id = -1; + char buff[64], manager_name[64], display_name[64]; - /* Find out the native screen resolution, which is needed to - * properly center the scaled image data. */ - ret = stat(pdata->fbname, &status); + /* Find out the native screen resolution, which is needed to + * properly center the scaled image data. */ + ret = stat(pdata->fbname, &status); - if (ret != 0) - { - RARCH_ERR("video_omap: can't stat %s\n", pdata->fbname); - return -1; - } - fb_id = minor(status.st_rdev); + if (ret != 0) + { + RARCH_ERR("[video_omap]: can't stat %s.\n", pdata->fbname); + return -1; + } + fb_id = minor(status.st_rdev); - snprintf(buff, sizeof(buff), "/sys/class/graphics/fb%d/overlays", fb_id); - f = fopen(buff, "r"); - if (f == NULL) - { - RARCH_ERR("video_omap: can't open %s\n", buff); - return -1; - } + snprintf(buff, sizeof(buff), "/sys/class/graphics/fb%d/overlays", fb_id); + f = fopen(buff, "r"); + if (!f) + { + RARCH_ERR("[video_omap]: can't open %s.\n", buff); + return -1; + } - ret = fscanf(f, "%d", &overlay_id); - fclose(f); - if (ret != 1) - { - RARCH_ERR("video_omap: can't parse %s\n", buff); - return -1; - } + ret = fscanf(f, "%d", &overlay_id); + fclose(f); + if (ret != 1) + { + RARCH_ERR("[video_omap]: can't parse %s.\n", buff); + return -1; + } - snprintf(buff, sizeof(buff), "/sys/devices/platform/omapdss/overlay%d/manager", overlay_id); - ret = read_sysfs(buff, manager_name, sizeof(manager_name)); - if (ret < 0) - { - RARCH_ERR("video_omap: can't read manager name\n"); - return -1; - } + snprintf(buff, sizeof(buff), "/sys/devices/platform/omapdss/overlay%d/manager", overlay_id); + ret = omapfb_read_sysfs(buff, manager_name, sizeof(manager_name)); + if (ret < 0) + { + RARCH_ERR("[video_omap]: can't read manager name.\n"); + return -1; + } - for (i = 0; ; i++) - { - snprintf(buff, sizeof(buff), "/sys/devices/platform/omapdss/manager%d/name", i); - ret = read_sysfs(buff, buff, sizeof(buff)); - - if (ret < 0) - break; - - if (!strcmp(manager_name, buff)) - { - snprintf(buff, sizeof(buff), "/sys/devices/platform/omapdss/manager%d/display", i); - ret = read_sysfs(buff, display_name, sizeof(display_name)); + for (i = 0; ; i++) + { + snprintf(buff, sizeof(buff), "/sys/devices/platform/omapdss/manager%d/name", i); + ret = omapfb_read_sysfs(buff, buff, sizeof(buff)); if (ret < 0) + break; + + if (!strcmp(manager_name, buff)) { - RARCH_ERR("video_omap: can't read display name\n"); - return -1; + snprintf(buff, sizeof(buff), "/sys/devices/platform/omapdss/manager%d/display", i); + ret = omapfb_read_sysfs(buff, display_name, sizeof(display_name)); + + if (ret < 0) + { + RARCH_ERR("[video_omap]: can't read display name.\n"); + return -1; + } + + break; } + } - break; - } - } + if (ret < 0) + { + RARCH_ERR("[video_omap]: couldn't find manager.\n"); + return -1; + } - if (ret < 0) - { - RARCH_ERR("video_omap: couldn't find manager\n"); - return -1; - } + for (i = 0; ; i++) + { + snprintf(buff, sizeof(buff), "/sys/devices/platform/omapdss/display%d/name", i); + ret = omapfb_read_sysfs(buff, buff, sizeof(buff)); - for (i = 0; ; i++) - { - snprintf(buff, sizeof(buff), "/sys/devices/platform/omapdss/display%d/name", i); - ret = read_sysfs(buff, buff, sizeof(buff)); + if (ret < 0) + break; - if (ret < 0) - break; + if (!strcmp(display_name, buff)) + { + display_id = i; + break; + } + } - if (!strcmp(display_name, buff)) - { - display_id = i; - break; - } - } + if (display_id < 0) + { + RARCH_ERR("[video_omap]: couldn't find display.\n"); + return -1; + } - if (display_id < 0) - { - RARCH_ERR("video_omap: couldn't find display\n"); - return -1; - } + snprintf(buff, sizeof(buff), "/sys/devices/platform/omapdss/display%d/timings", display_id); + f = fopen(buff, "r"); + if (!f) + { + RARCH_ERR("[video_omap]: can't open %s.\n", buff); + return -1; + } - snprintf(buff, sizeof(buff), "/sys/devices/platform/omapdss/display%d/timings", display_id); - f = fopen(buff, "r"); - if (f == NULL) - { - RARCH_ERR("video_omap: can't open %s\n", buff); - return -1; - } + ret = fscanf(f, "%*d,%d/%*d/%*d/%*d,%d/%*d/%*d/%*d", &w, &h); + fclose(f); + if (ret != 2) + { + RARCH_ERR("[video_omap]: can't parse %s (%d).\n", buff, ret); + return -1; + } - ret = fscanf(f, "%*d,%d/%*d/%*d/%*d,%d/%*d/%*d/%*d", &w, &h); - fclose(f); - if (ret != 2) - { - RARCH_ERR("video_omap: can't parse %s (%d)\n", buff, ret); - return -1; - } + if (w <= 0 || h <= 0) + { + RARCH_ERR("[video_omap]: unsane dimensions detected (%dx%d).\n", w, h); + return -1; + } - if (w <= 0 || h <= 0) - { - RARCH_ERR("video_omap: unsane dimensions detected (%dx%d)\n", w, h); - return -1; - } + RARCH_LOG("[video_omap]: detected %dx%d '%s' (%d) display attached to fb %d and overlay %d.\n", + w, h, display_name, display_id, fb_id, overlay_id); - RARCH_LOG("video_omap: detected %dx%d '%s' (%d) display attached to fb %d and overlay %d\n", - w, h, display_name, display_id, fb_id, overlay_id); + pdata->nat_w = w; + pdata->nat_h = h; - pdata->nat_w = w; - pdata->nat_h = h; - - return 0; + return 0; } static int omapfb_setup_pages(omapfb_data_t *pdata) { - int i; + int i; - if (pdata->pages == NULL) - { - pdata->pages = calloc(pdata->num_pages, sizeof(omapfb_page_t)); + if (!pdata->pages) + { + pdata->pages = (omapfb_page_t*)calloc(pdata->num_pages, sizeof(omapfb_page_t)); - if (pdata->pages == NULL) - { - RARCH_ERR("video_omap: pages allocation failed\n"); - return -1; - } - } + if (!pdata->pages) + { + RARCH_ERR("[video_omap]: pages allocation failed.\n"); + return -1; + } + } - for (i = 0; i < pdata->num_pages; ++i) - { - pdata->pages[i].yoffset = i * pdata->current_state->si.yres; - pdata->pages[i].buf = pdata->fb_mem + (i * pdata->fb_framesize); - pdata->pages[i].used = false; - } + for (i = 0; i < pdata->num_pages; ++i) + { + pdata->pages[i].yoffset = i * pdata->current_state->si.yres; + pdata->pages[i].buf = pdata->fb_mem + (i * pdata->fb_framesize); + pdata->pages[i].used = false; + } - pdata->old_page = NULL; - pdata->cur_page = &pdata->pages[0]; + pdata->old_page = NULL; + pdata->cur_page = &pdata->pages[0]; - memset(pdata->cur_page->buf, 0, pdata->fb_framesize); + memset(pdata->cur_page->buf, 0, pdata->fb_framesize); - page_flip(pdata); - pdata->cur_page->used = true; + omapfb_page_flip(pdata); + pdata->cur_page->used = true; - return 0; + return 0; } static int omapfb_mmap(omapfb_data_t *pdata) { - assert(pdata->fb_mem == NULL); + assert(pdata->fb_mem == NULL); - pdata->fb_mem = mmap(NULL, pdata->current_state->mi.size, PROT_WRITE, - MAP_SHARED, pdata->fd, 0); + pdata->fb_mem = mmap(NULL, pdata->current_state->mi.size, PROT_WRITE, + MAP_SHARED, pdata->fd, 0); - if (pdata->fb_mem == MAP_FAILED) - { - pdata->fb_mem = NULL; - RARCH_ERR("video_omap: framebuffer mmap failed\n"); + if (pdata->fb_mem == MAP_FAILED) + { + pdata->fb_mem = NULL; + RARCH_ERR("[video_omap]: framebuffer mmap failed\n"); - return -1; - } + return -1; + } - return 0; + return 0; } static int omapfb_backup_state(omapfb_data_t *pdata) { - void* mem; + void* mem; - assert(pdata->saved_state == NULL); + assert(pdata->saved_state == NULL); - pdata->saved_state = calloc(1, sizeof(omapfb_state_t)); - if (!pdata->saved_state) return -1; + pdata->saved_state = calloc(1, sizeof(omapfb_state_t)); + if (!pdata->saved_state) return -1; - if (ioctl(pdata->fd, OMAPFB_QUERY_PLANE, &pdata->saved_state->pi) != 0) - { - RARCH_ERR("video_omap: backup layer (plane) failed\n"); - return -1; - } + if (ioctl(pdata->fd, OMAPFB_QUERY_PLANE, &pdata->saved_state->pi) != 0) + { + RARCH_ERR("[video_omap]: backup layer (plane) failed\n"); + return -1; + } - if (ioctl(pdata->fd, OMAPFB_QUERY_MEM, &pdata->saved_state->mi) != 0) - { - RARCH_ERR("video_omap: backup layer (mem) failed\n"); - return -1; - } + if (ioctl(pdata->fd, OMAPFB_QUERY_MEM, &pdata->saved_state->mi) != 0) + { + RARCH_ERR("[video_omap]: backup layer (mem) failed\n"); + return -1; + } - if (ioctl(pdata->fd, FBIOGET_VSCREENINFO, &pdata->saved_state->si) != 0) - { - RARCH_ERR("video_omap: backup layer (screeninfo) failed\n"); - return -1; - } + if (ioctl(pdata->fd, FBIOGET_VSCREENINFO, &pdata->saved_state->si) != 0) + { + RARCH_ERR("[video_omap]: backup layer (screeninfo) failed\n"); + return -1; + } - pdata->saved_state->mem = malloc(pdata->saved_state->mi.size); - mem = mmap(NULL, pdata->saved_state->mi.size, PROT_WRITE|PROT_READ, - MAP_SHARED, pdata->fd, 0); - if (pdata->saved_state->mem == NULL || mem == MAP_FAILED) - { - RARCH_ERR("video_omap: backup layer (mem backup) failed\n"); - munmap(mem, pdata->saved_state->mi.size); - return -1; - } - memcpy(pdata->saved_state->mem, mem, pdata->saved_state->mi.size); - munmap(mem, pdata->saved_state->mi.size); + pdata->saved_state->mem = malloc(pdata->saved_state->mi.size); + mem = mmap(NULL, pdata->saved_state->mi.size, PROT_WRITE|PROT_READ, + MAP_SHARED, pdata->fd, 0); + if (pdata->saved_state->mem == NULL || mem == MAP_FAILED) + { + RARCH_ERR("[video_omap]: backup layer (mem backup) failed\n"); + munmap(mem, pdata->saved_state->mi.size); + return -1; + } + memcpy(pdata->saved_state->mem, mem, pdata->saved_state->mi.size); + munmap(mem, pdata->saved_state->mi.size); - return 0; + return 0; } static int omapfb_alloc_mem(omapfb_data_t *pdata) { - struct omapfb_plane_info pi; - struct omapfb_mem_info mi; - unsigned mem_size; - void* mem = NULL; - const struct retro_game_geometry *geom = NULL; - global_t *global = global_get_ptr(); + struct omapfb_plane_info pi; + struct omapfb_mem_info mi; + unsigned mem_size; + void* mem = NULL; + const struct retro_game_geometry *geom = NULL; + global_t *global = global_get_ptr(); - assert(pdata->current_state == NULL); + assert(pdata->current_state == NULL); - pdata->current_state = calloc(1, sizeof(omapfb_state_t)); - if (!pdata->current_state) return -1; + pdata->current_state = (omapfb_state_t*)calloc(1, sizeof(omapfb_state_t)); - if (ioctl(pdata->fd, OMAPFB_QUERY_PLANE, &pi) != 0) - { - RARCH_ERR("video_omap: alloc mem (query plane) failed\n"); - return -1; - } + if (!pdata->current_state) + goto error; - if (ioctl(pdata->fd, OMAPFB_QUERY_MEM, &mi) != 0) - { - RARCH_ERR("video_omap: alloc mem (query mem) failed\n"); - return -1; - } + if (ioctl(pdata->fd, OMAPFB_QUERY_PLANE, &pi) != 0) + { + RARCH_ERR("[video_omap]: alloc mem (query plane) failed\n"); + goto error; + } - /* disable plane when changing memory allocation */ - if (pi.enabled) - { - pi.enabled = 0; - if (ioctl(pdata->fd, OMAPFB_SETUP_PLANE, &pi) != 0) - { - RARCH_ERR("video_omap: alloc mem (disable plane) failed\n"); - return -1; - } - } + if (ioctl(pdata->fd, OMAPFB_QUERY_MEM, &mi) != 0) + { + RARCH_ERR("[video_omap]: alloc mem (query mem) failed\n"); + goto error; + } - geom = &global->system.av_info.geometry; - mem_size = geom->max_width * geom->max_height * - pdata->bpp * pdata->num_pages; + /* disable plane when changing memory allocation */ + if (pi.enabled) + { + pi.enabled = 0; + if (ioctl(pdata->fd, OMAPFB_SETUP_PLANE, &pi) != 0) + { + RARCH_ERR("[video_omap]: alloc mem (disable plane) failed\n"); + goto error; + } + } - if (mi.size < mem_size) - { - mi.size = mem_size; + geom = &global->system.av_info.geometry; + mem_size = geom->max_width * geom->max_height * + pdata->bpp * pdata->num_pages; - if (ioctl(pdata->fd, OMAPFB_SETUP_MEM, &mi) != 0) - { - RARCH_ERR("video_omap: allocation of %u bytes of VRAM failed\n", mem_size); - return -1; - } - } + if (mi.size < mem_size) + { + mi.size = mem_size; - mem = mmap(NULL, mi.size, PROT_WRITE|PROT_READ, MAP_SHARED, pdata->fd, 0); - if (mem == MAP_FAILED) - { - RARCH_ERR("video_omap: zeroing framebuffer failed\n"); - return -1; - } - memset(mem, 0, mi.size); - munmap(mem, mi.size); + if (ioctl(pdata->fd, OMAPFB_SETUP_MEM, &mi) != 0) + { + RARCH_ERR("[video_omap]: allocation of %u bytes of VRAM failed\n", mem_size); + goto error; + } + } - pdata->current_state->mi = mi; + mem = mmap(NULL, mi.size, PROT_WRITE|PROT_READ, MAP_SHARED, pdata->fd, 0); + if (mem == MAP_FAILED) + { + RARCH_ERR("[video_omap]: zeroing framebuffer failed\n"); + goto error; + } + memset(mem, 0, mi.size); + munmap(mem, mi.size); - /* Don't re-enable the plane here (setup not yet complete) */ + pdata->current_state->mi = mi; - return 0; + /* Don't re-enable the plane here (setup not yet complete) */ + + return 0; + +error: + if (pdata->current_state) + free(pdata->current_state); + return -1; } static int omapfb_setup_screeninfo(omapfb_data_t *pdata, int width, int height) { - omapfb_state_t* state = pdata->current_state; - - state->si.xres = width; - state->si.yres = height; - state->si.xres_virtual = width; - state->si.yres_virtual = height * pdata->num_pages; - - state->si.xoffset = 0; - state->si.yoffset = 0; + omapfb_state_t* state = pdata->current_state; + state->si.xres = width; + state->si.yres = height; + state->si.xres_virtual = width; + state->si.yres_virtual = height * pdata->num_pages; + state->si.xoffset = 0; + state->si.yoffset = 0; state->si.bits_per_pixel = pdata->bpp * 8; /* OMAPFB_COLOR_ARGB32 for bpp=4, OMAPFB_COLOR_RGB565 for bpp=2 */ - state->si.nonstd = 0; + state->si.nonstd = 0; if (ioctl(pdata->fd, FBIOPUT_VSCREENINFO, &state->si) != 0) { - RARCH_ERR("video_omap: setup screeninfo failed\n"); + RARCH_ERR("[video_omap]: setup screeninfo failed\n"); return -1; } - pdata->fb_framesize = width * height * pdata->bpp; + pdata->fb_framesize = width * height * pdata->bpp; return 0; } @@ -490,12 +495,11 @@ static float omapfb_scaling(omapfb_data_t *pdata, int width, int height) static int omapfb_setup_plane(omapfb_data_t *pdata, int width, int height) { - struct omapfb_plane_info pi = {0}; int x, y, w, h; + struct omapfb_plane_info pi = {0}; float scale = omapfb_scaling(pdata, width, height); - - w = (int)(scale * width); - h = (int)(scale * height); + int w = (int)(scale * width); + int h = (int)(scale * height); RARCH_LOG("omap_video: scaling %dx%d to %dx%d\n", width, height, w, h); @@ -510,20 +514,20 @@ static int omapfb_setup_plane(omapfb_data_t *pdata, int width, int height) if (ioctl(pdata->fd, OMAPFB_QUERY_PLANE, &pi) != 0) { - RARCH_ERR("video_omap: setup plane (query) failed\n"); + RARCH_ERR("[video_omap]: setup plane (query) failed\n"); return -1; } /* Disable the plane during setup to avoid garbage on screen. */ - pi.pos_x = x; - pi.pos_y = y; - pi.out_width = w; + pi.pos_x = x; + pi.pos_y = y; + pi.out_width = w; pi.out_height = h; - pi.enabled = 0; + pi.enabled = 0; if (ioctl(pdata->fd, OMAPFB_SETUP_PLANE, &pi) != 0) { - RARCH_ERR("video_omap: setup plane (param = %d %d %d %d) failed\n", x, y, w, h); + RARCH_ERR("[video_omap]: setup plane (param = %d %d %d %d) failed\n", x, y, w, h); return -1; } @@ -538,7 +542,7 @@ static int omapfb_enable_plane(omapfb_data_t *pdata) if (ioctl(pdata->fd, OMAPFB_QUERY_PLANE, &pi) != 0) { - RARCH_ERR("video_omap: enable plane (query) failed\n"); + RARCH_ERR("[video_omap]: enable plane (query) failed\n"); return -1; } @@ -546,7 +550,7 @@ static int omapfb_enable_plane(omapfb_data_t *pdata) if (ioctl(pdata->fd, OMAPFB_SETUP_PLANE, &pi) != 0) { - RARCH_ERR("video_omap: enable plane failed\n"); + RARCH_ERR("[video_omap]: enable plane failed\n"); return -1; } @@ -555,122 +559,124 @@ static int omapfb_enable_plane(omapfb_data_t *pdata) static int omapfb_init(omapfb_data_t *pdata, unsigned bpp) { - const char *fbname = get_fb_device(); - int fd = open(fbname, O_RDWR); + const char *fbname = omapfb_get_fb_device(); + int fd = open(fbname, O_RDWR); settings_t *settings = config_get_ptr(); if (fd == -1) { - RARCH_ERR("video_omap: can't open framebuffer device\n"); + RARCH_ERR("[video_omap]: can't open framebuffer device\n"); return -1; } - pdata->fbname = fbname; - pdata->fd = fd; + pdata->fbname = fbname; + pdata->fd = fd; if (omapfb_detect_screen(pdata)) { close(fd); - pdata->fbname = NULL; - pdata->fd = -1; + pdata->fbname = NULL; + pdata->fd = -1; return -1; } /* always use triple buffering to reduce chance of tearing */ - pdata->bpp = bpp; - pdata->num_pages = 3; - - pdata->sync = settings->video.vsync; + pdata->bpp = bpp; + pdata->num_pages = 3; + pdata->sync = settings->video.vsync; return 0; } void omapfb_free(omapfb_data_t *pdata) { - if (pdata->sync) - ioctl(pdata->fd, OMAPFB_WAITFORGO); + if (pdata->sync) + ioctl(pdata->fd, OMAPFB_WAITFORGO); - /* unmap the framebuffer memory */ - if (pdata->fb_mem != NULL) - { - munmap(pdata->fb_mem, pdata->current_state->mi.size); - pdata->fb_mem = NULL; - } + /* unmap the framebuffer memory */ + if (pdata->fb_mem) + { + munmap(pdata->fb_mem, pdata->current_state->mi.size); + pdata->fb_mem = NULL; + } - /* restore the framebuffer state (OMAP plane state, screen info) */ - if (pdata->saved_state != NULL) - { - void *mem; - int enabled = pdata->saved_state->pi.enabled; + /* restore the framebuffer state (OMAP plane state, screen info) */ + if (pdata->saved_state) + { + void *mem; + int enabled = pdata->saved_state->pi.enabled; - /* be sure to disable while setting up */ - pdata->saved_state->pi.enabled = 0; - ioctl(pdata->fd, OMAPFB_SETUP_PLANE, &pdata->saved_state->pi); - ioctl(pdata->fd, OMAPFB_SETUP_MEM, &pdata->saved_state->mi); - - if (enabled) - { - pdata->saved_state->pi.enabled = enabled; + /* be sure to disable while setting up */ + pdata->saved_state->pi.enabled = 0; ioctl(pdata->fd, OMAPFB_SETUP_PLANE, &pdata->saved_state->pi); - } + ioctl(pdata->fd, OMAPFB_SETUP_MEM, &pdata->saved_state->mi); - /* restore framebuffer content */ - mem = mmap(0, pdata->saved_state->mi.size, PROT_WRITE|PROT_READ, - MAP_SHARED, pdata->fd, 0); + if (enabled) + { + pdata->saved_state->pi.enabled = enabled; + ioctl(pdata->fd, OMAPFB_SETUP_PLANE, &pdata->saved_state->pi); + } - if (mem != MAP_FAILED) - { - memcpy(mem, pdata->saved_state->mem, pdata->saved_state->mi.size); - munmap(mem, pdata->saved_state->mi.size); - } + /* restore framebuffer content */ + mem = mmap(0, pdata->saved_state->mi.size, PROT_WRITE|PROT_READ, + MAP_SHARED, pdata->fd, 0); - /* restore screen info */ - ioctl(pdata->fd, FBIOPUT_VSCREENINFO, &pdata->saved_state->si); + if (mem != MAP_FAILED) + { + memcpy(mem, pdata->saved_state->mem, pdata->saved_state->mi.size); + munmap(mem, pdata->saved_state->mi.size); + } - free(pdata->saved_state->mem); - pdata->saved_state->mem = NULL; + /* restore screen info */ + ioctl(pdata->fd, FBIOPUT_VSCREENINFO, &pdata->saved_state->si); - free(pdata->saved_state); - pdata->saved_state = NULL; - } + free(pdata->saved_state->mem); + pdata->saved_state->mem = NULL; - free(pdata->current_state); - pdata->current_state = NULL; + free(pdata->saved_state); + pdata->saved_state = NULL; + } - close(pdata->fd); - pdata->fd = -1; + free(pdata->current_state); + pdata->current_state = NULL; + + close(pdata->fd); + pdata->fd = -1; } static int omapfb_set_mode(omapfb_data_t *pdata, int width, int height) { - if (pdata->sync) ioctl(pdata->fd, OMAPFB_WAITFORGO); + if (pdata->sync) + ioctl(pdata->fd, OMAPFB_WAITFORGO); - if (omapfb_setup_plane(pdata, width, height) != 0) - return -1; + if (omapfb_setup_plane(pdata, width, height) != 0) + return -1; - if (omapfb_setup_screeninfo(pdata, width, height) != 0 || - omapfb_setup_pages(pdata) != 0 || - omapfb_enable_plane(pdata) != 0) - return -1; + if (omapfb_setup_screeninfo(pdata, width, height) != 0 || + omapfb_setup_pages(pdata) != 0 || + omapfb_enable_plane(pdata) != 0) + return -1; - return 0; + return 0; } static void omapfb_prepare(omapfb_data_t *pdata) { - omapfb_page_t *page; + omapfb_page_t *page; - /* issue flip before getting free page */ - page_flip(pdata); - page = get_page(pdata); - assert(page != NULL); + /* issue flip before getting free page */ + omapfb_page_flip(pdata); - pdata->old_page = pdata->cur_page; - pdata->cur_page = page; + page = omapfb_get_page(pdata); - pdata->cur_page->used = true; + assert(page != NULL); + + pdata->old_page = pdata->cur_page; + pdata->cur_page = page; + + pdata->cur_page->used = true; } static void omapfb_blend_glyph_rgb565(omapfb_data_t *pdata, @@ -679,12 +685,9 @@ static void omapfb_blend_glyph_rgb565(omapfb_data_t *pdata, unsigned dst_x, unsigned dst_y) { unsigned x, y; - unsigned dst_pitch; - uint16_t *dst; unsigned r, g, b; - - dst_pitch = (pdata->current_state->si.xres * pdata->bpp) >> 1; - dst = (uint16_t*)pdata->cur_page->buf + dst_y * dst_pitch + dst_x; + unsigned dst_pitch = (pdata->current_state->si.xres * pdata->bpp) >> 1; + uint16_t *dst = (uint16_t*)pdata->cur_page->buf + dst_y * dst_pitch + dst_x; for (y = 0; y < g_height; ++y, src += g_pitch, dst += dst_pitch) { @@ -698,7 +701,7 @@ static void omapfb_blend_glyph_rgb565(omapfb_data_t *pdata, if (blend == 255) { - put_pixel_rgb565(&dst[x], f_rgb[0], f_rgb[1], f_rgb[2]); + omapfb_put_pixel_rgb565(&dst[x], f_rgb[0], f_rgb[1], f_rgb[2]); continue; } @@ -710,7 +713,7 @@ static void omapfb_blend_glyph_rgb565(omapfb_data_t *pdata, g = (g << 2) | (g >> 4); b = (b << 3) | (b >> 2); - put_pixel_rgb565(&dst[x], (r * (256 - blend) + f_rgb[0] * blend) >> 8, + omapfb_put_pixel_rgb565(&dst[x], (r * (256 - blend) + f_rgb[0] * blend) >> 8, (g * (256 - blend) + f_rgb[1] * blend) >> 8, (b * (256 - blend) + f_rgb[2] * blend) >> 8); } @@ -725,7 +728,7 @@ static void omapfb_blend_glyph_argb8888(omapfb_data_t *pdata, unsigned x, y; unsigned r, g, b; unsigned dst_pitch = (pdata->current_state->si.xres * pdata->bpp) >> 2; - uint32_t *dst = (uint32_t*)pdata->cur_page->buf + dst_y * dst_pitch + dst_x; + uint32_t *dst = (uint32_t*)pdata->cur_page->buf + dst_y * dst_pitch + dst_x; for (y = 0; y < g_height; ++y, src += g_pitch, dst += dst_pitch) { @@ -738,7 +741,7 @@ static void omapfb_blend_glyph_argb8888(omapfb_data_t *pdata, continue; if (blend == 255) { - put_pixel_argb8888(&dst[x], f_rgb[0], f_rgb[1], f_rgb[2]); + omapfb_put_pixel_argb8888(&dst[x], f_rgb[0], f_rgb[1], f_rgb[2]); continue; } @@ -746,7 +749,7 @@ static void omapfb_blend_glyph_argb8888(omapfb_data_t *pdata, g = (out & 0x00ff00) >> 8; b = (out & 0x0000ff) >> 0; - put_pixel_argb8888(&dst[x], (r * (256 - blend) + f_rgb[0] * blend) >> 8, + omapfb_put_pixel_argb8888(&dst[x], (r * (256 - blend) + f_rgb[0] * blend) >> 8, (g * (256 - blend) + f_rgb[1] * blend) >> 8, (b * (256 - blend) + f_rgb[2] * blend) >> 8); } @@ -756,10 +759,9 @@ static void omapfb_blend_glyph_argb8888(omapfb_data_t *pdata, static void omapfb_blit_frame(omapfb_data_t *pdata, const void *src, unsigned height, unsigned src_pitch) { - unsigned i, dst_pitch; - void *dst = pdata->cur_page->buf; - - dst_pitch = pdata->current_state->si.xres * pdata->bpp; + unsigned i; + void *dst = pdata->cur_page->buf; + unsigned dst_pitch = pdata->current_state->si.xres * pdata->bpp; for (i = 0; i < height; i++) memcpy(dst + dst_pitch * i, src + src_pitch * i, dst_pitch); @@ -818,7 +820,7 @@ static void omap_init_font(omap_video_t *vid, const char *font_path, unsigned fo if (!(font_renderer_create_default(&vid->font_driver, &vid->font, *settings->video.font_path ? settings->video.font_path : NULL, settings->video.font_size))) { - RARCH_LOG("video_omap: font init failed\n"); + RARCH_LOG("[video_omap]: font init failed\n"); return; } @@ -874,16 +876,16 @@ static void omap_render_msg(omap_video_t *vid, const char *msg) if (base_x < 0) { - src -= base_x; + src -= base_x; glyph_width += base_x; - base_x = 0; + base_x = 0; } if (base_y < 0) { - src -= base_y * (int)atlas->width; + src -= base_y * (int)atlas->width; glyph_height += base_y; - base_y = 0; + base_y = 0; } if (max_width <= 0 || max_height <= 0) @@ -915,7 +917,7 @@ static void omap_render_msg(omap_video_t *vid, const char *msg) static void *omap_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { - omap_video_t *vid = NULL; + omap_video_t *vid = NULL; settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); @@ -923,15 +925,15 @@ static void *omap_gfx_init(const video_info_t *video, * on the maximum used resolution difficult. */ if (global->filter.filter) { - RARCH_ERR("video_omap: filters are not supported\n"); + RARCH_ERR("[video_omap]: filters are not supported\n"); return NULL; } - vid = calloc(1, sizeof(omap_video_t)); + vid = (omap_video_t*)calloc(1, sizeof(omap_video_t)); if (!vid) return NULL; - vid->omap = calloc(1, sizeof(omapfb_data_t)); + vid->omap = (omapfb_data_t*)calloc(1, sizeof(omapfb_data_t)); if (!vid->omap) goto fail; @@ -946,7 +948,7 @@ static void *omap_gfx_init(const video_info_t *video, goto fail_omapfb; /* set some initial mode for the menu */ - vid->width = 320; + vid->width = 320; vid->height = 240; if (omapfb_set_mode(vid->omap, vid->width, vid->height) != 0) @@ -958,7 +960,7 @@ static void *omap_gfx_init(const video_info_t *video, omap_init_font(vid, settings->video.font_path, settings->video.font_size); vid->menu.frame = calloc(vid->width * vid->height, vid->bytes_per_pixel); - if (vid->menu.frame == NULL) + if (!vid->menu.frame) goto fail_omapfb; vid->menu.scaler.scaler_type = SCALER_TYPE_BILINEAR; @@ -972,7 +974,7 @@ fail_omapfb: free(vid->omap); fail: free(vid); - RARCH_ERR("video_omap: initialization failed\n"); + RARCH_ERR("[video_omap]: initialization failed\n"); return NULL; } @@ -987,11 +989,11 @@ static bool omap_gfx_frame(void *data, const void *frame, unsigned width, if (width > 4 && height > 4 && (width != vid->width || height != vid->height)) { - RARCH_LOG("video_omap: mode set (resolution changed by core)\n"); + RARCH_LOG("[video_omap]: mode set (resolution changed by core)\n"); if (omapfb_set_mode(vid->omap, width, height) != 0) { - RARCH_ERR("video_omap: mode set failed\n"); + RARCH_ERR("[video_omap]: mode set failed\n"); return false; } @@ -1108,7 +1110,7 @@ static void update_scaler(omap_video_t *vid, struct scaler_ctx *scaler, scaler->out_stride = vid->width * vid->bytes_per_pixel; if (!scaler_ctx_gen_filter(scaler)) - RARCH_ERR("video_omap: scaler_ctx_gen_filter failed\n"); + RARCH_ERR("[video_omap]: scaler_ctx_gen_filter failed\n"); } }