[cairo-commit] 4 commits - src/cairo-gl-private.h src/cairo-gl-surface.c src/cairo-mutex-impl-private.h
Chris Wilson
ickle at kemper.freedesktop.org
Thu Sep 3 12:12:57 PDT 2009
src/cairo-gl-private.h | 1
src/cairo-gl-surface.c | 49 +++++++++++++++++++++++++----------------
src/cairo-mutex-impl-private.h | 47 ++++++++++++++++++++-------------------
3 files changed, 55 insertions(+), 42 deletions(-)
New commits:
commit 535bcaa1a1dac28fbe3106c6605949171bc36cb2
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Sep 3 20:10:55 2009 +0100
[mutex] Hook into pthread last
Check for native mutex types before hooking into pthread, as this
workarounds broken builds on mingw that confuse us by including the
pthread header file.
diff --git a/src/cairo-mutex-impl-private.h b/src/cairo-mutex-impl-private.h
index a956b52..8ab7600 100644
--- a/src/cairo-mutex-impl-private.h
+++ b/src/cairo-mutex-impl-private.h
@@ -168,29 +168,6 @@
# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) CAIRO_MUTEX_IMPL_NOOP1(mutex)
# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER 0
-#elif HAVE_PTHREAD_H /*******************************************************/
-
-# include <pthread.h>
-
- typedef pthread_mutex_t cairo_mutex_impl_t;
-
-# define CAIRO_MUTEX_IMPL_PTHREAD 1
-#if HAVE_LOCKDEP
-/* expose all mutexes to the validator */
-# define CAIRO_MUTEX_IMPL_INIT(mutex) pthread_mutex_init (&(mutex), NULL)
-#endif
-# define CAIRO_MUTEX_IMPL_LOCK(mutex) pthread_mutex_lock (&(mutex))
-# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
-#if HAVE_LOCKDEP
-# define CAIRO_MUTEX_IS_LOCKED(mutex) LOCKDEP_IS_LOCKED (&(mutex))
-# define CAIRO_MUTEX_IS_UNLOCKED(mutex) LOCKDEP_IS_UNLOCKED (&(mutex))
-#endif
-# define CAIRO_MUTEX_IMPL_FINI(mutex) pthread_mutex_destroy (&(mutex))
-#if ! HAVE_LOCKDEP
-# define CAIRO_MUTEX_IMPL_FINALIZE() CAIRO_MUTEX_IMPL_NOOP
-#endif
-# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER
-
#elif defined(HAVE_WINDOWS_H) || defined(_MSC_VER) /*************************/
# include <windows.h>
@@ -230,6 +207,30 @@
# define CAIRO_MUTEX_IMPL_FINI(mutex) delete (mutex)
# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER NULL
+#elif HAVE_PTHREAD_H /* and finally if there are no native mutexes ********/
+
+# include <pthread.h>
+
+ typedef pthread_mutex_t cairo_mutex_impl_t;
+
+# define CAIRO_MUTEX_IMPL_PTHREAD 1
+#if HAVE_LOCKDEP
+/* expose all mutexes to the validator */
+# define CAIRO_MUTEX_IMPL_INIT(mutex) pthread_mutex_init (&(mutex), NULL)
+#endif
+# define CAIRO_MUTEX_IMPL_LOCK(mutex) pthread_mutex_lock (&(mutex))
+# define CAIRO_MUTEX_IMPL_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
+#if HAVE_LOCKDEP
+# define CAIRO_MUTEX_IS_LOCKED(mutex) LOCKDEP_IS_LOCKED (&(mutex))
+# define CAIRO_MUTEX_IS_UNLOCKED(mutex) LOCKDEP_IS_UNLOCKED (&(mutex))
+#endif
+# define CAIRO_MUTEX_IMPL_FINI(mutex) pthread_mutex_destroy (&(mutex))
+#if ! HAVE_LOCKDEP
+# define CAIRO_MUTEX_IMPL_FINALIZE() CAIRO_MUTEX_IMPL_NOOP
+#endif
+# define CAIRO_MUTEX_IMPL_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+
+
#else /**********************************************************************/
# error "XXX: No mutex implementation found. Cairo will not work with multiple threads. Define CAIRO_NO_MUTEX to 1 to acknowledge and accept this limitation and compile cairo without thread-safety support."
commit 769f4a4f47ab4636ec5cca3e92ce2c0ff19d2f75
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Sep 3 17:47:34 2009 +0100
[gl] Allocate small number of rectangles on the stack
FillRectangle is most frequently used to fill an entire imagee with the
background colour, i.e. with just a single, or few, rectangle. Avoid
heap allocation for this common case by allocating enough space for 4
rectangles (vertices+colors) on the stack.
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 22efbd4..a2c5b97 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -1522,7 +1522,10 @@ _cairo_gl_surface_fill_rectangles (void *abstract_surface,
cairo_rectangle_int_t *rects,
int num_rects)
{
+#define N_STACK_RECTS 4
cairo_gl_surface_t *surface = abstract_surface;
+ GLfloat vertices_stack[N_STACK_RECTS*4*2];
+ GLfloat colors_stack[N_STACK_RECTS*4*4]
cairo_gl_context_t *ctx;
int i;
GLfloat *vertices;
@@ -1536,23 +1539,32 @@ _cairo_gl_surface_fill_rectangles (void *abstract_surface,
_cairo_gl_set_destination (surface);
_cairo_gl_set_operator (surface, op);
- vertices = _cairo_malloc_ab (num_rects, sizeof (GLfloat) * 4 * 2);
- colors = _cairo_malloc_ab (num_rects, sizeof (GLfloat) * 4 * 4);
- if (!vertices || !colors) {
- _cairo_gl_context_release (ctx);
- free (vertices);
- free (colors);
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ if (num_rects > N_STACK_RECTS) {
+ vertices = _cairo_malloc_ab (num_rects, sizeof (GLfloat) * 4 * 2);
+ colors = _cairo_malloc_ab (num_rects, sizeof (GLfloat) * 4 * 4);
+ if (!vertices || !colors) {
+ _cairo_gl_context_release (ctx);
+ free (vertices);
+ free (colors);
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ }
+ } else {
+ vertices = vertices_stack;
+ colors = colors_stack;
}
/* This should be loaded in as either a blend constant and an operator
* setup specific to this, or better, a fragment shader constant.
*/
- for (i = 0; i < num_rects * 4; i++) {
- colors[i * 4 + 0] = color->red * color->alpha;
- colors[i * 4 + 1] = color->green * color->alpha;
- colors[i * 4 + 2] = color->blue * color->alpha;
- colors[i * 4 + 3] = color->alpha;
+ colors[0] = color->red * color->alpha;
+ colors[1] = color->green * color->alpha;
+ colors[2] = color->blue * color->alpha;
+ colors[3] = color->alpha;
+ for (i = 1; i < num_rects * 4; i++) {
+ colors[i*4 + 0] = colors[0];
+ colors[i*4 + 1] = colors[1];
+ colors[i*4 + 2] = colors[2];
+ colors[i*4 + 3] = colors[3];
}
for (i = 0; i < num_rects; i++) {
@@ -1570,6 +1582,7 @@ _cairo_gl_surface_fill_rectangles (void *abstract_surface,
glEnableClientState (GL_VERTEX_ARRAY);
glColorPointer (4, GL_FLOAT, sizeof (GLfloat)*4, colors);
glEnableClientState (GL_COLOR_ARRAY);
+
glDrawArrays (GL_QUADS, 0, 4 * num_rects);
glDisableClientState (GL_COLOR_ARRAY);
@@ -1577,8 +1590,10 @@ _cairo_gl_surface_fill_rectangles (void *abstract_surface,
glDisable (GL_BLEND);
_cairo_gl_context_release (ctx);
- free (vertices);
- free (colors);
+ if (vertices != vertices_stack)
+ free (vertices);
+ if (colors != colors_stack)
+ free (colors);
return CAIRO_STATUS_SUCCESS;
}
commit 6ce200da9d01a85a1de576229e75732db65a8b70
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Sep 3 17:38:00 2009 +0100
[gl] Assert that the error is impossible.
As we created the image, it should not need coercing into a suitable
format and so we should be able to upload it without failure.
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 4b127b9..22efbd4 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -780,8 +780,8 @@ _cairo_gl_surface_release_dest_image (void *abstract_surface,
0, 0,
image->width, image->height,
image_rect->x, image_rect->y);
- if (status)
- status = _cairo_surface_set_error (abstract_surface, status);
+ /* as we created the image, its format should be directly applicable */
+ assert (status == CAIRO_STATUS_SUCCESS);
cairo_surface_destroy (&image->base);
}
commit d3aeafb406da7bf69e9bf24e18a5975780a7a987
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Sep 3 17:32:28 2009 +0100
[gl] Remove reference to depth_stencil_tex
We no longer use a depth-stencil, so remove the vestigial reference.
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 8efab8f..79145cf 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -70,7 +70,6 @@ typedef struct _cairo_gl_surface {
int width, height;
GLuint tex; /* GL texture object containing our data. */
- GLuint depth_stencil_tex;
GLuint fb; /* GL framebuffer object wrapping our data. */
} cairo_gl_surface_t;
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index bfe2579..4b127b9 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -724,8 +724,6 @@ _cairo_gl_surface_finish (void *abstract_surface)
glDeleteFramebuffersEXT (1, &surface->fb);
glDeleteTextures (1, &surface->tex);
- if (surface->depth_stencil_tex)
- glDeleteTextures (1, &surface->depth_stencil_tex);
if (surface->ctx->current_target == surface)
surface->ctx->current_target = NULL;
More information about the cairo-commit
mailing list