Skip to main content

fidl_fuchsia_images2_common/
fidl_fuchsia_images2_common.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11pub const FORMAT_MODIFIER_ARM_BCH_BIT: u64 = 2048;
12
13pub const FORMAT_MODIFIER_ARM_SPARSE_BIT: u64 = 64;
14
15pub const FORMAT_MODIFIER_ARM_SPLIT_BLOCK_BIT: u64 = 32;
16
17pub const FORMAT_MODIFIER_ARM_TE_BIT: u64 = 4096;
18
19pub const FORMAT_MODIFIER_ARM_TILED_HEADER_BIT: u64 = 8192;
20
21pub const FORMAT_MODIFIER_ARM_YUV_BIT: u64 = 16;
22
23/// Format has a color control surface after the tile data
24pub const FORMAT_MODIFIER_INTEL_CCS_BIT: u64 = 16777216;
25
26pub const FORMAT_MODIFIER_VENDOR_ALLWINNER: u64 = 648518346341351424;
27
28pub const FORMAT_MODIFIER_VENDOR_AMD: u64 = 144115188075855872;
29
30pub const FORMAT_MODIFIER_VENDOR_AMLOGIC: u64 = 720575940379279360;
31
32pub const FORMAT_MODIFIER_VENDOR_ARM: u64 = 576460752303423488;
33
34pub const FORMAT_MODIFIER_VENDOR_BROADCOM: u64 = 504403158265495552;
35
36pub const FORMAT_MODIFIER_VENDOR_GOOGLE: u64 = 7421932185906577408;
37
38pub const FORMAT_MODIFIER_VENDOR_INTEL: u64 = 72057594037927936;
39
40pub const FORMAT_MODIFIER_VENDOR_NVIDIA: u64 = 216172782113783808;
41
42pub const FORMAT_MODIFIER_VENDOR_PVR: u64 = 10520408729537478656;
43
44pub const FORMAT_MODIFIER_VENDOR_QCOM: u64 = 360287970189639680;
45
46pub const FORMAT_MODIFIER_VENDOR_SAMSUNG: u64 = 288230376151711744;
47
48pub const FORMAT_MODIFIER_VENDOR_VIVANTE: u64 = 432345564227567616;
49
50/// Expresses the color space used to interpret video pixel values.
51///
52/// This list has a separate entry for each variant of a color space standard.
53///
54/// For this reason, should we ever add support for the RGB variant of 709, for
55/// example, we'd add a separate entry to this list for that variant.  Similarly
56/// for the RGB variants of 2020 or 2100.  Similarly for the YcCbcCrc variant of
57/// 2020.  Similarly for the ICtCp variant of 2100.
58///
59/// See ImageFormatIsSupportedColorSpaceForPixelFormat() for whether a
60/// combination of `PixelFormat` and `ColorSpace` is potentially supported.
61///
62/// Generally, a `ColorSpace` is not supported for any `PixelFormat` whose
63/// bits-per-sample isn't compatible with the color space's spec, nor for any
64/// `PixelFormat` which is a mismatch in terms of RGB vs. YUV.
65///
66/// The "limited range" in comments below refers to where black and white are
67/// defined to be (and simimlar for chroma), but should not be interpreted as
68/// guaranteeing that there won't be values outside the nominal "limited range".
69/// In other words, "limited range" doesn't necessarily mean there won't be any
70/// values below black or above white, or outside the "limited" chroma range.
71/// For "full range", black is 0 and white is the max possible/permitted numeric
72/// value (and similar for chroma).
73#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
74pub enum ColorSpace {
75    /// Not a valid color space type.
76    Invalid,
77    /// sRGB, gamma transfer function and full range, per spec
78    Srgb,
79    /// 601 NTSC ("525 line") YCbCr primaries, limited range
80    Rec601Ntsc,
81    /// 601 NTSC ("525 line") YCbCr primaries, full range
82    Rec601NtscFullRange,
83    /// 601 PAL ("625 line") YCbCr primaries, limited range
84    Rec601Pal,
85    /// 601 PAL ("625 line") YCbCr primaries, full range
86    Rec601PalFullRange,
87    /// 709 YCbCr (not RGB), limited range
88    Rec709,
89    /// 2020 YCbCr (not RGB, not YcCbcCrc), 10 or 12 bit according to
90    /// `PixelFormat`, with primaries, limited range (not full range), transfer
91    /// function ("gamma"), etc all per spec, wide color gamut SDR
92    Rec2020,
93    /// 2100 YCbCr (not RGB, not ICtCp), 10 or 12 bit according to
94    /// `PixelFormat`, BT.2020 primaries (same wide color gamut as REC2020),
95    /// limited range (not full range), PQ (aka SMPTE ST 2084) HDR transfer
96    /// function (not HLG, not SDR "gamma" used by REC2020 and REC709), wide
97    /// color gamut HDR
98    Rec2100,
99    /// Either the pixel format doesn't represent a color, or it's in an
100    /// application-specific colorspace that isn't describable by another entry
101    /// in this enum.
102    Passthrough,
103    /// A client is explicitly indicating that the client does not care which
104    /// color space is chosen / used.
105    DoNotCare,
106    #[doc(hidden)]
107    __SourceBreaking { unknown_ordinal: u32 },
108}
109
110/// Pattern that matches an unknown `ColorSpace` member.
111#[macro_export]
112macro_rules! ColorSpaceUnknown {
113    () => {
114        _
115    };
116}
117
118impl ColorSpace {
119    #[inline]
120    pub fn from_primitive(prim: u32) -> Option<Self> {
121        match prim {
122            0 => Some(Self::Invalid),
123            1 => Some(Self::Srgb),
124            2 => Some(Self::Rec601Ntsc),
125            3 => Some(Self::Rec601NtscFullRange),
126            4 => Some(Self::Rec601Pal),
127            5 => Some(Self::Rec601PalFullRange),
128            6 => Some(Self::Rec709),
129            7 => Some(Self::Rec2020),
130            8 => Some(Self::Rec2100),
131            9 => Some(Self::Passthrough),
132            4294967294 => Some(Self::DoNotCare),
133            _ => None,
134        }
135    }
136
137    #[inline]
138    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
139        match prim {
140            0 => Self::Invalid,
141            1 => Self::Srgb,
142            2 => Self::Rec601Ntsc,
143            3 => Self::Rec601NtscFullRange,
144            4 => Self::Rec601Pal,
145            5 => Self::Rec601PalFullRange,
146            6 => Self::Rec709,
147            7 => Self::Rec2020,
148            8 => Self::Rec2100,
149            9 => Self::Passthrough,
150            4294967294 => Self::DoNotCare,
151            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
152        }
153    }
154
155    #[inline]
156    pub fn unknown() -> Self {
157        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
158    }
159
160    #[inline]
161    pub const fn into_primitive(self) -> u32 {
162        match self {
163            Self::Invalid => 0,
164            Self::Srgb => 1,
165            Self::Rec601Ntsc => 2,
166            Self::Rec601NtscFullRange => 3,
167            Self::Rec601Pal => 4,
168            Self::Rec601PalFullRange => 5,
169            Self::Rec709 => 6,
170            Self::Rec2020 => 7,
171            Self::Rec2100 => 8,
172            Self::Passthrough => 9,
173            Self::DoNotCare => 4294967294,
174            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
175        }
176    }
177
178    #[inline]
179    pub fn is_unknown(&self) -> bool {
180        match self {
181            Self::__SourceBreaking { unknown_ordinal: _ } => true,
182            _ => false,
183        }
184    }
185}
186
187/// Expresses the manner in which video pixels are encoded.
188///
189/// The ordering of the channels in the format name reflects the actual layout
190/// of the channel.
191///
192/// Each of these values is opinionated re. the color spaces that should be
193/// contained within (in contrast with Vulkan).
194#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
195pub enum PixelFormat {
196    Invalid,
197    /// RGB only, 8 bits per each of R/G/B/A sample
198    ///
199    /// If A is actually X (not set to meaningful values), that can be specified
200    /// by settting ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present']
201    /// to false.
202    ///
203    /// If A is known to be set to meaningful values, that can be specified by
204    /// setting ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present'] to
205    /// true.
206    ///
207    /// Compatible with VK_FORMAT_R8G8B8A8_UNORM.
208    R8G8B8A8,
209    /// RGB only, 8 bits per each of R/G/B/X sample
210    ///
211    /// Compatible with VK_FORMAT_R8G8B8A8_UNORM, when treated as opaque.
212    ///
213    /// Deprecated. Use `R8G8B8A8` with
214    /// ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present'] set to false
215    /// instead.
216    R8G8B8X8,
217    /// 32bpp BGRA, 1 plane.  RGB only, 8 bits per each of B/G/R/A sample.
218    ///
219    /// Compatible with VK_FORMAT_B8G8R8A8_UNORM.
220    ///
221    /// If A is actually X (not set to meaningful values), that can be specified
222    /// by settting ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present']
223    /// to false.
224    ///
225    /// If A is known to be set to meaningful values, that can be specified by
226    /// setting ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present'] to
227    /// true.
228    ///
229    /// In sysmem(1), this is BGRA32.
230    B8G8R8A8,
231    /// 32bpp BGRA, 1 plane.  RGB only, 8 bits per each of B/G/R/X sample.
232    ///
233    /// Compatible with VK_FORMAT_B8G8R8A8_UNORM, when treated as opaque.
234    ///
235    /// Deprecated. Use `B8G8R8A8` with
236    /// [`fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present`] set to false
237    /// instead.
238    B8G8R8X8,
239    /// YUV only, 8 bits per Y sample
240    ///
241    /// Compatible with VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM.
242    I420,
243    /// YUV only, 8 bits per Y sample
244    ///
245    /// Not compatible with any vulkan format.
246    M420,
247    /// YUV only, 8 bits per Y sample
248    ///
249    /// Compatible with VK_FORMAT_G8_B8R8_2PLANE_420_UNORM.
250    Nv12,
251    /// YUV only, 8 bits per Y sample
252    ///
253    /// Compatible with VK_FORMAT_G8B8G8R8_422_UNORM.
254    Yuy2,
255    /// This value is reserved, and not currently used.
256    Mjpeg,
257    /// YUV only, 8 bits per Y sample
258    ///
259    /// Compatible with VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM. The U plane may be located in either
260    /// the B or R plane for the image (and likewise for the V plane); the ordering may be
261    /// determined by looking at the members of
262    /// `VkBufferCollectionPropertiesFUCHSIA.samplerYcbcrConversionComponents`.
263    Yv12,
264    /// 24bpp BGR, 1 plane. RGB only, 8 bits per each of B/G/R sample
265    ///
266    /// Compatible with VK_FORMAT_B8G8R8_UNORM.
267    ///
268    /// In sysmem(1), this is BGR24.
269    B8G8R8,
270    /// 16bpp RGB, 1 plane. 5 bits R, 6 bits G, 5 bits B
271    ///
272    /// Compatible with VK_FORMAT_R5G6B5_UNORM_PACK16.
273    ///
274    /// In sysmem(1), this is RGB565.
275    R5G6B5,
276    /// 8bpp RGB, 1 plane. 3 bits R, 3 bits G, 2 bits B
277    ///
278    /// Not compatible with any vulkan format.
279    ///
280    /// In sysmem(1), this is RGB332.
281    R3G3B2,
282    /// 8bpp RGB, 1 plane. 2 bits R, 2 bits G, 2 bits B
283    ///
284    /// Not compatible with any vulkan format.
285    ///
286    /// If X is actually X (not set to meaningful values), that can be specified
287    /// by settting ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present']
288    /// to false.
289    ///
290    /// If X is known to be set to meaningful values, that can be specified by
291    /// setting ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present'] to
292    /// true.
293    ///
294    /// In sysmem(1), this is RGB2220.
295    R2G2B2X2,
296    /// 8bpp, Luminance-only (red, green and blue have identical values.)
297    ///
298    /// Compatible with VK_FORMAT_R8_UNORM.
299    ///
300    /// Most clients will prefer to use R8 instead.
301    L8,
302    /// 8bpp, Red-only (Green and Blue are to be interpreted as 0).
303    ///
304    /// Compatible with VK_FORMAT_R8_UNORM.
305    R8,
306    /// 16bpp RG, 1 plane. 8 bits R, 8 bits G.
307    ///
308    /// Compatible with VK_FORMAT_R8G8_UNORM.
309    R8G8,
310    /// 32bpp RGBA, 1 plane. 2 bits A, 10 bits R/G/B.
311    ///
312    /// If A is actually X (not set to meaningful values), that can be specified
313    /// by settting ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present']
314    /// to false.
315    ///
316    /// If A is known to be set to meaningful values, that can be specified by
317    /// setting ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present'] to
318    /// true.
319    ///
320    /// Compatible with VK_FORMAT_A2R10G10B10_UNORM_PACK32.
321    A2R10G10B10,
322    /// 32bpp BGRA, 1 plane. 2 bits A, 10 bits R/G/B.
323    ///
324    /// If A is actually X (not set to meaningful values), that can be specified
325    /// by settting ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present']
326    /// to false.
327    ///
328    /// If A is known to be set to meaningful values, that can be specified by
329    /// setting ['fuchsia.sysmem2/ImageFormatConstraints.is_alpha_present'] to
330    /// true.
331    ///
332    /// Compatible with VK_FORMAT_A2B10G10R10_UNORM_PACK32.
333    A2B10G10R10,
334    /// YUV only, 16 bits per Y sample
335    ///
336    /// This is like NV12 but with 16 bit samples that have the bottom 6 bits of
337    /// each sample set to zero and/or ignored. The endianess of each 16 bit
338    /// sample is host endian-ness (LE on LE system, BE on BE system). The CbCr
339    /// plane has 16 bit Cb first, then 16 bit Cr, interleaved Cb Cr Cb Cr etc.
340    ///
341    /// Compatible with VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16.
342    P010,
343    /// 24bpp RGB, 1 plane. RGB only, 8 bits per each of R/G/B sample
344    ///
345    /// Compatible with VK_FORMAT_R8G8B8_UNORM.
346    R8G8B8,
347    /// A client is explicitly indicating that the client does not care which
348    /// pixel format is chosen / used.  When setting this value, the client must
349    /// not set `pixel_format_modifier`.
350    DoNotCare,
351    #[doc(hidden)]
352    __SourceBreaking {
353        unknown_ordinal: u32,
354    },
355}
356
357/// Pattern that matches an unknown `PixelFormat` member.
358#[macro_export]
359macro_rules! PixelFormatUnknown {
360    () => {
361        _
362    };
363}
364
365impl PixelFormat {
366    #[inline]
367    pub fn from_primitive(prim: u32) -> Option<Self> {
368        match prim {
369            0 => Some(Self::Invalid),
370            1 => Some(Self::R8G8B8A8),
371            119 => Some(Self::R8G8B8X8),
372            101 => Some(Self::B8G8R8A8),
373            120 => Some(Self::B8G8R8X8),
374            102 => Some(Self::I420),
375            103 => Some(Self::M420),
376            104 => Some(Self::Nv12),
377            105 => Some(Self::Yuy2),
378            106 => Some(Self::Mjpeg),
379            107 => Some(Self::Yv12),
380            108 => Some(Self::B8G8R8),
381            109 => Some(Self::R5G6B5),
382            110 => Some(Self::R3G3B2),
383            111 => Some(Self::R2G2B2X2),
384            112 => Some(Self::L8),
385            113 => Some(Self::R8),
386            114 => Some(Self::R8G8),
387            115 => Some(Self::A2R10G10B10),
388            116 => Some(Self::A2B10G10R10),
389            117 => Some(Self::P010),
390            118 => Some(Self::R8G8B8),
391            4294967294 => Some(Self::DoNotCare),
392            _ => None,
393        }
394    }
395
396    #[inline]
397    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
398        match prim {
399            0 => Self::Invalid,
400            1 => Self::R8G8B8A8,
401            119 => Self::R8G8B8X8,
402            101 => Self::B8G8R8A8,
403            120 => Self::B8G8R8X8,
404            102 => Self::I420,
405            103 => Self::M420,
406            104 => Self::Nv12,
407            105 => Self::Yuy2,
408            106 => Self::Mjpeg,
409            107 => Self::Yv12,
410            108 => Self::B8G8R8,
411            109 => Self::R5G6B5,
412            110 => Self::R3G3B2,
413            111 => Self::R2G2B2X2,
414            112 => Self::L8,
415            113 => Self::R8,
416            114 => Self::R8G8,
417            115 => Self::A2R10G10B10,
418            116 => Self::A2B10G10R10,
419            117 => Self::P010,
420            118 => Self::R8G8B8,
421            4294967294 => Self::DoNotCare,
422            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
423        }
424    }
425
426    #[inline]
427    pub fn unknown() -> Self {
428        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
429    }
430
431    #[inline]
432    pub const fn into_primitive(self) -> u32 {
433        match self {
434            Self::Invalid => 0,
435            Self::R8G8B8A8 => 1,
436            Self::R8G8B8X8 => 119,
437            Self::B8G8R8A8 => 101,
438            Self::B8G8R8X8 => 120,
439            Self::I420 => 102,
440            Self::M420 => 103,
441            Self::Nv12 => 104,
442            Self::Yuy2 => 105,
443            Self::Mjpeg => 106,
444            Self::Yv12 => 107,
445            Self::B8G8R8 => 108,
446            Self::R5G6B5 => 109,
447            Self::R3G3B2 => 110,
448            Self::R2G2B2X2 => 111,
449            Self::L8 => 112,
450            Self::R8 => 113,
451            Self::R8G8 => 114,
452            Self::A2R10G10B10 => 115,
453            Self::A2B10G10R10 => 116,
454            Self::P010 => 117,
455            Self::R8G8B8 => 118,
456            Self::DoNotCare => 4294967294,
457            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
458        }
459    }
460
461    #[inline]
462    pub fn is_unknown(&self) -> bool {
463        match self {
464            Self::__SourceBreaking { unknown_ordinal: _ } => true,
465            _ => false,
466        }
467    }
468}
469
470/// The upper 8 bits are a vendor code. The lower 56 bits are vendor-defined.
471///
472/// The defined `PixelFormatModifier` values are specific, complete, and valid
473/// values (except for `INVALID` and `DO_NOT_CARE` which have their own
474/// meanings).
475///
476/// Some other valid or potentially-valid `pixel_format_modifier` values are not
477/// defined as a `PixelFormatModifier` value, typically because the value isn't
478/// used in practice (or potentially is newly used but not yet defined in
479/// `PixelFormatModifier`). It is permitted to specify such a value as a
480/// `PixelFormatModifier` value in a `pixel_format_modifier` field, despite the
481/// lack of corresponding defined `PixelFormatModifier` value. If such a value
482/// is used outside test code, please consider adding it as a defined value in
483/// `PixelFormatModifier`. All such values must conform to the upper 8 bits
484/// vendor code (don't define/use values outside the/an appropriate vendor
485/// code).
486///
487/// The separately-defined `FORMAT_MODIFIER_*` uint64 values are vendor-specific
488/// bit field values, not complete valid values on their own. These uint64
489/// values can be used to help create or interpret a `PixelFormatModifier` value
490/// in terms of vendor-specific bitfields.
491///
492/// When the `pixel_format_modifier` is set to a supported value (excluding
493/// `DO_NOT_CARE`, `INVALID`, `LINEAR`), the arrangement of pixel data otherwise
494/// specified by the `pixel_format` field is "modified", typically to allow for
495/// some combination of tiling, compression (typically lossless, typically for
496/// memory bandwidth reduction not framebuffer size reduction), transaction
497/// elimination, dirt tracking, but typically not modifying the bit depth of the
498/// `pixel_format`. In some cases there's a per-image or per-tile header
499/// involved, or similar. The `pixel_format` field often still needs to be set
500/// to a valid supported value that works in combination with the
501/// `pixel_format_modifier`, and that `pixel_format` value can also contribute
502/// to the overall meaning of the `ImageFormat`. In other words, the "modifier"
503/// part of the name is more accurate than "override" would be.
504#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
505pub enum PixelFormatModifier {
506    DoNotCare,
507    Invalid,
508    Linear,
509    IntelI915XTiled,
510    IntelI915YTiled,
511    IntelI915YfTiled,
512    IntelI915YTiledCcs,
513    IntelI915YfTiledCcs,
514    ArmAfbc16X16,
515    ArmAfbc32X8,
516    ArmLinearTe,
517    ArmAfbc16X16Te,
518    ArmAfbc32X8Te,
519    ArmAfbc16X16YuvTiledHeader,
520    ArmAfbc16X16SplitBlockSparseYuv,
521    ArmAfbc16X16SplitBlockSparseYuvTe,
522    ArmAfbc16X16SplitBlockSparseYuvTiledHeader,
523    ArmAfbc16X16SplitBlockSparseYuvTeTiledHeader,
524    GoogleGoldfishOptimal,
525    /// PowerVR Framebuffer Compression (FBCDC / PVRIC) 8x8 tile, V14 (FBCDC v4/v5).
526    PvrFbcdc8X8V14,
527    /// PowerVR Framebuffer Compression (FBCDC / PVRIC) 16x4 tile, V14 (FBCDC v4/v5).
528    PvrFbcdc16X4V14,
529    #[doc(hidden)]
530    __SourceBreaking {
531        unknown_ordinal: u64,
532    },
533}
534
535/// Pattern that matches an unknown `PixelFormatModifier` member.
536#[macro_export]
537macro_rules! PixelFormatModifierUnknown {
538    () => {
539        _
540    };
541}
542
543impl PixelFormatModifier {
544    #[inline]
545    pub fn from_primitive(prim: u64) -> Option<Self> {
546        match prim {
547            72057594037927934 => Some(Self::DoNotCare),
548            72057594037927935 => Some(Self::Invalid),
549            0 => Some(Self::Linear),
550            72057594037927937 => Some(Self::IntelI915XTiled),
551            72057594037927938 => Some(Self::IntelI915YTiled),
552            72057594037927939 => Some(Self::IntelI915YfTiled),
553            72057594054705154 => Some(Self::IntelI915YTiledCcs),
554            72057594054705155 => Some(Self::IntelI915YfTiledCcs),
555            576460752303423489 => Some(Self::ArmAfbc16X16),
556            576460752303423490 => Some(Self::ArmAfbc32X8),
557            576460752303427584 => Some(Self::ArmLinearTe),
558            576460752303427585 => Some(Self::ArmAfbc16X16Te),
559            576460752303427586 => Some(Self::ArmAfbc32X8Te),
560            576460752303431697 => Some(Self::ArmAfbc16X16YuvTiledHeader),
561            576460752303423601 => Some(Self::ArmAfbc16X16SplitBlockSparseYuv),
562            576460752303427697 => Some(Self::ArmAfbc16X16SplitBlockSparseYuvTe),
563            576460752303431793 => Some(Self::ArmAfbc16X16SplitBlockSparseYuvTiledHeader),
564            576460752303435889 => Some(Self::ArmAfbc16X16SplitBlockSparseYuvTeTiledHeader),
565            7421932185906577409 => Some(Self::GoogleGoldfishOptimal),
566            10520408729537478690 => Some(Self::PvrFbcdc8X8V14),
567            10520408729537478695 => Some(Self::PvrFbcdc16X4V14),
568            _ => None,
569        }
570    }
571
572    #[inline]
573    pub fn from_primitive_allow_unknown(prim: u64) -> Self {
574        match prim {
575            72057594037927934 => Self::DoNotCare,
576            72057594037927935 => Self::Invalid,
577            0 => Self::Linear,
578            72057594037927937 => Self::IntelI915XTiled,
579            72057594037927938 => Self::IntelI915YTiled,
580            72057594037927939 => Self::IntelI915YfTiled,
581            72057594054705154 => Self::IntelI915YTiledCcs,
582            72057594054705155 => Self::IntelI915YfTiledCcs,
583            576460752303423489 => Self::ArmAfbc16X16,
584            576460752303423490 => Self::ArmAfbc32X8,
585            576460752303427584 => Self::ArmLinearTe,
586            576460752303427585 => Self::ArmAfbc16X16Te,
587            576460752303427586 => Self::ArmAfbc32X8Te,
588            576460752303431697 => Self::ArmAfbc16X16YuvTiledHeader,
589            576460752303423601 => Self::ArmAfbc16X16SplitBlockSparseYuv,
590            576460752303427697 => Self::ArmAfbc16X16SplitBlockSparseYuvTe,
591            576460752303431793 => Self::ArmAfbc16X16SplitBlockSparseYuvTiledHeader,
592            576460752303435889 => Self::ArmAfbc16X16SplitBlockSparseYuvTeTiledHeader,
593            7421932185906577409 => Self::GoogleGoldfishOptimal,
594            10520408729537478690 => Self::PvrFbcdc8X8V14,
595            10520408729537478695 => Self::PvrFbcdc16X4V14,
596            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
597        }
598    }
599
600    #[inline]
601    pub fn unknown() -> Self {
602        Self::__SourceBreaking { unknown_ordinal: 0xffffffffffffffff }
603    }
604
605    #[inline]
606    pub const fn into_primitive(self) -> u64 {
607        match self {
608            Self::DoNotCare => 72057594037927934,
609            Self::Invalid => 72057594037927935,
610            Self::Linear => 0,
611            Self::IntelI915XTiled => 72057594037927937,
612            Self::IntelI915YTiled => 72057594037927938,
613            Self::IntelI915YfTiled => 72057594037927939,
614            Self::IntelI915YTiledCcs => 72057594054705154,
615            Self::IntelI915YfTiledCcs => 72057594054705155,
616            Self::ArmAfbc16X16 => 576460752303423489,
617            Self::ArmAfbc32X8 => 576460752303423490,
618            Self::ArmLinearTe => 576460752303427584,
619            Self::ArmAfbc16X16Te => 576460752303427585,
620            Self::ArmAfbc32X8Te => 576460752303427586,
621            Self::ArmAfbc16X16YuvTiledHeader => 576460752303431697,
622            Self::ArmAfbc16X16SplitBlockSparseYuv => 576460752303423601,
623            Self::ArmAfbc16X16SplitBlockSparseYuvTe => 576460752303427697,
624            Self::ArmAfbc16X16SplitBlockSparseYuvTiledHeader => 576460752303431793,
625            Self::ArmAfbc16X16SplitBlockSparseYuvTeTiledHeader => 576460752303435889,
626            Self::GoogleGoldfishOptimal => 7421932185906577409,
627            Self::PvrFbcdc8X8V14 => 10520408729537478690,
628            Self::PvrFbcdc16X4V14 => 10520408729537478695,
629            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
630        }
631    }
632
633    #[inline]
634    pub fn is_unknown(&self) -> bool {
635        match self {
636            Self::__SourceBreaking { unknown_ordinal: _ } => true,
637            _ => false,
638        }
639    }
640}
641
642/// Describes the format of images.
643#[derive(Clone, Debug, Default, PartialEq)]
644pub struct ImageFormat {
645    /// Describes the manner in which pixels are encoded.
646    pub pixel_format: Option<PixelFormat>,
647    /// Vendor-specific pixel format modifier. See format_modifier.fidl.
648    pub pixel_format_modifier: Option<PixelFormatModifier>,
649    /// Indicates the color space used to interpret pixel values.
650    pub color_space: Option<ColorSpace>,
651    /// The size of the image in pixels.
652    ///
653    /// See also `bytes_per_row` which is also necessary (along with `size`) to
654    /// find where each pixel's data is within a buffer.
655    ///
656    /// Not all of the addressable pixel positions in the buffer are necessarily
657    /// populated with valid pixel data. See `valid_size` for the
658    /// potentially-smaller rectangle of valid pixels.
659    ///
660    /// The right and bottom of the image may have some valid pixels which are
661    /// not to be displayed.  See `display_rect`.
662    pub size: Option<fidl_fuchsia_math_common::SizeU>,
663    /// Number of bytes per row. For multi-plane YUV formats, this is the number
664    /// of bytes per row in the Y plane.
665    ///
666    /// When this field is not set, there is no padding at the end of each row
667    /// of pixels. In other words, when not set, the stride is equal to the
668    /// "stride bytes per width pixel" times the `size.width`.
669    ///
670    /// When set, the value in this field must be >= the "stride bytes per width
671    /// pixel" times the `size.width`. If equal, there is no padding at the end
672    /// of each row of pixels. If greater, the difference is how much padding is
673    /// at the end of each row of pixels, in bytes.
674    ///
675    /// This field has no assigned meaning when 'pixel_format_modifier' isn't
676    /// 'PixelFormatModifier::Linear'. Instead participants are expected to
677    /// implicitly know that a tiled (not linear) format will contain `size`
678    /// pixels by rounding up to the closest tile boundary greater than or equal
679    /// to width and same separately for height, without any "extra" tiles in
680    /// either direction. Tiled (not linear) formats don't have any way to
681    /// specify more blocks in either direction than are implied by `size`. When
682    /// relevant consumers support display_rect, `size` can imply more tiles
683    /// than display_rect touches.
684    ///
685    /// This is not "row stride in pixels", nor is it "per-pixel stride" (which
686    /// themselves are two different things both distinct from bytes_per_row).
687    ///
688    /// The number in this field is also known as the "row stride in bytes",
689    /// "line to line offset in bytes", "row to row offset in bytes", and other
690    /// variants of these names, sometimes just "stride", but only when
691    /// understood to be in bytes.
692    ///
693    /// Regarding "row stride in pixels" vs `bytes_per_row`, as an example, it's
694    /// not uncommon for BGR24 (3 bytes per pixel) to have some padding at the
695    /// end of each row so that each row of pixels starts at a 4 byte aligned
696    /// offset from the start of the image. That padding's size is not
697    /// necessarily divisible by the size in bytes of a pixel ("stride bytes per
698    /// width pixel"), so we indicate the padding using this field rather than
699    /// trying to incorporate the padding as a larger "fake" `size.width`.
700    ///
701    /// When `pixel_format_modifier` == `PixelFormatModifier.Linear`, this is
702    /// the offset in bytes of byte 0 of row 1 of plane 0 minus the offset in
703    /// bytes of byte 0 of row 0 of plane 0.
704    pub bytes_per_row: Option<u32>,
705    /// The rect within a frame that's for display. This is the location and
706    /// size in pixels of the rectangle of pixels that should be displayed, when
707    /// displaying the "whole image" in a UI display sense.
708    ///
709    /// The `x` + `width` must be <= `size.width`, and the `y` + `height` must
710    /// be <= `size.height`.
711    ///
712    /// For output from a video decoder, pixels outside the display_rect are
713    /// never to be displayed (outside of test programs), but must be preserved
714    /// for correct decoder function.  The `display_rect` will always fall
715    /// within the rect starting at (0, 0) and having `valid_size` size, when
716    /// `valid_size` is set.  In other words, `display_rect` is a subset (not
717    /// necessarily a proper subset) of `valid_size`, and `valid_size` is a
718    /// subset (not necessarily a proper subset) of `size`.
719    ///
720    /// Downstream texture filtering operations should avoid letting any pixel
721    /// outside of display_rect influence the visual appearance of any displayed
722    /// pixel, to avoid the potential for the right or bottom edge leaking in
723    /// arbitrary pixels defined by the decode process but not intended for
724    /// display.
725    ///
726    /// Behavior when this field is not set is protocol-specific. In some
727    /// protocols, fallback to `valid_size`, then to `size` may be implemented.
728    /// In others, fallback directly to `size` may be implemented. In others,
729    /// this field must be set or the channel will close.
730    ///
731    /// WARNING: fuchsia.sysmem.Images2 (V1) doesn't handle non-zero x, y, so
732    /// any non-zero x, y here (V2) will prevent conversion to V1.  Due to the
733    /// rarity of non-zero x, y in practice, even components that have moved to
734    /// V2 may in some cases still assume both x and y are 0, until there's a
735    /// practical reason to implment and test handling of non-zero x, y.  The
736    /// symptom of sending non-zero x, y to a downstream render and/or display
737    /// pipeline that assumes 0, 0 will be incorrect display, but not a crash,
738    /// since assuming 0, 0 for x, y does not cause reading out of buffer
739    /// bounds.
740    pub display_rect: Option<fidl_fuchsia_math_common::RectU>,
741    /// The size of a frame in terms of the number of pixels that have valid
742    /// pixel data in terms of video decoding, but not in terms of which pixels
743    /// are intended for display.
744    ///
745    /// To convert valid_size into a rect that's directly comparable to
746    /// `display_rect`, one can make a rect with (`x`: 0, `y`: 0, `width`:
747    /// `valid_size.width`, `height`: `valid_size.height`).
748    ///
749    /// In the case of a video decoder, `valid_size` can include some pixels
750    /// outside `display_rect`. The extra pixels are not meant to be displayed,
751    /// and may or may not contain any real image data. Typically anything that
752    /// looks like real image data in these regions is only an artifact of video
753    /// compression and the existence of the remainder of a macroblock which can
754    /// be referenced by later frames despite not being within the displayed
755    /// region, and not really any additional "real" pixels from the source. The
756    /// pixel values in this region are defined by the codec decode process and
757    /// must be retained for correct decoder operation. Typically the pixels
758    /// inside valid_size but outside display_rect will be up to the size of a
759    /// macroblock minus 1. The `valid_size` is can be useful for testing video
760    /// decoders and for certain transcoding scenarios.
761    pub valid_size: Option<fidl_fuchsia_math_common::SizeU>,
762    /// Aspect ratio of a single pixel as the video is intended to be displayed.
763    ///
764    /// For YUV formats, this is the pixel aspect ratio (AKA sample aspect ratio
765    /// aka SAR) for the luma (AKA Y) samples.
766    ///
767    /// Producers should ensure the width and height values are relatively prime
768    /// by reducing the fraction (dividing both by GCF) if necessary.
769    ///
770    /// A consumer should interpret this field being un-set as an unknown pixel
771    /// aspect ratio.  A default of 1:1 can be appropriate in some cases, but a
772    /// consumer may determine the actual pixel aspect ratio by OOB means.
773    pub pixel_aspect_ratio: Option<fidl_fuchsia_math_common::SizeU>,
774    #[doc(hidden)]
775    pub __source_breaking: fidl::marker::SourceBreaking,
776}
777
778impl fidl::Persistable for ImageFormat {}
779
780mod internal {
781    use super::*;
782    unsafe impl fidl::encoding::TypeMarker for ColorSpace {
783        type Owned = Self;
784
785        #[inline(always)]
786        fn inline_align(_context: fidl::encoding::Context) -> usize {
787            std::mem::align_of::<u32>()
788        }
789
790        #[inline(always)]
791        fn inline_size(_context: fidl::encoding::Context) -> usize {
792            std::mem::size_of::<u32>()
793        }
794
795        #[inline(always)]
796        fn encode_is_copy() -> bool {
797            false
798        }
799
800        #[inline(always)]
801        fn decode_is_copy() -> bool {
802            false
803        }
804    }
805
806    impl fidl::encoding::ValueTypeMarker for ColorSpace {
807        type Borrowed<'a> = Self;
808        #[inline(always)]
809        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
810            *value
811        }
812    }
813
814    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for ColorSpace {
815        #[inline]
816        unsafe fn encode(
817            self,
818            encoder: &mut fidl::encoding::Encoder<'_, D>,
819            offset: usize,
820            _depth: fidl::encoding::Depth,
821        ) -> fidl::Result<()> {
822            encoder.debug_check_bounds::<Self>(offset);
823            encoder.write_num(self.into_primitive(), offset);
824            Ok(())
825        }
826    }
827
828    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ColorSpace {
829        #[inline(always)]
830        fn new_empty() -> Self {
831            Self::unknown()
832        }
833
834        #[inline]
835        unsafe fn decode(
836            &mut self,
837            decoder: &mut fidl::encoding::Decoder<'_, D>,
838            offset: usize,
839            _depth: fidl::encoding::Depth,
840        ) -> fidl::Result<()> {
841            decoder.debug_check_bounds::<Self>(offset);
842            let prim = decoder.read_num::<u32>(offset);
843
844            *self = Self::from_primitive_allow_unknown(prim);
845            Ok(())
846        }
847    }
848    unsafe impl fidl::encoding::TypeMarker for PixelFormat {
849        type Owned = Self;
850
851        #[inline(always)]
852        fn inline_align(_context: fidl::encoding::Context) -> usize {
853            std::mem::align_of::<u32>()
854        }
855
856        #[inline(always)]
857        fn inline_size(_context: fidl::encoding::Context) -> usize {
858            std::mem::size_of::<u32>()
859        }
860
861        #[inline(always)]
862        fn encode_is_copy() -> bool {
863            false
864        }
865
866        #[inline(always)]
867        fn decode_is_copy() -> bool {
868            false
869        }
870    }
871
872    impl fidl::encoding::ValueTypeMarker for PixelFormat {
873        type Borrowed<'a> = Self;
874        #[inline(always)]
875        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
876            *value
877        }
878    }
879
880    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for PixelFormat {
881        #[inline]
882        unsafe fn encode(
883            self,
884            encoder: &mut fidl::encoding::Encoder<'_, D>,
885            offset: usize,
886            _depth: fidl::encoding::Depth,
887        ) -> fidl::Result<()> {
888            encoder.debug_check_bounds::<Self>(offset);
889            encoder.write_num(self.into_primitive(), offset);
890            Ok(())
891        }
892    }
893
894    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PixelFormat {
895        #[inline(always)]
896        fn new_empty() -> Self {
897            Self::unknown()
898        }
899
900        #[inline]
901        unsafe fn decode(
902            &mut self,
903            decoder: &mut fidl::encoding::Decoder<'_, D>,
904            offset: usize,
905            _depth: fidl::encoding::Depth,
906        ) -> fidl::Result<()> {
907            decoder.debug_check_bounds::<Self>(offset);
908            let prim = decoder.read_num::<u32>(offset);
909
910            *self = Self::from_primitive_allow_unknown(prim);
911            Ok(())
912        }
913    }
914    unsafe impl fidl::encoding::TypeMarker for PixelFormatModifier {
915        type Owned = Self;
916
917        #[inline(always)]
918        fn inline_align(_context: fidl::encoding::Context) -> usize {
919            std::mem::align_of::<u64>()
920        }
921
922        #[inline(always)]
923        fn inline_size(_context: fidl::encoding::Context) -> usize {
924            std::mem::size_of::<u64>()
925        }
926
927        #[inline(always)]
928        fn encode_is_copy() -> bool {
929            false
930        }
931
932        #[inline(always)]
933        fn decode_is_copy() -> bool {
934            false
935        }
936    }
937
938    impl fidl::encoding::ValueTypeMarker for PixelFormatModifier {
939        type Borrowed<'a> = Self;
940        #[inline(always)]
941        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
942            *value
943        }
944    }
945
946    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
947        for PixelFormatModifier
948    {
949        #[inline]
950        unsafe fn encode(
951            self,
952            encoder: &mut fidl::encoding::Encoder<'_, D>,
953            offset: usize,
954            _depth: fidl::encoding::Depth,
955        ) -> fidl::Result<()> {
956            encoder.debug_check_bounds::<Self>(offset);
957            encoder.write_num(self.into_primitive(), offset);
958            Ok(())
959        }
960    }
961
962    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PixelFormatModifier {
963        #[inline(always)]
964        fn new_empty() -> Self {
965            Self::unknown()
966        }
967
968        #[inline]
969        unsafe fn decode(
970            &mut self,
971            decoder: &mut fidl::encoding::Decoder<'_, D>,
972            offset: usize,
973            _depth: fidl::encoding::Depth,
974        ) -> fidl::Result<()> {
975            decoder.debug_check_bounds::<Self>(offset);
976            let prim = decoder.read_num::<u64>(offset);
977
978            *self = Self::from_primitive_allow_unknown(prim);
979            Ok(())
980        }
981    }
982
983    impl ImageFormat {
984        #[inline(always)]
985        fn max_ordinal_present(&self) -> u64 {
986            if let Some(_) = self.pixel_aspect_ratio {
987                return 8;
988            }
989            if let Some(_) = self.valid_size {
990                return 7;
991            }
992            if let Some(_) = self.display_rect {
993                return 6;
994            }
995            if let Some(_) = self.bytes_per_row {
996                return 5;
997            }
998            if let Some(_) = self.size {
999                return 4;
1000            }
1001            if let Some(_) = self.color_space {
1002                return 3;
1003            }
1004            if let Some(_) = self.pixel_format_modifier {
1005                return 2;
1006            }
1007            if let Some(_) = self.pixel_format {
1008                return 1;
1009            }
1010            0
1011        }
1012    }
1013
1014    impl fidl::encoding::ValueTypeMarker for ImageFormat {
1015        type Borrowed<'a> = &'a Self;
1016        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1017            value
1018        }
1019    }
1020
1021    unsafe impl fidl::encoding::TypeMarker for ImageFormat {
1022        type Owned = Self;
1023
1024        #[inline(always)]
1025        fn inline_align(_context: fidl::encoding::Context) -> usize {
1026            8
1027        }
1028
1029        #[inline(always)]
1030        fn inline_size(_context: fidl::encoding::Context) -> usize {
1031            16
1032        }
1033    }
1034
1035    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ImageFormat, D>
1036        for &ImageFormat
1037    {
1038        unsafe fn encode(
1039            self,
1040            encoder: &mut fidl::encoding::Encoder<'_, D>,
1041            offset: usize,
1042            mut depth: fidl::encoding::Depth,
1043        ) -> fidl::Result<()> {
1044            encoder.debug_check_bounds::<ImageFormat>(offset);
1045            // Vector header
1046            let max_ordinal: u64 = self.max_ordinal_present();
1047            encoder.write_num(max_ordinal, offset);
1048            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1049            // Calling encoder.out_of_line_offset(0) is not allowed.
1050            if max_ordinal == 0 {
1051                return Ok(());
1052            }
1053            depth.increment()?;
1054            let envelope_size = 8;
1055            let bytes_len = max_ordinal as usize * envelope_size;
1056            #[allow(unused_variables)]
1057            let offset = encoder.out_of_line_offset(bytes_len);
1058            let mut _prev_end_offset: usize = 0;
1059            if 1 > max_ordinal {
1060                return Ok(());
1061            }
1062
1063            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1064            // are envelope_size bytes.
1065            let cur_offset: usize = (1 - 1) * envelope_size;
1066
1067            // Zero reserved fields.
1068            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1069
1070            // Safety:
1071            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1072            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1073            //   envelope_size bytes, there is always sufficient room.
1074            fidl::encoding::encode_in_envelope_optional::<PixelFormat, D>(
1075                self.pixel_format
1076                    .as_ref()
1077                    .map(<PixelFormat as fidl::encoding::ValueTypeMarker>::borrow),
1078                encoder,
1079                offset + cur_offset,
1080                depth,
1081            )?;
1082
1083            _prev_end_offset = cur_offset + envelope_size;
1084            if 2 > max_ordinal {
1085                return Ok(());
1086            }
1087
1088            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1089            // are envelope_size bytes.
1090            let cur_offset: usize = (2 - 1) * envelope_size;
1091
1092            // Zero reserved fields.
1093            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1094
1095            // Safety:
1096            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1097            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1098            //   envelope_size bytes, there is always sufficient room.
1099            fidl::encoding::encode_in_envelope_optional::<PixelFormatModifier, D>(
1100                self.pixel_format_modifier
1101                    .as_ref()
1102                    .map(<PixelFormatModifier as fidl::encoding::ValueTypeMarker>::borrow),
1103                encoder,
1104                offset + cur_offset,
1105                depth,
1106            )?;
1107
1108            _prev_end_offset = cur_offset + envelope_size;
1109            if 3 > max_ordinal {
1110                return Ok(());
1111            }
1112
1113            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1114            // are envelope_size bytes.
1115            let cur_offset: usize = (3 - 1) * envelope_size;
1116
1117            // Zero reserved fields.
1118            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1119
1120            // Safety:
1121            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1122            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1123            //   envelope_size bytes, there is always sufficient room.
1124            fidl::encoding::encode_in_envelope_optional::<ColorSpace, D>(
1125                self.color_space
1126                    .as_ref()
1127                    .map(<ColorSpace as fidl::encoding::ValueTypeMarker>::borrow),
1128                encoder,
1129                offset + cur_offset,
1130                depth,
1131            )?;
1132
1133            _prev_end_offset = cur_offset + envelope_size;
1134            if 4 > max_ordinal {
1135                return Ok(());
1136            }
1137
1138            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1139            // are envelope_size bytes.
1140            let cur_offset: usize = (4 - 1) * envelope_size;
1141
1142            // Zero reserved fields.
1143            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1144
1145            // Safety:
1146            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1147            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1148            //   envelope_size bytes, there is always sufficient room.
1149            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math_common::SizeU, D>(
1150                self.size.as_ref().map(
1151                    <fidl_fuchsia_math_common::SizeU as fidl::encoding::ValueTypeMarker>::borrow,
1152                ),
1153                encoder,
1154                offset + cur_offset,
1155                depth,
1156            )?;
1157
1158            _prev_end_offset = cur_offset + envelope_size;
1159            if 5 > max_ordinal {
1160                return Ok(());
1161            }
1162
1163            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1164            // are envelope_size bytes.
1165            let cur_offset: usize = (5 - 1) * envelope_size;
1166
1167            // Zero reserved fields.
1168            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1169
1170            // Safety:
1171            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1172            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1173            //   envelope_size bytes, there is always sufficient room.
1174            fidl::encoding::encode_in_envelope_optional::<u32, D>(
1175                self.bytes_per_row.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1176                encoder,
1177                offset + cur_offset,
1178                depth,
1179            )?;
1180
1181            _prev_end_offset = cur_offset + envelope_size;
1182            if 6 > max_ordinal {
1183                return Ok(());
1184            }
1185
1186            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1187            // are envelope_size bytes.
1188            let cur_offset: usize = (6 - 1) * envelope_size;
1189
1190            // Zero reserved fields.
1191            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1192
1193            // Safety:
1194            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1195            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1196            //   envelope_size bytes, there is always sufficient room.
1197            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math_common::RectU, D>(
1198                self.display_rect.as_ref().map(
1199                    <fidl_fuchsia_math_common::RectU as fidl::encoding::ValueTypeMarker>::borrow,
1200                ),
1201                encoder,
1202                offset + cur_offset,
1203                depth,
1204            )?;
1205
1206            _prev_end_offset = cur_offset + envelope_size;
1207            if 7 > max_ordinal {
1208                return Ok(());
1209            }
1210
1211            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1212            // are envelope_size bytes.
1213            let cur_offset: usize = (7 - 1) * envelope_size;
1214
1215            // Zero reserved fields.
1216            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1217
1218            // Safety:
1219            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1220            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1221            //   envelope_size bytes, there is always sufficient room.
1222            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math_common::SizeU, D>(
1223                self.valid_size.as_ref().map(
1224                    <fidl_fuchsia_math_common::SizeU as fidl::encoding::ValueTypeMarker>::borrow,
1225                ),
1226                encoder,
1227                offset + cur_offset,
1228                depth,
1229            )?;
1230
1231            _prev_end_offset = cur_offset + envelope_size;
1232            if 8 > max_ordinal {
1233                return Ok(());
1234            }
1235
1236            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1237            // are envelope_size bytes.
1238            let cur_offset: usize = (8 - 1) * envelope_size;
1239
1240            // Zero reserved fields.
1241            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1242
1243            // Safety:
1244            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1245            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1246            //   envelope_size bytes, there is always sufficient room.
1247            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math_common::SizeU, D>(
1248                self.pixel_aspect_ratio.as_ref().map(
1249                    <fidl_fuchsia_math_common::SizeU as fidl::encoding::ValueTypeMarker>::borrow,
1250                ),
1251                encoder,
1252                offset + cur_offset,
1253                depth,
1254            )?;
1255
1256            _prev_end_offset = cur_offset + envelope_size;
1257
1258            Ok(())
1259        }
1260    }
1261
1262    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ImageFormat {
1263        #[inline(always)]
1264        fn new_empty() -> Self {
1265            Self::default()
1266        }
1267
1268        unsafe fn decode(
1269            &mut self,
1270            decoder: &mut fidl::encoding::Decoder<'_, D>,
1271            offset: usize,
1272            mut depth: fidl::encoding::Depth,
1273        ) -> fidl::Result<()> {
1274            decoder.debug_check_bounds::<Self>(offset);
1275            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1276                None => return Err(fidl::Error::NotNullable),
1277                Some(len) => len,
1278            };
1279            // Calling decoder.out_of_line_offset(0) is not allowed.
1280            if len == 0 {
1281                return Ok(());
1282            };
1283            depth.increment()?;
1284            let envelope_size = 8;
1285            let bytes_len = len * envelope_size;
1286            let offset = decoder.out_of_line_offset(bytes_len)?;
1287            // Decode the envelope for each type.
1288            let mut _next_ordinal_to_read = 0;
1289            let mut next_offset = offset;
1290            let end_offset = offset + bytes_len;
1291            _next_ordinal_to_read += 1;
1292            if next_offset >= end_offset {
1293                return Ok(());
1294            }
1295
1296            // Decode unknown envelopes for gaps in ordinals.
1297            while _next_ordinal_to_read < 1 {
1298                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1299                _next_ordinal_to_read += 1;
1300                next_offset += envelope_size;
1301            }
1302
1303            let next_out_of_line = decoder.next_out_of_line();
1304            let handles_before = decoder.remaining_handles();
1305            if let Some((inlined, num_bytes, num_handles)) =
1306                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1307            {
1308                let member_inline_size =
1309                    <PixelFormat as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1310                if inlined != (member_inline_size <= 4) {
1311                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1312                }
1313                let inner_offset;
1314                let mut inner_depth = depth.clone();
1315                if inlined {
1316                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1317                    inner_offset = next_offset;
1318                } else {
1319                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1320                    inner_depth.increment()?;
1321                }
1322                let val_ref =
1323                    self.pixel_format.get_or_insert_with(|| fidl::new_empty!(PixelFormat, D));
1324                fidl::decode!(PixelFormat, D, val_ref, decoder, inner_offset, inner_depth)?;
1325                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1326                {
1327                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1328                }
1329                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1330                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1331                }
1332            }
1333
1334            next_offset += envelope_size;
1335            _next_ordinal_to_read += 1;
1336            if next_offset >= end_offset {
1337                return Ok(());
1338            }
1339
1340            // Decode unknown envelopes for gaps in ordinals.
1341            while _next_ordinal_to_read < 2 {
1342                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1343                _next_ordinal_to_read += 1;
1344                next_offset += envelope_size;
1345            }
1346
1347            let next_out_of_line = decoder.next_out_of_line();
1348            let handles_before = decoder.remaining_handles();
1349            if let Some((inlined, num_bytes, num_handles)) =
1350                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1351            {
1352                let member_inline_size =
1353                    <PixelFormatModifier as fidl::encoding::TypeMarker>::inline_size(
1354                        decoder.context,
1355                    );
1356                if inlined != (member_inline_size <= 4) {
1357                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1358                }
1359                let inner_offset;
1360                let mut inner_depth = depth.clone();
1361                if inlined {
1362                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1363                    inner_offset = next_offset;
1364                } else {
1365                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1366                    inner_depth.increment()?;
1367                }
1368                let val_ref = self
1369                    .pixel_format_modifier
1370                    .get_or_insert_with(|| fidl::new_empty!(PixelFormatModifier, D));
1371                fidl::decode!(PixelFormatModifier, D, val_ref, decoder, inner_offset, inner_depth)?;
1372                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1373                {
1374                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1375                }
1376                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1377                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1378                }
1379            }
1380
1381            next_offset += envelope_size;
1382            _next_ordinal_to_read += 1;
1383            if next_offset >= end_offset {
1384                return Ok(());
1385            }
1386
1387            // Decode unknown envelopes for gaps in ordinals.
1388            while _next_ordinal_to_read < 3 {
1389                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1390                _next_ordinal_to_read += 1;
1391                next_offset += envelope_size;
1392            }
1393
1394            let next_out_of_line = decoder.next_out_of_line();
1395            let handles_before = decoder.remaining_handles();
1396            if let Some((inlined, num_bytes, num_handles)) =
1397                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1398            {
1399                let member_inline_size =
1400                    <ColorSpace as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1401                if inlined != (member_inline_size <= 4) {
1402                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1403                }
1404                let inner_offset;
1405                let mut inner_depth = depth.clone();
1406                if inlined {
1407                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1408                    inner_offset = next_offset;
1409                } else {
1410                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1411                    inner_depth.increment()?;
1412                }
1413                let val_ref =
1414                    self.color_space.get_or_insert_with(|| fidl::new_empty!(ColorSpace, D));
1415                fidl::decode!(ColorSpace, D, val_ref, decoder, inner_offset, inner_depth)?;
1416                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1417                {
1418                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1419                }
1420                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1421                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1422                }
1423            }
1424
1425            next_offset += envelope_size;
1426            _next_ordinal_to_read += 1;
1427            if next_offset >= end_offset {
1428                return Ok(());
1429            }
1430
1431            // Decode unknown envelopes for gaps in ordinals.
1432            while _next_ordinal_to_read < 4 {
1433                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1434                _next_ordinal_to_read += 1;
1435                next_offset += envelope_size;
1436            }
1437
1438            let next_out_of_line = decoder.next_out_of_line();
1439            let handles_before = decoder.remaining_handles();
1440            if let Some((inlined, num_bytes, num_handles)) =
1441                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1442            {
1443                let member_inline_size =
1444                    <fidl_fuchsia_math_common::SizeU as fidl::encoding::TypeMarker>::inline_size(
1445                        decoder.context,
1446                    );
1447                if inlined != (member_inline_size <= 4) {
1448                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1449                }
1450                let inner_offset;
1451                let mut inner_depth = depth.clone();
1452                if inlined {
1453                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1454                    inner_offset = next_offset;
1455                } else {
1456                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1457                    inner_depth.increment()?;
1458                }
1459                let val_ref = self
1460                    .size
1461                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math_common::SizeU, D));
1462                fidl::decode!(
1463                    fidl_fuchsia_math_common::SizeU,
1464                    D,
1465                    val_ref,
1466                    decoder,
1467                    inner_offset,
1468                    inner_depth
1469                )?;
1470                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1471                {
1472                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1473                }
1474                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1475                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1476                }
1477            }
1478
1479            next_offset += envelope_size;
1480            _next_ordinal_to_read += 1;
1481            if next_offset >= end_offset {
1482                return Ok(());
1483            }
1484
1485            // Decode unknown envelopes for gaps in ordinals.
1486            while _next_ordinal_to_read < 5 {
1487                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1488                _next_ordinal_to_read += 1;
1489                next_offset += envelope_size;
1490            }
1491
1492            let next_out_of_line = decoder.next_out_of_line();
1493            let handles_before = decoder.remaining_handles();
1494            if let Some((inlined, num_bytes, num_handles)) =
1495                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1496            {
1497                let member_inline_size =
1498                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1499                if inlined != (member_inline_size <= 4) {
1500                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1501                }
1502                let inner_offset;
1503                let mut inner_depth = depth.clone();
1504                if inlined {
1505                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1506                    inner_offset = next_offset;
1507                } else {
1508                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1509                    inner_depth.increment()?;
1510                }
1511                let val_ref = self.bytes_per_row.get_or_insert_with(|| fidl::new_empty!(u32, D));
1512                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
1513                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1514                {
1515                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1516                }
1517                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1518                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1519                }
1520            }
1521
1522            next_offset += envelope_size;
1523            _next_ordinal_to_read += 1;
1524            if next_offset >= end_offset {
1525                return Ok(());
1526            }
1527
1528            // Decode unknown envelopes for gaps in ordinals.
1529            while _next_ordinal_to_read < 6 {
1530                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1531                _next_ordinal_to_read += 1;
1532                next_offset += envelope_size;
1533            }
1534
1535            let next_out_of_line = decoder.next_out_of_line();
1536            let handles_before = decoder.remaining_handles();
1537            if let Some((inlined, num_bytes, num_handles)) =
1538                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1539            {
1540                let member_inline_size =
1541                    <fidl_fuchsia_math_common::RectU as fidl::encoding::TypeMarker>::inline_size(
1542                        decoder.context,
1543                    );
1544                if inlined != (member_inline_size <= 4) {
1545                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1546                }
1547                let inner_offset;
1548                let mut inner_depth = depth.clone();
1549                if inlined {
1550                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1551                    inner_offset = next_offset;
1552                } else {
1553                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1554                    inner_depth.increment()?;
1555                }
1556                let val_ref = self
1557                    .display_rect
1558                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math_common::RectU, D));
1559                fidl::decode!(
1560                    fidl_fuchsia_math_common::RectU,
1561                    D,
1562                    val_ref,
1563                    decoder,
1564                    inner_offset,
1565                    inner_depth
1566                )?;
1567                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1568                {
1569                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1570                }
1571                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1572                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1573                }
1574            }
1575
1576            next_offset += envelope_size;
1577            _next_ordinal_to_read += 1;
1578            if next_offset >= end_offset {
1579                return Ok(());
1580            }
1581
1582            // Decode unknown envelopes for gaps in ordinals.
1583            while _next_ordinal_to_read < 7 {
1584                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1585                _next_ordinal_to_read += 1;
1586                next_offset += envelope_size;
1587            }
1588
1589            let next_out_of_line = decoder.next_out_of_line();
1590            let handles_before = decoder.remaining_handles();
1591            if let Some((inlined, num_bytes, num_handles)) =
1592                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1593            {
1594                let member_inline_size =
1595                    <fidl_fuchsia_math_common::SizeU as fidl::encoding::TypeMarker>::inline_size(
1596                        decoder.context,
1597                    );
1598                if inlined != (member_inline_size <= 4) {
1599                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1600                }
1601                let inner_offset;
1602                let mut inner_depth = depth.clone();
1603                if inlined {
1604                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1605                    inner_offset = next_offset;
1606                } else {
1607                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1608                    inner_depth.increment()?;
1609                }
1610                let val_ref = self
1611                    .valid_size
1612                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math_common::SizeU, D));
1613                fidl::decode!(
1614                    fidl_fuchsia_math_common::SizeU,
1615                    D,
1616                    val_ref,
1617                    decoder,
1618                    inner_offset,
1619                    inner_depth
1620                )?;
1621                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1622                {
1623                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1624                }
1625                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1626                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1627                }
1628            }
1629
1630            next_offset += envelope_size;
1631            _next_ordinal_to_read += 1;
1632            if next_offset >= end_offset {
1633                return Ok(());
1634            }
1635
1636            // Decode unknown envelopes for gaps in ordinals.
1637            while _next_ordinal_to_read < 8 {
1638                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1639                _next_ordinal_to_read += 1;
1640                next_offset += envelope_size;
1641            }
1642
1643            let next_out_of_line = decoder.next_out_of_line();
1644            let handles_before = decoder.remaining_handles();
1645            if let Some((inlined, num_bytes, num_handles)) =
1646                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1647            {
1648                let member_inline_size =
1649                    <fidl_fuchsia_math_common::SizeU as fidl::encoding::TypeMarker>::inline_size(
1650                        decoder.context,
1651                    );
1652                if inlined != (member_inline_size <= 4) {
1653                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1654                }
1655                let inner_offset;
1656                let mut inner_depth = depth.clone();
1657                if inlined {
1658                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1659                    inner_offset = next_offset;
1660                } else {
1661                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1662                    inner_depth.increment()?;
1663                }
1664                let val_ref = self
1665                    .pixel_aspect_ratio
1666                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math_common::SizeU, D));
1667                fidl::decode!(
1668                    fidl_fuchsia_math_common::SizeU,
1669                    D,
1670                    val_ref,
1671                    decoder,
1672                    inner_offset,
1673                    inner_depth
1674                )?;
1675                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1676                {
1677                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1678                }
1679                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1680                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1681                }
1682            }
1683
1684            next_offset += envelope_size;
1685
1686            // Decode the remaining unknown envelopes.
1687            while next_offset < end_offset {
1688                _next_ordinal_to_read += 1;
1689                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1690                next_offset += envelope_size;
1691            }
1692
1693            Ok(())
1694        }
1695    }
1696}