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>
This commit is contained in:
parent
dd13dd06ee
commit
67355db150
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.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);
|
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
|
/* 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
|
* 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
|
* array if \keep_empty is false. \out_num is the number of entries in the
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "shl_dlist.h"
|
#include "shl_dlist.h"
|
||||||
#include "shl_hashtable.h"
|
#include "shl_hashtable.h"
|
||||||
|
#include "shl_misc.h"
|
||||||
#include "static_gl.h"
|
#include "static_gl.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "uterm_video.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 */
|
/* 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)
|
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
|
* valid texture size that is big enough to hold as many glyphs as
|
||||||
* possible but at least 1 */
|
* possible but at least 1 */
|
||||||
try_next:
|
try_next:
|
||||||
width = next_pow2(FONT_WIDTH(txt) * newsize);
|
width = shl_next_pow2(FONT_WIDTH(txt) * newsize);
|
||||||
height = next_pow2(FONT_HEIGHT(txt));
|
height = shl_next_pow2(FONT_HEIGHT(txt));
|
||||||
|
|
||||||
gl_clear_error();
|
gl_clear_error();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user