Fix issue with expose on GTK+ 3.

This commit is contained in:
Brandon Wright 2017-12-07 12:24:29 -06:00
parent 5e6b9f068a
commit bd59b4e9ac
3 changed files with 62 additions and 34 deletions

View File

@ -108,15 +108,7 @@ S9xGTKDisplayDriver::output (void *src,
height, height,
24); 24);
#ifndef USE_GTK3 cairo_t *cr = window->get_cairo ();
cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (drawing_area));
#else
cairo_rectangle_int_t rect = { x, y, dst_width, dst_height };
cairo_region_t *region = cairo_region_create_rectangle (&rect);
GdkDrawingContext *context = gdk_window_begin_draw_frame (gtk_widget_get_window (drawing_area),
region);
cairo_t *cr = gdk_drawing_context_get_cairo_context (context);
#endif
gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y); gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
@ -140,13 +132,7 @@ S9xGTKDisplayDriver::output (void *src,
cairo_rectangle (cr, x, y, dst_width, dst_height); cairo_rectangle (cr, x, y, dst_width, dst_height);
cairo_fill (cr); cairo_fill (cr);
#ifndef USE_GTK3 window->release_cairo ();
cairo_destroy (cr);
#else
gdk_window_end_draw_frame (gtk_widget_get_window (drawing_area), context);
cairo_region_destroy (region);
#endif
window->set_mouseable_area (x, y, width, height); window->set_mouseable_area (x, y, width, height);
return; return;
@ -219,22 +205,14 @@ S9xGTKDisplayDriver::clear (void)
width = allocation.width; width = allocation.width;
height = allocation.height; height = allocation.height;
#ifndef USE_GTK3 cairo_t *cr = window->get_cairo ();
cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (drawing_area));
#else
cairo_rectangle_int_t rect = { 0, 0, width, height };
cairo_region_t *region = cairo_region_create_rectangle (&rect);
GdkDrawingContext *context = gdk_window_begin_draw_frame (gtk_widget_get_window (drawing_area),
region);
cairo_t *cr = gdk_drawing_context_get_cairo_context (context);
#endif
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
if (window->last_width <= 0 || window->last_height <= 0) if (window->last_width <= 0 || window->last_height <= 0)
{ {
cairo_paint (cr); cairo_paint (cr);
cairo_destroy (cr); window->release_cairo ();
return; return;
} }
@ -265,12 +243,7 @@ S9xGTKDisplayDriver::clear (void)
cairo_fill (cr); cairo_fill (cr);
#ifndef USE_GTK3 window->release_cairo ();
cairo_destroy (cr);
#else
gdk_window_end_draw_frame (gtk_widget_get_window (drawing_area), context);
cairo_region_destroy (region);
#endif
return; return;
} }

View File

@ -139,11 +139,14 @@ event_drawingarea_draw (GtkWidget *widget,
cairo_t *cr, cairo_t *cr,
gpointer data) gpointer data)
{ {
((Snes9xWindow *) data)->expose (); Snes9xWindow *window = (Snes9xWindow *) data;
window->cr = cr;
window->cairo_owned = FALSE;
window->expose ();
window->cr = NULL;
return FALSE; return FALSE;
} }
#endif #endif
#ifndef USE_GTK3 #ifndef USE_GTK3
@ -600,6 +603,8 @@ Snes9xWindow::Snes9xWindow (Snes9xConfig *config) :
maximized_state = 0; maximized_state = 0;
focused = 1; focused = 1;
paused_from_focus_loss = 0; paused_from_focus_loss = 0;
cr = NULL;
cairo_owned = 0;
if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), "snes9x")) if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), "snes9x"))
{ {
@ -1952,3 +1957,44 @@ Snes9xWindow::resize_to_multiple (int factor)
return; return;
} }
cairo_t *
Snes9xWindow::get_cairo (void)
{
if (cr)
return cr;
GtkWidget *drawing_area = GTK_WIDGET (this->drawing_area);
#ifndef USE_GTK3
cr = gdk_cairo_create (gtk_widget_get_window (drawing_area));
#else
GtkAllocation allocation;
gtk_widget_get_allocation (drawing_area, &allocation);
cairo_rectangle_int_t rect = { 0, 0, allocation.width, allocation.height };
cairo_region = cairo_region_create_rectangle (&rect);
gdk_drawing_context = gdk_window_begin_draw_frame (gtk_widget_get_window (drawing_area),
cairo_region);
cr = gdk_drawing_context_get_cairo_context (gdk_drawing_context);
#endif
cairo_owned = TRUE;
return cr;
}
void
Snes9xWindow::release_cairo (void)
{
if (cairo_owned)
{
#ifndef USE_GTK3
cairo_destroy (cr);
#else
gdk_window_end_draw_frame (gtk_widget_get_window (GTK_WIDGET (drawing_area)), gdk_drawing_context);
cairo_region_destroy (cairo_region);
#endif
cairo_owned = FALSE;
cr = NULL;
}
}

View File

@ -62,6 +62,9 @@ class Snes9xWindow : public GtkBuilderWindow
void resize_viewport (int width, int height); void resize_viewport (int width, int height);
void expose (void); void expose (void);
cairo_t *get_cairo (void);
void release_cairo (void);
Snes9xConfig *config; Snes9xConfig *config;
int user_pause, sys_pause; int user_pause, sys_pause;
int user_rewind; int user_rewind;
@ -78,6 +81,12 @@ class Snes9xWindow : public GtkBuilderWindow
GdkCursor *default_cursor, *empty_cursor; GdkCursor *default_cursor, *empty_cursor;
GtkDrawingArea *drawing_area; GtkDrawingArea *drawing_area;
GtkWidget *recent_menu; GtkWidget *recent_menu;
cairo_t *cr;
int cairo_owned;
#ifdef USE_GTK3
GdkDrawingContext *gdk_drawing_context;
cairo_region_t *cairo_region;
#endif
}; };
typedef struct gtk_splash_t { typedef struct gtk_splash_t {