[gnome-photos] Scale the icons for HiDpi displays
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Scale the icons for HiDpi displays
- Date: Tue, 15 Apr 2014 09:43:34 +0000 (UTC)
commit 202f76ac147e734deeff19651059232b63c38fe9
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Mar 22 22:43:37 2014 +0100
Scale the icons for HiDpi displays
Original patch from Cosimo Cecchi for gnome-documents.
Fixes: https://bugzilla.gnome.org/726903
src/photos-base-item.c | 45 ++++++++++++++++++++++++++++--------------
src/photos-base-item.h | 4 +-
src/photos-utils.c | 17 +++++++++++++++-
src/photos-utils.h | 2 +
src/photos-view-container.c | 2 +-
src/photos-view-model.c | 5 ++-
6 files changed, 54 insertions(+), 21 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 050cbea..ef0fbac 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -27,12 +27,14 @@
#include <string.h>
+#include <gdk/gdk.h>
#include <gio/gio.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <libgd/gd.h>
#include <tracker-sparql.h>
+#include "photos-application.h"
#include "photos-base-item.h"
#include "photos-collection-icon-watcher.h"
#include "photos-delete-item-job.h"
@@ -49,7 +51,7 @@
struct _PhotosBaseItemPrivate
{
- GdkPixbuf *icon;
+ cairo_surface_t *surface;
GdkPixbuf *original_icon;
GeglNode *graph;
GeglNode *node;
@@ -134,9 +136,14 @@ static void
photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
{
PhotosBaseItemPrivate *priv = self->priv;
+ GApplication *app;
GIcon *pix;
GList *emblem_icons = NULL;
+ GList *windows;
GdkPixbuf *emblemed_pixbuf = NULL;
+ GdkPixbuf *thumbnailed_pixbuf = NULL;
+ GdkWindow *window;
+ gint scale;
if (priv->original_icon == NULL)
goto out;
@@ -202,25 +209,32 @@ photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
g_object_unref (emblemed_icon);
}
- g_clear_object (&priv->icon);
+ g_clear_pointer (&priv->surface, (GDestroyNotify) cairo_surface_destroy);
if (priv->thumb_path != NULL)
{
GtkBorder *slice;
slice = photos_utils_get_thumbnail_frame_border ();
- priv->icon = gd_embed_image_in_frame (emblemed_pixbuf,
- "resource:///org/gnome/photos/thumbnail-frame.png",
- slice,
- slice);
+ thumbnailed_pixbuf = gd_embed_image_in_frame (emblemed_pixbuf,
+ "resource:///org/gnome/photos/thumbnail-frame.png",
+ slice,
+ slice);
gtk_border_free (slice);
}
else
- priv->icon = g_object_ref (emblemed_pixbuf);
+ thumbnailed_pixbuf = g_object_ref (emblemed_pixbuf);
+
+ app = g_application_get_default ();
+ scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
+ windows = gtk_application_get_windows (GTK_APPLICATION (app));
+ window = gtk_widget_get_window (GTK_WIDGET (windows->data));
+ priv->surface = gdk_cairo_surface_create_from_pixbuf (thumbnailed_pixbuf, scale, window);
g_signal_emit (self, signals[INFO_UPDATED], 0);
out:
+ g_clear_object (&thumbnailed_pixbuf);
g_clear_object (&emblemed_pixbuf);
g_list_free_full (emblem_icons, g_object_unref);
}
@@ -670,6 +684,7 @@ photos_base_item_update_icon_from_type (PhotosBaseItem *self)
theme = gtk_icon_theme_get_default ();
icon_size = photos_utils_get_icon_size ();
+
info = gtk_icon_theme_lookup_by_gicon (theme,
icon,
icon_size,
@@ -871,8 +886,8 @@ photos_base_item_dispose (GObject *object)
PhotosBaseItem *self = PHOTOS_BASE_ITEM (object);
PhotosBaseItemPrivate *priv = self->priv;
+ g_clear_pointer (&priv->surface, (GDestroyNotify) cairo_surface_destroy);
g_clear_object (&priv->graph);
- g_clear_object (&priv->icon);
g_clear_object (&priv->original_icon);
g_clear_object (&priv->watcher);
g_clear_object (&priv->sel_cntrlr);
@@ -1149,13 +1164,6 @@ photos_base_item_get_height (PhotosBaseItem *self)
}
-GdkPixbuf *
-photos_base_item_get_icon (PhotosBaseItem *self)
-{
- return self->priv->icon;
-}
-
-
const gchar *
photos_base_item_get_identifier (PhotosBaseItem *self)
{
@@ -1212,6 +1220,13 @@ photos_base_item_get_source_name (PhotosBaseItem *self)
}
+cairo_surface_t *
+photos_base_item_get_surface (PhotosBaseItem *self)
+{
+ return self->priv->surface;
+}
+
+
const gchar *
photos_base_item_get_type_description (PhotosBaseItem *self)
{
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 4c1c731..6e31b86 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -117,8 +117,6 @@ gdouble photos_base_item_get_focal_length (PhotosBaseItem *self);
gint64 photos_base_item_get_height (PhotosBaseItem *self);
-GdkPixbuf *photos_base_item_get_icon (PhotosBaseItem *self);
-
const gchar *photos_base_item_get_identifier (PhotosBaseItem *self);
gdouble photos_base_item_get_iso_speed (PhotosBaseItem *self);
@@ -135,6 +133,8 @@ const gchar *photos_base_item_get_resource_urn (PhotosBaseItem *self);
const gchar *photos_base_item_get_source_name (PhotosBaseItem *self);
+cairo_surface_t *photos_base_item_get_surface (PhotosBaseItem *self);
+
const gchar *photos_base_item_get_type_description (PhotosBaseItem *self);
const gchar *photos_base_item_get_uri (PhotosBaseItem *self);
diff --git a/src/photos-utils.c b/src/photos-utils.c
index c2aff36..9c02c6d 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -1,6 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2012, 2013 Red Hat, Inc.
+ * Copyright © 2012, 2013, 2014 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -34,6 +34,7 @@
#include <tracker-sparql.h>
#include <libgd/gd.h>
+#include "photos-application.h"
#include "photos-query.h"
#include "photos-tracker-queue.h"
#include "photos-utils.h"
@@ -433,6 +434,20 @@ photos_utils_flash_on_quark (void)
gint
photos_utils_get_icon_size (void)
{
+ GApplication *app;
+ gint scale;
+ gint size;
+
+ app = g_application_get_default ();
+ scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
+ size = photos_utils_get_icon_size_unscaled ();
+ return scale * size;
+}
+
+
+gint
+photos_utils_get_icon_size_unscaled (void)
+{
return 256;
}
diff --git a/src/photos-utils.h b/src/photos-utils.h
index e61f8e0..97e6339 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -64,6 +64,8 @@ GQuark photos_utils_flash_on_quark (void);
gint photos_utils_get_icon_size (void);
+gint photos_utils_get_icon_size_unscaled (void);
+
char* photos_utils_get_pixbuf_common_suffix (GdkPixbufFormat *format);
GdkPixbufFormat* photos_utils_get_pixbuf_format (GFile *file);
diff --git a/src/photos-view-container.c b/src/photos-view-container.c
index b0277ff..aec7f8f 100644
--- a/src/photos-view-container.c
+++ b/src/photos-view-container.c
@@ -311,7 +311,7 @@ photos_view_container_constructed (GObject *object)
priv->view = gd_main_view_new (GD_MAIN_VIEW_ICON);
generic_view = gd_main_view_get_generic_view (priv->view);
- size = photos_utils_get_icon_size ();
+ size = photos_utils_get_icon_size_unscaled ();
gtk_icon_view_set_item_width (GTK_ICON_VIEW (generic_view), size + 24);
gtk_container_add (GTK_CONTAINER (grid), GTK_WIDGET (priv->view));
diff --git a/src/photos-view-model.c b/src/photos-view-model.c
index 725b74f..e5ad665 100644
--- a/src/photos-view-model.c
+++ b/src/photos-view-model.c
@@ -25,6 +25,7 @@
#include "config.h"
+#include <cairo-gobject.h>
#include <gio/gio.h>
#include "photos-base-manager.h"
@@ -83,7 +84,7 @@ photos_view_model_info_set (PhotosViewModel *self, PhotosBaseItem *item, GtkTree
PHOTOS_VIEW_MODEL_URI, photos_base_item_get_uri (item),
PHOTOS_VIEW_MODEL_NAME, photos_base_item_get_name (item),
PHOTOS_VIEW_MODEL_AUTHOR, photos_base_item_get_author (item),
- PHOTOS_VIEW_MODEL_ICON, photos_base_item_get_icon (item),
+ PHOTOS_VIEW_MODEL_ICON, photos_base_item_get_surface (item),
PHOTOS_VIEW_MODEL_MTIME, photos_base_item_get_mtime (item),
-1);
}
@@ -440,7 +441,7 @@ photos_view_model_init (PhotosViewModel *self)
G_TYPE_STRING, /* URI */
G_TYPE_STRING, /* NAME */
G_TYPE_STRING, /* AUTHOR */
- GDK_TYPE_PIXBUF, /* ICON */
+ CAIRO_GOBJECT_TYPE_SURFACE, /* ICON */
G_TYPE_INT64, /* MTIME */
G_TYPE_BOOLEAN, /* STATE */
G_TYPE_UINT}; /* PULSE (unused) */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]