[gtkmm/gtkmm-3-24] Add Gdk::Cairo::create_surface_from_pixbuf()



commit c6aafd855371c7843f058090fb9f1927560ad7c5
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Tue Aug 21 16:06:16 2018 +0200

    Add Gdk::Cairo::create_surface_from_pixbuf()
    
    and Gdk::Cairo::get_clip_rectangle(), create_region_from_surface(),
    draw_from_gl(). Fixes #25

 gdk/gdkmm/general.cc | 31 ++++++++++++++++-
 gdk/gdkmm/general.h  | 96 +++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 121 insertions(+), 6 deletions(-)
---
diff --git a/gdk/gdkmm/general.cc b/gdk/gdkmm/general.cc
index 6baca46c..038cd5e0 100644
--- a/gdk/gdkmm/general.cc
+++ b/gdk/gdkmm/general.cc
@@ -74,7 +74,6 @@ void set_source_pixbuf(const ::Cairo::RefPtr< ::Cairo::Context >& context, const
   gdk_cairo_set_source_pixbuf(context->cobj(), pixbuf->gobj(), pixbuf_x, pixbuf_y);
 }
 
-
 void add_rectangle_to_path(const ::Cairo::RefPtr< ::Cairo::Context >& context, const Gdk::Rectangle& 
rectangle)
 {
   gdk_cairo_rectangle(context->cobj(), const_cast<GdkRectangle*>(rectangle.gobj()));
@@ -85,6 +84,36 @@ void add_region_to_path(const ::Cairo::RefPtr< ::Cairo::Context >& context, cons
   gdk_cairo_region(context->cobj(), (region ? region->cobj() : nullptr));
 }
 
+bool get_clip_rectangle(const ::Cairo::RefPtr< ::Cairo::Context >& context, Gdk::Rectangle& rectangle)
+{
+  return gdk_cairo_get_clip_rectangle(context->cobj(), rectangle.gobj());
+}
+
+bool get_clip_rectangle(const ::Cairo::RefPtr< ::Cairo::Context >& context)
+{
+  return gdk_cairo_get_clip_rectangle(context->cobj(), nullptr);
+}
+
+::Cairo::RefPtr< ::Cairo::Region> create_region_from_surface(const ::Cairo::RefPtr< ::Cairo::Surface>& 
surface)
+{
+  return ::Cairo::RefPtr< ::Cairo::Region>(new 
::Cairo::Region(gdk_cairo_region_create_from_surface(surface->cobj()), true));
+}
+
+::Cairo::RefPtr< ::Cairo::ImageSurface> create_surface_from_pixbuf(const Glib::RefPtr<const Gdk::Pixbuf>& 
pixbuf,
+  int scale, const Glib::RefPtr<Gdk::Window>& for_window)
+{
+  return ::Cairo::RefPtr< ::Cairo::ImageSurface>(new 
::Cairo::ImageSurface(gdk_cairo_surface_create_from_pixbuf(
+    pixbuf->gobj(), scale, for_window ? for_window->gobj() : nullptr), true));
+}
+
+void draw_from_gl(const ::Cairo::RefPtr< ::Cairo::Context >& context,
+  const Glib::RefPtr<Gdk::Window>& window, int source, int source_type,
+  int buffer_scale, int x, int y, int width, int height)
+{
+  gdk_cairo_draw_from_gl(context->cobj(), window->gobj(), source, source_type,
+    buffer_scale, x, y, width, height);
+}
+
 } //namespace Cairo
 
 } //namespace Gdk
diff --git a/gdk/gdkmm/general.h b/gdk/gdkmm/general.h
index b9313748..73a567e3 100644
--- a/gdk/gdkmm/general.h
+++ b/gdk/gdkmm/general.h
@@ -22,8 +22,11 @@
 #include <gdkmm/color.h>
 #include <gdkmm/rectangle.h>
 #include <gdkmm/rgba.h>
+#include <gdkmm/glcontext.h>
+#include <gdkmm/window.h>
 #include <cairomm/context.h>
 #include <cairomm/region.h>
