diff options
author | Ernestas Kulik <ernestask@gnome.org> | 2018-07-23 21:02:40 +0300 |
---|---|---|
committer | Ernestas Kulik <ekulik@redhat.com> | 2019-06-29 14:33:41 +0200 |
commit | 4093044ff6fbac6cdc186a837b558ff5a2a21a87 (patch) | |
tree | 86c40b6afce916a9d1e99904eebfc190cf1390bb | |
parent | c275a2e67d827deebd2b2225f00c51ed73b4157d (diff) | |
download | nautilus-4093044ff6fbac6cdc186a837b558ff5a2a21a87.tar.gz |
list-model: Use GdkTexture for icon
GtkCellRendererPixbuf no longer allows using Cairo surfaces.
-rw-r--r-- | eel/eel-graphic-effects.c | 122 | ||||
-rw-r--r-- | eel/eel-graphic-effects.h | 4 | ||||
-rw-r--r-- | src/nautilus-list-model.c | 12 |
3 files changed, 48 insertions, 90 deletions
diff --git a/eel/eel-graphic-effects.c b/eel/eel-graphic-effects.c index 4b9afc101..b0f8b5a05 100644 --- a/eel/eel-graphic-effects.c +++ b/eel/eel-graphic-effects.c @@ -18,91 +18,57 @@ * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -/* This file contains pixbuf manipulation routines used for graphical effects like pre-lighting - * and selection hilighting */ +#include "eel-graphic-effects.h" -#include <config.h> +GdkTexture * +eel_create_spotlight_texture (GdkTexture *texture) +{ + int width; + int height; + cairo_surface_t *surface; + cairo_t *cr; + unsigned char *data; + int stride; + g_autoptr (GBytes) bytes = NULL; + GdkTexture *prelit_texture; -#include "eel-graphic-effects.h" -#include "eel-glib-extensions.h" + g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL); -#include <math.h> -#include <string.h> + width = gdk_texture_get_width (texture); + height = gdk_texture_get_height (texture); + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + cr = cairo_create (surface); + data = cairo_image_surface_get_data (surface); + stride = cairo_image_surface_get_stride (surface); -/* shared utility to create a new pixbuf from the passed-in one */ + gdk_texture_download (texture, data, stride); -static GdkPixbuf * -create_new_pixbuf (GdkPixbuf *src) -{ - g_assert (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB); - g_assert ((!gdk_pixbuf_get_has_alpha (src) - && gdk_pixbuf_get_n_channels (src) == 3) - || (gdk_pixbuf_get_has_alpha (src) - && gdk_pixbuf_get_n_channels (src) == 4)); - - return gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src), - gdk_pixbuf_get_has_alpha (src), - gdk_pixbuf_get_bits_per_sample (src), - gdk_pixbuf_get_width (src), - gdk_pixbuf_get_height (src)); -} + cairo_surface_mark_dirty (surface); -/* utility routine to bump the level of a color component with pinning */ + cairo_set_source_surface (cr, surface, 0, 0); + cairo_paint (cr); -const int HOVER_COMPONENT_ADDITION = 15; + cairo_set_operator (cr, CAIRO_OPERATOR_ADD); -static guchar -lighten_component (guchar cur_value) -{ - int new_value = cur_value; - new_value = cur_value + HOVER_COMPONENT_ADDITION; - if (new_value > 255) - { - new_value = 255; - } - return (guchar) new_value; -} + cairo_push_group (cr); -GdkPixbuf * -eel_create_spotlight_pixbuf (GdkPixbuf *src) -{ - GdkPixbuf *dest; - int i, j; - int width, height, has_alpha, src_row_stride, dst_row_stride; - guchar *target_pixels, *original_pixels; - guchar *pixsrc, *pixdest; - - g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL); - g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src) - && gdk_pixbuf_get_n_channels (src) == 3) - || (gdk_pixbuf_get_has_alpha (src) - && gdk_pixbuf_get_n_channels (src) == 4), NULL); - g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL); - - dest = create_new_pixbuf (src); - - has_alpha = gdk_pixbuf_get_has_alpha (src); - width = gdk_pixbuf_get_width (src); - height = gdk_pixbuf_get_height (src); - dst_row_stride = gdk_pixbuf_get_rowstride (dest); - src_row_stride = gdk_pixbuf_get_rowstride (src); - target_pixels = gdk_pixbuf_get_pixels (dest); - original_pixels = gdk_pixbuf_get_pixels (src); - - for (i = 0; i < height; i++) - { - pixdest = target_pixels + i * dst_row_stride; - pixsrc = original_pixels + i * src_row_stride; - for (j = 0; j < width; j++) - { - *pixdest++ = lighten_component (*pixsrc++); - *pixdest++ = lighten_component (*pixsrc++); - *pixdest++ = lighten_component (*pixsrc++); - if (has_alpha) - { - *pixdest++ = *pixsrc++; - } - } - } - return dest; + /* This is *close enough* to the original look. + * The magic alpha value was selected after visual comparison. + */ + cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.18); + cairo_paint (cr); + + cairo_pop_group_to_source (cr); + + cairo_mask_surface (cr, surface, 0.0, 0.0); + + cairo_surface_flush (surface); + + bytes = g_bytes_new (data, height * stride); + prelit_texture = gdk_memory_texture_new (width, height, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, bytes, stride); + + cairo_destroy (cr); + cairo_surface_destroy (surface); + + return prelit_texture; } diff --git a/eel/eel-graphic-effects.h b/eel/eel-graphic-effects.h index dece34739..9bda47b0c 100644 --- a/eel/eel-graphic-effects.h +++ b/eel/eel-graphic-effects.h @@ -21,8 +21,6 @@ #pragma once -#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk/gdk.h> -/* return a lightened pixbuf for pre-lighting */ -GdkPixbuf *eel_create_spotlight_pixbuf (GdkPixbuf *source_pixbuf); +GdkTexture *eel_create_spotlight_texture (GdkTexture *texture); diff --git a/src/nautilus-list-model.c b/src/nautilus-list-model.c index 5763d1b3b..7bb818953 100644 --- a/src/nautilus-list-model.c +++ b/src/nautilus-list-model.c @@ -417,17 +417,11 @@ nautilus_list_model_get_value (GtkTreeModel *tree_model, g_list_find_custom (priv->highlight_files, file, (GCompareFunc) nautilus_file_compare_location)) { -#if 0 - GdkPixbuf *rendered_icon; + g_autoptr (GdkTexture) prelit_texture = NULL; - rendered_icon = eel_create_spotlight_pixbuf (icon); + prelit_texture = eel_create_spotlight_texture (texture); - if (rendered_icon != NULL) - { - g_object_unref (icon); - icon = rendered_icon; - } -#endif + g_set_object (&texture, prelit_texture); } g_value_take_object (value, texture); |