[gtkmm] Add Gdk::Cairo::create_surface_from_pixbuf()



commit 0571861bff2fee3fafc3def99cf6947ea1211295
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Wed Oct 18 09:46:26 2017 +0200

    Add Gdk::Cairo::create_surface_from_pixbuf()
    
    and Gdk::Cairo::get_clip_rectangle(), create_region_from_surface(),
    draw_from_gl(), upload_surface_to_gl(). Bug 788533

 gdk/gdkmm/general.cc |   37 +++++++++++++++++
 gdk/gdkmm/general.h  |  110 +++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 142 insertions(+), 5 deletions(-)
---
diff --git a/gdk/gdkmm/general.cc b/gdk/gdkmm/general.cc
index 47f65a4..a2af944 100644
--- a/gdk/gdkmm/general.cc
+++ b/gdk/gdkmm/general.cc
@@ -51,6 +51,43 @@ 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::make_refptr_for_instance(new 
::Cairo::Region(gdk_cairo_region_create_from_surface(surface->cobj()), true));
+}
+
+::Cairo::RefPtr< ::Cairo::Surface> create_surface_from_pixbuf(const Glib::RefPtr<const Gdk::Pixbuf>& pixbuf,
+  int scale, const Glib::RefPtr<Gdk::Window>& for_window)
+{
+  return ::Cairo::make_refptr_for_instance(new ::Cairo::Surface(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);
+}
+
+void upload_surface_to_gl(const ::Cairo::RefPtr< ::Cairo::Surface>& surface,
+  int target, int width, int height, const Glib::RefPtr<GLContext>& context)
+{
+  gdk_cairo_surface_upload_to_gl(surface->cobj(), target, width, height,
+    context ? context->gobj() : nullptr);
+}
+
 } //namespace Cairo
 
 } //namespace Gdk
diff --git a/gdk/gdkmm/general.h b/gdk/gdkmm/general.h
index c590b9a..f189f17 100644
--- a/gdk/gdkmm/general.h
+++ b/gdk/gdkmm/general.h
@@ -21,8 +21,11 @@
 #include <gdkmm/pixbuf.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
 {
@@ -40,8 +43,9 @@ namespace Cairo
  */
 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::Pattern::Extend::NONE and is aligned
+ * so that the origin of @a 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.
@@ -49,9 +53,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.
  *
@@ -71,6 +74,103 @@ 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,92}
+ */
+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,92}
+ */
+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,92}
+ */
+::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,92}
+ */
+::Cairo::RefPtr< ::Cairo::Surface> 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,92}
+ */
+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);
+
+/** Uploads the contents of a %Cairo surface to a GL texture target.
+ *
+ * @param surface A %Cairo surface.
+ * @param target A GL texture target.
+ * @param width The width of the texture @a target.
+ * @param height The height of the texture @a target.
+ * @param context A Gdk::GLContext, or an empty Glib::RefPtr<Gdk::GLContext>
+ *        to use the currently bound context.
+ *
+ * @newin{3,92}
+ */
+void upload_surface_to_gl(const ::Cairo::RefPtr< ::Cairo::Surface>& surface,
+  int target, int width, int height, const Glib::RefPtr<GLContext>& context = {});
+
 } //namespace Cairo
 
 } //namespace Gdk


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