static cairo_pattern_t * _cairo_default_context_pop_group (void *abstract_cr) { cairo_default_context_t *cr = abstract_cr; cairo_surface_t *group_surface; cairo_pattern_t *group_pattern; cairo_matrix_t group_matrix, device_transform_matrix; cairo_status_t status; /* Verify that we are at the right nesting level */ if (unlikely (! _cairo_gstate_is_group (cr->gstate))) return _cairo_pattern_create_in_error (CAIRO_STATUS_INVALID_POP_GROUP); /* Get a reference to the active surface before restoring */ group_surface = _cairo_gstate_get_target (cr->gstate); group_surface = cairo_surface_reference (group_surface); status = _cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist); assert (status == CAIRO_STATUS_SUCCESS); group_pattern = cairo_pattern_create_for_surface (group_surface); status = group_pattern->status; if (unlikely (status)) goto done; _cairo_gstate_get_matrix (cr->gstate, &group_matrix); /* Transform by group_matrix centered around device_transform so that when * we call _cairo_gstate_copy_transformed_pattern the result is a pattern * with a matrix equivalent to the device_transform of group_surface. */ if (_cairo_surface_has_device_transform (group_surface)) { cairo_pattern_set_matrix (group_pattern, &group_surface->device_transform); _cairo_pattern_transform (group_pattern, &group_matrix); _cairo_pattern_transform (group_pattern, &group_surface->device_transform_inverse); } else { cairo_pattern_set_matrix (group_pattern, &group_matrix); } /* If we have a current path, we need to adjust it to compensate for * the device offset just removed. */ cairo_matrix_multiply (&device_transform_matrix, &_cairo_gstate_get_target (cr->gstate)->device_transform, &group_surface->device_transform_inverse); _cairo_path_fixed_transform (cr->path, &device_transform_matrix); done: cairo_surface_destroy (group_surface); return group_pattern; }
static cairo_pattern_t * _cairo_skia_context_pop_group (void *abstract_cr) { cairo_skia_context_t *cr = (cairo_skia_context_t *) abstract_cr; cairo_surface_t *group_surface; cairo_pattern_t *group_pattern; cairo_status_t status; group_surface = cairo_surface_reference (&cr->target->image.base); status = _cairo_skia_context_restore (cr); if (unlikely (status)) { group_pattern = _cairo_pattern_create_in_error (status); goto done; } group_pattern = cairo_pattern_create_for_surface (group_surface); status = group_pattern->status; if (unlikely (status)) goto done; #if 0 _cairo_gstate_get_matrix (cr->gstate, &group_matrix); /* Transform by group_matrix centered around device_transform so that when * we call _cairo_gstate_copy_transformed_pattern the result is a pattern * with a matrix equivalent to the device_transform of group_surface. */ if (_cairo_surface_has_device_transform (group_surface)) { cairo_pattern_set_matrix (group_pattern, &group_surface->device_transform); _cairo_pattern_transform (group_pattern, &group_matrix); _cairo_pattern_transform (group_pattern, &group_surface->device_transform_inverse); } else { cairo_pattern_set_matrix (group_pattern, &group_matrix); } /* If we have a current path, we need to adjust it to compensate for * the device offset just removed. */ _cairo_path_fixed_transform (cr->path, &group_surface->device_transform_inverse); #endif done: cairo_surface_destroy (group_surface); return group_pattern; }
static void _copy_transformed_pattern (cairo_pattern_t *pattern, const cairo_pattern_t *original, const cairo_matrix_t *ctm_inverse) { _cairo_pattern_init_static_copy (pattern, original); /* apply device_transform first so that it is transformed by ctm_inverse */ if (original->type == CAIRO_PATTERN_TYPE_SURFACE) { cairo_surface_pattern_t *surface_pattern; cairo_surface_t *surface; surface_pattern = (cairo_surface_pattern_t *) original; surface = surface_pattern->surface; if (_cairo_surface_has_device_transform (surface)) _cairo_pattern_transform (pattern, &surface->device_transform); } if (! _cairo_matrix_is_identity (ctm_inverse)) _cairo_pattern_transform (pattern, ctm_inverse); }
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); }
static cairo_int_status_t composite_aligned_boxes (const cairo_spans_compositor_t *compositor, const cairo_composite_rectangles_t *extents, cairo_boxes_t *boxes) { cairo_surface_t *dst = extents->surface; cairo_operator_t op = extents->op; const cairo_pattern_t *source = &extents->source_pattern.base; cairo_int_status_t status; cairo_bool_t need_clip_mask = ! _clip_is_region (extents->clip); cairo_bool_t op_is_source; cairo_bool_t no_mask; cairo_bool_t inplace; TRACE ((stderr, "%s: need_clip_mask=%d, is-bounded=%d\n", __FUNCTION__, need_clip_mask, extents->is_bounded)); if (need_clip_mask && ! extents->is_bounded) { TRACE ((stderr, "%s: unsupported clip\n", __FUNCTION__)); return CAIRO_INT_STATUS_UNSUPPORTED; } no_mask = extents->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID && CAIRO_COLOR_IS_OPAQUE (&extents->mask_pattern.solid.color); op_is_source = op_reduces_to_source (extents, no_mask); inplace = ! need_clip_mask && op_is_source && no_mask; TRACE ((stderr, "%s: op-is-source=%d [op=%d], no-mask=%d, inplace=%d\n", __FUNCTION__, op_is_source, op, no_mask, inplace)); if (op == CAIRO_OPERATOR_SOURCE && (need_clip_mask || ! no_mask)) { /* SOURCE with a mask is actually a LERP in cairo semantics */ if ((compositor->flags & CAIRO_SPANS_COMPOSITOR_HAS_LERP) == 0) { TRACE ((stderr, "%s: unsupported lerp\n", __FUNCTION__)); return CAIRO_INT_STATUS_UNSUPPORTED; } } /* Are we just copying a recording surface? */ if (inplace && recording_pattern_contains_sample (&extents->source_pattern.base, &extents->source_sample_area)) { cairo_clip_t *recording_clip; const cairo_pattern_t *source = &extents->source_pattern.base; const cairo_matrix_t *m; cairo_matrix_t matrix; /* XXX could also do tiling repeat modes... */ /* first clear the area about to be overwritten */ if (! dst->is_clear) { status = compositor->fill_boxes (dst, CAIRO_OPERATOR_CLEAR, CAIRO_COLOR_TRANSPARENT, boxes); if (unlikely (status)) return status; dst->is_clear = TRUE; } m = &source->matrix; if (_cairo_surface_has_device_transform (dst)) { cairo_matrix_multiply (&matrix, &source->matrix, &dst->device_transform); m = &matrix; } recording_clip = _cairo_clip_from_boxes (boxes); status = _cairo_recording_surface_replay_with_clip (unwrap_source (source), m, dst, recording_clip); _cairo_clip_destroy (recording_clip); return status; } status = CAIRO_INT_STATUS_UNSUPPORTED; if (! need_clip_mask && no_mask && source->type == CAIRO_PATTERN_TYPE_SOLID) { const cairo_color_t *color; color = &((cairo_solid_pattern_t *) source)->color; if (op_is_source) op = CAIRO_OPERATOR_SOURCE; status = compositor->fill_boxes (dst, op, color, boxes); } else if (inplace && source->type == CAIRO_PATTERN_TYPE_SURFACE) { status = upload_boxes (compositor, extents, boxes); } if (status == CAIRO_INT_STATUS_UNSUPPORTED) { cairo_surface_t *src; cairo_surface_t *mask = NULL; int src_x, src_y; int mask_x = 0, mask_y = 0; /* All typical cases will have been resolved before now... */ if (need_clip_mask) { mask = get_clip_surface (compositor, dst, extents->clip, &extents->bounded); if (unlikely (mask->status)) return mask->status; mask_x = -extents->bounded.x; mask_y = -extents->bounded.y; } /* XXX but this is still ugly */ if (! no_mask) { src = compositor->pattern_to_surface (dst, &extents->mask_pattern.base, TRUE, &extents->bounded, &extents->mask_sample_area, &src_x, &src_y); if (unlikely (src->status)) { cairo_surface_destroy (mask); return src->status; } if (mask != NULL) { status = compositor->composite_boxes (mask, CAIRO_OPERATOR_IN, src, NULL, src_x, src_y, 0, 0, mask_x, mask_y, boxes, &extents->bounded); cairo_surface_destroy (src); } else { mask = src; mask_x = src_x; mask_y = src_y; } } src = compositor->pattern_to_surface (dst, source, FALSE, &extents->bounded, &extents->source_sample_area, &src_x, &src_y); if (likely (src->status == CAIRO_STATUS_SUCCESS)) { status = compositor->composite_boxes (dst, op, src, mask, src_x, src_y, mask_x, mask_y, 0, 0, boxes, &extents->bounded); cairo_surface_destroy (src); } else status = src->status; cairo_surface_destroy (mask); } if (status == CAIRO_INT_STATUS_SUCCESS && ! extents->is_bounded) status = fixup_unbounded_boxes (compositor, extents, boxes); return status; }