+#include <cairomm/surface.h>
 
 namespace Gdk
 {
@@ -74,8 +77,9 @@ void set_source_color(const ::Cairo::RefPtr< ::Cairo::Context >& context, const
  */
 void set_source_rgba(const ::Cairo::RefPtr< ::Cairo::Context >& context, const Gdk::RGBA& color);
 
-
-/** Sets the given pixbuf as the source pattern for the Cairo context. The pattern has an extend mode of 
CAIRO_EXTEND_NONE and is aligned so that the origin of pixbuf is pixbuf_x, pixbuf_y.
+/** Sets the given pixbuf as the source pattern for the %Cairo context.
+ * The pattern has an extend mode of Cairo::EXTEND_NONE and is aligned
+ * so that the origin of pixbuf is @a pixbuf_x, @a pixbuf_y.
  * @param context The cairo context.
  * @param pixbuf A Gdk::Pixbuf
  * @param pixbuf_x X coordinate of location to place upper left corner of pixbuf.
@@ -83,9 +87,8 @@ void set_source_rgba(const ::Cairo::RefPtr< ::Cairo::Context >& context, const G
  *
  * @newin{2,10}
  */
-void set_source_pixbuf(const ::Cairo::RefPtr< ::Cairo::Context >& context, const Glib::RefPtr<Gdk::Pixbuf>& 
pixbuf, double pixbuf_x = 0, double pixbuf_y = 0);
-
-//TODO: Wrap gdk_cairo_set_source_window()?
+void set_source_pixbuf(const ::Cairo::RefPtr< ::Cairo::Context >& context,
+  const Glib::RefPtr<Gdk::Pixbuf>& pixbuf, double pixbuf_x = 0, double pixbuf_y = 0);
 
 /** Adds the given rectangle to the current path of the context.
  *
@@ -105,6 +108,89 @@ void add_rectangle_to_path(const ::Cairo::RefPtr< ::Cairo::Context >& context, c
  */
 void add_region_to_path(const ::Cairo::RefPtr< ::Cairo::Context >& context, const ::Cairo::RefPtr< 
::Cairo::Region>& region);
 
+/** This is a convenience function around Cairo::Context::get_clip_extents().
+ * It rounds the clip extents to integer coordinates and returns
+ * a boolean indicating if a clip area exists.
+ *
+ * @param context A cairo context.
+ * @param[out] rectangle Return location for the clip rectangle.
+ * @returns <tt>true</tt> if a clip rectangle exists, <tt>false</tt> if all
+ *          of @a context is clipped and all drawing can be skipped.
+ *
+ * @newin{3,24}
+ */
+bool get_clip_rectangle(const ::Cairo::RefPtr< ::Cairo::Context >& context, Gdk::Rectangle& rectangle);
+
+/** This is a convenience function around Cairo::Context::get_clip_extents().
+ *
+ * @param context A cairo context.
+ * @returns <tt>true</tt> if a clip rectangle exists, <tt>false</tt> if all
+ *          of @a context is clipped and all drawing can be skipped.
+ *
+ * @newin{3,24}
+ */
+bool get_clip_rectangle(const ::Cairo::RefPtr< ::Cairo::Context >& context);
+
+/** Creates a region that covers the area where the given
+ * @a surface is more than 50% opaque.
+ *
+ * This function takes into account device offsets that might be
+ * set with Cairo::Surface::set_device_offset().
+ *
+ * @param surface A cairo surface.
+ * @returns A cairo region.
+ *
+ * @newin{3,24}
+ */
+::Cairo::RefPtr< ::Cairo::Region> create_region_from_surface(const ::Cairo::RefPtr< ::Cairo::Surface>& 
surface);
+
+/** Creates an image surface with the same contents as the pixbuf.
+ *
+ * @param pixbuf A Gdk::Pixbuf.
+ * @param scale The scale of the new surface, or 0 to use same as @a for_window.
+ * @param for_window The window this will be drawn to, or an empty
+ *        Glib::RefPtr<Gdk::Window> if none.
+ * @returns A new cairo surface.
+ *
+ * @newin{3,24}
+ */
+::Cairo::RefPtr< ::Cairo::ImageSurface> create_surface_from_pixbuf(const Glib::RefPtr<const Gdk::Pixbuf>& 
pixbuf,
+  int scale, const Glib::RefPtr<Gdk::Window>& for_window = {});
+
+/** This is the main way to draw GL content in gtkmm.
+ * It takes a render buffer ID (@a source_type == GL_RENDERBUFFER) or a texture id
+ * (@a source_type == GL_TEXTURE) and draws it onto @a context with an OVER operation,
+ * respecting the current clip. The top left corner of the rectangle specified by
+ * @a x, @a y, @a width and @a height will be drawn at the current (0,0) position
+ * of the cairo context.
+ *
+ * This will work for *all* cairo contexts, as long as @a window is realized, but the
+ * fallback implementation that reads back the pixels from the buffer may be
+ * used in the general case. In the case of direct drawing to a window with
+ * no special effects applied to @a context it will however use a more efficient
+ * approach.
+ *
+ * For GL_RENDERBUFFER the code will always fall back to software for buffers
+ * with alpha components, so make sure you use GL_TEXTURE if using alpha.
+ *
+ * Calling this may change the current GL context.
+ *
+ * @param context A cairo context.
+ * @param window The window we're rendering for (not necessarily into).
+ * @param source The GL ID of the source buffer.
+ * @param source_type The type of the @a source.
+ * @param buffer_scale The scale-factor that the @a source buffer is allocated for.
+ * @param x The source x position in @a source to start copying from in GL coordinates.
+ * @param y The source y position in @a source to start copying from in GL coordinates.
+ * @param width The width of the region to draw.
+ * @param height The height of the region to draw.
+ *
+ * @newin{3,24}
+ */
+void draw_from_gl(const ::Cairo::RefPtr< ::Cairo::Context >& context,
+  const Glib::RefPtr<Gdk::Window>& window, int source, int source_type,
+  int buffer_scale, int x, int y, int width, int height);
+
 } //namespace Cairo
 
 } //namespace Gdk


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]