wp_viewporter_server_protocol/
wp_viewporter_server_protocol.rs

1// GENERATED FILE -- DO NOT EDIT
2//
3// Copyright © 2013-2016 Collabora, Ltd.
4// 
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11// 
12// The above copyright notice and this permission notice (including the next
13// paragraph) shall be included in all copies or substantial portions of the
14// Software.
15// 
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22// DEALINGS IN THE SOFTWARE.
23
24#![allow(warnings)]
25#![allow(clippy::all)]
26use anyhow;
27#[allow(unused_imports)]
28use fuchsia_wayland_core::{Array, Enum, Fixed, NewId, NewObject};
29use fuchsia_wayland_core::{ArgKind, Arg, FromArgs, IntoMessage, Message,
30                            MessageGroupSpec, MessageHeader, MessageSpec, MessageType,
31                            ObjectId, EncodeError, DecodeError, Interface};
32pub mod wp_viewporter {
33use super::*;
34
35/// surface cropping and scaling
36///
37/// The global interface exposing surface cropping and scaling
38/// capabilities is used to instantiate an interface extension for a
39/// wl_surface object. This extended interface will then allow
40/// cropping and scaling the surface contents, effectively
41/// disconnecting the direct relationship between the buffer and the
42/// surface size.
43#[derive(Debug)]
44pub struct WpViewporter;
45
46impl Interface for WpViewporter {
47    const NAME: &'static str = "wp_viewporter";
48    const VERSION: u32 = 1;
49    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
50        // destroy
51        MessageSpec(&[
52        ]),
53        // get_viewport
54        MessageSpec(&[
55            ArgKind::NewId,
56            ArgKind::Object,
57        ]),
58    ]);
59    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
60    ]);
61    type Incoming = Request;
62    type Outgoing = Event;
63}
64
65#[derive(Debug)]
66pub enum Request {
67
68    /// unbind from the cropping and scaling interface
69    ///
70    /// Informs the server that the client will not be using this
71    /// protocol object anymore. This does not affect any other objects,
72    /// wp_viewport objects included.
73    Destroy,
74
75    /// extend surface interface for crop and scale
76    ///
77    /// Instantiate an interface extension for the given wl_surface to
78    /// crop and scale its content. If the given wl_surface already has
79    /// a wp_viewport object associated, the viewport_exists
80    /// protocol error is raised.
81    GetViewport {
82        /// the new viewport interface id
83        id: NewObject<WpViewport>,
84        /// the surface
85        surface: ObjectId,
86    },
87}
88
89impl MessageType for Request {
90    fn log(&self, this: ObjectId) -> String {
91        match *self {
92            Request::Destroy {
93            } => {
94                format!("wp_viewporter@{:?}::destroy()", this)
95            }
96            Request::GetViewport {
97                ref id,
98                ref surface,
99            } => {
100                format!("wp_viewporter@{:?}::get_viewport(id: {:?}, surface: {:?})", this, id, surface)
101            }
102        }
103    }
104    fn message_name(&self) -> &'static std::ffi::CStr{
105        match *self {
106            Request::Destroy { .. } => c"wp_viewporter::destroy",
107            Request::GetViewport { .. } => c"wp_viewporter::get_viewport",
108        }
109    }
110}
111#[derive(Debug)]
112pub enum Event {
113}
114
115impl MessageType for Event {
116    fn log(&self, this: ObjectId) -> String {
117        match *self {
118        }
119    }
120    fn message_name(&self) -> &'static std::ffi::CStr{
121        match *self {
122        }
123    }
124}
125impl IntoMessage for Event {
126    type Error = EncodeError;
127    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
128        let mut header = MessageHeader {
129            sender: id,
130            opcode: 0,
131            length: 0,
132        };
133        let mut msg = Message::new();
134        msg.write_header(&header)?;
135        match self {
136        }
137        header.length = msg.bytes().len() as u16;
138        msg.rewind();
139        msg.write_header(&header)?;
140        Ok(msg)
141    }
142}
143impl FromArgs for Request {
144    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
145        match op {
146        0 /* destroy */ => {
147            let mut iter = args.into_iter();
148            Ok(Request::Destroy {
149
150            })
151        },
152        1 /* get_viewport */ => {
153            let mut iter = args.into_iter();
154            Ok(Request::GetViewport {
155                id: iter.next()
156                                             .ok_or(DecodeError::InsufficientArgs)?
157                                             .as_new_id()?.into(),
158                surface: iter.next()
159                                             .ok_or(DecodeError::InsufficientArgs)?
160                                             .as_object()?,
161
162            })
163        },
164        _ => {
165            Err(DecodeError::InvalidOpcode(op).into())
166        },
167        }
168    }
169}
170#[derive(Copy, Clone, Debug, Eq, PartialEq)]
171#[repr(u32)]
172pub enum Error {
173    /// the surface already has a viewport object associated,
174    ViewportExists = 0,
175}
176
177impl Error {
178    pub fn from_bits(v: u32) -> Option<Self> {
179        match v {
180        0 => Some(Error::ViewportExists),
181        _ => None,
182        }
183    }
184
185    pub fn bits(&self) -> u32 {
186        *self as u32
187    }
188}
189impl Into<Arg> for Error {
190    fn into(self) -> Arg {
191        Arg::Uint(self.bits())
192    }
193}
194} // mod wp_viewporter
195
196pub use crate::wp_viewporter::WpViewporter;
197pub use crate::wp_viewporter::Request as WpViewporterRequest;
198pub use crate::wp_viewporter::Event as WpViewporterEvent;
199pub mod wp_viewport {
200use super::*;
201
202/// crop and scale interface to a wl_surface
203///
204/// An additional interface to a wl_surface object, which allows the
205/// client to specify the cropping and scaling of the surface
206/// contents.
207/// 
208/// This interface works with two concepts: the source rectangle (src_x,
209/// src_y, src_width, src_height), and the destination size (dst_width,
210/// dst_height). The contents of the source rectangle are scaled to the
211/// destination size, and content outside the source rectangle is ignored.
212/// This state is double-buffered, and is applied on the next
213/// wl_surface.commit.
214/// 
215/// The two parts of crop and scale state are independent: the source
216/// rectangle, and the destination size. Initially both are unset, that
217/// is, no scaling is applied. The whole of the current wl_buffer is
218/// used as the source, and the surface size is as defined in
219/// wl_surface.attach.
220/// 
221/// If the destination size is set, it causes the surface size to become
222/// dst_width, dst_height. The source (rectangle) is scaled to exactly
223/// this size. This overrides whatever the attached wl_buffer size is,
224/// unless the wl_buffer is NULL. If the wl_buffer is NULL, the surface
225/// has no content and therefore no size. Otherwise, the size is always
226/// at least 1x1 in surface local coordinates.
227/// 
228/// If the source rectangle is set, it defines what area of the wl_buffer is
229/// taken as the source. If the source rectangle is set and the destination
230/// size is not set, then src_width and src_height must be integers, and the
231/// surface size becomes the source rectangle size. This results in cropping
232/// without scaling. If src_width or src_height are not integers and
233/// destination size is not set, the bad_size protocol error is raised when
234/// the surface state is applied.
235/// 
236/// The coordinate transformations from buffer pixel coordinates up to
237/// the surface-local coordinates happen in the following order:
238/// 1. buffer_transform (wl_surface.set_buffer_transform)
239/// 2. buffer_scale (wl_surface.set_buffer_scale)
240/// 3. crop and scale (wp_viewport.set*)
241/// This means, that the source rectangle coordinates of crop and scale
242/// are given in the coordinates after the buffer transform and scale,
243/// i.e. in the coordinates that would be the surface-local coordinates
244/// if the crop and scale was not applied.
245/// 
246/// If src_x or src_y are negative, the bad_value protocol error is raised.
247/// Otherwise, if the source rectangle is partially or completely outside of
248/// the non-NULL wl_buffer, then the out_of_buffer protocol error is raised
249/// when the surface state is applied. A NULL wl_buffer does not raise the
250/// out_of_buffer error.
251/// 
252/// The x, y arguments of wl_surface.attach are applied as normal to
253/// the surface. They indicate how many pixels to remove from the
254/// surface size from the left and the top. In other words, they are
255/// still in the surface-local coordinate system, just like dst_width
256/// and dst_height are.
257/// 
258/// If the wl_surface associated with the wp_viewport is destroyed,
259/// all wp_viewport requests except 'destroy' raise the protocol error
260/// no_surface.
261/// 
262/// If the wp_viewport object is destroyed, the crop and scale
263/// state is removed from the wl_surface. The change will be applied
264/// on the next wl_surface.commit.
265#[derive(Debug)]
266pub struct WpViewport;
267
268impl Interface for WpViewport {
269    const NAME: &'static str = "wp_viewport";
270    const VERSION: u32 = 1;
271    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
272        // destroy
273        MessageSpec(&[
274        ]),
275        // set_source
276        MessageSpec(&[
277            ArgKind::Fixed,
278            ArgKind::Fixed,
279            ArgKind::Fixed,
280            ArgKind::Fixed,
281        ]),
282        // set_destination
283        MessageSpec(&[
284            ArgKind::Int,
285            ArgKind::Int,
286        ]),
287    ]);
288    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
289    ]);
290    type Incoming = Request;
291    type Outgoing = Event;
292}
293
294#[derive(Debug)]
295pub enum Request {
296
297    /// remove scaling and cropping from the surface
298    ///
299    /// The associated wl_surface's crop and scale state is removed.
300    /// The change is applied on the next wl_surface.commit.
301    Destroy,
302
303    /// set the source rectangle for cropping
304    ///
305    /// Set the source rectangle of the associated wl_surface. See
306    /// wp_viewport for the description, and relation to the wl_buffer
307    /// size.
308    /// 
309    /// If all of x, y, width and height are -1.0, the source rectangle is
310    /// unset instead. Any other set of values where width or height are zero
311    /// or negative, or x or y are negative, raise the bad_value protocol
312    /// error.
313    /// 
314    /// The crop and scale state is double-buffered state, and will be
315    /// applied on the next wl_surface.commit.
316    SetSource {
317        /// source rectangle x
318        x: Fixed,
319        /// source rectangle y
320        y: Fixed,
321        /// source rectangle width
322        width: Fixed,
323        /// source rectangle height
324        height: Fixed,
325    },
326
327    /// set the surface size for scaling
328    ///
329    /// Set the destination size of the associated wl_surface. See
330    /// wp_viewport for the description, and relation to the wl_buffer
331    /// size.
332    /// 
333    /// If width is -1 and height is -1, the destination size is unset
334    /// instead. Any other pair of values for width and height that
335    /// contains zero or negative values raises the bad_value protocol
336    /// error.
337    /// 
338    /// The crop and scale state is double-buffered state, and will be
339    /// applied on the next wl_surface.commit.
340    SetDestination {
341        /// surface width
342        width: i32,
343        /// surface height
344        height: i32,
345    },
346}
347
348impl MessageType for Request {
349    fn log(&self, this: ObjectId) -> String {
350        match *self {
351            Request::Destroy {
352            } => {
353                format!("wp_viewport@{:?}::destroy()", this)
354            }
355            Request::SetSource {
356                ref x,
357                ref y,
358                ref width,
359                ref height,
360            } => {
361                format!("wp_viewport@{:?}::set_source(x: {:?}, y: {:?}, width: {:?}, height: {:?})", this, x, y, width, height)
362            }
363            Request::SetDestination {
364                ref width,
365                ref height,
366            } => {
367                format!("wp_viewport@{:?}::set_destination(width: {:?}, height: {:?})", this, width, height)
368            }
369        }
370    }
371    fn message_name(&self) -> &'static std::ffi::CStr{
372        match *self {
373            Request::Destroy { .. } => c"wp_viewport::destroy",
374            Request::SetSource { .. } => c"wp_viewport::set_source",
375            Request::SetDestination { .. } => c"wp_viewport::set_destination",
376        }
377    }
378}
379#[derive(Debug)]
380pub enum Event {
381}
382
383impl MessageType for Event {
384    fn log(&self, this: ObjectId) -> String {
385        match *self {
386        }
387    }
388    fn message_name(&self) -> &'static std::ffi::CStr{
389        match *self {
390        }
391    }
392}
393impl IntoMessage for Event {
394    type Error = EncodeError;
395    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
396        let mut header = MessageHeader {
397            sender: id,
398            opcode: 0,
399            length: 0,
400        };
401        let mut msg = Message::new();
402        msg.write_header(&header)?;
403        match self {
404        }
405        header.length = msg.bytes().len() as u16;
406        msg.rewind();
407        msg.write_header(&header)?;
408        Ok(msg)
409    }
410}
411impl FromArgs for Request {
412    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
413        match op {
414        0 /* destroy */ => {
415            let mut iter = args.into_iter();
416            Ok(Request::Destroy {
417
418            })
419        },
420        1 /* set_source */ => {
421            let mut iter = args.into_iter();
422            Ok(Request::SetSource {
423                x: iter.next()
424                                             .ok_or(DecodeError::InsufficientArgs)?
425                                             .as_fixed()?.into(),
426                y: iter.next()
427                                             .ok_or(DecodeError::InsufficientArgs)?
428                                             .as_fixed()?.into(),
429                width: iter.next()
430                                             .ok_or(DecodeError::InsufficientArgs)?
431                                             .as_fixed()?.into(),
432                height: iter.next()
433                                             .ok_or(DecodeError::InsufficientArgs)?
434                                             .as_fixed()?.into(),
435
436            })
437        },
438        2 /* set_destination */ => {
439            let mut iter = args.into_iter();
440            Ok(Request::SetDestination {
441                width: iter.next()
442                                             .ok_or(DecodeError::InsufficientArgs)?
443                                             .as_int()?,
444                height: iter.next()
445                                             .ok_or(DecodeError::InsufficientArgs)?
446                                             .as_int()?,
447
448            })
449        },
450        _ => {
451            Err(DecodeError::InvalidOpcode(op).into())
452        },
453        }
454    }
455}
456#[derive(Copy, Clone, Debug, Eq, PartialEq)]
457#[repr(u32)]
458pub enum Error {
459    /// negative or zero values in width or height,
460    BadValue = 0,
461    /// destination size is not integer,
462    BadSize = 1,
463    /// source rectangle extends outside of the content area,
464    OutOfBuffer = 2,
465    /// the wl_surface was destroyed,
466    NoSurface = 3,
467}
468
469impl Error {
470    pub fn from_bits(v: u32) -> Option<Self> {
471        match v {
472        0 => Some(Error::BadValue),
473        1 => Some(Error::BadSize),
474        2 => Some(Error::OutOfBuffer),
475        3 => Some(Error::NoSurface),
476        _ => None,
477        }
478    }
479
480    pub fn bits(&self) -> u32 {
481        *self as u32
482    }
483}
484impl Into<Arg> for Error {
485    fn into(self) -> Arg {
486        Arg::Uint(self.bits())
487    }
488}
489} // mod wp_viewport
490
491pub use crate::wp_viewport::WpViewport;
492pub use crate::wp_viewport::Request as WpViewportRequest;
493pub use crate::wp_viewport::Event as WpViewportEvent;