From 2b5bb06bed2b272ba408d53a471f78c705bf0467 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 6 Aug 2010 18:42:43 +0100 Subject: [PATCH] cogl-atlas: Try the next size when there would be less than 6% waste Previously when the atlas needs to be migrated it would start by trying with the same size as the existing atlas if there is enough space for the new texture. However even if the atlas is completely sorted there will always be some amount of waste so when the atlas needs to grow it would usually end up redundantly trying the same size when it is very unlikely to fit. This patch changes it so that there must be at least 6% waste available after the new texture is added otherwise it will start with the next atlas size. --- clutter/cogl/cogl/cogl-atlas.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/clutter/cogl/cogl/cogl-atlas.c b/clutter/cogl/cogl/cogl-atlas.c index 9676fe014..3c6abf5de 100644 --- a/clutter/cogl/cogl/cogl-atlas.c +++ b/clutter/cogl/cogl/cogl-atlas.c @@ -496,11 +496,13 @@ _cogl_atlas_reserve_space (CoglAtlas *atlas, map_width = _cogl_rectangle_map_get_width (atlas->map); map_height = _cogl_rectangle_map_get_height (atlas->map); - /* If there is enough space in the existing for the new - rectangle in the existing atlas we'll start with the same - size, otherwise we'll immediately double it */ - if (_cogl_rectangle_map_get_remaining_space (atlas->map) < - width * height) + /* If there is enough space in for the new rectangle in the + existing atlas with at least 6% waste we'll start with the + same size, otherwise we'll immediately double it */ + if ((map_width * map_height - + _cogl_rectangle_map_get_remaining_space (atlas->map) + + width * height) * 53 / 50 > + map_width * map_height) _cogl_atlas_get_next_size (&map_width, &map_height); } else