From c29a7526c040209a5ca0bb327f1df6a98c4d88aa Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Mon, 29 Nov 2010 18:47:10 +0000 Subject: [PATCH] matrix: Adds matrix_copy and _free functions As a pre-requisite for being able to register a boxed GType for CoglMatrix (enabling us to define gobject properties that accept a CoglMatrix) this adds cogl_matrix_copy and _free functions. --- clutter/cogl/cogl/cogl-matrix.c | 15 +++++++++++++++ clutter/cogl/cogl/cogl-matrix.h | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/clutter/cogl/cogl/cogl-matrix.c b/clutter/cogl/cogl/cogl-matrix.c index 85abab7f8..dc5578cc9 100644 --- a/clutter/cogl/cogl/cogl-matrix.c +++ b/clutter/cogl/cogl/cogl-matrix.c @@ -353,6 +353,21 @@ cogl_matrix_equal (gconstpointer v1, gconstpointer v2) return FALSE; } +CoglMatrix * +cogl_matrix_copy (const CoglMatrix *matrix) +{ + if (G_LIKELY (matrix)) + return g_slice_dup (CoglMatrix, matrix); + + return NULL; +} + +void +cogl_matrix_free (CoglMatrix *matrix) +{ + g_slice_free (CoglMatrix, matrix); +} + const float * cogl_matrix_get_array (const CoglMatrix *matrix) { diff --git a/clutter/cogl/cogl/cogl-matrix.h b/clutter/cogl/cogl/cogl-matrix.h index 8904d881b..b54f4b948 100644 --- a/clutter/cogl/cogl/cogl-matrix.h +++ b/clutter/cogl/cogl/cogl-matrix.h @@ -292,6 +292,33 @@ cogl_matrix_get_array (const CoglMatrix *matrix); gboolean cogl_matrix_equal (gconstpointer v1, gconstpointer v2); +/** + * cogl_matrix_copy: + * @matrix: A 4x4 transformation matrix you want to copy + * + * Allocates a new #CoglMatrix on the heap and initializes it with + * the same values as @matrix. + * + * Returns: A newly allocated #CoglMatrix which should be freed using + * cogl_matrix_free() + * + * Since: 1.6 + */ +CoglMatrix * +cogl_matrix_copy (const CoglMatrix *matrix); + +/** + * cogl_matrix_free: + * @matrix: A 4x4 transformation matrix you want to free + * + * Frees a #CoglMatrix that was previously allocated via a call to + * cogl_matrix_copy(). + * + * Since: 1.6 + */ +void +cogl_matrix_free (CoglMatrix *matrix); + /** * cogl_matrix_get_inverse: * @matrix: A 4x4 transformation matrix