fidl_fuchsia_images2/
fidl_fuchsia_images2.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
// WARNING: This file is machine generated by fidlgen.

#![warn(clippy::all)]
#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]

use bitflags::bitflags;
use fidl::client::QueryResponseFut;
use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
use fidl::endpoints::{ControlHandle as _, Responder as _};
use futures::future::{self, MaybeDone, TryFutureExt};
use zx_status;

pub const FORMAT_MODIFIER_ARM_BCH_BIT: u64 = 2048;

pub const FORMAT_MODIFIER_ARM_SPARSE_BIT: u64 = 64;

pub const FORMAT_MODIFIER_ARM_SPLIT_BLOCK_BIT: u64 = 32;

pub const FORMAT_MODIFIER_ARM_TE_BIT: u64 = 4096;

pub const FORMAT_MODIFIER_ARM_TILED_HEADER_BIT: u64 = 8192;

pub const FORMAT_MODIFIER_ARM_YUV_BIT: u64 = 16;

/// Format has a color control surface after the tile data
pub const FORMAT_MODIFIER_INTEL_CCS_BIT: u64 = 16777216;

pub const FORMAT_MODIFIER_VENDOR_ALLWINNER: u64 = 648518346341351424;

pub const FORMAT_MODIFIER_VENDOR_AMD: u64 = 144115188075855872;

pub const FORMAT_MODIFIER_VENDOR_AMLOGIC: u64 = 720575940379279360;

pub const FORMAT_MODIFIER_VENDOR_ARM: u64 = 576460752303423488;

pub const FORMAT_MODIFIER_VENDOR_BROADCOM: u64 = 504403158265495552;

pub const FORMAT_MODIFIER_VENDOR_GOOGLE: u64 = 7421932185906577408;

pub const FORMAT_MODIFIER_VENDOR_INTEL: u64 = 72057594037927936;

pub const FORMAT_MODIFIER_VENDOR_NVIDIA: u64 = 216172782113783808;

pub const FORMAT_MODIFIER_VENDOR_QCOM: u64 = 360287970189639680;

pub const FORMAT_MODIFIER_VENDOR_SAMSUNG: u64 = 288230376151711744;

pub const FORMAT_MODIFIER_VENDOR_VIVANTE: u64 = 432345564227567616;

/// Expresses the color space used to interpret video pixel values.
///
/// This list has a separate entry for each variant of a color space standard.
///
/// For this reason, should we ever add support for the RGB variant of 709, for
/// example, we'd add a separate entry to this list for that variant.  Similarly
/// for the RGB variants of 2020 or 2100.  Similarly for the YcCbcCrc variant of
/// 2020.  Similarly for the ICtCp variant of 2100.
///
/// See ImageFormatIsSupportedColorSpaceForPixelFormat() for whether a
/// combination of `PixelFormat` and `ColorSpace` is potentially supported.
///
/// Generally, a `ColorSpace` is not supported for any `PixelFormat` whose
/// bits-per-sample isn't compatible with the color space's spec, nor for any
/// `PixelFormat` which is a mismatch in terms of RGB vs. YUV.
///
/// The "limited range" in comments below refers to where black and white are
/// defined to be (and simimlar for chroma), but should not be interpreted as
/// guaranteeing that there won't be values outside the nominal "limited range".
/// In other words, "limited range" doesn't necessarily mean there won't be any
/// values below black or above white, or outside the "limited" chroma range.
/// For "full range", black is 0 and white is the max possible/permitted numeric
/// value (and similar for chroma).
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum ColorSpace {
    /// Not a valid color space type.
    Invalid,
    /// sRGB, gamma transfer function and full range, per spec
    Srgb,
    /// 601 NTSC ("525 line") YCbCr primaries, limited range
    Rec601Ntsc,
    /// 601 NTSC ("525 line") YCbCr primaries, full range
    Rec601NtscFullRange,
    /// 601 PAL ("625 line") YCbCr primaries, limited range
    Rec601Pal,
    /// 601 PAL ("625 line") YCbCr primaries, full range
    Rec601PalFullRange,
    /// 709 YCbCr (not RGB), limited range
    Rec709,
    /// 2020 YCbCr (not RGB, not YcCbcCrc), 10 or 12 bit according to
    /// `PixelFormat`, with primaries, limited range (not full range), transfer
    /// function ("gamma"), etc all per spec, wide color gamut SDR
    Rec2020,
    /// 2100 YCbCr (not RGB, not ICtCp), 10 or 12 bit according to
    /// `PixelFormat`, BT.2020 primaries (same wide color gamut as REC2020),
    /// limited range (not full range), PQ (aka SMPTE ST 2084) HDR transfer
    /// function (not HLG, not SDR "gamma" used by REC2020 and REC709), wide
    /// color gamut HDR
    Rec2100,
    /// Either the pixel format doesn't represent a color, or it's in an
    /// application-specific colorspace that isn't describable by another entry
    /// in this enum.
    Passthrough,
    /// A client is explicitly indicating that the client does not care which
    /// color space is chosen / used.
    DoNotCare,
    #[doc(hidden)]
    __SourceBreaking { unknown_ordinal: u32 },
}

/// Pattern that matches an unknown `ColorSpace` member.
#[macro_export]
macro_rules! ColorSpaceUnknown {
    () => {
        _
    };
}

impl ColorSpace {
    #[inline]
    pub fn from_primitive(prim: u32) -> Option<Self> {
        match prim {
            0 => Some(Self::Invalid),
            1 => Some(Self::Srgb),
            2 => Some(Self::Rec601Ntsc),
            3 => Some(Self::Rec601NtscFullRange),
            4 => Some(Self::Rec601Pal),
            5 => Some(Self::Rec601PalFullRange),
            6 => Some(Self::Rec709),
            7 => Some(Self::Rec2020),
            8 => Some(Self::Rec2100),
            9 => Some(Self::Passthrough),
            4294967294 => Some(Self::DoNotCare),
            _ => None,
        }
    }

    #[inline]
    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
        match prim {
            0 => Self::Invalid,
            1 => Self::Srgb,
            2 => Self::Rec601Ntsc,
            3 => Self::Rec601NtscFullRange,
            4 => Self::Rec601Pal,
            5 => Self::Rec601PalFullRange,
            6 => Self::Rec709,
            7 => Self::Rec2020,
            8 => Self::Rec2100,
            9 => Self::Passthrough,
            4294967294 => Self::DoNotCare,
            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
        }
    }

    #[inline]
    pub fn unknown() -> Self {
        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
    }

    #[inline]
    pub const fn into_primitive(self) -> u32 {
        match self {
            Self::Invalid => 0,
            Self::Srgb => 1,
            Self::Rec601Ntsc => 2,
            Self::Rec601NtscFullRange => 3,
            Self::Rec601Pal => 4,
            Self::Rec601PalFullRange => 5,
            Self::Rec709 => 6,
            Self::Rec2020 => 7,
            Self::Rec2100 => 8,
            Self::Passthrough => 9,
            Self::DoNotCare => 4294967294,
            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
        }
    }

    #[inline]
    pub fn is_unknown(&self) -> bool {
        match self {
            Self::__SourceBreaking { unknown_ordinal: _ } => true,
            _ => false,
        }
    }
}

