1 /* Cairo - a vector graphics library with display and print output
3 * Copyright © 2005 Red Hat, Inc.
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.
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
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/
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.
28 * The Original Code is the cairo graphics library.
30 * The Initial Developer of the Original Code is Red Hat, Inc.
33 * Chris Wilson <chris@chris-wilson.co.uk>
34 * Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
37 #ifndef CAIRO_XLIB_PRIVATE_H
38 #define CAIRO_XLIB_PRIVATE_H
40 #include "cairo-xlib.h"
41 #include "cairo-xlib-xrender-private.h"
43 #include "cairo-compiler-private.h"
44 #include "cairo-device-private.h"
45 #include "cairo-freelist-type-private.h"
46 #include "cairo-list-private.h"
47 #include "cairo-reference-count-private.h"
48 #include "cairo-types-private.h"
49 #include "cairo-scaled-font-private.h"
50 #include "cairo-surface-private.h"
54 typedef struct _cairo_xlib_display cairo_xlib_display_t;
55 typedef struct _cairo_xlib_screen cairo_xlib_screen_t;
56 typedef struct _cairo_xlib_source cairo_xlib_source_t;
57 typedef struct _cairo_xlib_surface cairo_xlib_surface_t;
59 /* size of color cube */
61 /* size of gray ramp */
63 /* maximum number of cached GC's */
64 #define GC_CACHE_SIZE 4
66 struct _cairo_xlib_display {
69 cairo_xlib_display_t *next;
75 const cairo_compositor_t *compositor;
79 XRenderPictFormat *cached_xrender_formats[CAIRO_FORMAT_RGB16_565 + 1];
83 cairo_surface_t *white;
84 cairo_surface_t *alpha[256];
85 cairo_surface_t *solid[32];
86 uint32_t solid_cache[32]; /* low 16 are opaque, high 16 transparent */
90 } last_solid_cache[2];
92 /* TRUE if the server has a bug with repeating pictures
94 * https://bugs.freedesktop.org/show_bug.cgi?id=3566
96 * We can't test for this because it depends on whether the
97 * picture is in video memory or not.
99 * We also use this variable as a guard against a second
100 * independent bug with transformed repeating pictures:
102 * http://lists.freedesktop.org/archives/cairo/2004-September/001839.html
104 * Both are fixed in xorg >= 6.9 and hopefully in > 6.8.2, so
105 * we can reuse the test for now.
107 unsigned int buggy_gradients : 1;
108 unsigned int buggy_pad_reflect : 1;
109 unsigned int buggy_repeat : 1;
110 unsigned int closed :1;
113 typedef struct _cairo_xlib_visual_info {
116 struct { uint8_t a, r, g, b; } colors[256];
117 uint8_t cube_to_pseudocolor[CUBE_SIZE][CUBE_SIZE][CUBE_SIZE];
118 uint8_t field8_to_cube[256];
119 int8_t dither8_to_cube[256];
120 uint8_t gray8_to_pseudocolor[256];
121 } cairo_xlib_visual_info_t;
123 struct _cairo_xlib_screen {
126 cairo_device_t *device;
129 cairo_list_t surfaces;
131 cairo_bool_t has_font_options;
132 cairo_font_options_t font_options;
134 GC gc[GC_CACHE_SIZE];
135 uint8_t gc_depths[GC_CACHE_SIZE];
137 cairo_list_t visuals;
141 GLYPHSET_INDEX_ARGB32,
147 typedef struct _cairo_xlib_font_glyphset {
149 cairo_format_t format;
150 XRenderPictFormat *xrender_format;
151 struct _cairo_xlib_font_glyphset_free_glyphs {
153 unsigned long indices[128];
155 } cairo_xlib_font_glyphset_t;
157 typedef struct _cairo_xlib_font {
158 cairo_scaled_font_private_t base;
159 cairo_scaled_font_t *font;
160 cairo_device_t *device;
162 cairo_xlib_font_glyphset_t glyphset[NUM_GLYPHSETS];
165 struct _cairo_xlib_surface {
166 cairo_surface_t base;
170 const cairo_compositor_t *compositor;
172 cairo_xlib_display_t *display;
173 cairo_xlib_screen_t *screen;
176 Display *dpy; /* only valid between acquire/release */
178 cairo_bool_t owns_pixmap;
188 XRenderPictFormat *xrender_format;
189 /* XXX pixman_format instead of masks? */
195 struct _cairo_xlib_source {
196 cairo_surface_t base;
201 unsigned int filter:3;
202 unsigned int extend:3;
203 unsigned int has_matrix:1;
204 unsigned int has_component_alpha:1;
208 cairo_private cairo_status_t
209 _cairo_xlib_surface_get_gc (cairo_xlib_display_t *display,
210 cairo_xlib_surface_t *surface,
213 cairo_private cairo_device_t *
214 _cairo_xlib_device_create (Display *display);
216 cairo_private cairo_xlib_screen_t *
217 _cairo_xlib_display_get_screen (cairo_xlib_display_t *display,
220 cairo_private cairo_status_t
221 _cairo_xlib_display_acquire (cairo_device_t *device,
222 cairo_xlib_display_t **display);
224 cairo_private cairo_bool_t
225 _cairo_xlib_display_has_repeat (cairo_device_t *device);
227 cairo_private cairo_bool_t
228 _cairo_xlib_display_has_reflect (cairo_device_t *device);
230 cairo_private cairo_bool_t
231 _cairo_xlib_display_has_gradients (cairo_device_t *device);
234 _cairo_xlib_display_set_precision(cairo_device_t *device,
237 cairo_private XRenderPictFormat *
238 _cairo_xlib_display_get_xrender_format (cairo_xlib_display_t *display,
239 cairo_format_t format);
241 cairo_private XRenderPictFormat *
242 _cairo_xlib_display_get_xrender_format_for_pixman (cairo_xlib_display_t *display,
243 pixman_format_code_t format);
245 cairo_private cairo_status_t
246 _cairo_xlib_screen_get (Display *dpy,
248 cairo_xlib_screen_t **out);
251 _cairo_xlib_screen_destroy (cairo_xlib_display_t *display,
252 cairo_xlib_screen_t *info);
255 _cairo_xlib_screen_get_gc (cairo_xlib_display_t *display,
256 cairo_xlib_screen_t *info,
260 _cairo_xlib_screen_put_gc (cairo_xlib_display_t *display,
261 cairo_xlib_screen_t *info,
265 cairo_private cairo_font_options_t *
266 _cairo_xlib_screen_get_font_options (cairo_xlib_screen_t *info);
268 cairo_private cairo_status_t
269 _cairo_xlib_screen_get_visual_info (cairo_xlib_display_t *display,
270 cairo_xlib_screen_t *info,
272 cairo_xlib_visual_info_t **out);
274 cairo_private cairo_status_t
275 _cairo_xlib_visual_info_create (Display *dpy,
278 cairo_xlib_visual_info_t **out);
281 _cairo_xlib_visual_info_destroy (cairo_xlib_visual_info_t *info);
283 cairo_private const cairo_compositor_t *
284 _cairo_xlib_core_compositor_get (void);
286 cairo_private const cairo_compositor_t *
287 _cairo_xlib_fallback_compositor_get (void);
289 cairo_private const cairo_compositor_t *
290 _cairo_xlib_mask_compositor_get (void);
292 cairo_private const cairo_compositor_t *
293 _cairo_xlib_traps_compositor_get (void);
296 _cairo_xlib_surface_ensure_picture (cairo_xlib_surface_t *surface);
299 _cairo_xlib_surface_set_precision (cairo_xlib_surface_t *surface,
300 cairo_antialias_t antialias);
302 cairo_private cairo_int_status_t
303 _cairo_xlib_surface_set_attributes (cairo_xlib_display_t *display,
304 cairo_xlib_surface_t *surface,
305 cairo_surface_attributes_t *attributes,
309 cairo_private cairo_status_t
310 _cairo_xlib_surface_draw_image (cairo_xlib_surface_t *surface,
311 cairo_image_surface_t *image,
319 cairo_private cairo_surface_t *
320 _cairo_xlib_source_create_for_pattern (cairo_surface_t *dst,
321 const cairo_pattern_t *pattern,
322 cairo_bool_t is_mask,
323 const cairo_rectangle_int_t *extents,
324 const cairo_rectangle_int_t *sample,
325 int *src_x, int *src_y);
328 _cairo_xlib_font_close (cairo_xlib_font_t *font);
330 #define CAIRO_RENDER_AT_LEAST(surface, major, minor) \
331 (((surface)->render_major > major) || \
332 (((surface)->render_major == major) && ((surface)->render_minor >= minor)))
334 #define CAIRO_RENDER_HAS_CREATE_PICTURE(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0)
335 #define CAIRO_RENDER_HAS_COMPOSITE(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0)
336 #define CAIRO_RENDER_HAS_COMPOSITE_TEXT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0)
338 #define CAIRO_RENDER_HAS_FILL_RECTANGLES(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 1)
340 #define CAIRO_RENDER_HAS_DISJOINT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 2)
341 #define CAIRO_RENDER_HAS_CONJOINT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 2)
343 #define CAIRO_RENDER_HAS_TRAPEZOIDS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4)
344 #define CAIRO_RENDER_HAS_TRIANGLES(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4)
345 #define CAIRO_RENDER_HAS_TRISTRIP(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4)
346 #define CAIRO_RENDER_HAS_TRIFAN(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4)
348 #define CAIRO_RENDER_HAS_PICTURE_TRANSFORM(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 6)
349 #define CAIRO_RENDER_HAS_FILTERS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 6)
351 #define CAIRO_RENDER_HAS_EXTENDED_REPEAT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 10)
352 #define CAIRO_RENDER_HAS_GRADIENTS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 10)
354 #define CAIRO_RENDER_HAS_PDF_OPERATORS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 11)
356 #define CAIRO_RENDER_SUPPORTS_OPERATOR(surface, op) \
357 ((op) <= CAIRO_OPERATOR_SATURATE || \
358 (CAIRO_RENDER_HAS_PDF_OPERATORS(surface) && \
359 (op) <= CAIRO_OPERATOR_HSL_LUMINOSITY))
362 * Return whether two xlib surfaces share the same
363 * screen. Both core and Render drawing require this
364 * when using multiple drawables in an operation.
366 static inline cairo_bool_t
367 _cairo_xlib_surface_same_screen (cairo_xlib_surface_t *dst,
368 cairo_xlib_surface_t *src)
370 return dst->screen == src->screen;
374 _cairo_xlib_surface_put_gc (cairo_xlib_display_t *display,
375 cairo_xlib_surface_t *surface,
378 _cairo_xlib_screen_put_gc (display,
384 #endif /* CAIRO_XLIB_PRIVATE_H */