From d5188c26b6dc928639d0779ba4910ad5f4fa7fcc Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Tue, 12 Oct 2010 11:46:29 +0100 Subject: [PATCH] buffer: remove flag macros All the macros get used for are to |= (a new flag bit), &= ~(a flag bit) or use the & operator to test if a flag bit is set. I haven't found the code more readable with these macros, but several times now I've felt the need to double check if these macros do anything else behind the hood or I've forgotten what flags are available so I've had to go to the macro definition to see what the full enum names are for the flags (the macros use symbol concatenation) so I can search for the definition of all the flags. It turns out they are defined next to the macro so you don't have to search far, but without the macro that wouldn't have been necessary. The more common use of the _IS_SET macro is actually more concise expanded and imho since it doesn't hide anything in a separate header file the code is more readable without the macro. --- clutter/cogl/cogl/cogl-bitmap.c | 4 ++-- clutter/cogl/cogl/cogl-buffer-private.h | 9 --------- clutter/cogl/cogl/cogl-buffer.c | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/clutter/cogl/cogl/cogl-bitmap.c b/clutter/cogl/cogl/cogl-bitmap.c index d1186129e..43b2be566 100644 --- a/clutter/cogl/cogl/cogl-bitmap.c +++ b/clutter/cogl/cogl/cogl-bitmap.c @@ -439,7 +439,7 @@ _cogl_bitmap_bind (CoglBitmap *bitmap, /* If buffer is using a malloc fallback then we'll just use the pointer directly */ - if (COGL_BUFFER_FLAG_IS_SET (bitmap->buffer, BUFFER_OBJECT)) + if (bitmap->buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT) { ptr = NULL; @@ -473,7 +473,7 @@ _cogl_bitmap_unbind (CoglBitmap *bitmap) implementation of unbind is the same as unmap */ if (bitmap->buffer) { - if (COGL_BUFFER_FLAG_IS_SET (bitmap->buffer, BUFFER_OBJECT)) + if (bitmap->buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT) _cogl_buffer_unbind (bitmap->buffer); } else diff --git a/clutter/cogl/cogl/cogl-buffer-private.h b/clutter/cogl/cogl/cogl-buffer-private.h index 4a727fd81..46dff7209 100644 --- a/clutter/cogl/cogl/cogl-buffer-private.h +++ b/clutter/cogl/cogl/cogl-buffer-private.h @@ -38,15 +38,6 @@ G_BEGIN_DECLS #define COGL_BUFFER(buffer) ((CoglBuffer *)(buffer)) -#define COGL_BUFFER_SET_FLAG(buffer, flag) \ - ((buffer)->flags |= (COGL_BUFFER_FLAG_ ## flag)) - -#define COGL_BUFFER_CLEAR_FLAG(buffer, flag) \ - ((buffer)->flags &= ~(COGL_BUFFER_FLAG_ ## flag)) - -#define COGL_BUFFER_FLAG_IS_SET(buffer, flag) \ - ((buffer)->flags & (COGL_BUFFER_FLAG_ ## flag)) - typedef struct _CoglBufferVtable CoglBufferVtable; struct _CoglBufferVtable diff --git a/clutter/cogl/cogl/cogl-buffer.c b/clutter/cogl/cogl/cogl-buffer.c index 6e8f5d42a..c55613fa8 100644 --- a/clutter/cogl/cogl/cogl-buffer.c +++ b/clutter/cogl/cogl/cogl-buffer.c @@ -166,7 +166,7 @@ bo_map (CoglBuffer *buffer, GE_RET( data, glMapBuffer (gl_target, _cogl_buffer_access_to_gl_enum (access)) ); if (data) - COGL_BUFFER_SET_FLAG (buffer, MAPPED); + buffer->flags |= COGL_BUFFER_FLAG_MAPPED; _cogl_buffer_unbind (buffer); @@ -188,7 +188,7 @@ bo_unmap (CoglBuffer *buffer) _cogl_buffer_bind (buffer, buffer->last_target); GE( glUnmapBuffer (convert_bind_target_to_gl_target (buffer->last_target)) ); - COGL_BUFFER_CLEAR_FLAG (buffer, MAPPED); + buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED; _cogl_buffer_unbind (buffer); #else @@ -242,14 +242,14 @@ malloc_map (CoglBuffer *buffer, CoglBufferAccess access, CoglBufferMapHint hints) { - COGL_BUFFER_SET_FLAG (buffer, MAPPED); + buffer->flags |= COGL_BUFFER_FLAG_MAPPED; return buffer->data; } static void malloc_unmap (CoglBuffer *buffer) { - COGL_BUFFER_CLEAR_FLAG (buffer, MAPPED); + buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED; } static gboolean @@ -294,14 +294,14 @@ _cogl_buffer_initialize (CoglBuffer *buffer, buffer->vtable.set_data = bo_set_data; GE( glGenBuffers (1, &buffer->gl_handle) ); - COGL_BUFFER_SET_FLAG (buffer, BUFFER_OBJECT); + buffer->flags |= COGL_BUFFER_FLAG_BUFFER_OBJECT; } } void _cogl_buffer_fini (CoglBuffer *buffer) { - g_return_if_fail (!COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED)); + g_return_if_fail (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED)); } /* OpenGL ES 1.1 and 2 have a GL_OES_mapbuffer extension that is able to map @@ -369,7 +369,7 @@ _cogl_buffer_bind (CoglBuffer *buffer, CoglBufferBindTarget target) buffer->last_target = target; - if (COGL_BUFFER_FLAG_IS_SET (buffer, BUFFER_OBJECT)) + if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT) { GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target); GE( glBindBuffer (gl_target, buffer->gl_handle) ); @@ -388,7 +388,7 @@ _cogl_buffer_unbind (CoglBuffer *buffer) /* the unbind should pair up with a previous bind */ g_return_if_fail (ctx->current_buffer[buffer->last_target] == buffer); - if (COGL_BUFFER_FLAG_IS_SET (buffer, BUFFER_OBJECT)) + if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT) { GLenum gl_target = convert_bind_target_to_gl_target (buffer->last_target); GE( glBindBuffer (gl_target, 0) ); @@ -436,7 +436,7 @@ cogl_buffer_map (CoglBuffer *buffer, if (!cogl_is_buffer (buffer)) return NULL; - if (COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED)) + if (buffer->flags & COGL_BUFFER_FLAG_MAPPED) return buffer->data; buffer->data = buffer->vtable.map (buffer, access, hints); @@ -449,7 +449,7 @@ cogl_buffer_unmap (CoglBuffer *buffer) if (!cogl_is_buffer (buffer)) return; - if (!COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED)) + if (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED)) return; buffer->vtable.unmap (buffer);