texture-cache: use scale factor to load background and borders

https://bugzilla.gnome.org/show_bug.cgi?id=726907
This commit is contained in:
Cosimo Cecchi 2014-03-22 20:29:23 -07:00
parent a22fdea0e3
commit 9ecf466ce1
3 changed files with 39 additions and 15 deletions

View File

@ -246,10 +246,11 @@ rgba_from_clutter (GdkRGBA *rgba,
rgba->alpha = color->alpha / 255.; rgba->alpha = color->alpha / 255.;
} }
/* A private structure for keeping width and height. */ /* A private structure for keeping width, height and scale. */
typedef struct { typedef struct {
int width; int width;
int height; int height;
int scale;
} Dimensions; } Dimensions;
/* This struct corresponds to a request for an texture. /* This struct corresponds to a request for an texture.
@ -317,6 +318,7 @@ on_image_size_prepared (GdkPixbufLoader *pixbuf_loader,
Dimensions *available_dimensions = data; Dimensions *available_dimensions = data;
int available_width = available_dimensions->width; int available_width = available_dimensions->width;
int available_height = available_dimensions->height; int available_height = available_dimensions->height;
int scale_factor = available_dimensions->scale;
int scaled_width; int scaled_width;
int scaled_height; int scaled_height;
@ -324,8 +326,8 @@ on_image_size_prepared (GdkPixbufLoader *pixbuf_loader,
&scaled_width, &scaled_height); &scaled_width, &scaled_height);
gdk_pixbuf_loader_set_size (pixbuf_loader, gdk_pixbuf_loader_set_size (pixbuf_loader,
scaled_width, scaled_width * scale_factor,
scaled_height); scaled_height * scale_factor);
} }
static GdkPixbuf * static GdkPixbuf *
@ -333,6 +335,7 @@ impl_load_pixbuf_data (const guchar *data,
gsize size, gsize size,
int available_width, int available_width,
int available_height, int available_height,
int scale,
GError **error) GError **error)
{ {
GdkPixbufLoader *pixbuf_loader = NULL; GdkPixbufLoader *pixbuf_loader = NULL;
@ -346,6 +349,7 @@ impl_load_pixbuf_data (const guchar *data,
available_dimensions.width = available_width; available_dimensions.width = available_width;
available_dimensions.height = available_height; available_dimensions.height = available_height;
available_dimensions.scale = scale;
g_signal_connect (pixbuf_loader, "size-prepared", g_signal_connect (pixbuf_loader, "size-prepared",
G_CALLBACK (on_image_size_prepared), &available_dimensions); G_CALLBACK (on_image_size_prepared), &available_dimensions);
@ -379,6 +383,7 @@ impl_load_pixbuf_data (const guchar *data,
/* We know that the image will later be rotated, so we reverse the available dimensions. */ /* We know that the image will later be rotated, so we reverse the available dimensions. */
available_dimensions.width = available_height; available_dimensions.width = available_height;
available_dimensions.height = available_width; available_dimensions.height = available_width;
available_dimensions.scale = scale;
g_signal_connect (pixbuf_loader, "size-prepared", g_signal_connect (pixbuf_loader, "size-prepared",
G_CALLBACK (on_image_size_prepared), &available_dimensions); G_CALLBACK (on_image_size_prepared), &available_dimensions);
@ -466,6 +471,7 @@ static GdkPixbuf *
impl_load_pixbuf_file (const char *uri, impl_load_pixbuf_file (const char *uri,
int available_width, int available_width,
int available_height, int available_height,
int scale,
GError **error) GError **error)
{ {
GdkPixbuf *pixbuf = NULL; GdkPixbuf *pixbuf = NULL;
@ -481,6 +487,7 @@ impl_load_pixbuf_file (const char *uri,
{ {
pixbuf = impl_load_pixbuf_data ((const guchar *) contents, size, pixbuf = impl_load_pixbuf_data ((const guchar *) contents, size,
available_width, available_height, available_width, available_height,
scale,
error); error);
} }
@ -503,7 +510,7 @@ load_pixbuf_thread (GSimpleAsyncResult *result,
g_assert (data != NULL); g_assert (data != NULL);
g_assert (data->uri != NULL); g_assert (data->uri != NULL);
pixbuf = impl_load_pixbuf_file (data->uri, data->width, data->height, &error); pixbuf = impl_load_pixbuf_file (data->uri, data->width, data->height, 1, &error);
if (error != NULL) if (error != NULL)
{ {
@ -1328,6 +1335,7 @@ st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache,
const gchar *uri, const gchar *uri,
int available_width, int available_width,
int available_height, int available_height,
int scale,
GError **error) GError **error)
{ {
CoglHandle texdata; CoglHandle texdata;
@ -1340,7 +1348,7 @@ st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache,
if (texdata == NULL) if (texdata == NULL)
{ {
pixbuf = impl_load_pixbuf_file (uri, available_width, available_height, error); pixbuf = impl_load_pixbuf_file (uri, available_width, available_height, scale, error);
if (!pixbuf) if (!pixbuf)
goto out; goto out;
@ -1369,6 +1377,7 @@ st_texture_cache_load_uri_sync_to_cairo_surface (StTextureCache *cache,
const gchar *uri, const gchar *uri,
int available_width, int available_width,
int available_height, int available_height,
int scale,
GError **error) GError **error)
{ {
cairo_surface_t *surface; cairo_surface_t *surface;
@ -1381,7 +1390,7 @@ st_texture_cache_load_uri_sync_to_cairo_surface (StTextureCache *cache,
if (surface == NULL) if (surface == NULL)
{ {
pixbuf = impl_load_pixbuf_file (uri, available_width, available_height, error); pixbuf = impl_load_pixbuf_file (uri, available_width, available_height, scale, error);
if (!pixbuf) if (!pixbuf)
goto out; goto out;
@ -1408,6 +1417,7 @@ out:
* st_texture_cache_load_file_to_cogl_texture: * st_texture_cache_load_file_to_cogl_texture:
* @cache: A #StTextureCache * @cache: A #StTextureCache
* @file_path: Path to a file in supported image format * @file_path: Path to a file in supported image format
* @scale: Scale factor of the display
* *
* This function synchronously loads the given file path * This function synchronously loads the given file path
* into a COGL texture. On error, a warning is emitted * into a COGL texture. On error, a warning is emitted
@ -1417,7 +1427,8 @@ out:
*/ */
CoglHandle CoglHandle
st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache, st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
const gchar *file_path) const gchar *file_path,
gint scale)
{ {
CoglHandle texture; CoglHandle texture;
GFile *file; GFile *file;
@ -1428,7 +1439,7 @@ st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
uri = g_file_get_uri (file); uri = g_file_get_uri (file);
texture = st_texture_cache_load_uri_sync_to_cogl_texture (cache, ST_TEXTURE_CACHE_POLICY_FOREVER, texture = st_texture_cache_load_uri_sync_to_cogl_texture (cache, ST_TEXTURE_CACHE_POLICY_FOREVER,
uri, -1, -1, &error); uri, -1, -1, scale, &error);
g_object_unref (file); g_object_unref (file);
g_free (uri); g_free (uri);
@ -1445,6 +1456,7 @@ st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
* st_texture_cache_load_file_to_cairo_surface: * st_texture_cache_load_file_to_cairo_surface:
* @cache: A #StTextureCache * @cache: A #StTextureCache
* @file_path: Path to a file in supported image format * @file_path: Path to a file in supported image format
* @scale: Scale factor of the display
* *
* This function synchronously loads the given file path * This function synchronously loads the given file path
* into a cairo surface. On error, a warning is emitted * into a cairo surface. On error, a warning is emitted
@ -1454,7 +1466,8 @@ st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
*/ */
cairo_surface_t * cairo_surface_t *
st_texture_cache_load_file_to_cairo_surface (StTextureCache *cache, st_texture_cache_load_file_to_cairo_surface (StTextureCache *cache,
const gchar *file_path) const gchar *file_path,
gint scale)
{ {
cairo_surface_t *surface; cairo_surface_t *surface;
GFile *file; GFile *file;
@ -1465,7 +1478,7 @@ st_texture_cache_load_file_to_cairo_surface (StTextureCache *cache,
uri = g_file_get_uri (file); uri = g_file_get_uri (file);
surface = st_texture_cache_load_uri_sync_to_cairo_surface (cache, ST_TEXTURE_CACHE_POLICY_FOREVER, surface = st_texture_cache_load_uri_sync_to_cairo_surface (cache, ST_TEXTURE_CACHE_POLICY_FOREVER,
uri, -1, -1, &error); uri, -1, -1, scale, &error);
g_object_unref (file); g_object_unref (file);
g_free (uri); g_free (uri);

View File

@ -93,10 +93,12 @@ ClutterActor *st_texture_cache_load_uri_async (StTextureCache *cache,
int available_height); int available_height);
CoglHandle st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache, CoglHandle st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
const gchar *file_path); const gchar *file_path,
gint scale);
cairo_surface_t *st_texture_cache_load_file_to_cairo_surface (StTextureCache *cache, cairo_surface_t *st_texture_cache_load_file_to_cairo_surface (StTextureCache *cache,
const gchar *file_path); const gchar *file_path,
gint scale);
/** /**
* StTextureCacheLoader: (skip) * StTextureCacheLoader: (skip)

View File

@ -606,12 +606,14 @@ create_cairo_pattern_of_background_image (StThemeNode *node,
gdouble background_image_width, background_image_height; gdouble background_image_width, background_image_height;
gdouble x, y; gdouble x, y;
gdouble scale_w, scale_h; gdouble scale_w, scale_h;
int scale_factor;
file = st_theme_node_get_background_image (node); file = st_theme_node_get_background_image (node);
texture_cache = st_texture_cache_get_default (); texture_cache = st_texture_cache_get_default ();
surface = st_texture_cache_load_file_to_cairo_surface (texture_cache, file); g_object_get (node->context, "scale-factor", &scale_factor, NULL);
surface = st_texture_cache_load_file_to_cairo_surface (texture_cache, file, scale_factor);
if (surface == NULL) if (surface == NULL)
return NULL; return NULL;
@ -1301,8 +1303,12 @@ st_theme_node_load_border_image (StThemeNode *node)
const char *filename; const char *filename;
filename = st_border_image_get_filename (border_image); filename = st_border_image_get_filename (border_image);
int scale_factor;
g_object_get (node->context, "scale-factor", &scale_factor, NULL);
node->border_slices_texture = st_texture_cache_load_file_to_cogl_texture (st_texture_cache_get_default (), node->border_slices_texture = st_texture_cache_load_file_to_cogl_texture (st_texture_cache_get_default (),
filename); filename, scale_factor);
if (node->border_slices_texture == COGL_INVALID_HANDLE) if (node->border_slices_texture == COGL_INVALID_HANDLE)
goto out; goto out;
@ -1347,9 +1353,12 @@ st_theme_node_load_background_image (StThemeNode *node)
if (background_image == NULL) if (background_image == NULL)
goto out; goto out;
int scale_factor;
g_object_get (node->context, "scale-factor", &scale_factor, NULL);
background_image_shadow_spec = st_theme_node_get_background_image_shadow (node); background_image_shadow_spec = st_theme_node_get_background_image_shadow (node);
node->background_texture = st_texture_cache_load_file_to_cogl_texture (st_texture_cache_get_default (), node->background_texture = st_texture_cache_load_file_to_cogl_texture (st_texture_cache_get_default (),
background_image); background_image, scale_factor);
if (node->background_texture == COGL_INVALID_HANDLE) if (node->background_texture == COGL_INVALID_HANDLE)
goto out; goto out;