diff options
author | Ray Strode <rstrode@redhat.com> | 2013-06-14 16:11:30 -0400 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2013-07-01 07:28:32 -0400 |
commit | 15e01152da335f5a9e7617674ffa54cb1bdef957 (patch) | |
tree | c0a31699e0a5a2345985ad6bd74d6d9c1ea5786a | |
parent | 2103ff6a5c62cae7bb82da4ad3f41fbeb7c088c7 (diff) | |
download | mutter-15e01152da335f5a9e7617674ffa54cb1bdef957.tar.gz |
background: downscale background to fit in texture limits
Some cards have 2k texture limits, which can be smaller than
commonly sized backgrounds.
This commit downscales the background in this situation, so that
it won't fail to load.
https://bugzilla.gnome.org/show_bug.cgi?id=702283
-rw-r--r-- | src/compositor/meta-background.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c index fca5dce60..35ca45c53 100644 --- a/src/compositor/meta-background.c +++ b/src/compositor/meta-background.c @@ -32,6 +32,8 @@ #include <clutter/clutter.h> +#include <GL/gl.h> + #include "cogl-utils.h" #include "compositor-private.h" #include "mutter-enum-types.h" @@ -971,6 +973,7 @@ load_file (GTask *task, { GError *error = NULL; GdkPixbuf *pixbuf; + int max_texture_size = 0; pixbuf = gdk_pixbuf_new_from_file (task_data->filename, &error); @@ -981,6 +984,33 @@ load_file (GTask *task, return; } + glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_texture_size); + + if (glGetError () != GL_NO_ERROR) + max_texture_size = 0; + + if (max_texture_size > 0) { + double width, height; + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + + if (width > max_texture_size || height > max_texture_size) { + GdkPixbuf *scaled_pixbuf; + + if (width > height) { + width = max_texture_size; + height *= max_texture_size / width; + } else { + width *= max_texture_size / height; + height = max_texture_size; + } + scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); + g_object_unref (pixbuf); + pixbuf = scaled_pixbuf; + } + } + g_task_return_pointer (task, pixbuf, (GDestroyNotify) g_object_unref); } |