Revert "Use aligned allocators for GtkSnapshot"
authorBenjamin Otte <otte@redhat.com>
Tue, 19 Jun 2018 17:52:52 +0000 (19:52 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 19 Jun 2018 17:52:52 +0000 (19:52 +0200)
This reverts commit c02bc22cc575470aab870599f2781c3781fb75e6.

This code is not necessary.
The bug causing this problem ws prsent in the graphene library.

gsk/gskalloc.c
gtk/gtksnapshot.c
gtk/gtksnapshotprivate.h

index 76d46f5c628e6665b42671b530b8aeb7bb902a17..cf1c03163cef5a15c8800b93fd6f53332e657613 100644 (file)
@@ -24,7 +24,7 @@
 # define aligned_free(x) free (x)
 #endif
 
-/*
+/**
  * gsk_aligned_alloc:
  * @size: the size of the memory to allocate
  * @number: the multiples of @size to allocate
@@ -91,7 +91,7 @@ gsk_aligned_alloc (gsize size,
   return res;
 }
 
-/*
+/**
  * gsk_aligned_alloc0:
  * @size: the size of the memory to allocate
  * @number: the multiples of @size to allocate
@@ -117,7 +117,7 @@ gsk_aligned_alloc0 (gsize size,
   return mem;
 }
 
-/*
+/**
  * gsk_aligned_free:
  * @mem: the memory to deallocate
  *
index ebb885e4fff4550a2602bb55790c61d6966aa937..fc71bbffa7163f5f2db1db7f7c34f0d0052c6d4a 100644 (file)
 
 #include "gsk/gskrendernodeprivate.h"
 
-#include "gsk/gskallocprivate.h"
-
 #include "gtk/gskpango.h"
 
 
-static void gtk_snapshot_state_clear (GtkSnapshotState *state);
-
-/* Returns the smallest power of 2 greater than n, or n if
- * such power does not fit in a guint
- */
-static guint
-g_nearest_pow (gint num)
-{
-  guint n = 1;
-
-  while (n < num && n > 0)
-    n <<= 1;
-
-  return n ? n : num;
-}
-
-typedef struct _GtkRealSnapshotStateArray  GtkRealSnapshotStateArray;
-
-struct _GtkRealSnapshotStateArray
-{
-  GtkSnapshotState *data;
-  guint   len;
-  guint   alloc;
-  gint    ref_count;
-};
-
-static GtkSnapshotStateArray*
-gtk_snapshot_state_array_new (void)
-{
-  GtkRealSnapshotStateArray *array;
-
-  g_return_val_if_fail (sizeof (GtkSnapshotState) % 16 == 0, NULL);
-
-  array = g_slice_new (GtkRealSnapshotStateArray);
-
-  array->data      = NULL;
-  array->len       = 0;
-  array->alloc     = 0;
-  array->ref_count = 1;
-
-  return (GtkSnapshotStateArray *) array;
-}
-
-static GtkSnapshotState *
-gtk_snapshot_state_array_free (GtkSnapshotStateArray *farray)
-{
-  GtkRealSnapshotStateArray *array = (GtkRealSnapshotStateArray*) farray;
-  guint i;
-
-  g_return_val_if_fail (array, NULL);
-
-  for (i = 0; i < array->len; i++)
-    gtk_snapshot_state_clear (&array->data[i]);
-
-  gsk_aligned_free (array->data);
-
-  g_slice_free1 (sizeof (GtkRealSnapshotStateArray), array);
-
-  return NULL;
-}
-
-#define MIN_ARRAY_SIZE 16
-
-static void
-gtk_snapshot_state_array_maybe_expand (GtkRealSnapshotStateArray *array,
-                                       gint                       len)
-{
-  guint want_alloc = sizeof (GtkSnapshotState) * (array->len + len);
-  GtkSnapshotState *new_data;
-
-  if (want_alloc <= array->alloc)
-    return;
-
-  want_alloc = g_nearest_pow (want_alloc);
-  want_alloc = MAX (want_alloc, MIN_ARRAY_SIZE);
-  new_data = gsk_aligned_alloc0 (want_alloc, 1, 16);
-  memcpy (new_data, array->data, sizeof (GtkSnapshotState) * array->len);
-  gsk_aligned_free (array->data);
-  array->data = new_data;
-  array->alloc = want_alloc;
-}
-
-static GtkSnapshotStateArray*
-gtk_snapshot_state_array_remove_index (GtkSnapshotStateArray *farray,
-                                       guint                  index_)
-{
-  GtkRealSnapshotStateArray *array = (GtkRealSnapshotStateArray*) farray;
-
-  g_return_val_if_fail (array, NULL);
-  g_return_val_if_fail (index_ < array->len, NULL);
-
-  gtk_snapshot_state_clear (&array->data[index_]);
-
-  memmove (&array->data[index_],
-           &array->data[index_ + 1],
-           (array->len - index_ - 1) * sizeof (GtkSnapshotState));
-
-  array->len -= 1;
-
-  return farray;
-}
-
-#define gtk_snapshot_state_array_append_val(a,v)       gtk_snapshot_state_array_append_vals (a, &(v), 1)
-
-static GtkSnapshotStateArray*
-gtk_snapshot_state_array_append_vals (GtkSnapshotStateArray *farray,
-                                      gconstpointer          data,
-                                      guint                  len)
-{
-  GtkRealSnapshotStateArray *array = (GtkRealSnapshotStateArray*) farray;
-
-  g_return_val_if_fail (array, NULL);
-
-  if (len == 0)
-    return farray;
-
-  gtk_snapshot_state_array_maybe_expand (array, len);
-
-  memcpy (&array->data[array->len], data,
-          sizeof (GtkSnapshotState) * len);
-
-  array->len += len;
-
-  return farray;
-}
-
-
 /**
  * SECTION:gtksnapshot
  * @Short_description: Auxiliary object for snapshots
@@ -249,9 +120,9 @@ gtk_snapshot_push_state (GtkSnapshot            *snapshot,
   state.start_node_index = snapshot->nodes->len;
   state.n_nodes = 0;
 
-  gtk_snapshot_state_array_append_val (snapshot->state_stack, state);
+  g_array_append_val (snapshot->state_stack, state);
 
-  return &snapshot->state_stack->data[snapshot->state_stack->len - 1];
+  return &g_array_index (snapshot->state_stack, GtkSnapshotState, snapshot->state_stack->len - 1);
 }
 
 static GtkSnapshotState *
@@ -259,7 +130,7 @@ gtk_snapshot_get_current_state (const GtkSnapshot *snapshot)
 {
   g_assert (snapshot->state_stack->len > 0);
 
-  return &snapshot->state_stack->data[snapshot->state_stack->len - 1];
+  return &g_array_index (snapshot->state_stack, GtkSnapshotState, snapshot->state_stack->len - 1);
 }
 
 static GtkSnapshotState *
@@ -267,7 +138,7 @@ gtk_snapshot_get_previous_state (const GtkSnapshot *snapshot)
 {
   g_assert (snapshot->state_stack->len > 1);
 
-  return &snapshot->state_stack->data[snapshot->state_stack->len - 2];
+  return &g_array_index (snapshot->state_stack, GtkSnapshotState, snapshot->state_stack->len - 2);
 }
 
 static void
@@ -289,7 +160,8 @@ gtk_snapshot_new (void)
 
   snapshot = g_object_new (GTK_TYPE_SNAPSHOT, NULL);
 
-  snapshot->state_stack = gtk_snapshot_state_array_new ();
+  snapshot->state_stack = g_array_new (FALSE, TRUE, sizeof (GtkSnapshotState));
+  g_array_set_clear_func (snapshot->state_stack, (GDestroyNotify)gtk_snapshot_state_clear);
   snapshot->nodes = g_ptr_array_new_with_free_func ((GDestroyNotify)gsk_render_node_unref);
 
   gtk_snapshot_push_state (snapshot,
@@ -1053,7 +925,7 @@ gtk_snapshot_pop_internal (GtkSnapshot *snapshot)
                             snapshot->nodes->len - state->n_nodes,
                             state->n_nodes);
 
-  gtk_snapshot_state_array_remove_index (snapshot->state_stack, state_index);
+  g_array_remove_index (snapshot->state_stack, state_index);
 
   return node;
 }
@@ -1083,7 +955,7 @@ gtk_snapshot_to_node (GtkSnapshot *snapshot)
   
   result = gtk_snapshot_pop_internal (snapshot);
 
-  gtk_snapshot_state_array_free (snapshot->state_stack);
+  g_array_free (snapshot->state_stack, TRUE);
   snapshot->state_stack = NULL;
 
   g_ptr_array_free (snapshot->nodes, TRUE);
index 0493491664da7d8593045075998baf18f1840259..b54fb4b7028e37008021716a9561845b89271875 100644 (file)
 G_BEGIN_DECLS
 
 typedef struct _GtkSnapshotState GtkSnapshotState;
-typedef struct _GtkSnapshotStateArray GtkSnapshotStateArray;
-
-/* This is a stripped-down copy of GArray tailored specifically
- * for GtkSnapshotState and guaranteed to be aligned to 16 byte
- * boundaries.
- */
-struct _GtkSnapshotStateArray
-{
-  GtkSnapshotState *data;
-  guint len;
-};
 
 typedef GskRenderNode * (* GtkSnapshotCollectFunc) (GtkSnapshot      *snapshot,
                                                     GtkSnapshotState *state,
@@ -99,7 +88,7 @@ struct _GtkSnapshotState {
 struct _GdkSnapshot {
   GObject                parent_instance; /* it's really GdkSnapshot, but don't tell anyone! */
 
-  GtkSnapshotStateArray *state_stack;
+  GArray                *state_stack;
   GPtrArray             *nodes;
 };