background: Improve preview performance

Since 7cef6dc5, the background previews are rendered at the full
resolution. However, this is expensive and causes considerable lag,
especially for resizes. Since then, the thumbnail size has doubled to
256 pixels, making the previews sharper even at larger sizes.

So, to improve performance, let's effectively revert 7cef6dc5. The
revert is not possible without disabling frame = 0 retrieval, since that
is broken for non-slideshow backgrounds and was not used before anyways
with force_size = TRUE.

Related to #674
Related to #704
Related to #2448
This commit is contained in:
velsinki 2023-11-23 01:27:41 +01:00 committed by Felipe Borges
parent 39f12a7d1b
commit b3afa91f1a
3 changed files with 32 additions and 66 deletions

View file

@ -177,19 +177,6 @@ update_size (CcBackgroundItem *item)
}
}
static GdkPixbuf *
render_at_size (GnomeBG *bg,
gint width,
gint height)
{
GdkPixbuf *pixbuf;
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
gnome_bg_draw (bg, pixbuf);
return pixbuf;
}
GdkPixbuf *
cc_background_item_get_frame_thumbnail (CcBackgroundItem *item,
GnomeDesktopThumbnailFactory *thumbs,
@ -197,13 +184,15 @@ cc_background_item_get_frame_thumbnail (CcBackgroundItem *item,
int height,
int scale_factor,
int frame,
gboolean force_size,
gboolean dark)
{
g_autoptr(GdkPixbuf) pixbuf = NULL;
g_autoptr(GdkPixbuf) retval = NULL;
GdkPixbuf *pixbuf;
CachedThumbnail *thumbnail;
GnomeBG *bg;
g_autoptr(GdkMonitor) monitor = NULL;
GdkDisplay *display;
GListModel *monitors;
GdkRectangle monitor_layout;
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
g_return_val_if_fail (width > 0 && height > 0, NULL);
@ -221,45 +210,26 @@ cc_background_item_get_frame_thumbnail (CcBackgroundItem *item,
set_bg_properties (item);
if (force_size) {
/* FIXME: this doesn't play nice with slideshow stepping at all,
* because it will always render the current slideshow frame, which
* might not be what we want.
* We're lacking an API to draw a high-res GnomeBG manually choosing
* the slideshow frame though, so we can't do much better than this
* for now.
*/
pixbuf = render_at_size (bg, width, height);
display = gdk_display_get_default ();
monitors = gdk_display_get_monitors (display);
monitor = g_list_model_get_item (monitors, 0);
gdk_monitor_get_geometry (monitor, &monitor_layout);
if (frame >= 0) {
pixbuf = gnome_bg_create_frame_thumbnail (bg,
thumbs,
&monitor_layout,
width,
height,
frame);
} else {
g_autoptr(GdkMonitor) monitor = NULL;
GdkDisplay *display;
GListModel *monitors;
GdkRectangle monitor_layout;
display = gdk_display_get_default ();
monitors = gdk_display_get_monitors (display);
monitor = g_list_model_get_item (monitors, 0);
gdk_monitor_get_geometry (monitor, &monitor_layout);
if (frame >= 0) {
pixbuf = gnome_bg_create_frame_thumbnail (bg,
thumbs,
&monitor_layout,
width,
height,
frame);
} else {
pixbuf = gnome_bg_create_thumbnail (bg,
thumbs,
&monitor_layout,
width,
height);
}
pixbuf = gnome_bg_create_thumbnail (bg,
thumbs,
&monitor_layout,
width,
height);
}
retval = g_steal_pointer (&pixbuf);
gnome_bg_get_image_size (bg,
thumbs,
width,
@ -270,13 +240,13 @@ cc_background_item_get_frame_thumbnail (CcBackgroundItem *item,
update_size (item);
/* Cache the new thumbnail */
g_set_object (&thumbnail->thumbnail, retval);
g_set_object (&thumbnail->thumbnail, pixbuf);
thumbnail->width = width;
thumbnail->height = height;
thumbnail->scale_factor = scale_factor;
thumbnail->frame = frame;
return g_steal_pointer (&retval);
return pixbuf;
}
@ -288,7 +258,7 @@ cc_background_item_get_thumbnail (CcBackgroundItem *item,
int scale_factor,
gboolean dark)
{
return cc_background_item_get_frame_thumbnail (item, thumbs, width, height, scale_factor, -1, FALSE, dark);
return cc_background_item_get_frame_thumbnail (item, thumbs, width, height, scale_factor, -1, dark);
}
static void

View file

@ -64,7 +64,6 @@ GdkPixbuf * cc_background_item_get_frame_thumbnail (CcBackgroundItem
int height,
int scale_factor,
int frame,
gboolean force_size,
gboolean dark);
GDesktopBackgroundStyle cc_background_item_get_placement (CcBackgroundItem *item);

View file

@ -65,16 +65,13 @@ draw_preview_func (GtkDrawingArea *drawing_area,
return;
scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (drawing_area));
pixbuf = cc_background_item_get_frame_thumbnail (self->item,
self->thumbnail_factory,
width,
height,
scale_factor,
0,
TRUE,
self->is_dark &&
cc_background_item_has_dark_version (self->item));
pixbuf = cc_background_item_get_thumbnail (self->item,
self->thumbnail_factory,
width,
height,
scale_factor,
self->is_dark &&
cc_background_item_has_dark_version (self->item));
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
cairo_paint (cr);