Skip to content

Commit

Permalink
Bug 676071 - Make GeglBufferIterator's flags parameter an enum type
Browse files Browse the repository at this point in the history
Add enum GeglAccessMode { GEGL_ACCESS_READ, _WRITE, _READWRITE } and
change everything to use it. Add compat #defines for the old values.
  • Loading branch information
mitchfoo committed Jul 1, 2014
1 parent c95e6a6 commit 5f3bdfc
Show file tree
Hide file tree
Showing 42 changed files with 189 additions and 129 deletions.
4 changes: 2 additions & 2 deletions examples/sdl-draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ draw_circle (GeglBuffer *buffer, int x, int y, float r)

iter = gegl_buffer_iterator_new (buffer, &roi, 0,
babl_format ("RGBA float"),
GEGL_BUFFER_READWRITE,
GEGL_ACCESS_READWRITE,
GEGL_ABYSS_NONE);

while (gegl_buffer_iterator_next (iter))
Expand Down Expand Up @@ -307,4 +307,4 @@ run_main_loop (SDL_Surface *main_window,
break;
}
}
}
}
6 changes: 3 additions & 3 deletions gegl/buffer/gegl-buffer-access.c
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ gegl_buffer_copy2 (GeglBuffer *src,
dest_rect_r.height = src_rect->height;

i = gegl_buffer_iterator_new (dst, &dest_rect_r, 0, dst->soft_format,
GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
while (gegl_buffer_iterator_next (i))
{
GeglRectangle src_rect = i->roi[0];
Expand Down Expand Up @@ -1771,7 +1771,7 @@ gegl_buffer_clear2 (GeglBuffer *dst,
* that fully voided tiles are dropped.
*/
i = gegl_buffer_iterator_new (dst, dst_rect, 0, dst->soft_format,
GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
while (gegl_buffer_iterator_next (i))
{
memset (((guchar*)(i->data[0])), 0, i->length * pxsize);
Expand Down Expand Up @@ -2013,7 +2013,7 @@ gegl_buffer_set_color (GeglBuffer *dst,
* that fully filled tiles are shared.
*/
i = gegl_buffer_iterator_new (dst, dst_rect, 0, dst->soft_format,
GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
while (gegl_buffer_iterator_next (i))
{
gegl_memset_pattern (i->data[0], pixel, bpp, i->length);
Expand Down
35 changes: 18 additions & 17 deletions gegl/buffer/gegl-buffer-iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ typedef enum {
typedef struct _SubIterState {
GeglRectangle full_rect; /* The entire area we are iterating over */
GeglBuffer *buffer;
unsigned int flags;
GeglAccessMode access_mode;
GeglAbyssPolicy abyss_policy;
const Babl *format;
gint format_bpp;
Expand Down Expand Up @@ -101,23 +101,24 @@ gegl_buffer_iterator_new (GeglBuffer *buf,
const GeglRectangle *roi,
gint level,
const Babl *format,
unsigned int flags,
GeglAccessMode access_mode,
GeglAbyssPolicy abyss_policy)
{
GeglBufferIterator *iter = gegl_buffer_iterator_empty_new ();

gegl_buffer_iterator_add (iter, buf, roi, level, format, flags, abyss_policy);
gegl_buffer_iterator_add (iter, buf, roi, level, format,
access_mode, abyss_policy);

return iter;
}

int
gegl_buffer_iterator_add (GeglBufferIterator *iter,
gegl_buffer_iterator_add (GeglBufferIterator *iter,
GeglBuffer *buf,
const GeglRectangle *roi,
gint level,
const Babl *format,
unsigned int flags,
GeglAccessMode access_mode,
GeglAbyssPolicy abyss_policy)
{
GeglBufferIteratorPriv *priv = iter->priv;
Expand All @@ -137,13 +138,13 @@ gegl_buffer_iterator_add (GeglBufferIterator *iter,

sub->buffer = buf;
sub->full_rect = *roi;
sub->flags = flags;
sub->access_mode = access_mode;
sub->abyss_policy = abyss_policy;
sub->current_tile = NULL;
sub->real_data = NULL;
sub->linear_tile = NULL;
sub->format = format;
sub->format_bpp = babl_format_get_bytes_per_pixel (format);
sub->abyss_policy = abyss_policy;

if (index > 0)
{
Expand All @@ -166,7 +167,7 @@ release_tile (GeglBufferIterator *iter,

if (sub->current_tile_mode == GeglIteratorTileMode_DirectTile)
{
if (sub->flags & GEGL_BUFFER_WRITE)
if (sub->access_mode & GEGL_ACCESS_WRITE)
gegl_tile_unlock (sub->current_tile);
gegl_tile_unref (sub->current_tile);

Expand All @@ -184,7 +185,7 @@ release_tile (GeglBufferIterator *iter,
}
else if (sub->current_tile_mode == GeglIteratorTileMode_GetBuffer)
{
if (sub->flags & GEGL_BUFFER_WRITE)
if (sub->access_mode & GEGL_ACCESS_WRITE)
{
gegl_buffer_set_unlocked_no_notify (sub->buffer,
&sub->real_roi,
Expand Down Expand Up @@ -320,7 +321,7 @@ get_tile (GeglBufferIterator *iter,

sub->current_tile = gegl_buffer_get_tile (buf, tile_x, tile_y, 0);

if (sub->flags & GEGL_BUFFER_WRITE)
if (sub->access_mode & GEGL_ACCESS_WRITE)
gegl_tile_lock (sub->current_tile);

sub->real_roi.x = (tile_x * tile_width) - shift_x;
Expand All @@ -345,7 +346,7 @@ get_indirect (GeglBufferIterator *iter,

sub->real_data = gegl_malloc (sub->format_bpp * sub->real_roi.width * sub->real_roi.height);

if (sub->flags & GEGL_BUFFER_READ)
if (sub->access_mode & GEGL_ACCESS_READ)
{
gegl_buffer_get_unlocked (sub->buffer, 1.0, &sub->real_roi, sub->format, sub->real_data,
GEGL_AUTO_ROWSTRIDE, sub->abyss_policy);
Expand All @@ -364,7 +365,7 @@ needs_indirect_read (GeglBufferIterator *iter,
GeglBufferIteratorPriv *priv = iter->priv;
SubIterState *sub = &priv->sub_iter[index];

if (sub->flags & GEGL_ITERATOR_INCOMPATIBLE)
if (sub->access_mode & GEGL_ITERATOR_INCOMPATIBLE)
return TRUE;

/* Needs abyss generation */
Expand Down Expand Up @@ -424,7 +425,7 @@ prepare_iteration (GeglBufferIterator *iter)

/* Format converison needed */
if (gegl_buffer_get_format (sub->buffer) != sub->format)
sub->flags |= GEGL_ITERATOR_INCOMPATIBLE;
sub->access_mode |= GEGL_ITERATOR_INCOMPATIBLE;
/* Incompatable tiles */
else if ((priv->origin_tile.width != buf->tile_width) ||
(priv->origin_tile.height != buf->tile_height) ||
Expand All @@ -439,11 +440,11 @@ prepare_iteration (GeglBufferIterator *iter)
{
sub->linear_tile = gegl_buffer_get_tile (sub->buffer, 0, 0, 0);

if (sub->flags & GEGL_BUFFER_WRITE)
if (sub->access_mode & GEGL_ACCESS_WRITE)
gegl_tile_lock (sub->linear_tile);
}
else
sub->flags |= GEGL_ITERATOR_INCOMPATIBLE;
sub->access_mode |= GEGL_ITERATOR_INCOMPATIBLE;
}

gegl_buffer_lock (sub->buffer);
Expand Down Expand Up @@ -509,14 +510,14 @@ gegl_buffer_iterator_stop (GeglBufferIterator *iter)

if (sub->linear_tile)
{
if (sub->flags & GEGL_BUFFER_WRITE)
if (sub->access_mode & GEGL_ACCESS_WRITE)
gegl_tile_unlock (sub->linear_tile);
gegl_tile_unref (sub->linear_tile);
}

gegl_buffer_unlock (sub->buffer);

if (sub->flags & GEGL_BUFFER_WRITE)
if (sub->access_mode & GEGL_ACCESS_WRITE)
gegl_buffer_emit_changed_signal (sub->buffer, &sub->full_rect);
}

Expand Down
22 changes: 11 additions & 11 deletions gegl/buffer/gegl-buffer-iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

#define GEGL_BUFFER_MAX_ITERATORS 6

#define GEGL_BUFFER_READ 1
#define GEGL_BUFFER_WRITE 2
#define GEGL_BUFFER_READWRITE (GEGL_BUFFER_READ|GEGL_BUFFER_WRITE)
#define GEGL_BUFFER_READ GEGL_ACCESS_READ
#define GEGL_BUFFER_WRITE GEGL_ACCESS_WRITE
#define GEGL_BUFFER_READWRITE GEGL_ACCESS_READWRITE

typedef struct _GeglBufferIteratorPriv GeglBufferIteratorPriv;

Expand Down Expand Up @@ -62,8 +62,8 @@ GeglBufferIterator *gegl_buffer_iterator_empty_new (void);
* @level: the level at which we are iterating, the roi will indicate the
* extent at 1:1, x,y,width and height are/(2^level)
* @format: the format we want to process this buffers data in, pass 0 to use the buffers format.
* @flags: whether we need reading or writing to this buffer one of GEGL_BUFFER_READ, GEGL_BUFFER_WRITE and GEGL_BUFFER_READWRITE.
* @repeat_mode: how request outside the buffer extent are handled.
* @access_mode: whether we need reading or writing to this buffer one of GEGL_BUFFER_READ, GEGL_BUFFER_WRITE and GEGL_BUFFER_READWRITE.
* @abyss_policy: how request outside the buffer extent are handled.
*
* Create a new buffer iterator, this buffer will be iterated through
* in linear chunks, some chunks might be full tiles the coordinates, see
Expand All @@ -77,8 +77,8 @@ GeglBufferIterator * gegl_buffer_iterator_new (GeglBuffer *buffer,
const GeglRectangle *roi,
gint level,
const Babl *format,
guint flags,
GeglAbyssPolicy repeat_mode);
GeglAccessMode access_mode,
GeglAbyssPolicy abyss_policy);


/**
Expand All @@ -89,8 +89,8 @@ GeglBufferIterator * gegl_buffer_iterator_new (GeglBuffer *buffer,
* @level: the level at which we are iterating, the roi will indicate the
* extent at 1:1, x,y,width and height are/(2^level)
* @format: the format we want to process this buffers data in, pass 0 to use the buffers format.
* @flags: whether we need reading or writing to this buffer.
* @repeat_mode: how request outside the buffer extent are handled.
* @access_mode: whether we need reading or writing to this buffer.
* @abyss_policy: how request outside the buffer extent are handled.
*
* Adds an additional buffer iterator that will be processed in sync with
* the original one, if the buffer doesn't align with the other for tile access
Expand All @@ -105,8 +105,8 @@ gint gegl_buffer_iterator_add (GeglBufferIterator *iterator,
const GeglRectangle *roi,
gint level,
const Babl *format,
guint flags,
GeglAbyssPolicy repeat_mode);
GeglAccessMode access_mode,
GeglAbyssPolicy abyss_policy);

/**
* gegl_buffer_iterator_stop: (skip)
Expand Down
26 changes: 26 additions & 0 deletions gegl/gegl-enums.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ gegl_abyss_policy_get_type (void)
return etype;
}

GType
gegl_access_mode_get_type (void)
{
static GType ftype = 0;

if (ftype == 0)
{
static GFlagsValue values[] = {
{ GEGL_ACCESS_READ, N_("Read"), "read" },
{ GEGL_ACCESS_WRITE, N_("Write"), "write" },
{ GEGL_ACCESS_READWRITE, N_("Read/Wrrite"), "readwrite" },
{ 0, NULL, NULL }
};
gint i;

for (i = 0; i < G_N_ELEMENTS (values); i++)
if (values[i].value_name)
values[i].value_name =
dgettext (GETTEXT_PACKAGE, values[i].value_name);

ftype = g_flags_register_static ("GeglAccessMode", values);
}

return ftype;
}

GType
gegl_orientation_get_type (void)
{
Expand Down
11 changes: 11 additions & 0 deletions gegl/gegl-enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ GType gegl_abyss_policy_get_type (void) G_GNUC_CONST;
#define GEGL_TYPE_ABYSS_POLICY (gegl_abyss_policy_get_type ())


typedef enum {
GEGL_ACCESS_READ = 1 << 0,
GEGL_ACCESS_WRITE = 1 << 1,
GEGL_ACCESS_READWRITE = (GEGL_ACCESS_READ | GEGL_ACCESS_WRITE)
} GeglAccessMode;

GType gegl_access_mode_get_type (void) G_GNUC_CONST;

#define GEGL_TYPE_ACCESS_MODE (gegl_access_mode_get_type ())


typedef enum {
GEGL_ORIENTATION_HORIZONTAL,
GEGL_ORIENTATION_VERTICAL
Expand Down
15 changes: 9 additions & 6 deletions gegl/operation/gegl-operation-point-composer.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ gegl_operation_point_composer_process (GeglOperation *operation,
gint threads = gegl_config ()->threads;
GThreadPool *pool = thread_pool ();
ThreadData thread_data[GEGL_MAX_THREADS];
GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, output_buf_format, GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, output_buf_format,
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
gint foo = 0, read = 0;

gint in_bpp = input?babl_format_get_bytes_per_pixel (in_format):0;
Expand All @@ -235,7 +236,8 @@ gegl_operation_point_composer_process (GeglOperation *operation,

if (input)
{
read = gegl_buffer_iterator_add (i, input, result, level, in_buf_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
read = gegl_buffer_iterator_add (i, input, result, level, in_buf_format,
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
for (gint j = 0; j < threads; j ++)
{
if (in_buf_format != in_format)
Expand All @@ -254,7 +256,8 @@ gegl_operation_point_composer_process (GeglOperation *operation,
thread_data[j].input_fish = NULL;
if (aux)
{
foo = gegl_buffer_iterator_add (i, aux, result, level, aux_buf_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
foo = gegl_buffer_iterator_add (i, aux, result, level, aux_buf_format,
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
for (gint j = 0; j < threads; j ++)
{
if (aux_buf_format != aux_format)
Expand Down Expand Up @@ -334,13 +337,13 @@ gegl_operation_point_composer_process (GeglOperation *operation,
}
else
{
GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, out_format, GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, out_format, GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
gint foo = 0, read = 0;

if (input)
read = gegl_buffer_iterator_add (i, input, result, level, in_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
read = gegl_buffer_iterator_add (i, input, result, level, in_format, GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
if (aux)
foo = gegl_buffer_iterator_add (i, aux, result, level, aux_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
foo = gegl_buffer_iterator_add (i, aux, result, level, aux_format, GEGL_ACCESS_READ, GEGL_ABYSS_NONE);

while (gegl_buffer_iterator_next (i))
{
Expand Down
22 changes: 14 additions & 8 deletions gegl/operation/gegl-operation-point-composer3.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ gegl_operation_point_composer3_process (GeglOperation *operation,
gint threads = gegl_config ()->threads;
GThreadPool *pool = thread_pool ();
ThreadData thread_data[GEGL_MAX_THREADS];
GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, output_buf_format, GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, output_buf_format, GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
gint foo = 0, bar = 0, read = 0;

gint in_bpp = input?babl_format_get_bytes_per_pixel (in_format):0;
Expand All @@ -257,7 +257,7 @@ gegl_operation_point_composer3_process (GeglOperation *operation,

if (input)
{
read = gegl_buffer_iterator_add (i, input, result, level, in_buf_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
read = gegl_buffer_iterator_add (i, input, result, level, in_buf_format, GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
for (gint j = 0; j < threads; j ++)
{
if (in_buf_format != in_format)
Expand All @@ -276,7 +276,8 @@ gegl_operation_point_composer3_process (GeglOperation *operation,
thread_data[j].input_fish = NULL;
if (aux)
{
foo = gegl_buffer_iterator_add (i, aux, result, level, aux_buf_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
foo = gegl_buffer_iterator_add (i, aux, result, level, aux_buf_format,
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
for (gint j = 0; j < threads; j ++)
{
if (aux_buf_format != aux_format)
Expand All @@ -297,7 +298,8 @@ gegl_operation_point_composer3_process (GeglOperation *operation,
}
if (aux2)
{
bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_buf_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_buf_format,
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
for (gint j = 0; j < threads; j ++)
{
if (aux2_buf_format != aux2_format)
Expand Down Expand Up @@ -378,15 +380,19 @@ gegl_operation_point_composer3_process (GeglOperation *operation,
}
else
{
GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, out_format, GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, out_format,
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
gint foo = 0, bar = 0, read = 0;

if (input)
read = gegl_buffer_iterator_add (i, input, result, level, in_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
read = gegl_buffer_iterator_add (i, input, result, level, in_format,
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
if (aux)
foo = gegl_buffer_iterator_add (i, aux, result, level, aux_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
foo = gegl_buffer_iterator_add (i, aux, result, level, aux_format,
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
if (aux2)
bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_format,
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);

while (gegl_buffer_iterator_next (i))
{
Expand Down
Loading

0 comments on commit 5f3bdfc

Please sign in to comment.