Merge branch 'ebassi/issue-5691' into 'gtk-3-24'

gdk: Swap Cairo calls when reading back from a GdkWindow

See merge request GNOME/gtk!5727
This commit is contained in:
Matthias Clasen 2023-03-26 15:19:23 +00:00
commit b5f27d2e9c

View File

@ -51,9 +51,11 @@
* @height: Height 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) * Transfers image data from a #GdkWindow and converts it to an RGB(A)
* representation inside a #GdkPixbuf. In other words, copies * representation inside a #GdkPixbuf.
* 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. * 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 * 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 * the size specified by the @width and @height arguments scaled by the
@ -62,7 +64,8 @@
* *
* If the window is off the screen, then there is no image data in the * 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 * obscured/offscreen regions to be placed in the pixbuf. The contents of
* portions of the pixbuf corresponding to the offscreen region are undefined. * portions of the pixbuf corresponding to the offscreen region are
* undefined.
* *
* If the window youre obtaining data from is partially obscured by * If the window youre obtaining data from is partially obscured by
* other windows, then the contents of the pixbuf areas corresponding * other windows, then the contents of the pixbuf areas corresponding
@ -74,8 +77,10 @@
* If memory cant be allocated for the return value, %NULL will be returned * If memory cant be allocated for the return value, %NULL will be returned
* instead. * instead.
* *
* (In short, there are several ways this function can fail, and if it fails * In short, there are several ways this function can fail, and if it fails
* it returns %NULL; so check the return value.) * it returns %NULL; so check the return value.
*
* You should rarely, if ever, need to call this function.
* *
* Returns: (nullable) (transfer full): A newly-created pixbuf with a * Returns: (nullable) (transfer full): A newly-created pixbuf with a
* reference count of 1, or %NULL on error * reference count of 1, or %NULL on error
@ -104,16 +109,19 @@ gdk_pixbuf_get_from_window (GdkWindow *src,
* by external applications. * by external applications.
* *
* So be on the safe side and: * So be on the safe side and:
* - flush the Cairo state
* - mark the surface as dirty, in case the GdkWindow was * - mark the surface as dirty, in case the GdkWindow was
* created from a foreign X11 surface * created from a foreign X11 surface
* - flush the Cairo state *
* THE ORDER IS IMPORTANT. DO NOT CHANGE IT.
* *
* For reference, see: * For reference, see:
* - https://bugzilla.gnome.org/show_bug.cgi?id=754952 * - https://bugzilla.gnome.org/show_bug.cgi?id=754952
* - https://gitlab.gnome.org/GNOME/gtk/-/issues/4456 * - https://gitlab.gnome.org/GNOME/gtk/-/issues/4456
* - https://gitlab.gnome.org/GNOME/gtk/-/issues/5691
*/ */
cairo_surface_mark_dirty (surface);
cairo_surface_flush (surface); cairo_surface_flush (surface);
cairo_surface_mark_dirty (surface);
if (cairo_surface_get_content (surface) & CAIRO_CONTENT_ALPHA) if (cairo_surface_get_content (surface) & CAIRO_CONTENT_ALPHA)
copy = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width * scale, height * scale); copy = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width * scale, height * scale);