diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-10-05 01:44:24 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2012-10-05 01:44:24 -0400 |
commit | 8749ffeeeec953ae0b6b926207d26d1d5dff1a8f (patch) | |
tree | 17564658e3519b12b79ea5a4dc99cf1fff1de67e | |
parent | c90d693c9742748bb89e140c628b3d3d2fd3e0bb (diff) |
rename command to composite; delete old comments; misc formatting
-rw-r--r-- | fimage.c | 389 | ||||
-rw-r--r-- | fragment.c | 33 |
2 files changed, 41 insertions, 381 deletions
@@ -5,6 +5,7 @@ /* TODO: * * rename to fragment_list? + * is the memory management too crackful? */ struct fimage_t @@ -29,20 +30,20 @@ fimage_ensure_space (fimage_t *fimage, int n_more) if (required_fragments > fimage->n_allocated_fragments) { - size_t pot = 1; - size_t space; fimage_t *new_image; + size_t space; + int pot; + pot = 1; while (pot < required_fragments) pot *= 2; space = sizeof (fimage_t) + (pot - 1) * sizeof (fragment_t *); - new_image = realloc (fimage, space); - - if (!new_image) + if (!(new_image = realloc (fimage, space))) { fimage_free (fimage); + return (fimage_t *)&broken_fimage; } @@ -57,20 +58,19 @@ fimage_ensure_space (fimage_t *fimage, int n_more) static fimage_t * fimage_append_fragment (fimage_t *fimage, fragment_t *fragment) { - if (fimage->broken) + if (fimage->broken || fragment_is_broken (fragment)) { + fimage_free (fimage); fragment_free (fragment); - return fimage; - } - if (fragment_is_broken (fragment)) - { - fimage_free (fimage); return (fimage_t *)&broken_fimage; } if (fragment_is_empty (fragment)) + { + fragment_free (fragment); return fimage; + } fimage = ensure_space (fimage, 1); if (fimage->broken) @@ -85,12 +85,8 @@ fimage_new (void) { fimage_t *fimage; - fimage = malloc (sizeof *fimage); - if (!fimage) - { - fragment_free (fragment); + if (!(fimage = malloc (sizeof *fimage))) return (fimage_t *)&broken_fimage; - } fimage->broken = FALSE; fimage->n_allocated_fragments = 1; @@ -121,7 +117,8 @@ fimage_t * fimage_new_traps (int width, int height, int n_traps, pixman_trapezoid_t *traps) { - return make_image (fragment_new_traps (width, height, n_traps, traps)); + return make_image ( + fragment_new_traps (width, height, n_traps, traps)); } fimage_t * @@ -162,39 +159,37 @@ fimage_new_region (int width, int height, } fimage_t * -fimage_composite (fimage_t *fimage, pixman_op_t op, fimage_t *source) +fimage_composite (fimage_t *dest, pixman_op_t op, fimage_t *source) { - fragment_t *dfrag, *sfrag; fimage_t *new_image; int i, j; - int n; - if (fimage->broken || source->broken) + if (dest->broken || source->broken) { - fimage_free (fimage); + fimage_free (dest); return (fimage_t *)&broken_fimage; } new_image = fimage_new (); - for (i = 0; fimage->n_fragments; ++i) + for (i = 0; dest->n_fragments; ++i) { for (j = 0; j < source->n_fragments; ++j) { - fragment_t *new, *dfrag, *sfrag; + fragment_t *new_frag, *dfrag, *sfrag; - dfrag = fimage->fragments[i]; + dfrag = dest->fragments[i]; sfrag = source->fragments[j]; - new = fragment_composite (dfrag, op, sfrag); + new_frag = fragment_composite (dfrag, op, sfrag); - new_image = fimage_append_fragment (new_image, new); + new_image = fimage_append_fragment (new_image, new_frag); new_image = fimage_append_fragment (new_image, dfrag); } } - fimage->n_fragments = 0; - fimage_free (fimage); + dest->n_fragments = 0; + fimage_free (dest); return new_image; } @@ -204,344 +199,10 @@ fimage_paint (fimage_t *image, pixman_image_t *image) { int i; - for (i = 0; i < image->n_fragments; ++i) + for (i = 0; i < image->n_fragments; ++i) { fragment_t *fragment = image->fragments[i]; fragment_apply (fragment, image); } } - -/* - - Memory management: - - For traps we don't want to copy them, so the image should take ownership. - Maybe the cairo->pixman conversion should just take place inside the image? - Maybe it doesn't matter that much. - Maybe polygon images will make the question irrelevant. - However, we definitely don't want to copy the traps structure to - all the fragments. - - For pimages, have the image take a ref would be more convenient. - - For initializing with a region, it would be convenient, but not essential, - if we can avoid copying the region parameter. - - Structures internal to the images and fragments are of course managed and - owned by the structures in question. - - - images take ownership - - fragments take ownership - - fragments wrap objects in refcountable structure - - fragments don't ref pixman images - - fragments ref the given objects - - pixman images are reffed by the fragments, and unreffed - when the image is destroyed. - - - ref countable state object? - -*/ -typedef struct fragment_t fragment_t; -typedef struct image_t image_t; -typedef struct command_buffer_t command_buffer_t; - -#define TRUE 1 -#define FALSE 0 - -typedef enum -{ - BLANK, - WHITE, - SOLID, - TRAPS, - PIXMAN, - COMMANDS -} state_t; - -struct fragment_t -{ - pixman_bool_t broken; - pixman_region32_t region; - fragment_t * next; - - /* State - should this be a separate structure? */ - state_t state; - pixman_bool_t alpha_only; - union - { - pixman_color_t solid; - struct - { - int n_traps; - pixman_trapezoid_t *traps; - } traps; - pixman_image_t *image; - command_buffer_t *buffer; - } u; -}; - -struct image_t -{ - pixman_bool_t broken; - int width, height; - fragment_t * fragments; -}; - -static const image_t broken = -{ - TRUE /* broken */ -}; - -static const fragment_t broken_fragment = -{ - TRUE -}; - -static fragment_t * -fragment_new (int width, int height) -{ - fragment_t *result = malloc (sizeof *result); - - if (!result) - return (fragment_t *)&broken_fragment; - - pixman_region32_init_rect (&result->region, 0, 0, width, height); - - return result; -} - -static void -fragment_free (fragment_t *fragment) -{ - if (fragment->broken) - return; - - - /* FIXME */ -} - -static void -fragment_set_blank (fragment_t *fragment) -{ - if (fragment->broken) - return; - - fragment->state = BLANK; -} - -static void -fragment_set_pixman (fragment_t *fragment, pixman_image_t *image) -{ - if (fragment->broken) - return; - - fragment->state = PIXMAN; - fragment->u.image = image; -} - -/* Split @fragment into two parts: one that intersects @source - * and one that doesn't. Both may be NULL. @dest is freed or reused. - */ -static void -fragment_intersect (fragment_t *dest, fragment_t *source, - fragment_t **intersection, - fragment_t **remains) -{ - *intersection = NULL; - - if (dest->broken) - { - *remains = NULL; - return; - } - - *remains = dest; - - if (source->broken) - { - *intersection = NULL; - return; - } - - *intersection = fragment_new (0, 0); - - if ((*intersection)->broken) - { - *intersection = NULL; - return; - } - - if (!pixman_region32_intersect (&((*intersection)->region), - &(dest->region), - &(source->region))) - { - fragment_free (*intersection); - *intersection = NULL; - return; - } - - if (!pixman_region32_subtract (&(dest->region), &(dest->region), - &(*intersection)->region)) - { - fragment_free (dest); - fragment_free (*intersection); - *remains = NULL; - *intersection = NULL; - return; - } - - if (!pixman_region32_not_empty (&(*intersection)->region)) - { - fragment_free (*intersection); - *intersection = NULL; - } - - if (!pixman_region32_not_empty (&dest->region)) - { - fragment_free (dest); - *remains = NULL; - } -} - -static void -fragment_composite (fragment_t *result, pixman_op_t op, - fragment_t *dest, fragment_t *src) -{ - if ((op == PIXMAN_OP_ADD && dest->state == BLANK) || - (op == PIXMAN_OP_IN && is_opaque (dest))) - { - op = PIXMAN_OP_SRC; - } - - switch (op) - { - case PIXMAN_OP_SRC: - copy_state (result, src); - break; - - case PIXMAN_OP_IN: - if (dest->state == BLANK || src->state == BLANK) - result->state == BLANK; - break; - - case PIXMAN_OP_OUT_REVERSE: - if (is_opaque (src)) - result->state == BLANK; - else if (src->state == BLANK) - copy_state (result, dest->state); - break; - - default: - /* FIXME: add command to composite the images */ - break; - } -} - -static image_t * -allocate_image (int width, int height) -{ - image_t *image = malloc (sizeof *image); - - if (!image) - return (image_t *)&broken; - - image->width = width; - image->height = height; - image->fragments = fragment_new (width, height); - - return image; -} - -static image_t * -image_new_blank (int width, int height) -{ - image_t *image; - - image = allocate_image (width, height); - if (image->broken) - return image; - - fragment_set_blank (image->fragments); - return image; -} - -void -image_free (image_t *image) -{ - if (image->broken) - return; - - /* FIXME */ -} - -static image_t * -image_new_pixman (int width, int height, pixman_image_t *pimage) -{ - image_t *image; - - image = allocate_image (width, height); - if (image->broken) - return image; - - fragment_set_pixman (image->fragments, pimage); - return image; -} - -static void -image_composite (image_t *dest, pixman_op_t op, image_t *src, image_t *mask) -{ - fragment_t *sfrag; - - if (dest->broken || src->broken || (mask && mask->broken)) - return; - - if (mask) - { - image_t *tmp = allocate_image (dest->width, dest->height); - - image_composite (tmp, PIXMAN_OP_SRC, mask, NULL); - image_composite (tmp, PIXMAN_OP_IN, src, NULL); - image_composite (dest, op, tmp, NULL); - - image_free (tmp); - - return; - } - - sfrag = src->fragments; - while (sfrag) - { - fragment_t *new_fragments = NULL; - fragment_t *dfrag; - - dfrag = dest->fragments; - while (dfrag != NULL) - { - fragment_t *intersection, *remains; - fragment_t *next = dfrag->next; - - fragment_intersect (dfrag, sfrag, &intersection, &remains); - - if (intersection) - { - fragment_composite (intersect, op, dfrag, sfrag); - - intersection->next = new_fragments; - new_fragments = intersection; - } - - if (remains) - { - remains->next = new_fragments; - new_fragments = remains; - } - - dfrag = next; - } - - sfrag = sfrag->next; - } - - dest->fragments = new_fragments; -} @@ -23,7 +23,7 @@ typedef enum STATE_TRAPS, STATE_GLYPHS, STATE_IMAGE, - STATE_COMMAND /* FIXME: should be called composite? */ + STATE_COMPOSITE } state_type_t; typedef struct @@ -61,7 +61,7 @@ typedef struct state_t * dest; pixman_op_t op; state_t * source; -} state_command_t; +} state_composite_t; union state_t { @@ -69,7 +69,7 @@ union state_t state_traps_t traps; state_glyphs_t glyphs; state_image_t image; - state_command_t command; + state_composite_t composite; }; struct fragment_t @@ -119,9 +119,9 @@ state_unref (state_t *state) case STATE_IMAGE: pixman_image_unref (state->image.image); break; - case STATE_COMMAND: - state_unref (state->command.dest); - state_unref (state->command.source); + case STATE_COMPOSITE: + state_unref (state->composite.dest); + state_unref (state->composite.source); break; } @@ -138,15 +138,15 @@ state_composite (state_t *dest, pixman_op_t op, state_t *source) if (!new_state) return NULL; - /* FIXME: Always using COMMAND should be correct, but + /* FIXME: Always using COMPOSITE should be correct, but * we can do a lot better with a few simple optimizations */ - new_state->common.type = STATE_COMMAND; + new_state->common.type = STATE_COMPOSITE; new_state->common.ref_count = 1; - new_state->command.dest = state_ref (dest); - new_state->command.op = op; - new_state->command.source = state_ref (source); + new_state->composite.dest = state_ref (dest); + new_state->composite.op = op; + new_state->composite.source = state_ref (source); return new_state; } @@ -264,8 +264,7 @@ fragment_intersect (fragment_t *dest, fragment_t *source) { fragment_t *new_fragment; - new_fragment = malloc (sizeof *new_fragment); - if (!new_fragment) + if (!(new_fragment = malloc (sizeof *new_fragment))) return (fragment_t *)&broken_fragment; new_fragment->broken = FALSE; @@ -398,7 +397,7 @@ state_apply (state_t *state, pixman_image_t *image) 0, 0, 0, 0, 0, 0, width, height); break; - case STATE_COMMAND: + case STATE_COMPOSITE: /* FIXME: track alpha-only */ temp = pixman_image_create_bits ( PIXMAN_a8r8g8b8, width, height, NULL, -1); @@ -406,15 +405,15 @@ state_apply (state_t *state, pixman_image_t *image) if (!temp) break; /* FIXME: status */ - state_apply (state->command.dest, image); + state_apply (state->composite.dest, image); /* FIXME: check if source can be expressed as * (s IN m), (s IN glyphs), (s IN traps) */ - state_apply (state->command.source, temp); + state_apply (state->composite.source, temp); pixman_image_composite32 ( - state->command.op, temp, NULL, image, + state->composite.op, temp, NULL, image, 0, 0, 0, 0, 0, 0, width, height); pixman_image_unref (temp); |