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