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
660    /// the end of each row of pixels. If greater, the difference is how much
661    /// padding is at the end of each row of pixels, in bytes.
662    ///
663    /// This is also known as the "stride", "line to line offset", "row to row
664    /// offset", and other names.
665    ///
666    /// As a specific example, it's not uncommon (but also not always required)
667    /// for BGR24 (3 bytes per pixel) to have some padding at the end of each
668    /// row so that each row of pixels starts at a 4 byte aligned offset from
669    /// the start of the image (the upper left pixel). That padding's size is
670    /// not necessarily divisible by the size in bytes of a pixel ("stride bytes
671    /// per width pixel"), so we indicate the padding using this field rather
672    /// than trying to incorporate the padding as a larger "fake"
673    /// `size.width`.
674    pub bytes_per_row: Option<u32>,
675    /// The rect within a frame that's for display. This is the location and
676    /// size in pixels of the rectangle of pixels that should be displayed, when
677    /// displaying the "whole image" in a UI display sense.
678    ///
679    /// The `x` + `width` must be <= `size.width`, and the `y` + `height` must
680    /// be <= `size.height`.
681    ///
682    /// For output from a video decoder, pixels outside the display_rect are
683    /// never to be displayed (outside of test programs), but must be preserved
684    /// for correct decoder function.  The `display_rect` will always fall
685    /// within the rect starting at (0, 0) and having `valid_size` size, when
686    /// `valid_size` is set.  In other words, `display_rect` is a subset (not
687    /// necessarily a proper subset) of `valid_size`, and `valid_size` is a
688    /// subset (not necessarily a proper subset) of `size`.
689    ///
690    /// Downstream texture filtering operations should avoid letting any pixel
691    /// outside of display_rect influence the visual appearance of any displayed
692    /// pixel, to avoid the potential for the right or bottom edge leaking in
693    /// arbitrary pixels defined by the decode process but not intended for
694    /// display.
695    ///
696    /// Behavior when this field is not set is protocol-specific. In some
697    /// protocols, fallback to `valid_size`, then to `size` may be implemented.
698    /// In others, fallback directly to `size` may be implemented. In others,
699    /// this field must be set or the channel will close.
700    ///
701    /// WARNING: fuchsia.sysmem.Images2 (V1) doesn't handle non-zero x, y, so
702    /// any non-zero x, y here (V2) will prevent conversion to V1.  Due to the
703    /// rarity of non-zero x, y in practice, even components that have moved to
704    /// V2 may in some cases still assume both x and y are 0, until there's a
705    /// practical reason to implment and test handling of non-zero x, y.  The
706    /// symptom of sending non-zero x, y to a downstream render and/or display
707    /// pipeline that assumes 0, 0 will be incorrect display, but not a crash,
708    /// since assuming 0, 0 for x, y does not cause reading out of buffer
709    /// bounds.
710    pub display_rect: Option<fidl_fuchsia_math__common::RectU>,
711    /// The size of a frame in terms of the number of pixels that have valid
712    /// pixel data in terms of video decoding, but not in terms of which pixels
713    /// are intended for display.
714    ///
715    /// To convert valid_size into a rect that's directly comparable to
716    /// `display_rect`, one can make a rect with (`x`: 0, `y`: 0, `width`:
717    /// `valid_size.width`, `height`: `valid_size.height`).
718    ///
719    /// In the case of a video decoder, `valid_size` can include some pixels
720    /// outside `display_rect`. The extra pixels are not meant to be displayed,
721    /// and may or may not contain any real image data. Typically anything that
722    /// looks like real image data in these regions is only an artifact of video
723    /// compression and the existence of the remainder of a macroblock which can
724    /// be referenced by later frames despite not being within the displayed
725    /// region, and not really any additional "real" pixels from the source. The
726    /// pixel values in this region are defined by the codec decode process and
727    /// must be retained for correct decoder operation. Typically the pixels
728    /// inside valid_size but outside display_rect will be up to the size of a
729    /// macroblock minus 1. The `valid_size` is can be useful for testing video
730    /// decoders and for certain transcoding scenarios.
731    pub valid_size: Option<fidl_fuchsia_math__common::SizeU>,
732    /// Aspect ratio of a single pixel as the video is intended to be displayed.
733    ///
734    /// For YUV formats, this is the pixel aspect ratio (AKA sample aspect ratio
735    /// aka SAR) for the luma (AKA Y) samples.
736    ///
737    /// Producers should ensure the width and height values are relatively prime
738    /// by reducing the fraction (dividing both by GCF) if necessary.
739    ///
740    /// A consumer should interpret this field being un-set as an unknown pixel
741    /// aspect ratio.  A default of 1:1 can be appropriate in some cases, but a
742    /// consumer may determine the actual pixel aspect ratio by OOB means.
743    pub pixel_aspect_ratio: Option<fidl_fuchsia_math__common::SizeU>,
744    #[doc(hidden)]
745    pub __source_breaking: fidl::marker::SourceBreaking,
746}
747
748impl fidl::Persistable for ImageFormat {}
749
750mod internal {
751    use super::*;
752    unsafe impl fidl::encoding::TypeMarker for ColorSpace {
753        type Owned = Self;
754
755        #[inline(always)]
756        fn inline_align(_context: fidl::encoding::Context) -> usize {
757            std::mem::align_of::<u32>()
758        }
759
760        #[inline(always)]
761        fn inline_size(_context: fidl::encoding::Context) -> usize {
762            std::mem::size_of::<u32>()
763        }
764
765        #[inline(always)]
766        fn encode_is_copy() -> bool {
767            false
768        }
769
770        #[inline(always)]
771        fn decode_is_copy() -> bool {
772            false
773        }
774    }
775
776    impl fidl::encoding::ValueTypeMarker for ColorSpace {
777        type Borrowed<'a> = Self;
778        #[inline(always)]
779        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
780            *value
781        }
782    }
783
784    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for ColorSpace {
785        #[inline]
786        unsafe fn encode(
787            self,
788            encoder: &mut fidl::encoding::Encoder<'_, D>,
789            offset: usize,
790            _depth: fidl::encoding::Depth,
791        ) -> fidl::Result<()> {
792            encoder.debug_check_bounds::<Self>(offset);
793            encoder.write_num(self.into_primitive(), offset);
794            Ok(())
795        }
796    }
797
798    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ColorSpace {
799        #[inline(always)]
800        fn new_empty() -> Self {
801            Self::unknown()
802        }
803
804        #[inline]
805        unsafe fn decode(
806            &mut self,
807            decoder: &mut fidl::encoding::Decoder<'_, D>,
808            offset: usize,
809            _depth: fidl::encoding::Depth,
810        ) -> fidl::Result<()> {
811            decoder.debug_check_bounds::<Self>(offset);
812            let prim = decoder.read_num::<u32>(offset);
813
814            *self = Self::from_primitive_allow_unknown(prim);
815            Ok(())
816        }
817    }
818    unsafe impl fidl::encoding::TypeMarker for PixelFormat {
819        type Owned = Self;
820
821        #[inline(always)]
822        fn inline_align(_context: fidl::encoding::Context) -> usize {
823            std::mem::align_of::<u32>()
824        }
825
826        #[inline(always)]
827        fn inline_size(_context: fidl::encoding::Context) -> usize {
828            std::mem::size_of::<u32>()
829        }
830
831        #[inline(always)]
832        fn encode_is_copy() -> bool {
833            false
834        }
835
836        #[inline(always)]
837        fn decode_is_copy() -> bool {
838            false
839        }
840    }
841
842    impl fidl::encoding::ValueTypeMarker for PixelFormat {
843        type Borrowed<'a> = Self;
844        #[inline(always)]
845        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
846            *value
847        }
848    }
849
850    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for PixelFormat {
851        #[inline]
852        unsafe fn encode(
853            self,
854            encoder: &mut fidl::encoding::Encoder<'_, D>,
855            offset: usize,
856            _depth: fidl::encoding::Depth,
857        ) -> fidl::Result<()> {
858            encoder.debug_check_bounds::<Self>(offset);
859            encoder.write_num(self.into_primitive(), offset);
860            Ok(())
861        }
862    }
863
864    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PixelFormat {
865        #[inline(always)]
866        fn new_empty() -> Self {
867            Self::unknown()
868        }
869
870        #[inline]
871        unsafe fn decode(
872            &mut self,
873            decoder: &mut fidl::encoding::Decoder<'_, D>,
874            offset: usize,
875            _depth: fidl::encoding::Depth,
876        ) -> fidl::Result<()> {
877            decoder.debug_check_bounds::<Self>(offset);
878            let prim = decoder.read_num::<u32>(offset);
879
880            *self = Self::from_primitive_allow_unknown(prim);
881            Ok(())
882        }
883    }
884    unsafe impl fidl::encoding::TypeMarker for PixelFormatModifier {
885        type Owned = Self;
886
887        #[inline(always)]
888        fn inline_align(_context: fidl::encoding::Context) -> usize {
889            std::mem::align_of::<u64>()
890        }
891
892        #[inline(always)]
893        fn inline_size(_context: fidl::encoding::Context) -> usize {
894            std::mem::size_of::<u64>()
895        }
896
897        #[inline(always)]
898        fn encode_is_copy() -> bool {
899            false
900        }
901
902        #[inline(always)]
903        fn decode_is_copy() -> bool {
904            false
905        }
906    }
907
908    impl fidl::encoding::ValueTypeMarker for PixelFormatModifier {
909        type Borrowed<'a> = Self;
910        #[inline(always)]
911        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
912            *value
913        }
914    }
915
916    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
917        for PixelFormatModifier
918    {
919        #[inline]
920        unsafe fn encode(
921            self,
922            encoder: &mut fidl::encoding::Encoder<'_, D>,
923            offset: usize,
924            _depth: fidl::encoding::Depth,
925        ) -> fidl::Result<()> {
926            encoder.debug_check_bounds::<Self>(offset);
927            encoder.write_num(self.into_primitive(), offset);
928            Ok(())
929        }
930    }
931
932    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PixelFormatModifier {
933        #[inline(always)]
934        fn new_empty() -> Self {
935            Self::unknown()
936        }
937
938        #[inline]
939        unsafe fn decode(
940            &mut self,
941            decoder: &mut fidl::encoding::Decoder<'_, D>,
942            offset: usize,
943            _depth: fidl::encoding::Depth,
944        ) -> fidl::Result<()> {
945            decoder.debug_check_bounds::<Self>(offset);
946            let prim = decoder.read_num::<u64>(offset);
947
948            *self = Self::from_primitive_allow_unknown(prim);
949            Ok(())
950        }
951    }
952
953    impl ImageFormat {
954        #[inline(always)]
955        fn max_ordinal_present(&self) -> u64 {
956            if let Some(_) = self.pixel_aspect_ratio {
957                return 8;
958            }
959            if let Some(_) = self.valid_size {
960                return 7;
961            }
962            if let Some(_) = self.display_rect {
963                return 6;
964            }
965            if let Some(_) = self.bytes_per_row {
966                return 5;
967            }
968            if let Some(_) = self.size {
969                return 4;
970            }
971            if let Some(_) = self.color_space {
972                return 3;
973            }
974            if let Some(_) = self.pixel_format_modifier {
975                return 2;
976            }
977            if let Some(_) = self.pixel_format {
978                return 1;
979            }
980            0
981        }
982    }
983
984    impl fidl::encoding::ValueTypeMarker for ImageFormat {
985        type Borrowed<'a> = &'a Self;
986        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
987            value
988        }
989    }
990
991    unsafe impl fidl::encoding::TypeMarker for ImageFormat {
992        type Owned = Self;
993
994        #[inline(always)]
995        fn inline_align(_context: fidl::encoding::Context) -> usize {
996            8
997        }
998
999        #[inline(always)]
1000        fn inline_size(_context: fidl::encoding::Context) -> usize {
1001            16
1002        }
1003    }
1004
1005    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ImageFormat, D>
1006        for &ImageFormat
1007    {
1008        unsafe fn encode(
1009            self,
1010            encoder: &mut fidl::encoding::Encoder<'_, D>,
1011            offset: usize,
1012            mut depth: fidl::encoding::Depth,
1013        ) -> fidl::Result<()> {
1014            encoder.debug_check_bounds::<ImageFormat>(offset);
1015            // Vector header
1016            let max_ordinal: u64 = self.max_ordinal_present();
1017            encoder.write_num(max_ordinal, offset);
1018            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1019            // Calling encoder.out_of_line_offset(0) is not allowed.
1020            if max_ordinal == 0 {
1021                return Ok(());
1022            }
1023            depth.increment()?;
1024            let envelope_size = 8;
1025            let bytes_len = max_ordinal as usize * envelope_size;
1026            #[allow(unused_variables)]
1027            let offset = encoder.out_of_line_offset(bytes_len);
1028            let mut _prev_end_offset: usize = 0;
1029            if 1 > max_ordinal {
1030                return Ok(());
1031            }
1032
1033            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1034            // are envelope_size bytes.
1035            let cur_offset: usize = (1 - 1) * envelope_size;
1036
1037            // Zero reserved fields.
1038            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1039
1040            // Safety:
1041            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1042            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1043            //   envelope_size bytes, there is always sufficient room.
1044            fidl::encoding::encode_in_envelope_optional::<PixelFormat, D>(
1045                self.pixel_format
1046                    .as_ref()
1047                    .map(<PixelFormat as fidl::encoding::ValueTypeMarker>::borrow),
1048                encoder,
1049                offset + cur_offset,
1050                depth,
1051            )?;
1052
1053            _prev_end_offset = cur_offset + envelope_size;
1054            if 2 > max_ordinal {
1055                return Ok(());
1056            }
1057
1058            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1059            // are envelope_size bytes.
1060            let cur_offset: usize = (2 - 1) * envelope_size;
1061
1062            // Zero reserved fields.
1063            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1064
1065            // Safety:
1066            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1067            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1068            //   envelope_size bytes, there is always sufficient room.
1069            fidl::encoding::encode_in_envelope_optional::<PixelFormatModifier, D>(
1070                self.pixel_format_modifier
1071                    .as_ref()
1072                    .map(<PixelFormatModifier as fidl::encoding::ValueTypeMarker>::borrow),
1073                encoder,
1074                offset + cur_offset,
1075                depth,
1076            )?;
1077
1078            _prev_end_offset = cur_offset + envelope_size;
1079            if 3 > max_ordinal {
1080                return Ok(());
1081            }
1082
1083            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1084            // are envelope_size bytes.
1085            let cur_offset: usize = (3 - 1) * envelope_size;
1086
1087            // Zero reserved fields.
1088            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1089
1090            // Safety:
1091            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1092            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1093            //   envelope_size bytes, there is always sufficient room.
1094            fidl::encoding::encode_in_envelope_optional::<ColorSpace, D>(
1095                self.color_space
1096                    .as_ref()
1097                    .map(<ColorSpace as fidl::encoding::ValueTypeMarker>::borrow),
1098                encoder,
1099                offset + cur_offset,
1100                depth,
1101            )?;
1102
1103            _prev_end_offset = cur_offset + envelope_size;
1104            if 4 > max_ordinal {
1105                return Ok(());
1106            }
1107
1108            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1109            // are envelope_size bytes.
1110            let cur_offset: usize = (4 - 1) * envelope_size;
1111
1112            // Zero reserved fields.
1113            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1114
1115            // Safety:
1116            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1117            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1118            //   envelope_size bytes, there is always sufficient room.
1119            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math__common::SizeU, D>(
1120                self.size.as_ref().map(
1121                    <fidl_fuchsia_math__common::SizeU as fidl::encoding::ValueTypeMarker>::borrow,
1122                ),
1123                encoder,
1124                offset + cur_offset,
1125                depth,
1126            )?;
1127
1128            _prev_end_offset = cur_offset + envelope_size;
1129            if 5 > max_ordinal {
1130                return Ok(());
1131            }
1132
1133            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1134            // are envelope_size bytes.
1135            let cur_offset: usize = (5 - 1) * envelope_size;
1136
1137            // Zero reserved fields.
1138            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1139
1140            // Safety:
1141            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1142            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1143            //   envelope_size bytes, there is always sufficient room.
1144            fidl::encoding::encode_in_envelope_optional::<u32, D>(
1145                self.bytes_per_row.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1146                encoder,
1147                offset + cur_offset,
1148                depth,
1149            )?;
1150
1151            _prev_end_offset = cur_offset + envelope_size;
1152            if 6 > max_ordinal {
1153                return Ok(());
1154            }
1155
1156            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1157            // are envelope_size bytes.
1158            let cur_offset: usize = (6 - 1) * envelope_size;
1159
1160            // Zero reserved fields.
1161            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1162
1163            // Safety:
1164            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1165            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1166            //   envelope_size bytes, there is always sufficient room.
1167            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math__common::RectU, D>(
1168                self.display_rect.as_ref().map(
1169                    <fidl_fuchsia_math__common::RectU as fidl::encoding::ValueTypeMarker>::borrow,
1170                ),
1171                encoder,
1172                offset + cur_offset,
1173                depth,
1174            )?;
1175
1176            _prev_end_offset = cur_offset + envelope_size;
1177            if 7 > max_ordinal {
1178                return Ok(());
1179            }
1180
1181            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1182            // are envelope_size bytes.
1183            let cur_offset: usize = (7 - 1) * envelope_size;
1184
1185            // Zero reserved fields.
1186            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1187
1188            // Safety:
1189            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1190            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1191            //   envelope_size bytes, there is always sufficient room.
1192            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math__common::SizeU, D>(
1193                self.valid_size.as_ref().map(
1194                    <fidl_fuchsia_math__common::SizeU as fidl::encoding::ValueTypeMarker>::borrow,
1195                ),
1196                encoder,
1197                offset + cur_offset,
1198                depth,
1199            )?;
1200
1201            _prev_end_offset = cur_offset + envelope_size;
1202            if 8 > max_ordinal {
1203                return Ok(());
1204            }
1205
1206            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1207            // are envelope_size bytes.
1208            let cur_offset: usize = (8 - 1) * envelope_size;
1209
1210            // Zero reserved fields.
1211            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1212
1213            // Safety:
1214            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1215            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1216            //   envelope_size bytes, there is always sufficient room.
1217            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_math__common::SizeU, D>(
1218                self.pixel_aspect_ratio.as_ref().map(
1219                    <fidl_fuchsia_math__common::SizeU as fidl::encoding::ValueTypeMarker>::borrow,
1220                ),
1221                encoder,
1222                offset + cur_offset,
1223                depth,
1224            )?;
1225
1226            _prev_end_offset = cur_offset + envelope_size;
1227
1228            Ok(())
1229        }
1230    }
1231
1232    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ImageFormat {
1233        #[inline(always)]
1234        fn new_empty() -> Self {
1235            Self::default()
1236        }
1237
1238        unsafe fn decode(
1239            &mut self,
1240            decoder: &mut fidl::encoding::Decoder<'_, D>,
1241            offset: usize,
1242            mut depth: fidl::encoding::Depth,
1243        ) -> fidl::Result<()> {
1244            decoder.debug_check_bounds::<Self>(offset);
1245            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1246                None => return Err(fidl::Error::NotNullable),
1247                Some(len) => len,
1248            };
1249            // Calling decoder.out_of_line_offset(0) is not allowed.
1250            if len == 0 {
1251                return Ok(());
1252            };
1253            depth.increment()?;
1254            let envelope_size = 8;
1255            let bytes_len = len * envelope_size;
1256            let offset = decoder.out_of_line_offset(bytes_len)?;
1257            // Decode the envelope for each type.
1258            let mut _next_ordinal_to_read = 0;
1259            let mut next_offset = offset;
1260            let end_offset = offset + bytes_len;
1261            _next_ordinal_to_read += 1;
1262            if next_offset >= end_offset {
1263                return Ok(());
1264            }
1265
1266            // Decode unknown envelopes for gaps in ordinals.
1267            while _next_ordinal_to_read < 1 {
1268                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1269                _next_ordinal_to_read += 1;
1270                next_offset += envelope_size;
1271            }
1272
1273            let next_out_of_line = decoder.next_out_of_line();
1274            let handles_before = decoder.remaining_handles();
1275            if let Some((inlined, num_bytes, num_handles)) =
1276                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1277            {
1278                let member_inline_size =
1279                    <PixelFormat as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1280                if inlined != (member_inline_size <= 4) {
1281                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1282                }
1283                let inner_offset;
1284                let mut inner_depth = depth.clone();
1285                if inlined {
1286                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1287                    inner_offset = next_offset;
1288                } else {
1289                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1290                    inner_depth.increment()?;
1291                }
1292                let val_ref =
1293                    self.pixel_format.get_or_insert_with(|| fidl::new_empty!(PixelFormat, D));
1294                fidl::decode!(PixelFormat, D, val_ref, decoder, inner_offset, inner_depth)?;
1295                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1296                {
1297                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1298                }
1299                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1300                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1301                }
1302            }
1303
1304            next_offset += envelope_size;
1305            _next_ordinal_to_read += 1;
1306            if next_offset >= end_offset {
1307                return Ok(());
1308            }
1309
1310            // Decode unknown envelopes for gaps in ordinals.
1311            while _next_ordinal_to_read < 2 {
1312                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1313                _next_ordinal_to_read += 1;
1314                next_offset += envelope_size;
1315            }
1316
1317            let next_out_of_line = decoder.next_out_of_line();
1318            let handles_before = decoder.remaining_handles();
1319            if let Some((inlined, num_bytes, num_handles)) =
1320                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1321            {
1322                let member_inline_size =
1323                    <PixelFormatModifier as fidl::encoding::TypeMarker>::inline_size(
1324                        decoder.context,
1325                    );
1326                if inlined != (member_inline_size <= 4) {
1327                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1328                }
1329                let inner_offset;
1330                let mut inner_depth = depth.clone();
1331                if inlined {
1332                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1333                    inner_offset = next_offset;
1334                } else {
1335                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1336                    inner_depth.increment()?;
1337                }
1338                let val_ref = self
1339                    .pixel_format_modifier
1340                    .get_or_insert_with(|| fidl::new_empty!(PixelFormatModifier, D));
1341                fidl::decode!(PixelFormatModifier, D, val_ref, decoder, inner_offset, inner_depth)?;
1342                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1343                {
1344                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1345                }
1346                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1347                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1348                }
1349            }
1350
1351            next_offset += envelope_size;
1352            _next_ordinal_to_read += 1;
1353            if next_offset >= end_offset {
1354                return Ok(());
1355            }
1356
1357            // Decode unknown envelopes for gaps in ordinals.
1358            while _next_ordinal_to_read < 3 {
1359                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1360                _next_ordinal_to_read += 1;
1361                next_offset += envelope_size;
1362            }
1363
1364            let next_out_of_line = decoder.next_out_of_line();
1365            let handles_before = decoder.remaining_handles();
1366            if let Some((inlined, num_bytes, num_handles)) =
1367                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1368            {
1369                let member_inline_size =
1370                    <ColorSpace as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1371                if inlined != (member_inline_size <= 4) {
1372                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1373                }
1374                let inner_offset;
1375                let mut inner_depth = depth.clone();
1376                if inlined {
1377                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1378                    inner_offset = next_offset;
1379                } else {
1380                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1381                    inner_depth.increment()?;
1382                }
1383                let val_ref =
1384                    self.color_space.get_or_insert_with(|| fidl::new_empty!(ColorSpace, D));
1385                fidl::decode!(ColorSpace, D, val_ref, decoder, inner_offset, inner_depth)?;
1386                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1387                {
1388                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1389                }
1390                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1391                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1392                }
1393            }
1394
1395            next_offset += envelope_size;
1396            _next_ordinal_to_read += 1;
1397            if next_offset >= end_offset {
1398                return Ok(());
1399            }
1400
1401            // Decode unknown envelopes for gaps in ordinals.
1402            while _next_ordinal_to_read < 4 {
1403                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1404                _next_ordinal_to_read += 1;
1405                next_offset += envelope_size;
1406            }
1407
1408            let next_out_of_line = decoder.next_out_of_line();
1409            let handles_before = decoder.remaining_handles();
1410            if let Some((inlined, num_bytes, num_handles)) =
1411                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1412            {
1413                let member_inline_size =
1414                    <fidl_fuchsia_math__common::SizeU as fidl::encoding::TypeMarker>::inline_size(
1415                        decoder.context,
1416                    );
1417                if inlined != (member_inline_size <= 4) {
1418                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1419                }
1420                let inner_offset;
1421                let mut inner_depth = depth.clone();
1422                if inlined {
1423                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1424                    inner_offset = next_offset;
1425                } else {
1426                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1427                    inner_depth.increment()?;
1428                }
1429                let val_ref = self
1430                    .size
1431                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math__common::SizeU, D));
1432                fidl::decode!(
1433                    fidl_fuchsia_math__common::SizeU,
1434                    D,
1435                    val_ref,
1436                    decoder,
1437                    inner_offset,
1438                    inner_depth
1439                )?;
1440                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1441                {
1442                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1443                }
1444                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1445                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1446                }
1447            }
1448
1449            next_offset += envelope_size;
1450            _next_ordinal_to_read += 1;
1451            if next_offset >= end_offset {
1452                return Ok(());
1453            }
1454
1455            // Decode unknown envelopes for gaps in ordinals.
1456            while _next_ordinal_to_read < 5 {
1457                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1458                _next_ordinal_to_read += 1;
1459                next_offset += envelope_size;
1460            }
1461
1462            let next_out_of_line = decoder.next_out_of_line();
1463            let handles_before = decoder.remaining_handles();
1464            if let Some((inlined, num_bytes, num_handles)) =
1465                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1466            {
1467                let member_inline_size =
1468                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1469                if inlined != (member_inline_size <= 4) {
1470                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1471                }
1472                let inner_offset;
1473                let mut inner_depth = depth.clone();
1474                if inlined {
1475                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1476                    inner_offset = next_offset;
1477                } else {
1478                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1479                    inner_depth.increment()?;
1480                }
1481                let val_ref = self.bytes_per_row.get_or_insert_with(|| fidl::new_empty!(u32, D));
1482                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
1483                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1484                {
1485                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1486                }
1487                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1488                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1489                }
1490            }
1491
1492            next_offset += envelope_size;
1493            _next_ordinal_to_read += 1;
1494            if next_offset >= end_offset {
1495                return Ok(());
1496            }
1497
1498            // Decode unknown envelopes for gaps in ordinals.
1499            while _next_ordinal_to_read < 6 {
1500                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1501                _next_ordinal_to_read += 1;
1502                next_offset += envelope_size;
1503            }
1504
1505            let next_out_of_line = decoder.next_out_of_line();
1506            let handles_before = decoder.remaining_handles();
1507            if let Some((inlined, num_bytes, num_handles)) =
1508                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1509            {
1510                let member_inline_size =
1511                    <fidl_fuchsia_math__common::RectU as fidl::encoding::TypeMarker>::inline_size(
1512                        decoder.context,
1513                    );
1514                if inlined != (member_inline_size <= 4) {
1515                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1516                }
1517                let inner_offset;
1518                let mut inner_depth = depth.clone();
1519                if inlined {
1520                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1521                    inner_offset = next_offset;
1522                } else {
1523                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1524                    inner_depth.increment()?;
1525                }
1526                let val_ref = self
1527                    .display_rect
1528                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math__common::RectU, D));
1529                fidl::decode!(
1530                    fidl_fuchsia_math__common::RectU,
1531                    D,
1532                    val_ref,
1533                    decoder,
1534                    inner_offset,
1535                    inner_depth
1536                )?;
1537                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1538                {
1539                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1540                }
1541                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1542                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1543                }
1544            }
1545
1546            next_offset += envelope_size;
1547            _next_ordinal_to_read += 1;
1548            if next_offset >= end_offset {
1549                return Ok(());
1550            }
1551
1552            // Decode unknown envelopes for gaps in ordinals.
1553            while _next_ordinal_to_read < 7 {
1554                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1555                _next_ordinal_to_read += 1;
1556                next_offset += envelope_size;
1557            }
1558
1559            let next_out_of_line = decoder.next_out_of_line();
1560            let handles_before = decoder.remaining_handles();
1561            if let Some((inlined, num_bytes, num_handles)) =
1562                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1563            {
1564                let member_inline_size =
1565                    <fidl_fuchsia_math__common::SizeU as fidl::encoding::TypeMarker>::inline_size(
1566                        decoder.context,
1567                    );
1568                if inlined != (member_inline_size <= 4) {
1569                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1570                }
1571                let inner_offset;
1572                let mut inner_depth = depth.clone();
1573                if inlined {
1574                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1575                    inner_offset = next_offset;
1576                } else {
1577                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1578                    inner_depth.increment()?;
1579                }
1580                let val_ref = self
1581                    .valid_size
1582                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math__common::SizeU, D));
1583                fidl::decode!(
1584                    fidl_fuchsia_math__common::SizeU,
1585                    D,
1586                    val_ref,
1587                    decoder,
1588                    inner_offset,
1589                    inner_depth
1590                )?;
1591                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1592                {
1593                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1594                }
1595                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1596                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1597                }
1598            }
1599
1600            next_offset += envelope_size;
1601            _next_ordinal_to_read += 1;
1602            if next_offset >= end_offset {
1603                return Ok(());
1604            }
1605
1606            // Decode unknown envelopes for gaps in ordinals.
1607            while _next_ordinal_to_read < 8 {
1608                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1609                _next_ordinal_to_read += 1;
1610                next_offset += envelope_size;
1611            }
1612
1613            let next_out_of_line = decoder.next_out_of_line();
1614            let handles_before = decoder.remaining_handles();
1615            if let Some((inlined, num_bytes, num_handles)) =
1616                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1617            {
1618                let member_inline_size =
1619                    <fidl_fuchsia_math__common::SizeU as fidl::encoding::TypeMarker>::inline_size(
1620                        decoder.context,
1621                    );
1622                if inlined != (member_inline_size <= 4) {
1623                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1624                }
1625                let inner_offset;
1626                let mut inner_depth = depth.clone();
1627                if inlined {
1628                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1629                    inner_offset = next_offset;
1630                } else {
1631                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1632                    inner_depth.increment()?;
1633                }
1634                let val_ref = self
1635                    .pixel_aspect_ratio
1636                    .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_math__common::SizeU, D));
1637                fidl::decode!(
1638                    fidl_fuchsia_math__common::SizeU,
1639                    D,
1640                    val_ref,
1641                    decoder,
1642                    inner_offset,
1643                    inner_depth
1644                )?;
1645                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1646                {
1647                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1648                }
1649                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1650                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1651                }
1652            }
1653
1654            next_offset += envelope_size;
1655
1656            // Decode the remaining unknown envelopes.
1657            while next_offset < end_offset {
1658                _next_ordinal_to_read += 1;
1659                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1660                next_offset += envelope_size;
1661            }
1662
1663            Ok(())
1664        }
1665    }
1666}