static cairo_status_t _cairo_default_context_paint_with_alpha (void *abstract_cr, double alpha) { cairo_default_context_t *cr = abstract_cr; cairo_solid_pattern_t pattern; cairo_status_t status; cairo_color_t color; if (CAIRO_ALPHA_IS_OPAQUE (alpha)) return _cairo_gstate_paint (cr->gstate); if (CAIRO_ALPHA_IS_ZERO (alpha) && _cairo_operator_bounded_by_mask (cr->gstate->op)) { return CAIRO_STATUS_SUCCESS; } _cairo_color_init_rgba (&color, 0., 0., 0., alpha); _cairo_pattern_init_solid (&pattern, &color); status = _cairo_gstate_mask (cr->gstate, &pattern.base); _cairo_pattern_fini (&pattern.base); return status; }
static cairo_status_t _cairo_skia_context_paint_with_alpha (void *abstract_cr, double alpha) { cairo_skia_context_t *cr = (cairo_skia_context_t *) abstract_cr; cairo_status_t status; if (CAIRO_ALPHA_IS_OPAQUE (alpha)) return _cairo_skia_context_paint (cr); cr->paint->setAlpha(SkScalarRound(255*alpha)); status = _cairo_skia_context_paint (cr); cr->paint->setAlpha(255); return 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 = extents->clip->path != NULL; cairo_bool_t op_is_source; cairo_bool_t no_mask; cairo_bool_t inplace; if (need_clip_mask && ! extents->is_bounded) return CAIRO_INT_STATUS_UNSUPPORTED; op_is_source = op_reduces_to_source (extents); no_mask = extents->mask_pattern.base.type == CAIRO_PATTERN_TYPE_SOLID && CAIRO_ALPHA_IS_OPAQUE (extents->mask_pattern.solid.color.alpha); inplace = ! need_clip_mask && op_is_source && no_mask; 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) 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; /* 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); recording_clip = _cairo_clip_from_boxes (boxes); status = _cairo_recording_surface_replay_with_clip (unwrap_surface (source), &source->matrix, dst, recording_clip); _cairo_clip_destroy (recording_clip); return status; } 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); #if 0 } else if (inplace && source->type == CAIRO_PATTERN_TYPE_SURFACE) { status = upload_inplace (compositor, extents, boxes); #endif } else { 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; }