1 /* cairo - a vector graphics library with display and print output
2  *
3  * Copyright © 2002 University of Southern California
4  * Copyright © 2005 Red Hat, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it either under the terms of the GNU Lesser General Public
8  * License version 2.1 as published by the Free Software Foundation
9  * (the "LGPL") or, at your option, under the terms of the Mozilla
10  * Public License Version 1.1 (the "MPL"). If you do not alter this
11  * notice, a recipient may use your version of this file under either
12  * the MPL or the LGPL.
13  *
14  * You should have received a copy of the LGPL along with this library
15  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  * You should have received a copy of the MPL along with this library
18  * in the file COPYING-MPL-1.1
19  *
20  * The contents of this file are subject to the Mozilla Public License
21  * Version 1.1 (the "License"); you may not use this file except in
22  * compliance with the License. You may obtain a copy of the License at
23  * http://www.mozilla.org/MPL/
24  *
25  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27  * the specific language governing rights and limitations.
28  *
29  * The Original Code is the cairo graphics library.
30  *
31  * The Initial Developer of the Original Code is University of Southern
32  * California.
33  *
34  * Contributor(s):
35  *	Carl D. Worth <cworth@cworth.org>
36  */
37 
38 #ifndef CAIRO_IMAGE_SURFACE_PRIVATE_H
39 #define CAIRO_IMAGE_SURFACE_PRIVATE_H
40 
41 #include "cairo-surface-private.h"
42 
43 #include <stddef.h>
44 #include <pixman.h>
45 
46 CAIRO_BEGIN_DECLS
47 
48 /* The canonical image backend */
49 struct _cairo_image_surface {
50     cairo_surface_t base;
51 
52     pixman_image_t *pixman_image;
53     const cairo_compositor_t *compositor;
54 
55     /* Parenting is tricky wrt lifetime tracking...
56      *
57      * One use for tracking the parent of an image surface is for
58      * create_similar_image() where we wish to create a device specific
59      * surface but return an image surface to the user. In such a case,
60      * the image may be owned by the device specific surface, its parent,
61      * but the user lifetime tracking is then performed on the image. So
62      * when the image is then finalized we call cairo_surface_destroy()
63      * on the parent. However, for normal usage where the lifetime tracking
64      * is done on the parent surface, we need to be careful to unhook
65      * the image->parent pointer before finalizing the image.
66      */
67     cairo_surface_t *parent;
68 
69     pixman_format_code_t pixman_format;
70     cairo_format_t format;
71     unsigned char *data;
72 
73     int width;
74     int height;
75     ptrdiff_t stride;
76     int depth;
77 
78     unsigned owns_data : 1;
79     unsigned transparency : 2;
80     unsigned color : 2;
81 };
82 #define to_image_surface(S) ((cairo_image_surface_t *)(S))
83 
84 /* A wrapper for holding pixman images returned by create_for_pattern */
85 typedef struct _cairo_image_source {
86     cairo_surface_t base;
87 
88     pixman_image_t *pixman_image;
89     unsigned is_opaque_solid : 1;
90 } cairo_image_source_t;
91 
92 cairo_private extern const cairo_surface_backend_t _cairo_image_surface_backend;
93 cairo_private extern const cairo_surface_backend_t _cairo_image_source_backend;
94 
95 cairo_private const cairo_compositor_t *
96 _cairo_image_mask_compositor_get (void);
97 
98 cairo_private const cairo_compositor_t *
99 _cairo_image_traps_compositor_get (void);
100 
101 cairo_private const cairo_compositor_t *
102 _cairo_image_spans_compositor_get (void);
103 
104 #define _cairo_image_default_compositor_get _cairo_image_spans_compositor_get
105 
106 cairo_private cairo_int_status_t
107 _cairo_image_surface_paint (void			*abstract_surface,
108 			    cairo_operator_t		 op,
109 			    const cairo_pattern_t	*source,
110 			    const cairo_clip_t		*clip);
111 
112 cairo_private cairo_int_status_t
113 _cairo_image_surface_mask (void				*abstract_surface,
114 			   cairo_operator_t		 op,
115 			   const cairo_pattern_t	*source,
116 			   const cairo_pattern_t	*mask,
117 			   const cairo_clip_t		*clip);
118 
119 cairo_private cairo_int_status_t
120 _cairo_image_surface_stroke (void			*abstract_surface,
121 			     cairo_operator_t		 op,
122 			     const cairo_pattern_t	*source,
123 			     const cairo_path_fixed_t	*path,
124 			     const cairo_stroke_style_t	*style,
125 			     const cairo_matrix_t	*ctm,
126 			     const cairo_matrix_t	*ctm_inverse,
127 			     double			 tolerance,
128 			     cairo_antialias_t		 antialias,
129 			     const cairo_clip_t		*clip);
130 
131 cairo_private cairo_int_status_t
132 _cairo_image_surface_fill (void				*abstract_surface,
133 			   cairo_operator_t		 op,
134 			   const cairo_pattern_t	*source,
135 			   const cairo_path_fixed_t	*path,
136 			   cairo_fill_rule_t		 fill_rule,
137 			   double			 tolerance,
138 			   cairo_antialias_t		 antialias,
139 			   const cairo_clip_t		*clip);
140 
141 cairo_private cairo_int_status_t
142 _cairo_image_surface_glyphs (void			*abstract_surface,
143 			     cairo_operator_t		 op,
144 			     const cairo_pattern_t	*source,
145 			     cairo_glyph_t		*glyphs,
146 			     int			 num_glyphs,
147 			     cairo_scaled_font_t	*scaled_font,
148 			     const cairo_clip_t		*clip);
149 
150 cairo_private void
151 _cairo_image_surface_init (cairo_image_surface_t *surface,
152 			   pixman_image_t	*pixman_image,
153 			   pixman_format_code_t	 pixman_format);
154 
155 cairo_private cairo_surface_t *
156 _cairo_image_surface_create_similar (void	       *abstract_other,
157 				     cairo_content_t	content,
158 				     int		width,
159 				     int		height);
160 
161 cairo_private cairo_image_surface_t *
162 _cairo_image_surface_map_to_image (void *abstract_other,
163 				   const cairo_rectangle_int_t *extents);
164 
165 cairo_private cairo_int_status_t
166 _cairo_image_surface_unmap_image (void *abstract_surface,
167 				  cairo_image_surface_t *image);
168 
169 cairo_private cairo_surface_t *
170 _cairo_image_surface_source (void			*abstract_surface,
171 			     cairo_rectangle_int_t	*extents);
172 
173 cairo_private cairo_status_t
174 _cairo_image_surface_acquire_source_image (void                    *abstract_surface,
175 					   cairo_image_surface_t  **image_out,
176 					   void                   **image_extra);
177 
178 cairo_private void
179 _cairo_image_surface_release_source_image (void                   *abstract_surface,
180 					   cairo_image_surface_t  *image,
181 					   void                   *image_extra);
182 
183 cairo_private cairo_surface_t *
184 _cairo_image_surface_snapshot (void *abstract_surface);
185 
186 cairo_private_no_warn cairo_bool_t
187 _cairo_image_surface_get_extents (void			  *abstract_surface,
188 				  cairo_rectangle_int_t   *rectangle);
189 
190 cairo_private void
191 _cairo_image_surface_get_font_options (void                  *abstract_surface,
192 				       cairo_font_options_t  *options);
193 
194 cairo_private cairo_surface_t *
195 _cairo_image_source_create_for_pattern (cairo_surface_t *dst,
196 					const cairo_pattern_t *pattern,
197 					cairo_bool_t is_mask,
198 					const cairo_rectangle_int_t *extents,
199 					const cairo_rectangle_int_t *sample,
200 					int *src_x, int *src_y);
201 
202 cairo_private cairo_status_t
203 _cairo_image_surface_finish (void *abstract_surface);
204 
205 cairo_private pixman_image_t *
206 _pixman_image_for_color (const cairo_color_t *cairo_color);
207 
208 cairo_private pixman_image_t *
209 _pixman_image_for_pattern (cairo_image_surface_t *dst,
210 			   const cairo_pattern_t *pattern,
211 			   cairo_bool_t is_mask,
212 			   const cairo_rectangle_int_t *extents,
213 			   const cairo_rectangle_int_t *sample,
214 			   int *tx, int *ty);
215 
216 cairo_private void
217 _pixman_image_add_traps (pixman_image_t *image,
218 			 int dst_x, int dst_y,
219 			 cairo_traps_t *traps);
220 
221 cairo_private void
222 _pixman_image_add_tristrip (pixman_image_t *image,
223 			    int dst_x, int dst_y,
224 			    cairo_tristrip_t *strip);
225 
226 cairo_private cairo_image_surface_t *
227 _cairo_image_surface_clone_subimage (cairo_surface_t             *surface,
228 				     const cairo_rectangle_int_t *extents);
229 
230 /* Similar to clone; but allow format conversion */
231 cairo_private cairo_image_surface_t *
232 _cairo_image_surface_create_from_image (cairo_image_surface_t *other,
233 					pixman_format_code_t format,
234 					int x, int y, int width, int height,
235 					int stride);
236 
237 CAIRO_END_DECLS
238 
239 #endif /* CAIRO_IMAGE_SURFACE_PRIVATE_H */
240