ddbb2c8f18575e8ca55f32846ea7264d92ea191b
[framework/graphics/cairo.git] / src / cairo-pattern-private.h
1 /* cairo - a vector graphics library with display and print output
2  *
3  * Copyright © 2005 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it either under the terms of the GNU Lesser General Public
7  * License version 2.1 as published by the Free Software Foundation
8  * (the "LGPL") or, at your option, under the terms of the Mozilla
9  * Public License Version 1.1 (the "MPL"). If you do not alter this
10  * notice, a recipient may use your version of this file under either
11  * the MPL or the LGPL.
12  *
13  * You should have received a copy of the LGPL along with this library
14  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
16  * You should have received a copy of the MPL along with this library
17  * in the file COPYING-MPL-1.1
18  *
19  * The contents of this file are subject to the Mozilla Public License
20  * Version 1.1 (the "License"); you may not use this file except in
21  * compliance with the License. You may obtain a copy of the License at
22  * http://www.mozilla.org/MPL/
23  *
24  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26  * the specific language governing rights and limitations.
27  *
28  * The Original Code is the cairo graphics library.
29  *
30  * The Initial Developer of the Original Code is Red Hat, Inc.
31  *
32  * Contributor(s):
33  *      Carl D. Worth <cworth@redhat.com>
34  */
35
36 #ifndef CAIRO_PATTERN_PRIVATE_H
37 #define CAIRO_PATTERN_PRIVATE_H
38
39 #include "cairo-error-private.h"
40 #include "cairo-types-private.h"
41 #include "cairo-list-private.h"
42 #include "cairo-surface-private.h"
43
44 #include <stdio.h> /* FILE* */
45
46 CAIRO_BEGIN_DECLS
47
48 typedef struct _cairo_pattern_observer cairo_pattern_observer_t;
49
50 enum {
51     CAIRO_PATTERN_NOTIFY_MATRIX = 0x1,
52     CAIRO_PATTERN_NOTIFY_FILTER = 0x2,
53     CAIRO_PATTERN_NOTIFY_EXTEND = 0x4,
54     CAIRO_PATTERN_NOTIFY_OPACITY = 0x9,
55 };
56
57 struct _cairo_pattern_observer {
58     void (*notify) (cairo_pattern_observer_t *,
59                     cairo_pattern_t *pattern,
60                     unsigned int flags);
61     cairo_list_t link;
62 };
63
64 struct _cairo_pattern {
65     cairo_reference_count_t     ref_count;
66     cairo_status_t              status;
67     cairo_user_data_array_t     user_data;
68     cairo_list_t                observers;
69
70     cairo_pattern_type_t        type;
71
72     cairo_filter_t              filter;
73     cairo_extend_t              extend;
74     cairo_bool_t                has_component_alpha;
75
76     cairo_matrix_t              matrix;
77     double                      opacity;
78 };
79
80 struct _cairo_solid_pattern {
81     cairo_pattern_t base;
82     cairo_color_t color;
83 };
84
85 typedef struct _cairo_surface_pattern {
86     cairo_pattern_t base;
87
88     cairo_surface_t *surface;
89 } cairo_surface_pattern_t;
90
91 typedef struct _cairo_gradient_stop {
92     double offset;
93     cairo_color_stop_t color;
94 } cairo_gradient_stop_t;
95
96 typedef struct _cairo_gradient_pattern {
97     cairo_pattern_t base;
98
99     unsigned int            n_stops;
100     unsigned int            stops_size;
101     cairo_gradient_stop_t  *stops;
102     cairo_gradient_stop_t   stops_embedded[2];
103 } cairo_gradient_pattern_t;
104
105 typedef struct _cairo_linear_pattern {
106     cairo_gradient_pattern_t base;
107
108     cairo_point_double_t pd1;
109     cairo_point_double_t pd2;
110 } cairo_linear_pattern_t;
111
112 typedef struct _cairo_radial_pattern {
113     cairo_gradient_pattern_t base;
114
115     cairo_circle_double_t cd1;
116     cairo_circle_double_t cd2;
117 } cairo_radial_pattern_t;
118
119 typedef union {
120     cairo_gradient_pattern_t base;
121
122     cairo_linear_pattern_t linear;
123     cairo_radial_pattern_t radial;
124 } cairo_gradient_pattern_union_t;
125
126 /*
127  * A mesh patch is a tensor-product patch (bicubic Bezier surface
128  * patch). It has 16 control points. Each set of 4 points along the
129  * sides of the 4x4 grid of control points is a Bezier curve that
130  * defines one side of the patch. A color is assigned to each
131  * corner. The inner 4 points provide additional control over the
132  * shape and the color mapping.
133  *
134  * Cairo uses the same convention as the PDF Reference for numbering
135  * the points and side of the patch.
136  *
137  *
138  *                      Side 1
139  *
140  *          p[0][3] p[1][3] p[2][3] p[3][3]
141  * Side 0   p[0][2] p[1][2] p[2][2] p[3][2]  Side 2
142  *          p[0][1] p[1][1] p[2][1] p[3][1]
143  *          p[0][0] p[1][0] p[2][0] p[3][0]
144  *
145  *                      Side 3
146  *
147  *
148  *   Point            Color
149  *  -------------------------
150  *  points[0][0]    colors[0]
151  *  points[0][3]    colors[1]
152  *  points[3][3]    colors[2]
153  *  points[3][0]    colors[3]
154  */
155
156 typedef struct _cairo_mesh_patch {
157     cairo_point_double_t points[4][4];
158     cairo_color_t colors[4];
159 } cairo_mesh_patch_t;
160
161 typedef struct _cairo_mesh_pattern {
162     cairo_pattern_t base;
163
164     cairo_array_t patches;
165     cairo_mesh_patch_t *current_patch;
166     int current_side;
167     cairo_bool_t has_control_point[4];
168     cairo_bool_t has_color[4];
169 } cairo_mesh_pattern_t;
170
171 typedef struct _cairo_raster_source_pattern {
172     cairo_pattern_t base;
173
174     cairo_content_t content;
175     cairo_rectangle_int_t extents;
176
177     cairo_raster_source_acquire_func_t acquire;
178     cairo_raster_source_release_func_t release;
179     cairo_raster_source_snapshot_func_t snapshot;
180     cairo_raster_source_copy_func_t copy;
181     cairo_raster_source_finish_func_t finish;
182
183     /* an explicit pre-allocated member in preference to the general user-data */
184     void *user_data;
185 } cairo_raster_source_pattern_t;
186
187 typedef union {
188     cairo_pattern_t                 base;
189
190     cairo_solid_pattern_t           solid;
191     cairo_surface_pattern_t         surface;
192     cairo_gradient_pattern_union_t  gradient;
193     cairo_mesh_pattern_t            mesh;
194     cairo_raster_source_pattern_t   raster_source;
195 } cairo_pattern_union_t;
196
197 /* cairo-pattern.c */
198
199 cairo_private cairo_pattern_t *
200 _cairo_pattern_create_in_error (cairo_status_t status);
201
202 cairo_private cairo_status_t
203 _cairo_pattern_create_copy (cairo_pattern_t       **pattern,
204                             const cairo_pattern_t  *other);
205
206 cairo_private void
207 _cairo_pattern_init (cairo_pattern_t *pattern,
208                      cairo_pattern_type_t type);
209
210 cairo_private cairo_status_t
211 _cairo_pattern_init_copy (cairo_pattern_t       *pattern,
212                           const cairo_pattern_t *other);
213
214 cairo_private void
215 _cairo_pattern_init_static_copy (cairo_pattern_t        *pattern,
216                                  const cairo_pattern_t *other);
217
218 cairo_private cairo_status_t
219 _cairo_pattern_init_snapshot (cairo_pattern_t       *pattern,
220                               const cairo_pattern_t *other);
221
222 cairo_private void
223 _cairo_pattern_init_solid (cairo_solid_pattern_t        *pattern,
224                            const cairo_color_t          *color);
225
226 cairo_private void
227 _cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern,
228                                  cairo_surface_t *surface);
229
230 cairo_private void
231 _cairo_pattern_fini (cairo_pattern_t *pattern);
232
233 cairo_private void
234 _cairo_pattern_fini_snapshot (cairo_pattern_t *pattern);
235
236 cairo_private cairo_pattern_t *
237 _cairo_pattern_create_solid (const cairo_color_t        *color);
238
239 cairo_private void
240 _cairo_pattern_transform (cairo_pattern_t      *pattern,
241                           const cairo_matrix_t *ctm_inverse);
242
243 cairo_private cairo_bool_t
244 _cairo_pattern_is_opaque_solid (const cairo_pattern_t *pattern);
245
246 cairo_private cairo_bool_t
247 _cairo_pattern_is_opaque (const cairo_pattern_t *pattern,
248                           const cairo_rectangle_int_t *extents);
249
250 cairo_private cairo_bool_t
251 _cairo_pattern_is_clear (const cairo_pattern_t *pattern);
252
253 cairo_private cairo_bool_t
254 _cairo_gradient_pattern_is_solid (const cairo_gradient_pattern_t *gradient,
255                                   const cairo_rectangle_int_t *extents,
256                                   cairo_color_t *color);
257
258 cairo_private void
259 _cairo_gradient_pattern_fit_to_range (const cairo_gradient_pattern_t *gradient,
260                                       double                          max_value,
261                                       cairo_matrix_t                 *out_matrix,
262                                       cairo_circle_double_t           out_circle[2]);
263
264 cairo_private cairo_bool_t
265 _cairo_radial_pattern_focus_is_inside (const cairo_radial_pattern_t *radial);
266
267 cairo_private void
268 _cairo_gradient_pattern_box_to_parameter (const cairo_gradient_pattern_t *gradient,
269                                           double x0, double y0,
270                                           double x1, double y1,
271                                           double tolerance,
272                                           double out_range[2]);
273
274 cairo_private void
275 _cairo_gradient_pattern_interpolate (const cairo_gradient_pattern_t *gradient,
276                                      double                          t,
277                                      cairo_circle_double_t          *out_circle);
278
279 cairo_private void
280 _cairo_pattern_alpha_range (const cairo_pattern_t *pattern,
281                             double                *out_min,
282                             double                *out_max);
283
284 cairo_private cairo_bool_t
285 _cairo_mesh_pattern_coord_box (const cairo_mesh_pattern_t *mesh,
286                                double                     *out_xmin,
287                                double                     *out_ymin,
288                                double                     *out_xmax,
289                                double                     *out_ymax);
290
291 cairo_private_no_warn cairo_filter_t
292 _cairo_pattern_sampled_area (const cairo_pattern_t *pattern,
293                              const cairo_rectangle_int_t *extents,
294                              cairo_rectangle_int_t *sample);
295
296 cairo_private void
297 _cairo_pattern_get_extents (const cairo_pattern_t           *pattern,
298                             cairo_rectangle_int_t           *extents);
299
300 cairo_private cairo_int_status_t
301 _cairo_pattern_get_ink_extents (const cairo_pattern_t       *pattern,
302                                 cairo_rectangle_int_t       *extents);
303
304 cairo_private unsigned long
305 _cairo_pattern_hash (const cairo_pattern_t *pattern);
306
307 cairo_private unsigned long
308 _cairo_linear_pattern_hash (unsigned long hash,
309                             const cairo_linear_pattern_t *linear);
310
311 cairo_private unsigned long
312 _cairo_radial_pattern_hash (unsigned long hash,
313                             const cairo_radial_pattern_t *radial);
314
315 cairo_private cairo_bool_t
316 _cairo_linear_pattern_equal (const cairo_linear_pattern_t *a,
317                              const cairo_linear_pattern_t *b);
318
319 cairo_private unsigned long
320 _cairo_pattern_size (const cairo_pattern_t *pattern);
321
322 cairo_private cairo_bool_t
323 _cairo_radial_pattern_equal (const cairo_radial_pattern_t *a,
324                              const cairo_radial_pattern_t *b);
325
326 cairo_private cairo_bool_t
327 _cairo_pattern_equal (const cairo_pattern_t *a,
328                       const cairo_pattern_t *b);
329
330 /* cairo-mesh-pattern-rasterizer.c */
331
332 cairo_private void
333 _cairo_mesh_pattern_rasterize (const cairo_mesh_pattern_t *mesh,
334                                void                       *data,
335                                int                         width,
336                                int                         height,
337                                int                         stride,
338                                double                      x_offset,
339                                double                      y_offset);
340
341 cairo_private cairo_surface_t *
342 _cairo_raster_source_pattern_acquire (const cairo_pattern_t *abstract_pattern,
343                                       cairo_surface_t *target,
344                                       const cairo_rectangle_int_t *extents);
345
346 cairo_private void
347 _cairo_raster_source_pattern_release (const cairo_pattern_t *abstract_pattern,
348                                       cairo_surface_t *surface);
349
350 cairo_private cairo_status_t
351 _cairo_raster_source_pattern_snapshot (cairo_pattern_t *abstract_pattern);
352
353 cairo_private cairo_status_t
354 _cairo_raster_source_pattern_init_copy (cairo_pattern_t *pattern,
355                                         const cairo_pattern_t *other);
356
357 cairo_private void
358 _cairo_raster_source_pattern_finish (cairo_pattern_t *abstract_pattern);
359
360 cairo_private void
361 _cairo_debug_print_pattern (FILE *file, const cairo_pattern_t *pattern);
362
363 CAIRO_END_DECLS
364
365 #endif /* CAIRO_PATTERN_PRIVATE */