efc8a79adc4d77f465aec9bee864ab97d4037a7e
[framework/graphics/cairo.git] / src / cairo-fallback-compositor.c
1 /* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
2 /* cairo - a vector graphics library with display and print output
3  *
4  * Copyright © 2002 University of Southern California
5  * Copyright © 2005 Red Hat, Inc.
6  * Copyright © 2011 Intel Corporation
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it either under the terms of the GNU Lesser General Public
10  * License version 2.1 as published by the Free Software Foundation
11  * (the "LGPL") or, at your option, under the terms of the Mozilla
12  * Public License Version 1.1 (the "MPL"). If you do not alter this
13  * notice, a recipient may use your version of this file under either
14  * the MPL or the LGPL.
15  *
16  * You should have received a copy of the LGPL along with this library
17  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
19  * You should have received a copy of the MPL along with this library
20  * in the file COPYING-MPL-1.1
21  *
22  * The contents of this file are subject to the Mozilla Public License
23  * Version 1.1 (the "License"); you may not use this file except in
24  * compliance with the License. You may obtain a copy of the License at
25  * http://www.mozilla.org/MPL/
26  *
27  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
28  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
29  * the specific language governing rights and limitations.
30  *
31  * The Original Code is the cairo graphics library.
32  *
33  * The Initial Developer of the Original Code is University of Southern
34  * California.
35  *
36  * Contributor(s):
37  *      Carl D. Worth <cworth@cworth.org>
38  *      Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
39  *      Chris Wilson <chris@chris-wilson.co.uk>
40  */
41
42 #include "cairoint.h"
43
44 #include "cairo-compositor-private.h"
45 #include "cairo-surface-offset-private.h"
46
47 /* high-level compositor interface */
48
49 static cairo_int_status_t
50 _cairo_fallback_compositor_paint (const cairo_compositor_t      *_compositor,
51                                   cairo_composite_rectangles_t  *extents)
52 {
53     cairo_surface_t *image;
54     cairo_int_status_t status;
55
56     TRACE ((stderr, "%s\n", __FUNCTION__));
57     image = cairo_surface_map_to_image (extents->surface, &extents->unbounded);
58     status = _cairo_surface_offset_paint (image,
59                                           extents->unbounded.x,
60                                           extents->unbounded.y,
61                                           extents->op,
62                                           &extents->source_pattern.base,
63                                           extents->clip);
64     cairo_surface_unmap_image (extents->surface, image);
65
66     return status;
67 }
68
69 static cairo_int_status_t
70 _cairo_fallback_compositor_mask (const cairo_compositor_t       *_compositor,
71                                  cairo_composite_rectangles_t   *extents)
72 {
73     cairo_surface_t *image;
74     cairo_int_status_t status;
75
76     TRACE ((stderr, "%s\n", __FUNCTION__));
77     image = cairo_surface_map_to_image (extents->surface, &extents->unbounded);
78     status = _cairo_surface_offset_mask (image,
79                                          extents->unbounded.x,
80                                          extents->unbounded.y,
81                                          extents->op,
82                                          &extents->source_pattern.base,
83                                          &extents->mask_pattern.base,
84                                          extents->clip);
85     cairo_surface_unmap_image (extents->surface, image);
86
87     return status;
88 }
89
90 static cairo_int_status_t
91 _cairo_fallback_compositor_stroke (const cairo_compositor_t     *_compositor,
92                                    cairo_composite_rectangles_t *extents,
93                                    const cairo_path_fixed_t     *path,
94                                    const cairo_stroke_style_t   *style,
95                                    const cairo_matrix_t         *ctm,
96                                    const cairo_matrix_t         *ctm_inverse,
97                                    double                        tolerance,
98                                    cairo_antialias_t             antialias)
99 {
100     cairo_surface_t *image;
101     cairo_int_status_t status;
102
103     TRACE ((stderr, "%s\n", __FUNCTION__));
104     image = cairo_surface_map_to_image (extents->surface, &extents->unbounded);
105     status = _cairo_surface_offset_stroke (image,
106                                            extents->unbounded.x,
107                                            extents->unbounded.y,
108                                            extents->op,
109                                            &extents->source_pattern.base,
110                                            path, style,
111                                            ctm, ctm_inverse,
112                                            tolerance,
113                                            antialias,
114                                            extents->clip);
115     cairo_surface_unmap_image (extents->surface, image);
116
117     return status;
118 }
119
120 static cairo_int_status_t
121 _cairo_fallback_compositor_fill (const cairo_compositor_t       *_compositor,
122                                  cairo_composite_rectangles_t *extents,
123                                  const cairo_path_fixed_t       *path,
124                                  cairo_fill_rule_t               fill_rule,
125                                  double                          tolerance,
126                                  cairo_antialias_t               antialias)
127 {
128     cairo_surface_t *image;
129     cairo_int_status_t status;
130
131     TRACE ((stderr, "%s\n", __FUNCTION__));
132     image = cairo_surface_map_to_image (extents->surface, &extents->unbounded);
133     status = _cairo_surface_offset_fill (image,
134                                          extents->unbounded.x,
135                                          extents->unbounded.y,
136                                          extents->op,
137                                          &extents->source_pattern.base,
138                                          path,
139                                          fill_rule, tolerance, antialias,
140                                          extents->clip);
141     cairo_surface_unmap_image (extents->surface, image);
142
143     return status;
144 }
145
146 static cairo_int_status_t
147 _cairo_fallback_compositor_glyphs (const cairo_compositor_t     *_compositor,
148                                    cairo_composite_rectangles_t *extents,
149                                    cairo_scaled_font_t          *scaled_font,
150                                    cairo_glyph_t                *glyphs,
151                                    int                           num_glyphs,
152                                    cairo_bool_t                  overlap)
153 {
154     cairo_surface_t *image;
155     cairo_int_status_t status;
156
157     TRACE ((stderr, "%s\n", __FUNCTION__));
158     image = cairo_surface_map_to_image (extents->surface, &extents->unbounded);
159     status = _cairo_surface_offset_glyphs (image,
160                                            extents->unbounded.x,
161                                            extents->unbounded.y,
162                                            extents->op,
163                                            &extents->source_pattern.base,
164                                            scaled_font, glyphs, num_glyphs,
165                                            extents->clip);
166     cairo_surface_unmap_image (extents->surface, image);
167
168     return status;
169 }
170
171 const cairo_compositor_t _cairo_fallback_compositor = {
172      &__cairo_no_compositor,
173
174      _cairo_fallback_compositor_paint,
175      _cairo_fallback_compositor_mask,
176      _cairo_fallback_compositor_stroke,
177      _cairo_fallback_compositor_fill,
178      _cairo_fallback_compositor_glyphs,
179 };