2010-09-25 17:46:12 +02:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#include <X11/extensions/XShm.h>
|
|
|
|
#include <X11/extensions/Xv.h>
|
|
|
|
#include <X11/extensions/Xvlib.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
|
|
|
|
#include "gtk_display.h"
|
|
|
|
#include "gtk_display_driver_xv.h"
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_inv_shift (uint32 mask, int bpp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Find mask */
|
|
|
|
for (i = 0; (i < bpp) && !(mask & (1 << i)); i++) {};
|
|
|
|
|
|
|
|
/* Find start of mask */
|
|
|
|
for (; (i < bpp) && (mask & (1 << i)); i++) {};
|
|
|
|
|
|
|
|
return (bpp - i);
|
|
|
|
}
|
|
|
|
|
|
|
|
S9xXVDisplayDriver::S9xXVDisplayDriver (Snes9xWindow *window,
|
|
|
|
Snes9xConfig *config)
|
|
|
|
{
|
|
|
|
this->window = window;
|
|
|
|
this->config = config;
|
|
|
|
this->drawing_area = GTK_WIDGET (window->drawing_area);
|
|
|
|
display =
|
2011-02-11 10:44:47 +01:00
|
|
|
gdk_x11_display_get_xdisplay (gtk_widget_get_display (drawing_area));
|
2010-09-25 17:46:12 +02:00
|
|
|
last_known_width = last_known_height = -1;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-26 11:19:15 +02:00
|
|
|
void
|
|
|
|
S9xXVDisplayDriver::resize_window (int width, int height)
|
|
|
|
{
|
2018-05-05 20:49:42 +02:00
|
|
|
gdk_window_destroy (gdk_window);
|
2014-02-05 09:44:04 +01:00
|
|
|
create_window (width, height);
|
2010-09-26 11:19:15 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
S9xXVDisplayDriver::create_window (int width, int height)
|
|
|
|
{
|
2018-05-05 20:49:42 +02:00
|
|
|
GdkWindowAttr window_attr;
|
|
|
|
memset (&window_attr, 0, sizeof (GdkWindowAttr));
|
|
|
|
window_attr.event_mask = GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK;
|
|
|
|
window_attr.width = width;
|
|
|
|
window_attr.height = height;
|
|
|
|
window_attr.x = 0;
|
|
|
|
window_attr.y = 0;
|
|
|
|
window_attr.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
window_attr.window_type = GDK_WINDOW_CHILD;
|
|
|
|
window_attr.visual = gdk_x11_screen_lookup_visual (gtk_widget_get_screen (drawing_area), vi->visualid);
|
|
|
|
|
|
|
|
gdk_window = gdk_window_new (gtk_widget_get_window (drawing_area),
|
|
|
|
&window_attr,
|
|
|
|
GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL);
|
|
|
|
gdk_window_set_user_data (gdk_window, (gpointer) drawing_area);
|
|
|
|
|
|
|
|
gdk_window_show (gdk_window);
|
2018-05-13 18:02:52 +02:00
|
|
|
xwindow = GDK_COMPAT_WINDOW_XID (gdk_window);
|
2010-09-26 11:19:15 +02:00
|
|
|
|
|
|
|
output_window_width = width;
|
|
|
|
output_window_height = height;
|
|
|
|
}
|
|
|
|
|
2010-09-25 17:46:12 +02:00
|
|
|
void
|
2018-05-05 00:12:22 +02:00
|
|
|
S9xXVDisplayDriver::update (int width, int height, int yoffset)
|
2010-09-25 17:46:12 +02:00
|
|
|
{
|
|
|
|
int current_width, current_height, final_pitch;
|
|
|
|
uint8 *final_buffer;
|
|
|
|
int dst_x, dst_y, dst_width, dst_height;
|
2010-09-26 11:19:15 +02:00
|
|
|
GtkAllocation allocation;
|
2010-09-25 17:46:12 +02:00
|
|
|
|
2010-09-26 11:19:15 +02:00
|
|
|
gtk_widget_get_allocation (drawing_area, &allocation);
|
2018-05-05 21:14:06 +02:00
|
|
|
|
|
|
|
if (output_window_width != allocation.width ||
|
|
|
|
output_window_height != allocation.height)
|
|
|
|
{
|
|
|
|
resize_window (allocation.width, allocation.height);
|
|
|
|
}
|
|
|
|
|
2016-10-03 02:41:42 +02:00
|
|
|
#if GTK_CHECK_VERSION(3,10,0)
|
|
|
|
int gdk_scale_factor = gdk_window_get_scale_factor (gdk_window);
|
|
|
|
|
|
|
|
allocation.width *= gdk_scale_factor;
|
|
|
|
allocation.height *= gdk_scale_factor;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-09-26 11:19:15 +02:00
|
|
|
current_width = allocation.width;
|
|
|
|
current_height = allocation.height;
|
2010-09-25 17:46:12 +02:00
|
|
|
|
|
|
|
if (config->scale_method > 0)
|
|
|
|
{
|
|
|
|
uint8 *src_buffer = (uint8 *) padded_buffer[0];
|
|
|
|
uint8 *dst_buffer = (uint8 *) padded_buffer[1];
|
|
|
|
int src_pitch = image_width * image_bpp;
|
|
|
|
int dst_pitch = scaled_max_width * image_bpp;
|
|
|
|
|
2018-05-05 00:12:22 +02:00
|
|
|
src_buffer += (src_pitch * yoffset);
|
|
|
|
|
2010-09-25 17:46:12 +02:00
|
|
|
S9xFilter (src_buffer,
|
|
|
|
src_pitch,
|
|
|
|
dst_buffer,
|
|
|
|
dst_pitch,
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
|
|
|
|
final_buffer = (uint8 *) padded_buffer[1];
|
|
|
|
final_pitch = dst_pitch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
final_buffer = (uint8 *) padded_buffer[0];
|
|
|
|
final_pitch = image_width * image_bpp;
|
2018-05-05 00:12:22 +02:00
|
|
|
final_buffer += (final_pitch * yoffset);
|
2010-09-25 17:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
update_image_size (width, height);
|
|
|
|
|
|
|
|
if (format == FOURCC_YUY2)
|
|
|
|
{
|
|
|
|
S9xConvertYUV (final_buffer,
|
|
|
|
(uint8 *) xv_image->data,
|
|
|
|
final_pitch,
|
|
|
|
2 * xv_image->width,
|
|
|
|
width + (width < xv_image->width ? (width % 2) + 4 : 0),
|
|
|
|
height + (height < xv_image->height ? 4 : 0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
S9xConvertMask (final_buffer,
|
|
|
|
(uint8 *) xv_image->data,
|
|
|
|
final_pitch,
|
|
|
|
bytes_per_pixel * xv_image->width,
|
|
|
|
width + (width < xv_image->width ? (width % 2) + 4 : 0),
|
|
|
|
height + (height < xv_image->height ? 4 : 0),
|
|
|
|
rshift,
|
|
|
|
gshift,
|
|
|
|
bshift,
|
|
|
|
bpp);
|
|
|
|
}
|
|
|
|
|
2010-09-26 11:19:15 +02:00
|
|
|
dst_x = width; dst_y = height;
|
|
|
|
dst_width = current_width; dst_height = current_height;
|
|
|
|
S9xApplyAspect (dst_x, dst_y, dst_width, dst_height);
|
2010-09-25 17:46:12 +02:00
|
|
|
|
|
|
|
if (last_known_width != dst_width || last_known_height != dst_height)
|
|
|
|
{
|
|
|
|
last_known_width = dst_width;
|
|
|
|
last_known_height = dst_height;
|
|
|
|
clear ();
|
|
|
|
}
|
|
|
|
|
|
|
|
XvShmPutImage (display,
|
|
|
|
xv_portid,
|
|
|
|
xwindow,
|
2010-09-26 11:19:15 +02:00
|
|
|
XDefaultGC (display, XDefaultScreen (display)),
|
2010-09-25 17:46:12 +02:00
|
|
|
xv_image,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
dst_x,
|
|
|
|
dst_y,
|
|
|
|
dst_width,
|
|
|
|
dst_height,
|
|
|
|
False);
|
|
|
|
|
|
|
|
top_level->set_mouseable_area (dst_x, dst_y, dst_width, dst_height);
|
|
|
|
|
|
|
|
XSync (display, False);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
S9xXVDisplayDriver::update_image_size (int width, int height)
|
|
|
|
{
|
|
|
|
if (desired_width != width || desired_height != height)
|
|
|
|
{
|
|
|
|
XShmDetach (display, &shm);
|
|
|
|
XSync (display, 0);
|
|
|
|
|
|
|
|
shmctl (shm.shmid, IPC_RMID, 0);
|
|
|
|
shmdt (shm.shmaddr);
|
|
|
|
|
|
|
|
xv_image = XvShmCreateImage (display,
|
|
|
|
xv_portid,
|
|
|
|
format,
|
|
|
|
0,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
&shm);
|
|
|
|
|
|
|
|
shm.shmid = shmget (IPC_PRIVATE, xv_image->data_size, IPC_CREAT | 0777);
|
|
|
|
for (int tries = 0; tries <= 10; tries++)
|
|
|
|
{
|
|
|
|
shm.shmaddr = (char *) shmat (shm.shmid, 0, 0);
|
|
|
|
|
|
|
|
if (shm.shmaddr == (void *) -1 && tries >= 10)
|
|
|
|
{
|
|
|
|
/* Can't recover, send exit. */
|
|
|
|
fprintf (stderr, "Couldn't reallocate shared memory.\n");
|
|
|
|
S9xExit ();
|
|
|
|
}
|
|
|
|
else if (shm.shmaddr != (void *) -1)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shm.readOnly = FALSE;
|
|
|
|
|
|
|
|
xv_image->data = shm.shmaddr;
|
|
|
|
|
|
|
|
XShmAttach (display, &shm);
|
|
|
|
|
|
|
|
desired_width = width;
|
|
|
|
desired_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
S9xXVDisplayDriver::init (void)
|
|
|
|
{
|
|
|
|
int depth = 0, num_formats, num_attrs, highest_formats = 0;
|
|
|
|
XvImageFormatValues *formats = NULL;
|
|
|
|
XvAdaptorInfo *adaptors;
|
|
|
|
XvAttribute *port_attr;
|
|
|
|
VisualID visualid = None;
|
|
|
|
unsigned int num_adaptors;
|
|
|
|
GdkScreen *screen;
|
|
|
|
GdkWindow *root;
|
|
|
|
|
|
|
|
buffer[0] = malloc (image_padded_size);
|
|
|
|
buffer[1] = malloc (scaled_padded_size);
|
|
|
|
|
2018-05-05 00:12:22 +02:00
|
|
|
padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + image_padded_offset);
|
|
|
|
padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + scaled_padded_offset);
|
2010-09-25 17:46:12 +02:00
|
|
|
|
|
|
|
memset (buffer[0], 0, image_padded_size);
|
|
|
|
memset (buffer[1], 0, scaled_padded_size);
|
|
|
|
|
|
|
|
/* Setup XV */
|
|
|
|
gtk_widget_realize (drawing_area);
|
|
|
|
|
2011-02-11 10:44:47 +01:00
|
|
|
display = gdk_x11_display_get_xdisplay (gtk_widget_get_display (drawing_area));
|
2010-09-25 17:46:12 +02:00
|
|
|
screen = gtk_widget_get_screen (drawing_area);
|
|
|
|
root = gdk_screen_get_root_window (screen);
|
|
|
|
|
|
|
|
xv_portid = -1;
|
|
|
|
XvQueryAdaptors (display,
|
2011-02-05 13:36:27 +01:00
|
|
|
GDK_COMPAT_WINDOW_XID (root),
|
2010-09-25 17:46:12 +02:00
|
|
|
&num_adaptors,
|
|
|
|
&adaptors);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < (int) num_adaptors; i++)
|
|
|
|
{
|
|
|
|
if (adaptors[i].type & XvInputMask &&
|
|
|
|
adaptors[i].type & XvImageMask)
|
|
|
|
{
|
|
|
|
formats = XvListImageFormats (display,
|
|
|
|
adaptors[i].base_id,
|
|
|
|
&num_formats);
|
|
|
|
|
|
|
|
if (num_formats > highest_formats)
|
|
|
|
{
|
|
|
|
xv_portid = adaptors[i].base_id;
|
|
|
|
highest_formats = num_formats;
|
|
|
|
visualid = adaptors[i].formats->visual_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
free (formats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XvFreeAdaptorInfo (adaptors);
|
|
|
|
|
|
|
|
if (xv_portid < 0)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Could not open Xv output port.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set XV_AUTOPAINT_COLORKEY _only_ if available */
|
|
|
|
port_attr = XvQueryPortAttributes (display, xv_portid, &num_attrs);
|
|
|
|
|
|
|
|
for (int i = 0; i < num_attrs; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp (port_attr[i].name, "XV_AUTOPAINT_COLORKEY"))
|
|
|
|
{
|
2016-09-27 22:25:37 +02:00
|
|
|
Atom colorkey;
|
2010-09-25 17:46:12 +02:00
|
|
|
|
|
|
|
colorkey = XInternAtom (display, "XV_AUTOPAINT_COLORKEY", True);
|
|
|
|
if (colorkey != None)
|
|
|
|
XvSetPortAttribute (display, xv_portid, colorkey, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to find an RGB format */
|
|
|
|
format = FOURCC_YUY2;
|
|
|
|
bpp = 100;
|
|
|
|
|
|
|
|
formats = XvListImageFormats (display,
|
|
|
|
xv_portid,
|
|
|
|
&num_formats);
|
|
|
|
|
|
|
|
for (int i = 0; i < num_formats; i++)
|
|
|
|
{
|
|
|
|
if (formats[i].id == 0x3 || formats[i].type == XvRGB)
|
|
|
|
{
|
|
|
|
if (formats[i].bits_per_pixel < bpp)
|
|
|
|
{
|
|
|
|
format = formats[i].id;
|
|
|
|
bpp = formats[i].bits_per_pixel;
|
|
|
|
bytes_per_pixel = (bpp == 15) ? 2 : bpp >> 3;
|
|
|
|
depth = formats[i].depth;
|
|
|
|
|
|
|
|
this->rshift = get_inv_shift (formats[i].red_mask, bpp);
|
|
|
|
this->gshift = get_inv_shift (formats[i].green_mask, bpp);
|
|
|
|
this->bshift = get_inv_shift (formats[i].blue_mask, bpp);
|
|
|
|
|
|
|
|
/* Check for red-blue inversion on SiliconMotion drivers */
|
|
|
|
if (formats[i].red_mask == 0x001f &&
|
|
|
|
formats[i].blue_mask == 0x7c00)
|
|
|
|
{
|
|
|
|
int copy = this->rshift;
|
|
|
|
this->rshift = this->bshift;
|
|
|
|
this->bshift = copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* on big-endian Xv still seems to like LSB order */
|
|
|
|
if (config->force_inverted_byte_order)
|
2018-05-04 21:28:50 +02:00
|
|
|
S9xSetEndianess (ENDIAN_SWAPPED);
|
2010-09-25 17:46:12 +02:00
|
|
|
else
|
2018-05-04 21:28:50 +02:00
|
|
|
S9xSetEndianess (ENDIAN_NORMAL);
|
2010-09-25 17:46:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format == FOURCC_YUY2)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < num_formats; i++)
|
|
|
|
{
|
|
|
|
if (formats[i].id == FOURCC_YUY2)
|
|
|
|
{
|
|
|
|
depth = formats[i].depth;
|
|
|
|
|
|
|
|
if (formats[i].byte_order == LSBFirst)
|
|
|
|
{
|
|
|
|
if (config->force_inverted_byte_order)
|
2018-05-04 21:28:50 +02:00
|
|
|
S9xSetEndianess (ENDIAN_SWAPPED);
|
2010-09-25 17:46:12 +02:00
|
|
|
else
|
2018-05-04 21:28:50 +02:00
|
|
|
S9xSetEndianess (ENDIAN_NORMAL);
|
2010-09-25 17:46:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (config->force_inverted_byte_order)
|
2018-05-04 21:28:50 +02:00
|
|
|
S9xSetEndianess (ENDIAN_NORMAL);
|
2010-09-25 17:46:12 +02:00
|
|
|
else
|
2018-05-04 21:28:50 +02:00
|
|
|
S9xSetEndianess (ENDIAN_SWAPPED);
|
2010-09-25 17:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free (formats);
|
|
|
|
|
|
|
|
/* Build a table for yuv conversion */
|
|
|
|
if (format == FOURCC_YUY2)
|
|
|
|
{
|
|
|
|
for (unsigned int color = 0; color < 65536; color++)
|
|
|
|
{
|
|
|
|
int r, g, b;
|
|
|
|
int y, u, v;
|
|
|
|
|
2018-05-05 20:49:42 +02:00
|
|
|
r = ((color & 0xf800) >> 8) | ((color >> 13) & 0x7);
|
|
|
|
g = ((color & 0x07e0) >> 3) | ((color >> 9 ) & 0x3);
|
|
|
|
b = ((color & 0x001F) << 3) | ((color >> 3 ) & 0x7);
|
2010-09-25 17:46:12 +02:00
|
|
|
|
|
|
|
y = (int) ((0.257 * ((double) r)) + (0.504 * ((double) g)) + (0.098 * ((double) b)) + 16.0);
|
|
|
|
u = (int) ((-0.148 * ((double) r)) + (-0.291 * ((double) g)) + (0.439 * ((double) b)) + 128.0);
|
|
|
|
v = (int) ((0.439 * ((double) r)) + (-0.368 * ((double) g)) + (-0.071 * ((double) b)) + 128.0);
|
|
|
|
|
|
|
|
y_table[color] = CLAMP (y, 0, 255);
|
|
|
|
u_table[color] = CLAMP (u, 0, 255);
|
|
|
|
v_table[color] = CLAMP (v, 0, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
S9xRegisterYUVTables (y_table, u_table, v_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a sub-window */
|
2010-09-26 11:19:15 +02:00
|
|
|
XVisualInfo vi_template;
|
2010-09-25 17:46:12 +02:00
|
|
|
int vi_num_items;
|
|
|
|
|
|
|
|
vi_template.visualid = visualid;
|
|
|
|
vi_template.depth = depth;
|
|
|
|
vi_template.visual = NULL;
|
|
|
|
vi = XGetVisualInfo (display, VisualIDMask | VisualDepthMask, &vi_template, &vi_num_items);
|
|
|
|
|
|
|
|
if (!vi)
|
|
|
|
{
|
|
|
|
vi_template.depth = 0;
|
|
|
|
vi = XGetVisualInfo (display, VisualIDMask, &vi_template, &vi_num_items);
|
|
|
|
|
|
|
|
if (!vi)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Couldn't map visual.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xcolormap = XCreateColormap (display,
|
2011-02-05 13:36:27 +01:00
|
|
|
GDK_COMPAT_WINDOW_XID (gtk_widget_get_window (drawing_area)),
|
2010-09-25 17:46:12 +02:00
|
|
|
vi->visual,
|
|
|
|
AllocNone);
|
|
|
|
|
2010-09-26 11:19:15 +02:00
|
|
|
create_window (1, 1);
|
2010-09-25 17:46:12 +02:00
|
|
|
gdk_window_hide (gdk_window);
|
|
|
|
|
|
|
|
/* Allocate a shared memory image. */
|
|
|
|
xv_image = XvShmCreateImage (display,
|
|
|
|
xv_portid,
|
|
|
|
format,
|
|
|
|
0,
|
|
|
|
scaled_max_width,
|
|
|
|
scaled_max_width,
|
|
|
|
&shm);
|
|
|
|
|
|
|
|
shm.shmid = shmget (IPC_PRIVATE, xv_image->data_size, IPC_CREAT | 0777);
|
|
|
|
shm.shmaddr = (char *) shmat (shm.shmid, 0, 0);
|
|
|
|
if (shm.shmaddr == (void *) -1)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Could not attach shared memory segment.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
shm.readOnly = FALSE;
|
|
|
|
|
|
|
|
xv_image->data = shm.shmaddr;
|
|
|
|
|
|
|
|
XShmAttach (display, &shm);
|
|
|
|
|
|
|
|
desired_width = scaled_max_width;
|
|
|
|
desired_height = scaled_max_width;
|
|
|
|
|
|
|
|
clear_buffers ();
|
|
|
|
|
|
|
|
/* Give Snes9x core a pointer to draw on */
|
|
|
|
GFX.Screen = (uint16 *) padded_buffer[0];
|
|
|
|
GFX.Pitch = image_width * image_bpp;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
S9xXVDisplayDriver::deinit (void)
|
|
|
|
{
|
2018-05-05 20:49:42 +02:00
|
|
|
gdk_window_destroy (gdk_window);
|
|
|
|
|
2010-09-25 17:46:12 +02:00
|
|
|
XShmDetach (display, &shm);
|
|
|
|
XSync (display, 0);
|
|
|
|
|
|
|
|
XFreeColormap (display, xcolormap);
|
2010-09-26 11:19:15 +02:00
|
|
|
XFree (vi);
|
|
|
|
|
2010-09-25 17:46:12 +02:00
|
|
|
free (buffer[0]);
|
|
|
|
free (buffer[1]);
|
|
|
|
|
|
|
|
shmctl (shm.shmid, IPC_RMID, 0);
|
|
|
|
shmdt (shm.shmaddr);
|
|
|
|
|
|
|
|
padded_buffer[0] = NULL;
|
|
|
|
padded_buffer[1] = NULL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
S9xXVDisplayDriver::clear (void)
|
|
|
|
{
|
2010-09-26 11:19:15 +02:00
|
|
|
int x, y, w, h;
|
|
|
|
int width, height;
|
|
|
|
GtkAllocation allocation;
|
|
|
|
GC xgc = XDefaultGC (display, XDefaultScreen (display));
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (drawing_area, &allocation);
|
2016-10-03 02:41:42 +02:00
|
|
|
#if GTK_CHECK_VERSION(3,10,0)
|
|
|
|
int gdk_scale_factor = gdk_window_get_scale_factor (gdk_window);
|
|
|
|
|
|
|
|
allocation.width *= gdk_scale_factor;
|
|
|
|
allocation.height *= gdk_scale_factor;
|
|
|
|
|
|
|
|
#endif
|
2010-09-26 11:19:15 +02:00
|
|
|
width = allocation.width;
|
|
|
|
height = allocation.height;
|
2010-09-25 17:46:12 +02:00
|
|
|
|
|
|
|
if (window->last_width <= 0 || window->last_height <= 0)
|
|
|
|
{
|
|
|
|
XDrawRectangle (display, xwindow, xgc, 0, 0, width, height);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get width of modified display */
|
2010-09-26 11:19:15 +02:00
|
|
|
x = window->last_width;
|
|
|
|
y = window->last_height;
|
|
|
|
get_filter_scale (x, y);
|
|
|
|
w = width;
|
|
|
|
h = height;
|
|
|
|
S9xApplyAspect (x, y, w, h);
|
2010-09-25 17:46:12 +02:00
|
|
|
|
|
|
|
if (x > 0)
|
|
|
|
{
|
|
|
|
XFillRectangle (display, xwindow, xgc, 0, y, x, h);
|
|
|
|
}
|
|
|
|
if (x + w < width)
|
|
|
|
{
|
|
|
|
XFillRectangle (display, xwindow, xgc, x + w, y, width - (x + w), h);
|
|
|
|
}
|
|
|
|
if (y > 0)
|
|
|
|
{
|
|
|
|
XFillRectangle (display, xwindow, xgc, 0, 0, width, y);
|
|
|
|
}
|
|
|
|
if (y + h < height)
|
|
|
|
{
|
|
|
|
XFillRectangle (display, xwindow, xgc, 0, y + h, width, height - (y + h));
|
|
|
|
}
|
|
|
|
|
|
|
|
XSync (display, False);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
S9xXVDisplayDriver::refresh (int width, int height)
|
|
|
|
{
|
|
|
|
clear ();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 *
|
|
|
|
S9xXVDisplayDriver::get_next_buffer (void)
|
|
|
|
{
|
|
|
|
return (uint16 *) padded_buffer[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 *
|
|
|
|
S9xXVDisplayDriver::get_current_buffer (void)
|
|
|
|
{
|
|
|
|
return get_next_buffer ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
S9xXVDisplayDriver::push_buffer (uint16 *src)
|
|
|
|
{
|
|
|
|
memmove (GFX.Screen, src, image_size);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
S9xXVDisplayDriver::clear_buffers (void)
|
|
|
|
{
|
|
|
|
uint32 black;
|
|
|
|
uint8 *color;
|
|
|
|
|
|
|
|
memset (buffer[0], 0, image_padded_size);
|
|
|
|
memset (buffer[1], 0, scaled_padded_size);
|
|
|
|
|
|
|
|
/* Construct value byte-order independently */
|
|
|
|
if (format == FOURCC_YUY2)
|
|
|
|
{
|
|
|
|
color = (uint8 *) &black;
|
|
|
|
*color++ = y_table[0];
|
|
|
|
*color++ = u_table[0];
|
|
|
|
*color++ = y_table[0];
|
|
|
|
*color++ = v_table[0];
|
|
|
|
|
|
|
|
for (int i = 0; i < xv_image->data_size >> 2; i++)
|
|
|
|
{
|
|
|
|
*(((uint32 *) xv_image->data) + i) = black;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset (xv_image->data, 0, xv_image->data_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
S9xXVDisplayDriver::query_availability (void)
|
|
|
|
{
|
|
|
|
unsigned int p_version,
|
|
|
|
p_release,
|
|
|
|
p_request_base,
|
|
|
|
p_event_base,
|
|
|
|
p_error_base;
|
2010-09-26 11:19:15 +02:00
|
|
|
Display *display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
|
2010-09-25 17:46:12 +02:00
|
|
|
|
|
|
|
/* Test if XV and SHM are feasible */
|
2010-09-26 11:19:15 +02:00
|
|
|
if (!XShmQueryExtension (display))
|
2010-09-25 17:46:12 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-26 11:19:15 +02:00
|
|
|
if (XvQueryExtension (display,
|
2010-09-25 17:46:12 +02:00
|
|
|
&p_version,
|
|
|
|
&p_release,
|
|
|
|
&p_request_base,
|
|
|
|
&p_event_base,
|
|
|
|
&p_error_base) != Success)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
S9xXVDisplayDriver::reconfigure (int width, int height)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|