summaryrefslogtreecommitdiff
path: root/src/cairo-xcb-private.h
blob: e9abe211e37d0645f39d6d24898239bcebad348d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
/* Cairo - a vector graphics library with display and print output
 *
 * Copyright © 2005 Red Hat, Inc.
 * Copyright © 2009 Intel Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it either under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * (the "LGPL") or, at your option, under the terms of the Mozilla
 * Public License Version 1.1 (the "MPL"). If you do not alter this
 * notice, a recipient may use your version of this file under either
 * the MPL or the LGPL.
 *
 * You should have received a copy of the LGPL along with this library
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * You should have received a copy of the MPL along with this library
 * in the file COPYING-MPL-1.1
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
 * the specific language governing rights and limitations.
 *
 * The Original Code is the cairo graphics library.
 *
 * The Initial Developer of the Original Code is Red Hat, Inc.
 *
 * Contributors(s):
 *	Chris Wilson <chris@chris-wilson.co.uk>
 */

#ifndef CAIRO_XCB_PRIVATE_H
#define CAIRO_XCB_PRIVATE_H

#include "cairo-cache-private.h"
#include "cairo-compiler-private.h"
#include "cairo-freelist-private.h"
#include "cairo-list-private.h"
#include "cairo-mutex-private.h"
#include "cairo-reference-count-private.h"
#include "cairo-surface-private.h"

#include <xcb/xcb.h>
#include <xcb/render.h>
#include <pixman.h>

typedef struct _cairo_xcb_connection_t cairo_xcb_connection_t;
typedef struct _cairo_xcb_screen_t cairo_xcb_screen_t;
typedef struct _cairo_xcb_surface cairo_xcb_surface_t;
typedef struct _cairo_xcb_shm_mem_pool cairo_xcb_shm_mem_pool_t;
typedef struct _cairo_xcb_shm_info cairo_xcb_shm_info_t;

struct _cairo_xcb_shm_info {
    cairo_xcb_connection_t *connection;
    uint32_t shm;
    uint32_t offset;
    void *mem;
    cairo_xcb_shm_mem_pool_t *pool;
};

struct _cairo_xcb_surface {
    cairo_surface_t base;
    cairo_surface_t *fallback;

    cairo_xcb_connection_t *connection;
    cairo_xcb_screen_t *screen;
    xcb_connection_t *xcb_connection;

    cairo_bool_t is_clear;

    xcb_drawable_t drawable;
    cairo_bool_t owns_pixmap;
    int use_pixmap;

    int width;
    int height;
    int depth;

    unsigned int flags;
    xcb_render_picture_t picture;
    xcb_render_pictformat_t xrender_format;
    pixman_format_code_t pixman_format;

    struct {
	cairo_surface_t *picture;
	cairo_color_t color;
    } solid_cache[4];
    int solid_cache_size;

    cairo_list_t link;
};

struct _cairo_xcb_screen_t {
    cairo_reference_count_t ref_count;
    cairo_mutex_t mutex;

    cairo_xcb_connection_t *connection;

    xcb_connection_t	    *xcb_connection;
    xcb_screen_t	    *xcb_screen;

    xcb_gcontext_t gc[4];
    int gc_depths; /* 4 x uint8_t */

    uint32_t xid;

    struct {
	cairo_surface_t *picture;
	cairo_color_t color;
    } solid_cache[16];
    int solid_cache_size;

    cairo_cache_t linear_pattern_cache;
    cairo_cache_t radial_pattern_cache;
    cairo_freelist_t pattern_cache_entry_freelist;

    cairo_list_t link;
};

struct _cairo_xcb_connection_t {
    cairo_reference_count_t ref_count;
    cairo_status_t status;
    cairo_mutex_t mutex;
    uintptr_t mutex_owner;
    unsigned mutex_depth;

    xcb_connection_t	    *xcb_connection;
    cairo_bool_t has_socket;

    xcb_render_pictformat_t standard_formats[5];
    cairo_hash_table_t *xrender_formats;
    cairo_hash_table_t *visual_to_xrender_format;

    unsigned int maximum_request_length;
    unsigned int flags;

    const xcb_setup_t *root;
    const xcb_query_extension_reply_t *render;

    cairo_list_t free_xids;
    cairo_freepool_t xid_pool;

