[gtk+] API: gdk: Remove ability to render window contents



commit e62a4d8eea55b08379cd0b0fc60e9ea95dce7b5e
Author: Benjamin Otte <otte redhat com>
Date:   Sun Nov 20 11:47:32 2016 +0100

    API: gdk: Remove ability to render window contents
    
    The functions gdk_pixbuf_get_from_window() and
    gdk_cairo_set_source_window() are unreliable and depend on the windowing
    system (they work great on X11 and Win32, less so on Quartz and Wayland).
    
    With the switch to new drawing API and OpenGL, we can definitely no
    longer support a generic way to snapshot windows.
    
    People should either write windowsystem-specific code or draw their
    widgets directly - like with gtk_widget_draw() - if they need to get a
    rendering.

 docs/reference/gdk/gdk4-sections.txt |    2 -
 gdk/gdkcairo.c                       |   34 -------------
 gdk/gdkcairo.h                       |    5 --
 gdk/gdkpixbuf-drawable.c             |   89 +---------------------------------
 gdk/gdkpixbuf.h                      |    7 ---
 gdk/gdkwindow.c                      |   56 ---------------------
 6 files changed, 1 insertions(+), 192 deletions(-)
---
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt
index d009b72..48e7daf 100644
--- a/docs/reference/gdk/gdk4-sections.txt
+++ b/docs/reference/gdk/gdk4-sections.txt
@@ -213,7 +213,6 @@ gdk_screen_get_type
 <SECTION>
 <TITLE>Pixbufs</TITLE>
 <FILE>pixbufs</FILE>
-gdk_pixbuf_get_from_window
 gdk_pixbuf_get_from_surface
 </SECTION>
 
@@ -538,7 +537,6 @@ gdk_cairo_get_clip_rectangle
 gdk_cairo_get_drawing_context
 gdk_cairo_set_source_rgba
 gdk_cairo_set_source_pixbuf
-gdk_cairo_set_source_window
 gdk_cairo_rectangle
 gdk_cairo_region
 gdk_cairo_region_create_from_surface
diff --git a/gdk/gdkcairo.c b/gdk/gdkcairo.c
index 954e2c4..f1cc3c4 100644
--- a/gdk/gdkcairo.c
+++ b/gdk/gdkcairo.c
@@ -323,40 +323,6 @@ gdk_cairo_set_source_pixbuf (cairo_t         *cr,
   cairo_surface_destroy (surface);
 }
 
-/**
- * gdk_cairo_set_source_window:
- * @cr: a cairo context
- * @window: a #GdkWindow
- * @x: X coordinate of location to place upper left corner of @window
- * @y: Y coordinate of location to place upper left corner of @window
- *
- * Sets the given window as the source pattern for @cr.
- *
- * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned
- * so that the origin of @window is @x, @y. The window contains all its
- * subwindows when rendering.
- *
- * Note that the contents of @window are undefined outside of the
- * visible part of @window, so use this function with care.
- *
- * Since: 2.24
- */
-void
-gdk_cairo_set_source_window (cairo_t   *cr,
-                             GdkWindow *window,
-                             gdouble    x,
-                             gdouble    y)
-{
-  cairo_surface_t *surface;
-
-  g_return_if_fail (cr != NULL);
-  g_return_if_fail (GDK_IS_WINDOW (window));
-
-  surface = _gdk_window_ref_cairo_surface (window);
-  cairo_set_source_surface (cr, surface, x, y);
-  cairo_surface_destroy (surface);
-}
-
 /*
  * _gdk_cairo_surface_extents:
  * @surface: surface to measure
diff --git a/gdk/gdkcairo.h b/gdk/gdkcairo.h
index 1b3b961..5283842 100644
--- a/gdk/gdkcairo.h
+++ b/gdk/gdkcairo.h
@@ -42,11 +42,6 @@ void       gdk_cairo_set_source_pixbuf  (cairo_t              *cr,
                                          const GdkPixbuf      *pixbuf,
                                          gdouble               pixbuf_x,
                                          gdouble               pixbuf_y);
-GDK_AVAILABLE_IN_ALL
-void       gdk_cairo_set_source_window  (cairo_t              *cr,
-                                         GdkWindow            *window,
-                                         gdouble               x,
-                                         gdouble               y);
 
 GDK_AVAILABLE_IN_ALL
 void       gdk_cairo_rectangle          (cairo_t              *cr,
diff --git a/gdk/gdkpixbuf-drawable.c b/gdk/gdkpixbuf-drawable.c
index d2c142a..3c1e0f8 100644
--- a/gdk/gdkpixbuf-drawable.c
+++ b/gdk/gdkpixbuf-drawable.c
@@ -41,92 +41,6 @@
  * #GdkWindows and cairo surfaces.
  */
 
