diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-02-18 19:17:49 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2013-02-18 19:17:49 +0100 |
commit | 67355db150b683f02443e5b0ece97c0567c90c3a (patch) | |
tree | 56479bb61299016e368371d47dbc2f7e8e41d4ea | |
parent | dd13dd06ee53574ec92c800d415984bf00ac2ca6 (diff) |
shl: misc: provide shl_next_pow2()
Move the next_pow2() helper to shl_misc.h so we can use it everywhere.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
-rw-r--r-- | src/shl_misc.h | 15 | ||||
-rw-r--r-- | src/text_gltex.c | 19 |
2 files changed, 18 insertions, 16 deletions
diff --git a/src/shl_misc.h b/src/shl_misc.h index 64d4836..2dfa53c 100644 --- a/src/shl_misc.h +++ b/src/shl_misc.h @@ -33,6 +33,7 @@ #include <dirent.h> #include <errno.h> +#include <limits.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> @@ -110,6 +111,20 @@ static inline bool shl_ends_with(const char *str, const char *suffix) return !memcmp(str + len - slen, suffix, slen); } +static inline unsigned long shl_next_pow2(unsigned long num) +{ + unsigned int i; + + if (!num) + return 0; + + --num; + for (i = 1; i < sizeof(unsigned long) * CHAR_BIT; i <<= 1) + num = num | num >> i; + + return num + 1; +} + /* This parses \arg and splits the string into a new allocated array. The array * is stored in \out and is NULL terminated. Empty entries are removed from the * array if \keep_empty is false. \out_num is the number of entries in the diff --git a/src/text_gltex.c b/src/text_gltex.c index 3151ec6..9e864a0 100644 --- a/src/text_gltex.c +++ b/src/text_gltex.c @@ -48,6 +48,7 @@ #include "log.h" #include "shl_dlist.h" #include "shl_hashtable.h" +#include "shl_misc.h" #include "static_gl.h" #include "text.h" #include "uterm_video.h" @@ -263,20 +264,6 @@ static void gltex_unset(struct kmscon_text *txt) } } -static unsigned int next_pow2(unsigned int num) -{ - int i; - - if (!num) - return num; - - --num; - for (i = 1; i < sizeof(unsigned int) * CHAR_BIT; i <<= 1) - num = num | num >> i; - - return num + 1; -} - /* returns an atlas with at least 1 free glyph position; NULL on error */ static struct atlas *get_atlas(struct kmscon_text *txt, unsigned int num) { @@ -318,8 +305,8 @@ static struct atlas *get_atlas(struct kmscon_text *txt, unsigned int num) * valid texture size that is big enough to hold as many glyphs as * possible but at least 1 */ try_next: - width = next_pow2(FONT_WIDTH(txt) * newsize); - height = next_pow2(FONT_HEIGHT(txt)); + width = shl_next_pow2(FONT_WIDTH(txt) * newsize); + height = shl_next_pow2(FONT_HEIGHT(txt)); gl_clear_error(); |