    cairo_list_t shm_pools;
    cairo_freepool_t shm_info_freelist;

    cairo_list_t link;
    cairo_list_t screens;
};

enum {
	 CAIRO_XCB_HAS_RENDER			    = 0x0001,
	 CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES	    = 0x0002,
	 CAIRO_XCB_RENDER_HAS_COMPOSITE		    = 0x0004,
	 CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS  = 0x0008,
	 CAIRO_XCB_RENDER_HAS_COMPOSITE_SPANS       = 0x0010,
	 CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS	    = 0x0020,
	 CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM	    = 0x0040,
	 CAIRO_XCB_RENDER_HAS_FILTERS		    = 0x0080,
	 CAIRO_XCB_RENDER_HAS_PDF_OPERATORS	    = 0x0100,
	 CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT	    = 0x0200,
	 CAIRO_XCB_RENDER_HAS_GRADIENTS		    = 0x0400,

	 CAIRO_XCB_HAS_CAIRO			    = 0x10000,

	 CAIRO_XCB_HAS_SHM			    = 0x80000000
};

cairo_private extern const cairo_surface_backend_t _cairo_xcb_surface_backend;

cairo_private cairo_xcb_connection_t *
_cairo_xcb_connection_create (xcb_connection_t *connection);

cairo_private cairo_xcb_connection_t *
_cairo_xcb_connection_reference (cairo_xcb_connection_t *connection);

cairo_private xcb_render_pictformat_t
_cairo_xcb_connection_get_xrender_format (cairo_xcb_connection_t *connection,
					  pixman_format_code_t pixman_format);

cairo_private xcb_render_pictformat_t
_cairo_xcb_connection_get_xrender_format_for_visual (cairo_xcb_connection_t *connection,
						     const xcb_visualid_t visual);

cairo_private cairo_status_t
_cairo_xcb_connection_acquire (cairo_xcb_connection_t *connection);

cairo_private uint32_t
_cairo_xcb_connection_get_xid (cairo_xcb_connection_t *connection);

cairo_private void
_cairo_xcb_connection_put_xid (cairo_xcb_connection_t *connection,
			       uint32_t xid);

cairo_private void
_cairo_xcb_connection_release (cairo_xcb_connection_t *connection);

cairo_private void
_cairo_xcb_connection_destroy (cairo_xcb_connection_t *connection);

cairo_private cairo_int_status_t
_cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *display,
					 size_t size,
					 cairo_xcb_shm_info_t **shm_info_out);

cairo_private void
_cairo_xcb_shm_info_destroy (cairo_xcb_shm_info_t *shm_info);

cairo_private void
_cairo_xcb_connection_shm_mem_pools_fini (cairo_xcb_connection_t *connection);

cairo_private cairo_xcb_screen_t *
_cairo_xcb_screen_create (xcb_connection_t *connection,
			  xcb_screen_t *screen);

cairo_private cairo_xcb_screen_t *
_cairo_xcb_screen_reference (cairo_xcb_screen_t *screen);

cairo_private void
_cairo_xcb_screen_destroy (cairo_xcb_screen_t *screen);


cairo_private xcb_gcontext_t
_cairo_xcb_screen_get_gc (cairo_xcb_screen_t *screen,
			  xcb_drawable_t drawable,
			  int depth);

cairo_private void
_cairo_xcb_screen_put_gc (cairo_xcb_screen_t *screen, int depth, xcb_gcontext_t gc);

#if HAS_ATOMIC_OPS
cairo_private uint32_t
_cairo_xcb_screen_generate_id (cairo_xcb_screen_t *screen);

cairo_private void
_cairo_xcb_screen_stash_id (cairo_xcb_screen_t *screen, uint32_t xid);
#else
#define _cairo_xcb_screen_generate_id(S) xcb_generate_id ((S)->xcb_connection)
#define _cairo_xcb_screen_stash_id(S, xid)
#endif

cairo_private cairo_status_t
_cairo_xcb_screen_store_linear_picture (cairo_xcb_screen_t *screen,
					const cairo_linear_pattern_t *linear,
					cairo_surface_t *picture);

cairo_private cairo_surface_t *
_cairo_xcb_screen_lookup_linear_picture (cairo_xcb_screen_t *screen,
					 const cairo_linear_pattern_t *linear);

