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;
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);
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 */
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
#include "gdkdisplay-x11.h"
#include "gdkglcontext-x11.h"
#include "gdkprivate-x11.h"
+#include "gdktextureprivate.h"
#include "gdk-private.h"
#include <stdlib.h>
GList *icon_list)
{
GdkToplevelX11 *toplevel;
- cairo_surface_t *best_icon;
+ GdkTexture *best_icon;
GList *tmp_list;
int best_size;
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
(ABS (best_size - IDEAL_SIZE) <
ABS (this - IDEAL_SIZE)))
{
- best_icon = surface;
+ best_icon = texture;
best_size = this;
}
}
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);
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);
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))
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))
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--;
}
g_free (data);
- gdk_window_update_icon (window, surfaces);
+ gdk_window_update_icon (window, textures);
}
static gboolean
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
window_props[PROP_ICON] =
- g_param_spec_boxed ("icon",
- P_("Icon"),
- P_("Icon for this window"),
- CAIRO_GOBJECT_TYPE_SURFACE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+ g_param_spec_object ("icon",
+ P_("Icon"),
+ P_("Icon for this window"),
+ GDK_TYPE_TEXTURE,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkWindow:mnemonics-visible:
break;
case PROP_ICON:
gtk_window_set_icon (window,
- g_value_get_boxed (value));
+ g_value_get_object (value));
break;
case PROP_ICON_NAME:
gtk_window_set_icon_name (window, g_value_get_string (value));
g_value_set_boolean (value, priv->destroy_with_parent);
break;
case PROP_ICON:
- g_value_set_boxed (value, gtk_window_get_icon (window));
+ g_value_set_object (value, gtk_window_get_icon (window));
break;
case PROP_ICON_NAME:
g_value_set_string (value, gtk_window_get_icon_name (window));
{
GtkWindowPrivate *priv = window->priv;
GList *list;
-
GtkIconTheme *icon_theme;
- cairo_surface_t *icon;
+ GdkTexture *icon;
+ GdkPixbuf *pixbuf;
gint *sizes;
gint i;
* fixed size of 48.
*/
if (sizes[i] == -1)
- icon = gtk_icon_theme_load_surface (icon_theme, name,
- 48, priv->scale,
- _gtk_widget_get_window (GTK_WIDGET (window)),
- 0, NULL);
+ pixbuf = gtk_icon_theme_load_icon_for_scale (icon_theme, name,
+ 48, priv->scale,
+ 0, NULL);
else
- icon = gtk_icon_theme_load_surface (icon_theme, name,
- sizes[i], priv->scale,
- _gtk_widget_get_window (GTK_WIDGET (window)),
- 0, NULL);
- if (icon)
- list = g_list_append (list, icon);
+ pixbuf = gtk_icon_theme_load_icon_for_scale (icon_theme, name,
+ sizes[i], priv->scale,
+ 0, NULL);
+ if (pixbuf)
+ {
+ icon = gdk_texture_new_for_pixbuf (pixbuf);
+ list = g_list_append (list, icon);
+ g_object_unref (pixbuf);
+ }
}
g_free (sizes);
if (info->using_themed_icon)
{
- g_list_free_full (icon_list, (GDestroyNotify)cairo_surface_destroy);
+ g_list_free_full (icon_list, g_object_unref);
}
}
-static cairo_surface_t *
-icon_from_list (GtkWindow *window,
- GList *list,
- gint size,
- gint scale)
+static GdkTexture *
+icon_from_list (GList *list,
+ gint size)
{
- cairo_surface_t *best;
- cairo_surface_t *surface;
+ GdkTexture *texture;
+ cairo_surface_t *source, *target;
+ cairo_t *cr;
GList *l;
- best = NULL;
- /* Look for exact match */
+ /* Look for possible match */
for (l = list; l; l = l->next)
{
- surface = list->data;
- double x_scale;
-
- cairo_surface_get_device_scale (surface, &x_scale, NULL);
+ texture = list->data;
- if (cairo_image_surface_get_width (surface) == size &&
- x_scale == scale)
- {
- best = cairo_surface_reference (surface);
- break;
- }
- }
-
- if (best != NULL)
- return best;
-
- /* Ignore scale */
- for (l = list; l; l = l->next)
- {
- surface = list->data;
- double x_scale;
-
- cairo_surface_get_device_scale (surface, &x_scale, NULL);
-
- if (cairo_image_surface_get_width (surface) * x_scale <= size)
- {
- best = cairo_surface_reference (surface);
- break;
- }
- }
-
- if (best == NULL && list != NULL)
- best = cairo_surface_reference ((cairo_surface_t *)list->data);
-
+ if (gdk_texture_get_width (texture) <= size)
+ return g_object_ref (texture);
+ }
+
+ /* scale larger match down */
+ texture = list->data;
+ source = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ gdk_texture_get_width (texture),
+ gdk_texture_get_height (texture));
+ gdk_texture_download (texture,
+ cairo_image_surface_get_data (source),
+ cairo_image_surface_get_stride (source));
+ cairo_surface_mark_dirty (source);
+
+ target = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size);
+ cr = cairo_create (target);
+ cairo_set_source_surface (cr, source , 0, 0);
+ cairo_scale (cr,
+ size / gdk_texture_get_width (texture),
+ size / gdk_texture_get_height (texture));
+ cairo_paint (cr);
+ cairo_destroy (cr);
+ cairo_surface_destroy (source);
+
+ texture = gdk_texture_new_for_data (cairo_image_surface_get_data (target),
+ cairo_image_surface_get_width (target),
+ cairo_image_surface_get_height (target),
+ cairo_image_surface_get_stride (target));
+ cairo_surface_destroy (target);
+
+ return texture;
+}
+
+static GdkTexture *
+icon_from_name (const gchar *name,
+ gint size)
+{
+ GdkPixbuf *pixbuf;
+ GdkTexture *texture;
- if (best)
- {
- cairo_t *cr;
- surface =
- gdk_window_create_similar_image_surface (_gtk_widget_get_window (GTK_WIDGET(window)),
- CAIRO_FORMAT_ARGB32,
- size * scale, size * scale, scale);
- cr = cairo_create (surface);
- cairo_set_source_surface (cr, best, 0, 0);
- cairo_scale (cr,
- size / cairo_image_surface_get_width (best),
- size / cairo_image_surface_get_height (best));
- cairo_paint (cr);
- cairo_destroy (cr);
- }
+ pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ name, size,
+ GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
+ if (pixbuf == NULL)
+ return NULL;
- return best;
-}
+ texture = gdk_texture_new_for_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
-static cairo_surface_t *
-icon_from_name (GtkWindow *window,
- const gchar *name,
- gint size,
- gint scale)
-{
- return gtk_icon_theme_load_surface (gtk_icon_theme_get_default (),
- name, size, scale,
- _gtk_widget_get_window (GTK_WIDGET(window)),
- GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
+ return texture;
}
-cairo_surface_t *
+GdkTexture *
gtk_window_get_icon_for_size (GtkWindow *window,
- int size,
- int scale)
+ int size)
{
GtkWindowPrivate *priv = window->priv;
GtkWindowIconInfo *info;
info = ensure_icon_info (window);
if (info->icon_list != NULL)
- return icon_from_list (window, info->icon_list, size, scale);
+ return icon_from_list (info->icon_list, size);
name = gtk_window_get_icon_name (window);
if (name != NULL)
- return icon_from_name (window, name, size, scale);
+ return icon_from_name (name, size);
if (priv->transient_parent != NULL)
{
info = ensure_icon_info (priv->transient_parent);
if (info->icon_list)
- return icon_from_list (window, info->icon_list, size, scale);
+ return icon_from_list (info->icon_list, size);
}
if (default_icon_list != NULL)
- return icon_from_list (window, default_icon_list, size, scale);
+ return icon_from_list (default_icon_list, size);
if (default_icon_name != NULL)
- return icon_from_name (window, default_icon_name, size, scale);
+ return icon_from_name (default_icon_name, size);
return NULL;
}
/**
* gtk_window_set_icon_list:
* @window: a #GtkWindow
- * @list: (element-type cairo_surface_t): list of image surfaces
+ * @list: (element-type GdkTexture): list of image surfaces
*
* Sets up the icon representing a #GtkWindow. The icon is used when
* the window is minimized (also known as iconified). Some window
return;
g_list_foreach (list,
- (GFunc) cairo_surface_reference, NULL);
+ (GFunc) g_object_ref, NULL);
- g_list_free_full (info->icon_list, (GDestroyNotify)cairo_surface_destroy);
+ g_list_free_full (info->icon_list, g_object_unref);
info->icon_list = g_list_copy (list);
* The list is copied, but the reference count on each
* member won’t be incremented.
*
- * Returns: (element-type cairo_surface_t) (transfer container): copy of window’s icon list
+ * Returns: (element-type GdkTexture) (transfer container): copy of window’s icon list
**/
GList*
gtk_window_get_icon_list (GtkWindow *window)
**/
void
gtk_window_set_icon (GtkWindow *window,
- cairo_surface_t *icon)
+ GdkTexture *icon)
{
GList *list;
g_return_if_fail (GTK_IS_WINDOW (window));
- g_return_if_fail (icon == NULL || cairo_surface_get_type (icon) == CAIRO_SURFACE_TYPE_IMAGE);
+ g_return_if_fail (icon == NULL || GDK_IS_TEXTURE (icon));
list = NULL;
* called gtk_window_set_icon_list(), gets the first icon in
* the icon list).
*
- * Returns: (transfer none): icon for window
+ * Returns: (transfer none) (nullable: icon for window or %NULL if none
**/
-cairo_surface_t *
+GdkTexture *
gtk_window_get_icon (GtkWindow *window)
{
GtkWindowIconInfo *info;
info = get_icon_info (window);
if (info && info->icon_list)
- return (cairo_surface_t *) (info->icon_list->data);
+ return (GdkTexture *) (info->icon_list->data);
else
return NULL;
}
/* Load surface, printing warning on failure if error == NULL
*/
-static cairo_surface_t *
-load_surface_verbosely (GdkWindow *window,
- const char *filename,
+static GdkTexture *
+load_texture_verbosely (const char *filename,
GError **err)
{
GError *local_err = NULL;
+ GdkTexture *texture;
GdkPixbuf *pixbuf;
- cairo_surface_t *surface = NULL;
pixbuf = gdk_pixbuf_new_from_file (filename, &local_err);
filename, local_err->message);
g_error_free (local_err);
}
- }
- else
- {
- surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, window);
- g_object_unref (pixbuf);
+ return NULL;
}
- return surface;
+ texture = gdk_texture_new_for_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
+
+ return texture;
}
/**
const gchar *filename,
GError **err)
{
- cairo_surface_t *surface = load_surface_verbosely (_gtk_widget_get_window (GTK_WIDGET (window)), filename, err);
+ GdkTexture *texture = load_texture_verbosely (filename, err);
- if (surface)
+ if (texture)
{
- gtk_window_set_icon (window, surface);
- cairo_surface_destroy (surface);
+ gtk_window_set_icon (window, texture);
+ g_object_unref (texture);
return TRUE;
}
/**
* gtk_window_set_default_icon_list:
- * @list: (element-type cairo_surface_t) (transfer container): a list of #cairo_surface_t image surfaces
+ * @list: (element-type GdkTexture) (transfer container): a list of #GdkTextures
*
* Sets an icon list to be used as fallback for windows that haven't
* had gtk_window_set_icon_list() called on them to set up a
default_icon_serial++;
g_list_foreach (list,
- (GFunc) cairo_surface_reference, NULL);
+ (GFunc) g_object_ref, NULL);
- g_list_free_full (default_icon_list, (GDestroyNotify)cairo_surface_destroy);
+ g_list_free_full (default_icon_list, g_object_unref);
default_icon_list = g_list_copy (list);
* Since: 2.4
**/
void
-gtk_window_set_default_icon (cairo_surface_t *icon)
+gtk_window_set_default_icon (GdkTexture *icon)
{
GList *list;
- g_return_if_fail (cairo_surface_get_type (icon) == CAIRO_SURFACE_TYPE_IMAGE);
+ g_return_if_fail (GDK_IS_TEXTURE (icon));
list = g_list_prepend (NULL, icon);
gtk_window_set_default_icon_list (list);
gtk_window_set_default_icon_from_file (const gchar *filename,
GError **err)
{
- cairo_surface_t *surface = load_surface_verbosely (NULL, filename, err);
+ GdkTexture *texture = load_texture_verbosely (filename, err);
- if (surface)
+ if (texture)
{
- gtk_window_set_default_icon (surface);
- cairo_surface_destroy (surface);
+ gtk_window_set_default_icon (texture);
+ g_object_unref (texture);
return TRUE;
}
* but the surfaces in the list have not had their reference count
* incremented.
*
- * Returns: (element-type cairo_surface_t) (transfer container): copy of default icon list
+ * Returns: (element-type GdkTexture) (transfer container): copy of default icon list
**/
GList*
gtk_window_get_default_icon_list (void)