/// Expresses the manner in which video pixels are encoded.
///
/// The ordering of the channels in the format name reflects the actual layout
/// of the channel.
///
/// Each of these values is opinionated re. the color spaces that should be
/// contained within (in contrast with Vulkan).
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum PixelFormat {
    Invalid,
    /// RGB only, 8 bits per each of R/G/B/A sample
    ///
    /// If A is actually X (not set to meaningful values), that can be specified
    /// by settting ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present']
    /// to false.
    ///
    /// If A is known to be set to meaningful values, that can be specified by
    /// setting ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present'] to
    /// true.
    ///
    /// Compatible with VK_FORMAT_R8G8B8A8_UNORM.
    R8G8B8A8,
    /// RGB only, 8 bits per each of R/G/B/X sample
    ///
    /// Compatible with VK_FORMAT_R8G8B8A8_UNORM, when treated as opaque.
    ///
    /// Deprecated. Use `R8G8B8A8` with
    /// ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present'] set to false
    /// instead.
    R8G8B8X8,
    /// 32bpp BGRA, 1 plane.  RGB only, 8 bits per each of B/G/R/A sample.
    ///
    /// Compatible with VK_FORMAT_B8G8R8A8_UNORM.
    ///
    /// If A is actually X (not set to meaningful values), that can be specified
    /// by settting ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present']
    /// to false.
    ///
    /// If A is known to be set to meaningful values, that can be specified by
    /// setting ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present'] to
    /// true.
    ///
    /// In sysmem(1), this is BGRA32.
    B8G8R8A8,
    /// 32bpp BGRA, 1 plane.  RGB only, 8 bits per each of B/G/R/X sample.
    ///
    /// Compatible with VK_FORMAT_B8G8R8A8_UNORM, when treated as opaque.
    ///
    /// Deprecated. Use `B8G8R8A8` with
    /// [`fuchsia.sysemm2/ImageFormatConstraints.is_alpha_present`] set to false
    /// instead.
    B8G8R8X8,
    /// YUV only, 8 bits per Y sample
    ///
    /// Compatible with VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM.
    I420,
    /// YUV only, 8 bits per Y sample
    ///
    /// Not compatible with any vulkan format.
    M420,
    /// YUV only, 8 bits per Y sample
    ///
    /// Compatible with VK_FORMAT_G8_B8R8_2PLANE_420_UNORM.
    Nv12,
    /// YUV only, 8 bits per Y sample
    ///
    /// Compatible with VK_FORMAT_G8B8G8R8_422_UNORM.
    Yuy2,
    /// This value is reserved, and not currently used.
    Mjpeg,
    /// YUV only, 8 bits per Y sample
    ///
    /// Compatible with VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM. The U plane may be located in either
    /// the B or R plane for the image (and likewise for the V plane); the ordering may be
    /// determined by looking at the members of
    /// `VkBufferCollectionPropertiesFUCHSIA.samplerYcbcrConversionComponents`.
    Yv12,
    /// 24bpp BGR, 1 plane. RGB only, 8 bits per each of B/G/R sample
    ///
    /// Compatible with VK_FORMAT_B8G8R8_UNORM.
    ///
    /// In sysmem(1), this is BGR24.
    B8G8R8,
    /// 16bpp RGB, 1 plane. 5 bits R, 6 bits G, 5 bits B
    ///
    /// Compatible with VK_FORMAT_R5G6B5_UNORM_PACK16.
    ///
    /// In sysmem(1), this is RGB565.
    R5G6B5,
    /// 8bpp RGB, 1 plane. 3 bits R, 3 bits G, 2 bits B
    ///
    /// Not compatible with any vulkan format.
    ///
    /// In sysmem(1), this is RGB332.
    R3G3B2,
    /// 8bpp RGB, 1 plane. 2 bits R, 2 bits G, 2 bits B
    ///
    /// Not compatible with any vulkan format.
    ///
    /// If X is actually X (not set to meaningful values), that can be specified
    /// by settting ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present']
    /// to false.
    ///
    /// If X is known to be set to meaningful values, that can be specified by
    /// setting ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present'] to
    /// true.
    ///
    /// In sysmem(1), this is RGB2220.
    R2G2B2X2,
    /// 8bpp, Luminance-only (red, green and blue have identical values.)
    ///
    /// Compatible with VK_FORMAT_R8_UNORM.
    ///
    /// Most clients will prefer to use R8 instead.
    L8,
    /// 8bpp, Red-only (Green and Blue are to be interpreted as 0).
    ///
    /// Compatible with VK_FORMAT_R8_UNORM.
    R8,
    /// 16bpp RG, 1 plane. 8 bits R, 8 bits G.
    ///
    /// Compatible with VK_FORMAT_R8G8_UNORM.
    R8G8,
    /// 32bpp RGBA, 1 plane. 2 bits A, 10 bits R/G/B.
    ///
    /// If A is actually X (not set to meaningful values), that can be specified
    /// by settting ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present']
    /// to false.
    ///
    /// If A is known to be set to meaningful values, that can be specified by
    /// setting ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present'] to
    /// true.
    ///
    /// Compatible with VK_FORMAT_A2R10G10B10_UNORM_PACK32.
    A2R10G10B10,
    /// 32bpp BGRA, 1 plane. 2 bits A, 10 bits R/G/B.
    ///
    /// If A is actually X (not set to meaningful values), that can be specified
    /// by settting ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present']
    /// to false.
    ///
    /// If A is known to be set to meaningful values, that can be specified by
    /// setting ['fuchsia.sysemm2.ImageFormatConstraints.is_alpha_present'] to
    /// true.
    ///
    /// Compatible with VK_FORMAT_A2B10G10R10_UNORM_PACK32.
    A2B10G10R10,
    /// YUV only, 16 bits per Y sample
    ///
    /// This is like NV12 but with 16 bit samples that have the bottom 6 bits of
    /// each sample set to zero and/or ignored. The endianess of each 16 bit
    /// sample is host endian-ness (LE on LE system, BE on BE system). The CbCr
    /// plane has 16 bit Cb first, then 16 bit Cr, interleaved Cb Cr Cb Cr etc.
    ///
    /// Compatible with VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16.
    P010,
    /// 24bpp RGB, 1 plane. RGB only, 8 bits per each of R/G/B sample
    ///
    /// Compatible with VK_FORMAT_R8G8B8_UNORM.
    R8G8B8,
    /// A client is explicitly indicating that the client does not care which
    /// pixel format is chosen / used.  When setting this value, the client must
    /// not set `pixel_format_modifier`.
    DoNotCare,
    #[doc(hidden)]
    __SourceBreaking {
        unknown_ordinal: u32,
    },
}

/// Pattern that matches an unknown `PixelFormat` member.
#[macro_export]
macro_rules! PixelFormatUnknown {
    () => {
        _
    };
}

