Merge pull request #11350 from valadaa48/oga_gfx_nits

oga_gfx: strlcpy + style nits
This commit is contained in:
Autechre 2020-09-19 18:09:33 +02:00 committed by GitHub
commit 6cd88283ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,15 +61,15 @@ typedef struct oga_rect
typedef struct oga_surface
{
uint8_t* map;
int width;
int height;
int pitch;
int prime_fd;
int rk_format;
uint8_t* map;
int width;
int height;
int pitch;
int prime_fd;
int rk_format;
int display_fd;
uint32_t handle;
int display_fd;
uint32_t handle;
} oga_surface_t;
typedef struct oga_framebuf
@ -80,199 +80,199 @@ typedef struct oga_framebuf
typedef struct oga_video
{
int fd;
uint32_t connector_id;
drmModeModeInfo mode;
int fd;
uint32_t connector_id;
drmModeModeInfo mode;
#if 0
uint32_t width;
uint32_t height;
uint32_t width;
uint32_t height;
#endif
uint32_t crtc_id;
uint32_t crtc_id;
oga_surface_t* frame_surface;
oga_surface_t* menu_surface;
oga_surface_t* frame_surface;
oga_surface_t* menu_surface;
oga_framebuf_t* pages[NUM_PAGES];
int cur_page;
int scale_mode;
int rotation;
bool threaded;
oga_framebuf_t* pages[NUM_PAGES];
int cur_page;
int scale_mode;
int rotation;
bool threaded;
oga_surface_t* msg_surface;
const font_renderer_driver_t *font_driver;
void *font;
int msg_width;
int msg_height;
char last_msg[1024];
oga_surface_t* msg_surface;
const font_renderer_driver_t *font_driver;
void *font;
int msg_width;
int msg_height;
char last_msg[128];
int bpp;
int bpp;
} oga_video_t;
bool oga_create_display(oga_video_t* vid)
{
int i, ret;
drmModeConnector *connector;
drmModeModeInfo *mode;
drmModeEncoder *encoder;
drmModeRes *resources;
int i, ret;
drmModeConnector *connector;
drmModeModeInfo *mode;
drmModeEncoder *encoder;
drmModeRes *resources;
vid->fd = open("/dev/dri/card0", O_RDWR);
if (vid->fd < 0)
{
RARCH_ERR("open /dev/dri/card0 failed.\n");
return false;
}
vid->fd = open("/dev/dri/card0", O_RDWR);
if (vid->fd < 0)
{
RARCH_ERR("open /dev/dri/card0 failed.\n");
return false;
}
resources = drmModeGetResources(vid->fd);
if (!resources)
{
RARCH_ERR("drmModeGetResources failed: %s\n", strerror(errno));
goto err_01;
}
resources = drmModeGetResources(vid->fd);
if (!resources)
{
RARCH_ERR("drmModeGetResources failed: %s\n", strerror(errno));
goto err_01;
}
for (i = 0; i < resources->count_connectors; i++)
{
connector = drmModeGetConnector(vid->fd, resources->connectors[i]);
if (connector->connection == DRM_MODE_CONNECTED)
break;
for (i = 0; i < resources->count_connectors; i++)
{
connector = drmModeGetConnector(vid->fd, resources->connectors[i]);
if (connector->connection == DRM_MODE_CONNECTED)
break;
drmModeFreeConnector(connector);
connector = NULL;
}
drmModeFreeConnector(connector);
connector = NULL;
}
if (!connector)
{
RARCH_ERR("DRM_MODE_CONNECTED not found.\n");
goto err_02;
}
if (!connector)
{
RARCH_ERR("DRM_MODE_CONNECTED not found.\n");
goto err_02;
}
vid->connector_id = connector->connector_id;
vid->connector_id = connector->connector_id;
/* Find prefered mode */
for (i = 0; i < connector->count_modes; i++)
{
drmModeModeInfo *current_mode = &connector->modes[i];
if (current_mode->type & DRM_MODE_TYPE_PREFERRED)
{
mode = current_mode;
break;
}
/* Find prefered mode */
for (i = 0; i < connector->count_modes; i++)
{
drmModeModeInfo *current_mode = &connector->modes[i];
if (current_mode->type & DRM_MODE_TYPE_PREFERRED)
{
mode = current_mode;
break;
}
mode = NULL;
}
mode = NULL;
}
if (!mode)
{
RARCH_ERR("DRM_MODE_TYPE_PREFERRED not found.\n");
goto err_03;
}
if (!mode)
{
RARCH_ERR("DRM_MODE_TYPE_PREFERRED not found.\n");
goto err_03;
}
vid->mode = *mode;
vid->mode = *mode;
#if 0
vid->width = mode->hdisplay;
vid->height = mode->vdisplay;
vid->width = mode->hdisplay;
vid->height = mode->vdisplay;
#endif
/* Find encoder */
for (i = 0; i < resources->count_encoders; i++)
{
encoder = drmModeGetEncoder(vid->fd, resources->encoders[i]);
if (encoder->encoder_id == connector->encoder_id)
break;
/* Find encoder */
for (i = 0; i < resources->count_encoders; i++)
{
encoder = drmModeGetEncoder(vid->fd, resources->encoders[i]);
if (encoder->encoder_id == connector->encoder_id)
break;
drmModeFreeEncoder(encoder);
encoder = NULL;
}
drmModeFreeEncoder(encoder);
encoder = NULL;
}
if (!encoder)
{
RARCH_ERR("could not find encoder!\n");
goto err_03;
}
if (!encoder)
{
RARCH_ERR("could not find encoder!\n");
goto err_03;
}
vid->crtc_id = encoder->crtc_id;
vid->crtc_id = encoder->crtc_id;
drmModeFreeEncoder(encoder);
drmModeFreeConnector(connector);
drmModeFreeResources(resources);
drmModeFreeEncoder(encoder);
drmModeFreeConnector(connector);
drmModeFreeResources(resources);
return true;
return true;
err_03:
drmModeFreeConnector(connector);
drmModeFreeConnector(connector);
err_02:
drmModeFreeResources(resources);
drmModeFreeResources(resources);
err_01:
close(vid->fd);
close(vid->fd);
return false;
return false;
}
oga_surface_t* oga_create_surface(int display_fd,
int width, int height, int rk_format)
{
struct drm_mode_create_dumb args = {0};
oga_surface_t* surface = (oga_surface_t*)
calloc(1, sizeof(oga_surface_t));
if (!surface)
{
RARCH_ERR("Error allocating surface\n");
return NULL;
}
struct drm_mode_create_dumb args = {0};
oga_surface_t* surface = (oga_surface_t*)
calloc(1, sizeof(oga_surface_t));
if (!surface)
{
RARCH_ERR("Error allocating surface\n");
return NULL;
}
args.width = width;
args.height = height;
args.bpp = rk_format == RK_FORMAT_BGRA_8888 ? 32 : 16;
args.flags = 0;
args.width = width;
args.height = height;
args.bpp = rk_format == RK_FORMAT_BGRA_8888 ? 32 : 16;
args.flags = 0;
if (drmIoctl(display_fd, DRM_IOCTL_MODE_CREATE_DUMB, &args) < 0)
{
RARCH_ERR("DRM_IOCTL_MODE_CREATE_DUMB failed.\n");
goto out;
}
if (drmIoctl(display_fd, DRM_IOCTL_MODE_CREATE_DUMB, &args) < 0)
{
RARCH_ERR("DRM_IOCTL_MODE_CREATE_DUMB failed.\n");
goto out;
}
surface->display_fd = display_fd;
surface->handle = args.handle;
surface->width = width;
surface->height = height;
surface->pitch = args.pitch;
surface->rk_format = rk_format;
surface->display_fd = display_fd;
surface->handle = args.handle;
surface->width = width;
surface->height = height;
surface->pitch = args.pitch;
surface->rk_format = rk_format;
if (drmPrimeHandleToFD(display_fd, surface->handle, DRM_RDWR | DRM_CLOEXEC, &surface->prime_fd) < 0)
{
RARCH_ERR("drmPrimeHandleToFD failed.\n");
goto out;
}
if (drmPrimeHandleToFD(display_fd, surface->handle, DRM_RDWR | DRM_CLOEXEC, &surface->prime_fd) < 0)
{
RARCH_ERR("drmPrimeHandleToFD failed.\n");
goto out;
}
surface->map = mmap(NULL, args.size, PROT_READ | PROT_WRITE, MAP_SHARED, surface->prime_fd, 0);
if (surface->map == MAP_FAILED)
{
RARCH_LOG("mmap failed.\n");
return NULL;
}
surface->map = mmap(NULL, args.size, PROT_READ | PROT_WRITE, MAP_SHARED, surface->prime_fd, 0);
if (surface->map == MAP_FAILED)
{
RARCH_LOG("mmap failed.\n");
return NULL;
}
return surface;
return surface;
out:
free(surface);
return NULL;
free(surface);
return NULL;
}
void oga_destroy_surface(oga_surface_t* surface)
{
int io;
struct drm_mode_destroy_dumb args = { 0 };
int io;
struct drm_mode_destroy_dumb args = { 0 };
args.handle = surface->handle;
args.handle = surface->handle;
io = drmIoctl(surface->display_fd,
DRM_IOCTL_MODE_DESTROY_DUMB, &args);
if (io < 0)
RARCH_ERR("DRM_IOCTL_MODE_DESTROY_DUMB failed.\n");
io = drmIoctl(surface->display_fd,
DRM_IOCTL_MODE_DESTROY_DUMB, &args);
if (io < 0)
RARCH_ERR("DRM_IOCTL_MODE_DESTROY_DUMB failed.\n");
free(surface);
free(surface);
}
oga_framebuf_t* oga_create_framebuf(oga_surface_t* surface)
@ -282,7 +282,7 @@ oga_framebuf_t* oga_create_framebuf(oga_surface_t* surface)
const uint32_t pitches[4] = {surface->pitch, 0, 0, 0};
const uint32_t offsets[4] = {0, 0, 0, 0};
oga_framebuf_t* framebuf = calloc(1, sizeof(oga_framebuf_t));
if (!framebuf)
{
RARCH_ERR("Error allocating framebuf\n");
@ -293,8 +293,8 @@ oga_framebuf_t* oga_create_framebuf(oga_surface_t* surface)
ret = drmModeAddFB2(surface->display_fd,
surface->width,
surface->height,
surface->rk_format == RK_FORMAT_BGRA_8888
? DRM_FORMAT_ARGB8888
surface->rk_format == RK_FORMAT_BGRA_8888
? DRM_FORMAT_ARGB8888
: DRM_FORMAT_RGB565,
handles,
pitches,
@ -314,11 +314,11 @@ oga_framebuf_t* oga_create_framebuf(oga_surface_t* surface)
void oga_destroy_framebuf(oga_framebuf_t* framebuf)
{
if (drmModeRmFB(framebuf->surface->display_fd, framebuf->fb_id) != 0)
RARCH_ERR("drmModeRmFB failed.\n");
if (drmModeRmFB(framebuf->surface->display_fd, framebuf->fb_id) != 0)
RARCH_ERR("drmModeRmFB failed.\n");
oga_destroy_surface(framebuf->surface);
free(framebuf);
oga_destroy_surface(framebuf->surface);
free(framebuf);
}
static void oga_gfx_free(void *data)
@ -349,7 +349,7 @@ static void oga_gfx_free(void *data)
}
static void *oga_gfx_init(const video_info_t *video,
input_driver_t **input, void **input_data)
input_driver_t **input, void **input_data)
{
int i;
oga_video_t *vid = NULL;
@ -399,7 +399,7 @@ static void *oga_gfx_init(const video_info_t *video,
* 1 MITCHELL
* 2 HERMITE
* 3 B-SPLINE
*/
*/
vid->scale_mode = video->ctx_scaling << 1 | video->smooth;
vid->rotation = 0;
@ -444,16 +444,16 @@ static void rga_clear_surface(oga_surface_t* surface, int color)
int get_message_width(oga_video_t* vid, const char* msg)
{
int width = 0;
for (const char* c = msg; *c; c++)
{
const struct font_glyph* glyph = vid->font_driver->get_glyph(vid->font, *c);
if (unlikely(!glyph))
continue;
int width = 0;
for (const char* c = msg; *c; c++)
{
const struct font_glyph* glyph = vid->font_driver->get_glyph(vid->font, *c);
if (unlikely(!glyph))
continue;
width += glyph->advance_x;
}
return width;
width += glyph->advance_x;
}
return width;
}
static bool render_msg(oga_video_t* vid, const char* msg)
@ -466,9 +466,9 @@ static bool render_msg(oga_video_t* vid, const char* msg)
int dest_stride;
if (strcmp(msg, vid->last_msg) == 0)
return true;
return true;
strncpy(vid->last_msg, c, sizeof(vid->last_msg)-1);
strlcpy(vid->last_msg, c, sizeof(vid->last_msg));
rga_clear_surface(vid->msg_surface, 0);
atlas = vid->font_driver->get_atlas(vid->font);
@ -496,8 +496,8 @@ static bool render_msg(oga_video_t* vid, const char* msg)
vid->msg_height += g->height;
}
source = atlas->buffer + g->atlas_offset_y *
atlas->width + g->atlas_offset_x;
source = atlas->buffer + g->atlas_offset_y *
atlas->width + g->atlas_offset_x;
dest = fb + dest_y * dest_stride + dest_x;
for (y = 0; y < g->height; y++)
@ -526,22 +526,22 @@ void oga_blit(oga_surface_t* src, int sx, int sy, int sw, int sh,
oga_surface_t* dst, int dx, int dy, int dw, int dh,
int rotation, int scale_mode, unsigned int blend)
{
rga_info_t s = {
.fd = src->prime_fd,
.rect = { sx, sy, sw, sh, src->width, src->height, src->rk_format },
.rotation = rotation,
.mmuFlag = 1,
.scale_mode = scale_mode,
.blend = blend,
};
rga_info_t s = {
.fd = src->prime_fd,
.rect = { sx, sy, sw, sh, src->width, src->height, src->rk_format },
.rotation = rotation,
.mmuFlag = 1,
.scale_mode = scale_mode,
.blend = blend,
};
rga_info_t d = {
.fd = dst->prime_fd,
.rect = { dx, dy, dw, dh, dst->width, dst->height, dst->rk_format },
.mmuFlag = 1,
};
rga_info_t d = {
.fd = dst->prime_fd,
.rect = { dx, dy, dw, dh, dst->width, dst->height, dst->rk_format },
.mmuFlag = 1,
};
c_RkRgaBlit(&s, &d, NULL);
c_RkRgaBlit(&s, &d, NULL);
}
void oga_calc_bounds(oga_rect_t* r, int width, int height, float aspect)
@ -563,8 +563,8 @@ void oga_calc_bounds(oga_rect_t* r, int width, int height, float aspect)
}
static bool oga_gfx_frame(void *data, const void *frame, unsigned width,
unsigned height, uint64_t frame_count,
unsigned pitch, const char *msg, video_frame_info_t *video_info)
unsigned height, uint64_t frame_count,
unsigned pitch, const char *msg, video_frame_info_t *video_info)
{
oga_video_t *vid = (oga_video_t*)data;
oga_framebuf_t* page = vid->pages[vid->cur_page];
@ -638,7 +638,7 @@ static bool oga_gfx_frame(void *data, const void *frame, unsigned width,
}
static void oga_gfx_set_texture_frame(void *data, const void *frame, bool rgb32,
unsigned width, unsigned height, float alpha)
unsigned width, unsigned height, float alpha)
{
oga_video_t *vid = (oga_video_t*)data;
unsigned i, j;
@ -674,7 +674,7 @@ static void oga_gfx_set_texture_frame(void *data, const void *frame, bool rgb32,
for (j = 0; j < src_pitch / 2; j++)
{
uint16_t src_pix = *((uint16_t*)frame + (src_pitch / 2 * i) + j);
/* The hex AND is for keeping only the part
/* The hex AND is for keeping only the part
* we need for each component. */
uint32_t R = (src_pix << 8) & 0x00FF0000;
uint32_t G = (src_pix << 4) & 0x0000FF00;
@ -705,13 +705,13 @@ static bool oga_gfx_has_windowed(void *data) { return false; }
static void oga_gfx_viewport_info(void *data, struct video_viewport *vp)
{
oga_video_t *vid = (oga_video_t*)data;
if (unlikely(!vid))
return;
oga_video_t *vid = (oga_video_t*)data;
if (unlikely(!vid))
return;
vp->x = vp->y = 0;
vp->width = vp->full_width = NATIVE_WIDTH;
vp->height = vp->full_height = NATIVE_HEIGHT;
vp->x = vp->y = 0;
vp->width = vp->full_width = NATIVE_WIDTH;
vp->height = vp->full_height = NATIVE_HEIGHT;
}
static bool oga_gfx_set_shader(void *data, enum rarch_shader_type type, const char *path)
@ -731,74 +731,74 @@ void oga_set_rotation(void *data, unsigned rotation)
switch (rotation)
{
case 0:
vid->rotation = HAL_TRANSFORM_ROT_270;
break;
case 1:
vid->rotation = HAL_TRANSFORM_ROT_180;
break;
case 2:
vid->rotation = HAL_TRANSFORM_ROT_90;
break;
case 3:
vid->rotation = 0;
break;
default:
RARCH_ERR("Unhandled rotation %hu\n", rotation);
break;
case 0:
vid->rotation = HAL_TRANSFORM_ROT_270;
break;
case 1:
vid->rotation = HAL_TRANSFORM_ROT_180;
break;
case 2:
vid->rotation = HAL_TRANSFORM_ROT_90;
break;
case 3:
vid->rotation = 0;
break;
default:
RARCH_ERR("Unhandled rotation %hu\n", rotation);
break;
}
}
static const video_poke_interface_t oga_poke_interface = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
oga_gfx_set_texture_frame,
oga_gfx_texture_enable,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
oga_gfx_set_texture_frame,
oga_gfx_texture_enable,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
static void oga_get_poke_interface(void *data, const video_poke_interface_t **iface)
{
*iface = &oga_poke_interface;
*iface = &oga_poke_interface;
}
video_driver_t video_oga = {
oga_gfx_init,
oga_gfx_frame,
oga_gfx_set_nonblock_state,
oga_gfx_alive,
oga_gfx_focus,
oga_gfx_suppress_screensaver,
oga_gfx_has_windowed,
oga_gfx_set_shader,
oga_gfx_free,
"oga",
NULL,
oga_set_rotation,
oga_gfx_viewport_info,
NULL,
NULL,
oga_gfx_init,
oga_gfx_frame,
oga_gfx_set_nonblock_state,
oga_gfx_alive,
oga_gfx_focus,
oga_gfx_suppress_screensaver,
oga_gfx_has_windowed,
oga_gfx_set_shader,
oga_gfx_free,
"oga",
NULL,
oga_set_rotation,
oga_gfx_viewport_info,
NULL,
NULL,
#ifdef HAVE_OVERLAY
NULL,
NULL,
#endif
#ifdef HAVE_VIDEO_LAYOUT
NULL,
NULL,
#endif
oga_get_poke_interface
oga_get_poke_interface
};