diff options
author | Mauro Carvalho Chehab <mchehab+samsung@kernel.org> | 2018-09-05 08:31:35 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab+samsung@kernel.org> | 2018-09-05 09:23:32 -0300 |
commit | 98a4baa241cfd710e27d51871f17bee3f60930cc (patch) | |
tree | 39d58498546ae0e04e4fd3a60f525bd023c964a8 | |
parent | b7c0e34d931af0bf04437e22b2490bee671e123f (diff) |
callbacks: Optimize cairo logic for Gtk 3
With Gtk 3, we don't need to implement the funtion
gdk_cairo_surface_create_from_pixbuf() ourselves, as it is
available there. So, just call the right function.
Also, with Gtk 3.22 and above, the old way of calling
gdk_cairo_create() is obsolete, as all windows already have
it. So, instead, just instance it.
That supresses a deprecated function warning:
callbacks.c:604:5: warning: ‘gdk_cairo_create’ is deprecated: Use 'gdk_window_begin_draw_frame() and gdk_drawing_context_get_cairo_context()' instead [-Wdeprecated-declarations]
cr = gdk_cairo_create(window);
^~
In file included from /usr/include/gtk-3.0/gdk/gdk.h:33,
from /usr/include/gtk-3.0/gtk/gtk.h:30,
from v4l.h:24,
from callbacks.h:4,
from callbacks.c:1:
/usr/include/gtk-3.0/gdk/gdkcairo.h:35:12: note: declared here
cairo_t * gdk_cairo_create (GdkWindow *window);
^~~~~~~~~~~~~~~~
While here, add a missing surface destroy in order to avoid
possible memory leaks.
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
-rw-r--r-- | src/callbacks.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/callbacks.c b/src/callbacks.c index d731b86..f8a378e 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -500,6 +500,9 @@ static void apply_filters(cam_t *cam) static cairo_surface_t *create_from_pixbuf(const GdkPixbuf *pixbuf, GdkWindow *for_window) { +#if GTK_MAJOR_VERSION >= 3 + return gdk_cairo_surface_create_from_pixbuf(pixbuf, 1, for_window); +#else gint width = gdk_pixbuf_get_width(pixbuf); gint height = gdk_pixbuf_get_height(pixbuf); guchar *gdk_pixels = gdk_pixbuf_get_pixels(pixbuf); @@ -564,6 +567,7 @@ static cairo_surface_t *create_from_pixbuf(const GdkPixbuf *pixbuf, cairo_surface_mark_dirty(surface); return surface; +#endif } static void show_buffer(cam_t *cam) @@ -579,6 +583,10 @@ static void show_buffer(cam_t *cam) .x = 0, .y = 0, .width = cam->width, .height = cam->height }; +#if GTK_MAJOR_VERSION >= 3 && GTK_MINOR_VERSION >= 22 + GdkDrawingContext *context; + cairo_region_t *region; +#endif /* * refer the frame @@ -601,13 +609,27 @@ static void show_buffer(cam_t *cam) window = gtk_widget_get_window(widget); surface = create_from_pixbuf(pb, window); + +#if GTK_MAJOR_VERSION >= 3 && GTK_MINOR_VERSION >= 22 + region = cairo_region_create(); + context = gdk_window_begin_draw_frame(window, region); + cr = gdk_drawing_context_get_cairo_context(context); +#else cr = gdk_cairo_create(window); - cairo_set_source_surface(cr, surface, 0, 0); +#endif + cairo_set_source_surface(cr, surface, 0, 0); gdk_cairo_rectangle(cr, &rect); - cairo_fill(cr); + +#if GTK_MAJOR_VERSION >= 3 && GTK_MINOR_VERSION >= 22 + gdk_window_end_draw_frame(window, context); +#else cairo_destroy(cr); + cairo_region_destroy(region); +#endif + + cairo_surface_destroy(surface); frames++; frames2++; |