impl PixelFormat {
    #[inline]
    pub fn from_primitive(prim: u32) -> Option<Self> {
        match prim {
            0 => Some(Self::Invalid),
            1 => Some(Self::R8G8B8A8),
            119 => Some(Self::R8G8B8X8),
            101 => Some(Self::B8G8R8A8),
            120 => Some(Self::B8G8R8X8),
            102 => Some(Self::I420),
            103 => Some(Self::M420),
            104 => Some(Self::Nv12),
            105 => Some(Self::Yuy2),
            106 => Some(Self::Mjpeg),
            107 => Some(Self::Yv12),
            108 => Some(Self::B8G8R8),
            109 => Some(Self::R5G6B5),
            110 => Some(Self::R3G3B2),
            111 => Some(Self::R2G2B2X2),
            112 => Some(Self::L8),
            113 => Some(Self::R8),
            114 => Some(Self::R8G8),
            115 => Some(Self::A2R10G10B10),
            116 => Some(Self::A2B10G10R10),
            117 => Some(Self::P010),
            118 => Some(Self::R8G8B8),
            4294967294 => Some(Self::DoNotCare),
            _ => None,
        }
    }

    #[inline]
    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
        match prim {
            0 => Self::Invalid,
            1 => Self::R8G8B8A8,
            119 => Self::R8G8B8X8,
            101 => Self::B8G8R8A8,
            120 => Self::B8G8R8X8,
            102 => Self::I420,
            103 => Self::M420,
            104 => Self::Nv12,
            105 => Self::Yuy2,
            106 => Self::Mjpeg,
            107 => Self::Yv12,
            108 => Self::B8G8R8,
            109 => Self::R5G6B5,
            110 => Self::R3G3B2,
            111 => Self::R2G2B2X2,
            112 => Self::L8,
            113 => Self::R8,
            114 => Self::R8G8,
            115 => Self::A2R10G10B10,
            116 => Self::A2B10G10R10,
            117 => Self::P010,
            118 => Self::R8G8B8,
            4294967294 => Self::DoNotCare,
            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
        }
    }

    #[inline]
    pub fn unknown() -> Self {
        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
    }

    #[inline]
    pub const fn into_primitive(self) -> u32 {
        match self {
            Self::Invalid => 0,
            Self::R8G8B8A8 => 1,
            Self::R8G8B8X8 => 119,
            Self::B8G8R8A8 => 101,
            Self::B8G8R8X8 => 120,
            Self::I420 => 102,
            Self::M420 => 103,
            Self::Nv12 => 104,
            Self::Yuy2 => 105,
            Self::Mjpeg => 106,
            Self::Yv12 => 107,
            Self::B8G8R8 => 108,
            Self::R5G6B5 => 109,
            Self::R3G3B2 => 110,
            Self::R2G2B2X2 => 111,
            Self::L8 => 112,
            Self::R8 => 113,
            Self::R8G8 => 114,
            Self::A2R10G10B10 => 115,
            Self::A2B10G10R10 => 116,
            Self::P010 => 117,
            Self::R8G8B8 => 118,
            Self::DoNotCare => 4294967294,
            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
        }
    }

    #[inline]
    pub fn is_unknown(&self) -> bool {
        match self {
            Self::__SourceBreaking { unknown_ordinal: _ } => true,
            _ => false,
        }
    }
}

/// The upper 8 bits are a vendor code. The lower 56 bits are vendor-defined.
///
/// The defined `PixelFormatModifier` values are specific, complete, and valid
/// values (except for `INVALID` and `DO_NOT_CARE` which have their own
/// meanings).
///
/// Some other valid or potentially-valid `pixel_format_modifier` values are not
/// defined as a `PixelFormatModifier` value, typically because the value isn't
/// used in practice (or potentially is newly used but not yet defined in
/// `PixelFormatModifier`). It is permitted to specify such a value as a
/// `PixelFormatModifier` value in a `pixel_format_modifier` field, despite the
/// lack of corresponding defined `PixelFormatModifier` value. If such a value
/// is used outside test code, please consider adding it as a defined value in
/// `PixelFormatModifier`. All such values must conform to the upper 8 bits
/// vendor code (don't define/use values outside the/an appropriate vendor
/// code).
///
/// The separately-defined `FORMAT_MODIFIER_*` uint64 values are vendor-specific
/// bit field values, not complete valid values on their own. These uint64
/// values can be used to help create or interpret a `PixelFormatModifier` value
/// in terms of vendor-specific bitfields.
///
/// When the `pixel_format_modifier` is set to a supported value (excluding
/// `DO_NOT_CARE`, `INVALID`, `LINEAR`), the arrangement of pixel data otherwise
/// specified by the `pixel_format` field is "modified", typically to allow for
/// some combination of tiling, compression (typically lossless, typically for
/// memory bandwidth reduction not framebuffer size reduction), transaction
/// elimination, dirt tracking, but typically not modifying the bit depth of the
/// `pixel_format`. In some cases there's a per-image or per-tile header
/// involved, or similar. The `pixel_format` field often still needs to be set
/// to a valid supported value that works in combination with the
/// `pixel_format_modifier`, and that `pixel_format` value can also contribute
/// to the overall meaning of the `ImageFormat`. In other words, the "modifier"
/// part of the name is more accurate than "override" would be.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum PixelFormatModifier {
    DoNotCare,
    Invalid,
    Linear,
    IntelI915XTiled,
    IntelI915YTiled,
    IntelI915YfTiled,
    IntelI915YTiledCcs,
    IntelI915YfTiledCcs,
    ArmAfbc16X16,
    ArmAfbc32X8,
    ArmLinearTe,
    ArmAfbc16X16Te,
    ArmAfbc32X8Te,
    ArmAfbc16X16YuvTiledHeader,
    ArmAfbc16X16SplitBlockSparseYuv,
    ArmAfbc16X16SplitBlockSparseYuvTe,
    ArmAfbc16X16SplitBlockSparseYuvTiledHeader,
    ArmAfbc16X16SplitBlockSparseYuvTeTiledHeader,
    GoogleGoldfishOptimal,
    #[doc(hidden)]
    __SourceBreaking {
        unknown_ordinal: u64,
    },
}

/// Pattern that matches an unknown `PixelFormatModifier` member.
#[macro_export]
macro_rules! PixelFormatModifierUnknown {
    () => {
        _
    };
}

impl PixelFormatModifier {
    #[inline]
    pub fn from_primitive(prim: u64) -> Option<Self> {
        match prim {
            72057594037927934 => Some(Self::DoNotCare),
            72057594037927935 => Some(Self::Invalid),
            0 => Some(Self::Linear),
            72057594037927937 => Some(Self::IntelI915XTiled),
            72057594037927938 => Some(Self::IntelI915YTiled),
            72057594037927939 => Some(Self::IntelI915YfTiled),
            72057594054705154 => Some(Self::IntelI915YTiledCcs),
            72057594054705155 => Some(Self::IntelI915YfTiledCcs),
            576460752303423489 => Some(Self::ArmAfbc16X16),
            576460752303423490 => Some(Self::ArmAfbc32X8),
            576460752303427584 => Some(Self::ArmLinearTe),
            576460752303427585 => Some(Self::ArmAfbc16X16Te),
            576460752303427586 => Some(Self::ArmAfbc32X8Te),
            576460752303431697 => Some(Self::ArmAfbc16X16YuvTiledHeader),
            576460752303423601 => Some(Self::ArmAfbc16X16SplitBlockSparseYuv),
            576460752303427697 => Some(Self::ArmAfbc16X16SplitBlockSparseYuvTe),
            576460752303431793 => Some(Self::ArmAfbc16X16SplitBlockSparseYuvTiledHeader),
            576460752303435889 => Some(Self::ArmAfbc16X16SplitBlockSparseYuvTeTiledHeader),
            7421932185906577409 => Some(Self::GoogleGoldfishOptimal),
            _ => None,
        }
    }

