[nautilus/wip/antoniof/hidpi-and-icons-cleanup: 2/11] ui-utilities: Add filmholes using GdkSnapshot
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/hidpi-and-icons-cleanup: 2/11] ui-utilities: Add filmholes using GdkSnapshot
- Date: Thu, 1 Sep 2022 08:53:41 +0000 (UTC)
commit 37c5255aa8690819f72e7f5c745de2f9c1ff5798
Author: António Fernandes <antoniof gnome org>
Date: Sun Aug 7 23:10:23 2022 +0100
ui-utilities: Add filmholes using GdkSnapshot
This can take advantage of GPU and prepares for next changes.
src/nautilus-file.c | 33 ++++++++++++++++++++------------
src/nautilus-ui-utilities.c | 46 +++++++++++++++++++++++----------------------
src/nautilus-ui-utilities.h | 4 +++-
3 files changed, 48 insertions(+), 35 deletions(-)
---
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index a2c02f690..375f148dc 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -5146,6 +5146,7 @@ nautilus_file_get_thumbnail_icon (NautilusFile *file,
int scale,
NautilusFileIconFlags flags)
{
+ g_autoptr (GdkPaintable) paintable = NULL;
int modified_size;
GdkPixbuf *pixbuf;
int w, h, s;
@@ -5159,6 +5160,11 @@ nautilus_file_get_thumbnail_icon (NautilusFile *file,
if (file->details->thumbnail)
{
+ gdouble texture_width;
+ gdouble texture_height;
+ g_autoptr (GdkTexture) texture = NULL;
+ g_autoptr (GtkSnapshot) snapshot = gtk_snapshot_new ();
+
w = gdk_pixbuf_get_width (file->details->thumbnail);
h = gdk_pixbuf_get_height (file->details->thumbnail);
@@ -5191,20 +5197,24 @@ nautilus_file_get_thumbnail_icon (NautilusFile *file,
MAX (h * thumb_scale, 1),
GDK_INTERP_BILINEAR);
- /* We don't want frames around small icons */
- if (!gdk_pixbuf_get_has_alpha (file->details->thumbnail) || s >= 128 * scale)
- {
- if (nautilus_is_video_file (file))
- {
- nautilus_ui_frame_video (&pixbuf);
- }
- }
-
g_clear_object (&file->details->scaled_thumbnail);
file->details->scaled_thumbnail = pixbuf;
file->details->thumbnail_scale = thumb_scale;
}
+ texture = gdk_texture_new_for_pixbuf (pixbuf);
+ texture_width = gdk_texture_get_width (texture);
+ texture_height = gdk_texture_get_height (texture);
+ gdk_paintable_snapshot (GDK_PAINTABLE (texture),
+ GDK_SNAPSHOT (snapshot),
+ texture_width, texture_height);
+ if (size >= NAUTILUS_GRID_ICON_SIZE_SMALL &&
+ nautilus_is_video_file (file))
+ {
+ nautilus_ui_frame_video (snapshot, texture_width, texture_height);
+ }
+ paintable = gtk_snapshot_to_paintable (snapshot, NULL);
+
DEBUG ("Returning thumbnailed image, at size %d %d",
(int) (w * thumb_scale), (int) (h * thumb_scale));
}
@@ -5217,10 +5227,9 @@ nautilus_file_get_thumbnail_icon (NautilusFile *file,
nautilus_create_thumbnail (file);
}
- if (pixbuf != NULL)
+ if (paintable != NULL)
{
- g_autoptr (GdkTexture) texture = gdk_texture_new_for_pixbuf (pixbuf);
- icon = nautilus_icon_info_new_for_paintable (GDK_PAINTABLE (texture), scale);
+ icon = nautilus_icon_info_new_for_paintable (paintable, scale);
}
else if (file->details->is_thumbnailing)
{
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index 74bba91f2..d87422460 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -164,39 +164,41 @@ ensure_filmholes (void)
}
void
-nautilus_ui_frame_video (GdkPixbuf **pixbuf)
+nautilus_ui_frame_video (GtkSnapshot *snapshot,
+ gdouble width,
+ gdouble height)
{
- int width, height;
+ g_autoptr (GdkTexture) left_texture = NULL;
+ g_autoptr (GdkTexture) right_texture = NULL;
int holes_width, holes_height;
- int i;
if (!ensure_filmholes ())
{
return;
}
- width = gdk_pixbuf_get_width (*pixbuf);
- height = gdk_pixbuf_get_height (*pixbuf);
holes_width = gdk_pixbuf_get_width (filmholes_left);
holes_height = gdk_pixbuf_get_height (filmholes_left);
- for (i = 0; i < height; i += holes_height)
- {
- gdk_pixbuf_composite (filmholes_left, *pixbuf, 0, i,
- MIN (width, holes_width),
- MIN (height - i, holes_height),
- 0, i, 1, 1, GDK_INTERP_NEAREST, 255);
- }
-
- for (i = 0; i < height; i += holes_height)
- {
- gdk_pixbuf_composite (filmholes_right, *pixbuf,
- width - holes_width, i,
- MIN (width, holes_width),
- MIN (height - i, holes_height),
- width - holes_width, i,
- 1, 1, GDK_INTERP_NEAREST, 255);
- }
+ /* Left */
+ gtk_snapshot_push_repeat (snapshot,
+ &GRAPHENE_RECT_INIT (0, 0, holes_width, height),
+ NULL);
+ left_texture = gdk_texture_new_for_pixbuf (filmholes_left);
+ gtk_snapshot_append_texture (snapshot,
+ left_texture,
+ &GRAPHENE_RECT_INIT (0, 0, holes_width, holes_height));
+ gtk_snapshot_pop (snapshot);
+
+ /* Right */
+ gtk_snapshot_push_repeat (snapshot,
+ &GRAPHENE_RECT_INIT (width - holes_width, 0, holes_width, height),
+ NULL);
+ right_texture = gdk_texture_new_for_pixbuf (filmholes_right);
+ gtk_snapshot_append_texture (snapshot,
+ right_texture,
+ &GRAPHENE_RECT_INIT (width - holes_width, 0, holes_width, holes_height));
+ gtk_snapshot_pop (snapshot);
}
gboolean
diff --git a/src/nautilus-ui-utilities.h b/src/nautilus-ui-utilities.h
index 44af13586..f3df67f9c 100644
--- a/src/nautilus-ui-utilities.h
+++ b/src/nautilus-ui-utilities.h
@@ -35,7 +35,9 @@ void nautilus_g_menu_replace_string_in_item (GMenu *menu,
const gchar *attribute,
const gchar *string);
-void nautilus_ui_frame_video (GdkPixbuf **pixbuf);
+void nautilus_ui_frame_video (GtkSnapshot *snapshot,
+ gdouble width,
+ gdouble height);
gboolean nautilus_date_time_is_between_dates (GDateTime *date,
GDateTime *initial_date,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]