-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcairo-xlib-render-compositor.c
1972 lines (1692 loc) · 57.3 KB
/
cairo-xlib-render-compositor.c
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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2002 University of Southern California
* Copyright © 2005 Red Hat, Inc.
* Copyright © 2011 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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, 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 University of Southern
* California.
*
* Contributor(s):
* Carl D. Worth <[email protected]>
* Behdad Esfahbod <[email protected]>
* Chris Wilson <[email protected]>
* Karl Tomlinson <[email protected]>, Mozilla Corporation
*/
#include "cairoint.h"
#if !CAIRO_HAS_XLIB_XCB_FUNCTIONS
#include "cairo-xlib-private.h"
#include "cairo-compositor-private.h"
#include "cairo-damage-private.h"
#include "cairo-image-surface-private.h"
#include "cairo-list-inline.h"
#include "cairo-pattern-private.h"
#include "cairo-traps-private.h"
#include "cairo-tristrip-private.h"
static cairo_int_status_t
acquire (void *abstract_dst)
{
cairo_xlib_surface_t *dst = abstract_dst;
cairo_int_status_t status;
status = _cairo_xlib_display_acquire (dst->base.device, &dst->display);
if (unlikely (status))
return status;
dst->dpy = dst->display->display;
return CAIRO_STATUS_SUCCESS;
}
static cairo_int_status_t
release (void *abstract_dst)
{
cairo_xlib_surface_t *dst = abstract_dst;
cairo_device_release (&dst->display->base);
dst->dpy = NULL;
return CAIRO_STATUS_SUCCESS;
}
static cairo_int_status_t
set_clip_region (void *_surface,
cairo_region_t *region)
{
cairo_xlib_surface_t *surface = _surface;
_cairo_xlib_surface_ensure_picture (surface);
if (region != NULL) {
XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (sizeof (XRectangle))];
XRectangle *rects = stack_rects;
int n_rects, i;
n_rects = cairo_region_num_rectangles (region);
if (n_rects > ARRAY_LENGTH (stack_rects)) {
rects = _cairo_malloc_ab (n_rects, sizeof (XRectangle));
if (unlikely (rects == NULL))
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
for (i = 0; i < n_rects; i++) {
cairo_rectangle_int_t rect;
cairo_region_get_rectangle (region, i, &rect);
rects[i].x = rect.x;
rects[i].y = rect.y;
rects[i].width = rect.width;
rects[i].height = rect.height;
}
XRenderSetPictureClipRectangles (surface->dpy,
surface->picture,
0, 0,
rects, n_rects);
if (rects != stack_rects)
free (rects);
} else {
XRenderPictureAttributes pa;
pa.clip_mask = None;
XRenderChangePicture (surface->dpy,
surface->picture,
CPClipMask, &pa);
}
return CAIRO_STATUS_SUCCESS;
}
static cairo_int_status_t
copy_image_boxes (void *_dst,
cairo_image_surface_t *image,
cairo_boxes_t *boxes,
int dx, int dy)
{
cairo_xlib_surface_t *dst = _dst;
struct _cairo_boxes_chunk *chunk;
cairo_int_status_t status;
Pixmap src;
GC gc;
int i, j;
assert (image->depth == dst->depth);
status = acquire (dst);
if (unlikely (status))
return status;
status = _cairo_xlib_surface_get_gc (dst->display, dst, &gc);
if (unlikely (status)) {
release (dst);
return status;
}
src = _cairo_xlib_shm_surface_get_pixmap (&image->base);
if (boxes->num_boxes == 1) {
int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x);
int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y);
int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x);
int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y);
XCopyArea (dst->dpy, src, dst->drawable, gc,
x1 + dx, y1 + dy,
x2 - x1, y2 - y1,
x1, y1);
} else {
XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)];
XRectangle *rects = stack_rects;
if (boxes->num_boxes > ARRAY_LENGTH (stack_rects)) {
rects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle));
if (unlikely (rects == NULL))
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
j = 0;
for (chunk = &boxes->chunks; chunk; chunk = chunk->next) {
for (i = 0; i < chunk->count; i++) {
int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x);
int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y);
int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x);
int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y);
if (x2 > x1 && y2 > y1) {
rects[j].x = x1;
rects[j].y = y1;
rects[j].width = x2 - x1;
rects[j].height = y2 - y1;
j++;
}
}
}
XSetClipRectangles (dst->dpy, gc, 0, 0, rects, j, Unsorted);
XCopyArea (dst->dpy, src, dst->drawable, gc,
0, 0, image->width, image->height, -dx, -dy);
XSetClipMask (dst->dpy, gc, None);
if (rects != stack_rects)
free (rects);
}
_cairo_xlib_shm_surface_mark_active (&image->base);
_cairo_xlib_surface_put_gc (dst->display, dst, gc);
release (dst);
return CAIRO_STATUS_SUCCESS;
}
static cairo_bool_t
boxes_cover_surface (cairo_boxes_t *boxes,
cairo_xlib_surface_t *surface)
{
cairo_box_t *b;
if (boxes->num_boxes != 1)
return FALSE;
b = &boxes->chunks.base[0];
if (_cairo_fixed_integer_part (b->p1.x) > 0 ||
_cairo_fixed_integer_part (b->p1.y) > 0)
return FALSE;
if (_cairo_fixed_integer_part (b->p2.x) < surface->width ||
_cairo_fixed_integer_part (b->p2.y) < surface->height)
return FALSE;
return TRUE;
}
static cairo_int_status_t
draw_image_boxes (void *_dst,
cairo_image_surface_t *image,
cairo_boxes_t *boxes,
int dx, int dy)
{
cairo_xlib_surface_t *dst = _dst;
struct _cairo_boxes_chunk *chunk;
cairo_image_surface_t *shm;
cairo_int_status_t status;
int i;
if (image->base.device == dst->base.device &&
image->depth == dst->depth &&
_cairo_xlib_shm_surface_get_pixmap (&image->base))
return copy_image_boxes (dst, image, boxes, dx, dy);
shm = NULL;
if (boxes_cover_surface (boxes, dst))
shm = (cairo_image_surface_t *) _cairo_xlib_surface_get_shm (dst, TRUE);
if (shm) {
for (chunk = &boxes->chunks; chunk; chunk = chunk->next) {
for (i = 0; i < chunk->count; i++) {
cairo_box_t *b = &chunk->base[i];
cairo_rectangle_int_t r;
r.x = _cairo_fixed_integer_part (b->p1.x);
r.y = _cairo_fixed_integer_part (b->p1.y);
r.width = _cairo_fixed_integer_part (b->p2.x) - r.x;
r.height = _cairo_fixed_integer_part (b->p2.y) - r.y;
if (shm->pixman_format != image->pixman_format ||
! pixman_blt ((uint32_t *)image->data, (uint32_t *)shm->data,
image->stride / sizeof (uint32_t),
shm->stride / sizeof (uint32_t),
PIXMAN_FORMAT_BPP (image->pixman_format),
PIXMAN_FORMAT_BPP (shm->pixman_format),
r.x + dx, r.y + dy,
r.x, r.y,
r.width, r.height))
{
pixman_image_composite32 (PIXMAN_OP_SRC,
image->pixman_image, NULL, shm->pixman_image,
r.x + dx, r.y + dy,
0, 0,
r.x, r.y,
r.width, r.height);
}
shm->base.damage =
_cairo_damage_add_rectangle (shm->base.damage, &r);
}
}
dst->base.is_clear = FALSE;
dst->fallback++;
dst->base.serial++;
return CAIRO_INT_STATUS_NOTHING_TO_DO;
}
if (image->depth == dst->depth &&
((cairo_xlib_display_t *)dst->display)->shm) {
cairo_box_t extents;
cairo_rectangle_int_t r;
_cairo_boxes_extents (boxes, &extents);
_cairo_box_round_to_rectangle (&extents, &r);
shm = (cairo_image_surface_t *)
_cairo_xlib_surface_create_shm (dst, image->pixman_format,
r.width, r.height);
if (shm) {
int tx = -r.x, ty = -r.y;
assert (shm->pixman_format == image->pixman_format);
for (chunk = &boxes->chunks; chunk; chunk = chunk->next) {
for (i = 0; i < chunk->count; i++) {
cairo_box_t *b = &chunk->base[i];
r.x = _cairo_fixed_integer_part (b->p1.x);
r.y = _cairo_fixed_integer_part (b->p1.y);
r.width = _cairo_fixed_integer_part (b->p2.x) - r.x;
r.height = _cairo_fixed_integer_part (b->p2.y) - r.y;
if (! pixman_blt ((uint32_t *)image->data, (uint32_t *)shm->data,
image->stride / sizeof (uint32_t),
shm->stride / sizeof (uint32_t),
PIXMAN_FORMAT_BPP (image->pixman_format),
PIXMAN_FORMAT_BPP (shm->pixman_format),
r.x + dx, r.y + dy,
r.x + tx, r.y + ty,
r.width, r.height))
{
pixman_image_composite32 (PIXMAN_OP_SRC,
image->pixman_image, NULL, shm->pixman_image,
r.x + dx, r.y + dy,
0, 0,
r.x + tx, r.y + ty,
r.width, r.height);
}
}
}
dx = tx;
dy = ty;
image = shm;
if (_cairo_xlib_shm_surface_get_pixmap (&image->base)) {
status = copy_image_boxes (dst, image, boxes, dx, dy);
if (status != CAIRO_INT_STATUS_UNSUPPORTED)
goto out;
}
}
}
status = CAIRO_STATUS_SUCCESS;
for (chunk = &boxes->chunks; chunk; chunk = chunk->next) {
for (i = 0; i < chunk->count; i++) {
cairo_box_t *b = &chunk->base[i];
int x1 = _cairo_fixed_integer_part (b->p1.x);
int y1 = _cairo_fixed_integer_part (b->p1.y);
int x2 = _cairo_fixed_integer_part (b->p2.x);
int y2 = _cairo_fixed_integer_part (b->p2.y);
if ( _cairo_xlib_surface_draw_image (dst, image,
x1 + dx, y1 + dy,
x2 - x1, y2 - y1,
x1, y1)) {
status = CAIRO_INT_STATUS_UNSUPPORTED;
goto out;
}
}
}
out:
cairo_surface_destroy (&shm->base);
return status;
}
static cairo_int_status_t
copy_boxes (void *_dst,
cairo_surface_t *_src,
cairo_boxes_t *boxes,
const cairo_rectangle_int_t *extents,
int dx, int dy)
{
cairo_xlib_surface_t *dst = _dst;
cairo_xlib_surface_t *src = (cairo_xlib_surface_t *)_src;
struct _cairo_boxes_chunk *chunk;
cairo_int_status_t status;
GC gc;
Drawable d;
int i, j;
if (! _cairo_xlib_surface_same_screen (dst, src))
return CAIRO_INT_STATUS_UNSUPPORTED;
if (dst->depth != src->depth)
return CAIRO_INT_STATUS_UNSUPPORTED;
status = acquire (dst);
if (unlikely (status))
return status;
status = _cairo_xlib_surface_get_gc (dst->display, dst, &gc);
if (unlikely (status)) {
release (dst);
return status;
}
if (src->fallback && src->shm->damage->dirty) {
assert (src != dst);
d = _cairo_xlib_shm_surface_get_pixmap (src->shm);
assert (d != 0);
} else {
if (! src->owns_pixmap) {
XGCValues gcv;
gcv.subwindow_mode = IncludeInferiors;
XChangeGC (dst->display->display, gc, GCSubwindowMode, &gcv);
}
d = src->drawable;
}
if (boxes->num_boxes == 1) {
int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x);
int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y);
int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x);
int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y);
XCopyArea (dst->dpy, d, dst->drawable, gc,
x1 + dx, y1 + dy,
x2 - x1, y2 - y1,
x1, y1);
} else {
/* We can only have a single control for subwindow_mode on the
* GC. If we have a Window destination, we need to set ClipByChildren,
* but if we have a Window source, we need IncludeInferiors. If we have
* both a Window destination and source, we must fallback. There is
* no convenient way to detect if a drawable is a Pixmap or Window,
* therefore we can only rely on those surfaces that we created
* ourselves to be Pixmaps, and treat everything else as a potential
* Window.
*/
if (src == dst || (!src->owns_pixmap && !dst->owns_pixmap)) {
for (chunk = &boxes->chunks; chunk; chunk = chunk->next) {
for (i = 0; i < chunk->count; i++) {
int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x);
int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y);
int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x);
int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y);
XCopyArea (dst->dpy, d, dst->drawable, gc,
x1 + dx, y1 + dy,
x2 - x1, y2 - y1,
x1, y1);
}
}
} else {
XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)];
XRectangle *rects = stack_rects;
if (boxes->num_boxes > ARRAY_LENGTH (stack_rects)) {
rects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle));
if (unlikely (rects == NULL))
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
j = 0;
for (chunk = &boxes->chunks; chunk; chunk = chunk->next) {
for (i = 0; i < chunk->count; i++) {
int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x);
int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y);
int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x);
int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y);
rects[j].x = x1;
rects[j].y = y1;
rects[j].width = x2 - x1;
rects[j].height = y2 - y1;
j++;
}
}
assert (j == boxes->num_boxes);
XSetClipRectangles (dst->dpy, gc, 0, 0, rects, j, Unsorted);
XCopyArea (dst->dpy, d, dst->drawable, gc,
extents->x + dx, extents->y + dy,
extents->width, extents->height,
extents->x, extents->y);
XSetClipMask (dst->dpy, gc, None);
if (rects != stack_rects)
free (rects);
}
}
if (src->fallback && src->shm->damage->dirty) {
_cairo_xlib_shm_surface_mark_active (src->shm);
} else if (! src->owns_pixmap) {
XGCValues gcv;
gcv.subwindow_mode = ClipByChildren;
XChangeGC (dst->display->display, gc, GCSubwindowMode, &gcv);
}
_cairo_xlib_surface_put_gc (dst->display, dst, gc);
release (dst);
return CAIRO_STATUS_SUCCESS;
}
static int
_render_operator (cairo_operator_t op)
{
switch (op) {
case CAIRO_OPERATOR_CLEAR:
return PictOpClear;
case CAIRO_OPERATOR_SOURCE:
return PictOpSrc;
case CAIRO_OPERATOR_OVER:
return PictOpOver;
case CAIRO_OPERATOR_IN:
return PictOpIn;
case CAIRO_OPERATOR_OUT:
return PictOpOut;
case CAIRO_OPERATOR_ATOP:
return PictOpAtop;
case CAIRO_OPERATOR_DEST:
return PictOpDst;
case CAIRO_OPERATOR_DEST_OVER:
return PictOpOverReverse;
case CAIRO_OPERATOR_DEST_IN:
return PictOpInReverse;
case CAIRO_OPERATOR_DEST_OUT:
return PictOpOutReverse;
case CAIRO_OPERATOR_DEST_ATOP:
return PictOpAtopReverse;
case CAIRO_OPERATOR_XOR:
return PictOpXor;
case CAIRO_OPERATOR_ADD:
return PictOpAdd;
case CAIRO_OPERATOR_SATURATE:
return PictOpSaturate;
case CAIRO_OPERATOR_MULTIPLY:
return PictOpMultiply;
case CAIRO_OPERATOR_SCREEN:
return PictOpScreen;
case CAIRO_OPERATOR_OVERLAY:
return PictOpOverlay;
case CAIRO_OPERATOR_DARKEN:
return PictOpDarken;
case CAIRO_OPERATOR_LIGHTEN:
return PictOpLighten;
case CAIRO_OPERATOR_COLOR_DODGE:
return PictOpColorDodge;
case CAIRO_OPERATOR_COLOR_BURN:
return PictOpColorBurn;
case CAIRO_OPERATOR_HARD_LIGHT:
return PictOpHardLight;
case CAIRO_OPERATOR_SOFT_LIGHT:
return PictOpSoftLight;
case CAIRO_OPERATOR_DIFFERENCE:
return PictOpDifference;
case CAIRO_OPERATOR_EXCLUSION:
return PictOpExclusion;
case CAIRO_OPERATOR_HSL_HUE:
return PictOpHSLHue;
case CAIRO_OPERATOR_HSL_SATURATION:
return PictOpHSLSaturation;
case CAIRO_OPERATOR_HSL_COLOR:
return PictOpHSLColor;
case CAIRO_OPERATOR_HSL_LUMINOSITY:
return PictOpHSLLuminosity;
default:
ASSERT_NOT_REACHED;
return PictOpOver;
}
}
static cairo_bool_t
fill_reduces_to_source (cairo_operator_t op,
const cairo_color_t *color,
cairo_xlib_surface_t *dst)
{
if (dst->base.is_clear || CAIRO_COLOR_IS_OPAQUE (color)) {
if (op == CAIRO_OPERATOR_OVER)
return TRUE;
if (op == CAIRO_OPERATOR_ADD)
return (dst->base.content & CAIRO_CONTENT_COLOR) == 0;
}
return FALSE;
}
static cairo_int_status_t
fill_rectangles (void *abstract_surface,
cairo_operator_t op,
const cairo_color_t *color,
cairo_rectangle_int_t *rects,
int num_rects)
{
cairo_xlib_surface_t *dst = abstract_surface;
XRenderColor render_color;
int i;
//X_DEBUG ((display->display, "fill_rectangles (dst=%x)", (unsigned int) surface->drawable));
render_color.red = color->red_short;
render_color.green = color->green_short;
render_color.blue = color->blue_short;
render_color.alpha = color->alpha_short;
if (fill_reduces_to_source (op, color, dst))
op = CAIRO_OPERATOR_SOURCE;
_cairo_xlib_surface_ensure_picture (dst);
if (num_rects == 1) {
/* Take advantage of the protocol compaction that libXrender performs
* to amalgamate sequences of XRenderFillRectangle().
*/
XRenderFillRectangle (dst->dpy,
_render_operator (op),
dst->picture,
&render_color,
rects->x, rects->y,
rects->width, rects->height);
} else {
XRectangle stack_xrects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)];
XRectangle *xrects = stack_xrects;
if (num_rects > ARRAY_LENGTH (stack_xrects)) {
xrects = _cairo_malloc_ab (num_rects, sizeof (XRectangle));
if (unlikely (xrects == NULL))
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
for (i = 0; i < num_rects; i++) {
xrects[i].x = rects[i].x;
xrects[i].y = rects[i].y;
xrects[i].width = rects[i].width;
xrects[i].height = rects[i].height;
}
XRenderFillRectangles (dst->dpy,
_render_operator (op),
dst->picture,
&render_color, xrects, num_rects);
if (xrects != stack_xrects)
free (xrects);
}
return CAIRO_STATUS_SUCCESS;
}
static cairo_int_status_t
fill_boxes (void *abstract_surface,
cairo_operator_t op,
const cairo_color_t *color,
cairo_boxes_t *boxes)
{
cairo_xlib_surface_t *dst = abstract_surface;
XRenderColor render_color;
render_color.red = color->red_short;
render_color.green = color->green_short;
render_color.blue = color->blue_short;
render_color.alpha = color->alpha_short;
if (fill_reduces_to_source (op, color, dst))
op = CAIRO_OPERATOR_SOURCE;
_cairo_xlib_surface_ensure_picture (dst);
if (boxes->num_boxes == 1) {
int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x);
int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y);
int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x);
int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y);
/* Take advantage of the protocol compaction that libXrender performs
* to amalgamate sequences of XRenderFillRectangle().
*/
XRenderFillRectangle (dst->dpy,
_render_operator (op),
dst->picture,
&render_color,
x1, y1,
x2 - x1, y2 - y1);
} else {
XRectangle stack_xrects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)];
XRectangle *xrects = stack_xrects;
struct _cairo_boxes_chunk *chunk;
int i, j;
if (boxes->num_boxes > ARRAY_LENGTH (stack_xrects)) {
xrects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle));
if (unlikely (xrects == NULL))
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
j = 0;
for (chunk = &boxes->chunks; chunk; chunk = chunk->next) {
for (i = 0; i < chunk->count; i++) {
int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x);
int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y);
int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x);
int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y);
xrects[j].x = x1;
xrects[j].y = y1;
xrects[j].width = x2 - x1;
xrects[j].height = y2 - y1;
j++;
}
}
XRenderFillRectangles (dst->dpy,
_render_operator (op),
dst->picture,
&render_color, xrects, j);
if (xrects != stack_xrects)
free (xrects);
}
return CAIRO_STATUS_SUCCESS;
}
#if 0
check_composite ()
operation = _categorize_composite_operation (dst, op, src_pattern,
mask_pattern != NULL);
if (operation == DO_UNSUPPORTED)
return UNSUPPORTED ("unsupported operation");
//X_DEBUG ((display->display, "composite (dst=%x)", (unsigned int) dst->drawable));
operation = _recategorize_composite_operation (dst, op, src, &src_attr,
mask_pattern != NULL);
if (operation == DO_UNSUPPORTED) {
status = UNSUPPORTED ("unsupported operation");
goto BAIL;
}
#endif
static cairo_int_status_t
composite (void *abstract_dst,
cairo_operator_t op,
cairo_surface_t *abstract_src,
cairo_surface_t *abstract_mask,
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_xlib_surface_t *dst = abstract_dst;
cairo_xlib_source_t *src = (cairo_xlib_source_t *)abstract_src;
op = _render_operator (op);
_cairo_xlib_surface_ensure_picture (dst);
if (abstract_mask) {
cairo_xlib_source_t *mask = (cairo_xlib_source_t *)abstract_mask;
XRenderComposite (dst->dpy, op,
src->picture, mask->picture, dst->picture,
src_x, src_y,
mask_x, mask_y,
dst_x, dst_y,
width, height);
} else {
XRenderComposite (dst->dpy, op,
src->picture, 0, dst->picture,
src_x, src_y,
0, 0,
dst_x, dst_y,
width, height);
}
return CAIRO_STATUS_SUCCESS;
}
static cairo_int_status_t
lerp (void *abstract_dst,
cairo_surface_t *abstract_src,
cairo_surface_t *abstract_mask,
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_xlib_surface_t *dst = abstract_dst;
cairo_xlib_source_t *src = (cairo_xlib_source_t *)abstract_src;
cairo_xlib_source_t *mask = (cairo_xlib_source_t *)abstract_mask;
_cairo_xlib_surface_ensure_picture (dst);
XRenderComposite (dst->dpy, PictOpOutReverse,
mask->picture, None, dst->picture,
mask_x, mask_y,
0, 0,
dst_x, dst_y,
width, height);
XRenderComposite (dst->dpy, PictOpAdd,
src->picture, mask->picture, dst->picture,
src_x, src_y,
mask_x, mask_y,
dst_x, dst_y,
width, height);
return CAIRO_STATUS_SUCCESS;
}
static cairo_int_status_t
composite_boxes (void *abstract_dst,
cairo_operator_t op,
cairo_surface_t *abstract_src,
cairo_surface_t *abstract_mask,
int src_x,
int src_y,
int mask_x,
int mask_y,
int dst_x,
int dst_y,
cairo_boxes_t *boxes,
const cairo_rectangle_int_t *extents)
{
cairo_xlib_surface_t *dst = abstract_dst;
Picture src = ((cairo_xlib_source_t *)abstract_src)->picture;
Picture mask = abstract_mask ? ((cairo_xlib_source_t *)abstract_mask)->picture : 0;
XRectangle stack_rects[CAIRO_STACK_ARRAY_LENGTH (XRectangle)];
XRectangle *rects = stack_rects;
struct _cairo_boxes_chunk *chunk;
int i, j;
op = _render_operator (op);
_cairo_xlib_surface_ensure_picture (dst);
if (boxes->num_boxes == 1) {
int x1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.x);
int y1 = _cairo_fixed_integer_part (boxes->chunks.base[0].p1.y);
int x2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.x);
int y2 = _cairo_fixed_integer_part (boxes->chunks.base[0].p2.y);
XRenderComposite (dst->dpy, op,
src, mask, dst->picture,
x1 + src_x, y1 + src_y,
x1 + mask_x, y1 + mask_y,
x1 - dst_x, y1 - dst_y,
x2 - x1, y2 - y1);
return CAIRO_STATUS_SUCCESS;
}
if (boxes->num_boxes > ARRAY_LENGTH (stack_rects)) {
rects = _cairo_malloc_ab (boxes->num_boxes, sizeof (XRectangle));
if (unlikely (rects == NULL))
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
j = 0;
for (chunk = &boxes->chunks; chunk; chunk = chunk->next) {
for (i = 0; i < chunk->count; i++) {
int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x);
int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y);
int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x);
int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y);
rects[j].x = x1 - dst_x;
rects[j].y = y1 - dst_y;
rects[j].width = x2 - x1;
rects[j].height = y2 - y1;
j++;
}
}
assert (j == boxes->num_boxes);
XRenderSetPictureClipRectangles (dst->dpy,
dst->picture,
0, 0,
rects, j);
if (rects != stack_rects)
free (rects);
XRenderComposite (dst->dpy, op,
src, mask, dst->picture,
extents->x + src_x, extents->y + src_y,
extents->x + mask_x, extents->y + mask_y,
extents->x - dst_x, extents->y - dst_y,
extents->width, extents->height);
set_clip_region (dst, NULL);
return CAIRO_STATUS_SUCCESS;
}
/* font rendering */
void
_cairo_xlib_font_close (cairo_xlib_font_t *priv)
{
cairo_xlib_display_t *display = (cairo_xlib_display_t *)priv->base.key;
int i;
/* XXX All I really want is to do is zap my glyphs... */
_cairo_scaled_font_reset_cache (priv->font);
for (i = 0; i < NUM_GLYPHSETS; i++) {
cairo_xlib_font_glyphset_t *info;
info = &priv->glyphset[i];
if (info->glyphset)
XRenderFreeGlyphSet (display->display, info->glyphset);
}
/* XXX locking */
cairo_list_del (&priv->link);
cairo_list_del (&priv->base.link);
free (priv);
}
static void
_cairo_xlib_font_fini (cairo_scaled_font_private_t *abstract_private,
cairo_scaled_font_t *font)
{
cairo_xlib_font_t *priv = (cairo_xlib_font_t *) abstract_private;
cairo_status_t status;
cairo_xlib_display_t *display;
int i;
cairo_list_del (&priv->base.link);
cairo_list_del (&priv->link);
status = _cairo_xlib_display_acquire (priv->device, &display);
if (status)
goto BAIL;
for (i = 0; i < NUM_GLYPHSETS; i++) {
cairo_xlib_font_glyphset_t *info;
info = &priv->glyphset[i];
if (info->glyphset)
XRenderFreeGlyphSet (display->display, info->glyphset);
}
cairo_device_release (&display->base);
BAIL:
cairo_device_destroy (&display->base);
free (priv);
}
static cairo_xlib_font_t *
_cairo_xlib_font_create (cairo_xlib_display_t *display,
cairo_scaled_font_t *font)
{
cairo_xlib_font_t *priv;
int i;
priv = malloc (sizeof (cairo_xlib_font_t));
if (unlikely (priv == NULL))
return NULL;
_cairo_scaled_font_attach_private (font, &priv->base, display,
_cairo_xlib_font_fini);
priv->device = cairo_device_reference (&display->base);
priv->font = font;
cairo_list_add (&priv->link, &display->fonts);
for (i = 0; i < NUM_GLYPHSETS; i++) {
cairo_xlib_font_glyphset_t *info = &priv->glyphset[i];
switch (i) {
case GLYPHSET_INDEX_ARGB32: info->format = CAIRO_FORMAT_ARGB32; break;
case GLYPHSET_INDEX_A8: info->format = CAIRO_FORMAT_A8; break;
case GLYPHSET_INDEX_A1: info->format = CAIRO_FORMAT_A1; break;
default: ASSERT_NOT_REACHED; break;
}
info->xrender_format = NULL;
info->glyphset = None;
info->to_free.count = 0;
}
return priv;
}
static int
_cairo_xlib_get_glyphset_index_for_format (cairo_format_t format)
{
if (format == CAIRO_FORMAT_A8)
return GLYPHSET_INDEX_A8;
if (format == CAIRO_FORMAT_A1)
return GLYPHSET_INDEX_A1;
assert (format == CAIRO_FORMAT_ARGB32);
return GLYPHSET_INDEX_ARGB32;
}
static inline cairo_xlib_font_t *
_cairo_xlib_font_get (const cairo_xlib_display_t *display,
cairo_scaled_font_t *font)
{
return (cairo_xlib_font_t *)_cairo_scaled_font_find_private (font, display);
}