fidl_fuchsia_images/
fidl_fuchsia_images.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::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_images__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct ImagePipe2AddBufferCollection2Request {
16    pub buffer_collection_id: u32,
17    pub buffer_collection_token:
18        fidl::endpoints::ClientEnd<fidl_fuchsia_sysmem2::BufferCollectionTokenMarker>,
19}
20
21impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
22    for ImagePipe2AddBufferCollection2Request
23{
24}
25
26#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
27pub struct ImagePipe2AddBufferCollectionRequest {
28    pub buffer_collection_id: u32,
29    pub buffer_collection_token:
30        fidl::endpoints::ClientEnd<fidl_fuchsia_sysmem::BufferCollectionTokenMarker>,
31}
32
33impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
34    for ImagePipe2AddBufferCollectionRequest
35{
36}
37
38#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
39pub struct ImagePipe2PresentImageRequest {
40    pub image_id: u32,
41    pub presentation_time: u64,
42    pub acquire_fences: Vec<fidl::Event>,
43    pub release_fences: Vec<fidl::Event>,
44}
45
46impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
47    for ImagePipe2PresentImageRequest
48{
49}
50
51#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
52pub struct ImagePipe2Marker;
53
54impl fidl::endpoints::ProtocolMarker for ImagePipe2Marker {
55    type Proxy = ImagePipe2Proxy;
56    type RequestStream = ImagePipe2RequestStream;
57    #[cfg(target_os = "fuchsia")]
58    type SynchronousProxy = ImagePipe2SynchronousProxy;
59
60    const DEBUG_NAME: &'static str = "(anonymous) ImagePipe2";
61}
62
63pub trait ImagePipe2ProxyInterface: Send + Sync {
64    fn r#add_buffer_collection2(
65        &self,
66        buffer_collection_id: u32,
67        buffer_collection_token: fidl::endpoints::ClientEnd<
68            fidl_fuchsia_sysmem2::BufferCollectionTokenMarker,
69        >,
70    ) -> Result<(), fidl::Error>;
71    fn r#add_buffer_collection(
72        &self,
73        buffer_collection_id: u32,
74        buffer_collection_token: fidl::endpoints::ClientEnd<
75            fidl_fuchsia_sysmem::BufferCollectionTokenMarker,
76        >,
77    ) -> Result<(), fidl::Error>;
78    fn r#add_image(
79        &self,
80        image_id: u32,
81        buffer_collection_id: u32,
82        buffer_collection_index: u32,
83        image_format: &fidl_fuchsia_sysmem::ImageFormat2,
84    ) -> Result<(), fidl::Error>;
85    fn r#remove_buffer_collection(&self, buffer_collection_id: u32) -> Result<(), fidl::Error>;
86    fn r#remove_image(&self, image_id: u32) -> Result<(), fidl::Error>;
87    type PresentImageResponseFut: std::future::Future<Output = Result<PresentationInfo, fidl::Error>>
88        + Send;
89    fn r#present_image(
90        &self,
91        image_id: u32,
92        presentation_time: u64,
93        acquire_fences: Vec<fidl::Event>,
94        release_fences: Vec<fidl::Event>,
95    ) -> Self::PresentImageResponseFut;
96}
97#[derive(Debug)]
98#[cfg(target_os = "fuchsia")]
99pub struct ImagePipe2SynchronousProxy {
100    client: fidl::client::sync::Client,
101}
102
103#[cfg(target_os = "fuchsia")]
104impl fidl::endpoints::SynchronousProxy for ImagePipe2SynchronousProxy {
105    type Proxy = ImagePipe2Proxy;
106    type Protocol = ImagePipe2Marker;
107
108    fn from_channel(inner: fidl::Channel) -> Self {
109        Self::new(inner)
110    }
111
112    fn into_channel(self) -> fidl::Channel {
113        self.client.into_channel()
114    }
115
116    fn as_channel(&self) -> &fidl::Channel {
117        self.client.as_channel()
118    }
119}
120
121#[cfg(target_os = "fuchsia")]
122impl ImagePipe2SynchronousProxy {
123    pub fn new(channel: fidl::Channel) -> Self {
124        let protocol_name = <ImagePipe2Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
125        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
126    }
127
128    pub fn into_channel(self) -> fidl::Channel {
129        self.client.into_channel()
130    }
131
132    /// Waits until an event arrives and returns it. It is safe for other
133    /// threads to make concurrent requests while waiting for an event.
134    pub fn wait_for_event(
135        &self,
136        deadline: zx::MonotonicInstant,
137    ) -> Result<ImagePipe2Event, fidl::Error> {
138        ImagePipe2Event::decode(self.client.wait_for_event(deadline)?)
139    }
140
141    /// Adds a BufferCollection resource to the image pipe.
142    ///
143    /// The producer is expected to set constraints on this resource for images added
144    /// via `AddImage()`. The consumer can set its constraints on
145    /// `buffer_collection_token` before or after. Note that the buffers won't be
146    /// allocated until all BufferCollectionToken instances are used to set
147    /// constraints, on both the producer and consumer side. See collection.fidl for
148    /// details.
149    ///
150    /// The following errors will cause the connection to be closed:
151    /// - `buffer_collection_id` is already registered
152    pub fn r#add_buffer_collection2(
153        &self,
154        mut buffer_collection_id: u32,
155        mut buffer_collection_token: fidl::endpoints::ClientEnd<
156            fidl_fuchsia_sysmem2::BufferCollectionTokenMarker,
157        >,
158    ) -> Result<(), fidl::Error> {
159        self.client.send::<ImagePipe2AddBufferCollection2Request>(
160            (buffer_collection_id, buffer_collection_token),
161            0x181c72c935b0b4ee,
162            fidl::encoding::DynamicFlags::empty(),
163        )
164    }
165
166    pub fn r#add_buffer_collection(
167        &self,
168        mut buffer_collection_id: u32,
169        mut buffer_collection_token: fidl::endpoints::ClientEnd<
170            fidl_fuchsia_sysmem::BufferCollectionTokenMarker,
171        >,
172    ) -> Result<(), fidl::Error> {
173        self.client.send::<ImagePipe2AddBufferCollectionRequest>(
174            (buffer_collection_id, buffer_collection_token),
175            0x663ec76e20c87c05,
176            fidl::encoding::DynamicFlags::empty(),
177        )
178    }
179
180    /// Adds an image resource to image pipe.
181    ///
182    /// `buffer_collection_id` refers to the BufferCollectionToken instance that is
183    /// registered via `AddBufferCollection()`. The underlying memory objects allocated
184    /// are used to address to the image data. `buffer_collection_index` refers to the
185    /// index of the memory object allocated in BufferCollection.
186    ///
187    /// `image_format` specifiies image properties. `coded_width` and `coded_height` are
188    /// used to set image dimensions.
189    ///
190    /// It is valid to create multiple images backed by the same memory object; they
191    /// may even overlap.  Consumers must detect this and handle it accordingly.
192    ///
193    /// The following errors will cause the connection to be closed:
194    /// - `image_id` is already registered
195    /// - `buffer_collection_id` refers to an unregistered BufferCollection.
196    /// - `buffer_collection_index` points to a resource index out of the initialized
197    ///     BufferCollection bounds
198    /// - No resource is allocated in the registered BufferCollection.
199    pub fn r#add_image(
200        &self,
201        mut image_id: u32,
202        mut buffer_collection_id: u32,
203        mut buffer_collection_index: u32,
204        mut image_format: &fidl_fuchsia_sysmem::ImageFormat2,
205    ) -> Result<(), fidl::Error> {
206        self.client.send::<ImagePipe2AddImageRequest>(
207            (image_id, buffer_collection_id, buffer_collection_index, image_format),
208            0x23566808b13af395,
209            fidl::encoding::DynamicFlags::empty(),
210        )
211    }
212
213    /// Removes a BufferCollection resource from the pipe.
214    ///
215    /// The `buffer_collection_id` resource is detached as well as all Images that are
216    /// associated with that BufferCollection. Leads to the same results as calling
217    /// `RemoveImage()` on all Images for `buffer_collection_id`.
218    ///
219    /// The producer must wait for all release fences associated with the Images to
220    /// be signaled before freeing or modifying the underlying memory object since
221    /// the image may still be in use in the presentation queue.
222    ///
223    /// The following errors will cause the connection to be closed:
224    /// - `buffer_collection_id` does not reference a currently registered BufferCollection
225    pub fn r#remove_buffer_collection(
226        &self,
227        mut buffer_collection_id: u32,
228    ) -> Result<(), fidl::Error> {
229        self.client.send::<ImagePipe2RemoveBufferCollectionRequest>(
230            (buffer_collection_id,),
231            0x16bebb759a932299,
232            fidl::encoding::DynamicFlags::empty(),
233        )
234    }
235
236    /// Removes an image resource from the pipe.
237    ///
238    /// The `image_id` is detached from the image resource and is free to be
239    /// reused to add a new image resource.
240    ///
241    /// Removing an image from the image pipe does not affect the presentation
242    /// queue or the currently presented image.
243    ///
244    /// The producer must wait for all release fences associated with the image to
245    /// be signaled before freeing or modifying the underlying memory object since
246    /// the image may still be in use in the presentation queue.
247    ///
248    /// The following errors will cause the connection to be closed:
249    /// - `image_id` does not reference a currently registered image resource
250    pub fn r#remove_image(&self, mut image_id: u32) -> Result<(), fidl::Error> {
251        self.client.send::<ImagePipe2RemoveImageRequest>(
252            (image_id,),
253            0x16e8edd0f4d50f68,
254            fidl::encoding::DynamicFlags::empty(),
255        )
256    }
257
258    /// Enqueues the specified image for presentation by the consumer.
259    ///
260    /// The `acquire_fences` are a set of fences which must all be signaled by
261    /// the producer before the consumer presents the image.
262    /// The `release_fences` are a set of fences which inform the producer that
263    /// it's safe to free or modify the `image_id` image, and it's safe to
264    /// re-use the fences in `acquire_fences`. The consumer must signal all the
265    /// fences in `release_fences` after `image_id` is no longer being
266    /// presented. The producer may reuse resources after any of the
267    /// `release_fences` is signaled.
268    ///
269    /// This design allows a producer to distribute image processing across
270    /// multiple threads / processes without unnecessary coordination delay.
271    /// Each thread / process signals its own fence in `acquire_fences` when
272    /// it's done rendering its piece of `image_id`, and waits on its own fence
273    /// in `release_fences` to render new content in `image_id`.
274    ///
275    /// `presentation_time` specifies the time on or after which the
276    /// client would like the enqueued operations should take visible effect
277    /// (light up pixels on the screen), expressed in nanoseconds in the
278    /// `CLOCK_MONOTONIC` timebase.  Desired presentation times must be
279    /// monotonically non-decreasing.
280    ///
281    /// `presentation_info` returns timing information about the submitted frame
282    /// and future frames (see presentation_info.fidl).
283    ///
284    /// The producer may decide not to signal `acquire_fences` for an image.
285    /// In that case, if a later image is enqueued and later image's
286    /// `presentation_time` is reached, the consumer presents the later image when
287    /// later image's `acquire_fences` are signaled. The consumer also signals
288    /// earlier image's `release_fences` and removes it from the presentation queue.
289    /// This sequence works as a cancellation mechanism.
290    ///
291    /// The following errors will cause the connection to be closed:
292    /// - `image_id` does not reference a currently registered image resource
293    pub fn r#present_image(
294        &self,
295        mut image_id: u32,
296        mut presentation_time: u64,
297        mut acquire_fences: Vec<fidl::Event>,
298        mut release_fences: Vec<fidl::Event>,
299        ___deadline: zx::MonotonicInstant,
300    ) -> Result<PresentationInfo, fidl::Error> {
301        let _response = self
302            .client
303            .send_query::<ImagePipe2PresentImageRequest, ImagePipe2PresentImageResponse>(
304                (image_id, presentation_time, acquire_fences.as_mut(), release_fences.as_mut()),
305                0x73cfb50f577c143a,
306                fidl::encoding::DynamicFlags::empty(),
307                ___deadline,
308            )?;
309        Ok(_response.presentation_info)
310    }
311}
312
313#[cfg(target_os = "fuchsia")]
314impl From<ImagePipe2SynchronousProxy> for zx::Handle {
315    fn from(value: ImagePipe2SynchronousProxy) -> Self {
316        value.into_channel().into()
317    }
318}
319
320#[cfg(target_os = "fuchsia")]
321impl From<fidl::Channel> for ImagePipe2SynchronousProxy {
322    fn from(value: fidl::Channel) -> Self {
323        Self::new(value)
324    }
325}
326
327#[cfg(target_os = "fuchsia")]
328impl fidl::endpoints::FromClient for ImagePipe2SynchronousProxy {
329    type Protocol = ImagePipe2Marker;
330
331    fn from_client(value: fidl::endpoints::ClientEnd<ImagePipe2Marker>) -> Self {
332        Self::new(value.into_channel())
333    }
334}
335
336#[derive(Debug, Clone)]
337pub struct ImagePipe2Proxy {
338    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
339}
340
341impl fidl::endpoints::Proxy for ImagePipe2Proxy {
342    type Protocol = ImagePipe2Marker;
343
344    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
345        Self::new(inner)
346    }
347
348    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
349        self.client.into_channel().map_err(|client| Self { client })
350    }
351
352    fn as_channel(&self) -> &::fidl::AsyncChannel {
353        self.client.as_channel()
354    }
355}
356
357impl ImagePipe2Proxy {
358    /// Create a new Proxy for fuchsia.images/ImagePipe2.
359    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
360        let protocol_name = <ImagePipe2Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
361        Self { client: fidl::client::Client::new(channel, protocol_name) }
362    }
363
364    /// Get a Stream of events from the remote end of the protocol.
365    ///
366    /// # Panics
367    ///
368    /// Panics if the event stream was already taken.
369    pub fn take_event_stream(&self) -> ImagePipe2EventStream {
370        ImagePipe2EventStream { event_receiver: self.client.take_event_receiver() }
371    }
372
373    /// Adds a BufferCollection resource to the image pipe.
374    ///
375    /// The producer is expected to set constraints on this resource for images added
376    /// via `AddImage()`. The consumer can set its constraints on
377    /// `buffer_collection_token` before or after. Note that the buffers won't be
378    /// allocated until all BufferCollectionToken instances are used to set
379    /// constraints, on both the producer and consumer side. See collection.fidl for
380    /// details.
381    ///
382    /// The following errors will cause the connection to be closed:
383    /// - `buffer_collection_id` is already registered
384    pub fn r#add_buffer_collection2(
385        &self,
386        mut buffer_collection_id: u32,
387        mut buffer_collection_token: fidl::endpoints::ClientEnd<
388            fidl_fuchsia_sysmem2::BufferCollectionTokenMarker,
389        >,
390    ) -> Result<(), fidl::Error> {
391        ImagePipe2ProxyInterface::r#add_buffer_collection2(
392            self,
393            buffer_collection_id,
394            buffer_collection_token,
395        )
396    }
397
398    pub fn r#add_buffer_collection(
399        &self,
400        mut buffer_collection_id: u32,
401        mut buffer_collection_token: fidl::endpoints::ClientEnd<
402            fidl_fuchsia_sysmem::BufferCollectionTokenMarker,
403        >,
404    ) -> Result<(), fidl::Error> {
405        ImagePipe2ProxyInterface::r#add_buffer_collection(
406            self,
407            buffer_collection_id,
408            buffer_collection_token,
409        )
410    }
411
412    /// Adds an image resource to image pipe.
413    ///
414    /// `buffer_collection_id` refers to the BufferCollectionToken instance that is
415    /// registered via `AddBufferCollection()`. The underlying memory objects allocated
416    /// are used to address to the image data. `buffer_collection_index` refers to the
417    /// index of the memory object allocated in BufferCollection.
418    ///
419    /// `image_format` specifiies image properties. `coded_width` and `coded_height` are
420    /// used to set image dimensions.
421    ///
422    /// It is valid to create multiple images backed by the same memory object; they
423    /// may even overlap.  Consumers must detect this and handle it accordingly.
424    ///
425    /// The following errors will cause the connection to be closed:
426    /// - `image_id` is already registered
427    /// - `buffer_collection_id` refers to an unregistered BufferCollection.
428    /// - `buffer_collection_index` points to a resource index out of the initialized
429    ///     BufferCollection bounds
430    /// - No resource is allocated in the registered BufferCollection.
431    pub fn r#add_image(
432        &self,
433        mut image_id: u32,
434        mut buffer_collection_id: u32,
435        mut buffer_collection_index: u32,
436        mut image_format: &fidl_fuchsia_sysmem::ImageFormat2,
437    ) -> Result<(), fidl::Error> {
438        ImagePipe2ProxyInterface::r#add_image(
439            self,
440            image_id,
441            buffer_collection_id,
442            buffer_collection_index,
443            image_format,
444        )
445    }
446
447    /// Removes a BufferCollection resource from the pipe.
448    ///
449    /// The `buffer_collection_id` resource is detached as well as all Images that are
450    /// associated with that BufferCollection. Leads to the same results as calling
451    /// `RemoveImage()` on all Images for `buffer_collection_id`.
452    ///
453    /// The producer must wait for all release fences associated with the Images to
454    /// be signaled before freeing or modifying the underlying memory object since
455    /// the image may still be in use in the presentation queue.
456    ///
457    /// The following errors will cause the connection to be closed:
458    /// - `buffer_collection_id` does not reference a currently registered BufferCollection
459    pub fn r#remove_buffer_collection(
460        &self,
461        mut buffer_collection_id: u32,
462    ) -> Result<(), fidl::Error> {
463        ImagePipe2ProxyInterface::r#remove_buffer_collection(self, buffer_collection_id)
464    }
465
466    /// Removes an image resource from the pipe.
467    ///
468    /// The `image_id` is detached from the image resource and is free to be
469    /// reused to add a new image resource.
470    ///
471    /// Removing an image from the image pipe does not affect the presentation
472    /// queue or the currently presented image.
473    ///
474    /// The producer must wait for all release fences associated with the image to
475    /// be signaled before freeing or modifying the underlying memory object since
476    /// the image may still be in use in the presentation queue.
477    ///
478    /// The following errors will cause the connection to be closed:
479    /// - `image_id` does not reference a currently registered image resource
480    pub fn r#remove_image(&self, mut image_id: u32) -> Result<(), fidl::Error> {
481        ImagePipe2ProxyInterface::r#remove_image(self, image_id)
482    }
483
484    /// Enqueues the specified image for presentation by the consumer.
485    ///
486    /// The `acquire_fences` are a set of fences which must all be signaled by
487    /// the producer before the consumer presents the image.
488    /// The `release_fences` are a set of fences which inform the producer that
489    /// it's safe to free or modify the `image_id` image, and it's safe to
490    /// re-use the fences in `acquire_fences`. The consumer must signal all the
491    /// fences in `release_fences` after `image_id` is no longer being
492    /// presented. The producer may reuse resources after any of the
493    /// `release_fences` is signaled.
494    ///
495    /// This design allows a producer to distribute image processing across
496    /// multiple threads / processes without unnecessary coordination delay.
497    /// Each thread / process signals its own fence in `acquire_fences` when
498    /// it's done rendering its piece of `image_id`, and waits on its own fence
499    /// in `release_fences` to render new content in `image_id`.
500    ///
501    /// `presentation_time` specifies the time on or after which the
502    /// client would like the enqueued operations should take visible effect
503    /// (light up pixels on the screen), expressed in nanoseconds in the
504    /// `CLOCK_MONOTONIC` timebase.  Desired presentation times must be
505    /// monotonically non-decreasing.
506    ///
507    /// `presentation_info` returns timing information about the submitted frame
508    /// and future frames (see presentation_info.fidl).
509    ///
510    /// The producer may decide not to signal `acquire_fences` for an image.
511    /// In that case, if a later image is enqueued and later image's
512    /// `presentation_time` is reached, the consumer presents the later image when
513    /// later image's `acquire_fences` are signaled. The consumer also signals
514    /// earlier image's `release_fences` and removes it from the presentation queue.
515    /// This sequence works as a cancellation mechanism.
516    ///
517    /// The following errors will cause the connection to be closed:
518    /// - `image_id` does not reference a currently registered image resource
519    pub fn r#present_image(
520        &self,
521        mut image_id: u32,
522        mut presentation_time: u64,
523        mut acquire_fences: Vec<fidl::Event>,
524        mut release_fences: Vec<fidl::Event>,
525    ) -> fidl::client::QueryResponseFut<
526        PresentationInfo,
527        fidl::encoding::DefaultFuchsiaResourceDialect,
528    > {
529        ImagePipe2ProxyInterface::r#present_image(
530            self,
531            image_id,
532            presentation_time,
533            acquire_fences,
534            release_fences,
535        )
536    }
537}
538
539impl ImagePipe2ProxyInterface for ImagePipe2Proxy {
540    fn r#add_buffer_collection2(
541        &self,
542        mut buffer_collection_id: u32,
543        mut buffer_collection_token: fidl::endpoints::ClientEnd<
544            fidl_fuchsia_sysmem2::BufferCollectionTokenMarker,
545        >,
546    ) -> Result<(), fidl::Error> {
547        self.client.send::<ImagePipe2AddBufferCollection2Request>(
548            (buffer_collection_id, buffer_collection_token),
549            0x181c72c935b0b4ee,
550            fidl::encoding::DynamicFlags::empty(),
551        )
552    }
553
554    fn r#add_buffer_collection(
555        &self,
556        mut buffer_collection_id: u32,
557        mut buffer_collection_token: fidl::endpoints::ClientEnd<
558            fidl_fuchsia_sysmem::BufferCollectionTokenMarker,
559        >,
560    ) -> Result<(), fidl::Error> {
561        self.client.send::<ImagePipe2AddBufferCollectionRequest>(
562            (buffer_collection_id, buffer_collection_token),
563            0x663ec76e20c87c05,
564            fidl::encoding::DynamicFlags::empty(),
565        )
566    }
567
568    fn r#add_image(
569        &self,
570        mut image_id: u32,
571        mut buffer_collection_id: u32,
572        mut buffer_collection_index: u32,
573        mut image_format: &fidl_fuchsia_sysmem::ImageFormat2,
574    ) -> Result<(), fidl::Error> {
575        self.client.send::<ImagePipe2AddImageRequest>(
576            (image_id, buffer_collection_id, buffer_collection_index, image_format),
577            0x23566808b13af395,
578            fidl::encoding::DynamicFlags::empty(),
579        )
580    }
581
582    fn r#remove_buffer_collection(&self, mut buffer_collection_id: u32) -> Result<(), fidl::Error> {
583        self.client.send::<ImagePipe2RemoveBufferCollectionRequest>(
584            (buffer_collection_id,),
585            0x16bebb759a932299,
586            fidl::encoding::DynamicFlags::empty(),
587        )
588    }
589
590    fn r#remove_image(&self, mut image_id: u32) -> Result<(), fidl::Error> {
591        self.client.send::<ImagePipe2RemoveImageRequest>(
592            (image_id,),
593            0x16e8edd0f4d50f68,
594            fidl::encoding::DynamicFlags::empty(),
595        )
596    }
597
598    type PresentImageResponseFut = fidl::client::QueryResponseFut<
599        PresentationInfo,
600        fidl::encoding::DefaultFuchsiaResourceDialect,
601    >;
602    fn r#present_image(
603        &self,
604        mut image_id: u32,
605        mut presentation_time: u64,
606        mut acquire_fences: Vec<fidl::Event>,
607        mut release_fences: Vec<fidl::Event>,
608    ) -> Self::PresentImageResponseFut {
609        fn _decode(
610            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
611        ) -> Result<PresentationInfo, fidl::Error> {
612            let _response = fidl::client::decode_transaction_body::<
613                ImagePipe2PresentImageResponse,
614                fidl::encoding::DefaultFuchsiaResourceDialect,
615                0x73cfb50f577c143a,
616            >(_buf?)?;
617            Ok(_response.presentation_info)
618        }
619        self.client.send_query_and_decode::<ImagePipe2PresentImageRequest, PresentationInfo>(
620            (image_id, presentation_time, acquire_fences.as_mut(), release_fences.as_mut()),
621            0x73cfb50f577c143a,
622            fidl::encoding::DynamicFlags::empty(),
623            _decode,
624        )
625    }
626}
627
628pub struct ImagePipe2EventStream {
629    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
630}
631
632impl std::marker::Unpin for ImagePipe2EventStream {}
633
634impl futures::stream::FusedStream for ImagePipe2EventStream {
635    fn is_terminated(&self) -> bool {
636        self.event_receiver.is_terminated()
637    }
638}
639
640impl futures::Stream for ImagePipe2EventStream {
641    type Item = Result<ImagePipe2Event, fidl::Error>;
642
643    fn poll_next(
644        mut self: std::pin::Pin<&mut Self>,
645        cx: &mut std::task::Context<'_>,
646    ) -> std::task::Poll<Option<Self::Item>> {
647        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
648            &mut self.event_receiver,
649            cx
650        )?) {
651            Some(buf) => std::task::Poll::Ready(Some(ImagePipe2Event::decode(buf))),
652            None => std::task::Poll::Ready(None),
653        }
654    }
655}
656
657#[derive(Debug)]
658pub enum ImagePipe2Event {}
659
660impl ImagePipe2Event {
661    /// Decodes a message buffer as a [`ImagePipe2Event`].
662    fn decode(
663        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
664    ) -> Result<ImagePipe2Event, fidl::Error> {
665        let (bytes, _handles) = buf.split_mut();
666        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
667        debug_assert_eq!(tx_header.tx_id, 0);
668        match tx_header.ordinal {
669            _ => Err(fidl::Error::UnknownOrdinal {
670                ordinal: tx_header.ordinal,
671                protocol_name: <ImagePipe2Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
672            }),
673        }
674    }
675}
676
677/// A Stream of incoming requests for fuchsia.images/ImagePipe2.
678pub struct ImagePipe2RequestStream {
679    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
680    is_terminated: bool,
681}
682
683impl std::marker::Unpin for ImagePipe2RequestStream {}
684
685impl futures::stream::FusedStream for ImagePipe2RequestStream {
686    fn is_terminated(&self) -> bool {
687        self.is_terminated
688    }
689}
690
691impl fidl::endpoints::RequestStream for ImagePipe2RequestStream {
692    type Protocol = ImagePipe2Marker;
693    type ControlHandle = ImagePipe2ControlHandle;
694
695    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
696        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
697    }
698
699    fn control_handle(&self) -> Self::ControlHandle {
700        ImagePipe2ControlHandle { inner: self.inner.clone() }
701    }
702
703    fn into_inner(
704        self,
705    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
706    {
707        (self.inner, self.is_terminated)
708    }
709
710    fn from_inner(
711        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
712        is_terminated: bool,
713    ) -> Self {
714        Self { inner, is_terminated }
715    }
716}
717
718impl futures::Stream for ImagePipe2RequestStream {
719    type Item = Result<ImagePipe2Request, fidl::Error>;
720
721    fn poll_next(
722        mut self: std::pin::Pin<&mut Self>,
723        cx: &mut std::task::Context<'_>,
724    ) -> std::task::Poll<Option<Self::Item>> {
725        let this = &mut *self;
726        if this.inner.check_shutdown(cx) {
727            this.is_terminated = true;
728            return std::task::Poll::Ready(None);
729        }
730        if this.is_terminated {
731            panic!("polled ImagePipe2RequestStream after completion");
732        }
733        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
734            |bytes, handles| {
735                match this.inner.channel().read_etc(cx, bytes, handles) {
736                    std::task::Poll::Ready(Ok(())) => {}
737                    std::task::Poll::Pending => return std::task::Poll::Pending,
738                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
739                        this.is_terminated = true;
740                        return std::task::Poll::Ready(None);
741                    }
742                    std::task::Poll::Ready(Err(e)) => {
743                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
744                            e.into(),
745                        ))))
746                    }
747                }
748
749                // A message has been received from the channel
750                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
751
752                std::task::Poll::Ready(Some(match header.ordinal {
753                    0x181c72c935b0b4ee => {
754                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
755                        let mut req = fidl::new_empty!(
756                            ImagePipe2AddBufferCollection2Request,
757                            fidl::encoding::DefaultFuchsiaResourceDialect
758                        );
759                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ImagePipe2AddBufferCollection2Request>(&header, _body_bytes, handles, &mut req)?;
760                        let control_handle = ImagePipe2ControlHandle { inner: this.inner.clone() };
761                        Ok(ImagePipe2Request::AddBufferCollection2 {
762                            buffer_collection_id: req.buffer_collection_id,
763                            buffer_collection_token: req.buffer_collection_token,
764
765                            control_handle,
766                        })
767                    }
768                    0x663ec76e20c87c05 => {
769                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
770                        let mut req = fidl::new_empty!(
771                            ImagePipe2AddBufferCollectionRequest,
772                            fidl::encoding::DefaultFuchsiaResourceDialect
773                        );
774                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ImagePipe2AddBufferCollectionRequest>(&header, _body_bytes, handles, &mut req)?;
775                        let control_handle = ImagePipe2ControlHandle { inner: this.inner.clone() };
776                        Ok(ImagePipe2Request::AddBufferCollection {
777                            buffer_collection_id: req.buffer_collection_id,
778                            buffer_collection_token: req.buffer_collection_token,
779
780                            control_handle,
781                        })
782                    }
783                    0x23566808b13af395 => {
784                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
785                        let mut req = fidl::new_empty!(
786                            ImagePipe2AddImageRequest,
787                            fidl::encoding::DefaultFuchsiaResourceDialect
788                        );
789                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ImagePipe2AddImageRequest>(&header, _body_bytes, handles, &mut req)?;
790                        let control_handle = ImagePipe2ControlHandle { inner: this.inner.clone() };
791                        Ok(ImagePipe2Request::AddImage {
792                            image_id: req.image_id,
793                            buffer_collection_id: req.buffer_collection_id,
794                            buffer_collection_index: req.buffer_collection_index,
795                            image_format: req.image_format,
796
797                            control_handle,
798                        })
799                    }
800                    0x16bebb759a932299 => {
801                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
802                        let mut req = fidl::new_empty!(
803                            ImagePipe2RemoveBufferCollectionRequest,
804                            fidl::encoding::DefaultFuchsiaResourceDialect
805                        );
806                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ImagePipe2RemoveBufferCollectionRequest>(&header, _body_bytes, handles, &mut req)?;
807                        let control_handle = ImagePipe2ControlHandle { inner: this.inner.clone() };
808                        Ok(ImagePipe2Request::RemoveBufferCollection {
809                            buffer_collection_id: req.buffer_collection_id,
810
811                            control_handle,
812                        })
813                    }
814                    0x16e8edd0f4d50f68 => {
815                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
816                        let mut req = fidl::new_empty!(
817                            ImagePipe2RemoveImageRequest,
818                            fidl::encoding::DefaultFuchsiaResourceDialect
819                        );
820                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ImagePipe2RemoveImageRequest>(&header, _body_bytes, handles, &mut req)?;
821                        let control_handle = ImagePipe2ControlHandle { inner: this.inner.clone() };
822                        Ok(ImagePipe2Request::RemoveImage {
823                            image_id: req.image_id,
824
825                            control_handle,
826                        })
827                    }
828                    0x73cfb50f577c143a => {
829                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
830                        let mut req = fidl::new_empty!(
831                            ImagePipe2PresentImageRequest,
832                            fidl::encoding::DefaultFuchsiaResourceDialect
833                        );
834                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ImagePipe2PresentImageRequest>(&header, _body_bytes, handles, &mut req)?;
835                        let control_handle = ImagePipe2ControlHandle { inner: this.inner.clone() };
836                        Ok(ImagePipe2Request::PresentImage {
837                            image_id: req.image_id,
838                            presentation_time: req.presentation_time,
839                            acquire_fences: req.acquire_fences,
840                            release_fences: req.release_fences,
841
842                            responder: ImagePipe2PresentImageResponder {
843                                control_handle: std::mem::ManuallyDrop::new(control_handle),
844                                tx_id: header.tx_id,
845                            },
846                        })
847                    }
848                    _ => Err(fidl::Error::UnknownOrdinal {
849                        ordinal: header.ordinal,
850                        protocol_name:
851                            <ImagePipe2Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
852                    }),
853                }))
854            },
855        )
856    }
857}
858
859/// ImagePipe is a mechanism for streaming shared images between a producer
860/// and a consumer which may be running in different processes.
861///
862/// Conceptually, the image pipe maintains a table of image resources supplied
863/// by the producer into which graphical content may be stored as well as a
864/// presentation queue containing a sequence of images which the producer has
865/// asked the consumer to present.
866///
867/// The presentation queue is initially empty.
868///
869/// Each entry in the presentation queue consists of an image together with a
870/// pair of optional synchronization fences:
871/// - Acquire fence: signaled by the producer when the image is ready to be consumed
872/// - Release fence: signaled by the consumer when the image is free to be freed or
873///   modified by the producer
874///
875/// The producer performs the following sequence of steps to present content:
876/// - Allocate and add some number of BufferCollections to the image pipe to allow
877/// consumer to set constraints.
878/// - Allocate and add some number of images (often 2 or 3) to the image pipe
879///   to establish a pool using `AddImage()`.
880/// - Obtain the next available image from the pool.
881/// - Ask the consumer to enqueue an image for presentation and provide fences
882///   using `PresentImage()`.
883/// - Start rendering the image.
884/// - Signal the image's acquire fence when rendering is complete.
885/// - Loop to present more image, listen for signals on release fences to recycle
886///   images back into the pool.
887///
888/// The consumer performs the following sequence of steps for each image which
889/// is enqueued in the presentation queue:
890/// - Await signals on the image's acquire fence.
891/// - If the fence wait cannot be satisfied or if some other error is detected,
892///   close the image pipe.
893///   Otherwise, begin presenting the image's content.
894/// - Retire the previously presented image (if any) from the presentation queue
895///   and signal its release fence when no longer needed.
896/// - Continue presenting the same image until the next one is ready.  Loop.
897///
898/// If the producer wants to close the image pipe, it should:
899/// - Close its side of the connection.
900/// - Wait on all release fences for buffers that it has submitted with
901///   `PresentImage()`.
902/// - Proceed with resource cleanup.
903///
904/// When the consumer detects the image pipe has closed, it should:
905/// - Stop using/presenting any images from the pipe.
906/// - Unmap all memory objects associated with the images in the pipe.
907/// - Close all BufferCollection resources.
908/// - Signal all release fences for presented and queued buffers.
909/// - Close all handles to fences.
910/// - Close its side of the connection.
911///
912/// When either party detects that a fence has been abandoned (remotely closed
913/// without being signaled) it should assume that the associated image is in
914/// an indeterminate state.  This will typically happen when the other party
915/// (or one of its delegates) has crashed.  The safest course of action is to
916/// close the image pipe, release all resources which were shared with the
917/// other party, and re-establish the connection to recover.
918#[derive(Debug)]
919pub enum ImagePipe2Request {
920    /// Adds a BufferCollection resource to the image pipe.
921    ///
922    /// The producer is expected to set constraints on this resource for images added
923    /// via `AddImage()`. The consumer can set its constraints on
924    /// `buffer_collection_token` before or after. Note that the buffers won't be
925    /// allocated until all BufferCollectionToken instances are used to set
926    /// constraints, on both the producer and consumer side. See collection.fidl for
927    /// details.
928    ///
929    /// The following errors will cause the connection to be closed:
930    /// - `buffer_collection_id` is already registered
931    AddBufferCollection2 {
932        buffer_collection_id: u32,
933        buffer_collection_token:
934            fidl::endpoints::ClientEnd<fidl_fuchsia_sysmem2::BufferCollectionTokenMarker>,
935        control_handle: ImagePipe2ControlHandle,
936    },
937    AddBufferCollection {
938        buffer_collection_id: u32,
939        buffer_collection_token:
940            fidl::endpoints::ClientEnd<fidl_fuchsia_sysmem::BufferCollectionTokenMarker>,
941        control_handle: ImagePipe2ControlHandle,
942    },
943    /// Adds an image resource to image pipe.
944    ///
945    /// `buffer_collection_id` refers to the BufferCollectionToken instance that is
946    /// registered via `AddBufferCollection()`. The underlying memory objects allocated
947    /// are used to address to the image data. `buffer_collection_index` refers to the
948    /// index of the memory object allocated in BufferCollection.
949    ///
950    /// `image_format` specifiies image properties. `coded_width` and `coded_height` are
951    /// used to set image dimensions.
952    ///
953    /// It is valid to create multiple images backed by the same memory object; they
954    /// may even overlap.  Consumers must detect this and handle it accordingly.
955    ///
956    /// The following errors will cause the connection to be closed:
957    /// - `image_id` is already registered
958    /// - `buffer_collection_id` refers to an unregistered BufferCollection.
959    /// - `buffer_collection_index` points to a resource index out of the initialized
960    ///     BufferCollection bounds
961    /// - No resource is allocated in the registered BufferCollection.
962    AddImage {
963        image_id: u32,
964        buffer_collection_id: u32,
965        buffer_collection_index: u32,
966        image_format: fidl_fuchsia_sysmem::ImageFormat2,
967        control_handle: ImagePipe2ControlHandle,
968    },
969    /// Removes a BufferCollection resource from the pipe.
970    ///
971    /// The `buffer_collection_id` resource is detached as well as all Images that are
972    /// associated with that BufferCollection. Leads to the same results as calling
973    /// `RemoveImage()` on all Images for `buffer_collection_id`.
974    ///
975    /// The producer must wait for all release fences associated with the Images to
976    /// be signaled before freeing or modifying the underlying memory object since
977    /// the image may still be in use in the presentation queue.
978    ///
979    /// The following errors will cause the connection to be closed:
980    /// - `buffer_collection_id` does not reference a currently registered BufferCollection
981    RemoveBufferCollection { buffer_collection_id: u32, control_handle: ImagePipe2ControlHandle },
982    /// Removes an image resource from the pipe.
983    ///
984    /// The `image_id` is detached from the image resource and is free to be
985    /// reused to add a new image resource.
986    ///
987    /// Removing an image from the image pipe does not affect the presentation
988    /// queue or the currently presented image.
989    ///
990    /// The producer must wait for all release fences associated with the image to
991    /// be signaled before freeing or modifying the underlying memory object since
992    /// the image may still be in use in the presentation queue.
993    ///
994    /// The following errors will cause the connection to be closed:
995    /// - `image_id` does not reference a currently registered image resource
996    RemoveImage { image_id: u32, control_handle: ImagePipe2ControlHandle },
997    /// Enqueues the specified image for presentation by the consumer.
998    ///
999    /// The `acquire_fences` are a set of fences which must all be signaled by
1000    /// the producer before the consumer presents the image.
1001    /// The `release_fences` are a set of fences which inform the producer that
1002    /// it's safe to free or modify the `image_id` image, and it's safe to
1003    /// re-use the fences in `acquire_fences`. The consumer must signal all the
1004    /// fences in `release_fences` after `image_id` is no longer being
1005    /// presented. The producer may reuse resources after any of the
1006    /// `release_fences` is signaled.
1007    ///
1008    /// This design allows a producer to distribute image processing across
1009    /// multiple threads / processes without unnecessary coordination delay.
1010    /// Each thread / process signals its own fence in `acquire_fences` when
1011    /// it's done rendering its piece of `image_id`, and waits on its own fence
1012    /// in `release_fences` to render new content in `image_id`.
1013    ///
1014    /// `presentation_time` specifies the time on or after which the
1015    /// client would like the enqueued operations should take visible effect
1016    /// (light up pixels on the screen), expressed in nanoseconds in the
1017    /// `CLOCK_MONOTONIC` timebase.  Desired presentation times must be
1018    /// monotonically non-decreasing.
1019    ///
1020    /// `presentation_info` returns timing information about the submitted frame
1021    /// and future frames (see presentation_info.fidl).
1022    ///
1023    /// The producer may decide not to signal `acquire_fences` for an image.
1024    /// In that case, if a later image is enqueued and later image's
1025    /// `presentation_time` is reached, the consumer presents the later image when
1026    /// later image's `acquire_fences` are signaled. The consumer also signals
1027    /// earlier image's `release_fences` and removes it from the presentation queue.
1028    /// This sequence works as a cancellation mechanism.
1029    ///
1030    /// The following errors will cause the connection to be closed:
1031    /// - `image_id` does not reference a currently registered image resource
1032    PresentImage {
1033        image_id: u32,
1034        presentation_time: u64,
1035        acquire_fences: Vec<fidl::Event>,
1036        release_fences: Vec<fidl::Event>,
1037        responder: ImagePipe2PresentImageResponder,
1038    },
1039}
1040
1041impl ImagePipe2Request {
1042    #[allow(irrefutable_let_patterns)]
1043    pub fn into_add_buffer_collection2(
1044        self,
1045    ) -> Option<(
1046        u32,
1047        fidl::endpoints::ClientEnd<fidl_fuchsia_sysmem2::BufferCollectionTokenMarker>,
1048        ImagePipe2ControlHandle,
1049    )> {
1050        if let ImagePipe2Request::AddBufferCollection2 {
1051            buffer_collection_id,
1052            buffer_collection_token,
1053            control_handle,
1054        } = self
1055        {
1056            Some((buffer_collection_id, buffer_collection_token, control_handle))
1057        } else {
1058            None
1059        }
1060    }
1061
1062    #[allow(irrefutable_let_patterns)]
1063    pub fn into_add_buffer_collection(
1064        self,
1065    ) -> Option<(
1066        u32,
1067        fidl::endpoints::ClientEnd<fidl_fuchsia_sysmem::BufferCollectionTokenMarker>,
1068        ImagePipe2ControlHandle,
1069    )> {
1070        if let ImagePipe2Request::AddBufferCollection {
1071            buffer_collection_id,
1072            buffer_collection_token,
1073            control_handle,
1074        } = self
1075        {
1076            Some((buffer_collection_id, buffer_collection_token, control_handle))
1077        } else {
1078            None
1079        }
1080    }
1081
1082    #[allow(irrefutable_let_patterns)]
1083    pub fn into_add_image(
1084        self,
1085    ) -> Option<(u32, u32, u32, fidl_fuchsia_sysmem::ImageFormat2, ImagePipe2ControlHandle)> {
1086        if let ImagePipe2Request::AddImage {
1087            image_id,
1088            buffer_collection_id,
1089            buffer_collection_index,
1090            image_format,
1091            control_handle,
1092        } = self
1093        {
1094            Some((
1095                image_id,
1096                buffer_collection_id,
1097                buffer_collection_index,
1098                image_format,
1099                control_handle,
1100            ))
1101        } else {
1102            None
1103        }
1104    }
1105
1106    #[allow(irrefutable_let_patterns)]
1107    pub fn into_remove_buffer_collection(self) -> Option<(u32, ImagePipe2ControlHandle)> {
1108        if let ImagePipe2Request::RemoveBufferCollection { buffer_collection_id, control_handle } =
1109            self
1110        {
1111            Some((buffer_collection_id, control_handle))
1112        } else {
1113            None
1114        }
1115    }
1116
1117    #[allow(irrefutable_let_patterns)]
1118    pub fn into_remove_image(self) -> Option<(u32, ImagePipe2ControlHandle)> {
1119        if let ImagePipe2Request::RemoveImage { image_id, control_handle } = self {
1120            Some((image_id, control_handle))
1121        } else {
1122            None
1123        }
1124    }
1125
1126    #[allow(irrefutable_let_patterns)]
1127    pub fn into_present_image(
1128        self,
1129    ) -> Option<(u32, u64, Vec<fidl::Event>, Vec<fidl::Event>, ImagePipe2PresentImageResponder)>
1130    {
1131        if let ImagePipe2Request::PresentImage {
1132            image_id,
1133            presentation_time,
1134            acquire_fences,
1135            release_fences,
1136            responder,
1137        } = self
1138        {
1139            Some((image_id, presentation_time, acquire_fences, release_fences, responder))
1140        } else {
1141            None
1142        }
1143    }
1144
1145    /// Name of the method defined in FIDL
1146    pub fn method_name(&self) -> &'static str {
1147        match *self {
1148            ImagePipe2Request::AddBufferCollection2 { .. } => "add_buffer_collection2",
1149            ImagePipe2Request::AddBufferCollection { .. } => "add_buffer_collection",
1150            ImagePipe2Request::AddImage { .. } => "add_image",
1151            ImagePipe2Request::RemoveBufferCollection { .. } => "remove_buffer_collection",
1152            ImagePipe2Request::RemoveImage { .. } => "remove_image",
1153            ImagePipe2Request::PresentImage { .. } => "present_image",
1154        }
1155    }
1156}
1157
1158#[derive(Debug, Clone)]
1159pub struct ImagePipe2ControlHandle {
1160    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1161}
1162
1163impl fidl::endpoints::ControlHandle for ImagePipe2ControlHandle {
1164    fn shutdown(&self) {
1165        self.inner.shutdown()
1166    }
1167    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1168        self.inner.shutdown_with_epitaph(status)
1169    }
1170
1171    fn is_closed(&self) -> bool {
1172        self.inner.channel().is_closed()
1173    }
1174    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1175        self.inner.channel().on_closed()
1176    }
1177
1178    #[cfg(target_os = "fuchsia")]
1179    fn signal_peer(
1180        &self,
1181        clear_mask: zx::Signals,
1182        set_mask: zx::Signals,
1183    ) -> Result<(), zx_status::Status> {
1184        use fidl::Peered;
1185        self.inner.channel().signal_peer(clear_mask, set_mask)
1186    }
1187}
1188
1189impl ImagePipe2ControlHandle {}
1190
1191#[must_use = "FIDL methods require a response to be sent"]
1192#[derive(Debug)]
1193pub struct ImagePipe2PresentImageResponder {
1194    control_handle: std::mem::ManuallyDrop<ImagePipe2ControlHandle>,
1195    tx_id: u32,
1196}
1197
1198/// Set the the channel to be shutdown (see [`ImagePipe2ControlHandle::shutdown`])
1199/// if the responder is dropped without sending a response, so that the client
1200/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1201impl std::ops::Drop for ImagePipe2PresentImageResponder {
1202    fn drop(&mut self) {
1203        self.control_handle.shutdown();
1204        // Safety: drops once, never accessed again
1205        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1206    }
1207}
1208
1209impl fidl::endpoints::Responder for ImagePipe2PresentImageResponder {
1210    type ControlHandle = ImagePipe2ControlHandle;
1211
1212    fn control_handle(&self) -> &ImagePipe2ControlHandle {
1213        &self.control_handle
1214    }
1215
1216    fn drop_without_shutdown(mut self) {
1217        // Safety: drops once, never accessed again due to mem::forget
1218        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1219        // Prevent Drop from running (which would shut down the channel)
1220        std::mem::forget(self);
1221    }
1222}
1223
1224impl ImagePipe2PresentImageResponder {
1225    /// Sends a response to the FIDL transaction.
1226    ///
1227    /// Sets the channel to shutdown if an error occurs.
1228    pub fn send(self, mut presentation_info: &PresentationInfo) -> Result<(), fidl::Error> {
1229        let _result = self.send_raw(presentation_info);
1230        if _result.is_err() {
1231            self.control_handle.shutdown();
1232        }
1233        self.drop_without_shutdown();
1234        _result
1235    }
1236
1237    /// Similar to "send" but does not shutdown the channel if an error occurs.
1238    pub fn send_no_shutdown_on_err(
1239        self,
1240        mut presentation_info: &PresentationInfo,
1241    ) -> Result<(), fidl::Error> {
1242        let _result = self.send_raw(presentation_info);
1243        self.drop_without_shutdown();
1244        _result
1245    }
1246
1247    fn send_raw(&self, mut presentation_info: &PresentationInfo) -> Result<(), fidl::Error> {
1248        self.control_handle.inner.send::<ImagePipe2PresentImageResponse>(
1249            (presentation_info,),
1250            self.tx_id,
1251            0x73cfb50f577c143a,
1252            fidl::encoding::DynamicFlags::empty(),
1253        )
1254    }
1255}
1256
1257mod internal {
1258    use super::*;
1259
1260    impl fidl::encoding::ResourceTypeMarker for ImagePipe2AddBufferCollection2Request {
1261        type Borrowed<'a> = &'a mut Self;
1262        fn take_or_borrow<'a>(
1263            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1264        ) -> Self::Borrowed<'a> {
1265            value
1266        }
1267    }
1268
1269    unsafe impl fidl::encoding::TypeMarker for ImagePipe2AddBufferCollection2Request {
1270        type Owned = Self;
1271
1272        #[inline(always)]
1273        fn inline_align(_context: fidl::encoding::Context) -> usize {
1274            4
1275        }
1276
1277        #[inline(always)]
1278        fn inline_size(_context: fidl::encoding::Context) -> usize {
1279            8
1280        }
1281    }
1282
1283    unsafe impl
1284        fidl::encoding::Encode<
1285            ImagePipe2AddBufferCollection2Request,
1286            fidl::encoding::DefaultFuchsiaResourceDialect,
1287        > for &mut ImagePipe2AddBufferCollection2Request
1288    {
1289        #[inline]
1290        unsafe fn encode(
1291            self,
1292            encoder: &mut fidl::encoding::Encoder<
1293                '_,
1294                fidl::encoding::DefaultFuchsiaResourceDialect,
1295            >,
1296            offset: usize,
1297            _depth: fidl::encoding::Depth,
1298        ) -> fidl::Result<()> {
1299            encoder.debug_check_bounds::<ImagePipe2AddBufferCollection2Request>(offset);
1300            // Delegate to tuple encoding.
1301            fidl::encoding::Encode::<
1302                ImagePipe2AddBufferCollection2Request,
1303                fidl::encoding::DefaultFuchsiaResourceDialect,
1304            >::encode(
1305                (
1306                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.buffer_collection_id),
1307                    <fidl::encoding::Endpoint<
1308                        fidl::endpoints::ClientEnd<
1309                            fidl_fuchsia_sysmem2::BufferCollectionTokenMarker,
1310                        >,
1311                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1312                        &mut self.buffer_collection_token,
1313                    ),
1314                ),
1315                encoder,
1316                offset,
1317                _depth,
1318            )
1319        }
1320    }
1321    unsafe impl<
1322            T0: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
1323            T1: fidl::encoding::Encode<
1324                fidl::encoding::Endpoint<
1325                    fidl::endpoints::ClientEnd<fidl_fuchsia_sysmem2::BufferCollectionTokenMarker>,
1326                >,
1327                fidl::encoding::DefaultFuchsiaResourceDialect,
1328            >,
1329        >
1330        fidl::encoding::Encode<
1331            ImagePipe2AddBufferCollection2Request,
1332            fidl::encoding::DefaultFuchsiaResourceDialect,
1333        > for (T0, T1)
1334    {
1335        #[inline]
1336        unsafe fn encode(
1337            self,
1338            encoder: &mut fidl::encoding::Encoder<
1339                '_,
1340                fidl::encoding::DefaultFuchsiaResourceDialect,
1341            >,
1342            offset: usize,
1343            depth: fidl::encoding::Depth,
1344        ) -> fidl::Result<()> {
1345            encoder.debug_check_bounds::<ImagePipe2AddBufferCollection2Request>(offset);
1346            // Zero out padding regions. There's no need to apply masks
1347            // because the unmasked parts will be overwritten by fields.
1348            // Write the fields.
1349            self.0.encode(encoder, offset + 0, depth)?;
1350            self.1.encode(encoder, offset + 4, depth)?;
1351            Ok(())
1352        }
1353    }
1354
1355    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1356        for ImagePipe2AddBufferCollection2Request
1357    {
1358        #[inline(always)]
1359        fn new_empty() -> Self {
1360            Self {
1361                buffer_collection_id: fidl::new_empty!(
1362                    u32,
1363                    fidl::encoding::DefaultFuchsiaResourceDialect
1364                ),
1365                buffer_collection_token: fidl::new_empty!(
1366                    fidl::encoding::Endpoint<
1367                        fidl::endpoints::ClientEnd<
1368                            fidl_fuchsia_sysmem2::BufferCollectionTokenMarker,
1369                        >,
1370                    >,
1371                    fidl::encoding::DefaultFuchsiaResourceDialect
1372                ),
1373            }
1374        }
1375
1376        #[inline]
1377        unsafe fn decode(
1378            &mut self,
1379            decoder: &mut fidl::encoding::Decoder<
1380                '_,
1381                fidl::encoding::DefaultFuchsiaResourceDialect,
1382            >,
1383            offset: usize,
1384            _depth: fidl::encoding::Depth,
1385        ) -> fidl::Result<()> {
1386            decoder.debug_check_bounds::<Self>(offset);
1387            // Verify that padding bytes are zero.
1388            fidl::decode!(
1389                u32,
1390                fidl::encoding::DefaultFuchsiaResourceDialect,
1391                &mut self.buffer_collection_id,
1392                decoder,
1393                offset + 0,
1394                _depth
1395            )?;
1396            fidl::decode!(
1397                fidl::encoding::Endpoint<
1398                    fidl::endpoints::ClientEnd<fidl_fuchsia_sysmem2::BufferCollectionTokenMarker>,
1399                >,
1400                fidl::encoding::DefaultFuchsiaResourceDialect,
1401                &mut self.buffer_collection_token,
1402                decoder,
1403                offset + 4,
1404                _depth
1405            )?;
1406            Ok(())
1407        }
1408    }
1409
1410    impl fidl::encoding::ResourceTypeMarker for ImagePipe2AddBufferCollectionRequest {
1411        type Borrowed<'a> = &'a mut Self;
1412        fn take_or_borrow<'a>(
1413            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1414        ) -> Self::Borrowed<'a> {
1415            value
1416        }
1417    }
1418
1419    unsafe impl fidl::encoding::TypeMarker for ImagePipe2AddBufferCollectionRequest {
1420        type Owned = Self;
1421
1422        #[inline(always)]
1423        fn inline_align(_context: fidl::encoding::Context) -> usize {
1424            4
1425        }
1426
1427        #[inline(always)]
1428        fn inline_size(_context: fidl::encoding::Context) -> usize {
1429            8
1430        }
1431    }
1432
1433    unsafe impl
1434        fidl::encoding::Encode<
1435            ImagePipe2AddBufferCollectionRequest,
1436            fidl::encoding::DefaultFuchsiaResourceDialect,
1437        > for &mut ImagePipe2AddBufferCollectionRequest
1438    {
1439        #[inline]
1440        unsafe fn encode(
1441            self,
1442            encoder: &mut fidl::encoding::Encoder<
1443                '_,
1444                fidl::encoding::DefaultFuchsiaResourceDialect,
1445            >,
1446            offset: usize,
1447            _depth: fidl::encoding::Depth,
1448        ) -> fidl::Result<()> {
1449            encoder.debug_check_bounds::<ImagePipe2AddBufferCollectionRequest>(offset);
1450            // Delegate to tuple encoding.
1451            fidl::encoding::Encode::<
1452                ImagePipe2AddBufferCollectionRequest,
1453                fidl::encoding::DefaultFuchsiaResourceDialect,
1454            >::encode(
1455                (
1456                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.buffer_collection_id),
1457                    <fidl::encoding::Endpoint<
1458                        fidl::endpoints::ClientEnd<
1459                            fidl_fuchsia_sysmem::BufferCollectionTokenMarker,
1460                        >,
1461                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1462                        &mut self.buffer_collection_token,
1463                    ),
1464                ),
1465                encoder,
1466                offset,
1467                _depth,
1468            )
1469        }
1470    }
1471    unsafe impl<
1472            T0: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
1473            T1: fidl::encoding::Encode<
1474                fidl::encoding::Endpoint<
1475                    fidl::endpoints::ClientEnd<fidl_fuchsia_sysmem::BufferCollectionTokenMarker>,
1476                >,
1477                fidl::encoding::DefaultFuchsiaResourceDialect,
1478            >,
1479        >
1480        fidl::encoding::Encode<
1481            ImagePipe2AddBufferCollectionRequest,
1482            fidl::encoding::DefaultFuchsiaResourceDialect,
1483        > for (T0, T1)
1484    {
1485        #[inline]
1486        unsafe fn encode(
1487            self,
1488            encoder: &mut fidl::encoding::Encoder<
1489                '_,
1490                fidl::encoding::DefaultFuchsiaResourceDialect,
1491            >,
1492            offset: usize,
1493            depth: fidl::encoding::Depth,
1494        ) -> fidl::Result<()> {
1495            encoder.debug_check_bounds::<ImagePipe2AddBufferCollectionRequest>(offset);
1496            // Zero out padding regions. There's no need to apply masks
1497            // because the unmasked parts will be overwritten by fields.
1498            // Write the fields.
1499            self.0.encode(encoder, offset + 0, depth)?;
1500            self.1.encode(encoder, offset + 4, depth)?;
1501            Ok(())
1502        }
1503    }
1504
1505    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1506        for ImagePipe2AddBufferCollectionRequest
1507    {
1508        #[inline(always)]
1509        fn new_empty() -> Self {
1510            Self {
1511                buffer_collection_id: fidl::new_empty!(
1512                    u32,
1513                    fidl::encoding::DefaultFuchsiaResourceDialect
1514                ),
1515                buffer_collection_token: fidl::new_empty!(
1516                    fidl::encoding::Endpoint<
1517                        fidl::endpoints::ClientEnd<
1518                            fidl_fuchsia_sysmem::BufferCollectionTokenMarker,
1519                        >,
1520                    >,
1521                    fidl::encoding::DefaultFuchsiaResourceDialect
1522                ),
1523            }
1524        }
1525
1526        #[inline]
1527        unsafe fn decode(
1528            &mut self,
1529            decoder: &mut fidl::encoding::Decoder<
1530                '_,
1531                fidl::encoding::DefaultFuchsiaResourceDialect,
1532            >,
1533            offset: usize,
1534            _depth: fidl::encoding::Depth,
1535        ) -> fidl::Result<()> {
1536            decoder.debug_check_bounds::<Self>(offset);
1537            // Verify that padding bytes are zero.
1538            fidl::decode!(
1539                u32,
1540                fidl::encoding::DefaultFuchsiaResourceDialect,
1541                &mut self.buffer_collection_id,
1542                decoder,
1543                offset + 0,
1544                _depth
1545            )?;
1546            fidl::decode!(
1547                fidl::encoding::Endpoint<
1548                    fidl::endpoints::ClientEnd<fidl_fuchsia_sysmem::BufferCollectionTokenMarker>,
1549                >,
1550                fidl::encoding::DefaultFuchsiaResourceDialect,
1551                &mut self.buffer_collection_token,
1552                decoder,
1553                offset + 4,
1554                _depth
1555            )?;
1556            Ok(())
1557        }
1558    }
1559
1560    impl fidl::encoding::ResourceTypeMarker for ImagePipe2PresentImageRequest {
1561        type Borrowed<'a> = &'a mut Self;
1562        fn take_or_borrow<'a>(
1563            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1564        ) -> Self::Borrowed<'a> {
1565            value
1566        }
1567    }
1568
1569    unsafe impl fidl::encoding::TypeMarker for ImagePipe2PresentImageRequest {
1570        type Owned = Self;
1571
1572        #[inline(always)]
1573        fn inline_align(_context: fidl::encoding::Context) -> usize {
1574            8
1575        }
1576
1577        #[inline(always)]
1578        fn inline_size(_context: fidl::encoding::Context) -> usize {
1579            48
1580        }
1581    }
1582
1583    unsafe impl
1584        fidl::encoding::Encode<
1585            ImagePipe2PresentImageRequest,
1586            fidl::encoding::DefaultFuchsiaResourceDialect,
1587        > for &mut ImagePipe2PresentImageRequest
1588    {
1589        #[inline]
1590        unsafe fn encode(
1591            self,
1592            encoder: &mut fidl::encoding::Encoder<
1593                '_,
1594                fidl::encoding::DefaultFuchsiaResourceDialect,
1595            >,
1596            offset: usize,
1597            _depth: fidl::encoding::Depth,
1598        ) -> fidl::Result<()> {
1599            encoder.debug_check_bounds::<ImagePipe2PresentImageRequest>(offset);
1600            // Delegate to tuple encoding.
1601            fidl::encoding::Encode::<
1602                ImagePipe2PresentImageRequest,
1603                fidl::encoding::DefaultFuchsiaResourceDialect,
1604            >::encode(
1605                (
1606                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.image_id),
1607                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.presentation_time),
1608                    <fidl::encoding::Vector<
1609                        fidl::encoding::HandleType<
1610                            fidl::Event,
1611                            { fidl::ObjectType::EVENT.into_raw() },
1612                            2147483648,
1613                        >,
1614                        16,
1615                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1616                        &mut self.acquire_fences,
1617                    ),
1618                    <fidl::encoding::Vector<
1619                        fidl::encoding::HandleType<
1620                            fidl::Event,
1621                            { fidl::ObjectType::EVENT.into_raw() },
1622                            2147483648,
1623                        >,
1624                        16,
1625                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1626                        &mut self.release_fences,
1627                    ),
1628                ),
1629                encoder,
1630                offset,
1631                _depth,
1632            )
1633        }
1634    }
1635    unsafe impl<
1636            T0: fidl::encoding::Encode<u32, fidl::encoding::DefaultFuchsiaResourceDialect>,
1637            T1: fidl::encoding::Encode<u64, fidl::encoding::DefaultFuchsiaResourceDialect>,
1638            T2: fidl::encoding::Encode<
1639                fidl::encoding::Vector<
1640                    fidl::encoding::HandleType<
1641                        fidl::Event,
1642                        { fidl::ObjectType::EVENT.into_raw() },
1643                        2147483648,
1644                    >,
1645                    16,
1646                >,
1647                fidl::encoding::DefaultFuchsiaResourceDialect,
1648            >,
1649            T3: fidl::encoding::Encode<
1650                fidl::encoding::Vector<
1651                    fidl::encoding::HandleType<
1652                        fidl::Event,
1653                        { fidl::ObjectType::EVENT.into_raw() },
1654                        2147483648,
1655                    >,
1656                    16,
1657                >,
1658                fidl::encoding::DefaultFuchsiaResourceDialect,
1659            >,
1660        >
1661        fidl::encoding::Encode<
1662            ImagePipe2PresentImageRequest,
1663            fidl::encoding::DefaultFuchsiaResourceDialect,
1664        > for (T0, T1, T2, T3)
1665    {
1666        #[inline]
1667        unsafe fn encode(
1668            self,
1669            encoder: &mut fidl::encoding::Encoder<
1670                '_,
1671                fidl::encoding::DefaultFuchsiaResourceDialect,
1672            >,
1673            offset: usize,
1674            depth: fidl::encoding::Depth,
1675        ) -> fidl::Result<()> {
1676            encoder.debug_check_bounds::<ImagePipe2PresentImageRequest>(offset);
1677            // Zero out padding regions. There's no need to apply masks
1678            // because the unmasked parts will be overwritten by fields.
1679            unsafe {
1680                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
1681                (ptr as *mut u64).write_unaligned(0);
1682            }
1683            // Write the fields.
1684            self.0.encode(encoder, offset + 0, depth)?;
1685            self.1.encode(encoder, offset + 8, depth)?;
1686            self.2.encode(encoder, offset + 16, depth)?;
1687            self.3.encode(encoder, offset + 32, depth)?;
1688            Ok(())
1689        }
1690    }
1691
1692    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1693        for ImagePipe2PresentImageRequest
1694    {
1695        #[inline(always)]
1696        fn new_empty() -> Self {
1697            Self {
1698                image_id: fidl::new_empty!(u32, fidl::encoding::DefaultFuchsiaResourceDialect),
1699                presentation_time: fidl::new_empty!(
1700                    u64,
1701                    fidl::encoding::DefaultFuchsiaResourceDialect
1702                ),
1703                acquire_fences: fidl::new_empty!(
1704                    fidl::encoding::Vector<
1705                        fidl::encoding::HandleType<
1706                            fidl::Event,
1707                            { fidl::ObjectType::EVENT.into_raw() },
1708                            2147483648,
1709                        >,
1710                        16,
1711                    >,
1712                    fidl::encoding::DefaultFuchsiaResourceDialect
1713                ),
1714                release_fences: fidl::new_empty!(
1715                    fidl::encoding::Vector<
1716                        fidl::encoding::HandleType<
1717                            fidl::Event,
1718                            { fidl::ObjectType::EVENT.into_raw() },
1719                            2147483648,
1720                        >,
1721                        16,
1722                    >,
1723                    fidl::encoding::DefaultFuchsiaResourceDialect
1724                ),
1725            }
1726        }
1727
1728        #[inline]
1729        unsafe fn decode(
1730            &mut self,
1731            decoder: &mut fidl::encoding::Decoder<
1732                '_,
1733                fidl::encoding::DefaultFuchsiaResourceDialect,
1734            >,
1735            offset: usize,
1736            _depth: fidl::encoding::Depth,
1737        ) -> fidl::Result<()> {
1738            decoder.debug_check_bounds::<Self>(offset);
1739            // Verify that padding bytes are zero.
1740            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
1741            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1742            let mask = 0xffffffff00000000u64;
1743            let maskedval = padval & mask;
1744            if maskedval != 0 {
1745                return Err(fidl::Error::NonZeroPadding {
1746                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
1747                });
1748            }
1749            fidl::decode!(
1750                u32,
1751                fidl::encoding::DefaultFuchsiaResourceDialect,
1752                &mut self.image_id,
1753                decoder,
1754                offset + 0,
1755                _depth
1756            )?;
1757            fidl::decode!(
1758                u64,
1759                fidl::encoding::DefaultFuchsiaResourceDialect,
1760                &mut self.presentation_time,
1761                decoder,
1762                offset + 8,
1763                _depth
1764            )?;
1765            fidl::decode!(
1766                fidl::encoding::Vector<
1767                    fidl::encoding::HandleType<
1768                        fidl::Event,
1769                        { fidl::ObjectType::EVENT.into_raw() },
1770                        2147483648,
1771                    >,
1772                    16,
1773                >,
1774                fidl::encoding::DefaultFuchsiaResourceDialect,
1775                &mut self.acquire_fences,
1776                decoder,
1777                offset + 16,
1778                _depth
1779            )?;
1780            fidl::decode!(
1781                fidl::encoding::Vector<
1782                    fidl::encoding::HandleType<
1783                        fidl::Event,
1784                        { fidl::ObjectType::EVENT.into_raw() },
1785                        2147483648,
1786                    >,
1787                    16,
1788                >,
1789                fidl::encoding::DefaultFuchsiaResourceDialect,
1790                &mut self.release_fences,
1791                decoder,
1792                offset + 32,
1793                _depth
1794            )?;
1795            Ok(())
1796        }
1797    }
1798}