    #[inline]
    pub fn from_primitive_allow_unknown(prim: u64) -> Self {
        match prim {
            72057594037927934 => Self::DoNotCare,
            72057594037927935 => Self::Invalid,
            0 => Self::Linear,
            72057594037927937 => Self::IntelI915XTiled,
            72057594037927938 => Self::IntelI915YTiled,
            72057594037927939 => Self::IntelI915YfTiled,
            72057594054705154 => Self::IntelI915YTiledCcs,
            72057594054705155 => Self::IntelI915YfTiledCcs,
            576460752303423489 => Self::ArmAfbc16X16,
            576460752303423490 => Self::ArmAfbc32X8,
            576460752303427584 => Self::ArmLinearTe,
            576460752303427585 => Self::ArmAfbc16X16Te,
            576460752303427586 => Self::ArmAfbc32X8Te,
            576460752303431697 => Self::ArmAfbc16X16YuvTiledHeader,
            576460752303423601 => Self::ArmAfbc16X16SplitBlockSparseYuv,
            576460752303427697 => Self::ArmAfbc16X16SplitBlockSparseYuvTe,
            576460752303431793 => Self::ArmAfbc16X16SplitBlockSparseYuvTiledHeader,
            576460752303435889 => Self::ArmAfbc16X16SplitBlockSparseYuvTeTiledHeader,
            7421932185906577409 => Self::GoogleGoldfishOptimal,
            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
        }
    }

    #[inline]
    pub fn unknown() -> Self {
        Self::__SourceBreaking { unknown_ordinal: 0xffffffffffffffff }
    }

    #[inline]
    pub const fn into_primitive(self) -> u64 {
        match self {
            Self::DoNotCare => 72057594037927934,
            Self::Invalid => 72057594037927935,
            Self::Linear => 0,
            Self::IntelI915XTiled => 72057594037927937,
            Self::IntelI915YTiled => 72057594037927938,
            Self::IntelI915YfTiled => 72057594037927939,
            Self::IntelI915YTiledCcs => 72057594054705154,
            Self::IntelI915YfTiledCcs => 72057594054705155,
            Self::ArmAfbc16X16 => 576460752303423489,
            Self::ArmAfbc32X8 => 576460752303423490,
            Self::ArmLinearTe => 576460752303427584,
            Self::ArmAfbc16X16Te => 576460752303427585,
            Self::ArmAfbc32X8Te => 576460752303427586,
            Self::ArmAfbc16X16YuvTiledHeader => 576460752303431697,
            Self::ArmAfbc16X16SplitBlockSparseYuv => 576460752303423601,
            Self::ArmAfbc16X16SplitBlockSparseYuvTe => 576460752303427697,
            Self::ArmAfbc16X16SplitBlockSparseYuvTiledHeader => 576460752303431793,
            Self::ArmAfbc16X16SplitBlockSparseYuvTeTiledHeader => 576460752303435889,
            Self::GoogleGoldfishOptimal => 7421932185906577409,
            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
        }
    }

    #[inline]
    pub fn is_unknown(&self) -> bool {
        match self {
            Self::__SourceBreaking { unknown_ordinal: _ } => true,
            _ => false,
        }
    }
}

/// An integral, rectangular, axis-aligned region in a 2D cartesian
/// space, with unsigned location and distance fields.
///
/// This type does not specify units. Protocols that use this type should
/// specify the characteristics of the vector space, including orientation and
/// units.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[repr(C)]
pub struct RectU {
    /// The location of the origin of the rectangle in the x-axis.
    pub x: u32,
    /// The location of the origin of the rectangle in the y-axis.
    pub y: u32,
    /// The distance along the x-axis.
    ///
    /// The region includes x values starting at `x` and increasing along the
    /// x-axis.
    pub width: u32,
    /// The distance along the y-axis.
    ///
    /// The region includes y values starting at `y` and increasing along the
    /// y-axis.
    pub height: u32,
}

impl fidl::Persistable for RectU {}

