mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 08:00:42 -05:00
Use a GList instead of a BSD list for CoglPipelineSnippetList
Previously CoglPipelineSnippetList was using the BSD embedded list type with a mini struct to combine the list node with a pointer to the snippet. This is effectively equivalent to just using a GList so we might as well do that. This will help if we eventually want to get rid of cogl-queue.h Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 54a168f3c7829c427d54ab517533bb9f7384d022)
This commit is contained in:
parent
fa0df6ea96
commit
ed510dbe6d
@ -118,11 +118,11 @@ _cogl_pipeline_layer_has_alpha (CoglPipelineLayer *layer)
|
|||||||
/* All bets are off if the layer contains any snippets */
|
/* All bets are off if the layer contains any snippets */
|
||||||
snippets_authority = _cogl_pipeline_layer_get_authority
|
snippets_authority = _cogl_pipeline_layer_get_authority
|
||||||
(layer, COGL_PIPELINE_LAYER_STATE_VERTEX_SNIPPETS);
|
(layer, COGL_PIPELINE_LAYER_STATE_VERTEX_SNIPPETS);
|
||||||
if (!COGL_LIST_EMPTY (&snippets_authority->big_state->vertex_snippets))
|
if (snippets_authority->big_state->vertex_snippets.entries != NULL)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
snippets_authority = _cogl_pipeline_layer_get_authority
|
snippets_authority = _cogl_pipeline_layer_get_authority
|
||||||
(layer, COGL_PIPELINE_LAYER_STATE_FRAGMENT_SNIPPETS);
|
(layer, COGL_PIPELINE_LAYER_STATE_FRAGMENT_SNIPPETS);
|
||||||
if (!COGL_LIST_EMPTY (&snippets_authority->big_state->fragment_snippets))
|
if (snippets_authority->big_state->fragment_snippets.entries != NULL)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -31,18 +31,11 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include "cogl-snippet.h"
|
#include "cogl-snippet.h"
|
||||||
#include "cogl-queue.h"
|
|
||||||
|
|
||||||
typedef struct _CoglPipelineSnippet CoglPipelineSnippet;
|
typedef struct
|
||||||
|
|
||||||
COGL_LIST_HEAD (CoglPipelineSnippetList, CoglPipelineSnippet);
|
|
||||||
|
|
||||||
struct _CoglPipelineSnippet
|
|
||||||
{
|
{
|
||||||
COGL_LIST_ENTRY (CoglPipelineSnippet) list_node;
|
GList *entries;
|
||||||
|
} CoglPipelineSnippetList;
|
||||||
CoglSnippet *snippet;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Arguments to pass to _cogl_pipeline_snippet_generate_code() */
|
/* Arguments to pass to _cogl_pipeline_snippet_generate_code() */
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -41,27 +41,32 @@
|
|||||||
void
|
void
|
||||||
_cogl_pipeline_snippet_generate_code (const CoglPipelineSnippetData *data)
|
_cogl_pipeline_snippet_generate_code (const CoglPipelineSnippetData *data)
|
||||||
{
|
{
|
||||||
CoglPipelineSnippet *first_snippet, *snippet;
|
GList *first_snippet, *l;
|
||||||
|
CoglSnippet *snippet;
|
||||||
int snippet_num = 0;
|
int snippet_num = 0;
|
||||||
int n_snippets = 0;
|
int n_snippets = 0;
|
||||||
|
|
||||||
first_snippet = COGL_LIST_FIRST (data->snippets);
|
first_snippet = data->snippets->entries;
|
||||||
|
|
||||||
/* First count the number of snippets so we can easily tell when
|
/* First count the number of snippets so we can easily tell when
|
||||||
we're at the last one */
|
we're at the last one */
|
||||||
COGL_LIST_FOREACH (snippet, data->snippets, list_node)
|
for (l = data->snippets->entries; l; l = l->next)
|
||||||
if (snippet->snippet->hook == data->hook)
|
{
|
||||||
{
|
snippet = l->data;
|
||||||
/* Don't bother processing any previous snippets if we reach
|
|
||||||
one that has a replacement */
|
if (snippet->hook == data->hook)
|
||||||
if (snippet->snippet->replace)
|
{
|
||||||
{
|
/* Don't bother processing any previous snippets if we reach
|
||||||
n_snippets = 1;
|
one that has a replacement */
|
||||||
first_snippet = snippet;
|
if (snippet->replace)
|
||||||
}
|
{
|
||||||
else
|
n_snippets = 1;
|
||||||
n_snippets++;
|
first_snippet = l;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
n_snippets++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* If there weren't any snippets then generate a stub function with
|
/* If there weren't any snippets then generate a stub function with
|
||||||
the final name */
|
the final name */
|
||||||
@ -98,90 +103,92 @@ _cogl_pipeline_snippet_generate_code (const CoglPipelineSnippetData *data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (snippet = first_snippet, snippet_num = 0;
|
for (l = first_snippet; snippet_num < n_snippets; l = l->next)
|
||||||
snippet_num < n_snippets;
|
{
|
||||||
snippet = COGL_LIST_NEXT (snippet, list_node))
|
snippet = l->data;
|
||||||
if (snippet->snippet->hook == data->hook)
|
|
||||||
{
|
|
||||||
const char *source;
|
|
||||||
|
|
||||||
if ((source = cogl_snippet_get_declarations (snippet->snippet)))
|
if (snippet->hook == data->hook)
|
||||||
g_string_append (data->source_buf, source);
|
{
|
||||||
|
const char *source;
|
||||||
|
|
||||||
g_string_append_printf (data->source_buf,
|
if ((source = cogl_snippet_get_declarations (snippet)))
|
||||||
"\n"
|
g_string_append (data->source_buf, source);
|
||||||
"%s\n",
|
|
||||||
data->return_type ?
|
|
||||||
data->return_type :
|
|
||||||
"void");
|
|
||||||
|
|
||||||
if (snippet_num + 1 < n_snippets)
|
|
||||||
g_string_append_printf (data->source_buf,
|
g_string_append_printf (data->source_buf,
|
||||||
"%s_%i",
|
"\n"
|
||||||
data->function_prefix,
|
"%s\n",
|
||||||
snippet_num);
|
data->return_type ?
|
||||||
else
|
data->return_type :
|
||||||
g_string_append (data->source_buf, data->final_name);
|
"void");
|
||||||
|
|
||||||
g_string_append (data->source_buf, " (");
|
if (snippet_num + 1 < n_snippets)
|
||||||
|
g_string_append_printf (data->source_buf,
|
||||||
|
"%s_%i",
|
||||||
|
data->function_prefix,
|
||||||
|
snippet_num);
|
||||||
|
else
|
||||||
|
g_string_append (data->source_buf, data->final_name);
|
||||||
|
|
||||||
if (data->argument_declarations)
|
g_string_append (data->source_buf, " (");
|
||||||
g_string_append (data->source_buf, data->argument_declarations);
|
|
||||||
|
|
||||||
g_string_append (data->source_buf,
|
if (data->argument_declarations)
|
||||||
")\n"
|
g_string_append (data->source_buf, data->argument_declarations);
|
||||||
"{\n");
|
|
||||||
|
|
||||||
if (data->return_type && !data->return_variable_is_argument)
|
g_string_append (data->source_buf,
|
||||||
g_string_append_printf (data->source_buf,
|
")\n"
|
||||||
" %s %s;\n"
|
"{\n");
|
||||||
"\n",
|
|
||||||
data->return_type,
|
|
||||||
data->return_variable);
|
|
||||||
|
|
||||||
if ((source = cogl_snippet_get_pre (snippet->snippet)))
|
if (data->return_type && !data->return_variable_is_argument)
|
||||||
g_string_append (data->source_buf, source);
|
g_string_append_printf (data->source_buf,
|
||||||
|
" %s %s;\n"
|
||||||
|
"\n",
|
||||||
|
data->return_type,
|
||||||
|
data->return_variable);
|
||||||
|
|
||||||
/* Chain on to the next function, or bypass it if there is
|
if ((source = cogl_snippet_get_pre (snippet)))
|
||||||
a replace string */
|
g_string_append (data->source_buf, source);
|
||||||
if ((source = cogl_snippet_get_replace (snippet->snippet)))
|
|
||||||
g_string_append (data->source_buf, source);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_string_append (data->source_buf, " ");
|
|
||||||
|
|
||||||
if (data->return_type)
|
/* Chain on to the next function, or bypass it if there is
|
||||||
g_string_append_printf (data->source_buf,
|
a replace string */
|
||||||
"%s = ",
|
if ((source = cogl_snippet_get_replace (snippet)))
|
||||||
data->return_variable);
|
g_string_append (data->source_buf, source);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_string_append (data->source_buf, " ");
|
||||||
|
|
||||||
if (snippet_num > 0)
|
if (data->return_type)
|
||||||
g_string_append_printf (data->source_buf,
|
g_string_append_printf (data->source_buf,
|
||||||
"%s_%i",
|
"%s = ",
|
||||||
data->function_prefix,
|
data->return_variable);
|
||||||
snippet_num - 1);
|
|
||||||
else
|
|
||||||
g_string_append (data->source_buf, data->chain_function);
|
|
||||||
|
|
||||||
g_string_append (data->source_buf, " (");
|
if (snippet_num > 0)
|
||||||
|
g_string_append_printf (data->source_buf,
|
||||||
|
"%s_%i",
|
||||||
|
data->function_prefix,
|
||||||
|
snippet_num - 1);
|
||||||
|
else
|
||||||
|
g_string_append (data->source_buf, data->chain_function);
|
||||||
|
|
||||||
if (data->arguments)
|
g_string_append (data->source_buf, " (");
|
||||||
g_string_append (data->source_buf, data->arguments);
|
|
||||||
|
|
||||||
g_string_append (data->source_buf, ");\n");
|
if (data->arguments)
|
||||||
}
|
g_string_append (data->source_buf, data->arguments);
|
||||||
|
|
||||||
if ((source = cogl_snippet_get_post (snippet->snippet)))
|
g_string_append (data->source_buf, ");\n");
|
||||||
g_string_append (data->source_buf, source);
|
}
|
||||||
|
|
||||||
if (data->return_type)
|
if ((source = cogl_snippet_get_post (snippet)))
|
||||||
g_string_append_printf (data->source_buf,
|
g_string_append (data->source_buf, source);
|
||||||
" return %s;\n",
|
|
||||||
data->return_variable);
|
|
||||||
|
|
||||||
g_string_append (data->source_buf, "}\n");
|
if (data->return_type)
|
||||||
snippet_num++;
|
g_string_append_printf (data->source_buf,
|
||||||
}
|
" return %s;\n",
|
||||||
|
data->return_variable);
|
||||||
|
|
||||||
|
g_string_append (data->source_buf, "}\n");
|
||||||
|
snippet_num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -189,92 +196,70 @@ _cogl_pipeline_snippet_generate_declarations (GString *declarations_buf,
|
|||||||
CoglSnippetHook hook,
|
CoglSnippetHook hook,
|
||||||
CoglPipelineSnippetList *snippets)
|
CoglPipelineSnippetList *snippets)
|
||||||
{
|
{
|
||||||
CoglPipelineSnippet *snippet;
|
GList *l;
|
||||||
|
|
||||||
COGL_LIST_FOREACH (snippet, snippets, list_node)
|
for (l = snippets->entries; l; l = l->next)
|
||||||
if (snippet->snippet->hook == hook)
|
{
|
||||||
{
|
CoglSnippet *snippet = l->data;
|
||||||
const char *source;
|
|
||||||
|
|
||||||
if ((source = cogl_snippet_get_declarations (snippet->snippet)))
|
if (snippet->hook == hook)
|
||||||
g_string_append (declarations_buf, source);
|
{
|
||||||
}
|
const char *source;
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
if ((source = cogl_snippet_get_declarations (snippet)))
|
||||||
_cogl_pipeline_snippet_free (CoglPipelineSnippet *pipeline_snippet)
|
g_string_append (declarations_buf, source);
|
||||||
{
|
}
|
||||||
cogl_object_unref (pipeline_snippet->snippet);
|
}
|
||||||
g_slice_free (CoglPipelineSnippet, pipeline_snippet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_pipeline_snippet_list_free (CoglPipelineSnippetList *list)
|
_cogl_pipeline_snippet_list_free (CoglPipelineSnippetList *list)
|
||||||
{
|
{
|
||||||
CoglPipelineSnippet *pipeline_snippet, *tmp;
|
GList *l, *tmp;
|
||||||
|
|
||||||
COGL_LIST_FOREACH_SAFE (pipeline_snippet, list, list_node, tmp)
|
for (l = list->entries; l; l = tmp)
|
||||||
_cogl_pipeline_snippet_free (pipeline_snippet);
|
{
|
||||||
|
tmp = l->next;
|
||||||
|
|
||||||
|
cogl_object_unref (l->data);
|
||||||
|
g_list_free_1 (l);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_pipeline_snippet_list_add (CoglPipelineSnippetList *list,
|
_cogl_pipeline_snippet_list_add (CoglPipelineSnippetList *list,
|
||||||
CoglSnippet *snippet)
|
CoglSnippet *snippet)
|
||||||
{
|
{
|
||||||
CoglPipelineSnippet *pipeline_snippet = g_slice_new (CoglPipelineSnippet);
|
list->entries = g_list_append (list->entries, cogl_object_ref (snippet));
|
||||||
|
|
||||||
pipeline_snippet->snippet = cogl_object_ref (snippet);
|
_cogl_snippet_make_immutable (snippet);
|
||||||
|
|
||||||
_cogl_snippet_make_immutable (pipeline_snippet->snippet);
|
|
||||||
|
|
||||||
if (COGL_LIST_EMPTY (list))
|
|
||||||
COGL_LIST_INSERT_HEAD (list, pipeline_snippet, list_node);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CoglPipelineSnippet *tail;
|
|
||||||
|
|
||||||
for (tail = COGL_LIST_FIRST (list);
|
|
||||||
COGL_LIST_NEXT (tail, list_node);
|
|
||||||
tail = COGL_LIST_NEXT (tail, list_node));
|
|
||||||
|
|
||||||
COGL_LIST_INSERT_AFTER (tail, pipeline_snippet, list_node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_pipeline_snippet_list_copy (CoglPipelineSnippetList *dst,
|
_cogl_pipeline_snippet_list_copy (CoglPipelineSnippetList *dst,
|
||||||
const CoglPipelineSnippetList *src)
|
const CoglPipelineSnippetList *src)
|
||||||
{
|
{
|
||||||
CoglPipelineSnippet *tail = NULL;
|
GQueue queue = G_QUEUE_INIT;
|
||||||
const CoglPipelineSnippet *l;
|
const GList *l;
|
||||||
|
|
||||||
COGL_LIST_INIT (dst);
|
for (l = src->entries; l; l = l->next)
|
||||||
|
g_queue_push_tail (&queue, cogl_object_ref (l->data));
|
||||||
|
|
||||||
COGL_LIST_FOREACH (l, src, list_node)
|
dst->entries = queue.head;
|
||||||
{
|
|
||||||
CoglPipelineSnippet *copy = g_slice_dup (CoglPipelineSnippet, l);
|
|
||||||
|
|
||||||
cogl_object_ref (copy->snippet);
|
|
||||||
|
|
||||||
if (tail)
|
|
||||||
COGL_LIST_INSERT_AFTER (tail, copy, list_node);
|
|
||||||
else
|
|
||||||
COGL_LIST_INSERT_HEAD (dst, copy, list_node);
|
|
||||||
|
|
||||||
tail = copy;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_pipeline_snippet_list_hash (CoglPipelineSnippetList *list,
|
_cogl_pipeline_snippet_list_hash (CoglPipelineSnippetList *list,
|
||||||
unsigned int *hash)
|
unsigned int *hash)
|
||||||
{
|
{
|
||||||
CoglPipelineSnippet *l;
|
GList *l;
|
||||||
|
|
||||||
COGL_LIST_FOREACH (l, list, list_node)
|
for (l = list->entries; l; l = l->next)
|
||||||
{
|
{
|
||||||
|
CoglSnippet *snippet = l->data;
|
||||||
|
|
||||||
*hash = _cogl_util_one_at_a_time_hash (*hash,
|
*hash = _cogl_util_one_at_a_time_hash (*hash,
|
||||||
&l->snippet,
|
&snippet,
|
||||||
sizeof (CoglSnippet *));
|
sizeof (CoglSnippet *));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,12 +268,12 @@ CoglBool
|
|||||||
_cogl_pipeline_snippet_list_equal (CoglPipelineSnippetList *list0,
|
_cogl_pipeline_snippet_list_equal (CoglPipelineSnippetList *list0,
|
||||||
CoglPipelineSnippetList *list1)
|
CoglPipelineSnippetList *list1)
|
||||||
{
|
{
|
||||||
CoglPipelineSnippet *l0, *l1;
|
GList *l0, *l1;
|
||||||
|
|
||||||
for (l0 = COGL_LIST_FIRST (list0), l1 = COGL_LIST_FIRST (list1);
|
for (l0 = list0->entries, l1 = list1->entries;
|
||||||
l0 && l1;
|
l0 && l1;
|
||||||
l0 = COGL_LIST_NEXT (l0, list_node), l1 = COGL_LIST_NEXT (l1, list_node))
|
l0 = l0->next, l1 = l1->next)
|
||||||
if (l0->snippet != l1->snippet)
|
if (l0->data != l1->data)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return l0 == NULL && l1 == NULL;
|
return l0 == NULL && l1 == NULL;
|
||||||
|
@ -1661,7 +1661,7 @@ _cogl_pipeline_has_non_layer_vertex_snippets (CoglPipeline *pipeline)
|
|||||||
_cogl_pipeline_get_authority (pipeline,
|
_cogl_pipeline_get_authority (pipeline,
|
||||||
COGL_PIPELINE_STATE_VERTEX_SNIPPETS);
|
COGL_PIPELINE_STATE_VERTEX_SNIPPETS);
|
||||||
|
|
||||||
return !COGL_LIST_EMPTY (&authority->big_state->vertex_snippets);
|
return authority->big_state->vertex_snippets.entries != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CoglBool
|
static CoglBool
|
||||||
@ -1673,7 +1673,7 @@ check_layer_has_vertex_snippet (CoglPipelineLayer *layer,
|
|||||||
_cogl_pipeline_layer_get_authority (layer, state);
|
_cogl_pipeline_layer_get_authority (layer, state);
|
||||||
CoglBool *found_vertex_snippet = user_data;
|
CoglBool *found_vertex_snippet = user_data;
|
||||||
|
|
||||||
if (!COGL_LIST_EMPTY (&authority->big_state->vertex_snippets))
|
if (authority->big_state->vertex_snippets.entries)
|
||||||
{
|
{
|
||||||
*found_vertex_snippet = TRUE;
|
*found_vertex_snippet = TRUE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -1704,7 +1704,7 @@ _cogl_pipeline_has_non_layer_fragment_snippets (CoglPipeline *pipeline)
|
|||||||
_cogl_pipeline_get_authority (pipeline,
|
_cogl_pipeline_get_authority (pipeline,
|
||||||
COGL_PIPELINE_STATE_FRAGMENT_SNIPPETS);
|
COGL_PIPELINE_STATE_FRAGMENT_SNIPPETS);
|
||||||
|
|
||||||
return !COGL_LIST_EMPTY (&authority->big_state->fragment_snippets);
|
return authority->big_state->fragment_snippets.entries != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CoglBool
|
static CoglBool
|
||||||
@ -1716,7 +1716,7 @@ check_layer_has_fragment_snippet (CoglPipelineLayer *layer,
|
|||||||
_cogl_pipeline_layer_get_authority (layer, state);
|
_cogl_pipeline_layer_get_authority (layer, state);
|
||||||
CoglBool *found_fragment_snippet = user_data;
|
CoglBool *found_fragment_snippet = user_data;
|
||||||
|
|
||||||
if (!COGL_LIST_EMPTY (&authority->big_state->fragment_snippets))
|
if (authority->big_state->fragment_snippets.entries)
|
||||||
{
|
{
|
||||||
*found_fragment_snippet = TRUE;
|
*found_fragment_snippet = TRUE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -198,11 +198,15 @@ static CoglBool
|
|||||||
has_replace_hook (CoglPipelineLayer *layer,
|
has_replace_hook (CoglPipelineLayer *layer,
|
||||||
CoglSnippetHook hook)
|
CoglSnippetHook hook)
|
||||||
{
|
{
|
||||||
CoglPipelineSnippet *snippet;
|
GList *l;
|
||||||
|
|
||||||
COGL_LIST_FOREACH (snippet, get_layer_fragment_snippets (layer), list_node)
|
for (l = get_layer_fragment_snippets (layer)->entries; l; l = l->next)
|
||||||
if (snippet->snippet->hook == hook && snippet->snippet->replace)
|
{
|
||||||
return TRUE;
|
CoglSnippet *snippet = l->data;
|
||||||
|
|
||||||
|
if (snippet->hook == hook && snippet->replace)
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user