(omap_gfx) Cleanups

This commit is contained in:
twinaphex 2015-04-03 04:07:04 +02:00
parent a039a64314
commit 352bd086b0

View File

@ -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,14 +154,14 @@ 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);
}
@ -181,16 +181,16 @@ static int omapfb_detect_screen(omapfb_data_t *pdata)
if (ret != 0)
{
RARCH_ERR("video_omap: can't stat %s\n", pdata->fbname);
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)
if (!f)
{
RARCH_ERR("video_omap: can't open %s\n", buff);
RARCH_ERR("[video_omap]: can't open %s.\n", buff);
return -1;
}
@ -198,22 +198,22 @@ static int omapfb_detect_screen(omapfb_data_t *pdata)
fclose(f);
if (ret != 1)
{
RARCH_ERR("video_omap: can't parse %s\n", buff);
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));
ret = omapfb_read_sysfs(buff, manager_name, sizeof(manager_name));
if (ret < 0)
{
RARCH_ERR("video_omap: can't read manager name\n");
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));
ret = omapfb_read_sysfs(buff, buff, sizeof(buff));
if (ret < 0)
break;
@ -221,11 +221,11 @@ static int omapfb_detect_screen(omapfb_data_t *pdata)
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));
ret = omapfb_read_sysfs(buff, display_name, sizeof(display_name));
if (ret < 0)
{
RARCH_ERR("video_omap: can't read display name\n");
RARCH_ERR("[video_omap]: can't read display name.\n");
return -1;
}
@ -235,14 +235,14 @@ static int omapfb_detect_screen(omapfb_data_t *pdata)
if (ret < 0)
{
RARCH_ERR("video_omap: couldn't find manager\n");
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 = read_sysfs(buff, buff, sizeof(buff));
ret = omapfb_read_sysfs(buff, buff, sizeof(buff));
if (ret < 0)
break;
@ -256,15 +256,15 @@ static int omapfb_detect_screen(omapfb_data_t *pdata)
if (display_id < 0)
{
RARCH_ERR("video_omap: couldn't find display\n");
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 == NULL)
if (!f)
{
RARCH_ERR("video_omap: can't open %s\n", buff);
RARCH_ERR("[video_omap]: can't open %s.\n", buff);
return -1;
}
@ -272,17 +272,17 @@ static int omapfb_detect_screen(omapfb_data_t *pdata)
fclose(f);
if (ret != 2)
{
RARCH_ERR("video_omap: can't parse %s (%d)\n", buff, ret);
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);
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",
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;
@ -295,13 +295,13 @@ static int omapfb_setup_pages(omapfb_data_t *pdata)
{
int i;
if (pdata->pages == NULL)
if (!pdata->pages)
{
pdata->pages = calloc(pdata->num_pages, sizeof(omapfb_page_t));
pdata->pages = (omapfb_page_t*)calloc(pdata->num_pages, sizeof(omapfb_page_t));
if (pdata->pages == NULL)
if (!pdata->pages)
{
RARCH_ERR("video_omap: pages allocation failed\n");
RARCH_ERR("[video_omap]: pages allocation failed.\n");
return -1;
}
}
@ -318,7 +318,7 @@ static int omapfb_setup_pages(omapfb_data_t *pdata)
memset(pdata->cur_page->buf, 0, pdata->fb_framesize);
page_flip(pdata);
omapfb_page_flip(pdata);
pdata->cur_page->used = true;
return 0;
@ -334,7 +334,7 @@ static int omapfb_mmap(omapfb_data_t *pdata)
if (pdata->fb_mem == MAP_FAILED)
{
pdata->fb_mem = NULL;
RARCH_ERR("video_omap: framebuffer mmap failed\n");
RARCH_ERR("[video_omap]: framebuffer mmap failed\n");
return -1;
}
@ -353,19 +353,19 @@ static int omapfb_backup_state(omapfb_data_t *pdata)
if (ioctl(pdata->fd, OMAPFB_QUERY_PLANE, &pdata->saved_state->pi) != 0)
{
RARCH_ERR("video_omap: backup layer (plane) failed\n");
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");
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");
RARCH_ERR("[video_omap]: backup layer (screeninfo) failed\n");
return -1;
}
@ -374,7 +374,7 @@ static int omapfb_backup_state(omapfb_data_t *pdata)
MAP_SHARED, pdata->fd, 0);
if (pdata->saved_state->mem == NULL || mem == MAP_FAILED)
{
RARCH_ERR("video_omap: backup layer (mem backup) failed\n");
RARCH_ERR("[video_omap]: backup layer (mem backup) failed\n");
munmap(mem, pdata->saved_state->mi.size);
return -1;
}
@ -395,19 +395,21 @@ static int omapfb_alloc_mem(omapfb_data_t *pdata)
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 (!pdata->current_state)
goto error;
if (ioctl(pdata->fd, OMAPFB_QUERY_PLANE, &pi) != 0)
{
RARCH_ERR("video_omap: alloc mem (query plane) failed\n");
return -1;
RARCH_ERR("[video_omap]: alloc mem (query plane) failed\n");
goto error;
}
if (ioctl(pdata->fd, OMAPFB_QUERY_MEM, &mi) != 0)
{
RARCH_ERR("video_omap: alloc mem (query mem) failed\n");
return -1;
RARCH_ERR("[video_omap]: alloc mem (query mem) failed\n");
goto error;
}
/* disable plane when changing memory allocation */
@ -416,8 +418,8 @@ static int omapfb_alloc_mem(omapfb_data_t *pdata)
pi.enabled = 0;
if (ioctl(pdata->fd, OMAPFB_SETUP_PLANE, &pi) != 0)
{
RARCH_ERR("video_omap: alloc mem (disable plane) failed\n");
return -1;
RARCH_ERR("[video_omap]: alloc mem (disable plane) failed\n");
goto error;
}
}
@ -431,16 +433,16 @@ static int omapfb_alloc_mem(omapfb_data_t *pdata)
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;
RARCH_ERR("[video_omap]: allocation of %u bytes of VRAM failed\n", mem_size);
goto error;
}
}
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;
RARCH_ERR("[video_omap]: zeroing framebuffer failed\n");
goto error;
}
memset(mem, 0, mi.size);
munmap(mem, mi.size);
@ -450,6 +452,11 @@ static int omapfb_alloc_mem(omapfb_data_t *pdata)
/* 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)
@ -460,10 +467,8 @@ static int omapfb_setup_screeninfo(omapfb_data_t *pdata, int width, int height)
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 */
@ -471,7 +476,7 @@ static int omapfb_setup_screeninfo(omapfb_data_t *pdata, int width, int height)
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;
}
@ -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,7 +514,7 @@ 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;
}
@ -523,7 +527,7 @@ static int omapfb_setup_plane(omapfb_data_t *pdata, int width, int height)
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,13 +559,13 @@ 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();
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;
}
@ -581,7 +585,6 @@ static int omapfb_init(omapfb_data_t *pdata, unsigned bpp)
/* always use triple buffering to reduce chance of tearing */
pdata->bpp = bpp;
pdata->num_pages = 3;
pdata->sync = settings->video.vsync;
return 0;
@ -593,14 +596,14 @@ void omapfb_free(omapfb_data_t *pdata)
ioctl(pdata->fd, OMAPFB_WAITFORGO);
/* unmap the framebuffer memory */
if (pdata->fb_mem != NULL)
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)
if (pdata->saved_state)
{
void *mem;
int enabled = pdata->saved_state->pi.enabled;
@ -645,7 +648,8 @@ void omapfb_free(omapfb_data_t *pdata)
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;
@ -663,8 +667,10 @@ static void omapfb_prepare(omapfb_data_t *pdata)
omapfb_page_t *page;
/* issue flip before getting free page */
page_flip(pdata);
page = get_page(pdata);
omapfb_page_flip(pdata);
page = omapfb_get_page(pdata);
assert(page != NULL);
pdata->old_page = pdata->cur_page;
@ -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);
}
@ -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;
unsigned i;
void *dst = pdata->cur_page->buf;
dst_pitch = pdata->current_state->si.xres * pdata->bpp;
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;
}
@ -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;
@ -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");
}
}