-
-/**
- * gdk_pixbuf_get_from_window:
- * @window: Source window
- * @src_x: Source X coordinate within @window
- * @src_y: Source Y coordinate within @window
- * @width: Width in pixels of region to get
- * @height: Height in pixels of region to get
- *
- * Transfers image data from a #GdkWindow and converts it to an RGB(A)
- * representation inside a #GdkPixbuf. In other words, copies
- * image data from a server-side drawable to a client-side RGB(A) buffer.
- * This allows you to efficiently read individual pixels on the client side.
- *
- * This function will create an RGB pixbuf with 8 bits per channel with
- * the size specified by the @width and @height arguments scaled by the
- * scale factor of @window. The pixbuf will contain an alpha channel if
- * the @window contains one.
- *
- * If the window is off the screen, then there is no image data in the
- * obscured/offscreen regions to be placed in the pixbuf. The contents of
- * portions of the pixbuf corresponding to the offscreen region are undefined.
- *
- * If the window you’re obtaining data from is partially obscured by
- * other windows, then the contents of the pixbuf areas corresponding
- * to the obscured regions are undefined.
- *
- * If the window is not mapped (typically because it’s iconified/minimized
- * or not on the current workspace), then %NULL will be returned.
- *
- * If memory can’t be allocated for the return value, %NULL will be returned
- * instead.
- *
- * (In short, there are several ways this function can fail, and if it fails
- *  it returns %NULL; so check the return value.)
- *
- * Returns: (nullable) (transfer full): A newly-created pixbuf with a
- *     reference count of 1, or %NULL on error
- */
-GdkPixbuf *
-gdk_pixbuf_get_from_window (GdkWindow *src,
-                            gint       src_x,
-                            gint       src_y,
-                            gint       width,
-                            gint       height)
-{
-  cairo_surface_t *surface;
-  cairo_surface_t *copy;
-  cairo_t *cr;
-  GdkPixbuf *dest;
-  int scale;
-
-  g_return_val_if_fail (GDK_IS_WINDOW (src), NULL);
-  g_return_val_if_fail (gdk_window_is_viewable (src), NULL);
-
-  surface = _gdk_window_ref_cairo_surface (src);
-  scale = gdk_window_get_scale_factor (src);
-
-  /* We do not know what happened to this surface outside of GDK.
-   * Especially for foreign windows, they will have been modified
-   * by external applications.
-   * So be on the safe side and:
-   */
-  cairo_surface_mark_dirty (surface);
-
-  if (cairo_surface_get_content (surface) & CAIRO_CONTENT_ALPHA)
-    copy = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width * scale, height * scale);
-  else
-    copy = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width * scale, height * scale);
-
-  cairo_surface_set_device_scale (copy, scale, scale);
-
-  cr = cairo_create (copy);
-  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-  cairo_set_source_surface (cr, surface, -src_x, -src_y);
-  cairo_paint (cr);
-  cairo_destroy (cr);
-
-  dest = gdk_pixbuf_get_from_surface (copy, 0, 0, width * scale, height * scale);
-
-  cairo_surface_destroy (copy);
-  cairo_surface_destroy (surface);
-
-  return dest;
-}
-
 static cairo_format_t
 gdk_cairo_format_for_content (cairo_content_t content)
 {
@@ -244,8 +158,7 @@ convert_no_alpha (guchar *dest_data,
  *
  * Transfers image data from a #cairo_surface_t and converts it to an RGB(A)
  * representation inside a #GdkPixbuf. This allows you to efficiently read
- * individual pixels from cairo surfaces. For #GdkWindows, use
- * gdk_pixbuf_get_from_window() instead.
+ * individual pixels from cairo surfaces.
  *
  * This function will create an RGB pixbuf with 8 bits per channel.
  * The pixbuf will contain an alpha channel if the @surface contains one.
diff --git a/gdk/gdkpixbuf.h b/gdk/gdkpixbuf.h
index 4a96b1a..215c277 100644
--- a/gdk/gdkpixbuf.h
+++ b/gdk/gdkpixbuf.h
@@ -37,13 +37,6 @@
 G_BEGIN_DECLS
 
 GDK_AVAILABLE_IN_ALL
-GdkPixbuf *gdk_pixbuf_get_from_window  (GdkWindow       *window,
-                                        gint             src_x,
-                                        gint             src_y,
-                                        gint             width,
-                                        gint             height);
-
-GDK_AVAILABLE_IN_ALL
 GdkPixbuf *gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
                                         gint             src_x,
                                         gint             src_y,
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index de2a841..ee93ade 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -3175,62 +3175,6 @@ _gdk_window_ref_cairo_surface (GdkWindow *window)
     }
 }
 
-#if 0
-/**
- * gdk_cairo_create:
- * @window: a #GdkWindow
- * 
- * Creates a Cairo context for drawing to @window.
- *
- * Note that calling cairo_reset_clip() on the resulting #cairo_t will
- * produce undefined results, so avoid it at all costs.
- *
- * Typically, this function is used to draw on a #GdkWindow out of the paint
- * cycle of the toolkit; this should be avoided, as it breaks various assumptions
- * and optimizations.
- *
- * If you are drawing on a native #GdkWindow in response to a %GDK_EXPOSE event
- * you should use gdk_window_begin_draw_frame() and gdk_drawing_context_get_cairo_context()
- * instead. GTK will automatically do this for you when drawing a widget.
- *
- * Returns: A newly created Cairo context. Free with
- *  cairo_destroy() when you are done drawing.
- * 
- * Since: 2.8
- *
- * Deprecated: 3.22: Use gdk_window_begin_draw_frame() and
- *   gdk_drawing_context_get_cairo_context() instead
- **/
-cairo_t *
-gdk_cairo_create (GdkWindow *window)
-{
-  cairo_region_t *region;
-  cairo_surface_t *surface;
-  cairo_t *cr;
-
-  g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
-
-  surface = _gdk_window_ref_cairo_surface (window);
-
-  cr = cairo_create (surface);
-
-  region = gdk_window_get_current_paint_region (window);
-  gdk_cairo_region (cr, region);
-  cairo_region_destroy (region);
-  cairo_clip (cr);
-
-  /* Assign a drawing context, if one is set; if gdk_cairo_create()
-   * is called outside of a frame drawing then this is going to be
-   * NULL.
-   */
-  gdk_cairo_set_drawing_context (cr, window->drawing_context);
-
-  cairo_surface_destroy (surface);
-
-  return cr;
-}
-#endif
-
 /* Code for dirty-region queueing
  */
 static GSList *update_windows = NULL;


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