[gtk+/gtk-2-24] Bug 676362 - _gdk_quartz_image_copy_to_image always returns black...
- From: Kristian Rietveld <kristian src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-2-24] Bug 676362 - _gdk_quartz_image_copy_to_image always returns black...
- Date: Mon, 11 Jun 2012 19:11:57 +0000 (UTC)
commit 2f706868ff3c4a3d25aa85e233590161a55c9657
Author: Daniel Sabo <DanielSabo gmail com>
Date: Mon Jun 11 21:06:58 2012 +0200
Bug 676362 - _gdk_quartz_image_copy_to_image always returns black...
Implement a special case for the root window, which has to be handled
differently on OS X.
Contains some bit fiddling corrections by Kristian Rietveld.
gdk/quartz/gdkimage-quartz.c | 69 ++++++++++++++++++++++++++++-------------
1 files changed, 47 insertions(+), 22 deletions(-)
---
diff --git a/gdk/quartz/gdkimage-quartz.c b/gdk/quartz/gdkimage-quartz.c
index c8e37bc..ce032aa 100644
--- a/gdk/quartz/gdkimage-quartz.c
+++ b/gdk/quartz/gdkimage-quartz.c
@@ -135,39 +135,64 @@ _gdk_quartz_image_copy_to_image (GdkDrawable *drawable,
guchar *data;
int x, y;
NSSize size;
-
- view = GDK_WINDOW_IMPL_QUARTZ (drawable)->view;
-
- /* We return the image even if we can't copy to it. */
- if (![view lockFocusIfCanDraw])
- return image;
-
+
rect = NSMakeRect (src_x, src_y, width, height);
+
+ if (GDK_WINDOW_IMPL_QUARTZ (drawable) == GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (_gdk_root)->impl))
+ {
+ /* Special case for the root window. */
+ CGImageRef root_image_ref = CGWindowListCreateImage (rect,
+ kCGWindowListOptionOnScreenOnly,
+ kCGNullWindowID,
+ kCGWindowImageDefault);
+ rep = [[NSBitmapImageRep alloc] initWithCGImage: root_image_ref];
+ CGImageRelease (root_image_ref);
+ }
+ else
+ {
+ view = GDK_WINDOW_IMPL_QUARTZ (drawable)->view;
- rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect: rect];
- [view unlockFocus];
+ /* We return the image even if we can't copy to it. */
+ if (![view lockFocusIfCanDraw])
+ return image;
+
+ rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect: rect];
+ [view unlockFocus];
+ }
data = [rep bitmapData];
size = [rep size];
for (y = 0; y < size.height; y++)
- {
- guchar *src = data + y * [rep bytesPerRow];
+ {
+ guchar *src = data + y * [rep bytesPerRow];
- for (x = 0; x < size.width; x++)
- {
- gint32 pixel;
+ for (x = 0; x < size.width; x++)
+ {
+ gint32 pixel;
- if (image->byte_order == GDK_LSB_FIRST)
- pixel = src[0] << 8 | src[1] << 16 |src[2] << 24;
- else
- pixel = src[0] << 16 | src[1] << 8 |src[2];
+ if ([rep hasAlpha])
+ {
+ if (image->byte_order == GDK_LSB_FIRST)
+ pixel = src[3] | src[2] << 8 | src[1] << 16 | src[0] << 24;
+ else
+ pixel = src[3] << 24 | src[2] << 16 | src[1] << 8 | src[0];
- src += 3;
+ src += [rep bitsPerPixel] / 8;
+ }
+ else
+ {
+ if (image->byte_order == GDK_LSB_FIRST)
+ pixel = src[3] | src[2] << 8 |src[1] << 16;
+ else
+ pixel = src[3] << 16 | src[2] << 8 |src[1];
- gdk_image_put_pixel (image, dest_x + x, dest_y + y, pixel);
- }
- }
+ src += [rep bitsPerPixel] / 8;
+ }
+
+ gdk_image_put_pixel (image, dest_x + x, dest_y + y, pixel);
+ }
+ }
[rep release];
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]