/// Describes the format of images.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ImageFormat {
    /// Describes the manner in which pixels are encoded.
    pub pixel_format: Option<PixelFormat>,
    /// Vendor-specific pixel format modifier. See format_modifier.fidl.
    pub pixel_format_modifier: Option<PixelFormatModifier>,
    /// Indicates the color space used to interpret pixel values.
    pub color_space: Option<ColorSpace>,
    /// The size of the image in pixels.
    ///
    /// See also `bytes_per_row` which is also necessary (along with `size`) to
    /// find where each pixel's data is within a buffer.
    ///
    /// Not all of the addressable pixel positions in the buffer are necessarily
    /// populated with valid pixel data. See `valid_size` for the
    /// potentially-smaller rectangle of valid pixels.
    ///
    /// The right and bottom of the image may have some valid pixels which are
    /// not to be displayed.  See `display_rect`.
    pub size: Option<fidl_fuchsia_math::SizeU>,
    /// Number of bytes per row. For multi-plane YUV formats, this is the number
    /// of bytes per row in the Y plane.
    ///
    /// When this field is not set, there is no padding at the end of each row
    /// of pixels. In other words, when not set, the stride is equal to the
    /// "stride bytes per width pixel" times the `size.width`.
    ///
    /// When set, the value in this field must be >= the "stride bytes per width
    /// pixel" times the `size.width`. If equal, there is no padding at
    /// the end of each row of pixels. If greater, the difference is how much
    /// padding is at the end of each row of pixels, in bytes.
    ///
    /// This is also known as the "stride", "line to line offset", "row to row
    /// offset", and other names.
    ///
    /// As a specific example, it's not uncommon (but also not always required)
    /// for BGR24 (3 bytes per pixel) to have some padding at the end of each
    /// row so that each row of pixels starts at a 4 byte aligned offset from
    /// the start of the image (the upper left pixel). That padding's size is
    /// not necessarily divisible by the size in bytes of a pixel ("stride bytes
    /// per width pixel"), so we indicate the padding using this field rather
    /// than trying to incorporate the padding as a larger "fake"
    /// `size.width`.
    pub bytes_per_row: Option<u32>,
    /// The rect within a frame that's for display. This is the location and
    /// size in pixels of the rectangle of pixels that should be displayed, when
    /// displaying the "whole image" in a UI display sense.
    ///
    /// The `x` + `width` must be <= `size.width`, and the `y` + `height` must
    /// be <= `size.height`.
    ///
    /// For output from a video decoder, pixels outside the display_rect are
    /// never to be displayed (outside of test programs), but must be preserved
    /// for correct decoder function.  The `display_rect` will always fall
    /// within the rect starting at (0, 0) and having `valid_size` size, when
    /// `valid_size` is set.  In other words, `display_rect` is a subset (not
    /// necessarily a proper subset) of `valid_size`, and `valid_size` is a
    /// subset (not necessarily a proper subset) of `size`.
    ///
    /// Downstream texture filtering operations should avoid letting any pixel
    /// outside of display_rect influence the visual appearance of any displayed
    /// pixel, to avoid the potential for the right or bottom edge leaking in
    /// arbitrary pixels defined by the decode process but not intended for
    /// display.
    ///
    /// Behavior when this field is not set is protocol-specific. In some
    /// protocols, fallback to `valid_size`, then to `size` may be implemented.
    /// In others, fallback directly to `size` may be implemented. In others,
    /// this field must be set or the channel will close.
    ///
    /// WARNING: fuchsia.sysmem.Images2 (V1) doesn't handle non-zero x, y, so
    /// any non-zero x, y here (V2) will prevent conversion to V1.  Due to the
    /// rarity of non-zero x, y in practice, even components that have moved to
    /// V2 may in some cases still assume both x and y are 0, until there's a
    /// practical reason to implment and test handling of non-zero x, y.  The
    /// symptom of sending non-zero x, y to a downstream render and/or display
    /// pipeline that assumes 0, 0 will be incorrect display, but not a crash,
    /// since assuming 0, 0 for x, y does not cause reading out of buffer
    /// bounds.
    pub display_rect: Option<fidl_fuchsia_math::RectU>,
    /// The size of a frame in terms of the number of pixels that have valid
    /// pixel data in terms of video decoding, but not in terms of which pixels
    /// are intended for display.
    ///
    /// To convert valid_size into a rect that's directly comparable to
    /// `display_rect`, one can make a rect with (`x`: 0, `y`: 0, `width`:
    /// `valid_size.width`, `height`: `valid_size.height`).
    ///
    /// In the case of a video decoder, `valid_size` can include some pixels
    /// outside `display_rect`. The extra pixels are not meant to be displayed,
    /// and may or may not contain any real image data. Typically anything that
    /// looks like real image data in these regions is only an artifact of video
    /// compression and the existence of the remainder of a macroblock which can
    /// be referenced by later frames despite not being within the displayed
    /// region, and not really any additional "real" pixels from the source. The
    /// pixel values in this region are defined by the codec decode process and
    /// must be retained for correct decoder operation. Typically the pixels
    /// inside valid_size but outside display_rect will be up to the size of a
    /// macroblock minus 1. The `valid_size` is can be useful for testing video
    /// decoders and for certain transcoding scenarios.
    pub valid_size: Option<fidl_fuchsia_math::SizeU>,
    /// Aspect ratio of a single pixel as the video is intended to be displayed.
    ///
    /// For YUV formats, this is the pixel aspect ratio (AKA sample aspect ratio
    /// aka SAR) for the luma (AKA Y) samples.
    ///
    /// Producers should ensure the width and height values are relatively prime
    /// by reducing the fraction (dividing both by GCF) if necessary.
    ///
    /// A consumer should interpret this field being un-set as an unknown pixel
    /// aspect ratio.  A default of 1:1 can be appropriate in some cases, but a
    /// consumer may determine the actual pixel aspect ratio by OOB means.
    pub pixel_aspect_ratio: Option<fidl_fuchsia_math::SizeU>,
    #[doc(hidden)]
    pub __source_breaking: fidl::marker::SourceBreaking,
}

impl fidl::Persistable for ImageFormat {}

mod internal {
    use super::*;
    unsafe impl fidl::encoding::TypeMarker for ColorSpace {
        type Owned = Self;

        #[inline(always)]
        fn inline_align(_context: fidl::encoding::Context) -> usize {
            std::mem::align_of::<u32>()
        }

        #[inline(always)]
        fn inline_size(_context: fidl::encoding::Context) -> usize {
            std::mem::size_of::<u32>()
        }

        #[inline(always)]
        fn encode_is_copy() -> bool {
            false
        }

        #[inline(always)]
        fn decode_is_copy() -> bool {
            false
        }
    }

