From 44a609b0c2965b199cee877255b29936baee9423 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 26 Jan 2015 19:53:21 +0100 Subject: [PATCH] (exynos_gfx.c) Style nits --- gfx/drivers/exynos_gfx.c | 1146 +++++++++++++++++++++----------------- 1 file changed, 640 insertions(+), 506 deletions(-) diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index c0482a2fc2..fa7644b8a4 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -168,15 +168,16 @@ static inline unsigned align_common(unsigned i, unsigned j) { } /* Find the index of a compatible DRM device. */ -static int get_device_index(void) { +static int get_device_index(void) +{ char buf[32]; - drmVersionPtr ver; - - int index = 0; int fd; + drmVersionPtr ver; + int index = 0; bool found = false; - while (!found) { + while (!found) + { snprintf(buf, sizeof(buf), "/dev/dri/card%d", index); fd = open(buf, O_RDWR); @@ -192,13 +193,17 @@ static int get_device_index(void) { drmFreeVersion(ver); close(fd); } - - return (found ? index : -1); + + if (!found) + return -1; + return index; } /* Restore the original CRTC. */ -static void restore_crtc(struct exynos_drm *d, int fd) { - if (d->orig_crtc == NULL) return; +static void restore_crtc(struct exynos_drm *d, int fd) +{ + if (d->orig_crtc == NULL) + return; drmModeSetCrtc(fd, d->orig_crtc->crtc_id, d->orig_crtc->buffer_id, @@ -210,360 +215,413 @@ static void restore_crtc(struct exynos_drm *d, int fd) { d->orig_crtc = NULL; } -static void clean_up_drm(struct exynos_drm *d, int fd) { - if (d->encoder) drmModeFreeEncoder(d->encoder); - if (d->connector) drmModeFreeConnector(d->connector); - if (d->resources) drmModeFreeResources(d->resources); +static void clean_up_drm(struct exynos_drm *d, int fd) +{ + if (d->encoder) + drmModeFreeEncoder(d->encoder); + if (d->connector) + drmModeFreeConnector(d->connector); + if (d->resources) + drmModeFreeResources(d->resources); free(d); close(fd); } -/* The main pageflip handler, which the DRM executes when it flips to the page. * - * Decreases the pending pageflip count and updates the current page. */ +/* The main pageflip handler, which the DRM executes + * when it flips to the page. + * + * Decreases the pending pageflip count and + * updates the current page. + */ static void page_flip_handler(int fd, unsigned frame, unsigned sec, - unsigned usec, void *data) { + unsigned usec, void *data) +{ struct exynos_page *page = data; #if (EXYNOS_GFX_DEBUG_LOG == 1) RARCH_LOG("video_exynos: in page_flip_handler, page = %p\n", page); #endif - if (page->base->cur_page != NULL) { + if (page->base->cur_page != NULL) page->base->cur_page->used = false; - } page->base->pageflip_pending--; page->base->cur_page = page; } -static void wait_flip(struct exynos_fliphandler *fh) { - const int timeout = -1; +static void wait_flip(struct exynos_fliphandler *fh) +{ + const int timeout = -1; - fh->fds.revents = 0; + fh->fds.revents = 0; - if (poll(&fh->fds, 1, timeout) < 0) - return; + if (poll(&fh->fds, 1, timeout) < 0) + return; - if (fh->fds.revents & (POLLHUP | POLLERR)) - return; + if (fh->fds.revents & (POLLHUP | POLLERR)) + return; - if (fh->fds.revents & POLLIN) - drmHandleEvent(fh->fds.fd, &fh->evctx); + if (fh->fds.revents & POLLIN) + drmHandleEvent(fh->fds.fd, &fh->evctx); } -static struct exynos_page *get_free_page(struct exynos_page *p, unsigned cnt) { - unsigned i; +static struct exynos_page *get_free_page(struct exynos_page *p, unsigned cnt) +{ + unsigned i; - for (i = 0; i < cnt; ++i) { - if (!p[i].used) return &p[i]; - } + for (i = 0; i < cnt; ++i) + { + if (!p[i].used) + return &p[i]; + } - return NULL; + return NULL; } /* Count the number of used pages. */ -static unsigned pages_used(struct exynos_page *p, unsigned cnt) { - unsigned i; - unsigned count = 0; +static unsigned pages_used(struct exynos_page *p, unsigned cnt) +{ + unsigned i; + unsigned count = 0; - for (i = 0; i < cnt; ++i) { - if (p[i].used) ++count; - } + for (i = 0; i < cnt; ++i) + { + if (p[i].used) + ++count; + } - return count; + return count; } -static void clean_up_pages(struct exynos_page *p, unsigned cnt) { - unsigned i; +static void clean_up_pages(struct exynos_page *p, unsigned cnt) +{ + unsigned i; - for (i = 0; i < cnt; ++i) { - if (p[i].bo != NULL) { - if (p[i].buf_id != 0) - drmModeRmFB(p[i].buf_id, p[i].bo->handle); + for (i = 0; i < cnt; ++i) + { + if (p[i].bo != NULL) + { + if (p[i].buf_id != 0) + drmModeRmFB(p[i].buf_id, p[i].bo->handle); - exynos_bo_destroy(p[i].bo); - } - } + exynos_bo_destroy(p[i].bo); + } + } } #if (EXYNOS_GFX_DEBUG_LOG == 1) -static const char *buffer_name(enum exynos_buffer_type type) { - switch (type) { - case exynos_buffer_main: - return "main"; - case exynos_buffer_aux: - return "aux"; - default: - assert(false); - return NULL; - } +static const char *buffer_name(enum exynos_buffer_type type) +{ + switch (type) + { + case exynos_buffer_main: + return "main"; + case exynos_buffer_aux: + return "aux"; + default: + assert(false); + } + + return NULL; } #endif -/* Create a GEM buffer with userspace mapping. Buffer is cleared after creation. */ -static struct exynos_bo *create_mapped_buffer(struct exynos_device *dev, unsigned size) { - struct exynos_bo *buf; - const unsigned flags = 0; +/* Create a GEM buffer with userspace mapping. + * Buffer is cleared after creation. */ +static struct exynos_bo *create_mapped_buffer( + struct exynos_device *dev, unsigned size) +{ + struct exynos_bo *buf; + const unsigned flags = 0; - buf = exynos_bo_create(dev, size, flags); - if (buf == NULL) { - RARCH_ERR("video_exynos: failed to create temp buffer object\n"); - return NULL; - } + buf = exynos_bo_create(dev, size, flags); + if (buf == NULL) + { + RARCH_ERR("video_exynos: failed to create temp buffer object\n"); + return NULL; + } - if (exynos_bo_map(buf) == NULL) { - RARCH_ERR("video_exynos: failed to map temp buffer object\n"); - exynos_bo_destroy(buf); - return NULL; - } + if (exynos_bo_map(buf) == NULL) + { + RARCH_ERR("video_exynos: failed to map temp buffer object\n"); + exynos_bo_destroy(buf); + return NULL; + } - memset(buf->vaddr, 0, size); + memset(buf->vaddr, 0, size); - return buf; + return buf; } static int realloc_buffer(struct exynos_data *pdata, - enum exynos_buffer_type type, unsigned size) { - struct exynos_bo *buf = pdata->buf[type]; - unsigned i; + enum exynos_buffer_type type, unsigned size) +{ + struct exynos_bo *buf = pdata->buf[type]; + unsigned i; - if (size > buf->size) { + if (size > buf->size) + { #if (EXYNOS_GFX_DEBUG_LOG == 1) - RARCH_LOG("video_exynos: reallocating %s buffer (%u -> %u bytes)\n", - buffer_name(type), buf->size, size); + RARCH_LOG("video_exynos: reallocating %s buffer (%u -> %u bytes)\n", + buffer_name(type), buf->size, size); #endif - exynos_bo_destroy(buf); - buf = create_mapped_buffer(pdata->device, size); + exynos_bo_destroy(buf); + buf = create_mapped_buffer(pdata->device, size); - if (buf == NULL) { - RARCH_ERR("video_exynos: reallocation failed\n"); - return -1; - } + if (buf == NULL) + { + RARCH_ERR("video_exynos: reallocation failed\n"); + return -1; + } - pdata->buf[type] = buf; + pdata->buf[type] = buf; - /* Map new GEM buffer to the G2D images backed by it. */ - for (i = 0; i < exynos_image_count; ++i) { - if (defaults[i].buf_type == type) - pdata->src[i]->bo[0] = buf->handle; - } - } + /* Map new GEM buffer to the G2D images backed by it. */ + for (i = 0; i < exynos_image_count; ++i) + { + if (defaults[i].buf_type == type) + pdata->src[i]->bo[0] = buf->handle; + } + } - return 0; + return 0; } /* Clear a buffer associated to a G2D image by doing a (fast) solid fill. */ -static int clear_buffer(struct g2d_context *g2d, struct g2d_image *img) { - int ret; +static int clear_buffer(struct g2d_context *g2d, struct g2d_image *img) +{ + int ret; - ret = g2d_solid_fill(g2d, img, 0, 0, img->width, img->height); + ret = g2d_solid_fill(g2d, img, 0, 0, img->width, img->height); - if (ret == 0) - ret = g2d_exec(g2d); + if (ret == 0) + ret = g2d_exec(g2d); - if (ret != 0) - RARCH_ERR("video_exynos: failed to clear buffer using G2D\n"); + if (ret != 0) + RARCH_ERR("video_exynos: failed to clear buffer using G2D\n"); - return ret; + return ret; } /* Put a font glyph at a position in the buffer that is backing the G2D font image object. */ static void put_glyph_rgba4444(struct exynos_data *pdata, const uint8_t *__restrict__ src, uint16_t color, unsigned g_width, unsigned g_height, - unsigned g_pitch, unsigned dst_x, unsigned dst_y) { - const enum exynos_image_type buf_type = defaults[exynos_image_font].buf_type; - const unsigned buf_width = pdata->src[exynos_image_font]->width; + unsigned g_pitch, unsigned dst_x, unsigned dst_y) +{ + const enum exynos_image_type buf_type = defaults[exynos_image_font].buf_type; + const unsigned buf_width = pdata->src[exynos_image_font]->width; - unsigned x, y; - uint16_t *__restrict__ dst = (uint16_t*)pdata->buf[buf_type]->vaddr + - dst_y * buf_width + dst_x; + unsigned x, y; + uint16_t *__restrict__ dst = (uint16_t*)pdata->buf[buf_type]->vaddr + + dst_y * buf_width + dst_x; - for (y = 0; y < g_height; ++y, src += g_pitch, dst += buf_width) { - for (x = 0; x < g_width; ++x) { - const uint16_t blend = src[x]; - - dst[x] = color | ((blend << 8) & 0xf000); - } - } + for (y = 0; y < g_height; ++y, src += g_pitch, dst += buf_width) + { + for (x = 0; x < g_width; ++x) + { + const uint16_t blend = src[x]; + dst[x] = color | ((blend << 8) & 0xf000); + } + } } #if (EXYNOS_GFX_DEBUG_PERF == 1) -void perf_init(struct exynos_perf *p) { - p->memcpy_calls = 0; - p->g2d_calls = 0; +void perf_init(struct exynos_perf *p) +{ + p->memcpy_calls = 0; + p->g2d_calls = 0; - p->memcpy_time = 0; - p->g2d_time = 0; + p->memcpy_time = 0; + p->g2d_time = 0; - memset(&p->tspec, 0, sizeof(struct timespec)); + memset(&p->tspec, 0, sizeof(struct timespec)); } -void perf_finish(struct exynos_perf *p) { - RARCH_LOG("video_exynos: debug: total memcpy calls: %u\n", p->memcpy_calls); - RARCH_LOG("video_exynos: debug: total g2d calls: %u\n", p->g2d_calls); +void perf_finish(struct exynos_perf *p) +{ + RARCH_LOG("video_exynos: debug: total memcpy calls: %u\n", p->memcpy_calls); + RARCH_LOG("video_exynos: debug: total g2d calls: %u\n", p->g2d_calls); - RARCH_LOG("video_exynos: debug: total memcpy time: %f seconds\n", - (double)p->memcpy_time / 1000000.0); - RARCH_LOG("video_exynos: debug: total g2d time: %f seconds\n", - (double)p->g2d_time / 1000000.0); + RARCH_LOG("video_exynos: debug: total memcpy time: %f seconds\n", + (double)p->memcpy_time / 1000000.0); + RARCH_LOG("video_exynos: debug: total g2d time: %f seconds\n", + (double)p->g2d_time / 1000000.0); - RARCH_LOG("video_exynos: debug: average time per memcpy call: %f microseconds\n", - (double)p->memcpy_time / (double)p->memcpy_calls); - RARCH_LOG("video_exynos: debug: average time per g2d call: %f microseconds\n", - (double)p->g2d_time / (double)p->g2d_calls); + RARCH_LOG("video_exynos: debug: average time per memcpy call: %f microseconds\n", + (double)p->memcpy_time / (double)p->memcpy_calls); + RARCH_LOG("video_exynos: debug: average time per g2d call: %f microseconds\n", + (double)p->g2d_time / (double)p->g2d_calls); } -void perf_memcpy(struct exynos_perf *p, bool start) { - if (start) { - clock_gettime(CLOCK_MONOTONIC, &p->tspec); - } else { - struct timespec new = { 0 }; - clock_gettime(CLOCK_MONOTONIC, &new); +void perf_memcpy(struct exynos_perf *p, bool start) +{ + if (start) + clock_gettime(CLOCK_MONOTONIC, &p->tspec); + else + { + struct timespec new = { 0 }; + clock_gettime(CLOCK_MONOTONIC, &new); - p->memcpy_time += (new.tv_sec - p->tspec.tv_sec) * 1000000; - p->memcpy_time += (new.tv_nsec - p->tspec.tv_nsec) / 1000; - ++p->memcpy_calls; - } + p->memcpy_time += (new.tv_sec - p->tspec.tv_sec) * 1000000; + p->memcpy_time += (new.tv_nsec - p->tspec.tv_nsec) / 1000; + ++p->memcpy_calls; + } } -void perf_g2d(struct exynos_perf *p, bool start) { - if (start) { - clock_gettime(CLOCK_MONOTONIC, &p->tspec); - } else { - struct timespec new = { 0 }; - clock_gettime(CLOCK_MONOTONIC, &new); +void perf_g2d(struct exynos_perf *p, bool start) +{ + if (start) + clock_gettime(CLOCK_MONOTONIC, &p->tspec); + else + { + struct timespec new = { 0 }; + clock_gettime(CLOCK_MONOTONIC, &new); - p->g2d_time += (new.tv_sec - p->tspec.tv_sec) * 1000000; - p->g2d_time += (new.tv_nsec - p->tspec.tv_nsec) / 1000; - ++p->g2d_calls; - } + p->g2d_time += (new.tv_sec - p->tspec.tv_sec) * 1000000; + p->g2d_time += (new.tv_nsec - p->tspec.tv_nsec) / 1000; + ++p->g2d_calls; + } } #endif -static int exynos_g2d_init(struct exynos_data *pdata) { - struct g2d_image *dst; - struct g2d_context *g2d; - unsigned i; +static int exynos_g2d_init(struct exynos_data *pdata) +{ + struct g2d_image *dst; + struct g2d_context *g2d; + unsigned i; - g2d = g2d_init(pdata->fd); - if (g2d == NULL) return -1; + g2d = g2d_init(pdata->fd); + if (g2d == NULL) + return -1; - dst = calloc(1, sizeof(struct g2d_image)); - if (dst == NULL) goto fail; + dst = calloc(1, sizeof(struct g2d_image)); + if (dst == NULL) + goto fail; - dst->buf_type = G2D_IMGBUF_GEM; - dst->color_mode = (pdata->bpp == 2) ? G2D_COLOR_FMT_RGB565 | G2D_ORDER_AXRGB : - G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB; - dst->width = pdata->width; - dst->height = pdata->height; - dst->stride = pdata->pitch; - dst->color = 0xff000000; /* Clear color for solid fill operation. */ + dst->buf_type = G2D_IMGBUF_GEM; + dst->color_mode = (pdata->bpp == 2) ? G2D_COLOR_FMT_RGB565 | G2D_ORDER_AXRGB : + G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB; + dst->width = pdata->width; + dst->height = pdata->height; + dst->stride = pdata->pitch; + dst->color = 0xff000000; /* Clear color for solid fill operation. */ - for (i = 0; i < exynos_image_count; ++i) { - const enum exynos_buffer_type buf_type = defaults[i].buf_type; - const unsigned buf_size = defaults[i].width * defaults[i].height * defaults[i].bpp; + for (i = 0; i < exynos_image_count; ++i) + { + const enum exynos_buffer_type buf_type = defaults[i].buf_type; + const unsigned buf_size = defaults[i].width * defaults[i].height * defaults[i].bpp; - struct g2d_image *src; + struct g2d_image *src; - src = calloc(1, sizeof(struct g2d_image)); - if (src == NULL) break; + src = calloc(1, sizeof(struct g2d_image)); + if (src == NULL) + break; - src->width = defaults[i].width; - src->height = defaults[i].height; - src->stride = defaults[i].width * defaults[i].bpp; + src->width = defaults[i].width; + src->height = defaults[i].height; + src->stride = defaults[i].width * defaults[i].bpp; - src->color_mode = defaults[i].g2d_color_mode; + src->color_mode = defaults[i].g2d_color_mode; - /* Associate GEM buffer storage with G2D image. */ - src->buf_type = G2D_IMGBUF_GEM; - src->bo[0] = pdata->buf[buf_type]->handle; + /* Associate GEM buffer storage with G2D image. */ + src->buf_type = G2D_IMGBUF_GEM; + src->bo[0] = pdata->buf[buf_type]->handle; - src->repeat_mode = G2D_REPEAT_MODE_PAD; /* Pad creates no border artifacts. */ + src->repeat_mode = G2D_REPEAT_MODE_PAD; /* Pad creates no border artifacts. */ - /* Make sure that the storage buffer is large enough. If the code is working * - * properly, then this is just a NOP. Still put it here as an insurance. */ - realloc_buffer(pdata, buf_type, buf_size); + /* Make sure that the storage buffer is large enough. If the code is working * + * properly, then this is just a NOP. Still put it here as an insurance. */ + realloc_buffer(pdata, buf_type, buf_size); - pdata->src[i] = src; - } + pdata->src[i] = src; + } - if (i != exynos_image_count) { - while (i-- > 0) { - free(pdata->src[i]); - pdata->src[i] = NULL; - } - goto fail_src; - } + if (i != exynos_image_count) + { + while (i-- > 0) + { + free(pdata->src[i]); + pdata->src[i] = NULL; + } + goto fail_src; + } - pdata->dst = dst; - pdata->g2d = g2d; + pdata->dst = dst; + pdata->g2d = g2d; - return 0; + return 0; fail_src: - free(dst); + free(dst); fail: - g2d_fini(g2d); + g2d_fini(g2d); - return -1; + return -1; } -static void exynos_g2d_free(struct exynos_data *pdata) { - unsigned i; +static void exynos_g2d_free(struct exynos_data *pdata) +{ + unsigned i; - free(pdata->dst); + free(pdata->dst); - for (i = 0; i < exynos_image_count; ++i) { - free(pdata->src[i]); - pdata->src[i] = NULL; - } + for (i = 0; i < exynos_image_count; ++i) + { + free(pdata->src[i]); + pdata->src[i] = NULL; + } - g2d_fini(pdata->g2d); + g2d_fini(pdata->g2d); } -static int exynos_open(struct exynos_data *pdata) { +static int exynos_open(struct exynos_data *pdata) +{ char buf[32]; int devidx; - + unsigned i; int fd = -1; struct exynos_drm *drm = NULL; struct exynos_fliphandler *fliphandler = NULL; - unsigned i; pdata->fd = -1; devidx = get_device_index(); - if (devidx != -1) { + if (devidx != -1) snprintf(buf, sizeof(buf), "/dev/dri/card%d", devidx); - } else { + else + { RARCH_ERR("video_exynos: no compatible drm device found\n"); return -1; } fd = open(buf, O_RDWR); - if (fd == -1) { + if (fd == -1) + { RARCH_ERR("video_exynos: can't open drm device\n"); return -1; } drm = calloc(1, sizeof(struct exynos_drm)); - if (drm == NULL) { + if (drm == NULL) + { RARCH_ERR("video_exynos: failed to allocate drm\n"); close(fd); return -1; } drm->resources = drmModeGetResources(fd); - if (drm->resources == NULL) { + if (drm->resources == NULL) + { RARCH_ERR("video_exynos: failed to get drm resources\n"); goto fail; } - for (i = 0; i < drm->resources->count_connectors; ++i) { + for (i = 0; i < drm->resources->count_connectors; ++i) + { if (g_settings.video.monitor_index != 0 && g_settings.video.monitor_index - 1 != i) continue; @@ -580,15 +638,18 @@ static int exynos_open(struct exynos_data *pdata) { drm->connector = NULL; } - if (i == drm->resources->count_connectors) { + if (i == drm->resources->count_connectors) + { RARCH_ERR("video_exynos: no currently active connector found\n"); goto fail; } - for (i = 0; i < drm->resources->count_encoders; i++) { + for (i = 0; i < drm->resources->count_encoders; i++) + { drm->encoder = drmModeGetEncoder(fd, drm->resources->encoders[i]); - if (drm->encoder == NULL) continue; + if (drm->encoder == NULL) + continue; if (drm->encoder->encoder_id == drm->connector->encoder_id) break; @@ -598,7 +659,9 @@ static int exynos_open(struct exynos_data *pdata) { } fliphandler = calloc(1, sizeof(struct exynos_fliphandler)); - if (fliphandler == NULL) { + + if (fliphandler == NULL) + { RARCH_ERR("video_exynos: failed to allocate fliphandler\n"); goto fail; } @@ -628,81 +691,90 @@ fail: } /* Counterpart to exynos_open. */ -static void exynos_close(struct exynos_data *pdata) { - free(pdata->fliphandler); - pdata->fliphandler = NULL; +static void exynos_close(struct exynos_data *pdata) +{ + free(pdata->fliphandler); + pdata->fliphandler = NULL; - memset(pdata->drmname, 0, sizeof(char) * 32); + memset(pdata->drmname, 0, sizeof(char) * 32); - clean_up_drm(pdata->drm, pdata->fd); - pdata->fd = -1; - pdata->drm = NULL; + clean_up_drm(pdata->drm, pdata->fd); + pdata->fd = -1; + pdata->drm = NULL; } -static int exynos_init(struct exynos_data *pdata, unsigned bpp) { - struct exynos_drm *drm = pdata->drm; - int fd = pdata->fd; +static int exynos_init(struct exynos_data *pdata, unsigned bpp) +{ + unsigned i; + struct exynos_drm *drm = pdata->drm; + int fd = pdata->fd; - unsigned i; - - if (g_settings.video.fullscreen_x != 0 && - g_settings.video.fullscreen_y != 0) { - for (i = 0; i < drm->connector->count_modes; i++) { - if (drm->connector->modes[i].hdisplay == g_settings.video.fullscreen_x && - drm->connector->modes[i].vdisplay == g_settings.video.fullscreen_y) { - drm->mode = &drm->connector->modes[i]; - break; + if (g_settings.video.fullscreen_x != 0 && + g_settings.video.fullscreen_y != 0) + { + for (i = 0; i < drm->connector->count_modes; i++) + { + if (drm->connector->modes[i].hdisplay == g_settings.video.fullscreen_x && + drm->connector->modes[i].vdisplay == g_settings.video.fullscreen_y) + { + drm->mode = &drm->connector->modes[i]; + break; + } } - } - if (drm->mode == NULL) { - RARCH_ERR("video_exynos: requested resolution (%ux%u) not available\n", - g_settings.video.fullscreen_x, g_settings.video.fullscreen_y); + if (drm->mode == NULL) + { + RARCH_ERR("video_exynos: requested resolution (%ux%u) not available\n", + g_settings.video.fullscreen_x, g_settings.video.fullscreen_y); + goto fail; + } + + } + else + { + /* Select first mode, which is the native one. */ + drm->mode = &drm->connector->modes[0]; + } + + if (drm->mode->hdisplay == 0 || drm->mode->vdisplay == 0) + { + RARCH_ERR("video_exynos: failed to select sane resolution\n"); goto fail; - } + } - } else { - /* Select first mode, which is the native one. */ - drm->mode = &drm->connector->modes[0]; - } + drm->crtc_id = drm->encoder->crtc_id; + drm->orig_crtc = drmModeGetCrtc(fd, drm->crtc_id); + if (!drm->orig_crtc) + RARCH_WARN("video_exynos: cannot find original crtc\n"); - if (drm->mode->hdisplay == 0 || drm->mode->vdisplay == 0) { - RARCH_ERR("video_exynos: failed to select sane resolution\n"); - goto fail; - } + pdata->width = drm->mode->hdisplay; + pdata->height = drm->mode->vdisplay; - drm->crtc_id = drm->encoder->crtc_id; - drm->orig_crtc = drmModeGetCrtc(fd, drm->crtc_id); - if (!drm->orig_crtc) - RARCH_WARN("video_exynos: cannot find original crtc\n"); + pdata->aspect = (float)drm->mode->hdisplay / (float)drm->mode->vdisplay; - pdata->width = drm->mode->hdisplay; - pdata->height = drm->mode->vdisplay; + /* Always use triple buffering to reduce chance of tearing. */ + pdata->num_pages = 3; - pdata->aspect = (float)drm->mode->hdisplay / (float)drm->mode->vdisplay; + pdata->bpp = bpp; + pdata->pitch = bpp * pdata->width; + pdata->size = pdata->pitch * pdata->height; - /* Always use triple buffering to reduce chance of tearing. */ - pdata->num_pages = 3; + RARCH_LOG("video_exynos: selected %ux%u resolution with %u bpp\n", + pdata->width, pdata->height, pdata->bpp); - pdata->bpp = bpp; - pdata->pitch = bpp * pdata->width; - pdata->size = pdata->pitch * pdata->height; - - RARCH_LOG("video_exynos: selected %ux%u resolution with %u bpp\n", - pdata->width, pdata->height, pdata->bpp); - - return 0; + return 0; fail: - restore_crtc(drm, fd); + restore_crtc(drm, fd); - drm->mode = NULL; + drm->mode = NULL; - return -1; + return -1; } /* Counterpart to exynos_init. */ -static void exynos_deinit(struct exynos_data *pdata) { +static void exynos_deinit(struct exynos_data *pdata) +{ struct exynos_drm *drm = pdata->drm; restore_crtc(drm, pdata->fd); @@ -719,7 +791,8 @@ static void exynos_deinit(struct exynos_data *pdata) { pdata->size = 0; } -static int exynos_alloc(struct exynos_data *pdata) { +static int exynos_alloc(struct exynos_data *pdata) +{ struct exynos_device *device; struct exynos_bo *bo; struct exynos_page *pages; @@ -730,28 +803,34 @@ static int exynos_alloc(struct exynos_data *pdata) { const unsigned flags = 0; device = exynos_device_create(pdata->fd); - if (device == NULL) { + if (device == NULL) + { RARCH_ERR("video_exynos: failed to create device from fd\n"); return -1; } pages = calloc(pdata->num_pages, sizeof(struct exynos_page)); - if (pages == NULL) { + if (pages == NULL) + { RARCH_ERR("video_exynos: failed to allocate pages\n"); goto fail_alloc; } - for (i = 0; i < exynos_buffer_count; ++i) { + for (i = 0; i < exynos_buffer_count; ++i) + { const unsigned buffer_size = defaults[i].width * defaults[i].height * defaults[i].bpp; bo = create_mapped_buffer(device, buffer_size); - if (bo == NULL) break; + if (bo == NULL) + break; pdata->buf[i] = bo; } - if (i != exynos_buffer_count) { - while (i-- > 0) { + if (i != exynos_buffer_count) + { + while (i-- > 0) + { exynos_bo_destroy(pdata->buf[i]); pdata->buf[i] = NULL; } @@ -759,9 +838,11 @@ static int exynos_alloc(struct exynos_data *pdata) { goto fail; } - for (i = 0; i < pdata->num_pages; ++i) { + for (i = 0; i < pdata->num_pages; ++i) + { bo = exynos_bo_create(device, pdata->size, flags); - if (bo == NULL) { + if (bo == NULL) + { RARCH_ERR("video_exynos: failed to create buffer object\n"); goto fail; } @@ -779,12 +860,14 @@ static int exynos_alloc(struct exynos_data *pdata) { pitches[0] = pdata->pitch; offsets[0] = 0; - for (i = 0; i < pdata->num_pages; ++i) { + for (i = 0; i < pdata->num_pages; ++i) + { handles[0] = pages[i].bo->handle; if (drmModeAddFB2(pdata->fd, pdata->width, pdata->height, pixel_format, handles, pitches, offsets, - &pages[i].buf_id, flags)) { + &pages[i].buf_id, flags)) + { RARCH_ERR("video_exynos: failed to add bo %u to fb\n", i); goto fail; } @@ -809,33 +892,37 @@ fail_alloc: } /* Counterpart to exynos_alloc. */ -static void exynos_free(struct exynos_data *pdata) { - unsigned i; +static void exynos_free(struct exynos_data *pdata) +{ + unsigned i; - /* Disable the CRTC. */ - drmModeSetCrtc(pdata->fd, pdata->drm->crtc_id, 0, - 0, 0, &pdata->drm->connector_id, 1, NULL); + /* Disable the CRTC. */ + drmModeSetCrtc(pdata->fd, pdata->drm->crtc_id, 0, + 0, 0, &pdata->drm->connector_id, 1, NULL); - clean_up_pages(pdata->pages, pdata->num_pages); + clean_up_pages(pdata->pages, pdata->num_pages); - free(pdata->pages); - pdata->pages = NULL; + free(pdata->pages); + pdata->pages = NULL; - for (i = 0; i < exynos_buffer_count; ++i) { - exynos_bo_destroy(pdata->buf[i]); - pdata->buf[i] = NULL; - } + for (i = 0; i < exynos_buffer_count; ++i) + { + exynos_bo_destroy(pdata->buf[i]); + pdata->buf[i] = NULL; + } } #if (EXYNOS_GFX_DEBUG_LOG == 1) -static void exynos_alloc_status(struct exynos_data *pdata) { +static void exynos_alloc_status(struct exynos_data *pdata) +{ unsigned i; struct exynos_page *pages = pdata->pages; RARCH_LOG("video_exynos: allocated %u pages with %u bytes each (pitch = %u bytes)\n", pdata->num_pages, pdata->size, pdata->pitch); - for (i = 0; i < pdata->num_pages; ++i) { + for (i = 0; i < pdata->num_pages; ++i) + { RARCH_LOG("video_exynos: page %u: BO at %p, buffer id = %u\n", i, pages[i].bo, pages[i].buf_id); } @@ -844,34 +931,38 @@ static void exynos_alloc_status(struct exynos_data *pdata) { /* Find a free page, clear it if necessary, and return the page. If * * no free page is available when called, wait for a page flip. */ -static struct exynos_page *exynos_free_page(struct exynos_data *pdata) { - struct exynos_page *page = NULL; - struct g2d_image *dst = pdata->dst; +static struct exynos_page *exynos_free_page(struct exynos_data *pdata) +{ + struct exynos_page *page = NULL; + struct g2d_image *dst = pdata->dst; - /* Wait until a free page is available. */ - while (page == NULL) { - page = get_free_page(pdata->pages, pdata->num_pages); + /* Wait until a free page is available. */ + while (page == NULL) + { + page = get_free_page(pdata->pages, pdata->num_pages); - if (page == NULL) wait_flip(pdata->fliphandler); - } + if (page == NULL) + wait_flip(pdata->fliphandler); + } - dst->bo[0] = page->bo->handle; + dst->bo[0] = page->bo->handle; - if (page->clear) { - if (clear_buffer(pdata->g2d, dst) == 0) - page->clear = false; - } + if (page->clear) + { + if (clear_buffer(pdata->g2d, dst) == 0) + page->clear = false; + } - page->used = true; - return page; + page->used = true; + return page; } static void exynos_setup_scale(struct exynos_data *pdata, unsigned width, - unsigned height, unsigned src_bpp) { - struct g2d_image *src = pdata->src[exynos_image_frame]; + unsigned height, unsigned src_bpp) +{ unsigned i; unsigned w, h; - + struct g2d_image *src = pdata->src[exynos_image_frame]; const float aspect = (float)width / (float)height; src->width = width; @@ -881,14 +972,20 @@ static void exynos_setup_scale(struct exynos_data *pdata, unsigned width, G2D_COLOR_FMT_RGB565 | G2D_ORDER_AXRGB: G2D_COLOR_FMT_XRGB8888 | G2D_ORDER_AXRGB; - if (fabsf(pdata->aspect - aspect) < 0.0001f) { + if (fabsf(pdata->aspect - aspect) < 0.0001f) + { w = pdata->width; h = pdata->height; - } else { - if (pdata->aspect > aspect) { + } + else + { + if (pdata->aspect > aspect) + { w = (float)pdata->width * aspect / pdata->aspect; h = pdata->height; - } else { + } + else + { w = pdata->width; h = (float)pdata->height * pdata->aspect / aspect; } @@ -905,7 +1002,8 @@ static void exynos_setup_scale(struct exynos_data *pdata, unsigned width, pdata->pages[i].clear = true; } -static void exynos_set_fake_blit(struct exynos_data *pdata) { +static void exynos_set_fake_blit(struct exynos_data *pdata) +{ unsigned i; pdata->blit_params[0] = 0; @@ -918,116 +1016,126 @@ static void exynos_set_fake_blit(struct exynos_data *pdata) { } static int exynos_blit_frame(struct exynos_data *pdata, const void *frame, - unsigned src_pitch) { - const enum exynos_buffer_type buf_type = defaults[exynos_image_frame].buf_type; - const unsigned size = src_pitch * pdata->blit_params[5]; + unsigned src_pitch) +{ + const enum exynos_buffer_type buf_type = defaults[exynos_image_frame].buf_type; + const unsigned size = src_pitch * pdata->blit_params[5]; - struct g2d_image *src = pdata->src[exynos_image_frame]; + struct g2d_image *src = pdata->src[exynos_image_frame]; - if (realloc_buffer(pdata, buf_type, size) != 0) - return -1; + if (realloc_buffer(pdata, buf_type, size) != 0) + return -1; #if (EXYNOS_GFX_DEBUG_PERF == 1) - perf_memcpy(&pdata->perf, true); + perf_memcpy(&pdata->perf, true); #endif - /* HACK: Without IOMMU the G2D only works properly between GEM buffers. */ - memcpy_neon(pdata->buf[buf_type]->vaddr, frame, size); - src->stride = src_pitch; + /* HACK: Without IOMMU the G2D only works properly between GEM buffers. */ + memcpy_neon(pdata->buf[buf_type]->vaddr, frame, size); + src->stride = src_pitch; #if (EXYNOS_GFX_DEBUG_PERF == 1) - perf_memcpy(&pdata->perf, false); + perf_memcpy(&pdata->perf, false); #endif #if (EXYNOS_GFX_DEBUG_PERF == 1) - perf_g2d(&pdata->perf, true); + perf_g2d(&pdata->perf, true); #endif - if (g2d_copy_with_scale(pdata->g2d, src, pdata->dst, 0, 0, - pdata->blit_params[4], pdata->blit_params[5], - pdata->blit_params[0], pdata->blit_params[1], - pdata->blit_params[2], pdata->blit_params[3], 0) || - g2d_exec(pdata->g2d)) { - RARCH_ERR("video_exynos: failed to blit frame\n"); - return -1; - } + if (g2d_copy_with_scale(pdata->g2d, src, pdata->dst, 0, 0, + pdata->blit_params[4], pdata->blit_params[5], + pdata->blit_params[0], pdata->blit_params[1], + pdata->blit_params[2], pdata->blit_params[3], 0) || + g2d_exec(pdata->g2d)) + { + RARCH_ERR("video_exynos: failed to blit frame\n"); + return -1; + } #if (EXYNOS_GFX_DEBUG_PERF == 1) - perf_g2d(&pdata->perf, false); + perf_g2d(&pdata->perf, false); #endif - return 0; + return 0; } static int exynos_blend_menu(struct exynos_data *pdata, - unsigned rotation) { - struct g2d_image *src = pdata->src[exynos_image_menu]; + unsigned rotation) +{ + struct g2d_image *src = pdata->src[exynos_image_menu]; #if (EXYNOS_GFX_DEBUG_PERF == 1) - perf_g2d(&pdata->perf, true); + perf_g2d(&pdata->perf, true); #endif - if (g2d_scale_and_blend(pdata->g2d, src, pdata->dst, 0, 0, - src->width, src->height, pdata->blit_params[0], - pdata->blit_params[1], pdata->blit_params[2], - pdata->blit_params[3], G2D_OP_INTERPOLATE) || - g2d_exec(pdata->g2d)) { - RARCH_ERR("video_exynos: failed to blend menu\n"); - return -1; - } + if (g2d_scale_and_blend(pdata->g2d, src, pdata->dst, 0, 0, + src->width, src->height, pdata->blit_params[0], + pdata->blit_params[1], pdata->blit_params[2], + pdata->blit_params[3], G2D_OP_INTERPOLATE) || + g2d_exec(pdata->g2d)) + { + RARCH_ERR("video_exynos: failed to blend menu\n"); + return -1; + } #if (EXYNOS_GFX_DEBUG_PERF == 1) - perf_g2d(&pdata->perf, false); + perf_g2d(&pdata->perf, false); #endif - return 0; + return 0; } -static int exynos_blend_font(struct exynos_data *pdata) { - struct g2d_image *src = pdata->src[exynos_image_font]; +static int exynos_blend_font(struct exynos_data *pdata) +{ + struct g2d_image *src = pdata->src[exynos_image_font]; #if (EXYNOS_GFX_DEBUG_PERF == 1) - perf_g2d(&pdata->perf, true); + perf_g2d(&pdata->perf, true); #endif - if (g2d_scale_and_blend(pdata->g2d, src, pdata->dst, 0, 0, src->width, - src->height, 0, 0, pdata->width, pdata->height, - G2D_OP_INTERPOLATE) || - g2d_exec(pdata->g2d)) { - RARCH_ERR("video_exynos: failed to blend font\n"); - return -1; - } + if (g2d_scale_and_blend(pdata->g2d, src, pdata->dst, 0, 0, src->width, + src->height, 0, 0, pdata->width, pdata->height, + G2D_OP_INTERPOLATE) || + g2d_exec(pdata->g2d)) + { + RARCH_ERR("video_exynos: failed to blend font\n"); + return -1; + } #if (EXYNOS_GFX_DEBUG_PERF == 1) - perf_g2d(&pdata->perf, false); + perf_g2d(&pdata->perf, false); #endif - return 0; + return 0; } -static int exynos_flip(struct exynos_data *pdata, struct exynos_page *page) { - /* We don't queue multiple page flips. */ - if (pdata->pageflip_pending > 0) { - wait_flip(pdata->fliphandler); - } +static int exynos_flip(struct exynos_data *pdata, struct exynos_page *page) +{ + /* We don't queue multiple page flips. */ + if (pdata->pageflip_pending > 0) + wait_flip(pdata->fliphandler); - /* Issue a page flip at the next vblank interval. */ - if (drmModePageFlip(pdata->fd, pdata->drm->crtc_id, page->buf_id, - DRM_MODE_PAGE_FLIP_EVENT, page) != 0) { - RARCH_ERR("video_exynos: failed to issue page flip\n"); - return -1; - } else { - pdata->pageflip_pending++; - } + /* Issue a page flip at the next vblank interval. */ + if (drmModePageFlip(pdata->fd, pdata->drm->crtc_id, page->buf_id, + DRM_MODE_PAGE_FLIP_EVENT, page) != 0) + { + RARCH_ERR("video_exynos: failed to issue page flip\n"); + return -1; + } + else + { + pdata->pageflip_pending++; + } - /* On startup no frame is displayed. We therefore wait for the initial flip to finish. */ - if (pdata->cur_page == NULL) wait_flip(pdata->fliphandler); + /* On startup no frame is displayed. We therefore wait for the initial flip to finish. */ + if (pdata->cur_page == NULL) + wait_flip(pdata->fliphandler); - return 0; + return 0; } - -struct exynos_video { +struct exynos_video +{ struct exynos_data *data; void *font; @@ -1048,19 +1156,21 @@ struct exynos_video { }; -static int exynos_init_font(struct exynos_video *vid) { +static int exynos_init_font(struct exynos_video *vid) +{ struct exynos_data *pdata = vid->data; struct g2d_image *src = pdata->src[exynos_image_font]; - const unsigned buf_height = defaults[exynos_image_font].height; const unsigned buf_width = align_common(pdata->aspect * (float)buf_height, 16); const unsigned buf_bpp = defaults[exynos_image_font].bpp; - if (!g_settings.video.font_enable) return 0; + if (!g_settings.video.font_enable) + return 0; if (font_renderer_create_default(&vid->font_driver, &vid->font, *g_settings.video.font_path ? g_settings.video.font_path : NULL, - g_settings.video.font_size)) { + g_settings.video.font_size)) + { const int r = g_settings.video.msg_color_r * 15; const int g = g_settings.video.msg_color_g * 15; const int b = g_settings.video.msg_color_b * 15; @@ -1068,7 +1178,9 @@ static int exynos_init_font(struct exynos_video *vid) { vid->font_color = ((b < 0 ? 0 : (b > 15 ? 15 : b)) << 0) | ((g < 0 ? 0 : (g > 15 ? 15 : g)) << 4) | ((r < 0 ? 0 : (r > 15 ? 15 : r)) << 8); - } else { + } + else + { RARCH_ERR("video_exynos: creating font renderer failed\n"); return -1; } @@ -1093,12 +1205,11 @@ static int exynos_init_font(struct exynos_video *vid) { } static int exynos_render_msg(struct exynos_video *vid, - const char *msg) { + const char *msg) +{ + const struct font_atlas *atlas; struct exynos_data *pdata = vid->data; struct g2d_image *dst = pdata->src[exynos_image_font]; - - const struct font_atlas *atlas; - int msg_base_x = g_settings.video.msg_pos_x * dst->width; int msg_base_y = (1.0f - g_settings.video.msg_pos_y) * dst->height; @@ -1110,80 +1221,96 @@ static int exynos_render_msg(struct exynos_video *vid, atlas = vid->font_driver->get_atlas(vid->font); - for (; *msg; ++msg) { - const struct font_glyph *glyph = vid->font_driver->get_glyph(vid->font, (uint8_t)*msg); - if (glyph == NULL) - continue; + for (; *msg; ++msg) + { + int base_x, base_y; + int glyph_width, glyph_height; + const uint8_t *src = NULL; + const struct font_glyph *glyph = vid->font_driver->get_glyph(vid->font, (uint8_t)*msg); + if (glyph == NULL) + continue; - int base_x = msg_base_x + glyph->draw_offset_x; - int base_y = msg_base_y + glyph->draw_offset_y; + base_x = msg_base_x + glyph->draw_offset_x; + base_y = msg_base_y + glyph->draw_offset_y; - const int max_width = dst->width - base_x; - const int max_height = dst->height - base_y; + const int max_width = dst->width - base_x; + const int max_height = dst->height - base_y; - int glyph_width = glyph->width; - int glyph_height = glyph->height; + glyph_width = glyph->width; + glyph_height = glyph->height; - const uint8_t *src = atlas->buffer + glyph->atlas_offset_x + glyph->atlas_offset_y * atlas->width; + src = atlas->buffer + glyph->atlas_offset_x + glyph->atlas_offset_y * atlas->width; - if (base_x < 0) { - src -= base_x; - glyph_width += base_x; - base_x = 0; - } + if (base_x < 0) + { + src -= base_x; + glyph_width += base_x; + base_x = 0; + } - if (base_y < 0) { - src -= base_y * (int)atlas->width; - glyph_height += base_y; - base_y = 0; - } + if (base_y < 0) + { + src -= base_y * (int)atlas->width; + glyph_height += base_y; + base_y = 0; + } - if (max_width <= 0 || max_height <= 0) continue; + if (max_width <= 0 || max_height <= 0) + continue; - if (glyph_width > max_width) glyph_width = max_width; - if (glyph_height > max_height) glyph_height = max_height; + if (glyph_width > max_width) + glyph_width = max_width; + if (glyph_height > max_height) + glyph_height = max_height; - put_glyph_rgba4444(pdata, src, vid->font_color, - glyph_width, glyph_height, - atlas->width, base_x, base_y); + put_glyph_rgba4444(pdata, src, vid->font_color, + glyph_width, glyph_height, + atlas->width, base_x, base_y); - msg_base_x += glyph->advance_x; - msg_base_y += glyph->advance_y; + msg_base_x += glyph->advance_x; + msg_base_y += glyph->advance_y; } return exynos_blend_font(pdata); } -static void *exynos_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { +static void *exynos_gfx_init(const video_info_t *video, + const input_driver_t **input, void **input_data) +{ struct exynos_video *vid; - const unsigned fb_bpp = 4; /* Use XRGB8888 framebuffer. */ vid = calloc(1, sizeof(struct exynos_video)); - if (!vid) return NULL; + if (!vid) + return NULL; vid->data = calloc(1, sizeof(struct exynos_data)); - if (!vid->data) goto fail_data; + if (!vid->data) + goto fail_data; vid->bytes_per_pixel = video->rgb32 ? 4 : 2; - if (exynos_open(vid->data) != 0) { + if (exynos_open(vid->data) != 0) + { RARCH_ERR("video_exynos: opening device failed\n"); goto fail; } - if (exynos_init(vid->data, fb_bpp) != 0) { + if (exynos_init(vid->data, fb_bpp) != 0) + { RARCH_ERR("video_exynos: initialization failed\n"); goto fail_init; } - if (exynos_alloc(vid->data) != 0) { + if (exynos_alloc(vid->data) != 0) + { RARCH_ERR("video_exynos: allocation failed\n"); goto fail_alloc; } - if (exynos_g2d_init(vid->data) != 0) { + if (exynos_g2d_init(vid->data) != 0) + { RARCH_ERR("video_exynos: G2D initialization failed\n"); goto fail_g2d; } @@ -1196,11 +1323,11 @@ static void *exynos_gfx_init(const video_info_t *video, const input_driver_t **i perf_init(&vid->data->perf); #endif - if (input && input_data) { + if (input && input_data) *input = NULL; - } - if (exynos_init_font(vid) != 0) { + if (exynos_init_font(vid) != 0) + { RARCH_ERR("video_exynos: font initialization failed\n"); goto fail_font; } @@ -1227,20 +1354,21 @@ fail_data: return NULL; } -static void exynos_gfx_free(void *data) { +static void exynos_gfx_free(void *data) +{ struct exynos_video *vid = data; struct exynos_data *pdata; - if (!vid) return; + if (!vid) + return; pdata = vid->data; exynos_g2d_free(pdata); /* Flush pages: One page remains, the one being displayed at this moment. */ - while (pages_used(pdata->pages, pdata->num_pages) > 1) { + while (pages_used(pdata->pages, pdata->num_pages) > 1) wait_flip(pdata->fliphandler); - } exynos_free(pdata); exynos_deinit(pdata); @@ -1259,73 +1387,81 @@ static void exynos_gfx_free(void *data) { } static bool exynos_gfx_frame(void *data, const void *frame, unsigned width, - unsigned height, unsigned pitch, const char *msg) { - struct exynos_video *vid = data; - struct exynos_page *page = NULL; + unsigned height, unsigned pitch, const char *msg) +{ + struct exynos_video *vid = data; + struct exynos_page *page = NULL; - /* Check if neither menu nor core framebuffer is to be displayed. */ - if (!vid->menu_active && frame == NULL) return true; + /* Check if neither menu nor core framebuffer is to be displayed. */ + if (!vid->menu_active && frame == NULL) + return true; - if (frame != NULL) { - if (width != vid->width || height != vid->height) { - /* Sanity check on new dimension parameters. */ - if (width == 0 || height == 0) return true; + if (frame != NULL) + { + if (width != vid->width || height != vid->height) + { + /* Sanity check on new dimension parameters. */ + if (width == 0 || height == 0) + return true; - RARCH_LOG("video_exynos: resolution changed by core: %ux%u -> %ux%u\n", - vid->width, vid->height, width, height); - exynos_setup_scale(vid->data, width, height, vid->bytes_per_pixel); + RARCH_LOG("video_exynos: resolution changed by core: %ux%u -> %ux%u\n", + vid->width, vid->height, width, height); + exynos_setup_scale(vid->data, width, height, vid->bytes_per_pixel); - vid->width = width; - vid->height = height; - } + vid->width = width; + vid->height = height; + } - page = exynos_free_page(vid->data); + page = exynos_free_page(vid->data); - if (exynos_blit_frame(vid->data, frame, pitch) != 0) + if (exynos_blit_frame(vid->data, frame, pitch) != 0) + goto fail; + } + + if (g_settings.fps_show) + { + char buffer[128], buffer_fps[128]; + video_monitor_get_fps(buffer, sizeof(buffer), + g_settings.fps_show ? buffer_fps : NULL, sizeof(buffer_fps)); + msg_queue_push(g_extern.msg_queue, buffer_fps, 1, 1); + } + + /* If at this point the dimension parameters are still zero, setup some * + * fake blit parameters so that menu and font rendering work properly. */ + if (vid->width == 0 || vid->height == 0) + exynos_set_fake_blit(vid->data); + + if (page == NULL) + page = exynos_free_page(vid->data); + + if (vid->menu_active) + { + if (exynos_blend_menu(vid->data, vid->menu_rotation) != 0) + goto fail; + } + + if (msg) + { + if (exynos_render_msg(vid, msg) != 0) + goto fail; + + /* Font is blitted to the entire screen, so issue clear afterwards. */ + page->clear = true; + } + + if (exynos_flip(vid->data, page) != 0) goto fail; - } - if (g_settings.fps_show) - { - char buffer[128], buffer_fps[128]; - video_monitor_get_fps(buffer, sizeof(buffer), - g_settings.fps_show ? buffer_fps : NULL, sizeof(buffer_fps)); - msg_queue_push(g_extern.msg_queue, buffer_fps, 1, 1); - } + g_extern.frame_count++; - if (vid->width == 0 || vid->height == 0) { - /* If at this point the dimension parameters are still zero, setup some * - * fake blit parameters so that menu and font rendering work properly. */ - exynos_set_fake_blit(vid->data); - } - - if (page == NULL) - page = exynos_free_page(vid->data); - - if (vid->menu_active) { - if (exynos_blend_menu(vid->data, vid->menu_rotation) != 0) - goto fail; - } - - if (msg) { - if (exynos_render_msg(vid, msg) != 0) goto fail; - - /* Font is blitted to the entire screen, so issue clear afterwards. */ - page->clear = true; - } - - if (exynos_flip(vid->data, page) != 0) goto fail; - - g_extern.frame_count++; - - return true; + return true; fail: - /* Since we didn't manage to issue a pageflip to this page, set * - * it to 'unused' again, and hope that it works next time. */ - page->used = false; + /* Since we didn't manage to issue a pageflip to this page, set * + * it to 'unused' again, and hope that it works next time. */ + page->used = false; - return false; + return false; } static void exynos_gfx_set_nonblock_state(void *data, bool state) @@ -1364,22 +1500,22 @@ static bool exynos_gfx_has_windowed(void *data) static void exynos_gfx_set_rotation(void *data, unsigned rotation) { - struct exynos_video *vid = (struct exynos_video*)data; - if (vid) - vid->menu_rotation = rotation; + struct exynos_video *vid = (struct exynos_video*)data; + if (vid) + vid->menu_rotation = rotation; } static void exynos_gfx_viewport_info(void *data, struct rarch_viewport *vp) { - struct exynos_video *vid = (struct exynos_video*)data; + struct exynos_video *vid = (struct exynos_video*)data; - if (!vid) - return; + if (!vid) + return; - vp->x = vp->y = 0; + vp->x = vp->y = 0; - vp->width = vp->full_width = vid->width; - vp->height = vp->full_height = vid->height; + vp->width = vp->full_width = vid->width; + vp->height = vp->full_height = vid->height; } static void exynos_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) @@ -1419,11 +1555,9 @@ static void exynos_set_texture_frame(void *data, const void *frame, bool rgb32, unsigned width, unsigned height, float alpha) { const enum exynos_buffer_type buf_type = defaults[exynos_image_menu].buf_type; - struct exynos_video *vid = data; struct exynos_data *pdata = vid->data; struct g2d_image *src = pdata->src[exynos_image_menu]; - const unsigned size = width * height * (rgb32 ? 4 : 2); if (realloc_buffer(pdata, buf_type, size) != 0)