2013-11-24 16:28:21 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2015-02-20 09:39:27 +00:00
|
|
|
* Copyright (C) 2013-2015 - Tobias Jakobi
|
2013-11-24 16:28:21 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <poll.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
#include <drm_fourcc.h>
|
|
|
|
#include <libdrm/exynos_drmif.h>
|
|
|
|
|
2014-08-06 17:33:00 +00:00
|
|
|
#include <exynos/exynos_fimg2d.h>
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-03-15 03:37:54 +00:00
|
|
|
#include <retro_inline.h>
|
|
|
|
|
2015-01-12 05:45:12 +00:00
|
|
|
#include "../../general.h"
|
|
|
|
#include "../../retroarch.h"
|
2015-03-15 01:47:23 +00:00
|
|
|
#include "../../runloop.h"
|
2015-01-18 22:59:57 +00:00
|
|
|
#include "../video_viewport.h"
|
2015-01-18 19:03:33 +00:00
|
|
|
#include "../video_monitor.h"
|
2015-01-12 22:35:40 +00:00
|
|
|
#include "../font_renderer_driver.h"
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2014-07-08 13:20:50 +00:00
|
|
|
/* TODO: Honor these properties: vsync, menu rotation, menu alpha, aspect ratio change */
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
/* Set to '1' to enable debug logging code. */
|
|
|
|
#define EXYNOS_GFX_DEBUG_LOG 0
|
|
|
|
|
|
|
|
/* Set to '1' to enable debug perf code. */
|
|
|
|
#define EXYNOS_GFX_DEBUG_PERF 0
|
|
|
|
|
|
|
|
extern void *memcpy_neon(void *dst, const void *src, size_t n);
|
|
|
|
|
|
|
|
/* We use two GEM buffers (main and aux) to handle 'data' from the frontend. */
|
2015-03-16 15:33:23 +00:00
|
|
|
enum exynos_buffer_type
|
|
|
|
{
|
|
|
|
EXYNOS_BUFFER_MAIN = 0,
|
|
|
|
EXYNOS_BUFFER_AUX,
|
|
|
|
EXYNOS_BUFFER_COUNT
|
2013-11-24 16:28:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* We have to handle three types of 'data' from the frontend, each abstracted by a *
|
|
|
|
* G2D image object. The image objects are then backed by some storage buffer. *
|
2014-10-08 02:56:09 +00:00
|
|
|
* (1) the core framebuffer (backed by main buffer) *
|
2014-07-08 13:20:50 +00:00
|
|
|
* (2) the menu buffer (backed by aux buffer) *
|
2013-11-24 16:28:21 +00:00
|
|
|
* (3) the font rendering buffer (backed by aux buffer) */
|
2015-03-16 15:33:23 +00:00
|
|
|
enum exynos_image_type
|
|
|
|
{
|
|
|
|
EXYNOS_IMAGE_FRAME = 0,
|
|
|
|
EXYNOS_IMAGE_FRONT,
|
|
|
|
EXYNOS_IMAGE_MENU,
|
|
|
|
EXYNOS_IMAGE_COUNT
|
2013-11-24 16:28:21 +00:00
|
|
|
};
|
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
static const struct exynos_config_default
|
|
|
|
{
|
|
|
|
unsigned width, height;
|
|
|
|
enum exynos_buffer_type buf_type;
|
|
|
|
unsigned g2d_color_mode;
|
|
|
|
unsigned bpp; /* bytes per pixel */
|
2015-03-16 15:33:23 +00:00
|
|
|
} defaults[EXYNOS_IMAGE_COUNT] = {
|
2015-04-11 06:45:55 +00:00
|
|
|
{1024, 640, EXYNOS_BUFFER_MAIN, G2D_COLOR_FMT_RGB565 | G2D_ORDER_AXRGB, 2}, /* frame */
|
|
|
|
{720, 368, EXYNOS_BUFFER_AUX, G2D_COLOR_FMT_ARGB4444 | G2D_ORDER_AXRGB, 2}, /* font */
|
|
|
|
{400, 240, EXYNOS_BUFFER_AUX, G2D_COLOR_FMT_ARGB4444 | G2D_ORDER_RGBAX, 2} /* menu */
|
2013-11-24 16:28:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct exynos_data;
|
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-03-16 15:33:23 +00:00
|
|
|
struct exynos_perf
|
|
|
|
{
|
2013-11-24 16:28:21 +00:00
|
|
|
unsigned memcpy_calls;
|
|
|
|
unsigned g2d_calls;
|
|
|
|
|
|
|
|
unsigned long long memcpy_time;
|
|
|
|
unsigned long long g2d_time;
|
|
|
|
|
|
|
|
struct timespec tspec;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2015-03-16 15:33:23 +00:00
|
|
|
struct exynos_page
|
|
|
|
{
|
2013-11-24 16:28:21 +00:00
|
|
|
struct exynos_bo *bo;
|
|
|
|
uint32_t buf_id;
|
|
|
|
|
|
|
|
struct exynos_data *base;
|
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
bool used; /* Set if page is currently used. */
|
|
|
|
bool clear; /* Set if page has to be cleared. */
|
2013-11-24 16:28:21 +00:00
|
|
|
};
|
|
|
|
|
2015-03-16 15:33:23 +00:00
|
|
|
struct exynos_fliphandler
|
|
|
|
{
|
2013-11-24 16:28:21 +00:00
|
|
|
struct pollfd fds;
|
|
|
|
drmEventContext evctx;
|
|
|
|
};
|
|
|
|
|
2015-03-16 15:33:23 +00:00
|
|
|
struct exynos_drm
|
|
|
|
{
|
2013-11-24 16:28:21 +00:00
|
|
|
drmModeRes *resources;
|
|
|
|
drmModeConnector *connector;
|
|
|
|
drmModeEncoder *encoder;
|
|
|
|
drmModeModeInfo *mode;
|
|
|
|
drmModeCrtc *orig_crtc;
|
|
|
|
|
|
|
|
uint32_t crtc_id;
|
|
|
|
uint32_t connector_id;
|
|
|
|
};
|
|
|
|
|
2015-03-16 15:33:23 +00:00
|
|
|
struct exynos_data
|
|
|
|
{
|
2013-11-24 16:28:21 +00:00
|
|
|
char drmname[32];
|
|
|
|
int fd;
|
|
|
|
struct exynos_device *device;
|
|
|
|
|
|
|
|
struct exynos_drm *drm;
|
|
|
|
struct exynos_fliphandler *fliphandler;
|
|
|
|
|
|
|
|
/* G2D is used for scaling to framebuffer dimensions. */
|
|
|
|
struct g2d_context *g2d;
|
|
|
|
struct g2d_image *dst;
|
2015-03-16 15:33:23 +00:00
|
|
|
struct g2d_image *src[EXYNOS_IMAGE_COUNT];
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-03-16 15:33:23 +00:00
|
|
|
struct exynos_bo *buf[EXYNOS_BUFFER_COUNT];
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
struct exynos_page *pages;
|
|
|
|
unsigned num_pages;
|
|
|
|
|
|
|
|
/* currently displayed page */
|
|
|
|
struct exynos_page *cur_page;
|
|
|
|
|
|
|
|
unsigned pageflip_pending;
|
|
|
|
|
|
|
|
/* framebuffer dimensions */
|
|
|
|
unsigned width, height;
|
|
|
|
|
|
|
|
/* framebuffer aspect ratio */
|
|
|
|
float aspect;
|
|
|
|
|
2014-10-08 02:56:09 +00:00
|
|
|
/* parameters for blitting core fb to screen */
|
2013-11-24 16:28:21 +00:00
|
|
|
unsigned blit_params[6];
|
|
|
|
|
|
|
|
/* bytes per pixel */
|
|
|
|
unsigned bpp;
|
|
|
|
|
|
|
|
/* framebuffer parameters */
|
|
|
|
unsigned pitch, size;
|
|
|
|
|
|
|
|
bool sync;
|
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
|
|
|
struct exynos_perf perf;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2015-03-15 03:37:54 +00:00
|
|
|
static INLINE unsigned align_common(unsigned i, unsigned j)
|
|
|
|
{
|
|
|
|
return (i + j - 1) & ~(j - 1);
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the index of a compatible DRM device. */
|
2015-04-03 01:53:01 +00:00
|
|
|
static int exynos_get_device_index(void)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
char buf[32];
|
|
|
|
int fd;
|
|
|
|
drmVersionPtr ver;
|
|
|
|
int index = 0;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
while (!found)
|
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "/dev/dri/card%d", index);
|
|
|
|
|
|
|
|
fd = open(buf, O_RDWR);
|
|
|
|
if (fd < 0) break;
|
|
|
|
|
|
|
|
ver = drmGetVersion(fd);
|
|
|
|
|
|
|
|
if (strcmp("exynos", ver->name) == 0)
|
|
|
|
found = true;
|
|
|
|
else
|
|
|
|
++index;
|
|
|
|
|
|
|
|
drmFreeVersion(ver);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return -1;
|
|
|
|
return index;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the original CRTC. */
|
2015-04-03 01:53:01 +00:00
|
|
|
static void exynos_restore_crtc(struct exynos_drm *d, int fd)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
if (!d->orig_crtc)
|
|
|
|
return;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
drmModeSetCrtc(fd, d->orig_crtc->crtc_id,
|
|
|
|
d->orig_crtc->buffer_id,
|
|
|
|
d->orig_crtc->x,
|
|
|
|
d->orig_crtc->y,
|
|
|
|
&d->connector_id, 1, &d->orig_crtc->mode);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
drmModeFreeCrtc(d->orig_crtc);
|
|
|
|
d->orig_crtc = NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
static void exynos_clean_up_drm(struct exynos_drm *d, int fd)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
if (d->encoder)
|
|
|
|
drmModeFreeEncoder(d->encoder);
|
|
|
|
if (d->connector)
|
|
|
|
drmModeFreeConnector(d->connector);
|
|
|
|
if (d->resources)
|
|
|
|
drmModeFreeResources(d->resources);
|
|
|
|
|
|
|
|
free(d);
|
|
|
|
close(fd);
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* The main pageflip handler, which the DRM executes
|
|
|
|
* when it flips to the page.
|
|
|
|
*
|
|
|
|
* Decreases the pending pageflip count and
|
|
|
|
* updates the current page.
|
|
|
|
*/
|
2015-04-03 01:53:01 +00:00
|
|
|
static void exynos_page_flip_handler(int fd, unsigned frame, unsigned sec,
|
2015-01-26 18:53:21 +00:00
|
|
|
unsigned usec, void *data)
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
struct exynos_page *page = data;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_LOG == 1)
|
2015-04-11 06:45:55 +00:00
|
|
|
RARCH_LOG("[video_exynos]: in exynos_page_flip_handler, page = %p\n", page);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
if (page->base->cur_page)
|
|
|
|
page->base->cur_page->used = false;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
page->base->pageflip_pending--;
|
|
|
|
page->base->cur_page = page;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
static void exynos_wait_flip(struct exynos_fliphandler *fh)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
const int timeout = -1;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
fh->fds.revents = 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (poll(&fh->fds, 1, timeout) < 0)
|
|
|
|
return;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (fh->fds.revents & (POLLHUP | POLLERR))
|
|
|
|
return;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (fh->fds.revents & POLLIN)
|
|
|
|
drmHandleEvent(fh->fds.fd, &fh->evctx);
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
static struct exynos_page *exynos_get_free_page(
|
|
|
|
struct exynos_page *p, unsigned cnt)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
for (i = 0; i < cnt; ++i)
|
|
|
|
{
|
|
|
|
if (!p[i].used)
|
|
|
|
return &p[i];
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Count the number of used pages. */
|
2015-04-03 01:53:01 +00:00
|
|
|
static unsigned exynos_pages_used(struct exynos_page *p, unsigned cnt)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
unsigned count = 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
for (i = 0; i < cnt; ++i)
|
|
|
|
{
|
|
|
|
if (p[i].used)
|
|
|
|
++count;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return count;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
static void exynos_clean_up_pages(struct exynos_page *p, unsigned cnt)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
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);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
exynos_bo_destroy(p[i].bo);
|
|
|
|
}
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_LOG == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
static const char *exynos_buffer_name(enum exynos_buffer_type type)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2015-03-16 15:33:23 +00:00
|
|
|
case EXYNOS_BUFFER_MAIN:
|
2015-01-26 18:53:21 +00:00
|
|
|
return "main";
|
2015-03-16 15:33:23 +00:00
|
|
|
case EXYNOS_BUFFER_AUX:
|
2015-01-26 18:53:21 +00:00
|
|
|
return "aux";
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* Create a GEM buffer with userspace mapping.
|
|
|
|
* Buffer is cleared after creation. */
|
2015-04-03 01:53:01 +00:00
|
|
|
static struct exynos_bo *exynos_create_mapped_buffer(
|
2015-01-26 18:53:21 +00:00
|
|
|
struct exynos_device *dev, unsigned size)
|
|
|
|
{
|
|
|
|
struct exynos_bo *buf;
|
|
|
|
const unsigned flags = 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
buf = exynos_bo_create(dev, size, flags);
|
2015-04-03 01:53:01 +00:00
|
|
|
if (!buf)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_ERR("[video_exynos]: failed to create temp buffer object\n");
|
2015-01-26 18:53:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
if (!exynos_bo_map(buf))
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_ERR("[video_exynos]: failed to map temp buffer object\n");
|
2015-01-26 18:53:21 +00:00
|
|
|
exynos_bo_destroy(buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
memset(buf->vaddr, 0, size);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return buf;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
static int exynos_realloc_buffer(struct exynos_data *pdata,
|
|
|
|
enum exynos_buffer_type type, unsigned size)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
struct exynos_bo *buf = pdata->buf[type];
|
|
|
|
unsigned i;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (size > buf->size)
|
|
|
|
{
|
2013-11-24 16:28:21 +00:00
|
|
|
#if (EXYNOS_GFX_DEBUG_LOG == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_LOG("[video_exynos]: reallocating %s buffer (%u -> %u bytes)\n",
|
|
|
|
exynos_buffer_name(type), buf->size, size);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
exynos_bo_destroy(buf);
|
2015-04-03 01:53:01 +00:00
|
|
|
buf = exynos_create_mapped_buffer(pdata->device, size);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
if (!buf)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_ERR("[video_exynos]: reallocation failed\n");
|
2015-01-26 18:53:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
pdata->buf[type] = buf;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* Map new GEM buffer to the G2D images backed by it. */
|
2015-03-16 15:33:23 +00:00
|
|
|
for (i = 0; i < EXYNOS_IMAGE_COUNT; ++i)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
if (defaults[i].buf_type == type)
|
|
|
|
pdata->src[i]->bo[0] = buf->handle;
|
|
|
|
}
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear a buffer associated to a G2D image by doing a (fast) solid fill. */
|
2015-04-03 01:53:01 +00:00
|
|
|
static int exynos_clear_buffer(struct g2d_context *g2d, struct g2d_image *img)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
int ret = g2d_solid_fill(g2d, img, 0, 0, img->width, img->height);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (ret == 0)
|
|
|
|
ret = g2d_exec(g2d);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (ret != 0)
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_ERR("[video_exynos]: failed to clear buffer using G2D\n");
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return ret;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Put a font glyph at a position in the buffer that is backing the G2D font image object. */
|
2015-04-03 01:53:01 +00:00
|
|
|
static void exynos_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)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
unsigned x, y;
|
2015-03-16 15:33:23 +00:00
|
|
|
const enum exynos_image_type buf_type = defaults[EXYNOS_IMAGE_FONT].buf_type;
|
|
|
|
const unsigned buf_width = pdata->src[EXYNOS_IMAGE_FONT]->width;
|
2015-01-26 18:53:21 +00:00
|
|
|
uint16_t *__restrict__ dst = (uint16_t*)pdata->buf[buf_type]->vaddr +
|
|
|
|
dst_y * buf_width + dst_x;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
static void exynos_perf_init(struct exynos_perf *p)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
p->memcpy_calls = 0;
|
|
|
|
p->g2d_calls = 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
p->memcpy_time = 0;
|
|
|
|
p->g2d_time = 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
memset(&p->tspec, 0, sizeof(struct timespec));
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
static void exynos_perf_finish(struct exynos_perf *p)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
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);
|
2015-01-26 18:53:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_LOG("[video_exynos]: debug: total memcpy time: %f seconds\n",
|
2015-01-26 18:53:21 +00:00
|
|
|
(double)p->memcpy_time / 1000000.0);
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_LOG("[video_exynos]: debug: total g2d time: %f seconds\n",
|
2015-01-26 18:53:21 +00:00
|
|
|
(double)p->g2d_time / 1000000.0);
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_LOG("[video_exynos]: debug: average time per memcpy call: %f microseconds\n",
|
2015-01-26 18:53:21 +00:00
|
|
|
(double)p->memcpy_time / (double)p->memcpy_calls);
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_LOG("[video_exynos]: debug: average time per g2d call: %f microseconds\n",
|
2015-01-26 18:53:21 +00:00
|
|
|
(double)p->g2d_time / (double)p->g2d_calls);
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
static void exynos_perf_memcpy(struct exynos_perf *p, bool start)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
if (start)
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &p->tspec);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct timespec new = { 0 };
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &new);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
static void exynos_perf_g2d(struct exynos_perf *p, bool start)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
if (start)
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &p->tspec);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct timespec new = { 0 };
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &new);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static int exynos_g2d_init(struct exynos_data *pdata)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2015-04-03 01:53:01 +00:00
|
|
|
struct g2d_image *dst = NULL;
|
|
|
|
struct g2d_context *g2d = g2d_init(pdata->fd);
|
|
|
|
if (!g2d)
|
2015-01-26 18:53:21 +00:00
|
|
|
return -1;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
dst = calloc(1, sizeof(struct g2d_image));
|
2015-04-03 01:53:01 +00:00
|
|
|
if (!dst)
|
2015-01-26 18:53:21 +00:00
|
|
|
goto fail;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
dst->buf_type = G2D_IMGBUF_GEM;
|
2015-01-26 18:53:21 +00:00
|
|
|
dst->color_mode = (pdata->bpp == 2) ? G2D_COLOR_FMT_RGB565 | G2D_ORDER_AXRGB :
|
|
|
|
G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB;
|
2015-04-03 01:53:01 +00:00
|
|
|
dst->width = pdata->width;
|
|
|
|
dst->height = pdata->height;
|
|
|
|
dst->stride = pdata->pitch;
|
|
|
|
dst->color = 0xff000000; /* Clear color for solid fill operation. */
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-03-16 15:33:23 +00:00
|
|
|
for (i = 0; i < EXYNOS_IMAGE_COUNT; ++i)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
const enum exynos_buffer_type buf_type = defaults[i].buf_type;
|
|
|
|
const unsigned buf_size = defaults[i].width * defaults[i].height * defaults[i].bpp;
|
2015-04-03 01:53:01 +00:00
|
|
|
struct g2d_image *src = (struct g2d_image*)calloc(1, sizeof(struct g2d_image));
|
|
|
|
if (!src)
|
2015-01-26 18:53:21 +00:00
|
|
|
break;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
src->width = defaults[i].width;
|
|
|
|
src->height = defaults[i].height;
|
|
|
|
src->stride = defaults[i].width * defaults[i].bpp;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
src->color_mode = defaults[i].g2d_color_mode;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* Associate GEM buffer storage with G2D image. */
|
2015-04-03 01:53:01 +00:00
|
|
|
src->buf_type = G2D_IMGBUF_GEM;
|
|
|
|
src->bo[0] = pdata->buf[buf_type]->handle;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
src->repeat_mode = G2D_REPEAT_MODE_PAD; /* Pad creates no border artifacts. */
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* 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. */
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_realloc_buffer(pdata, buf_type, buf_size);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
pdata->src[i] = src;
|
2015-01-26 18:53:21 +00:00
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-03-16 15:33:23 +00:00
|
|
|
if (i != EXYNOS_IMAGE_COUNT)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
while (i-- > 0)
|
|
|
|
{
|
|
|
|
free(pdata->src[i]);
|
|
|
|
pdata->src[i] = NULL;
|
|
|
|
}
|
|
|
|
goto fail_src;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
pdata->dst = dst;
|
|
|
|
pdata->g2d = g2d;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail_src:
|
2015-01-26 18:53:21 +00:00
|
|
|
free(dst);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail:
|
2015-01-26 18:53:21 +00:00
|
|
|
g2d_fini(g2d);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return -1;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static void exynos_g2d_free(struct exynos_data *pdata)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
free(pdata->dst);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-03-16 15:33:23 +00:00
|
|
|
for (i = 0; i < EXYNOS_IMAGE_COUNT; ++i)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
free(pdata->src[i]);
|
|
|
|
pdata->src[i] = NULL;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
g2d_fini(pdata->g2d);
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static int exynos_open(struct exynos_data *pdata)
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
char buf[32];
|
|
|
|
unsigned i;
|
|
|
|
int fd = -1;
|
|
|
|
struct exynos_drm *drm = NULL;
|
|
|
|
struct exynos_fliphandler *fliphandler = NULL;
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
int devidx = exynos_get_device_index();
|
|
|
|
|
|
|
|
if (pdata)
|
|
|
|
pdata->fd = -1;
|
|
|
|
|
|
|
|
if (devidx != -1)
|
|
|
|
snprintf(buf, sizeof(buf), "/dev/dri/card%d", devidx);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: no compatible DRM device found\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = open(buf, O_RDWR);
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: can't open DRM device\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm = (struct exynos_drm*)calloc(1, sizeof(struct exynos_drm));
|
|
|
|
|
|
|
|
if (!drm)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: failed to allocate DRM.\n");
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm->resources = drmModeGetResources(fd);
|
|
|
|
if (!drm->resources)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: failed to get DRM resources\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < drm->resources->count_connectors; ++i)
|
|
|
|
{
|
|
|
|
if (settings->video.monitor_index != 0 &&
|
|
|
|
settings->video.monitor_index - 1 != i)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
drm->connector = drmModeGetConnector(fd, drm->resources->connectors[i]);
|
|
|
|
if (!drm->connecto)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (drm->connector->connection == DRM_MODE_CONNECTED &&
|
|
|
|
drm->connector->count_modes > 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
drmModeFreeConnector(drm->connector);
|
|
|
|
drm->connector = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
drm->encoder = drmModeGetEncoder(fd, drm->resources->encoders[i]);
|
|
|
|
|
|
|
|
if (!drm->encoder)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (drm->encoder->encoder_id == drm->connector->encoder_id)
|
|
|
|
break;
|
|
|
|
|
|
|
|
drmModeFreeEncoder(drm->encoder);
|
|
|
|
drm->encoder = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fliphandler = (struct exynos_fliphandler*)calloc(1, sizeof(struct exynos_fliphandler));
|
|
|
|
|
|
|
|
if (!fliphandler)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: failed to allocate fliphandler\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the flip handler. */
|
|
|
|
fliphandler->fds.fd = fd;
|
|
|
|
fliphandler->fds.events = POLLIN;
|
|
|
|
fliphandler->evctx.version = DRM_EVENT_CONTEXT_VERSION;
|
|
|
|
fliphandler->evctx.page_flip_handler = exynos_page_flip_handler;
|
|
|
|
|
|
|
|
strncpy(pdata->drmname, buf, sizeof(buf));
|
|
|
|
pdata->fd = fd;
|
|
|
|
|
|
|
|
pdata->drm = drm;
|
|
|
|
pdata->fliphandler = fliphandler;
|
|
|
|
|
|
|
|
RARCH_LOG("[video_exynos]: using DRM device \"%s\" with connector id %u.\n",
|
|
|
|
pdata->drmname, pdata->drm->connector->connector_id);
|
|
|
|
|
|
|
|
return 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail:
|
2015-04-11 06:45:55 +00:00
|
|
|
free(fliphandler);
|
|
|
|
exynos_clean_up_drm(drm, fd);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
return -1;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Counterpart to exynos_open. */
|
2015-01-26 18:53:21 +00:00
|
|
|
static void exynos_close(struct exynos_data *pdata)
|
|
|
|
{
|
|
|
|
free(pdata->fliphandler);
|
|
|
|
pdata->fliphandler = NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
memset(pdata->drmname, 0, sizeof(char) * 32);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_clean_up_drm(pdata->drm, pdata->fd);
|
2015-01-26 18:53:21 +00:00
|
|
|
pdata->fd = -1;
|
|
|
|
pdata->drm = NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static int exynos_init(struct exynos_data *pdata, unsigned bpp)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2015-03-20 21:08:36 +00:00
|
|
|
int fd = pdata->fd;
|
2015-01-26 18:53:21 +00:00
|
|
|
struct exynos_drm *drm = pdata->drm;
|
2015-03-20 21:08:36 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-03-20 21:08:36 +00:00
|
|
|
if (settings->video.fullscreen_x != 0 &&
|
|
|
|
settings->video.fullscreen_y != 0)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < drm->connector->count_modes; i++)
|
|
|
|
{
|
2015-03-20 21:08:36 +00:00
|
|
|
if (drm->connector->modes[i].hdisplay == settings->video.fullscreen_x &&
|
|
|
|
drm->connector->modes[i].vdisplay == settings->video.fullscreen_y)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
drm->mode = &drm->connector->modes[i];
|
|
|
|
break;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
if (!drm->mode)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_ERR("[video_exynos]: requested resolution (%ux%u) not available\n",
|
2015-03-20 21:08:36 +00:00
|
|
|
settings->video.fullscreen_x, settings->video.fullscreen_y);
|
2015-01-26 18:53:21 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Select first mode, which is the native one. */
|
|
|
|
drm->mode = &drm->connector->modes[0];
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (drm->mode->hdisplay == 0 || drm->mode->vdisplay == 0)
|
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_ERR("[video_exynos]: failed to select sane resolution\n");
|
2015-01-26 18:53:21 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
drm->crtc_id = drm->encoder->crtc_id;
|
2015-02-20 09:44:54 +00:00
|
|
|
drm->connector_id = drm->connector->connector_id;
|
2015-04-03 01:53:01 +00:00
|
|
|
drm->orig_crtc = drmModeGetCrtc(fd, drm->crtc_id);
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (!drm->orig_crtc)
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_WARN("[video_exynos]: cannot find original crtc\n");
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
pdata->width = drm->mode->hdisplay;
|
|
|
|
pdata->height = drm->mode->vdisplay;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
pdata->aspect = (float)drm->mode->hdisplay / (float)drm->mode->vdisplay;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* Always use triple buffering to reduce chance of tearing. */
|
2015-04-03 01:53:01 +00:00
|
|
|
pdata->num_pages = 3;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
pdata->bpp = bpp;
|
|
|
|
pdata->pitch = bpp * pdata->width;
|
|
|
|
pdata->size = pdata->pitch * pdata->height;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_LOG("[video_exynos]: selected %ux%u resolution with %u bpp\n",
|
2015-01-26 18:53:21 +00:00
|
|
|
pdata->width, pdata->height, pdata->bpp);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail:
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_restore_crtc(drm, fd);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
drm->mode = NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return -1;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Counterpart to exynos_init. */
|
2015-01-26 18:53:21 +00:00
|
|
|
static void exynos_deinit(struct exynos_data *pdata)
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
struct exynos_drm *drm = pdata->drm;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_restore_crtc(drm, pdata->fd);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
drm = NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
pdata->width = 0;
|
|
|
|
pdata->height = 0;
|
|
|
|
pdata->num_pages = 0;
|
|
|
|
pdata->bpp = 0;
|
|
|
|
pdata->pitch = 0;
|
|
|
|
pdata->size = 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static int exynos_alloc(struct exynos_data *pdata)
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
struct exynos_bo *bo;
|
|
|
|
struct exynos_page *pages;
|
|
|
|
unsigned i;
|
|
|
|
uint32_t pixel_format;
|
|
|
|
const unsigned flags = 0;
|
|
|
|
uint32_t handles[4] = {0}, pitches[4] = {0}, offsets[4] = {0};
|
|
|
|
struct exynos_device *device = exynos_device_create(pdata->fd);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: failed to create device from fd\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
pages = (struct exynos_page*)calloc(pdata->num_pages,
|
|
|
|
sizeof(struct exynos_page));
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
if (!pages)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: failed to allocate pages\n");
|
|
|
|
goto fail_alloc;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
for (i = 0; i < EXYNOS_BUFFER_COUNT; ++i)
|
|
|
|
{
|
|
|
|
const unsigned buffer_size = defaults[i].width * defaults[i].height * defaults[i].bpp;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
bo = exynos_create_mapped_buffer(device, buffer_size);
|
|
|
|
if (!bo)
|
|
|
|
break;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
pdata->buf[i] = bo;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
if (i != EXYNOS_BUFFER_COUNT)
|
|
|
|
{
|
|
|
|
while (i-- > 0)
|
|
|
|
{
|
|
|
|
exynos_bo_destroy(pdata->buf[i]);
|
|
|
|
pdata->buf[i] = NULL;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
goto fail;
|
2015-04-11 06:45:55 +00:00
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
for (i = 0; i < pdata->num_pages; ++i)
|
|
|
|
{
|
|
|
|
bo = exynos_bo_create(device, pdata->size, flags);
|
|
|
|
if (!bo)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: failed to create buffer object\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't map the BO, since we don't access it through userspace. */
|
|
|
|
|
|
|
|
pages[i].bo = bo;
|
|
|
|
pages[i].base = pdata;
|
2015-02-20 09:54:23 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
pages[i].used = false;
|
|
|
|
pages[i].clear = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pixel_format = (pdata->bpp == 2) ? DRM_FORMAT_RGB565 : DRM_FORMAT_XRGB8888;
|
|
|
|
pitches[0] = pdata->pitch;
|
|
|
|
offsets[0] = 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
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))
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: failed to add bo %u to fb\n", i);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup CRTC: display the last allocated page. */
|
|
|
|
if (drmModeSetCrtc(pdata->fd, pdata->drm->crtc_id,
|
|
|
|
pages[pdata->num_pages - 1].buf_id,
|
|
|
|
0, 0, &pdata->drm->connector_id, 1, pdata->drm->mode))
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: initial CRTC setup failed.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata->pages = pages;
|
|
|
|
pdata->device = device;
|
|
|
|
|
|
|
|
return 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail:
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_clean_up_pages(pages, pdata->num_pages);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail_alloc:
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_device_destroy(device);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
return -1;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Counterpart to exynos_alloc. */
|
2015-01-26 18:53:21 +00:00
|
|
|
static void exynos_free(struct exynos_data *pdata)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* Disable the CRTC. */
|
2015-02-20 09:54:23 +00:00
|
|
|
if (drmModeSetCrtc(pdata->fd, pdata->drm->crtc_id, 0,
|
2015-04-11 06:45:55 +00:00
|
|
|
0, 0, NULL, 0, NULL))
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_WARN("[video_exynos]: failed to disable the CRTC.\n");
|
2014-07-10 22:39:12 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_clean_up_pages(pdata->pages, pdata->num_pages);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
free(pdata->pages);
|
|
|
|
pdata->pages = NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-03-16 15:33:23 +00:00
|
|
|
for (i = 0; i < EXYNOS_BUFFER_COUNT; ++i)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
exynos_bo_destroy(pdata->buf[i]);
|
|
|
|
pdata->buf[i] = NULL;
|
|
|
|
}
|
2015-02-20 09:41:13 +00:00
|
|
|
|
|
|
|
exynos_device_destroy(pdata->device);
|
|
|
|
pdata->device = NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_LOG == 1)
|
2015-01-26 18:53:21 +00:00
|
|
|
static void exynos_alloc_status(struct exynos_data *pdata)
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
unsigned i;
|
|
|
|
struct exynos_page *pages = pdata->pages;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
RARCH_LOG("[video_exynos]: Allocated %u pages with %u bytes each (pitch = %u bytes)\n",
|
|
|
|
pdata->num_pages, pdata->size, pdata->pitch);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
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);
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* 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. */
|
2015-01-26 18:53:21 +00:00
|
|
|
static struct exynos_page *exynos_free_page(struct exynos_data *pdata)
|
|
|
|
{
|
|
|
|
struct exynos_page *page = NULL;
|
|
|
|
struct g2d_image *dst = pdata->dst;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* Wait until a free page is available. */
|
2015-04-03 01:53:01 +00:00
|
|
|
while (!page)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
page = exynos_get_free_page(pdata->pages, pdata->num_pages);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
if (!page)
|
|
|
|
exynos_wait_flip(pdata->fliphandler);
|
2015-01-26 18:53:21 +00:00
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
dst->bo[0] = page->bo->handle;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (page->clear)
|
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
if (exynos_clear_buffer(pdata->g2d, dst) == 0)
|
2015-01-26 18:53:21 +00:00
|
|
|
page->clear = false;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
page->used = true;
|
|
|
|
return page;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
static void exynos_setup_scale(struct exynos_data *pdata,
|
|
|
|
unsigned width, unsigned height, unsigned src_bpp)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
unsigned i;
|
|
|
|
unsigned w, h;
|
|
|
|
struct g2d_image *src = pdata->src[EXYNOS_IMAGE_FRAME];
|
|
|
|
const float aspect = (float)width / (float)height;
|
|
|
|
|
|
|
|
src->width = width;
|
|
|
|
src->height = height;
|
|
|
|
src->color_mode = (src_bpp == 2) ?
|
|
|
|
G2D_COLOR_FMT_RGB565 | G2D_ORDER_AXRGB:
|
|
|
|
G2D_COLOR_FMT_XRGB8888 | G2D_ORDER_AXRGB;
|
|
|
|
|
|
|
|
if (fabsf(pdata->aspect - aspect) < 0.0001f)
|
|
|
|
{
|
2013-11-24 16:28:21 +00:00
|
|
|
w = pdata->width;
|
2015-04-11 06:45:55 +00:00
|
|
|
h = pdata->height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pdata->aspect > aspect)
|
|
|
|
{
|
|
|
|
w = (float)pdata->width * aspect / pdata->aspect;
|
|
|
|
h = pdata->height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w = pdata->width;
|
|
|
|
h = (float)pdata->height * pdata->aspect / aspect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata->blit_params[0] = (pdata->width - w) / 2;
|
|
|
|
pdata->blit_params[1] = (pdata->height - h) / 2;
|
|
|
|
pdata->blit_params[2] = w;
|
|
|
|
pdata->blit_params[3] = h;
|
|
|
|
pdata->blit_params[4] = width;
|
|
|
|
pdata->blit_params[5] = height;
|
|
|
|
|
|
|
|
for (i = 0; i < pdata->num_pages; ++i)
|
|
|
|
pdata->pages[i].clear = true;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static void exynos_set_fake_blit(struct exynos_data *pdata)
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
unsigned i;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
pdata->blit_params[0] = 0;
|
|
|
|
pdata->blit_params[1] = 0;
|
|
|
|
pdata->blit_params[2] = pdata->width;
|
|
|
|
pdata->blit_params[3] = pdata->height;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
for (i = 0; i < pdata->num_pages; ++i)
|
|
|
|
pdata->pages[i].clear = true;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int exynos_blit_frame(struct exynos_data *pdata, const void *frame,
|
2015-01-26 18:53:21 +00:00
|
|
|
unsigned src_pitch)
|
|
|
|
{
|
2015-03-16 15:33:23 +00:00
|
|
|
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];
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
if (exynos_realloc_buffer(pdata, buf_type, size) != 0)
|
2015-01-26 18:53:21 +00:00
|
|
|
return -1;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_perf_memcpy(&pdata->perf, true);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* HACK: Without IOMMU the G2D only works properly between GEM buffers. */
|
|
|
|
memcpy_neon(pdata->buf[buf_type]->vaddr, frame, size);
|
|
|
|
src->stride = src_pitch;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_perf_memcpy(&pdata->perf, false);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_perf_g2d(&pdata->perf, true);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
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))
|
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_ERR("[video_exynos]: failed to blit frame.\n");
|
2015-01-26 18:53:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_perf_g2d(&pdata->perf, false);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 13:20:50 +00:00
|
|
|
static int exynos_blend_menu(struct exynos_data *pdata,
|
2015-01-26 18:53:21 +00:00
|
|
|
unsigned rotation)
|
|
|
|
{
|
2015-03-16 15:33:23 +00:00
|
|
|
struct g2d_image *src = pdata->src[EXYNOS_IMAGE_MENU];
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_perf_g2d(&pdata->perf, true);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
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))
|
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_ERR("[video_exynos]: failed to blend menu.\n");
|
2015-01-26 18:53:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_perf_g2d(&pdata->perf, false);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static int exynos_blend_font(struct exynos_data *pdata)
|
|
|
|
{
|
2015-03-16 15:33:23 +00:00
|
|
|
struct g2d_image *src = pdata->src[EXYNOS_IMAGE_FONT];
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_perf_g2d(&pdata->perf, true);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
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))
|
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_ERR("[video_exynos]: failed to blend font\n");
|
2015-01-26 18:53:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_perf_g2d(&pdata->perf, false);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static int exynos_flip(struct exynos_data *pdata, struct exynos_page *page)
|
|
|
|
{
|
|
|
|
/* We don't queue multiple page flips. */
|
|
|
|
if (pdata->pageflip_pending > 0)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_wait_flip(pdata->fliphandler);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* 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)
|
|
|
|
{
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_ERR("[video_exynos]: failed to issue page flip\n");
|
2015-01-26 18:53:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pdata->pageflip_pending++;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* On startup no frame is displayed. We therefore wait for the initial flip to finish. */
|
2015-04-03 01:53:01 +00:00
|
|
|
if (!pdata->cur_page)
|
|
|
|
exynos_wait_flip(pdata->fliphandler);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
struct exynos_video
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
struct exynos_data *data;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
void *font;
|
|
|
|
const font_renderer_driver_t *font_driver;
|
|
|
|
uint16_t font_color; /* ARGB4444 */
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
unsigned bytes_per_pixel;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
/* current dimensions of the core fb */
|
|
|
|
unsigned width;
|
|
|
|
unsigned height;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
/* menu data */
|
|
|
|
unsigned menu_rotation;
|
|
|
|
bool menu_active;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
bool aspect_changed;
|
2013-11-24 16:28:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static int exynos_init_font(struct exynos_video *vid)
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
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;
|
2015-03-20 21:08:36 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
if (!settings->video.font_enable)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (font_renderer_create_default(&vid->font_driver, &vid->font,
|
|
|
|
*settings->video.font_path ? settings->video.font_path : NULL,
|
|
|
|
settings->video.font_size))
|
|
|
|
{
|
|
|
|
const int r = settings->video.msg_color_r * 15;
|
|
|
|
const int g = settings->video.msg_color_g * 15;
|
|
|
|
const int b = settings->video.msg_color_b * 15;
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: creating font renderer failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The font buffer color type is ARGB4444. */
|
|
|
|
if (exynos_realloc_buffer(pdata, defaults[EXYNOS_IMAGE_FONT].buf_type,
|
|
|
|
buf_width * buf_height * buf_bpp) != 0)
|
|
|
|
{
|
|
|
|
vid->font_driver->free(vid->font);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
src->width = buf_width;
|
|
|
|
src->height = buf_height;
|
|
|
|
src->stride = buf_width * buf_bpp;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_LOG == 1)
|
2015-04-11 06:45:55 +00:00
|
|
|
RARCH_LOG("[video_exynos]: using font rendering image with size %ux%u\n",
|
|
|
|
buf_width, buf_height);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
return 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int exynos_render_msg(struct exynos_video *vid,
|
2015-04-03 01:53:01 +00:00
|
|
|
const char *msg)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
const struct font_atlas *atlas;
|
|
|
|
struct exynos_data *pdata = vid->data;
|
|
|
|
struct g2d_image *dst = pdata->src[EXYNOS_IMAGE_FONT];
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
int msg_base_x = settings->video.msg_pos_x * dst->width;
|
|
|
|
int msg_base_y = (1.0f - settings->video.msg_pos_y) * dst->height;
|
|
|
|
|
|
|
|
if (!vid->font || !vid->font_driver)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (exynos_clear_buffer(pdata->g2d, dst) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
atlas = vid->font_driver->get_atlas(vid->font);
|
|
|
|
|
|
|
|
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)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
glyph_width = glyph->width;
|
|
|
|
glyph_height = glyph->height;
|
|
|
|
|
|
|
|
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_y < 0)
|
|
|
|
{
|
|
|
|
src -= base_y * (int)atlas->width;
|
|
|
|
glyph_height += base_y;
|
|
|
|
base_y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
exynos_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return exynos_blend_font(pdata);
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static void *exynos_gfx_init(const video_info_t *video,
|
|
|
|
const input_driver_t **input, void **input_data)
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
struct exynos_video *vid;
|
|
|
|
const unsigned fb_bpp = 4; /* Use XRGB8888 framebuffer. */
|
|
|
|
|
|
|
|
vid = calloc(1, sizeof(struct exynos_video));
|
|
|
|
if (!vid)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
vid->data = calloc(1, sizeof(struct exynos_data));
|
|
|
|
if (!vid->data)
|
|
|
|
goto fail_data;
|
|
|
|
|
|
|
|
vid->bytes_per_pixel = video->rgb32 ? 4 : 2;
|
|
|
|
|
|
|
|
if (exynos_open(vid->data) != 0)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: opening device failed\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exynos_init(vid->data, fb_bpp) != 0)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: initialization failed\n");
|
|
|
|
goto fail_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exynos_alloc(vid->data) != 0)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: allocation failed\n");
|
|
|
|
goto fail_alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exynos_g2d_init(vid->data) != 0)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: G2D initialization failed\n");
|
|
|
|
goto fail_g2d;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_LOG == 1)
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_alloc_status(vid->data);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_perf_init(&vid->data->perf);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
if (input && input_data)
|
|
|
|
*input = NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
if (exynos_init_font(vid) != 0)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[video_exynos]: font initialization failed\n");
|
|
|
|
goto fail_font;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
return vid;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail_font:
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_g2d_free(vid->data);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail_g2d:
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_free(vid->data);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail_alloc:
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_deinit(vid->data);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail_init:
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_close(vid->data);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail:
|
2015-04-11 06:45:55 +00:00
|
|
|
free(vid->data);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail_data:
|
2015-04-11 06:45:55 +00:00
|
|
|
free(vid);
|
|
|
|
return NULL;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
static void exynos_gfx_free(void *data)
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
struct exynos_video *vid = data;
|
|
|
|
struct exynos_data *pdata;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
if (!vid)
|
|
|
|
return;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
pdata = vid->data;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_g2d_free(pdata);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
/* Flush pages: One page remains, the one being displayed at this moment. */
|
|
|
|
while (exynos_pages_used(pdata->pages, pdata->num_pages) > 1)
|
|
|
|
exynos_wait_flip(pdata->fliphandler);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_free(pdata);
|
|
|
|
exynos_deinit(pdata);
|
|
|
|
exynos_close(pdata);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-11 06:45:55 +00:00
|
|
|
exynos_perf_finish(&pdata->perf);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
free(pdata);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
if (vid->font != NULL && vid->font_driver != NULL)
|
|
|
|
vid->font_driver->free(vid->font);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-11 06:45:55 +00:00
|
|
|
free(vid);
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool exynos_gfx_frame(void *data, const void *frame, unsigned width,
|
2015-01-26 18:53:21 +00:00
|
|
|
unsigned height, unsigned pitch, const char *msg)
|
|
|
|
{
|
|
|
|
struct exynos_video *vid = data;
|
|
|
|
struct exynos_page *page = NULL;
|
2015-04-11 06:45:55 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* Check if neither menu nor core framebuffer is to be displayed. */
|
2015-04-03 01:53:01 +00:00
|
|
|
if (!vid->menu_active && !frame)
|
2015-01-26 18:53:21 +00:00
|
|
|
return true;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (frame != NULL)
|
|
|
|
{
|
|
|
|
if (width != vid->width || height != vid->height)
|
|
|
|
{
|
|
|
|
/* Sanity check on new dimension parameters. */
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
return true;
|
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
RARCH_LOG("[video_exynos]: resolution changed by core: %ux%u -> %ux%u\n",
|
2015-01-26 18:53:21 +00:00
|
|
|
vid->width, vid->height, width, height);
|
|
|
|
exynos_setup_scale(vid->data, width, height, vid->bytes_per_pixel);
|
|
|
|
|
|
|
|
vid->width = width;
|
|
|
|
vid->height = height;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
page = exynos_free_page(vid->data);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (exynos_blit_frame(vid->data, frame, pitch) != 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-03-20 21:08:36 +00:00
|
|
|
if (settings->fps_show)
|
2015-01-26 18:53:21 +00:00
|
|
|
{
|
|
|
|
char buffer[128], buffer_fps[128];
|
|
|
|
video_monitor_get_fps(buffer, sizeof(buffer),
|
2015-03-20 21:08:36 +00:00
|
|
|
settings->fps_show ? buffer_fps : NULL, sizeof(buffer_fps));
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(buffer_fps, 1, 1, false);
|
2015-01-26 18:53:21 +00:00
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* 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);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
if (!page)
|
2015-01-26 18:53:21 +00:00
|
|
|
page = exynos_free_page(vid->data);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (vid->menu_active)
|
|
|
|
{
|
|
|
|
if (exynos_blend_menu(vid->data, vid->menu_rotation) != 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
if (exynos_render_msg(vid, msg) != 0)
|
|
|
|
goto fail;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
/* Font is blitted to the entire screen, so issue clear afterwards. */
|
|
|
|
page->clear = true;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (exynos_flip(vid->data, page) != 0)
|
|
|
|
goto fail;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return true;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
fail:
|
2015-01-26 18:53:21 +00:00
|
|
|
/* 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;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
return false;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static void exynos_gfx_set_nonblock_state(void *data, bool state)
|
|
|
|
{
|
|
|
|
struct exynos_video *vid = data;
|
|
|
|
if (vid && vid->data)
|
|
|
|
vid->data->sync = !state;
|
|
|
|
}
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static bool exynos_gfx_alive(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return true; /* always alive */
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static bool exynos_gfx_focus(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return true; /* drm device always has focus */
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 21:32:14 +00:00
|
|
|
static bool exynos_gfx_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)enable;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static bool exynos_gfx_has_windowed(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
return false;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2014-09-09 18:18:06 +00:00
|
|
|
static void exynos_gfx_set_rotation(void *data, unsigned rotation)
|
|
|
|
{
|
2015-01-26 18:53:21 +00:00
|
|
|
struct exynos_video *vid = (struct exynos_video*)data;
|
|
|
|
if (vid)
|
|
|
|
vid->menu_rotation = rotation;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2015-02-14 04:52:05 +00:00
|
|
|
static void exynos_gfx_viewport_info(void *data, struct video_viewport *vp)
|
2014-09-09 18:18:06 +00:00
|
|
|
{
|
2015-01-26 18:53:21 +00:00
|
|
|
struct exynos_video *vid = (struct exynos_video*)data;
|
2014-10-08 15:23:02 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
if (!vid)
|
|
|
|
return;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
vp->x = vp->y = 0;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-01-26 18:53:21 +00:00
|
|
|
vp->width = vp->full_width = vid->width;
|
|
|
|
vp->height = vp->full_height = vid->height;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static void exynos_set_aspect_ratio(void *data, unsigned aspect_ratio_idx)
|
|
|
|
{
|
2015-03-21 04:42:49 +00:00
|
|
|
struct exynos_video *vid = (struct exynos_video*)data;
|
|
|
|
global_t *global = global_get_ptr();
|
2014-10-08 15:23:02 +00:00
|
|
|
|
|
|
|
switch (aspect_ratio_idx)
|
|
|
|
{
|
|
|
|
case ASPECT_RATIO_SQUARE:
|
2015-01-18 22:59:57 +00:00
|
|
|
video_viewport_set_square_pixel(
|
2015-03-21 04:42:49 +00:00
|
|
|
global->system.av_info.geometry.base_width,
|
|
|
|
global->system.av_info.geometry.base_height);
|
2014-10-08 15:23:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ASPECT_RATIO_CORE:
|
2015-01-18 22:59:57 +00:00
|
|
|
video_viewport_set_core();
|
2014-10-08 15:23:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ASPECT_RATIO_CONFIG:
|
2015-01-18 22:59:57 +00:00
|
|
|
video_viewport_set_config();
|
2014-10-08 15:23:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-21 04:42:49 +00:00
|
|
|
global->system.aspect_ratio = aspectratio_lut[aspect_ratio_idx].value;
|
2014-10-08 15:23:02 +00:00
|
|
|
vid->aspect_changed = true;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static void exynos_apply_state_changes(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void exynos_set_texture_frame(void *data, const void *frame, bool rgb32,
|
2014-10-08 15:23:02 +00:00
|
|
|
unsigned width, unsigned height, float alpha)
|
|
|
|
{
|
2015-03-16 15:33:23 +00:00
|
|
|
const enum exynos_buffer_type buf_type = defaults[EXYNOS_IMAGE_MENU].buf_type;
|
2014-10-08 15:23:02 +00:00
|
|
|
struct exynos_video *vid = data;
|
|
|
|
struct exynos_data *pdata = vid->data;
|
2015-03-16 15:33:23 +00:00
|
|
|
struct g2d_image *src = pdata->src[EXYNOS_IMAGE_MENU];
|
2014-10-08 15:23:02 +00:00
|
|
|
const unsigned size = width * height * (rgb32 ? 4 : 2);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2015-04-03 01:53:01 +00:00
|
|
|
if (exynos_realloc_buffer(pdata, buf_type, size) != 0)
|
2014-10-08 15:23:02 +00:00
|
|
|
return;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
src->width = width;
|
|
|
|
src->height = height;
|
|
|
|
src->stride = width * (rgb32 ? 4 : 2);
|
|
|
|
src->color_mode = rgb32 ? G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_RGBAX :
|
|
|
|
G2D_COLOR_FMT_ARGB4444 | G2D_ORDER_RGBAX;
|
2013-11-24 16:28:21 +00:00
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
src->component_alpha = (unsigned char)(255.0f * alpha);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_perf_memcpy(&pdata->perf, true);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
memcpy_neon(pdata->buf[buf_type]->vaddr, frame, size);
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#if (EXYNOS_GFX_DEBUG_PERF == 1)
|
2015-04-03 01:53:01 +00:00
|
|
|
exynos_perf_memcpy(&pdata->perf, false);
|
2013-11-24 16:28:21 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static void exynos_set_texture_enable(void *data, bool state, bool full_screen)
|
|
|
|
{
|
2015-04-11 06:45:55 +00:00
|
|
|
struct exynos_video *vid = data;
|
|
|
|
if (vid)
|
|
|
|
vid->menu_active = state;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static void exynos_set_osd_msg(void *data, const char *msg,
|
|
|
|
const struct font_params *params)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)msg;
|
|
|
|
(void)params;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 15:23:02 +00:00
|
|
|
static void exynos_show_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)state;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const video_poke_interface_t exynos_poke_interface = {
|
2015-02-24 20:57:51 +00:00
|
|
|
NULL, /* set_video_mode */
|
2013-11-24 16:28:21 +00:00
|
|
|
NULL, /* set_filtering */
|
2015-02-24 19:06:58 +00:00
|
|
|
NULL, /* get_video_output_size */
|
2015-02-24 20:36:23 +00:00
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
2013-11-24 16:28:21 +00:00
|
|
|
NULL, /* get_current_framebuffer */
|
2015-02-08 17:39:12 +00:00
|
|
|
NULL, /* get_proc_address */
|
2013-11-24 16:28:21 +00:00
|
|
|
exynos_set_aspect_ratio,
|
|
|
|
exynos_apply_state_changes,
|
2014-07-08 13:20:50 +00:00
|
|
|
#ifdef HAVE_MENU
|
2013-11-24 16:28:21 +00:00
|
|
|
exynos_set_texture_frame,
|
|
|
|
exynos_set_texture_enable,
|
|
|
|
#endif
|
|
|
|
exynos_set_osd_msg,
|
|
|
|
exynos_show_mouse
|
|
|
|
};
|
|
|
|
|
2014-09-09 18:18:06 +00:00
|
|
|
static void exynos_gfx_get_poke_interface(void *data,
|
|
|
|
const video_poke_interface_t **iface)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
*iface = &exynos_poke_interface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool exynos_gfx_set_shader(void *data,
|
|
|
|
enum rarch_shader_type type, const char *path)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)type;
|
|
|
|
(void)path;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool exynos_gfx_read_viewport(void *data, uint8_t *buffer)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)buffer;
|
|
|
|
|
2014-09-09 20:41:04 +00:00
|
|
|
return true;
|
2013-11-24 16:28:21 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 05:06:20 +00:00
|
|
|
video_driver_t video_exynos = {
|
2013-11-24 16:28:21 +00:00
|
|
|
exynos_gfx_init,
|
|
|
|
exynos_gfx_frame,
|
|
|
|
exynos_gfx_set_nonblock_state,
|
|
|
|
exynos_gfx_alive,
|
|
|
|
exynos_gfx_focus,
|
2015-01-18 21:32:14 +00:00
|
|
|
exynos_gfx_suppress_screensaver,
|
2014-10-08 15:23:02 +00:00
|
|
|
exynos_gfx_has_windowed,
|
2014-09-09 18:18:06 +00:00
|
|
|
exynos_gfx_set_shader,
|
2013-11-24 16:28:21 +00:00
|
|
|
exynos_gfx_free,
|
|
|
|
"exynos",
|
|
|
|
exynos_gfx_set_rotation,
|
|
|
|
exynos_gfx_viewport_info,
|
2014-09-09 18:18:06 +00:00
|
|
|
exynos_gfx_read_viewport,
|
2015-03-16 08:33:16 +00:00
|
|
|
NULL, /* read_frame_raw */
|
2013-11-24 16:28:21 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
NULL, /* overlay_interface */
|
|
|
|
#endif
|
|
|
|
exynos_gfx_get_poke_interface
|
|
|
|
};
|