cairo_private cairo_status_t
_cairo_xcb_screen_store_radial_picture (cairo_xcb_screen_t *screen,
					const cairo_radial_pattern_t *radial,
					cairo_surface_t *picture);

cairo_private cairo_surface_t *
_cairo_xcb_screen_lookup_radial_picture (cairo_xcb_screen_t *screen,
					 const cairo_radial_pattern_t *radial);

cairo_private cairo_int_status_t
_cairo_xcb_surface_cairo_paint (cairo_xcb_surface_t	*surface,
				cairo_operator_t	 op,
				const cairo_pattern_t	*source,
				cairo_clip_t		*clip);

cairo_private cairo_int_status_t
_cairo_xcb_surface_cairo_mask (cairo_xcb_surface_t	*surface,
			       cairo_operator_t		 op,
			       const cairo_pattern_t	*source,
			       const cairo_pattern_t	*mask,
			       cairo_clip_t		*clip);

cairo_private cairo_int_status_t
_cairo_xcb_surface_cairo_stroke (cairo_xcb_surface_t	*surface,
				 cairo_operator_t	 op,
				 const cairo_pattern_t	*source,
				 cairo_path_fixed_t	*path,
				 cairo_stroke_style_t	*style,
				 cairo_matrix_t		*ctm,
				 cairo_matrix_t		*ctm_inverse,
				 double			 tolerance,
				 cairo_antialias_t	 antialias,
				 cairo_clip_t		*clip);

cairo_private cairo_int_status_t
_cairo_xcb_surface_cairo_fill (cairo_xcb_surface_t	*surface,
			       cairo_operator_t		 op,
			       const cairo_pattern_t	*source,
			       cairo_path_fixed_t	*path,
			       cairo_fill_rule_t	 fill_rule,
			       double			 tolerance,
			       cairo_antialias_t	 antialias,
			       cairo_clip_t		*clip);

cairo_private cairo_int_status_t
_cairo_xcb_surface_cairo_show_glyphs (cairo_xcb_surface_t	*surface,
				      cairo_operator_t		 op,
				      const cairo_pattern_t	*source,
				      cairo_glyph_t		*glyphs,
				      int			 num_glyphs,
				      cairo_scaled_font_t	*scaled_font,
				      cairo_clip_t		*clip,
				      int			*remaining_glyphs);

cairo_private cairo_int_status_t
_cairo_xcb_surface_composite (cairo_operator_t	 op,
			      const cairo_pattern_t	*src_pattern,
			      const cairo_pattern_t	*mask_pattern,
			      void			*abstract_dst,
			      int			 src_x,
			      int			 src_y,
			      int			 mask_x,
			      int			 mask_y,
			      int			 dst_x,
			      int			 dst_y,
			      unsigned int		 width,
			      unsigned int		 height,
			      cairo_region_t		*clip_region);

cairo_private cairo_int_status_t
_cairo_xcb_surface_fill_rectangles (void			*abstract_surface,
				    cairo_operator_t		 op,
				    const cairo_color_t		*color,
				    cairo_rectangle_int_t	*rects,
				    int				 num_rects);

cairo_private cairo_int_status_t
_cairo_xcb_surface_composite_trapezoids (cairo_operator_t	op,
					 const cairo_pattern_t *pattern,
					 void			*abstract_dst,
					 cairo_antialias_t	antialias,
					 int			src_x,
					 int			src_y,
					 int			dst_x,
					 int			dst_y,
					 unsigned int		width,
					 unsigned int		height,
					 cairo_trapezoid_t	*traps,
					 int			num_traps,
					 cairo_region_t	*clip_region);

cairo_private cairo_bool_t
_cairo_xcb_surface_check_span_renderer (cairo_operator_t	 op,
					const cairo_pattern_t	*pattern,
					void			*abstract_dst,
					cairo_antialias_t	 antialias);

cairo_private cairo_span_renderer_t *
_cairo_xcb_surface_create_span_renderer (cairo_operator_t	 op,
					 const cairo_pattern_t  *pattern,
					 void			*abstract_dst,
					 cairo_antialias_t	 antialias,
					 const cairo_composite_rectangles_t *rects,
					 cairo_region_t		*clip_region);

