cogl-atlas: Make the cogl_atlas_* API internal

This just adds an underscore to every entry point for the CoglAtlas
API so that it's not exported.
This commit is contained in:
Neil Roberts 2010-02-03 19:54:12 +00:00
parent 145cc9d3df
commit 5063f4669c
4 changed files with 132 additions and 131 deletions

View File

@ -244,18 +244,18 @@ _cogl_atlas_texture_remove_from_atlas (CoglAtlasTexture *atlas_tex)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
cogl_atlas_remove_rectangle (ctx->atlas, &atlas_tex->rectangle); _cogl_atlas_remove_rectangle (ctx->atlas, &atlas_tex->rectangle);
COGL_NOTE (ATLAS, "Removed rectangle sized %ix%i", COGL_NOTE (ATLAS, "Removed rectangle sized %ix%i",
atlas_tex->rectangle.width, atlas_tex->rectangle.width,
atlas_tex->rectangle.height); atlas_tex->rectangle.height);
COGL_NOTE (ATLAS, "Atlas is %ix%i, has %i textures and is %i%% waste", COGL_NOTE (ATLAS, "Atlas is %ix%i, has %i textures and is %i%% waste",
cogl_atlas_get_width (ctx->atlas), _cogl_atlas_get_width (ctx->atlas),
cogl_atlas_get_height (ctx->atlas), _cogl_atlas_get_height (ctx->atlas),
cogl_atlas_get_n_rectangles (ctx->atlas), _cogl_atlas_get_n_rectangles (ctx->atlas),
cogl_atlas_get_remaining_space (ctx->atlas) * 100 / _cogl_atlas_get_remaining_space (ctx->atlas) * 100 /
(cogl_atlas_get_width (ctx->atlas) * (_cogl_atlas_get_width (ctx->atlas) *
cogl_atlas_get_height (ctx->atlas))); _cogl_atlas_get_height (ctx->atlas)));
atlas_tex->in_atlas = FALSE; atlas_tex->in_atlas = FALSE;
} }
@ -730,16 +730,16 @@ _cogl_atlas_texture_create_atlas (guint atlas_width,
the textures */ the textures */
while (atlas_width < max_texture_size && atlas_height < max_texture_size) while (atlas_width < max_texture_size && atlas_height < max_texture_size)
{ {
CoglAtlas *new_atlas = cogl_atlas_new (atlas_width, atlas_height, NULL); CoglAtlas *new_atlas = _cogl_atlas_new (atlas_width, atlas_height, NULL);
guint i; guint i;
/* Add all of the textures and keep track of the new position */ /* Add all of the textures and keep track of the new position */
for (i = 0; i < n_textures; i++) for (i = 0; i < n_textures; i++)
if (!cogl_atlas_add_rectangle (new_atlas, if (!_cogl_atlas_add_rectangle (new_atlas,
textures[i].texture->rectangle.width, textures[i].texture->rectangle.width,
textures[i].texture->rectangle.height, textures[i].texture->rectangle.height,
textures[i].texture, textures[i].texture,
&textures[i].new_position)) &textures[i].new_position))
break; break;
/* If the atlas can contain all of the textures then we have a /* If the atlas can contain all of the textures then we have a
@ -747,7 +747,7 @@ _cogl_atlas_texture_create_atlas (guint atlas_width,
if (i >= n_textures) if (i >= n_textures)
return new_atlas; return new_atlas;
cogl_atlas_free (new_atlas); _cogl_atlas_free (new_atlas);
_cogl_atlas_texture_get_next_size (&atlas_width, &atlas_height); _cogl_atlas_texture_get_next_size (&atlas_width, &atlas_height);
} }
@ -785,17 +785,17 @@ _cogl_atlas_texture_reserve_space (CoglAtlasTexture *new_sub_tex,
_COGL_GET_CONTEXT (ctx, FALSE); _COGL_GET_CONTEXT (ctx, FALSE);
/* Check if we can fit the rectangle into the existing atlas */ /* Check if we can fit the rectangle into the existing atlas */
if (ctx->atlas && cogl_atlas_add_rectangle (ctx->atlas, width, height, if (ctx->atlas && _cogl_atlas_add_rectangle (ctx->atlas, width, height,
new_sub_tex, new_sub_tex,
&new_sub_tex->rectangle)) &new_sub_tex->rectangle))
{ {
COGL_NOTE (ATLAS, "Atlas is %ix%i, has %i textures and is %i%% waste", COGL_NOTE (ATLAS, "Atlas is %ix%i, has %i textures and is %i%% waste",
cogl_atlas_get_width (ctx->atlas), _cogl_atlas_get_width (ctx->atlas),
cogl_atlas_get_height (ctx->atlas), _cogl_atlas_get_height (ctx->atlas),
cogl_atlas_get_n_rectangles (ctx->atlas), _cogl_atlas_get_n_rectangles (ctx->atlas),
cogl_atlas_get_remaining_space (ctx->atlas) * 100 / _cogl_atlas_get_remaining_space (ctx->atlas) * 100 /
(cogl_atlas_get_width (ctx->atlas) * (_cogl_atlas_get_width (ctx->atlas) *
cogl_atlas_get_height (ctx->atlas))); _cogl_atlas_get_height (ctx->atlas)));
return TRUE; return TRUE;
} }
@ -807,10 +807,11 @@ _cogl_atlas_texture_reserve_space (CoglAtlasTexture *new_sub_tex,
data.textures = g_malloc (sizeof (CoglAtlasTextureRepositionData)); data.textures = g_malloc (sizeof (CoglAtlasTextureRepositionData));
else else
{ {
data.textures = g_malloc (sizeof (CoglAtlasTextureRepositionData) * data.textures =
(cogl_atlas_get_n_rectangles (ctx->atlas) + 1)); g_malloc (sizeof (CoglAtlasTextureRepositionData) *
cogl_atlas_foreach (ctx->atlas, _cogl_atlas_texture_get_rectangles_cb, (_cogl_atlas_get_n_rectangles (ctx->atlas) + 1));
&data); _cogl_atlas_foreach (ctx->atlas, _cogl_atlas_texture_get_rectangles_cb,
&data);
} }
/* Add the new rectangle as a dummy texture so that it can be /* Add the new rectangle as a dummy texture so that it can be
@ -827,13 +828,13 @@ _cogl_atlas_texture_reserve_space (CoglAtlasTexture *new_sub_tex,
/* Try to create a new atlas that can contain all of the textures */ /* Try to create a new atlas that can contain all of the textures */
if (ctx->atlas) if (ctx->atlas)
{ {
atlas_width = cogl_atlas_get_width (ctx->atlas); atlas_width = _cogl_atlas_get_width (ctx->atlas);
atlas_height = cogl_atlas_get_height (ctx->atlas); atlas_height = _cogl_atlas_get_height (ctx->atlas);
/* If there is enough space in the existing for the new /* If there is enough space in the existing for the new
rectangle in the existing atlas we'll start with the same rectangle in the existing atlas we'll start with the same
size, otherwise we'll immediately double it */ size, otherwise we'll immediately double it */
if (cogl_atlas_get_remaining_space (ctx->atlas) < width * height) if (_cogl_atlas_get_remaining_space (ctx->atlas) < width * height)
_cogl_atlas_texture_get_next_size (&atlas_width, &atlas_height); _cogl_atlas_texture_get_next_size (&atlas_width, &atlas_height);
} }
else else
@ -856,21 +857,21 @@ _cogl_atlas_texture_reserve_space (CoglAtlasTexture *new_sub_tex,
{ {
/* We need to migrate the existing textures into a new texture */ /* We need to migrate the existing textures into a new texture */
new_tex = new_tex =
_cogl_texture_2d_new_with_size (cogl_atlas_get_width (new_atlas), _cogl_texture_2d_new_with_size (_cogl_atlas_get_width (new_atlas),
cogl_atlas_get_height (new_atlas), _cogl_atlas_get_height (new_atlas),
COGL_TEXTURE_NONE, COGL_TEXTURE_NONE,
COGL_PIXEL_FORMAT_RGBA_8888); COGL_PIXEL_FORMAT_RGBA_8888);
COGL_NOTE (ATLAS, COGL_NOTE (ATLAS,
"Atlas %s with size %ix%i", "Atlas %s with size %ix%i",
ctx->atlas == NULL || ctx->atlas == NULL ||
cogl_atlas_get_width (ctx->atlas) != _cogl_atlas_get_width (ctx->atlas) !=
cogl_atlas_get_width (new_atlas) || _cogl_atlas_get_width (new_atlas) ||
cogl_atlas_get_height (ctx->atlas) != _cogl_atlas_get_height (ctx->atlas) !=
cogl_atlas_get_height (new_atlas) ? _cogl_atlas_get_height (new_atlas) ?
"resized" : "reorganized", "resized" : "reorganized",
cogl_atlas_get_width (new_atlas), _cogl_atlas_get_width (new_atlas),
cogl_atlas_get_height (new_atlas)); _cogl_atlas_get_height (new_atlas));
if (ctx->atlas) if (ctx->atlas)
{ {
@ -881,7 +882,7 @@ _cogl_atlas_texture_reserve_space (CoglAtlasTexture *new_sub_tex,
ctx->atlas_texture, ctx->atlas_texture,
new_tex, new_tex,
new_sub_tex); new_sub_tex);
cogl_atlas_free (ctx->atlas); _cogl_atlas_free (ctx->atlas);
cogl_handle_unref (ctx->atlas_texture); cogl_handle_unref (ctx->atlas_texture);
} }
else else
@ -893,12 +894,12 @@ _cogl_atlas_texture_reserve_space (CoglAtlasTexture *new_sub_tex,
ctx->atlas_texture = new_tex; ctx->atlas_texture = new_tex;
COGL_NOTE (ATLAS, "Atlas is %ix%i, has %i textures and is %i%% waste", COGL_NOTE (ATLAS, "Atlas is %ix%i, has %i textures and is %i%% waste",
cogl_atlas_get_width (ctx->atlas), _cogl_atlas_get_width (ctx->atlas),
cogl_atlas_get_height (ctx->atlas), _cogl_atlas_get_height (ctx->atlas),
cogl_atlas_get_n_rectangles (ctx->atlas), _cogl_atlas_get_n_rectangles (ctx->atlas),
cogl_atlas_get_remaining_space (ctx->atlas) * 100 / _cogl_atlas_get_remaining_space (ctx->atlas) * 100 /
(cogl_atlas_get_width (ctx->atlas) * (_cogl_atlas_get_width (ctx->atlas) *
cogl_atlas_get_height (ctx->atlas))); _cogl_atlas_get_height (ctx->atlas)));
ret = TRUE; ret = TRUE;
} }
@ -994,7 +995,7 @@ _cogl_atlas_texture_new_from_bitmap (CoglHandle bmp_handle,
&gl_format, &gl_format,
&gl_type)) &gl_type))
{ {
cogl_atlas_remove_rectangle (ctx->atlas, &atlas_tex->rectangle); _cogl_atlas_remove_rectangle (ctx->atlas, &atlas_tex->rectangle);
g_free (atlas_tex); g_free (atlas_tex);
return COGL_INVALID_HANDLE; return COGL_INVALID_HANDLE;
} }

View File

@ -46,7 +46,7 @@
the atlas */ the atlas */
#include <cairo.h> #include <cairo.h>
static void cogl_atlas_dump_image (CoglAtlas *atlas); static void _cogl_atlas_dump_image (CoglAtlas *atlas);
#endif /* COGL_ENABLE_DEBUG */ #endif /* COGL_ENABLE_DEBUG */
@ -107,23 +107,23 @@ struct _CoglAtlasStackEntry
}; };
static CoglAtlasNode * static CoglAtlasNode *
cogl_atlas_node_new (void) _cogl_atlas_node_new (void)
{ {
return g_slice_new (CoglAtlasNode); return g_slice_new (CoglAtlasNode);
} }
static void static void
cogl_atlas_node_free (CoglAtlasNode *node) _cogl_atlas_node_free (CoglAtlasNode *node)
{ {
g_slice_free (CoglAtlasNode, node); g_slice_free (CoglAtlasNode, node);
} }
CoglAtlas * CoglAtlas *
cogl_atlas_new (guint width, guint height, _cogl_atlas_new (guint width, guint height,
GDestroyNotify value_destroy_func) GDestroyNotify value_destroy_func)
{ {
CoglAtlas *atlas = g_new (CoglAtlas, 1); CoglAtlas *atlas = g_new (CoglAtlas, 1);
CoglAtlasNode *root = cogl_atlas_node_new (); CoglAtlasNode *root = _cogl_atlas_node_new ();
root->type = COGL_ATLAS_EMPTY_LEAF; root->type = COGL_ATLAS_EMPTY_LEAF;
root->parent = NULL; root->parent = NULL;
@ -141,9 +141,9 @@ cogl_atlas_new (guint width, guint height,
} }
static CoglAtlasStackEntry * static CoglAtlasStackEntry *
cogl_atlas_stack_push (CoglAtlasStackEntry *stack, _cogl_atlas_stack_push (CoglAtlasStackEntry *stack,
CoglAtlasNode *node, CoglAtlasNode *node,
gboolean next_index) gboolean next_index)
{ {
CoglAtlasStackEntry *new_entry = g_slice_new (CoglAtlasStackEntry); CoglAtlasStackEntry *new_entry = g_slice_new (CoglAtlasStackEntry);
@ -155,7 +155,7 @@ cogl_atlas_stack_push (CoglAtlasStackEntry *stack,
} }
static CoglAtlasStackEntry * static CoglAtlasStackEntry *
cogl_atlas_stack_pop (CoglAtlasStackEntry *stack) _cogl_atlas_stack_pop (CoglAtlasStackEntry *stack)
{ {
CoglAtlasStackEntry *next = stack->next; CoglAtlasStackEntry *next = stack->next;
@ -165,8 +165,8 @@ cogl_atlas_stack_pop (CoglAtlasStackEntry *stack)
} }
static CoglAtlasNode * static CoglAtlasNode *
cogl_atlas_node_split_horizontally (CoglAtlasNode *node, _cogl_atlas_node_split_horizontally (CoglAtlasNode *node,
guint left_width) guint left_width)
{ {
/* Splits the node horizontally (according to emacs' definition, not /* Splits the node horizontally (according to emacs' definition, not
vim) by converting it to a branch and adding two new leaf vim) by converting it to a branch and adding two new leaf
@ -179,7 +179,7 @@ cogl_atlas_node_split_horizontally (CoglAtlasNode *node,
if (node->rectangle.width == left_width) if (node->rectangle.width == left_width)
return node; return node;
left_node = cogl_atlas_node_new (); left_node = _cogl_atlas_node_new ();
left_node->type = COGL_ATLAS_EMPTY_LEAF; left_node->type = COGL_ATLAS_EMPTY_LEAF;
left_node->parent = node; left_node->parent = node;
left_node->rectangle.x = node->rectangle.x; left_node->rectangle.x = node->rectangle.x;
@ -188,7 +188,7 @@ cogl_atlas_node_split_horizontally (CoglAtlasNode *node,
left_node->rectangle.height = node->rectangle.height; left_node->rectangle.height = node->rectangle.height;
node->d.branch.left = left_node; node->d.branch.left = left_node;
right_node = cogl_atlas_node_new (); right_node = _cogl_atlas_node_new ();
right_node->type = COGL_ATLAS_EMPTY_LEAF; right_node->type = COGL_ATLAS_EMPTY_LEAF;
right_node->parent = node; right_node->parent = node;
right_node->rectangle.x = node->rectangle.x + left_width; right_node->rectangle.x = node->rectangle.x + left_width;
@ -203,8 +203,8 @@ cogl_atlas_node_split_horizontally (CoglAtlasNode *node,
} }
static CoglAtlasNode * static CoglAtlasNode *
cogl_atlas_node_split_vertically (CoglAtlasNode *node, _cogl_atlas_node_split_vertically (CoglAtlasNode *node,
guint top_height) guint top_height)
{ {
/* Splits the node vertically (according to emacs' definition, not /* Splits the node vertically (according to emacs' definition, not
vim) by converting it to a branch and adding two new leaf vim) by converting it to a branch and adding two new leaf
@ -217,7 +217,7 @@ cogl_atlas_node_split_vertically (CoglAtlasNode *node,
if (node->rectangle.height == top_height) if (node->rectangle.height == top_height)
return node; return node;
top_node = cogl_atlas_node_new (); top_node = _cogl_atlas_node_new ();
top_node->type = COGL_ATLAS_EMPTY_LEAF; top_node->type = COGL_ATLAS_EMPTY_LEAF;
top_node->parent = node; top_node->parent = node;
top_node->rectangle.x = node->rectangle.x; top_node->rectangle.x = node->rectangle.x;
@ -226,7 +226,7 @@ cogl_atlas_node_split_vertically (CoglAtlasNode *node,
top_node->rectangle.height = top_height; top_node->rectangle.height = top_height;
node->d.branch.left = top_node; node->d.branch.left = top_node;
bottom_node = cogl_atlas_node_new (); bottom_node = _cogl_atlas_node_new ();
bottom_node->type = COGL_ATLAS_EMPTY_LEAF; bottom_node->type = COGL_ATLAS_EMPTY_LEAF;
bottom_node->parent = node; bottom_node->parent = node;
bottom_node->rectangle.x = node->rectangle.x; bottom_node->rectangle.x = node->rectangle.x;
@ -241,10 +241,10 @@ cogl_atlas_node_split_vertically (CoglAtlasNode *node,
} }
gboolean gboolean
cogl_atlas_add_rectangle (CoglAtlas *atlas, _cogl_atlas_add_rectangle (CoglAtlas *atlas,
guint width, guint height, guint width, guint height,
gpointer data, gpointer data,
CoglAtlasRectangle *rectangle) CoglAtlasRectangle *rectangle)
{ {
/* Stack of nodes to search in */ /* Stack of nodes to search in */
CoglAtlasStackEntry *node_stack; CoglAtlasStackEntry *node_stack;
@ -255,7 +255,7 @@ cogl_atlas_add_rectangle (CoglAtlas *atlas,
g_return_val_if_fail (width > 0 && height > 0, FALSE); g_return_val_if_fail (width > 0 && height > 0, FALSE);
/* Start with the root node */ /* Start with the root node */
node_stack = cogl_atlas_stack_push (NULL, atlas->root, FALSE); node_stack = _cogl_atlas_stack_push (NULL, atlas->root, FALSE);
/* Depth-first search for an empty node that is big enough */ /* Depth-first search for an empty node that is big enough */
while (node_stack) while (node_stack)
@ -263,7 +263,7 @@ cogl_atlas_add_rectangle (CoglAtlas *atlas,
/* Pop an entry off the stack */ /* Pop an entry off the stack */
CoglAtlasNode *node = node_stack->node; CoglAtlasNode *node = node_stack->node;
int next_index = node_stack->next_index; int next_index = node_stack->next_index;
node_stack = cogl_atlas_stack_pop (node_stack); node_stack = _cogl_atlas_stack_pop (node_stack);
/* Regardless of the type of the node, there's no point /* Regardless of the type of the node, there's no point
descending any further if the new rectangle won't fit within descending any further if the new rectangle won't fit within
@ -281,20 +281,20 @@ cogl_atlas_add_rectangle (CoglAtlas *atlas,
{ {
if (next_index) if (next_index)
/* Try the right branch */ /* Try the right branch */
node_stack = cogl_atlas_stack_push (node_stack, node_stack = _cogl_atlas_stack_push (node_stack,
node->d.branch.right, node->d.branch.right,
0); 0);
else else
{ {
/* Make sure we remember to try the right branch once /* Make sure we remember to try the right branch once
we've finished descending the left branch */ we've finished descending the left branch */
node_stack = cogl_atlas_stack_push (node_stack, node_stack = _cogl_atlas_stack_push (node_stack,
node, node,
1); 1);
/* Try the left branch */ /* Try the left branch */
node_stack = cogl_atlas_stack_push (node_stack, node_stack = _cogl_atlas_stack_push (node_stack,
node->d.branch.left, node->d.branch.left,
0); 0);
} }
} }
} }
@ -302,7 +302,7 @@ cogl_atlas_add_rectangle (CoglAtlas *atlas,
/* Free the stack */ /* Free the stack */
while (node_stack) while (node_stack)
node_stack = cogl_atlas_stack_pop (node_stack); node_stack = _cogl_atlas_stack_pop (node_stack);
if (found_node) if (found_node)
{ {
@ -311,13 +311,13 @@ cogl_atlas_add_rectangle (CoglAtlas *atlas,
if (found_node->rectangle.width - width > if (found_node->rectangle.width - width >
found_node->rectangle.height - height) found_node->rectangle.height - height)
{ {
found_node = cogl_atlas_node_split_horizontally (found_node, width); found_node = _cogl_atlas_node_split_horizontally (found_node, width);
found_node = cogl_atlas_node_split_vertically (found_node, height); found_node = _cogl_atlas_node_split_vertically (found_node, height);
} }
else else
{ {
found_node = cogl_atlas_node_split_vertically (found_node, height); found_node = _cogl_atlas_node_split_vertically (found_node, height);
found_node = cogl_atlas_node_split_horizontally (found_node, width); found_node = _cogl_atlas_node_split_horizontally (found_node, width);
} }
found_node->type = COGL_ATLAS_FILLED_LEAF; found_node->type = COGL_ATLAS_FILLED_LEAF;
@ -333,7 +333,7 @@ cogl_atlas_add_rectangle (CoglAtlas *atlas,
#ifdef COGL_ENABLE_DEBUG #ifdef COGL_ENABLE_DEBUG
if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DUMP_ATLAS_IMAGE)) if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DUMP_ATLAS_IMAGE))
cogl_atlas_dump_image (atlas); _cogl_atlas_dump_image (atlas);
#endif #endif
return TRUE; return TRUE;
@ -343,8 +343,8 @@ cogl_atlas_add_rectangle (CoglAtlas *atlas,
} }
void void
cogl_atlas_remove_rectangle (CoglAtlas *atlas, _cogl_atlas_remove_rectangle (CoglAtlas *atlas,
const CoglAtlasRectangle *rectangle) const CoglAtlasRectangle *rectangle)
{ {
CoglAtlasNode *node = atlas->root; CoglAtlasNode *node = atlas->root;
@ -391,8 +391,8 @@ cogl_atlas_remove_rectangle (CoglAtlas *atlas,
if (node->d.branch.left->type == COGL_ATLAS_EMPTY_LEAF && if (node->d.branch.left->type == COGL_ATLAS_EMPTY_LEAF &&
node->d.branch.right->type == COGL_ATLAS_EMPTY_LEAF) node->d.branch.right->type == COGL_ATLAS_EMPTY_LEAF)
{ {
cogl_atlas_node_free (node->d.branch.left); _cogl_atlas_node_free (node->d.branch.left);
cogl_atlas_node_free (node->d.branch.right); _cogl_atlas_node_free (node->d.branch.right);
node->type = COGL_ATLAS_EMPTY_LEAF; node->type = COGL_ATLAS_EMPTY_LEAF;
} }
else else
@ -407,44 +407,44 @@ cogl_atlas_remove_rectangle (CoglAtlas *atlas,
#ifdef COGL_ENABLE_DEBUG #ifdef COGL_ENABLE_DEBUG
if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DUMP_ATLAS_IMAGE)) if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DUMP_ATLAS_IMAGE))
cogl_atlas_dump_image (atlas); _cogl_atlas_dump_image (atlas);
#endif #endif
} }
guint guint
cogl_atlas_get_width (CoglAtlas *atlas) _cogl_atlas_get_width (CoglAtlas *atlas)
{ {
return atlas->root->rectangle.width; return atlas->root->rectangle.width;
} }
guint guint
cogl_atlas_get_height (CoglAtlas *atlas) _cogl_atlas_get_height (CoglAtlas *atlas)
{ {
return atlas->root->rectangle.height; return atlas->root->rectangle.height;
} }
guint guint
cogl_atlas_get_remaining_space (CoglAtlas *atlas) _cogl_atlas_get_remaining_space (CoglAtlas *atlas)
{ {
return atlas->space_remaining; return atlas->space_remaining;
} }
guint guint
cogl_atlas_get_n_rectangles (CoglAtlas *atlas) _cogl_atlas_get_n_rectangles (CoglAtlas *atlas)
{ {
return atlas->n_rectangles; return atlas->n_rectangles;
} }
static void static void
cogl_atlas_internal_foreach (CoglAtlas *atlas, _cogl_atlas_internal_foreach (CoglAtlas *atlas,
CoglAtlasInternalForeachCb callback, CoglAtlasInternalForeachCb callback,
gpointer data) gpointer data)
{ {
/* Stack of nodes to search in */ /* Stack of nodes to search in */
CoglAtlasStackEntry *node_stack; CoglAtlasStackEntry *node_stack;
/* Start with the root node */ /* Start with the root node */
node_stack = cogl_atlas_stack_push (NULL, atlas->root, 0); node_stack = _cogl_atlas_stack_push (NULL, atlas->root, 0);
/* Iterate all nodes depth-first */ /* Iterate all nodes depth-first */
while (node_stack) while (node_stack)
@ -460,7 +460,7 @@ cogl_atlas_internal_foreach (CoglAtlas *atlas,
node_stack->next_index = 1; node_stack->next_index = 1;
/* Explore the left branch next */ /* Explore the left branch next */
node_stack = cogl_atlas_stack_push (node_stack, node_stack = _cogl_atlas_stack_push (node_stack,
node->d.branch.left, node->d.branch.left,
0); 0);
} }
@ -470,7 +470,7 @@ cogl_atlas_internal_foreach (CoglAtlas *atlas,
node_stack->next_index = 2; node_stack->next_index = 2;
/* Explore the right branch next */ /* Explore the right branch next */
node_stack = cogl_atlas_stack_push (node_stack, node_stack = _cogl_atlas_stack_push (node_stack,
node->d.branch.right, node->d.branch.right,
0); 0);
} }
@ -478,14 +478,14 @@ cogl_atlas_internal_foreach (CoglAtlas *atlas,
{ {
/* We're finished with this node so we can call the callback */ /* We're finished with this node so we can call the callback */
callback (node, data); callback (node, data);
node_stack = cogl_atlas_stack_pop (node_stack); node_stack = _cogl_atlas_stack_pop (node_stack);
} }
break; break;
default: default:
/* Some sort of leaf node, just call the callback */ /* Some sort of leaf node, just call the callback */
callback (node, data); callback (node, data);
node_stack = cogl_atlas_stack_pop (node_stack); node_stack = _cogl_atlas_stack_pop (node_stack);
break; break;
} }
} }
@ -501,7 +501,7 @@ typedef struct _CoglAtlasForeachClosure
} CoglAtlasForeachClosure; } CoglAtlasForeachClosure;
static void static void
cogl_atlas_foreach_cb (CoglAtlasNode *node, gpointer data) _cogl_atlas_foreach_cb (CoglAtlasNode *node, gpointer data)
{ {
CoglAtlasForeachClosure *closure = data; CoglAtlasForeachClosure *closure = data;
@ -510,40 +510,40 @@ cogl_atlas_foreach_cb (CoglAtlasNode *node, gpointer data)
} }
void void
cogl_atlas_foreach (CoglAtlas *atlas, _cogl_atlas_foreach (CoglAtlas *atlas,
CoglAtlasCallback callback, CoglAtlasCallback callback,
gpointer data) gpointer data)
{ {
CoglAtlasForeachClosure closure; CoglAtlasForeachClosure closure;
closure.callback = callback; closure.callback = callback;
closure.data = data; closure.data = data;
cogl_atlas_internal_foreach (atlas, cogl_atlas_foreach_cb, &closure); _cogl_atlas_internal_foreach (atlas, _cogl_atlas_foreach_cb, &closure);
} }
static void static void
cogl_atlas_free_cb (CoglAtlasNode *node, gpointer data) _cogl_atlas_free_cb (CoglAtlasNode *node, gpointer data)
{ {
CoglAtlas *atlas = data; CoglAtlas *atlas = data;
if (node->type == COGL_ATLAS_FILLED_LEAF && atlas->value_destroy_func) if (node->type == COGL_ATLAS_FILLED_LEAF && atlas->value_destroy_func)
atlas->value_destroy_func (node->d.data); atlas->value_destroy_func (node->d.data);
cogl_atlas_node_free (node); _cogl_atlas_node_free (node);
} }
void void
cogl_atlas_free (CoglAtlas *atlas) _cogl_atlas_free (CoglAtlas *atlas)
{ {
cogl_atlas_internal_foreach (atlas, cogl_atlas_free_cb, atlas); _cogl_atlas_internal_foreach (atlas, _cogl_atlas_free_cb, atlas);
g_free (atlas); g_free (atlas);
} }
#ifdef COGL_ENABLE_DEBUG #ifdef COGL_ENABLE_DEBUG
static void static void
cogl_atlas_dump_image_cb (CoglAtlasNode *node, gpointer data) _cogl_atlas_dump_image_cb (CoglAtlasNode *node, gpointer data)
{ {
cairo_t *cr = data; cairo_t *cr = data;
@ -572,7 +572,7 @@ cogl_atlas_dump_image_cb (CoglAtlasNode *node, gpointer data)
} }
static void static void
cogl_atlas_dump_image (CoglAtlas *atlas) _cogl_atlas_dump_image (CoglAtlas *atlas)
{ {
/* This dumps a png to help visualize the atlas. Each leaf rectangle /* This dumps a png to help visualize the atlas. Each leaf rectangle
is drawn with a white outline. Unused leaves are filled in black is drawn with a white outline. Unused leaves are filled in black
@ -580,11 +580,11 @@ cogl_atlas_dump_image (CoglAtlas *atlas)
cairo_surface_t *surface = cairo_surface_t *surface =
cairo_image_surface_create (CAIRO_FORMAT_RGB24, cairo_image_surface_create (CAIRO_FORMAT_RGB24,
cogl_atlas_get_width (atlas), _cogl_atlas_get_width (atlas),
cogl_atlas_get_height (atlas)); _cogl_atlas_get_height (atlas));
cairo_t *cr = cairo_create (surface); cairo_t *cr = cairo_create (surface);
cogl_atlas_internal_foreach (atlas, cogl_atlas_dump_image_cb, cr); _cogl_atlas_internal_foreach (atlas, _cogl_atlas_dump_image_cb, cr);
cairo_destroy (cr); cairo_destroy (cr);

View File

@ -40,37 +40,37 @@ struct _CoglAtlasRectangle
}; };
CoglAtlas * CoglAtlas *
cogl_atlas_new (guint width, guint height, _cogl_atlas_new (guint width, guint height,
GDestroyNotify value_destroy_func); GDestroyNotify value_destroy_func);
gboolean gboolean
cogl_atlas_add_rectangle (CoglAtlas *atlas, _cogl_atlas_add_rectangle (CoglAtlas *atlas,
guint width, guint height, guint width, guint height,
gpointer data, gpointer data,
CoglAtlasRectangle *rectangle); CoglAtlasRectangle *rectangle);
void void
cogl_atlas_remove_rectangle (CoglAtlas *atlas, _cogl_atlas_remove_rectangle (CoglAtlas *atlas,
const CoglAtlasRectangle *rectangle); const CoglAtlasRectangle *rectangle);
guint guint
cogl_atlas_get_width (CoglAtlas *atlas); _cogl_atlas_get_width (CoglAtlas *atlas);
guint guint
cogl_atlas_get_height (CoglAtlas *atlas); _cogl_atlas_get_height (CoglAtlas *atlas);
guint guint
cogl_atlas_get_remaining_space (CoglAtlas *atlas); _cogl_atlas_get_remaining_space (CoglAtlas *atlas);
guint guint
cogl_atlas_get_n_rectangles (CoglAtlas *atlas); _cogl_atlas_get_n_rectangles (CoglAtlas *atlas);
void void
cogl_atlas_foreach (CoglAtlas *atlas, _cogl_atlas_foreach (CoglAtlas *atlas,
CoglAtlasCallback callback, CoglAtlasCallback callback,
gpointer data); gpointer data);
void void
cogl_atlas_free (CoglAtlas *atlas); _cogl_atlas_free (CoglAtlas *atlas);
#endif /* __COGL_ATLAS_H */ #endif /* __COGL_ATLAS_H */

View File

@ -192,7 +192,7 @@ _cogl_destroy_context ()
cogl_handle_unref (_context->default_material); cogl_handle_unref (_context->default_material);
if (_context->atlas) if (_context->atlas)
cogl_atlas_free (_context->atlas); _cogl_atlas_free (_context->atlas);
if (_context->atlas_texture) if (_context->atlas_texture)
cogl_handle_unref (_context->atlas_texture); cogl_handle_unref (_context->atlas_texture);