summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Roberts <neil@linux.intel.com>2010-10-05 17:17:53 +0100
committerNeil Roberts <neil@linux.intel.com>2010-10-11 14:41:28 +0100
commitdc472dccec1d3d282342c44af2a538c4817dd08a (patch)
tree1290772a863a52f4532ce56888aabe6008a4c92c
parentb930a102df7e1a07495fdf8eb7fdaa34bb3f66bb (diff)
downloadclutter-dc472dccec1d3d282342c44af2a538c4817dd08a.tar.gz
cogl-texture-2d-sliced: Use the smallest possible waste
When picking a size for the last slice in a texture, Cogl would always pick the biggest power of two size that doesn't create too much waste and is less than or equal to the previous slice size. However this can end up creating a texture that is bigger than needed if there is a smaller power of two. For example, if the maximum waste is 127 (the current default) and we try to create a texture that is 257 pixels wide it will decide that the next power of two (512) is too much waste (255) so it will create the first slice at 256 pixels wide. Then we only have 1 pixel left to allocate but Cogl would pick the next smaller size that has a small enough waste which is 128. But of course 1 is already a power of two so that's redundantly oversized by 127. This patch fixes it so that whenever it finds a size that would be big enough, instead of using exactly that it picks the next power of two up from the size we need to fill. http://bugzilla.clutter-project.org/show_bug.cgi?id=2355 (cherry picked from commit 7e112472b5ad9deea9b0ad1fda47aa16199a780a)
-rw-r--r--clutter/cogl/cogl/cogl-texture-2d-sliced.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/clutter/cogl/cogl/cogl-texture-2d-sliced.c b/clutter/cogl/cogl/cogl-texture-2d-sliced.c
index 51323df8a..f6fd3bf1a 100644
--- a/clutter/cogl/cogl/cogl-texture-2d-sliced.c
+++ b/clutter/cogl/cogl/cogl-texture-2d-sliced.c
@@ -698,6 +698,10 @@ _cogl_pot_slices_for_size (int size_to_fill,
else if (span.size - size_to_fill <= max_waste)
{
/* Yes and waste is small enough */
+ /* Pick the next power of two up from size_to_fill. This can
+ sometimes be less than the span.size that would be chosen
+ otherwise */
+ span.size = _cogl_util_next_p2 (size_to_fill);
span.waste = span.size - size_to_fill;
if (out_spans)
g_array_append_val (out_spans, span);