summaryrefslogtreecommitdiff
path: root/cogl/cogl-clip-stack.c
diff options
context:
space:
mode:
authorNeil Roberts <neil@linux.intel.com>2010-04-15 10:58:28 +0100
committerNeil Roberts <neil@linux.intel.com>2010-04-15 14:51:01 +0100
commit30c4678ff4c7fdcded9756333cd220a67ba26125 (patch)
tree55137d6e728013f2ca2888139b4a5a8a256ae8bc /cogl/cogl-clip-stack.c
parent84b87e811e0152dfd6a55930c62d1211f808b8e1 (diff)
downloadcogl-30c4678ff4c7fdcded9756333cd220a67ba26125.tar.gz
cogl: Implement retained clip stacks
This adds three new internal API functions which can be used to retain the clip stack state and restore it later: _cogl_get_clip_stack _cogl_set_clip_stack _cogl_clip_stack_copy The functions are currently internal and not yet used but we may want to make them public in future to replace the cogl_clip_stack_save() and cogl_clip_stack_restore() APIs. The get function just returns the handle to the clip stack at the top of the stack of stacks and the set function just replaces it. The copy function makes a cheap copy of an existing stack by taking a reference to the top stack entry. This ends up working like a deep copy because there is no way to modify entries of a stack but it doesn't actually copy the data.
Diffstat (limited to 'cogl/cogl-clip-stack.c')
-rw-r--r--cogl/cogl-clip-stack.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/cogl/cogl-clip-stack.c b/cogl/cogl-clip-stack.c
index 37e7d398..63221561 100644
--- a/cogl/cogl-clip-stack.c
+++ b/cogl/cogl-clip-stack.c
@@ -682,3 +682,29 @@ _cogl_clip_stack_free (CoglClipStack *stack)
g_slice_free (CoglClipStack, stack);
}
+
+CoglHandle
+_cogl_clip_stack_copy (CoglHandle handle)
+{
+ CoglHandle new_handle;
+ CoglClipStack *new_stack, *old_stack;
+
+ if (!cogl_is_clip_stack (handle))
+ return COGL_INVALID_HANDLE;
+
+ old_stack = COGL_CLIP_STACK (handle);
+
+ new_handle = _cogl_clip_stack_new ();
+ new_stack = COGL_CLIP_STACK (new_handle);
+
+ /* We can copy the stack by just referencing the other stack's
+ data. There's no need to implement copy-on-write because the
+ entries of the stack can't be modified. If the other stack pops
+ some entries off they will still be kept alive because this stack
+ holds a reference. */
+ new_stack->stack_top = old_stack->stack_top;
+ if (new_stack->stack_top)
+ new_stack->stack_top->ref_count++;
+
+ return new_handle;
+}