GTK+: Faster cairo software output path.

This commit is contained in:
Brandon Wright 2018-10-27 19:07:49 -05:00
parent 09498e72e0
commit f1b508de1c
2 changed files with 12 additions and 61 deletions

View File

@ -11,7 +11,6 @@ S9xGTKDisplayDriver::S9xGTKDisplayDriver (Snes9xWindow *window,
this->window = window;
this->config = config;
this->drawing_area = GTK_WIDGET (window->drawing_area);
this->pixbuf = NULL;
return;
}
@ -20,17 +19,15 @@ void
S9xGTKDisplayDriver::update (int width, int height, int yoffset)
{
int x, y, w, h;
int c_width, c_height, final_pitch;
int final_pitch;
uint8 *final_buffer;
GtkAllocation allocation;
gtk_widget_get_allocation (drawing_area, &allocation);
c_width = allocation.width;
c_height = allocation.height;
if (width <= 0)
return;
gtk_widget_get_allocation (drawing_area, &allocation);
if (config->scale_method > 0)
{
uint8 *src_buffer = (uint8 *) padded_buffer[0];
@ -57,7 +54,7 @@ S9xGTKDisplayDriver::update (int width, int height, int yoffset)
final_buffer += (final_pitch * yoffset);
}
x = width; y = height; w = c_width; h = c_height;
x = width; y = height; w = allocation.width; h = allocation.height;
S9xApplyAspect (x, y, w, h);
output (final_buffer, final_pitch, x, y, width, height, w, h);
@ -75,26 +72,6 @@ S9xGTKDisplayDriver::output (void *src,
int dst_width,
int dst_height)
{
if (width != gdk_buffer_width || height != gdk_buffer_height)
{
gdk_buffer_width = width;
gdk_buffer_height = height;
g_object_unref (pixbuf);
padded_buffer[2] = realloc (padded_buffer[2],
gdk_buffer_width * gdk_buffer_height * 3);
pixbuf = gdk_pixbuf_new_from_data ((guchar *) padded_buffer[2],
GDK_COLORSPACE_RGB,
FALSE,
8,
gdk_buffer_width,
gdk_buffer_height,
gdk_buffer_width * 3,
NULL,
NULL);
}
if (last_known_width != dst_width || last_known_height != dst_height)
{
clear ();
@ -103,17 +80,13 @@ S9xGTKDisplayDriver::output (void *src,
last_known_height = dst_height;
}
S9xConvert (src,
padded_buffer[2],
src_pitch,
gdk_buffer_width * 3,
width,
height,
24);
cairo_t *cr = window->get_cairo ();
gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
cairo_surface_t *surface;
surface = cairo_image_surface_create_for_data ((unsigned char *) src, CAIRO_FORMAT_RGB16_565, width, height, src_pitch);
cairo_set_source_surface (cr, surface, 0, 0);
if (width != dst_width || height != dst_height)
{
@ -135,6 +108,9 @@ S9xGTKDisplayDriver::output (void *src,
cairo_rectangle (cr, x, y, dst_width, dst_height);
cairo_fill (cr);
cairo_surface_finish (surface);
cairo_surface_destroy (surface);
window->release_cairo ();
window->set_mouseable_area (x, y, width, height);
@ -144,31 +120,12 @@ S9xGTKDisplayDriver::output (void *src,
int
S9xGTKDisplayDriver::init (void)
{
GtkAllocation allocation;
buffer[0] = malloc (image_padded_size);
buffer[1] = malloc (scaled_padded_size);
padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + image_padded_offset);
padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + scaled_padded_offset);
gtk_widget_get_allocation (drawing_area, &allocation);
gdk_buffer_width = allocation.width;
gdk_buffer_height = allocation.height;
padded_buffer[2] = malloc (gdk_buffer_width * gdk_buffer_height * 3);
pixbuf = gdk_pixbuf_new_from_data ((guchar *) padded_buffer[2],
GDK_COLORSPACE_RGB,
FALSE,
8,
gdk_buffer_width,
gdk_buffer_height,
gdk_buffer_width * 3,
NULL,
NULL);
S9xSetEndianess (ENDIAN_SWAPPED);
memset (buffer[0], 0, image_padded_size);
memset (buffer[1], 0, scaled_padded_size);
@ -187,9 +144,6 @@ S9xGTKDisplayDriver::deinit (void)
free (buffer[0]);
free (buffer[1]);
g_object_unref (pixbuf);
free (padded_buffer[2]);
return;
}

View File

@ -30,9 +30,6 @@ class S9xGTKDisplayDriver : public S9xDisplayDriver
int dst_width,
int dst_height);
GdkPixbuf *pixbuf;
int gdk_buffer_width;
int gdk_buffer_height;
int last_known_width;
int last_known_height;
};