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-xrender-private.h"
41 #include "cairo-xlib.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"
55 typedef struct _cairo_xlib_display cairo_xlib_display_t;
56 typedef struct _cairo_xlib_shm_display cairo_xlib_shm_display_t;
57 typedef struct _cairo_xlib_screen cairo_xlib_screen_t;
58 typedef struct _cairo_xlib_source cairo_xlib_source_t;
59 typedef struct _cairo_xlib_proxy cairo_xlib_proxy_t;
60 typedef struct _cairo_xlib_surface cairo_xlib_surface_t;
62 /* size of color cube */
64 /* size of gray ramp */
66 /* maximum number of cached GC's */
67 #define GC_CACHE_SIZE 4
69 struct _cairo_xlib_display {
72 cairo_xlib_display_t *next;
78 cairo_xlib_shm_display_t *shm;
80 const cairo_compositor_t *compositor;
84 XRenderPictFormat *cached_xrender_formats[CAIRO_FORMAT_RGB30 + 1];
88 cairo_surface_t *white;
89 cairo_surface_t *alpha[256];
90 cairo_surface_t *solid[32];
91 uint32_t solid_cache[32]; /* low 16 are opaque, high 16 transparent */
95 } last_solid_cache[2];
97 /* TRUE if the server has a bug with repeating pictures
99 * https://bugs.freedesktop.org/show_bug.cgi?id=3566
101 * We can't test for this because it depends on whether the
102 * picture is in video memory or not.
104 * We also use this variable as a guard against a second
105 * independent bug with transformed repeating pictures:
107 * http://lists.freedesktop.org/archives/cairo/2004-September/001839.html
109 * Both are fixed in xorg >= 6.9 and hopefully in > 6.8.2, so
110 * we can reuse the test for now.
112 unsigned int buggy_gradients : 1;
113 unsigned int buggy_pad_reflect : 1;
114 unsigned int buggy_repeat : 1;
115 unsigned int closed :1;
118 typedef struct _cairo_xlib_visual_info {
121 struct { uint8_t a, r, g, b; } colors[256];
122 uint8_t cube_to_pseudocolor[CUBE_SIZE][CUBE_SIZE][CUBE_SIZE];
123 uint8_t field8_to_cube[256];
124 int8_t dither8_to_cube[256];
125 uint8_t gray8_to_pseudocolor[256];
126 } cairo_xlib_visual_info_t;
128 struct _cairo_xlib_screen {
131 cairo_device_t *device;
134 cairo_list_t surfaces;
136 cairo_bool_t has_font_options;
137 cairo_font_options_t font_options;
139 GC gc[GC_CACHE_SIZE];
140 uint8_t gc_depths[GC_CACHE_SIZE];
142 cairo_list_t visuals;
146 GLYPHSET_INDEX_ARGB32,
152 typedef struct _cairo_xlib_font_glyphset {
154 cairo_format_t format;
155 XRenderPictFormat *xrender_format;
156 struct _cairo_xlib_font_glyphset_free_glyphs {
158 unsigned long indices[128];
160 } cairo_xlib_font_glyphset_t;
162 typedef struct _cairo_xlib_font {
163 cairo_scaled_font_private_t base;
164 cairo_scaled_font_t *font;
165 cairo_device_t *device;
167 cairo_xlib_font_glyphset_t glyphset[NUM_GLYPHSETS];
170 struct _cairo_xlib_surface {
171 cairo_surface_t base;
176 const cairo_compositor_t *compositor;
177 cairo_surface_t *shm;
180 cairo_xlib_display_t *display;
181 cairo_xlib_screen_t *screen;
184 Display *dpy; /* only valid between acquire/release */
185 cairo_bool_t owns_pixmap;
195 XRenderPictFormat *xrender_format;
196 /* XXX pixman_format instead of masks? */
202 struct _cairo_xlib_source {
203 cairo_surface_t base;
209 unsigned int filter:3;
210 unsigned int extend:3;
211 unsigned int has_matrix:1;
212 unsigned int has_component_alpha:1;
216 struct _cairo_xlib_proxy {
217 struct _cairo_xlib_source source;
218 cairo_surface_t *owner;
221 inline static cairo_bool_t
222 _cairo_xlib_vendor_is_xorg (Display *dpy)
224 const char *const vendor = ServerVendor (dpy);
225 return strstr (vendor, "X.Org") || strstr (vendor, "Xorg");
228 cairo_private cairo_status_t
229 _cairo_xlib_surface_get_gc (cairo_xlib_display_t *display,
230 cairo_xlib_surface_t *surface,
233 cairo_private cairo_device_t *
234 _cairo_xlib_device_create (Display *display);
237 _cairo_xlib_display_init_shm (cairo_xlib_display_t *display);
240 _cairo_xlib_display_fini_shm (cairo_xlib_display_t *display);
242 cairo_private cairo_xlib_screen_t *
243 _cairo_xlib_display_get_screen (cairo_xlib_display_t *display,
246 cairo_private cairo_status_t
247 _cairo_xlib_display_acquire (cairo_device_t *device,
248 cairo_xlib_display_t **display);
250 cairo_private cairo_bool_t
251 _cairo_xlib_display_has_repeat (cairo_device_t *device);
253 cairo_private cairo_bool_t
254 _cairo_xlib_display_has_reflect (cairo_device_t *device);
256 cairo_private cairo_bool_t
257 _cairo_xlib_display_has_gradients (cairo_device_t *device);
260 _cairo_xlib_display_set_precision(cairo_device_t *device,
263 cairo_private XRenderPictFormat *
264 _cairo_xlib_display_get_xrender_format (cairo_xlib_display_t *display,
265 cairo_format_t format);
267 cairo_private XRenderPictFormat *
268 _cairo_xlib_display_get_xrender_format_for_pixman (cairo_xlib_display_t *display,
269 pixman_format_code_t format);
271 cairo_private cairo_status_t
272 _cairo_xlib_screen_get (Display *dpy,
274 cairo_xlib_screen_t **out);
277 _cairo_xlib_screen_destroy (cairo_xlib_display_t *display,
278 cairo_xlib_screen_t *info);
281 _cairo_xlib_screen_get_gc (cairo_xlib_display_t *display,
282 cairo_xlib_screen_t *info,
286 _cairo_xlib_screen_put_gc (cairo_xlib_display_t *display,
287 cairo_xlib_screen_t *info,
291 cairo_private cairo_font_options_t *
292 _cairo_xlib_screen_get_font_options (cairo_xlib_screen_t *info);
294 cairo_private cairo_status_t
295 _cairo_xlib_screen_get_visual_info (cairo_xlib_display_t *display,
296 cairo_xlib_screen_t *info,
298 cairo_xlib_visual_info_t **out);
300 cairo_private cairo_status_t
301 _cairo_xlib_visual_info_create (Display *dpy,
304 cairo_xlib_visual_info_t **out);
307 _cairo_xlib_visual_info_destroy (cairo_xlib_visual_info_t *info);
309 cairo_private const cairo_compositor_t *
310 _cairo_xlib_core_compositor_get (void);
312 cairo_private const cairo_compositor_t *
313 _cairo_xlib_fallback_compositor_get (void);
315 cairo_private const cairo_compositor_t *
316 _cairo_xlib_mask_compositor_get (void);
318 cairo_private const cairo_compositor_t *
319 _cairo_xlib_traps_compositor_get (void);
322 _cairo_xlib_surface_ensure_picture (cairo_xlib_surface_t *surface);
325 _cairo_xlib_surface_set_precision (cairo_xlib_surface_t *surface,
326 cairo_antialias_t antialias);
328 cairo_private cairo_int_status_t
329 _cairo_xlib_surface_set_attributes (cairo_xlib_display_t *display,
330 cairo_xlib_surface_t *surface,
331 cairo_surface_attributes_t *attributes,
335 cairo_private cairo_status_t
336 _cairo_xlib_surface_draw_image (cairo_xlib_surface_t *surface,
337 cairo_image_surface_t *image,
345 cairo_private cairo_surface_t *
346 _cairo_xlib_source_create_for_pattern (cairo_surface_t *dst,
347 const cairo_pattern_t *pattern,
348 cairo_bool_t is_mask,
349 const cairo_rectangle_int_t *extents,
350 const cairo_rectangle_int_t *sample,
351 int *src_x, int *src_y);
354 _cairo_xlib_font_close (cairo_xlib_font_t *font);
356 #define CAIRO_RENDER_AT_LEAST(surface, major, minor) \
357 (((surface)->render_major > major) || \
358 (((surface)->render_major == major) && ((surface)->render_minor >= minor)))
360 #define CAIRO_RENDER_HAS_CREATE_PICTURE(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0)
361 #define CAIRO_RENDER_HAS_COMPOSITE(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0)
362 #define CAIRO_RENDER_HAS_COMPOSITE_TEXT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 0)
364 #define CAIRO_RENDER_HAS_FILL_RECTANGLES(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 1)
366 #define CAIRO_RENDER_HAS_DISJOINT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 2)
367 #define CAIRO_RENDER_HAS_CONJOINT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 2)
369 #define CAIRO_RENDER_HAS_TRAPEZOIDS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4)
370 #define CAIRO_RENDER_HAS_TRIANGLES(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4)
371 #define CAIRO_RENDER_HAS_TRISTRIP(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4)
372 #define CAIRO_RENDER_HAS_TRIFAN(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 4)
374 #define CAIRO_RENDER_HAS_PICTURE_TRANSFORM(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 6)
375 #define CAIRO_RENDER_HAS_FILTERS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 6)
376 #define CAIRO_RENDER_HAS_FILTER_GOOD(surface) FALSE
377 #define CAIRO_RENDER_HAS_FILTER_BEST(surface) FALSE
379 #define CAIRO_RENDER_HAS_EXTENDED_REPEAT(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 10)
380 #define CAIRO_RENDER_HAS_GRADIENTS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 10)
382 #define CAIRO_RENDER_HAS_PDF_OPERATORS(surface) CAIRO_RENDER_AT_LEAST((surface), 0, 11)
384 #define CAIRO_RENDER_SUPPORTS_OPERATOR(surface, op) \
385 ((op) <= CAIRO_OPERATOR_SATURATE || \
386 (CAIRO_RENDER_HAS_PDF_OPERATORS(surface) && \
387 (op) <= CAIRO_OPERATOR_HSL_LUMINOSITY))
390 * Return whether two xlib surfaces share the same
391 * screen. Both core and Render drawing require this
392 * when using multiple drawables in an operation.
394 static inline cairo_bool_t
395 _cairo_xlib_surface_same_screen (cairo_xlib_surface_t *dst,
396 cairo_xlib_surface_t *src)
398 return dst->screen == src->screen;
401 cairo_private cairo_int_status_t
402 _cairo_xlib_core_fill_boxes (cairo_xlib_surface_t *dst,
403 const cairo_color_t *color,
404 cairo_boxes_t *boxes);
406 cairo_private cairo_int_status_t
407 _cairo_xlib_core_fill_rectangles (cairo_xlib_surface_t *dst,
408 const cairo_color_t *color,
410 cairo_rectangle_int_t *rects);
413 _cairo_xlib_surface_put_gc (cairo_xlib_display_t *display,
414 cairo_xlib_surface_t *surface,
417 _cairo_xlib_screen_put_gc (display,
423 cairo_private cairo_surface_t *
424 _cairo_xlib_surface_create_similar_shm (void *surface,
425 cairo_format_t format,
426 int width, int height);
428 cairo_private cairo_surface_t *
429 _cairo_xlib_surface_get_shm (cairo_xlib_surface_t *surface,
430 cairo_bool_t overwrite);
432 cairo_private cairo_int_status_t
433 _cairo_xlib_surface_put_shm (cairo_xlib_surface_t *surface);
435 cairo_private cairo_surface_t *
436 _cairo_xlib_surface_create_shm (cairo_xlib_surface_t *other,
437 pixman_format_code_t format,
438 int width, int height);
440 cairo_private cairo_surface_t *
441 _cairo_xlib_surface_create_shm__image (cairo_xlib_surface_t *surface,
442 pixman_format_code_t format,
443 int width, int height);
446 _cairo_xlib_shm_surface_get_ximage (cairo_surface_t *surface,
450 _cairo_xlib_shm_surface_get_obdata (cairo_surface_t *surface);
453 _cairo_xlib_shm_surface_mark_active (cairo_surface_t *shm);
455 cairo_private cairo_bool_t
456 _cairo_xlib_shm_surface_is_active (cairo_surface_t *surface);
458 cairo_private cairo_bool_t
459 _cairo_xlib_shm_surface_is_idle (cairo_surface_t *surface);
462 _cairo_xlib_shm_surface_get_pixmap (cairo_surface_t *surface);
464 cairo_private XRenderPictFormat *
465 _cairo_xlib_shm_surface_get_xrender_format (cairo_surface_t *surface);
467 cairo_private pixman_format_code_t
468 _pixman_format_for_xlib_surface (cairo_xlib_surface_t *surface);
470 #endif /* CAIRO_XLIB_PRIVATE_H */