    impl fidl::encoding::ValueTypeMarker for ColorSpace {
        type Borrowed<'a> = Self;
        #[inline(always)]
        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
            *value
        }
    }

    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for ColorSpace {
        #[inline]
        unsafe fn encode(
            self,
            encoder: &mut fidl::encoding::Encoder<'_, D>,
            offset: usize,
            _depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            encoder.debug_check_bounds::<Self>(offset);
            encoder.write_num(self.into_primitive(), offset);
            Ok(())
        }
    }

    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ColorSpace {
        #[inline(always)]
        fn new_empty() -> Self {
            Self::unknown()
        }

        #[inline]
        unsafe fn decode(
            &mut self,
            decoder: &mut fidl::encoding::Decoder<'_, D>,
            offset: usize,
            _depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            decoder.debug_check_bounds::<Self>(offset);
            let prim = decoder.read_num::<u32>(offset);

            *self = Self::from_primitive_allow_unknown(prim);
            Ok(())
        }
    }
    unsafe impl fidl::encoding::TypeMarker for PixelFormat {
        type Owned = Self;

        #[inline(always)]
        fn inline_align(_context: fidl::encoding::Context) -> usize {
            std::mem::align_of::<u32>()
        }

        #[inline(always)]
        fn inline_size(_context: fidl::encoding::Context) -> usize {
            std::mem::size_of::<u32>()
        }

        #[inline(always)]
        fn encode_is_copy() -> bool {
            false
        }

        #[inline(always)]
        fn decode_is_copy() -> bool {
            false
        }
    }

    impl fidl::encoding::ValueTypeMarker for PixelFormat {
        type Borrowed<'a> = Self;
        #[inline(always)]
        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
            *value
        }
    }

    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for PixelFormat {
        #[inline]
        unsafe fn encode(
            self,
            encoder: &mut fidl::encoding::Encoder<'_, D>,
            offset: usize,
            _depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            encoder.debug_check_bounds::<Self>(offset);
            encoder.write_num(self.into_primitive(), offset);
            Ok(())
        }
    }

    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PixelFormat {
        #[inline(always)]
        fn new_empty() -> Self {
            Self::unknown()
        }

        #[inline]
        unsafe fn decode(
            &mut self,
            decoder: &mut fidl::encoding::Decoder<'_, D>,
            offset: usize,
            _depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            decoder.debug_check_bounds::<Self>(offset);
            let prim = decoder.read_num::<u32>(offset);

            *self = Self::from_primitive_allow_unknown(prim);
            Ok(())
        }
    }
    unsafe impl fidl::encoding::TypeMarker for PixelFormatModifier {
        type Owned = Self;

        #[inline(always)]
        fn inline_align(_context: fidl::encoding::Context) -> usize {
            std::mem::align_of::<u64>()
        }

        #[inline(always)]
        fn inline_size(_context: fidl::encoding::Context) -> usize {
            std::mem::size_of::<u64>()
        }

        #[inline(always)]
        fn encode_is_copy() -> bool {
            false
        }

        #[inline(always)]
        fn decode_is_copy() -> bool {
            false
        }
    }

    impl fidl::encoding::ValueTypeMarker for PixelFormatModifier {
        type Borrowed<'a> = Self;
        #[inline(always)]
        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
            *value
        }
    }

    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
        for PixelFormatModifier
    {
        #[inline]
        unsafe fn encode(
            self,
            encoder: &mut fidl::encoding::Encoder<'_, D>,
            offset: usize,
            _depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            encoder.debug_check_bounds::<Self>(offset);
            encoder.write_num(self.into_primitive(), offset);
            Ok(())
        }
    }

    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PixelFormatModifier {
        #[inline(always)]
        fn new_empty() -> Self {
            Self::unknown()
        }

        #[inline]
        unsafe fn decode(
            &mut self,
            decoder: &mut fidl::encoding::Decoder<'_, D>,
            offset: usize,
            _depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            decoder.debug_check_bounds::<Self>(offset);
            let prim = decoder.read_num::<u64>(offset);

            *self = Self::from_primitive_allow_unknown(prim);
            Ok(())
        }
    }

    impl fidl::encoding::ValueTypeMarker for RectU {
        type Borrowed<'a> = &'a Self;
        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
            value
        }
    }

    unsafe impl fidl::encoding::TypeMarker for RectU {
        type Owned = Self;

        #[inline(always)]
        fn inline_align(_context: fidl::encoding::Context) -> usize {
            4
        }

        #[inline(always)]
        fn inline_size(_context: fidl::encoding::Context) -> usize {
            16
        }
        #[inline(always)]
        fn encode_is_copy() -> bool {
            true
        }

        #[inline(always)]
        fn decode_is_copy() -> bool {
            true
        }
    }

    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<RectU, D> for &RectU {
        #[inline]
        unsafe fn encode(
            self,
            encoder: &mut fidl::encoding::Encoder<'_, D>,
            offset: usize,
            _depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            encoder.debug_check_bounds::<RectU>(offset);
            unsafe {
                // Copy the object into the buffer.
                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
                (buf_ptr as *mut RectU).write_unaligned((self as *const RectU).read());
                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
                // done second because the memcpy will write garbage to these bytes.
            }
            Ok(())
        }
    }
    unsafe impl<
            D: fidl::encoding::ResourceDialect,
            T0: fidl::encoding::Encode<u32, D>,
            T1: fidl::encoding::Encode<u32, D>,
            T2: fidl::encoding::Encode<u32, D>,
            T3: fidl::encoding::Encode<u32, D>,
        > fidl::encoding::Encode<RectU, D> for (T0, T1, T2, T3)
    {
        #[inline]
        unsafe fn encode(
            self,
            encoder: &mut fidl::encoding::Encoder<'_, D>,
            offset: usize,
            depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            encoder.debug_check_bounds::<RectU>(offset);
            // Zero out padding regions. There's no need to apply masks
            // because the unmasked parts will be overwritten by fields.
            // Write the fields.
            self.0.encode(encoder, offset + 0, depth)?;
            self.1.encode(encoder, offset + 4, depth)?;
            self.2.encode(encoder, offset + 8, depth)?;
            self.3.encode(encoder, offset + 12, depth)?;
            Ok(())
        }
    }

    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for RectU {
        #[inline(always)]
        fn new_empty() -> Self {
            Self {
                x: fidl::new_empty!(u32, D),
                y: fidl::new_empty!(u32, D),
                width: fidl::new_empty!(u32, D),
                height: fidl::new_empty!(u32, D),
            }
        }

        #[inline]
        unsafe fn decode(
            &mut self,
            decoder: &mut fidl::encoding::Decoder<'_, D>,
            offset: usize,
            _depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            decoder.debug_check_bounds::<Self>(offset);
            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
            // Verify that padding bytes are zero.
            // Copy from the buffer into the object.
            unsafe {
                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 16);
            }
            Ok(())
        }
    }

    impl ImageFormat {
        #[inline(always)]
        fn max_ordinal_present(&self) -> u64 {
            if let Some(_) = self.pixel_aspect_ratio {
                return 8;
            }
            if let Some(_) = self.valid_size {
                return 7;
            }
            if let Some(_) = self.display_rect {
                return 6;
            }
            if let Some(_) = self.bytes_per_row {
                return 5;
            }
            if let Some(_) = self.size {
                return 4;
            }
            if let Some(_) = self.color_space {
                return 3;
            }
            if let Some(_) = self.pixel_format_modifier {
                return 2;
            }
            if let Some(_) = self.pixel_format {
                return 1;
            }
            0
        }
    }

    impl fidl::encoding::ValueTypeMarker for ImageFormat {
        type Borrowed<'a> = &'a Self;
        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
            value
        }
    }

    unsafe impl fidl::encoding::TypeMarker for ImageFormat {
        type Owned = Self;

        #[inline(always)]
        fn inline_align(_context: fidl::encoding::Context) -> usize {
            8
        }

        #[inline(always)]
        fn inline_size(_context: fidl::encoding::Context) -> usize {
            16
        }
    }

    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ImageFormat, D>
        for &ImageFormat
    {
        unsafe fn encode(
            self,
            encoder: &mut fidl::encoding::Encoder<'_, D>,
            offset: usize,
            mut depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            encoder.debug_check_bounds::<ImageFormat>(offset);
            // Vector header
            let max_ordinal: u64 = self.max_ordinal_present();
            encoder.write_num(max_ordinal, offset);
            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
            // Calling encoder.out_of_line_offset(0) is not allowed.
            if max_ordinal == 0 {
                return Ok(());
            }
            depth.increment()?;
            let envelope_size = 8;
            let bytes_len = max_ordinal as usize * envelope_size;
            #[allow(unused_variables)]
            let offset = encoder.out_of_line_offset(bytes_len);
            let mut _prev_end_offset: usize = 0;
            if 1 > max_ordinal {
                return Ok(());
            }

            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
            // are envelope_size bytes.
            let cur_offset: usize = (1 - 1) * envelope_size;

            // Zero reserved fields.
            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);

            // Safety:
            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
            //   envelope_size bytes, there is always sufficient room.
            fidl::encoding::encode_in_envelope_optional::<PixelFormat, D>(
                self.pixel_format
                    .as_ref()
                    .map(<PixelFormat as fidl::encoding::ValueTypeMarker>::borrow),
                encoder,
                offset + cur_offset,
                depth,
            )?;

            _prev_end_offset = cur_offset + envelope_size;
            if 2 > max_ordinal {
                return Ok(());
            }

            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
            // are envelope_size bytes.
            let cur_offset: usize = (2 - 1) * envelope_size;

            // Zero reserved fields.
            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);

            // Safety:
            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
            //   envelope_size bytes, there is always sufficient room.
            fidl::encoding::encode_in_envelope_optional::<PixelFormatModifier, D>(
                self.pixel_format_modifier
                    .as_ref()
                    .map(<PixelFormatModifier as fidl::encoding::ValueTypeMarker>::borrow),
                encoder,
                offset + cur_offset,
                depth,
            )?;

            _prev_end_offset = cur_offset + envelope_size;
            if 3 > max_ordinal {
                return Ok(());
            }

            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
            // are envelope_size bytes.
            let cur_offset: usize = (3 - 1) * envelope_size;

            // Zero reserved fields.
            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);

            // Safety:
            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
            //   envelope_size bytes, there is always sufficient room.
            fidl::encoding::encode_in_envelope_optional::<ColorSpace, D>(
                self.color_space
                    .as_ref()
                    .map(<ColorSpace as fidl::encoding::ValueTypeMarker>::borrow),
                encoder,
                offset + cur_offset,
                depth,
            )?;

            _prev_end_offset = cur_offset + envelope_size;
            if 4 > max_ordinal {
                return Ok(());
            }

            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
            // are envelope_size bytes.
            let cur_offset: usize = (4 - 1) * envelope_size;

            // Zero reserved fields.
            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);

            // Safety:
            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
            //   envelope_size bytes, there is always sufficient room.
            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math::SizeU, D>(
                self.size
                    .as_ref()
                    .map(<fidl_fuchsia_math::SizeU as fidl::encoding::ValueTypeMarker>::borrow),
                encoder,
                offset + cur_offset,
                depth,
            )?;

            _prev_end_offset = cur_offset + envelope_size;
            if 5 > max_ordinal {
                return Ok(());
            }

            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
            // are envelope_size bytes.
            let cur_offset: usize = (5 - 1) * envelope_size;

            // Zero reserved fields.
            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);

            // Safety:
            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
            //   envelope_size bytes, there is always sufficient room.
            fidl::encoding::encode_in_envelope_optional::<u32, D>(
                self.bytes_per_row.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
                encoder,
                offset + cur_offset,
                depth,
            )?;

            _prev_end_offset = cur_offset + envelope_size;
            if 6 > max_ordinal {
                return Ok(());
            }

            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
            // are envelope_size bytes.
            let cur_offset: usize = (6 - 1) * envelope_size;

            // Zero reserved fields.
            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);

            // Safety:
            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
            //   envelope_size bytes, there is always sufficient room.
            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math::RectU, D>(
                self.display_rect
                    .as_ref()
                    .map(<fidl_fuchsia_math::RectU as fidl::encoding::ValueTypeMarker>::borrow),
                encoder,
                offset + cur_offset,
                depth,
            )?;

            _prev_end_offset = cur_offset + envelope_size;
            if 7 > max_ordinal {
                return Ok(());
            }

            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
            // are envelope_size bytes.
            let cur_offset: usize = (7 - 1) * envelope_size;

            // Zero reserved fields.
            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);

            // Safety:
            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
            //   envelope_size bytes, there is always sufficient room.
            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math::SizeU, D>(
                self.valid_size
                    .as_ref()
                    .map(<fidl_fuchsia_math::SizeU as fidl::encoding::ValueTypeMarker>::borrow),
                encoder,
                offset + cur_offset,
                depth,
            )?;

            _prev_end_offset = cur_offset + envelope_size;
            if 8 > max_ordinal {
                return Ok(());
            }

            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
            // are envelope_size bytes.
            let cur_offset: usize = (8 - 1) * envelope_size;

            // Zero reserved fields.
            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);

            // Safety:
            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
            //   envelope_size bytes, there is always sufficient room.
            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math::SizeU, D>(
                self.pixel_aspect_ratio
                    .as_ref()
                    .map(<fidl_fuchsia_math::SizeU as fidl::encoding::ValueTypeMarker>::borrow),
                encoder,
                offset + cur_offset,
                depth,
            )?;

            _prev_end_offset = cur_offset + envelope_size;

            Ok(())
        }
    }

    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ImageFormat {
        #[inline(always)]
        fn new_empty() -> Self {
            Self::default()
        }

        unsafe fn decode(
            &mut self,
            decoder: &mut fidl::encoding::Decoder<'_, D>,
            offset: usize,
            mut depth: fidl::encoding::Depth,
        ) -> fidl::Result<()> {
            decoder.debug_check_bounds::<Self>(offset);
            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
                None => return Err(fidl::Error::NotNullable),
                Some(len) => len,
            };
            // Calling decoder.out_of_line_offset(0) is not allowed.
            if len == 0 {
                return Ok(());
            };
            depth.increment()?;
            let envelope_size = 8;
            let bytes_len = len * envelope_size;
            let offset = decoder.out_of_line_offset(bytes_len)?;
            // Decode the envelope for each type.
            let mut _next_ordinal_to_read = 0;
            let mut next_offset = offset;
            let end_offset = offset + bytes_len;
            _next_ordinal_to_read += 1;
            if next_offset >= end_offset {
                return Ok(());
            }

            // Decode unknown envelopes for gaps in ordinals.
            while _next_ordinal_to_read < 1 {
                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
                _next_ordinal_to_read += 1;
                next_offset += envelope_size;
            }

            let next_out_of_line = decoder.next_out_of_line();
            let handles_before = decoder.remaining_handles();
            if let Some((inlined, num_bytes, num_handles)) =
                fidl::encoding::decode_envelope_header(decoder, next_offset)?
            {
                let member_inline_size =
                    <PixelFormat as fidl::encoding::TypeMarker>::inline_size(decoder.context);
                if inlined != (member_inline_size <= 4) {
                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
                }
                let inner_offset;
                let mut inner_depth = depth.clone();
                if inlined {
                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
                    inner_offset = next_offset;
                } else {
                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
                    inner_depth.increment()?;
                }
                let val_ref =
                    self.pixel_format.get_or_insert_with(|| fidl::new_empty!(PixelFormat, D));
                fidl::decode!(PixelFormat, D, val_ref, decoder, inner_offset, inner_depth)?;
                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
                {
                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
                }
                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
                }
            }

            next_offset += envelope_size;
            _next_ordinal_to_read += 1;
            if next_offset >= end_offset {
                return Ok(());
            }

            // Decode unknown envelopes for gaps in ordinals.
            while _next_ordinal_to_read < 2 {
                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
                _next_ordinal_to_read += 1;
                next_offset += envelope_size;
            }

            let next_out_of_line = decoder.next_out_of_line();
            let handles_before = decoder.remaining_handles();
            if let Some((inlined, num_bytes, num_handles)) =
                fidl::encoding::decode_envelope_header(decoder, next_offset)?
            {
                let member_inline_size =
                    <PixelFormatModifier as fidl::encoding::TypeMarker>::inline_size(
                        decoder.context,
                    );
                if inlined != (member_inline_size <= 4) {
                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
                }
                let inner_offset;
                let mut inner_depth = depth.clone();
                if inlined {
                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
                    inner_offset = next_offset;
                } else {
                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
                    inner_depth.increment()?;
                }
                let val_ref = self
                    .pixel_format_modifier
                    .get_or_insert_with(|| fidl::new_empty!(PixelFormatModifier, D));
                fidl::decode!(PixelFormatModifier, D, val_ref, decoder, inner_offset, inner_depth)?;
                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
                {
                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
                }
                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
                }
            }

            next_offset += envelope_size;
            _next_ordinal_to_read += 1;
            if next_offset >= end_offset {
                return Ok(());
            }

            // Decode unknown envelopes for gaps in ordinals.
            while _next_ordinal_to_read < 3 {
                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
                _next_ordinal_to_read += 1;
                next_offset += envelope_size;
            }

            let next_out_of_line = decoder.next_out_of_line();
            let handles_before = decoder.remaining_handles();
            if let Some((inlined, num_bytes, num_handles)) =
                fidl::encoding::decode_envelope_header(decoder, next_offset)?
            {
                let member_inline_size =
                    <ColorSpace as fidl::encoding::TypeMarker>::inline_size(decoder.context);
                if inlined != (member_inline_size <= 4) {
                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
                }
                let inner_offset;
                let mut inner_depth = depth.clone();
                if inlined {
                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
                    inner_offset = next_offset;
                } else {
                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
                    inner_depth.increment()?;
                }
                let val_ref =
                    self.color_space.get_or_insert_with(|| fidl::new_empty!(ColorSpace, D));
                fidl::decode!(ColorSpace, D, val_ref, decoder, inner_offset, inner_depth)?;
                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
                {
                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
                }
                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
                }
            }

            next_offset += envelope_size;
            _next_ordinal_to_read += 1;
            if next_offset >= end_offset {
                return Ok(());
            }

            // Decode unknown envelopes for gaps in ordinals.
            while _next_ordinal_to_read < 4 {
                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
                _next_ordinal_to_read += 1;
                next_offset += envelope_size;
            }

            let next_out_of_line = decoder.next_out_of_line();
            let handles_before = decoder.remaining_handles();
            if let Some((inlined, num_bytes, num_handles)) =
                fidl::encoding::decode_envelope_header(decoder, next_offset)?
            {
                let member_inline_size =
                    <fidl_fuchsia_math::SizeU as fidl::encoding::TypeMarker>::inline_size(
                        decoder.context,
                    );
                if inlined != (member_inline_size <= 4) {
                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
                }
                let inner_offset;
                let mut inner_depth = depth.clone();
                if inlined {
                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
                    inner_offset = next_offset;
                } else {
                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
                    inner_depth.increment()?;
                }
                let val_ref =
                    self.size.get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math::SizeU, D));
                fidl::decode!(
                    fidl_fuchsia_math::SizeU,
                    D,
                    val_ref,
                    decoder,
                    inner_offset,
                    inner_depth
                )?;
                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
                {
                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
                }
                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
                }
            }

            next_offset += envelope_size;
            _next_ordinal_to_read += 1;
            if next_offset >= end_offset {
                return Ok(());
            }

            // Decode unknown envelopes for gaps in ordinals.
            while _next_ordinal_to_read < 5 {
                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
                _next_ordinal_to_read += 1;
                next_offset += envelope_size;
            }

            let next_out_of_line = decoder.next_out_of_line();
            let handles_before = decoder.remaining_handles();
            if let Some((inlined, num_bytes, num_handles)) =
                fidl::encoding::decode_envelope_header(decoder, next_offset)?
            {
                let member_inline_size =
                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
                if inlined != (member_inline_size <= 4) {
                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
                }
                let inner_offset;
                let mut inner_depth = depth.clone();
                if inlined {
                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
                    inner_offset = next_offset;
                } else {
                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
                    inner_depth.increment()?;
                }
                let val_ref = self.bytes_per_row.get_or_insert_with(|| fidl::new_empty!(u32, D));
                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
                {
                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
                }
                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
                }
            }

            next_offset += envelope_size;
            _next_ordinal_to_read += 1;
            if next_offset >= end_offset {
                return Ok(());
            }

            // Decode unknown envelopes for gaps in ordinals.
            while _next_ordinal_to_read < 6 {
                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
                _next_ordinal_to_read += 1;
                next_offset += envelope_size;
            }

            let next_out_of_line = decoder.next_out_of_line();
            let handles_before = decoder.remaining_handles();
            if let Some((inlined, num_bytes, num_handles)) =
                fidl::encoding::decode_envelope_header(decoder, next_offset)?
            {
                let member_inline_size =
                    <fidl_fuchsia_math::RectU as fidl::encoding::TypeMarker>::inline_size(
                        decoder.context,
                    );
                if inlined != (member_inline_size <= 4) {
                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
                }
                let inner_offset;
                let mut inner_depth = depth.clone();
                if inlined {
                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
                    inner_offset = next_offset;
                } else {
                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
                    inner_depth.increment()?;
                }
                let val_ref = self
                    .display_rect
                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math::RectU, D));
                fidl::decode!(
                    fidl_fuchsia_math::RectU,
                    D,
                    val_ref,
                    decoder,
                    inner_offset,
                    inner_depth
                )?;
                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
                {
                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
                }
                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
                }
            }

            next_offset += envelope_size;
            _next_ordinal_to_read += 1;
            if next_offset >= end_offset {
                return Ok(());
            }

            // Decode unknown envelopes for gaps in ordinals.
            while _next_ordinal_to_read < 7 {
                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
                _next_ordinal_to_read += 1;
                next_offset += envelope_size;
            }

            let next_out_of_line = decoder.next_out_of_line();
            let handles_before = decoder.remaining_handles();
            if let Some((inlined, num_bytes, num_handles)) =
                fidl::encoding::decode_envelope_header(decoder, next_offset)?
            {
                let member_inline_size =
                    <fidl_fuchsia_math::SizeU as fidl::encoding::TypeMarker>::inline_size(
                        decoder.context,
                    );
                if inlined != (member_inline_size <= 4) {
                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
                }
                let inner_offset;
                let mut inner_depth = depth.clone();
                if inlined {
                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
                    inner_offset = next_offset;
                } else {
                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
                    inner_depth.increment()?;
                }
                let val_ref = self
                    .valid_size
                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math::SizeU, D));
                fidl::decode!(
                    fidl_fuchsia_math::SizeU,
                    D,
                    val_ref,
                    decoder,
                    inner_offset,
                    inner_depth
                )?;
                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
                {
                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
                }
                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
                }
            }

            next_offset += envelope_size;
            _next_ordinal_to_read += 1;
            if next_offset >= end_offset {
                return Ok(());
            }

            // Decode unknown envelopes for gaps in ordinals.
            while _next_ordinal_to_read < 8 {
                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
                _next_ordinal_to_read += 1;
                next_offset += envelope_size;
            }

            let next_out_of_line = decoder.next_out_of_line();
            let handles_before = decoder.remaining_handles();
            if let Some((inlined, num_bytes, num_handles)) =
                fidl::encoding::decode_envelope_header(decoder, next_offset)?
            {
                let member_inline_size =
                    <fidl_fuchsia_math::SizeU as fidl::encoding::TypeMarker>::inline_size(
                        decoder.context,
                    );
                if inlined != (member_inline_size <= 4) {
                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
                }
                let inner_offset;
                let mut inner_depth = depth.clone();
                if inlined {
                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
                    inner_offset = next_offset;
                } else {
                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
                    inner_depth.increment()?;
                }
                let val_ref = self
                    .pixel_aspect_ratio
                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math::SizeU, D));
                fidl::decode!(
                    fidl_fuchsia_math::SizeU,
                    D,
                    val_ref,
                    decoder,
                    inner_offset,
                    inner_depth
                )?;
                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
                {
                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
                }
                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
                }
            }

            next_offset += envelope_size;

            // Decode the remaining unknown envelopes.
            while next_offset < end_offset {
                _next_ordinal_to_read += 1;
                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
                next_offset += envelope_size;
            }

            Ok(())
        }
    }
}