cairo_private cairo_int_status_t
_cairo_xcb_surface_composite_glyphs (void			*abstract_dst,
				     cairo_operator_t		 op,
				     const cairo_pattern_t	*pattern,
				     cairo_scaled_font_t	*scaled_font,
				     cairo_glyph_t		*glyphs,
				     int			 num_glyphs,
				     int			 src_x,
				     int			 src_y,
				     int			 dst_x,
				     int			 dst_y,
				     unsigned int		 width,
				     unsigned int		 height,
				     cairo_region_t		*clip_region);

cairo_private cairo_int_status_t
_cairo_xcb_surface_core_composite (cairo_operator_t		 op,
				   const cairo_pattern_t	*src_pattern,
				   const cairo_pattern_t	*mask_pattern,
				   void				*abstract_dst,
				   int				 src_x,
				   int				 src_y,
				   int				 mask_x,
				   int				 mask_y,
				   int				 dst_x,
				   int				 dst_y,
				   unsigned int			 width,
				   unsigned int			 height,
				   cairo_region_t		*clip_region);

cairo_private cairo_int_status_t
_cairo_xcb_surface_core_fill_rectangles (void			*abstract_dst,
					 cairo_operator_t	 op,
					 const cairo_color_t	*color,
					 cairo_rectangle_int_t	*rects,
					 int			 num_rects);

cairo_private void
_cairo_xcb_connection_render_spans (cairo_xcb_connection_t *connection,
				    xcb_render_picture_t dst,
				    int op,
				    xcb_render_picture_t src,
				    int16_t src_x, int16_t src_y,
				    int16_t dst_x, int16_t dst_y,
				    int16_t width, int16_t height,
				    unsigned int length,
				    uint16_t *spans);
cairo_private void
_cairo_xcb_connection_render_create_picture (cairo_xcb_connection_t  *connection,
					     xcb_render_picture_t     pid,
					     xcb_drawable_t           drawable,
					     xcb_render_pictformat_t  format,
					     uint32_t                 value_mask,
					     uint32_t                *value_list);

cairo_private void
_cairo_xcb_connection_render_change_picture (cairo_xcb_connection_t     *connection,
					     xcb_render_picture_t  picture,
					     uint32_t              value_mask,
					     uint32_t             *value_list);

cairo_private void
_cairo_xcb_connection_render_set_picture_clip_rectangles (cairo_xcb_connection_t      *connection,
							  xcb_render_picture_t   picture,
							  int16_t                clip_x_origin,
							  int16_t                clip_y_origin,
							  uint32_t               rectangles_len,
							  xcb_rectangle_t       *rectangles);

cairo_private void
_cairo_xcb_connection_render_free_picture (cairo_xcb_connection_t *connection,
					   xcb_render_picture_t  picture);

cairo_private void
_cairo_xcb_connection_render_composite (cairo_xcb_connection_t     *connection,
					uint8_t               op,
					xcb_render_picture_t  src,
					xcb_render_picture_t  mask,
					xcb_render_picture_t  dst,
					int16_t               src_x,
					int16_t               src_y,
					int16_t               mask_x,
					int16_t               mask_y,
					int16_t               dst_x,
					int16_t               dst_y,
					uint16_t              width,
					uint16_t              height);

cairo_private void
_cairo_xcb_connection_render_trapezoids (cairo_xcb_connection_t *connection,
					 uint8_t                       op,
					 xcb_render_picture_t          src,
					 xcb_render_picture_t          dst,
					 xcb_render_pictformat_t       mask_format,
					 int16_t                       src_x,
					 int16_t                       src_y,
					 uint32_t                      traps_len,
					 xcb_render_trapezoid_t       *traps);

cairo_private void
_cairo_xcb_connection_render_create_glyph_set (cairo_xcb_connection_t        *connection,
					       xcb_render_glyphset_t    gsid,
					       xcb_render_pictformat_t  format);

cairo_private void
_cairo_xcb_connection_render_free_glyph_set (cairo_xcb_connection_t      *connection,
					     xcb_render_glyphset_t  glyphset);

