mirror of
https://github.com/brl/mutter.git
synced 2025-04-14 06:09:39 +00:00
cogl/matrix-stack: Embed graphene matrices in entry structs
Instead of heap allocated graphene matrices, embed them into the entries themselves. That makes the matrix magazine unused, and thus also remove it. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
This commit is contained in:
parent
3cb59050f3
commit
d03ffe1e97
@ -102,7 +102,7 @@ typedef struct _CoglMatrixEntryMultiply
|
|||||||
{
|
{
|
||||||
CoglMatrixEntry _parent_data;
|
CoglMatrixEntry _parent_data;
|
||||||
|
|
||||||
graphene_matrix_t *matrix;
|
graphene_matrix_t matrix;
|
||||||
|
|
||||||
} CoglMatrixEntryMultiply;
|
} CoglMatrixEntryMultiply;
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ typedef struct _CoglMatrixEntryLoad
|
|||||||
{
|
{
|
||||||
CoglMatrixEntry _parent_data;
|
CoglMatrixEntry _parent_data;
|
||||||
|
|
||||||
graphene_matrix_t *matrix;
|
graphene_matrix_t matrix;
|
||||||
|
|
||||||
} CoglMatrixEntryLoad;
|
} CoglMatrixEntryLoad;
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ typedef struct _CoglMatrixEntrySave
|
|||||||
{
|
{
|
||||||
CoglMatrixEntry _parent_data;
|
CoglMatrixEntry _parent_data;
|
||||||
|
|
||||||
graphene_matrix_t *cache;
|
graphene_matrix_t cache;
|
||||||
gboolean cache_valid;
|
gboolean cache_valid;
|
||||||
|
|
||||||
} CoglMatrixEntrySave;
|
} CoglMatrixEntrySave;
|
||||||
|
@ -52,7 +52,6 @@ COGL_GTYPE_DEFINE_BOXED (MatrixEntry, matrix_entry,
|
|||||||
cogl_matrix_entry_unref);
|
cogl_matrix_entry_unref);
|
||||||
|
|
||||||
static CoglMagazine *cogl_matrix_stack_magazine;
|
static CoglMagazine *cogl_matrix_stack_magazine;
|
||||||
static CoglMagazine *cogl_matrix_stack_matrices_magazine;
|
|
||||||
|
|
||||||
/* XXX: Note: this leaves entry->parent uninitialized! */
|
/* XXX: Note: this leaves entry->parent uninitialized! */
|
||||||
static CoglMatrixEntry *
|
static CoglMatrixEntry *
|
||||||
@ -209,11 +208,7 @@ cogl_matrix_stack_multiply (CoglMatrixStack *stack,
|
|||||||
CoglMatrixEntryMultiply *entry;
|
CoglMatrixEntryMultiply *entry;
|
||||||
|
|
||||||
entry = _cogl_matrix_stack_push_operation (stack, COGL_MATRIX_OP_MULTIPLY);
|
entry = _cogl_matrix_stack_push_operation (stack, COGL_MATRIX_OP_MULTIPLY);
|
||||||
|
graphene_matrix_init_from_matrix (&entry->matrix, matrix);
|
||||||
entry->matrix =
|
|
||||||
_cogl_magazine_chunk_alloc (cogl_matrix_stack_matrices_magazine);
|
|
||||||
|
|
||||||
cogl_matrix_init_from_array (entry->matrix, (float *)matrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -225,11 +220,7 @@ cogl_matrix_stack_set (CoglMatrixStack *stack,
|
|||||||
entry =
|
entry =
|
||||||
_cogl_matrix_stack_push_replacement_entry (stack,
|
_cogl_matrix_stack_push_replacement_entry (stack,
|
||||||
COGL_MATRIX_OP_LOAD);
|
COGL_MATRIX_OP_LOAD);
|
||||||
|
graphene_matrix_init_from_matrix (&entry->matrix, matrix);
|
||||||
entry->matrix =
|
|
||||||
_cogl_magazine_chunk_alloc (cogl_matrix_stack_matrices_magazine);
|
|
||||||
|
|
||||||
cogl_matrix_init_from_array (entry->matrix, (float *)matrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -247,11 +238,8 @@ cogl_matrix_stack_frustum (CoglMatrixStack *stack,
|
|||||||
_cogl_matrix_stack_push_replacement_entry (stack,
|
_cogl_matrix_stack_push_replacement_entry (stack,
|
||||||
COGL_MATRIX_OP_LOAD);
|
COGL_MATRIX_OP_LOAD);
|
||||||
|
|
||||||
entry->matrix =
|
cogl_matrix_init_identity (&entry->matrix);
|
||||||
_cogl_magazine_chunk_alloc (cogl_matrix_stack_matrices_magazine);
|
cogl_matrix_frustum (&entry->matrix,
|
||||||
|
|
||||||
cogl_matrix_init_identity (entry->matrix);
|
|
||||||
cogl_matrix_frustum (entry->matrix,
|
|
||||||
left, right, bottom, top,
|
left, right, bottom, top,
|
||||||
z_near, z_far);
|
z_near, z_far);
|
||||||
}
|
}
|
||||||
@ -268,12 +256,8 @@ cogl_matrix_stack_perspective (CoglMatrixStack *stack,
|
|||||||
entry =
|
entry =
|
||||||
_cogl_matrix_stack_push_replacement_entry (stack,
|
_cogl_matrix_stack_push_replacement_entry (stack,
|
||||||
COGL_MATRIX_OP_LOAD);
|
COGL_MATRIX_OP_LOAD);
|
||||||
|
cogl_matrix_init_identity (&entry->matrix);
|
||||||
entry->matrix =
|
cogl_matrix_perspective (&entry->matrix,
|
||||||
_cogl_magazine_chunk_alloc (cogl_matrix_stack_matrices_magazine);
|
|
||||||
|
|
||||||
cogl_matrix_init_identity (entry->matrix);
|
|
||||||
cogl_matrix_perspective (entry->matrix,
|
|
||||||
fov_y, aspect, z_near, z_far);
|
fov_y, aspect, z_near, z_far);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,12 +275,8 @@ cogl_matrix_stack_orthographic (CoglMatrixStack *stack,
|
|||||||
entry =
|
entry =
|
||||||
_cogl_matrix_stack_push_replacement_entry (stack,
|
_cogl_matrix_stack_push_replacement_entry (stack,
|
||||||
COGL_MATRIX_OP_LOAD);
|
COGL_MATRIX_OP_LOAD);
|
||||||
|
cogl_matrix_init_identity (&entry->matrix);
|
||||||
entry->matrix =
|
cogl_matrix_orthographic (&entry->matrix,
|
||||||
_cogl_magazine_chunk_alloc (cogl_matrix_stack_matrices_magazine);
|
|
||||||
|
|
||||||
cogl_matrix_init_identity (entry->matrix);
|
|
||||||
cogl_matrix_orthographic (entry->matrix,
|
|
||||||
x_1, y_1, x_2, y_2, near, far);
|
x_1, y_1, x_2, y_2, near, far);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,40 +309,6 @@ cogl_matrix_entry_unref (CoglMatrixEntry *entry)
|
|||||||
for (; entry && --entry->ref_count <= 0; entry = parent)
|
for (; entry && --entry->ref_count <= 0; entry = parent)
|
||||||
{
|
{
|
||||||
parent = entry->parent;
|
parent = entry->parent;
|
||||||
|
|
||||||
switch (entry->op)
|
|
||||||
{
|
|
||||||
case COGL_MATRIX_OP_LOAD_IDENTITY:
|
|
||||||
case COGL_MATRIX_OP_TRANSLATE:
|
|
||||||
case COGL_MATRIX_OP_ROTATE:
|
|
||||||
case COGL_MATRIX_OP_ROTATE_EULER:
|
|
||||||
case COGL_MATRIX_OP_SCALE:
|
|
||||||
break;
|
|
||||||
case COGL_MATRIX_OP_MULTIPLY:
|
|
||||||
{
|
|
||||||
CoglMatrixEntryMultiply *multiply =
|
|
||||||
(CoglMatrixEntryMultiply *)entry;
|
|
||||||
_cogl_magazine_chunk_free (cogl_matrix_stack_matrices_magazine,
|
|
||||||
multiply->matrix);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case COGL_MATRIX_OP_LOAD:
|
|
||||||
{
|
|
||||||
CoglMatrixEntryLoad *load = (CoglMatrixEntryLoad *)entry;
|
|
||||||
_cogl_magazine_chunk_free (cogl_matrix_stack_matrices_magazine,
|
|
||||||
load->matrix);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case COGL_MATRIX_OP_SAVE:
|
|
||||||
{
|
|
||||||
CoglMatrixEntrySave *save = (CoglMatrixEntrySave *)entry;
|
|
||||||
if (save->cache_valid)
|
|
||||||
_cogl_magazine_chunk_free (cogl_matrix_stack_matrices_magazine,
|
|
||||||
save->cache);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_cogl_magazine_chunk_free (cogl_matrix_stack_magazine, entry);
|
_cogl_magazine_chunk_free (cogl_matrix_stack_magazine, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -444,7 +390,7 @@ cogl_matrix_entry_get (CoglMatrixEntry *entry,
|
|||||||
{
|
{
|
||||||
CoglMatrixEntryLoad *load = (CoglMatrixEntryLoad *)current;
|
CoglMatrixEntryLoad *load = (CoglMatrixEntryLoad *)current;
|
||||||
_cogl_matrix_init_from_matrix_without_inverse (matrix,
|
_cogl_matrix_init_from_matrix_without_inverse (matrix,
|
||||||
load->matrix);
|
&load->matrix);
|
||||||
goto initialized;
|
goto initialized;
|
||||||
}
|
}
|
||||||
case COGL_MATRIX_OP_SAVE:
|
case COGL_MATRIX_OP_SAVE:
|
||||||
@ -452,13 +398,10 @@ cogl_matrix_entry_get (CoglMatrixEntry *entry,
|
|||||||
CoglMatrixEntrySave *save = (CoglMatrixEntrySave *)current;
|
CoglMatrixEntrySave *save = (CoglMatrixEntrySave *)current;
|
||||||
if (!save->cache_valid)
|
if (!save->cache_valid)
|
||||||
{
|
{
|
||||||
CoglMagazine *matrices_magazine =
|
cogl_matrix_entry_get (current->parent, &save->cache);
|
||||||
cogl_matrix_stack_matrices_magazine;
|
|
||||||
save->cache = _cogl_magazine_chunk_alloc (matrices_magazine);
|
|
||||||
cogl_matrix_entry_get (current->parent, save->cache);
|
|
||||||
save->cache_valid = TRUE;
|
save->cache_valid = TRUE;
|
||||||
}
|
}
|
||||||
_cogl_matrix_init_from_matrix_without_inverse (matrix, save->cache);
|
_cogl_matrix_init_from_matrix_without_inverse (matrix, &save->cache);
|
||||||
goto initialized;
|
goto initialized;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -483,12 +426,12 @@ initialized:
|
|||||||
case COGL_MATRIX_OP_LOAD:
|
case COGL_MATRIX_OP_LOAD:
|
||||||
{
|
{
|
||||||
CoglMatrixEntryLoad *load = (CoglMatrixEntryLoad *)entry;
|
CoglMatrixEntryLoad *load = (CoglMatrixEntryLoad *)entry;
|
||||||
return load->matrix;
|
return &load->matrix;
|
||||||
}
|
}
|
||||||
case COGL_MATRIX_OP_SAVE:
|
case COGL_MATRIX_OP_SAVE:
|
||||||
{
|
{
|
||||||
CoglMatrixEntrySave *save = (CoglMatrixEntrySave *)entry;
|
CoglMatrixEntrySave *save = (CoglMatrixEntrySave *)entry;
|
||||||
return save->cache;
|
return &save->cache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_warn_if_reached ();
|
g_warn_if_reached ();
|
||||||
@ -574,7 +517,7 @@ initialized:
|
|||||||
{
|
{
|
||||||
CoglMatrixEntryMultiply *multiply =
|
CoglMatrixEntryMultiply *multiply =
|
||||||
(CoglMatrixEntryMultiply *)children[i];
|
(CoglMatrixEntryMultiply *)children[i];
|
||||||
cogl_matrix_multiply (matrix, matrix, multiply->matrix);
|
cogl_matrix_multiply (matrix, matrix, &multiply->matrix);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -623,8 +566,6 @@ cogl_matrix_stack_new (CoglContext *ctx)
|
|||||||
{
|
{
|
||||||
cogl_matrix_stack_magazine =
|
cogl_matrix_stack_magazine =
|
||||||
_cogl_magazine_new (sizeof (CoglMatrixEntryFull), 20);
|
_cogl_magazine_new (sizeof (CoglMatrixEntryFull), 20);
|
||||||
cogl_matrix_stack_matrices_magazine =
|
|
||||||
_cogl_magazine_new (sizeof (graphene_matrix_t), 20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stack->context = ctx;
|
stack->context = ctx;
|
||||||
@ -852,7 +793,7 @@ cogl_matrix_entry_equal (CoglMatrixEntry *entry0,
|
|||||||
{
|
{
|
||||||
CoglMatrixEntryMultiply *mult0 = (CoglMatrixEntryMultiply *)entry0;
|
CoglMatrixEntryMultiply *mult0 = (CoglMatrixEntryMultiply *)entry0;
|
||||||
CoglMatrixEntryMultiply *mult1 = (CoglMatrixEntryMultiply *)entry1;
|
CoglMatrixEntryMultiply *mult1 = (CoglMatrixEntryMultiply *)entry1;
|
||||||
if (!cogl_matrix_equal (mult0->matrix, mult1->matrix))
|
if (!cogl_matrix_equal (&mult0->matrix, &mult1->matrix))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -863,7 +804,7 @@ cogl_matrix_entry_equal (CoglMatrixEntry *entry0,
|
|||||||
/* There's no need to check any further since an
|
/* There's no need to check any further since an
|
||||||
* _OP_LOAD makes all the ancestors redundant as far as
|
* _OP_LOAD makes all the ancestors redundant as far as
|
||||||
* the final matrix value is concerned. */
|
* the final matrix value is concerned. */
|
||||||
return cogl_matrix_equal (load0->matrix, load1->matrix);
|
return cogl_matrix_equal (&load0->matrix, &load1->matrix);
|
||||||
}
|
}
|
||||||
case COGL_MATRIX_OP_SAVE:
|
case COGL_MATRIX_OP_SAVE:
|
||||||
/* We skip over saves above so we shouldn't see save entries */
|
/* We skip over saves above so we shouldn't see save entries */
|
||||||
@ -949,14 +890,14 @@ cogl_debug_matrix_entry_print (CoglMatrixEntry *entry)
|
|||||||
{
|
{
|
||||||
CoglMatrixEntryMultiply *mult = (CoglMatrixEntryMultiply *)entry;
|
CoglMatrixEntryMultiply *mult = (CoglMatrixEntryMultiply *)entry;
|
||||||
g_print (" MULT:\n");
|
g_print (" MULT:\n");
|
||||||
_cogl_matrix_prefix_print (" ", mult->matrix);
|
_cogl_matrix_prefix_print (" ", &mult->matrix);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case COGL_MATRIX_OP_LOAD:
|
case COGL_MATRIX_OP_LOAD:
|
||||||
{
|
{
|
||||||
CoglMatrixEntryLoad *load = (CoglMatrixEntryLoad *)entry;
|
CoglMatrixEntryLoad *load = (CoglMatrixEntryLoad *)entry;
|
||||||
g_print (" LOAD:\n");
|
g_print (" LOAD:\n");
|
||||||
_cogl_matrix_prefix_print (" ", load->matrix);
|
_cogl_matrix_prefix_print (" ", &load->matrix);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case COGL_MATRIX_OP_SAVE:
|
case COGL_MATRIX_OP_SAVE:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user