mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 21:32:45 +00:00
(xvideo.c) Style nits
This commit is contained in:
parent
eaf08ad88c
commit
94b8e8820e
@ -77,15 +77,16 @@ typedef struct xv
|
|||||||
|
|
||||||
static void xv_set_nonblock_state(void *data, bool state)
|
static void xv_set_nonblock_state(void *data, bool state)
|
||||||
{
|
{
|
||||||
xv_t *xv = (xv_t*)data;
|
xv_t *xv = (xv_t*)data;
|
||||||
Atom atom = XInternAtom(g_x11_dpy, "XV_SYNC_TO_VBLANK", true);
|
Atom atom = XInternAtom(g_x11_dpy, "XV_SYNC_TO_VBLANK", true);
|
||||||
|
|
||||||
if (atom != None && xv->port)
|
if (atom != None && xv->port)
|
||||||
XvSetPortAttribute(g_x11_dpy, xv->port, atom, !state);
|
XvSetPortAttribute(g_x11_dpy, xv->port, atom, !state);
|
||||||
else
|
else
|
||||||
RARCH_WARN("Failed to set SYNC_TO_VBLANK attribute.\n");
|
RARCH_WARN("Failed to set SYNC_TO_VBLANK attribute.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE void calculate_yuv(uint8_t *y, uint8_t *u, uint8_t *v,
|
static INLINE void xv_calculate_yuv(uint8_t *y, uint8_t *u, uint8_t *v,
|
||||||
unsigned r, unsigned g, unsigned b)
|
unsigned r, unsigned g, unsigned b)
|
||||||
{
|
{
|
||||||
int y_ = (int)(+((double)r * 0.257) + ((double)g * 0.504)
|
int y_ = (int)(+((double)r * 0.257) + ((double)g * 0.504)
|
||||||
@ -95,9 +96,9 @@ static INLINE void calculate_yuv(uint8_t *y, uint8_t *u, uint8_t *v,
|
|||||||
int v_ = (int)(+((double)r * 0.439) - ((double)g * 0.368)
|
int v_ = (int)(+((double)r * 0.439) - ((double)g * 0.368)
|
||||||
- ((double)b * 0.071) + 128.0);
|
- ((double)b * 0.071) + 128.0);
|
||||||
|
|
||||||
*y = y_ < 0 ? 0 : (y_ > 255 ? 255 : y_);
|
*y = y_ < 0 ? 0 : (y_ > 255 ? 255 : y_);
|
||||||
*u = y_ < 0 ? 0 : (u_ > 255 ? 255 : u_);
|
*u = y_ < 0 ? 0 : (u_ > 255 ? 255 : u_);
|
||||||
*v = v_ < 0 ? 0 : (v_ > 255 ? 255 : v_);
|
*v = v_ < 0 ? 0 : (v_ > 255 ? 255 : v_);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_yuv_tables(xv_t *xv)
|
static void init_yuv_tables(xv_t *xv)
|
||||||
@ -110,12 +111,15 @@ static void init_yuv_tables(xv_t *xv)
|
|||||||
for (i = 0; i < 0x10000; i++)
|
for (i = 0; i < 0x10000; i++)
|
||||||
{
|
{
|
||||||
/* Extract RGB565 color data from i */
|
/* Extract RGB565 color data from i */
|
||||||
unsigned r = (i >> 11) & 0x1f, g = (i >> 5) & 0x3f, b = (i >> 0) & 0x1f;
|
unsigned r = (i >> 11) & 0x1f;
|
||||||
r = (r << 3) | (r >> 2); /* R5->R8 */
|
unsigned g = (i >> 5) & 0x3f;
|
||||||
g = (g << 2) | (g >> 4); /* G6->G8 */
|
unsigned b = (i >> 0) & 0x1f;
|
||||||
b = (b << 3) | (b >> 2); /* B5->B8 */
|
r = (r << 3) | (r >> 2); /* R5->R8 */
|
||||||
|
g = (g << 2) | (g >> 4); /* G6->G8 */
|
||||||
|
b = (b << 3) | (b >> 2); /* B5->B8 */
|
||||||
|
|
||||||
calculate_yuv(&xv->ytable[i], &xv->utable[i], &xv->vtable[i], r, g, b);
|
xv_calculate_yuv(&xv->ytable[i],
|
||||||
|
&xv->utable[i], &xv->vtable[i], r, g, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +142,7 @@ static void xv_init_font(xv_t *xv, const char *font_path, unsigned font_size)
|
|||||||
b = settings->video.msg_color_b * 255;
|
b = settings->video.msg_color_b * 255;
|
||||||
b = (b < 0 ? 0 : (b > 255 ? 255 : b));
|
b = (b < 0 ? 0 : (b > 255 ? 255 : b));
|
||||||
|
|
||||||
calculate_yuv(&xv->font_y, &xv->font_u, &xv->font_v,
|
xv_calculate_yuv(&xv->font_y, &xv->font_u, &xv->font_v,
|
||||||
r, g, b);
|
r, g, b);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -152,21 +156,20 @@ static void render16_yuy2(xv_t *xv, const void *input_,
|
|||||||
{
|
{
|
||||||
unsigned x, y;
|
unsigned x, y;
|
||||||
const uint16_t *input = (const uint16_t*)input_;
|
const uint16_t *input = (const uint16_t*)input_;
|
||||||
uint8_t *output = (uint8_t*)xv->image->data;
|
uint8_t *output = (uint8_t*)xv->image->data;
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for (x = 0; x < width; x++)
|
for (x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
uint16_t p = *input++;
|
uint16_t p = *input++;
|
||||||
|
uint8_t y0 = xv->ytable[p];
|
||||||
uint8_t y0 = xv->ytable[p];
|
uint8_t u = xv->utable[p];
|
||||||
uint8_t u = xv->utable[p];
|
uint8_t v = xv->vtable[p];
|
||||||
uint8_t v = xv->vtable[p];
|
|
||||||
|
|
||||||
unsigned img_width = xv->width << 1;
|
unsigned img_width = xv->width << 1;
|
||||||
|
|
||||||
output[0] = output[img_width] = y0;
|
output[0] = output[img_width] = y0;
|
||||||
output[1] = output[img_width + 1] = u;
|
output[1] = output[img_width + 1] = u;
|
||||||
output[2] = output[img_width + 2] = y0;
|
output[2] = output[img_width + 2] = y0;
|
||||||
output[3] = output[img_width + 3] = v;
|
output[3] = output[img_width + 3] = v;
|
||||||
@ -183,21 +186,19 @@ static void render16_uyvy(xv_t *xv, const void *input_,
|
|||||||
{
|
{
|
||||||
unsigned x, y;
|
unsigned x, y;
|
||||||
const uint16_t *input = (const uint16_t*)input_;
|
const uint16_t *input = (const uint16_t*)input_;
|
||||||
uint8_t *output = (uint8_t*)xv->image->data;
|
uint8_t *output = (uint8_t*)xv->image->data;
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for (x = 0; x < width; x++)
|
for (x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
uint16_t p = *input++;
|
uint16_t p = *input++;
|
||||||
|
uint8_t y0 = xv->ytable[p];
|
||||||
uint8_t y0 = xv->ytable[p];
|
uint8_t u = xv->utable[p];
|
||||||
uint8_t u = xv->utable[p];
|
uint8_t v = xv->vtable[p];
|
||||||
uint8_t v = xv->vtable[p];
|
|
||||||
|
|
||||||
unsigned img_width = xv->width << 1;
|
unsigned img_width = xv->width << 1;
|
||||||
|
|
||||||
output[0] = output[img_width] = u;
|
output[0] = output[img_width] = u;
|
||||||
output[1] = output[img_width + 1] = y0;
|
output[1] = output[img_width + 1] = y0;
|
||||||
output[2] = output[img_width + 2] = v;
|
output[2] = output[img_width + 2] = v;
|
||||||
output[3] = output[img_width + 3] = y0;
|
output[3] = output[img_width + 3] = y0;
|
||||||
@ -214,7 +215,7 @@ static void render32_yuy2(xv_t *xv, const void *input_,
|
|||||||
{
|
{
|
||||||
unsigned x, y;
|
unsigned x, y;
|
||||||
const uint32_t *input = (const uint32_t*)input_;
|
const uint32_t *input = (const uint32_t*)input_;
|
||||||
uint8_t *output = (uint8_t*)xv->image->data;
|
uint8_t *output = (uint8_t*)xv->image->data;
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
@ -226,9 +227,9 @@ static void render32_yuy2(xv_t *xv, const void *input_,
|
|||||||
p = ((p >> 8) & 0xf800) | ((p >> 5) & 0x07e0)
|
p = ((p >> 8) & 0xf800) | ((p >> 5) & 0x07e0)
|
||||||
| ((p >> 3) & 0x1f); /* ARGB -> RGB16 */
|
| ((p >> 3) & 0x1f); /* ARGB -> RGB16 */
|
||||||
|
|
||||||
y0 = xv->ytable[p];
|
y0 = xv->ytable[p];
|
||||||
u = xv->utable[p];
|
u = xv->utable[p];
|
||||||
v = xv->vtable[p];
|
v = xv->vtable[p];
|
||||||
|
|
||||||
img_width = xv->width << 1;
|
img_width = xv->width << 1;
|
||||||
output[0] = output[img_width] = y0;
|
output[0] = output[img_width] = y0;
|
||||||
@ -248,7 +249,7 @@ static void render32_uyvy(xv_t *xv, const void *input_,
|
|||||||
{
|
{
|
||||||
unsigned x, y;
|
unsigned x, y;
|
||||||
const uint32_t *input = (const uint32_t*)input_;
|
const uint32_t *input = (const uint32_t*)input_;
|
||||||
uint16_t *output = (uint16_t*)xv->image->data;
|
uint16_t *output = (uint16_t*)xv->image->data;
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
@ -260,9 +261,9 @@ static void render32_uyvy(xv_t *xv, const void *input_,
|
|||||||
p = ((p >> 8) & 0xf800)
|
p = ((p >> 8) & 0xf800)
|
||||||
| ((p >> 5) & 0x07e0) | ((p >> 3) & 0x1f); /* ARGB -> RGB16 */
|
| ((p >> 5) & 0x07e0) | ((p >> 3) & 0x1f); /* ARGB -> RGB16 */
|
||||||
|
|
||||||
y0 = xv->ytable[p];
|
y0 = xv->ytable[p];
|
||||||
u = xv->utable[p];
|
u = xv->utable[p];
|
||||||
v = xv->vtable[p];
|
v = xv->vtable[p];
|
||||||
|
|
||||||
img_width = xv->width << 1;
|
img_width = xv->width << 1;
|
||||||
output[0] = output[img_width] = u;
|
output[0] = output[img_width] = u;
|
||||||
@ -308,13 +309,14 @@ static const struct format_desc formats[] = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool adaptor_set_format(xv_t *xv, Display *dpy,
|
static bool xv_adaptor_set_format(xv_t *xv, Display *dpy,
|
||||||
XvPortID port, const video_info_t *video)
|
XvPortID port, const video_info_t *video)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned j;
|
unsigned j;
|
||||||
int format_count;
|
int format_count;
|
||||||
XvImageFormatValues *format = XvListImageFormats(g_x11_dpy, port, &format_count);
|
XvImageFormatValues *format = XvListImageFormats(
|
||||||
|
g_x11_dpy, port, &format_count);
|
||||||
|
|
||||||
if (!format)
|
if (!format)
|
||||||
return false;
|
return false;
|
||||||
@ -351,21 +353,23 @@ static bool adaptor_set_format(xv_t *xv, Display *dpy,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void calc_out_rect(bool keep_aspect, struct video_viewport *vp,
|
static void xv_calc_out_rect(bool keep_aspect,
|
||||||
|
struct video_viewport *vp,
|
||||||
unsigned vp_width, unsigned vp_height)
|
unsigned vp_width, unsigned vp_height)
|
||||||
{
|
{
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
|
|
||||||
vp->full_width = vp_width;
|
vp->full_width = vp_width;
|
||||||
vp->full_height = vp_height;
|
vp->full_height = vp_height;
|
||||||
|
|
||||||
if (settings->video.scale_integer)
|
if (settings->video.scale_integer)
|
||||||
video_viewport_get_scaled_integer(vp, vp_width, vp_height,
|
video_viewport_get_scaled_integer(vp, vp_width, vp_height,
|
||||||
video_driver_get_aspect_ratio(), keep_aspect);
|
video_driver_get_aspect_ratio(), keep_aspect);
|
||||||
else if (!keep_aspect)
|
else if (!keep_aspect)
|
||||||
{
|
{
|
||||||
vp->x = 0; vp->y = 0;
|
vp->x = 0;
|
||||||
vp->width = vp_width;
|
vp->y = 0;
|
||||||
|
vp->width = vp_width;
|
||||||
vp->height = vp_height;
|
vp->height = vp_height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -379,25 +383,26 @@ static void calc_out_rect(bool keep_aspect, struct video_viewport *vp,
|
|||||||
*/
|
*/
|
||||||
if (fabs(device_aspect - desired_aspect) < 0.0001)
|
if (fabs(device_aspect - desired_aspect) < 0.0001)
|
||||||
{
|
{
|
||||||
vp->x = 0; vp->y = 0;
|
vp->x = 0;
|
||||||
vp->width = vp_width;
|
vp->y = 0;
|
||||||
vp->height = vp_height;
|
vp->width = vp_width;
|
||||||
|
vp->height = vp_height;
|
||||||
}
|
}
|
||||||
else if (device_aspect > desired_aspect)
|
else if (device_aspect > desired_aspect)
|
||||||
{
|
{
|
||||||
float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
||||||
vp->x = vp_width * (0.5 - delta);
|
vp->x = vp_width * (0.5 - delta);
|
||||||
vp->y = 0;
|
vp->y = 0;
|
||||||
vp->width = 2.0 * vp_width * delta;
|
vp->width = 2.0 * vp_width * delta;
|
||||||
vp->height = vp_height;
|
vp->height = vp_height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
||||||
vp->x = 0;
|
vp->x = 0;
|
||||||
vp->y = vp_height * (0.5 - delta);
|
vp->y = vp_height * (0.5 - delta);
|
||||||
vp->width = vp_width;
|
vp->width = vp_width;
|
||||||
vp->height = 2.0 * vp_height * delta;
|
vp->height = 2.0 * vp_height * delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -460,7 +465,8 @@ static void *xv_init(const video_info_t *video,
|
|||||||
continue;
|
continue;
|
||||||
if (!(adaptor_info[i].type & XvImageMask))
|
if (!(adaptor_info[i].type & XvImageMask))
|
||||||
continue;
|
continue;
|
||||||
if (!adaptor_set_format(xv, g_x11_dpy, adaptor_info[i].base_id, video))
|
if (!xv_adaptor_set_format(xv, g_x11_dpy,
|
||||||
|
adaptor_info[i].base_id, video))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
xv->port = adaptor_info[i].base_id;
|
xv->port = adaptor_info[i].base_id;
|
||||||
@ -584,7 +590,7 @@ static void *xv_init(const video_info_t *video,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
XGetWindowAttributes(g_x11_dpy, g_x11_win, &target);
|
XGetWindowAttributes(g_x11_dpy, g_x11_win, &target);
|
||||||
calc_out_rect(xv->keep_aspect, &xv->vp, target.width, target.height);
|
xv_calc_out_rect(xv->keep_aspect, &xv->vp, target.width, target.height);
|
||||||
xv->vp.full_width = target.width;
|
xv->vp.full_width = target.width;
|
||||||
xv->vp.full_height = target.height;
|
xv->vp.full_height = target.height;
|
||||||
|
|
||||||
@ -597,7 +603,7 @@ error:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool check_resize(xv_t *xv, unsigned width, unsigned height)
|
static bool xv_check_resize(xv_t *xv, unsigned width, unsigned height)
|
||||||
{
|
{
|
||||||
/* We render @ 2x scale to combat chroma downsampling. */
|
/* We render @ 2x scale to combat chroma downsampling. */
|
||||||
if (xv->width != (width << 1) || xv->height != (height << 1))
|
if (xv->width != (width << 1) || xv->height != (height << 1))
|
||||||
@ -774,13 +780,13 @@ static bool xv_frame(void *data, const void *frame, unsigned width,
|
|||||||
if (!frame)
|
if (!frame)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!check_resize(xv, width, height))
|
if (!xv_check_resize(xv, width, height))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
XGetWindowAttributes(g_x11_dpy, g_x11_win, &target);
|
XGetWindowAttributes(g_x11_dpy, g_x11_win, &target);
|
||||||
xv->render_func(xv, frame, width, height, pitch);
|
xv->render_func(xv, frame, width, height, pitch);
|
||||||
|
|
||||||
calc_out_rect(xv->keep_aspect, &xv->vp, target.width, target.height);
|
xv_calc_out_rect(xv->keep_aspect, &xv->vp, target.width, target.height);
|
||||||
xv->vp.full_width = target.width;
|
xv->vp.full_width = target.width;
|
||||||
xv->vp.full_height = target.height;
|
xv->vp.full_height = target.height;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user