cairo_private void
_cairo_xcb_connection_render_add_glyphs (cairo_xcb_connection_t             *connection,
					 xcb_render_glyphset_t         glyphset,
					 uint32_t                      num_glyphs,
					 uint32_t                     *glyphs_id,
					 xcb_render_glyphinfo_t       *glyphs,
					 uint32_t                      data_len,
					 uint8_t                      *data);

cairo_private void
_cairo_xcb_connection_render_free_glyphs (cairo_xcb_connection_t         *connection,
					  xcb_render_glyphset_t     glyphset,
					  uint32_t                  num_glyphs,
					  xcb_render_glyph_t       *glyphs);

cairo_private void
_cairo_xcb_connection_render_composite_glyphs_8 (cairo_xcb_connection_t        *connection,
						 uint8_t                  op,
						 xcb_render_picture_t     src,
						 xcb_render_picture_t     dst,
						 xcb_render_pictformat_t  mask_format,
						 xcb_render_glyphset_t    glyphset,
						 int16_t                  src_x,
						 int16_t                  src_y,
						 uint32_t                 glyphcmds_len,
						 uint8_t                 *glyphcmds);

cairo_private void
_cairo_xcb_connection_render_composite_glyphs_16 (cairo_xcb_connection_t        *connection,
						  uint8_t                  op,
						  xcb_render_picture_t     src,
						  xcb_render_picture_t     dst,
						  xcb_render_pictformat_t  mask_format,
						  xcb_render_glyphset_t    glyphset,
						  int16_t                  src_x,
						  int16_t                  src_y,
						  uint32_t                 glyphcmds_len,
						  uint8_t                 *glyphcmds);

cairo_private void
_cairo_xcb_connection_render_composite_glyphs_32 (cairo_xcb_connection_t        *connection,
						  uint8_t                  op,
						  xcb_render_picture_t     src,
						  xcb_render_picture_t     dst,
						  xcb_render_pictformat_t  mask_format,
						  xcb_render_glyphset_t    glyphset,
						  int16_t                  src_x,
						  int16_t                  src_y,
						  uint32_t                 glyphcmds_len,
						  uint8_t                 *glyphcmds);

cairo_private void
_cairo_xcb_connection_render_fill_rectangles (cairo_xcb_connection_t      *connection,
					      uint8_t                op,
					      xcb_render_picture_t   dst,
					      xcb_render_color_t     color,
					      uint32_t               num_rects,
					      xcb_rectangle_t       *rects);

cairo_private void
_cairo_xcb_connection_render_set_picture_transform (cairo_xcb_connection_t       *connection,
						    xcb_render_picture_t    picture,
						    xcb_render_transform_t  *transform);

cairo_private void
_cairo_xcb_connection_render_set_picture_filter (cairo_xcb_connection_t         *connection,
						 xcb_render_picture_t      picture,
						 uint16_t                  filter_len,
						 char                     *filter);

cairo_private void
_cairo_xcb_connection_render_create_solid_fill (cairo_xcb_connection_t     *connection,
						xcb_render_picture_t  picture,
						xcb_render_color_t    color);

cairo_private void
_cairo_xcb_connection_render_create_linear_gradient (cairo_xcb_connection_t         *connection,
						     xcb_render_picture_t      picture,
						     xcb_render_pointfix_t     p1,
						     xcb_render_pointfix_t     p2,
						     uint32_t                  num_stops,
						     xcb_render_fixed_t *stops,
						     xcb_render_color_t *colors);

cairo_private void
_cairo_xcb_connection_render_create_radial_gradient (cairo_xcb_connection_t         *connection,
						     xcb_render_picture_t      picture,
						     xcb_render_pointfix_t     inner,
						     xcb_render_pointfix_t     outer,
						     xcb_render_fixed_t        inner_radius,
						     xcb_render_fixed_t        outer_radius,
						     uint32_t                  num_stops,
						     xcb_render_fixed_t *stops,
						     xcb_render_color_t *colors);

cairo_private void
_cairo_xcb_connection_render_create_conical_gradient (cairo_xcb_connection_t         *c,
						      xcb_render_picture_t      picture,
						      xcb_render_pointfix_t     center,
						      xcb_render_fixed_t        angle,
						      uint32_t                  num_stops,
						      xcb_render_fixed_t *stops,
						      xcb_render_color_t *colors);

#endif /* CAIRO_XCB_PRIVATE_H */