st-texture-cache: Fix stretched textures
st_texture_cache_load_from_raw() enforces a square ClutterTexture, resulting in the texture being stretched if the passed in image data has a different width:height ratio. Add padding in those cases as we already do when loading from pixbufs. https://bugzilla.gnome.org/show_bug.cgi?id=683483
This commit is contained in:
parent
b98c5f94ee
commit
6b016c2528
@ -560,26 +560,27 @@ load_pixbuf_async_finish (StTextureCache *cache, GAsyncResult *result, GError **
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CoglHandle
|
static CoglHandle
|
||||||
pixbuf_to_cogl_handle (GdkPixbuf *pixbuf,
|
data_to_cogl_handle (const guchar *data,
|
||||||
|
gboolean has_alpha,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int rowstride,
|
||||||
gboolean add_padding)
|
gboolean add_padding)
|
||||||
{
|
{
|
||||||
CoglHandle texture, offscreen;
|
CoglHandle texture, offscreen;
|
||||||
CoglColor clear_color;
|
CoglColor clear_color;
|
||||||
int width, height;
|
|
||||||
guint size;
|
guint size;
|
||||||
|
|
||||||
width = gdk_pixbuf_get_width (pixbuf);
|
|
||||||
height = gdk_pixbuf_get_height (pixbuf);
|
|
||||||
size = MAX (width, height);
|
size = MAX (width, height);
|
||||||
|
|
||||||
if (!add_padding || width == height)
|
if (!add_padding || width == height)
|
||||||
return cogl_texture_new_from_data (width,
|
return cogl_texture_new_from_data (width,
|
||||||
height,
|
height,
|
||||||
COGL_TEXTURE_NONE,
|
COGL_TEXTURE_NONE,
|
||||||
gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
|
has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
|
||||||
COGL_PIXEL_FORMAT_ANY,
|
COGL_PIXEL_FORMAT_ANY,
|
||||||
gdk_pixbuf_get_rowstride (pixbuf),
|
rowstride,
|
||||||
gdk_pixbuf_get_pixels (pixbuf));
|
data);
|
||||||
|
|
||||||
texture = cogl_texture_new_with_size (size, size,
|
texture = cogl_texture_new_with_size (size, size,
|
||||||
COGL_TEXTURE_NO_SLICING,
|
COGL_TEXTURE_NO_SLICING,
|
||||||
@ -597,12 +598,24 @@ pixbuf_to_cogl_handle (GdkPixbuf *pixbuf,
|
|||||||
(size - width) / 2, (size - height) / 2,
|
(size - width) / 2, (size - height) / 2,
|
||||||
width, height,
|
width, height,
|
||||||
width, height,
|
width, height,
|
||||||
gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
|
has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
|
||||||
gdk_pixbuf_get_rowstride (pixbuf),
|
rowstride,
|
||||||
gdk_pixbuf_get_pixels (pixbuf));
|
data);
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CoglHandle
|
||||||
|
pixbuf_to_cogl_handle (GdkPixbuf *pixbuf,
|
||||||
|
gboolean add_padding)
|
||||||
|
{
|
||||||
|
return data_to_cogl_handle (gdk_pixbuf_get_pixels (pixbuf),
|
||||||
|
gdk_pixbuf_get_has_alpha (pixbuf),
|
||||||
|
gdk_pixbuf_get_width (pixbuf),
|
||||||
|
gdk_pixbuf_get_height (pixbuf),
|
||||||
|
gdk_pixbuf_get_rowstride (pixbuf),
|
||||||
|
add_padding);
|
||||||
|
}
|
||||||
|
|
||||||
static cairo_surface_t *
|
static cairo_surface_t *
|
||||||
pixbuf_to_cairo_surface (GdkPixbuf *pixbuf)
|
pixbuf_to_cairo_surface (GdkPixbuf *pixbuf)
|
||||||
{
|
{
|
||||||
@ -1408,10 +1421,7 @@ st_texture_cache_load_from_raw (StTextureCache *cache,
|
|||||||
texdata = g_hash_table_lookup (cache->priv->keyed_cache, key);
|
texdata = g_hash_table_lookup (cache->priv->keyed_cache, key);
|
||||||
if (texdata == NULL)
|
if (texdata == NULL)
|
||||||
{
|
{
|
||||||
texdata = cogl_texture_new_from_data (width, height, COGL_TEXTURE_NONE,
|
texdata = data_to_cogl_handle (data, has_alpha, width, height, rowstride, TRUE);
|
||||||
has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
|
|
||||||
COGL_PIXEL_FORMAT_ANY,
|
|
||||||
rowstride, data);
|
|
||||||
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata);
|
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user