cairo_status_t _cairo_clip_init_copy_transformed (cairo_clip_t *clip, cairo_clip_t *other, const cairo_matrix_t *matrix) { cairo_status_t status = CAIRO_STATUS_SUCCESS; int tx, ty; if (other == NULL) { _cairo_clip_init (clip); return CAIRO_STATUS_SUCCESS; } if (other->all_clipped) { _cairo_clip_init (clip); clip->all_clipped = TRUE; return CAIRO_STATUS_SUCCESS; } if (_cairo_matrix_is_identity (matrix)) { _cairo_clip_init_copy (clip, other); return CAIRO_STATUS_SUCCESS; } if (other->path != NULL) { _cairo_clip_init (clip); /* if we only need to translate, so we can reuse the caches... */ /* XXX we still loose the benefit of constructs when the copy is * deleted though. Indirect clip_paths? */ if (_cairo_matrix_is_integer_translation (matrix, &tx, &ty)) { status = _cairo_clip_path_reapply_clip_path_translate (clip, other->path, tx, ty); } else { status = _cairo_clip_path_reapply_clip_path_transform (clip, other->path, matrix); if (clip->path->extents.width == 0 && clip->path->extents.height == 0) { _cairo_clip_set_all_clipped (clip); } } } return status; }
void _cairo_clip_init_deep_copy (cairo_clip_t *clip, cairo_clip_t *other, cairo_surface_t *target) { _cairo_clip_init (clip, target); if (other->mode != clip->mode) { /* We should reapply the original clip path in this case, and let * whatever the right handling is happen */ } else { if (other->region) { clip->region = pixman_region_create (); pixman_region_copy (clip->region, other->region); } if (other->surface) { _cairo_surface_clone_similar (target, other->surface, &clip->surface); clip->surface_rect = other->surface_rect; } if (other->path) { _cairo_clip_path_reapply_clip_path (clip, other->path); } } }
void _cairo_surface_clipper_init (cairo_surface_clipper_t *clipper, cairo_surface_clipper_intersect_clip_path_func_t func) { _cairo_clip_init (&clipper->clip); clipper->is_clipped = FALSE; clipper->intersect_clip_path = func; }
cairo_status_t _cairo_clip_init_deep_copy (cairo_clip_t *clip, cairo_clip_t *other, cairo_surface_t *target) { cairo_status_t status; _cairo_clip_init (clip, target); if (other->mode != clip->mode) { /* We should reapply the original clip path in this case, and let * whatever the right handling is happen */ } else { if (other->has_region) { status = _cairo_region_copy (&clip->region, &other->region); if (unlikely (status)) goto BAIL; clip->has_region = TRUE; } if (other->surface) { int dx, dy; status = _cairo_surface_clone_similar (target, other->surface, 0, 0, other->surface_rect.width, other->surface_rect.height, &dx, &dy, &clip->surface); if (unlikely (status)) goto BAIL; clip->surface_rect = other->surface_rect; /* src offset was 0, so we expect an exact replica of the surface */ assert (dx == 0); assert (dy == 0); } if (other->path) { status = _cairo_clip_path_reapply_clip_path (clip, other->path); if (_cairo_status_is_error (status)) goto BAIL; } } return CAIRO_STATUS_SUCCESS; BAIL: if (clip->has_region) _cairo_region_fini (&clip->region); if (clip->surface) cairo_surface_destroy (clip->surface); return status; }
cairo_status_t _cairo_clip_init_deep_copy (cairo_clip_t *clip, cairo_clip_t *other, cairo_surface_t *target) { cairo_status_t status; _cairo_clip_init (clip, target); if (other->mode != clip->mode) { /* We should reapply the original clip path in this case, and let * whatever the right handling is happen */ } else { if (other->has_region) { status = _cairo_region_copy (&clip->region, &other->region); if (status) goto BAIL; clip->has_region = TRUE; } if (other->surface) { status = _cairo_surface_clone_similar (target, other->surface, other->surface_rect.x, other->surface_rect.y, other->surface_rect.width, other->surface_rect.height, &clip->surface); if (status) goto BAIL; clip->surface_rect = other->surface_rect; } if (other->path) { status = _cairo_clip_path_reapply_clip_path (clip, other->path); if (status && status != CAIRO_INT_STATUS_UNSUPPORTED) goto BAIL; } } return CAIRO_STATUS_SUCCESS; BAIL: if (clip->has_region) _cairo_region_fini (&clip->region); if (clip->surface) cairo_surface_destroy (clip->surface); return status; }
/** * cairo_recording_surface_create: * @content: the content of the recording surface * @extents: the extents to record in pixels, can be %NULL to record * unbounded operations. * * Creates a recording-surface which can be used to record all drawing operations * at the highest level (that is, the level of paint, mask, stroke, fill * and show_text_glyphs). The recording surface can then be "replayed" against * any target surface by using it as a source to drawing operations. * * The recording phase of the recording surface is careful to snapshot all * necessary objects (paths, patterns, etc.), in order to achieve * accurate replay. * * Return value: a pointer to the newly created surface. The caller * owns the surface and should call cairo_surface_destroy() when done * with it. * * Since: 1.10 **/ cairo_surface_t * cairo_recording_surface_create (cairo_content_t content, const cairo_rectangle_t *extents) { cairo_recording_surface_t *recording_surface; cairo_status_t status; recording_surface = malloc (sizeof (cairo_recording_surface_t)); if (unlikely (recording_surface == NULL)) return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); _cairo_surface_init (&recording_surface->base, &cairo_recording_surface_backend, NULL, /* device */ content); recording_surface->content = content; recording_surface->unbounded = TRUE; _cairo_clip_init (&recording_surface->clip); /* unbounded -> 'infinite' extents */ if (extents != NULL) { recording_surface->extents_pixels = *extents; /* XXX check for overflow */ recording_surface->extents.x = floor (extents->x); recording_surface->extents.y = floor (extents->y); recording_surface->extents.width = ceil (extents->x + extents->width) - recording_surface->extents.x; recording_surface->extents.height = ceil (extents->y + extents->height) - recording_surface->extents.y; status = _cairo_clip_rectangle (&recording_surface->clip, &recording_surface->extents); if (unlikely (status)) { free (recording_surface); return _cairo_surface_create_in_error (status); } recording_surface->unbounded = FALSE; } _cairo_array_init (&recording_surface->commands, sizeof (cairo_command_t *)); recording_surface->replay_start_idx = 0; recording_surface->base.is_clear = TRUE; return &recording_surface->base; }
cairo_clip_t * _cairo_clip_init_copy (cairo_clip_t *clip, cairo_clip_t *other) { if (other != NULL) { clip->all_clipped = other->all_clipped; clip->path = _cairo_clip_path_reference (other->path); /* this guy is here because of the weird return semantics of _cairo_clip_init_copy */ if (!other->path) return NULL; } else { _cairo_clip_init (clip); } return clip; }
/* XXX consider accepting a matrix, no users yet. */ cairo_status_t _cairo_clip_init_rectangle (cairo_clip_t *clip, const cairo_rectangle_int_t *rect) { _cairo_clip_init (clip); if (rect == NULL) return CAIRO_STATUS_SUCCESS; if (rect->width == 0 || rect->height == 0) { _cairo_clip_set_all_clipped (clip); return CAIRO_STATUS_SUCCESS; } return _cairo_clip_intersect_rectangle (clip, rect); }
static cairo_status_t _cairo_meta_surface_replay_internal (cairo_surface_t *surface, cairo_surface_t *target, cairo_meta_replay_type_t type, cairo_meta_region_type_t region) { cairo_meta_surface_t *meta; cairo_command_t *command, **elements; int i, num_elements; cairo_int_status_t status, status2; cairo_clip_t clip, *old_clip; cairo_bool_t has_device_transform = _cairo_surface_has_device_transform (target); cairo_matrix_t *device_transform = &target->device_transform; cairo_path_fixed_t path_copy, *dev_path; if (surface->status) return surface->status; if (target->status) return _cairo_surface_set_error (surface, target->status); meta = (cairo_meta_surface_t *) surface; status = CAIRO_STATUS_SUCCESS; _cairo_clip_init (&clip, target); old_clip = _cairo_surface_get_clip (target); num_elements = meta->commands.num_elements; elements = _cairo_array_index (&meta->commands, 0); for (i = meta->replay_start_idx; i < num_elements; i++) { command = elements[i]; if (type == CAIRO_META_REPLAY && region != CAIRO_META_REGION_ALL) { if (command->header.region != region) continue; } /* For all commands except intersect_clip_path, we have to * ensure the current clip gets set on the surface. */ if (command->header.type != CAIRO_COMMAND_INTERSECT_CLIP_PATH) { status = _cairo_surface_set_clip (target, &clip); if (status) break; } dev_path = _cairo_command_get_path (command); if (dev_path && has_device_transform) { status = _cairo_path_fixed_init_copy (&path_copy, dev_path); if (status) break; _cairo_path_fixed_transform (&path_copy, device_transform); dev_path = &path_copy; } switch (command->header.type) { case CAIRO_COMMAND_PAINT: status = _cairo_surface_paint (target, command->paint.op, &command->paint.source.base); break; case CAIRO_COMMAND_MASK: status = _cairo_surface_mask (target, command->mask.op, &command->mask.source.base, &command->mask.mask.base); break; case CAIRO_COMMAND_STROKE: { cairo_matrix_t dev_ctm = command->stroke.ctm; cairo_matrix_t dev_ctm_inverse = command->stroke.ctm_inverse; if (has_device_transform) { cairo_matrix_multiply (&dev_ctm, &dev_ctm, device_transform); cairo_matrix_multiply (&dev_ctm_inverse, &target->device_transform_inverse, &dev_ctm_inverse); } status = _cairo_surface_stroke (target, command->stroke.op, &command->stroke.source.base, dev_path, &command->stroke.style, &dev_ctm, &dev_ctm_inverse, command->stroke.tolerance, command->stroke.antialias); break; } case CAIRO_COMMAND_FILL: { cairo_command_t *stroke_command; if (type != CAIRO_META_CREATE_REGIONS) stroke_command = (i < num_elements - 1) ? elements[i + 1] : NULL; else stroke_command = NULL; if (stroke_command != NULL && type == CAIRO_META_REPLAY && region != CAIRO_META_REGION_ALL) { if (stroke_command->header.region != region) stroke_command = NULL; } if (stroke_command != NULL && stroke_command->header.type == CAIRO_COMMAND_STROKE && _cairo_path_fixed_is_equal (dev_path, _cairo_command_get_path (stroke_command))) { cairo_matrix_t dev_ctm; cairo_matrix_t dev_ctm_inverse; dev_ctm = stroke_command->stroke.ctm; dev_ctm_inverse = stroke_command->stroke.ctm_inverse; if (has_device_transform) { cairo_matrix_multiply (&dev_ctm, &dev_ctm, device_transform); cairo_matrix_multiply (&dev_ctm_inverse, &surface->device_transform_inverse, &dev_ctm_inverse); } status = _cairo_surface_fill_stroke (target, command->fill.op, &command->fill.source.base, command->fill.fill_rule, command->fill.tolerance, command->fill.antialias, dev_path, stroke_command->stroke.op, &stroke_command->stroke.source.base, &stroke_command->stroke.style, &dev_ctm, &dev_ctm_inverse, stroke_command->stroke.tolerance, stroke_command->stroke.antialias); i++; } else status = _cairo_surface_fill (target, command->fill.op, &command->fill.source.base, dev_path, command->fill.fill_rule, command->fill.tolerance, command->fill.antialias); break; } case CAIRO_COMMAND_SHOW_TEXT_GLYPHS: { cairo_glyph_t *glyphs = command->show_text_glyphs.glyphs; cairo_glyph_t *dev_glyphs; int i, num_glyphs = command->show_text_glyphs.num_glyphs; /* show_text_glyphs is special because _cairo_surface_show_text_glyphs is allowed * to modify the glyph array that's passed in. We must always * copy the array before handing it to the backend. */ dev_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t)); if (dev_glyphs == NULL) { status = _cairo_error (CAIRO_STATUS_NO_MEMORY); break; } if (has_device_transform) { for (i = 0; i < num_glyphs; i++) { dev_glyphs[i] = glyphs[i]; cairo_matrix_transform_point (device_transform, &dev_glyphs[i].x, &dev_glyphs[i].y); } } else { memcpy (dev_glyphs, glyphs, sizeof (cairo_glyph_t) * num_glyphs); } status = _cairo_surface_show_text_glyphs (target, command->show_text_glyphs.op, &command->show_text_glyphs.source.base, command->show_text_glyphs.utf8, command->show_text_glyphs.utf8_len, dev_glyphs, num_glyphs, command->show_text_glyphs.clusters, command->show_text_glyphs.num_clusters, command->show_text_glyphs.cluster_flags, command->show_text_glyphs.scaled_font); free (dev_glyphs); break; } case CAIRO_COMMAND_INTERSECT_CLIP_PATH: /* XXX Meta surface clipping is broken and requires some * cairo-gstate.c rewriting. Work around it for now. */ if (dev_path == NULL) _cairo_clip_reset (&clip); else status = _cairo_clip_clip (&clip, dev_path, command->intersect_clip_path.fill_rule, command->intersect_clip_path.tolerance, command->intersect_clip_path.antialias, target); break; default: ASSERT_NOT_REACHED; } if (dev_path == &path_copy) _cairo_path_fixed_fini (&path_copy); if (type == CAIRO_META_CREATE_REGIONS) { if (status == CAIRO_STATUS_SUCCESS) { command->header.region = CAIRO_META_REGION_NATIVE; } else if (status == CAIRO_INT_STATUS_IMAGE_FALLBACK) { command->header.region = CAIRO_META_REGION_IMAGE_FALLBACK; status = CAIRO_STATUS_SUCCESS; } } if (status) break; } _cairo_clip_reset (&clip); status2 = _cairo_surface_set_clip (target, old_clip); if (status == CAIRO_STATUS_SUCCESS) status = status2; return _cairo_surface_set_error (surface, status); }
cairo_int_status_t _cairo_meta_surface_replay (cairo_surface_t *surface, cairo_surface_t *target) { cairo_meta_surface_t *meta; cairo_command_t *command, **elements; int i, num_elements; cairo_int_status_t status; cairo_traps_t traps; cairo_clip_t clip; meta = (cairo_meta_surface_t *) surface; status = CAIRO_STATUS_SUCCESS; _cairo_clip_init (&clip, target); num_elements = meta->commands.num_elements; elements = (cairo_command_t **) meta->commands.elements; for (i = 0; i < num_elements; i++) { command = elements[i]; switch (command->type) { case CAIRO_COMMAND_COMPOSITE: status = _cairo_surface_set_clip (target, &clip); if (status) break; status = _cairo_surface_composite (command->composite.operator, &command->composite.src_pattern.base, command->composite.mask_pattern_pointer, target, command->composite.src_x, command->composite.src_y, command->composite.mask_x, command->composite.mask_y, command->composite.dst_x, command->composite.dst_y, command->composite.width, command->composite.height); break; case CAIRO_COMMAND_FILL_RECTANGLES: status = _cairo_surface_set_clip (target, &clip); if (status) break; status = _cairo_surface_fill_rectangles (target, command->fill_rectangles.operator, &command->fill_rectangles.color, command->fill_rectangles.rects, command->fill_rectangles.num_rects); break; case CAIRO_COMMAND_COMPOSITE_TRAPEZOIDS: status = _cairo_surface_set_clip (target, &clip); if (status) break; status = _cairo_surface_composite_trapezoids (command->composite_trapezoids.operator, &command->composite_trapezoids.pattern.base, target, command->composite_trapezoids.antialias, command->composite_trapezoids.x_src, command->composite_trapezoids.y_src, command->composite_trapezoids.x_dst, command->composite_trapezoids.y_dst, command->composite_trapezoids.width, command->composite_trapezoids.height, command->composite_trapezoids.traps, command->composite_trapezoids.num_traps); break; case CAIRO_COMMAND_INTERSECT_CLIP_PATH: /* XXX Meta surface clipping is broken and requires some * cairo-gstate.c rewriting. Work around it for now. */ if (command->intersect_clip_path.path_pointer == NULL) status = _cairo_clip_reset (&clip); else status = _cairo_clip_clip (&clip, command->intersect_clip_path.path_pointer, command->intersect_clip_path.fill_rule, command->intersect_clip_path.tolerance, command->intersect_clip_path.antialias, target); break; case CAIRO_COMMAND_SHOW_GLYPHS: status = _cairo_surface_set_clip (target, &clip); if (status) break; status = _cairo_surface_show_glyphs (command->show_glyphs.scaled_font, command->show_glyphs.operator, &command->show_glyphs.pattern.base, target, command->show_glyphs.source_x, command->show_glyphs.source_y, command->show_glyphs.dest_x, command->show_glyphs.dest_y, command->show_glyphs.width, command->show_glyphs.height, command->show_glyphs.glyphs, command->show_glyphs.num_glyphs); if (status != CAIRO_INT_STATUS_UNSUPPORTED) break; status = (*command->show_glyphs.scaled_font->backend-> show_glyphs) (command->show_glyphs.scaled_font, command->show_glyphs.operator, &command->show_glyphs.pattern.base, target, command->show_glyphs.source_x, command->show_glyphs.source_y, command->show_glyphs.dest_x, command->show_glyphs.dest_y, command->show_glyphs.width, command->show_glyphs.height, command->show_glyphs.glyphs, command->show_glyphs.num_glyphs); break; case CAIRO_COMMAND_FILL_PATH: status = _cairo_surface_set_clip (target, &clip); if (status) break; status = _cairo_surface_fill_path (command->fill_path.operator, &command->fill_path.pattern.base, target, &command->fill_path.path, command->fill_path.fill_rule, command->fill_path.tolerance); if (status != CAIRO_INT_STATUS_UNSUPPORTED) break; _cairo_traps_init (&traps); status = _cairo_path_fixed_fill_to_traps (&command->fill_path.path, command->fill_path.fill_rule, command->fill_path.tolerance, &traps); if (status) { _cairo_traps_fini (&traps); break; } status = _cairo_surface_clip_and_composite_trapezoids (&command->fill_path.pattern.base, command->fill_path.operator, target, &traps, &clip, command->fill_path.antialias); _cairo_traps_fini (&traps); break; default: ASSERT_NOT_REACHED; } if (status) break; } _cairo_clip_fini (&clip); return status; }