diff options
author | Benjamin Otte <otte@redhat.com> | 2017-11-04 20:23:33 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2017-11-05 00:07:17 +0100 |
commit | 70846c85b32cd31c2c5adba301c24f9684ad7f60 (patch) | |
tree | 0b0990907daaeb62441179a081c061637544db65 /gdk | |
parent | b4b7c2727438a0a80b0a187aba06267b495becd4 (diff) | |
download | gtk+-70846c85b32cd31c2c5adba301c24f9684ad7f60.tar.gz |
window: Make icons GdkTextures
Cairo surfaces are bad, mkay?
Diffstat (limited to 'gdk')
-rw-r--r-- | gdk/gdkwindow.c | 6 | ||||
-rw-r--r-- | gdk/win32/gdkwindow-win32.c | 40 | ||||
-rw-r--r-- | gdk/x11/gdkwindow-x11.c | 91 |
3 files changed, 51 insertions, 86 deletions
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index c7c2f40d5b..6084576292 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -6441,7 +6441,7 @@ gdk_window_get_event_compression (GdkWindow *window) /** * gdk_window_set_icon_list: * @window: The #GdkWindow toplevel window to set the icon of. - * @surfaces: (transfer none) (element-type cairo_surface_t): + * @surfaces: (transfer none) (element-type GdkTexture): * A list of image surfaces, of different sizes. * * Sets a list of icons for the window. One of these will be used @@ -6456,9 +6456,9 @@ gdk_window_get_event_compression (GdkWindow *window) */ void gdk_window_set_icon_list (GdkWindow *window, - GList *surfaces) + GList *textures) { - GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, surfaces); + GDK_WINDOW_IMPL_GET_CLASS (window->impl)->set_icon_list (window, textures); } /** diff --git a/gdk/win32/gdkwindow-win32.c b/gdk/win32/gdkwindow-win32.c index 97f86fa810..24cd94e1a8 100644 --- a/gdk/win32/gdkwindow-win32.c +++ b/gdk/win32/gdkwindow-win32.c @@ -2251,9 +2251,9 @@ gdk_win32_window_set_focus_on_map (GdkWindow *window, static void gdk_win32_window_set_icon_list (GdkWindow *window, - GList *surfaces) + GList *textures) { - cairo_surface_t *surface, *big_surface, *small_surface; + GdkTexture *big_texture, *small_texture; GdkPixbuf *big_pixbuf, *small_pixbuf; gint big_diff, small_diff; gint big_w, big_h, small_w, small_h; @@ -2264,7 +2264,7 @@ gdk_win32_window_set_icon_list (GdkWindow *window, g_return_if_fail (GDK_IS_WINDOW (window)); - if (GDK_WINDOW_DESTROYED (window) || surfaces == NULL) + if (GDK_WINDOW_DESTROYED (window) || textures == NULL) return; impl = GDK_WINDOW_IMPL_WIN32 (window->impl); @@ -2276,48 +2276,42 @@ gdk_win32_window_set_icon_list (GdkWindow *window, small_h = GetSystemMetrics (SM_CYSMICON); /* find closest sized icons in the list */ - big_surface = NULL; - small_surface = NULL; + big_texture = NULL; + small_texture = NULL; big_diff = 0; small_diff = 0; - while (surfaces) + for (l = textures; l; l = l->next) { - surface = surfaces->data; - w = cairo_image_surface_get_width (surface); - h = cairo_image_surface_get_height (surface); + texture = l->data; + w = gdk_texture_get_width (texture); + h = gdk_texture_get_height (texture); dw = ABS (w - big_w); dh = ABS (h - big_h); diff = dw*dw + dh*dh; - if (big_surface == NULL || diff < big_diff) + if (big_texture == NULL || diff < big_diff) { - big_surface = surface; + big_texture = texture; big_diff = diff; } dw = ABS (w - small_w); dh = ABS (h - small_h); diff = dw*dw + dh*dh; - if (small_surface == NULL || diff < small_diff) + if (small_texture == NULL || diff < small_diff) { - small_surface = surface; + small_texture = texture; small_diff = diff; } - surfaces = surfaces->next; + textures = textures->next; } /* Create the icons */ - big_pixbuf = gdk_pixbuf_get_from_surface (big_surface, 0, 0, - cairo_image_surface_get_width (big_surface), - cairo_image_surface_get_height (big_surface)); - big_hicon = _gdk_win32_pixbuf_to_hicon (big_pixbuf); + big_hicon = gdk_win32_texture_to_hicon (big_texture); g_object_unref (big_pixbuf); - small_pixbuf = gdk_pixbuf_get_from_surface (small_surface, 0, 0, - cairo_image_surface_get_width (small_surface), - cairo_image_surface_get_height (small_surface)); - small_hicon = _gdk_win32_pixbuf_to_hicon (small_pixbuf); + small_hicon = _gdk_win32_texture_to_hicon (small_texture); g_object_unref (small_pixbuf); /* Set the icons */ @@ -2337,7 +2331,7 @@ gdk_win32_window_set_icon_list (GdkWindow *window, static void gdk_win32_window_set_icon_name (GdkWindow *window, - const gchar *name) + const gchar *name) { /* In case I manage to confuse this again (or somebody else does): * Please note that "icon name" here really *does* mean the name or diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index ddd08b1fb4..cfd7273f00 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -38,6 +38,7 @@ #include "gdkdisplay-x11.h" #include "gdkglcontext-x11.h" #include "gdkprivate-x11.h" +#include "gdktextureprivate.h" #include "gdk-private.h" #include <stdlib.h> @@ -3115,7 +3116,7 @@ gdk_window_update_icon (GdkWindow *window, GList *icon_list) { GdkToplevelX11 *toplevel; - cairo_surface_t *best_icon; + GdkTexture *best_icon; GList *tmp_list; int best_size; @@ -3139,18 +3140,18 @@ gdk_window_update_icon (GdkWindow *window, best_icon = NULL; for (tmp_list = icon_list; tmp_list; tmp_list = tmp_list->next) { - cairo_surface_t *surface = tmp_list->data; + GdkTexture *texture = tmp_list->data; int this; /* average width and height - if someone passes in a rectangular * icon they deserve what they get. */ - this = cairo_image_surface_get_width (surface) + cairo_image_surface_get_height (surface); + this = gdk_texture_get_width (texture) + gdk_texture_get_height (texture); this /= 2; if (best_icon == NULL) { - best_icon = surface; + best_icon = texture; best_size = this; } else @@ -3162,7 +3163,7 @@ gdk_window_update_icon (GdkWindow *window, (ABS (best_size - IDEAL_SIZE) < ABS (this - IDEAL_SIZE))) { - best_icon = surface; + best_icon = texture; best_size = this; } } @@ -3170,18 +3171,21 @@ gdk_window_update_icon (GdkWindow *window, if (best_icon) { - int width = cairo_image_surface_get_width (best_icon); - int height = cairo_image_surface_get_height (best_icon); + int width = gdk_texture_get_width (best_icon); + int height = gdk_texture_get_height (best_icon); + cairo_surface_t *surface; cairo_t *cr; toplevel->icon_pixmap = gdk_x11_window_create_pixmap_surface (window, width, height); + surface = gdk_texture_download_surface (best_icon); + cr = cairo_create (toplevel->icon_pixmap); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - cairo_set_source_surface (cr, best_icon, 0, 0); - if (cairo_surface_get_content (best_icon) == CAIRO_CONTENT_COLOR_ALPHA) + cairo_set_source_surface (cr, surface, 0, 0); + if (cairo_surface_get_content (surface) == CAIRO_CONTENT_COLOR_ALPHA) { /* Saturate the image, so it has bilevel alpha */ cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA); @@ -3193,18 +3197,20 @@ gdk_window_update_icon (GdkWindow *window, cairo_paint (cr); cairo_destroy (cr); - if (cairo_surface_get_content (best_icon) == CAIRO_CONTENT_COLOR_ALPHA) + if (cairo_surface_get_content (surface) == CAIRO_CONTENT_COLOR_ALPHA) { toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window, width, height); cr = cairo_create (toplevel->icon_mask); - cairo_set_source_surface (cr, best_icon, 0, 0); + cairo_set_source_surface (cr, surface, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); cairo_destroy (cr); } + + cairo_surface_destroy (surface); } update_wm_hints (window, FALSE); @@ -3212,19 +3218,16 @@ gdk_window_update_icon (GdkWindow *window, static void gdk_x11_window_set_icon_list (GdkWindow *window, - GList *surfaces) + GList *textures) { gulong *data; - guchar *pixels; gulong *p; gint size; GList *l; - cairo_surface_t *surface; - gint width, height, stride; - gint x, y; + gint width, height; + GdkTexture *texture; GdkDisplay *display; gint n; - cairo_format_t format; if (GDK_WINDOW_DESTROYED (window) || !WINDOW_IS_TOPLEVEL_OR_FOREIGN (window)) @@ -3234,16 +3237,12 @@ gdk_x11_window_set_icon_list (GdkWindow *window, size = 0; n = 0; - for (l = surfaces; l != NULL; l = l->next) + for (l = textures; l != NULL; l = l->next) { - surface = l->data; + texture = l->data; - width = cairo_image_surface_get_width (surface); - height = cairo_image_surface_get_height (surface); - format = cairo_image_surface_get_format (surface); - - if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24) - continue; + width = gdk_texture_get_width (texture); + height = gdk_texture_get_height (texture); /* silently ignore overlarge icons */ if (size + 2 + width * height > GDK_SELECTION_MAX_SIZE(display)) @@ -3256,47 +3255,19 @@ gdk_x11_window_set_icon_list (GdkWindow *window, data = g_malloc (size * sizeof (gulong)); p = data; - for (l = surfaces; l != NULL && n > 0; l = l->next) + for (l = textures; l != NULL && n > 0; l = l->next) { - surface = l->data; - - width = cairo_image_surface_get_width (surface); - height = cairo_image_surface_get_height (surface); - stride = cairo_image_surface_get_stride (surface); - format = cairo_image_surface_get_format (surface); + texture = l->data; - if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24) - continue; + width = gdk_texture_get_width (texture); + height = gdk_texture_get_height (texture); *p++ = width; *p++ = height; - pixels = cairo_image_surface_get_data (surface); - - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - guchar r, g, b, a; - a = 255; -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - if (format == CAIRO_FORMAT_ARGB32) - a = pixels[y*stride + x*4 + 3]; - r = pixels[y*stride + x*4 + 2]; - g = pixels[y*stride + x*4 + 1]; - b = pixels[y*stride + x*4 + 0]; -#else - if (format == CAIRO_FORMAT_ARGB32) - a = pixels[y*stride + x*4 + 0]; - r = pixels[y*stride + x*4 + 1]; - g = pixels[y*stride + x*4 + 2]; - b = pixels[y*stride + x*4 + 3]; -#endif - - *p++ = a << 24 | r << 16 | g << 8 | b ; - } - } + gdk_texture_download (texture, (guchar *) p, width * 4); + p += width * height; n--; } @@ -3318,7 +3289,7 @@ gdk_x11_window_set_icon_list (GdkWindow *window, g_free (data); - gdk_window_update_icon (window, surfaces); + gdk_window_update_icon (window, textures); } static gboolean |