/
render.rs
5182 lines (5074 loc) · 190 KB
/
render.rs
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
// This file contains generated code. Do not edit directly.
// To regenerate this, run 'make'.
//! Bindings to the `Render` X11 extension.
#![allow(clippy::too_many_arguments)]
// The code generator is simpler if it can always use conversions
#![allow(clippy::useless_conversion)]
#[allow(unused_imports)]
use alloc::borrow::Cow;
#[allow(unused_imports)]
use core::convert::TryInto;
use alloc::vec;
use alloc::vec::Vec;
use core::convert::TryFrom;
use crate::errors::ParseError;
#[allow(unused_imports)]
use crate::x11_utils::TryIntoUSize;
use crate::{BufWithFds, PiecewiseBuf};
#[allow(unused_imports)]
use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum};
#[allow(unused_imports)]
use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd};
#[allow(unused_imports)]
use super::xproto;
/// The X11 name of the extension for QueryExtension
pub const X11_EXTENSION_NAME: &str = "RENDER";
/// The version number of this extension that this client library supports.
///
/// This constant contains the version number of this extension that is supported
/// by this build of x11rb. For most things, it does not make sense to use this
/// information. If you need to send a `QueryVersion`, it is recommended to instead
/// send the maximum version of the extension that you need.
pub const X11_XML_VERSION: (u32, u32) = (0, 11);
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PictType(u8);
impl PictType {
pub const INDEXED: Self = Self(0);
pub const DIRECT: Self = Self(1);
}
impl From<PictType> for u8 {
#[inline]
fn from(input: PictType) -> Self {
input.0
}
}
impl From<PictType> for Option<u8> {
#[inline]
fn from(input: PictType) -> Self {
Some(input.0)
}
}
impl From<PictType> for u16 {
#[inline]
fn from(input: PictType) -> Self {
u16::from(input.0)
}
}
impl From<PictType> for Option<u16> {
#[inline]
fn from(input: PictType) -> Self {
Some(u16::from(input.0))
}
}
impl From<PictType> for u32 {
#[inline]
fn from(input: PictType) -> Self {
u32::from(input.0)
}
}
impl From<PictType> for Option<u32> {
#[inline]
fn from(input: PictType) -> Self {
Some(u32::from(input.0))
}
}
impl From<u8> for PictType {
#[inline]
fn from(value: u8) -> Self {
Self(value)
}
}
impl core::fmt::Debug for PictType {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let variants = [
(Self::INDEXED.0.into(), "INDEXED", "Indexed"),
(Self::DIRECT.0.into(), "DIRECT", "Direct"),
];
pretty_print_enum(fmt, self.0.into(), &variants)
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PictureEnum(u8);
impl PictureEnum {
pub const NONE: Self = Self(0);
}
impl From<PictureEnum> for u8 {
#[inline]
fn from(input: PictureEnum) -> Self {
input.0
}
}
impl From<PictureEnum> for Option<u8> {
#[inline]
fn from(input: PictureEnum) -> Self {
Some(input.0)
}
}
impl From<PictureEnum> for u16 {
#[inline]
fn from(input: PictureEnum) -> Self {
u16::from(input.0)
}
}
impl From<PictureEnum> for Option<u16> {
#[inline]
fn from(input: PictureEnum) -> Self {
Some(u16::from(input.0))
}
}
impl From<PictureEnum> for u32 {
#[inline]
fn from(input: PictureEnum) -> Self {
u32::from(input.0)
}
}
impl From<PictureEnum> for Option<u32> {
#[inline]
fn from(input: PictureEnum) -> Self {
Some(u32::from(input.0))
}
}
impl From<u8> for PictureEnum {
#[inline]
fn from(value: u8) -> Self {
Self(value)
}
}
impl core::fmt::Debug for PictureEnum {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let variants = [
(Self::NONE.0.into(), "NONE", "None"),
];
pretty_print_enum(fmt, self.0.into(), &variants)
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PictOp(u8);
impl PictOp {
pub const CLEAR: Self = Self(0);
pub const SRC: Self = Self(1);
pub const DST: Self = Self(2);
pub const OVER: Self = Self(3);
pub const OVER_REVERSE: Self = Self(4);
pub const IN: Self = Self(5);
pub const IN_REVERSE: Self = Self(6);
pub const OUT: Self = Self(7);
pub const OUT_REVERSE: Self = Self(8);
pub const ATOP: Self = Self(9);
pub const ATOP_REVERSE: Self = Self(10);
pub const XOR: Self = Self(11);
pub const ADD: Self = Self(12);
pub const SATURATE: Self = Self(13);
pub const DISJOINT_CLEAR: Self = Self(16);
pub const DISJOINT_SRC: Self = Self(17);
pub const DISJOINT_DST: Self = Self(18);
pub const DISJOINT_OVER: Self = Self(19);
pub const DISJOINT_OVER_REVERSE: Self = Self(20);
pub const DISJOINT_IN: Self = Self(21);
pub const DISJOINT_IN_REVERSE: Self = Self(22);
pub const DISJOINT_OUT: Self = Self(23);
pub const DISJOINT_OUT_REVERSE: Self = Self(24);
pub const DISJOINT_ATOP: Self = Self(25);
pub const DISJOINT_ATOP_REVERSE: Self = Self(26);
pub const DISJOINT_XOR: Self = Self(27);
pub const CONJOINT_CLEAR: Self = Self(32);
pub const CONJOINT_SRC: Self = Self(33);
pub const CONJOINT_DST: Self = Self(34);
pub const CONJOINT_OVER: Self = Self(35);
pub const CONJOINT_OVER_REVERSE: Self = Self(36);
pub const CONJOINT_IN: Self = Self(37);
pub const CONJOINT_IN_REVERSE: Self = Self(38);
pub const CONJOINT_OUT: Self = Self(39);
pub const CONJOINT_OUT_REVERSE: Self = Self(40);
pub const CONJOINT_ATOP: Self = Self(41);
pub const CONJOINT_ATOP_REVERSE: Self = Self(42);
pub const CONJOINT_XOR: Self = Self(43);
pub const MULTIPLY: Self = Self(48);
pub const SCREEN: Self = Self(49);
pub const OVERLAY: Self = Self(50);
pub const DARKEN: Self = Self(51);
pub const LIGHTEN: Self = Self(52);
pub const COLOR_DODGE: Self = Self(53);
pub const COLOR_BURN: Self = Self(54);
pub const HARD_LIGHT: Self = Self(55);
pub const SOFT_LIGHT: Self = Self(56);
pub const DIFFERENCE: Self = Self(57);
pub const EXCLUSION: Self = Self(58);
pub const HSL_HUE: Self = Self(59);
pub const HSL_SATURATION: Self = Self(60);
pub const HSL_COLOR: Self = Self(61);
pub const HSL_LUMINOSITY: Self = Self(62);
}
impl From<PictOp> for u8 {
#[inline]
fn from(input: PictOp) -> Self {
input.0
}
}
impl From<PictOp> for Option<u8> {
#[inline]
fn from(input: PictOp) -> Self {
Some(input.0)
}
}
impl From<PictOp> for u16 {
#[inline]
fn from(input: PictOp) -> Self {
u16::from(input.0)
}
}
impl From<PictOp> for Option<u16> {
#[inline]
fn from(input: PictOp) -> Self {
Some(u16::from(input.0))
}
}
impl From<PictOp> for u32 {
#[inline]
fn from(input: PictOp) -> Self {
u32::from(input.0)
}
}
impl From<PictOp> for Option<u32> {
#[inline]
fn from(input: PictOp) -> Self {
Some(u32::from(input.0))
}
}
impl From<u8> for PictOp {
#[inline]
fn from(value: u8) -> Self {
Self(value)
}
}
impl core::fmt::Debug for PictOp {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let variants = [
(Self::CLEAR.0.into(), "CLEAR", "Clear"),
(Self::SRC.0.into(), "SRC", "Src"),
(Self::DST.0.into(), "DST", "Dst"),
(Self::OVER.0.into(), "OVER", "Over"),
(Self::OVER_REVERSE.0.into(), "OVER_REVERSE", "OverReverse"),
(Self::IN.0.into(), "IN", "In"),
(Self::IN_REVERSE.0.into(), "IN_REVERSE", "InReverse"),
(Self::OUT.0.into(), "OUT", "Out"),
(Self::OUT_REVERSE.0.into(), "OUT_REVERSE", "OutReverse"),
(Self::ATOP.0.into(), "ATOP", "Atop"),
(Self::ATOP_REVERSE.0.into(), "ATOP_REVERSE", "AtopReverse"),
(Self::XOR.0.into(), "XOR", "Xor"),
(Self::ADD.0.into(), "ADD", "Add"),
(Self::SATURATE.0.into(), "SATURATE", "Saturate"),
(Self::DISJOINT_CLEAR.0.into(), "DISJOINT_CLEAR", "DisjointClear"),
(Self::DISJOINT_SRC.0.into(), "DISJOINT_SRC", "DisjointSrc"),
(Self::DISJOINT_DST.0.into(), "DISJOINT_DST", "DisjointDst"),
(Self::DISJOINT_OVER.0.into(), "DISJOINT_OVER", "DisjointOver"),
(Self::DISJOINT_OVER_REVERSE.0.into(), "DISJOINT_OVER_REVERSE", "DisjointOverReverse"),
(Self::DISJOINT_IN.0.into(), "DISJOINT_IN", "DisjointIn"),
(Self::DISJOINT_IN_REVERSE.0.into(), "DISJOINT_IN_REVERSE", "DisjointInReverse"),
(Self::DISJOINT_OUT.0.into(), "DISJOINT_OUT", "DisjointOut"),
(Self::DISJOINT_OUT_REVERSE.0.into(), "DISJOINT_OUT_REVERSE", "DisjointOutReverse"),
(Self::DISJOINT_ATOP.0.into(), "DISJOINT_ATOP", "DisjointAtop"),
(Self::DISJOINT_ATOP_REVERSE.0.into(), "DISJOINT_ATOP_REVERSE", "DisjointAtopReverse"),
(Self::DISJOINT_XOR.0.into(), "DISJOINT_XOR", "DisjointXor"),
(Self::CONJOINT_CLEAR.0.into(), "CONJOINT_CLEAR", "ConjointClear"),
(Self::CONJOINT_SRC.0.into(), "CONJOINT_SRC", "ConjointSrc"),
(Self::CONJOINT_DST.0.into(), "CONJOINT_DST", "ConjointDst"),
(Self::CONJOINT_OVER.0.into(), "CONJOINT_OVER", "ConjointOver"),
(Self::CONJOINT_OVER_REVERSE.0.into(), "CONJOINT_OVER_REVERSE", "ConjointOverReverse"),
(Self::CONJOINT_IN.0.into(), "CONJOINT_IN", "ConjointIn"),
(Self::CONJOINT_IN_REVERSE.0.into(), "CONJOINT_IN_REVERSE", "ConjointInReverse"),
(Self::CONJOINT_OUT.0.into(), "CONJOINT_OUT", "ConjointOut"),
(Self::CONJOINT_OUT_REVERSE.0.into(), "CONJOINT_OUT_REVERSE", "ConjointOutReverse"),
(Self::CONJOINT_ATOP.0.into(), "CONJOINT_ATOP", "ConjointAtop"),
(Self::CONJOINT_ATOP_REVERSE.0.into(), "CONJOINT_ATOP_REVERSE", "ConjointAtopReverse"),
(Self::CONJOINT_XOR.0.into(), "CONJOINT_XOR", "ConjointXor"),
(Self::MULTIPLY.0.into(), "MULTIPLY", "Multiply"),
(Self::SCREEN.0.into(), "SCREEN", "Screen"),
(Self::OVERLAY.0.into(), "OVERLAY", "Overlay"),
(Self::DARKEN.0.into(), "DARKEN", "Darken"),
(Self::LIGHTEN.0.into(), "LIGHTEN", "Lighten"),
(Self::COLOR_DODGE.0.into(), "COLOR_DODGE", "ColorDodge"),
(Self::COLOR_BURN.0.into(), "COLOR_BURN", "ColorBurn"),
(Self::HARD_LIGHT.0.into(), "HARD_LIGHT", "HardLight"),
(Self::SOFT_LIGHT.0.into(), "SOFT_LIGHT", "SoftLight"),
(Self::DIFFERENCE.0.into(), "DIFFERENCE", "Difference"),
(Self::EXCLUSION.0.into(), "EXCLUSION", "Exclusion"),
(Self::HSL_HUE.0.into(), "HSL_HUE", "HSLHue"),
(Self::HSL_SATURATION.0.into(), "HSL_SATURATION", "HSLSaturation"),
(Self::HSL_COLOR.0.into(), "HSL_COLOR", "HSLColor"),
(Self::HSL_LUMINOSITY.0.into(), "HSL_LUMINOSITY", "HSLLuminosity"),
];
pretty_print_enum(fmt, self.0.into(), &variants)
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PolyEdge(u32);
impl PolyEdge {
pub const SHARP: Self = Self(0);
pub const SMOOTH: Self = Self(1);
}
impl From<PolyEdge> for u32 {
#[inline]
fn from(input: PolyEdge) -> Self {
input.0
}
}
impl From<PolyEdge> for Option<u32> {
#[inline]
fn from(input: PolyEdge) -> Self {
Some(input.0)
}
}
impl From<u8> for PolyEdge {
#[inline]
fn from(value: u8) -> Self {
Self(value.into())
}
}
impl From<u16> for PolyEdge {
#[inline]
fn from(value: u16) -> Self {
Self(value.into())
}
}
impl From<u32> for PolyEdge {
#[inline]
fn from(value: u32) -> Self {
Self(value)
}
}
impl core::fmt::Debug for PolyEdge {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let variants = [
(Self::SHARP.0, "SHARP", "Sharp"),
(Self::SMOOTH.0, "SMOOTH", "Smooth"),
];
pretty_print_enum(fmt, self.0, &variants)
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PolyMode(u32);
impl PolyMode {
pub const PRECISE: Self = Self(0);
pub const IMPRECISE: Self = Self(1);
}
impl From<PolyMode> for u32 {
#[inline]
fn from(input: PolyMode) -> Self {
input.0
}
}
impl From<PolyMode> for Option<u32> {
#[inline]
fn from(input: PolyMode) -> Self {
Some(input.0)
}
}
impl From<u8> for PolyMode {
#[inline]
fn from(value: u8) -> Self {
Self(value.into())
}
}
impl From<u16> for PolyMode {
#[inline]
fn from(value: u16) -> Self {
Self(value.into())
}
}
impl From<u32> for PolyMode {
#[inline]
fn from(value: u32) -> Self {
Self(value)
}
}
impl core::fmt::Debug for PolyMode {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let variants = [
(Self::PRECISE.0, "PRECISE", "Precise"),
(Self::IMPRECISE.0, "IMPRECISE", "Imprecise"),
];
pretty_print_enum(fmt, self.0, &variants)
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CP(u32);
impl CP {
pub const REPEAT: Self = Self(1 << 0);
pub const ALPHA_MAP: Self = Self(1 << 1);
pub const ALPHA_X_ORIGIN: Self = Self(1 << 2);
pub const ALPHA_Y_ORIGIN: Self = Self(1 << 3);
pub const CLIP_X_ORIGIN: Self = Self(1 << 4);
pub const CLIP_Y_ORIGIN: Self = Self(1 << 5);
pub const CLIP_MASK: Self = Self(1 << 6);
pub const GRAPHICS_EXPOSURE: Self = Self(1 << 7);
pub const SUBWINDOW_MODE: Self = Self(1 << 8);
pub const POLY_EDGE: Self = Self(1 << 9);
pub const POLY_MODE: Self = Self(1 << 10);
pub const DITHER: Self = Self(1 << 11);
pub const COMPONENT_ALPHA: Self = Self(1 << 12);
}
impl From<CP> for u32 {
#[inline]
fn from(input: CP) -> Self {
input.0
}
}
impl From<CP> for Option<u32> {
#[inline]
fn from(input: CP) -> Self {
Some(input.0)
}
}
impl From<u8> for CP {
#[inline]
fn from(value: u8) -> Self {
Self(value.into())
}
}
impl From<u16> for CP {
#[inline]
fn from(value: u16) -> Self {
Self(value.into())
}
}
impl From<u32> for CP {
#[inline]
fn from(value: u32) -> Self {
Self(value)
}
}
impl core::fmt::Debug for CP {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let variants = [
(Self::REPEAT.0, "REPEAT", "Repeat"),
(Self::ALPHA_MAP.0, "ALPHA_MAP", "AlphaMap"),
(Self::ALPHA_X_ORIGIN.0, "ALPHA_X_ORIGIN", "AlphaXOrigin"),
(Self::ALPHA_Y_ORIGIN.0, "ALPHA_Y_ORIGIN", "AlphaYOrigin"),
(Self::CLIP_X_ORIGIN.0, "CLIP_X_ORIGIN", "ClipXOrigin"),
(Self::CLIP_Y_ORIGIN.0, "CLIP_Y_ORIGIN", "ClipYOrigin"),
(Self::CLIP_MASK.0, "CLIP_MASK", "ClipMask"),
(Self::GRAPHICS_EXPOSURE.0, "GRAPHICS_EXPOSURE", "GraphicsExposure"),
(Self::SUBWINDOW_MODE.0, "SUBWINDOW_MODE", "SubwindowMode"),
(Self::POLY_EDGE.0, "POLY_EDGE", "PolyEdge"),
(Self::POLY_MODE.0, "POLY_MODE", "PolyMode"),
(Self::DITHER.0, "DITHER", "Dither"),
(Self::COMPONENT_ALPHA.0, "COMPONENT_ALPHA", "ComponentAlpha"),
];
pretty_print_bitmask(fmt, self.0, &variants)
}
}
bitmask_binop!(CP, u32);
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SubPixel(u32);
impl SubPixel {
pub const UNKNOWN: Self = Self(0);
pub const HORIZONTAL_RGB: Self = Self(1);
pub const HORIZONTAL_BGR: Self = Self(2);
pub const VERTICAL_RGB: Self = Self(3);
pub const VERTICAL_BGR: Self = Self(4);
pub const NONE: Self = Self(5);
}
impl From<SubPixel> for u32 {
#[inline]
fn from(input: SubPixel) -> Self {
input.0
}
}
impl From<SubPixel> for Option<u32> {
#[inline]
fn from(input: SubPixel) -> Self {
Some(input.0)
}
}
impl From<u8> for SubPixel {
#[inline]
fn from(value: u8) -> Self {
Self(value.into())
}
}
impl From<u16> for SubPixel {
#[inline]
fn from(value: u16) -> Self {
Self(value.into())
}
}
impl From<u32> for SubPixel {
#[inline]
fn from(value: u32) -> Self {
Self(value)
}
}
impl core::fmt::Debug for SubPixel {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let variants = [
(Self::UNKNOWN.0, "UNKNOWN", "Unknown"),
(Self::HORIZONTAL_RGB.0, "HORIZONTAL_RGB", "HorizontalRGB"),
(Self::HORIZONTAL_BGR.0, "HORIZONTAL_BGR", "HorizontalBGR"),
(Self::VERTICAL_RGB.0, "VERTICAL_RGB", "VerticalRGB"),
(Self::VERTICAL_BGR.0, "VERTICAL_BGR", "VerticalBGR"),
(Self::NONE.0, "NONE", "None"),
];
pretty_print_enum(fmt, self.0, &variants)
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Repeat(u32);
impl Repeat {
pub const NONE: Self = Self(0);
pub const NORMAL: Self = Self(1);
pub const PAD: Self = Self(2);
pub const REFLECT: Self = Self(3);
}
impl From<Repeat> for u32 {
#[inline]
fn from(input: Repeat) -> Self {
input.0
}
}
impl From<Repeat> for Option<u32> {
#[inline]
fn from(input: Repeat) -> Self {
Some(input.0)
}
}
impl From<u8> for Repeat {
#[inline]
fn from(value: u8) -> Self {
Self(value.into())
}
}
impl From<u16> for Repeat {
#[inline]
fn from(value: u16) -> Self {
Self(value.into())
}
}
impl From<u32> for Repeat {
#[inline]
fn from(value: u32) -> Self {
Self(value)
}
}
impl core::fmt::Debug for Repeat {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let variants = [
(Self::NONE.0, "NONE", "None"),
(Self::NORMAL.0, "NORMAL", "Normal"),
(Self::PAD.0, "PAD", "Pad"),
(Self::REFLECT.0, "REFLECT", "Reflect"),
];
pretty_print_enum(fmt, self.0, &variants)
}
}
pub type Glyph = u32;
pub type Glyphset = u32;
pub type Picture = u32;
pub type Pictformat = u32;
pub type Fixed = i32;
/// Opcode for the PictFormat error
pub const PICT_FORMAT_ERROR: u8 = 0;
/// Opcode for the Picture error
pub const PICTURE_ERROR: u8 = 1;
/// Opcode for the PictOp error
pub const PICT_OP_ERROR: u8 = 2;
/// Opcode for the GlyphSet error
pub const GLYPH_SET_ERROR: u8 = 3;
/// Opcode for the Glyph error
pub const GLYPH_ERROR: u8 = 4;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Directformat {
pub red_shift: u16,
pub red_mask: u16,
pub green_shift: u16,
pub green_mask: u16,
pub blue_shift: u16,
pub blue_mask: u16,
pub alpha_shift: u16,
pub alpha_mask: u16,
}
impl TryParse for Directformat {
fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
let (red_shift, remaining) = u16::try_parse(remaining)?;
let (red_mask, remaining) = u16::try_parse(remaining)?;
let (green_shift, remaining) = u16::try_parse(remaining)?;
let (green_mask, remaining) = u16::try_parse(remaining)?;
let (blue_shift, remaining) = u16::try_parse(remaining)?;
let (blue_mask, remaining) = u16::try_parse(remaining)?;
let (alpha_shift, remaining) = u16::try_parse(remaining)?;
let (alpha_mask, remaining) = u16::try_parse(remaining)?;
let result = Directformat { red_shift, red_mask, green_shift, green_mask, blue_shift, blue_mask, alpha_shift, alpha_mask };
Ok((result, remaining))
}
}
impl Serialize for Directformat {
type Bytes = [u8; 16];
fn serialize(&self) -> [u8; 16] {
let red_shift_bytes = self.red_shift.serialize();
let red_mask_bytes = self.red_mask.serialize();
let green_shift_bytes = self.green_shift.serialize();
let green_mask_bytes = self.green_mask.serialize();
let blue_shift_bytes = self.blue_shift.serialize();
let blue_mask_bytes = self.blue_mask.serialize();
let alpha_shift_bytes = self.alpha_shift.serialize();
let alpha_mask_bytes = self.alpha_mask.serialize();
[
red_shift_bytes[0],
red_shift_bytes[1],
red_mask_bytes[0],
red_mask_bytes[1],
green_shift_bytes[0],
green_shift_bytes[1],
green_mask_bytes[0],
green_mask_bytes[1],
blue_shift_bytes[0],
blue_shift_bytes[1],
blue_mask_bytes[0],
blue_mask_bytes[1],
alpha_shift_bytes[0],
alpha_shift_bytes[1],
alpha_mask_bytes[0],
alpha_mask_bytes[1],
]
}
fn serialize_into(&self, bytes: &mut Vec<u8>) {
bytes.reserve(16);
self.red_shift.serialize_into(bytes);
self.red_mask.serialize_into(bytes);
self.green_shift.serialize_into(bytes);
self.green_mask.serialize_into(bytes);
self.blue_shift.serialize_into(bytes);
self.blue_mask.serialize_into(bytes);
self.alpha_shift.serialize_into(bytes);
self.alpha_mask.serialize_into(bytes);
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Pictforminfo {
pub id: Pictformat,
pub type_: PictType,
pub depth: u8,
pub direct: Directformat,
pub colormap: xproto::Colormap,
}
impl TryParse for Pictforminfo {
fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
let (id, remaining) = Pictformat::try_parse(remaining)?;
let (type_, remaining) = u8::try_parse(remaining)?;
let (depth, remaining) = u8::try_parse(remaining)?;
let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
let (direct, remaining) = Directformat::try_parse(remaining)?;
let (colormap, remaining) = xproto::Colormap::try_parse(remaining)?;
let type_ = type_.into();
let result = Pictforminfo { id, type_, depth, direct, colormap };
Ok((result, remaining))
}
}
impl Serialize for Pictforminfo {
type Bytes = [u8; 28];
fn serialize(&self) -> [u8; 28] {
let id_bytes = self.id.serialize();
let type_bytes = u8::from(self.type_).serialize();
let depth_bytes = self.depth.serialize();
let direct_bytes = self.direct.serialize();
let colormap_bytes = self.colormap.serialize();
[
id_bytes[0],
id_bytes[1],
id_bytes[2],
id_bytes[3],
type_bytes[0],
depth_bytes[0],
0,
0,
direct_bytes[0],
direct_bytes[1],
direct_bytes[2],
direct_bytes[3],
direct_bytes[4],
direct_bytes[5],
direct_bytes[6],
direct_bytes[7],
direct_bytes[8],
direct_bytes[9],
direct_bytes[10],
direct_bytes[11],
direct_bytes[12],
direct_bytes[13],
direct_bytes[14],
direct_bytes[15],
colormap_bytes[0],
colormap_bytes[1],
colormap_bytes[2],
colormap_bytes[3],
]
}
fn serialize_into(&self, bytes: &mut Vec<u8>) {
bytes.reserve(28);
self.id.serialize_into(bytes);
u8::from(self.type_).serialize_into(bytes);
self.depth.serialize_into(bytes);
bytes.extend_from_slice(&[0; 2]);
self.direct.serialize_into(bytes);
self.colormap.serialize_into(bytes);
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Pictvisual {
pub visual: xproto::Visualid,
pub format: Pictformat,
}
impl TryParse for Pictvisual {
fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
let (visual, remaining) = xproto::Visualid::try_parse(remaining)?;
let (format, remaining) = Pictformat::try_parse(remaining)?;
let result = Pictvisual { visual, format };
Ok((result, remaining))
}
}
impl Serialize for Pictvisual {
type Bytes = [u8; 8];
fn serialize(&self) -> [u8; 8] {
let visual_bytes = self.visual.serialize();
let format_bytes = self.format.serialize();
[
visual_bytes[0],
visual_bytes[1],
visual_bytes[2],
visual_bytes[3],
format_bytes[0],
format_bytes[1],
format_bytes[2],
format_bytes[3],
]
}
fn serialize_into(&self, bytes: &mut Vec<u8>) {
bytes.reserve(8);
self.visual.serialize_into(bytes);
self.format.serialize_into(bytes);
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Pictdepth {
pub depth: u8,
pub visuals: Vec<Pictvisual>,
}
impl TryParse for Pictdepth {
fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
let (depth, remaining) = u8::try_parse(remaining)?;
let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
let (num_visuals, remaining) = u16::try_parse(remaining)?;
let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
let (visuals, remaining) = crate::x11_utils::parse_list::<Pictvisual>(remaining, num_visuals.try_to_usize()?)?;
let result = Pictdepth { depth, visuals };
Ok((result, remaining))
}
}
impl Serialize for Pictdepth {
type Bytes = Vec<u8>;
fn serialize(&self) -> Vec<u8> {
let mut result = Vec::new();
self.serialize_into(&mut result);
result
}
fn serialize_into(&self, bytes: &mut Vec<u8>) {
bytes.reserve(8);
self.depth.serialize_into(bytes);
bytes.extend_from_slice(&[0; 1]);
let num_visuals = u16::try_from(self.visuals.len()).expect("`visuals` has too many elements");
num_visuals.serialize_into(bytes);
bytes.extend_from_slice(&[0; 4]);
self.visuals.serialize_into(bytes);
}
}
impl Pictdepth {
/// Get the value of the `num_visuals` field.
///
/// The `num_visuals` field is used as the length field of the `visuals` field.
/// This function computes the field's value again based on the length of the list.
///
/// # Panics
///
/// Panics if the value cannot be represented in the target type. This
/// cannot happen with values of the struct received from the X11 server.
pub fn num_visuals(&self) -> u16 {
self.visuals.len()
.try_into().unwrap()
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Pictscreen {
pub fallback: Pictformat,
pub depths: Vec<Pictdepth>,
}
impl TryParse for Pictscreen {
fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
let (num_depths, remaining) = u32::try_parse(remaining)?;
let (fallback, remaining) = Pictformat::try_parse(remaining)?;
let (depths, remaining) = crate::x11_utils::parse_list::<Pictdepth>(remaining, num_depths.try_to_usize()?)?;
let result = Pictscreen { fallback, depths };
Ok((result, remaining))
}
}
impl Serialize for Pictscreen {
type Bytes = Vec<u8>;
fn serialize(&self) -> Vec<u8> {
let mut result = Vec::new();
self.serialize_into(&mut result);
result
}
fn serialize_into(&self, bytes: &mut Vec<u8>) {
bytes.reserve(8);
let num_depths = u32::try_from(self.depths.len()).expect("`depths` has too many elements");
num_depths.serialize_into(bytes);
self.fallback.serialize_into(bytes);
self.depths.serialize_into(bytes);
}
}
impl Pictscreen {
/// Get the value of the `num_depths` field.
///
/// The `num_depths` field is used as the length field of the `depths` field.
/// This function computes the field's value again based on the length of the list.
///
/// # Panics
///
/// Panics if the value cannot be represented in the target type. This
/// cannot happen with values of the struct received from the X11 server.
pub fn num_depths(&self) -> u32 {
self.depths.len()
.try_into().unwrap()
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Indexvalue {
pub pixel: u32,
pub red: u16,
pub green: u16,
pub blue: u16,
pub alpha: u16,
}
impl TryParse for Indexvalue {
fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
let (pixel, remaining) = u32::try_parse(remaining)?;
let (red, remaining) = u16::try_parse(remaining)?;
let (green, remaining) = u16::try_parse(remaining)?;
let (blue, remaining) = u16::try_parse(remaining)?;
let (alpha, remaining) = u16::try_parse(remaining)?;
let result = Indexvalue { pixel, red, green, blue, alpha };
Ok((result, remaining))
}
}
impl Serialize for Indexvalue {
type Bytes = [u8; 12];
fn serialize(&self) -> [u8; 12] {
let pixel_bytes = self.pixel.serialize();
let red_bytes = self.red.serialize();
let green_bytes = self.green.serialize();
let blue_bytes = self.blue.serialize();
let alpha_bytes = self.alpha.serialize();
[
pixel_bytes[0],
pixel_bytes[1],
pixel_bytes[2],
pixel_bytes[3],
red_bytes[0],
red_bytes[1],
green_bytes[0],
green_bytes[1],
blue_bytes[0],
blue_bytes[1],
alpha_bytes[0],
alpha_bytes[1],
]
}
fn serialize_into(&self, bytes: &mut Vec<u8>) {
bytes.reserve(12);
self.pixel.serialize_into(bytes);
self.red.serialize_into(bytes);
self.green.serialize_into(bytes);
self.blue.serialize_into(bytes);
self.alpha.serialize_into(bytes);
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Color {
pub red: u16,
pub green: u16,
pub blue: u16,
pub alpha: u16,
}
impl TryParse for Color {
fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
let (red, remaining) = u16::try_parse(remaining)?;
let (green, remaining) = u16::try_parse(remaining)?;
let (blue, remaining) = u16::try_parse(remaining)?;
let (alpha, remaining) = u16::try_parse(remaining)?;
let result = Color { red, green, blue, alpha };
Ok((result, remaining))
}
}
impl Serialize for Color {
type Bytes = [u8; 8];
fn serialize(&self) -> [u8; 8] {
let red_bytes = self.red.serialize();
let green_bytes = self.green.serialize();
let blue_bytes = self.blue.serialize();
let alpha_bytes = self.alpha.serialize();
[
red_bytes[0],
red_bytes[1],
green_bytes[0],
green_bytes[1],
blue_bytes[0],
blue_bytes[1],
alpha_bytes[0],
alpha_bytes[1],
]
}
fn serialize_into(&self, bytes: &mut Vec<u8>) {
bytes.reserve(8);
self.red.serialize_into(bytes);
self.green.serialize_into(bytes);
self.blue.serialize_into(bytes);
self.alpha.serialize_into(bytes);
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Pointfix {
pub x: Fixed,
pub y: Fixed,
}
impl TryParse for Pointfix {
fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
let (x, remaining) = Fixed::try_parse(remaining)?;
let (y, remaining) = Fixed::try_parse(remaining)?;
let result = Pointfix { x, y };
Ok((result, remaining))
}
}
impl Serialize for Pointfix {
type Bytes = [u8; 8];
fn serialize(&self) -> [u8; 8] {
let x_bytes = self.x.serialize();