1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
// GENERATED FILE -- DO NOT EDIT
//
// Copyright © 2013-2016 Collabora, Ltd.
// 
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice (including the next
// paragraph) shall be included in all copies or substantial portions of the
// Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

#![allow(warnings)]
#![allow(clippy::all)]
use anyhow;
#[allow(unused_imports)]
use fuchsia_wayland_core::{Array, Enum, Fixed, NewId, NewObject};
use fuchsia_wayland_core::{ArgKind, Arg, FromArgs, IntoMessage, Message,
                            MessageGroupSpec, MessageHeader, MessageSpec, MessageType,
                            ObjectId, EncodeError, DecodeError, Interface};
pub mod wp_viewporter {
use super::*;

/// surface cropping and scaling
///
/// The global interface exposing surface cropping and scaling
/// capabilities is used to instantiate an interface extension for a
/// wl_surface object. This extended interface will then allow
/// cropping and scaling the surface contents, effectively
/// disconnecting the direct relationship between the buffer and the
/// surface size.
#[derive(Debug)]
pub struct WpViewporter;

impl Interface for WpViewporter {
    const NAME: &'static str = "wp_viewporter";
    const VERSION: u32 = 1;
    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
        // destroy
        MessageSpec(&[
        ]),
        // get_viewport
        MessageSpec(&[
            ArgKind::NewId,
            ArgKind::Object,
        ]),
    ]);
    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
    ]);
    type Incoming = Request;
    type Outgoing = Event;
}

#[derive(Debug)]
pub enum Request {

    /// unbind from the cropping and scaling interface
    ///
    /// Informs the server that the client will not be using this
    /// protocol object anymore. This does not affect any other objects,
    /// wp_viewport objects included.
    Destroy,

    /// extend surface interface for crop and scale
    ///
    /// Instantiate an interface extension for the given wl_surface to
    /// crop and scale its content. If the given wl_surface already has
    /// a wp_viewport object associated, the viewport_exists
    /// protocol error is raised.
    GetViewport {
        /// the new viewport interface id
        id: NewObject<WpViewport>,
        /// the surface
        surface: ObjectId,
    },
}

impl MessageType for Request {
    fn log(&self, this: ObjectId) -> String {
        match *self {
            Request::Destroy {
            } => {
                format!("wp_viewporter@{:?}::destroy()", this)
            }
            Request::GetViewport {
                ref id,
                ref surface,
            } => {
                format!("wp_viewporter@{:?}::get_viewport(id: {:?}, surface: {:?})", this, id, surface)
            }
        }
    }
    fn message_name(&self) -> &'static std::ffi::CStr{
        match *self {
            Request::Destroy { .. } => c"wp_viewporter::destroy",
            Request::GetViewport { .. } => c"wp_viewporter::get_viewport",
        }
    }
}
#[derive(Debug)]
pub enum Event {
}

impl MessageType for Event {
    fn log(&self, this: ObjectId) -> String {
        match *self {
        }
    }
    fn message_name(&self) -> &'static std::ffi::CStr{
        match *self {
        }
    }
}
impl IntoMessage for Event {
    type Error = EncodeError;
    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
        let mut header = MessageHeader {
            sender: id,
            opcode: 0,
            length: 0,
        };
        let mut msg = Message::new();
        msg.write_header(&header)?;
        match self {
        }
        header.length = msg.bytes().len() as u16;
        msg.rewind();
        msg.write_header(&header)?;
        Ok(msg)
    }
}
impl FromArgs for Request {
    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
        match op {
        0 /* destroy */ => {
            let mut iter = args.into_iter();
            Ok(Request::Destroy {

            })
        },
        1 /* get_viewport */ => {
            let mut iter = args.into_iter();
            Ok(Request::GetViewport {
                id: iter.next()
                                             .ok_or(DecodeError::InsufficientArgs)?
                                             .as_new_id()?.into(),
                surface: iter.next()
                                             .ok_or(DecodeError::InsufficientArgs)?
                                             .as_object()?,

            })
        },
        _ => {
            Err(DecodeError::InvalidOpcode(op).into())
        },
        }
    }
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum Error {
    /// the surface already has a viewport object associated,
    ViewportExists = 0,
}

impl Error {
    pub fn from_bits(v: u32) -> Option<Self> {
        match v {
        0 => Some(Error::ViewportExists),
        _ => None,
        }
    }

    pub fn bits(&self) -> u32 {
        *self as u32
    }
}
impl Into<Arg> for Error {
    fn into(self) -> Arg {
        Arg::Uint(self.bits())
    }
}
} // mod wp_viewporter

pub use crate::wp_viewporter::WpViewporter;
pub use crate::wp_viewporter::Request as WpViewporterRequest;
pub use crate::wp_viewporter::Event as WpViewporterEvent;
pub mod wp_viewport {
use super::*;

/// crop and scale interface to a wl_surface
///
/// An additional interface to a wl_surface object, which allows the
/// client to specify the cropping and scaling of the surface
/// contents.
/// 
/// This interface works with two concepts: the source rectangle (src_x,
/// src_y, src_width, src_height), and the destination size (dst_width,
/// dst_height). The contents of the source rectangle are scaled to the
/// destination size, and content outside the source rectangle is ignored.
/// This state is double-buffered, and is applied on the next
/// wl_surface.commit.
/// 
/// The two parts of crop and scale state are independent: the source
/// rectangle, and the destination size. Initially both are unset, that
/// is, no scaling is applied. The whole of the current wl_buffer is
/// used as the source, and the surface size is as defined in
/// wl_surface.attach.
/// 
/// If the destination size is set, it causes the surface size to become
/// dst_width, dst_height. The source (rectangle) is scaled to exactly
/// this size. This overrides whatever the attached wl_buffer size is,
/// unless the wl_buffer is NULL. If the wl_buffer is NULL, the surface
/// has no content and therefore no size. Otherwise, the size is always
/// at least 1x1 in surface local coordinates.
/// 
/// If the source rectangle is set, it defines what area of the wl_buffer is
/// taken as the source. If the source rectangle is set and the destination
/// size is not set, then src_width and src_height must be integers, and the
/// surface size becomes the source rectangle size. This results in cropping
/// without scaling. If src_width or src_height are not integers and
/// destination size is not set, the bad_size protocol error is raised when
/// the surface state is applied.
/// 
/// The coordinate transformations from buffer pixel coordinates up to
/// the surface-local coordinates happen in the following order:
/// 1. buffer_transform (wl_surface.set_buffer_transform)
/// 2. buffer_scale (wl_surface.set_buffer_scale)
/// 3. crop and scale (wp_viewport.set*)
/// This means, that the source rectangle coordinates of crop and scale
/// are given in the coordinates after the buffer transform and scale,
/// i.e. in the coordinates that would be the surface-local coordinates
/// if the crop and scale was not applied.
/// 
/// If src_x or src_y are negative, the bad_value protocol error is raised.
/// Otherwise, if the source rectangle is partially or completely outside of
/// the non-NULL wl_buffer, then the out_of_buffer protocol error is raised
/// when the surface state is applied. A NULL wl_buffer does not raise the
/// out_of_buffer error.
/// 
/// The x, y arguments of wl_surface.attach are applied as normal to
/// the surface. They indicate how many pixels to remove from the
/// surface size from the left and the top. In other words, they are
/// still in the surface-local coordinate system, just like dst_width
/// and dst_height are.
/// 
/// If the wl_surface associated with the wp_viewport is destroyed,
/// all wp_viewport requests except 'destroy' raise the protocol error
/// no_surface.
/// 
/// If the wp_viewport object is destroyed, the crop and scale
/// state is removed from the wl_surface. The change will be applied
/// on the next wl_surface.commit.
#[derive(Debug)]
pub struct WpViewport;

impl Interface for WpViewport {
    const NAME: &'static str = "wp_viewport";
    const VERSION: u32 = 1;
    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
        // destroy
        MessageSpec(&[
        ]),
        // set_source
        MessageSpec(&[
            ArgKind::Fixed,
            ArgKind::Fixed,
            ArgKind::Fixed,
            ArgKind::Fixed,
        ]),
        // set_destination
        MessageSpec(&[
            ArgKind::Int,
            ArgKind::Int,
        ]),
    ]);
    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
    ]);
    type Incoming = Request;
    type Outgoing = Event;
}

#[derive(Debug)]
pub enum Request {

    /// remove scaling and cropping from the surface
    ///
    /// The associated wl_surface's crop and scale state is removed.
    /// The change is applied on the next wl_surface.commit.
    Destroy,

    /// set the source rectangle for cropping
    ///
    /// Set the source rectangle of the associated wl_surface. See
    /// wp_viewport for the description, and relation to the wl_buffer
    /// size.
    /// 
    /// If all of x, y, width and height are -1.0, the source rectangle is
    /// unset instead. Any other set of values where width or height are zero
    /// or negative, or x or y are negative, raise the bad_value protocol
    /// error.
    /// 
    /// The crop and scale state is double-buffered state, and will be
    /// applied on the next wl_surface.commit.
    SetSource {
        /// source rectangle x
        x: Fixed,
        /// source rectangle y
        y: Fixed,
        /// source rectangle width
        width: Fixed,
        /// source rectangle height
        height: Fixed,
    },

    /// set the surface size for scaling
    ///
    /// Set the destination size of the associated wl_surface. See
    /// wp_viewport for the description, and relation to the wl_buffer
    /// size.
    /// 
    /// If width is -1 and height is -1, the destination size is unset
    /// instead. Any other pair of values for width and height that
    /// contains zero or negative values raises the bad_value protocol
    /// error.
    /// 
    /// The crop and scale state is double-buffered state, and will be
    /// applied on the next wl_surface.commit.
    SetDestination {
        /// surface width
        width: i32,
        /// surface height
        height: i32,
    },
}

impl MessageType for Request {
    fn log(&self, this: ObjectId) -> String {
        match *self {
            Request::Destroy {
            } => {
                format!("wp_viewport@{:?}::destroy()", this)
            }
            Request::SetSource {
                ref x,
                ref y,
                ref width,
                ref height,
            } => {
                format!("wp_viewport@{:?}::set_source(x: {:?}, y: {:?}, width: {:?}, height: {:?})", this, x, y, width, height)
            }
            Request::SetDestination {
                ref width,
                ref height,
            } => {
                format!("wp_viewport@{:?}::set_destination(width: {:?}, height: {:?})", this, width, height)
            }
        }
    }
    fn message_name(&self) -> &'static std::ffi::CStr{
        match *self {
            Request::Destroy { .. } => c"wp_viewport::destroy",
            Request::SetSource { .. } => c"wp_viewport::set_source",
            Request::SetDestination { .. } => c"wp_viewport::set_destination",
        }
    }
}
#[derive(Debug)]
pub enum Event {
}

impl MessageType for Event {
    fn log(&self, this: ObjectId) -> String {
        match *self {
        }
    }
    fn message_name(&self) -> &'static std::ffi::CStr{
        match *self {
        }
    }
}
impl IntoMessage for Event {
    type Error = EncodeError;
    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
        let mut header = MessageHeader {
            sender: id,
            opcode: 0,
            length: 0,
        };
        let mut msg = Message::new();
        msg.write_header(&header)?;
        match self {
        }
        header.length = msg.bytes().len() as u16;
        msg.rewind();
        msg.write_header(&header)?;
        Ok(msg)
    }
}
impl FromArgs for Request {
    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
        match op {
        0 /* destroy */ => {
            let mut iter = args.into_iter();
            Ok(Request::Destroy {

            })
        },
        1 /* set_source */ => {
            let mut iter = args.into_iter();
            Ok(Request::SetSource {
                x: iter.next()
                                             .ok_or(DecodeError::InsufficientArgs)?
                                             .as_fixed()?.into(),
                y: iter.next()
                                             .ok_or(DecodeError::InsufficientArgs)?
                                             .as_fixed()?.into(),
                width: iter.next()
                                             .ok_or(DecodeError::InsufficientArgs)?
                                             .as_fixed()?.into(),
                height: iter.next()
                                             .ok_or(DecodeError::InsufficientArgs)?
                                             .as_fixed()?.into(),

            })
        },
        2 /* set_destination */ => {
            let mut iter = args.into_iter();
            Ok(Request::SetDestination {
                width: iter.next()
                                             .ok_or(DecodeError::InsufficientArgs)?
                                             .as_int()?,
                height: iter.next()
                                             .ok_or(DecodeError::InsufficientArgs)?
                                             .as_int()?,

            })
        },
        _ => {
            Err(DecodeError::InvalidOpcode(op).into())
        },
        }
    }
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum Error {
    /// negative or zero values in width or height,
    BadValue = 0,
    /// destination size is not integer,
    BadSize = 1,
    /// source rectangle extends outside of the content area,
    OutOfBuffer = 2,
    /// the wl_surface was destroyed,
    NoSurface = 3,
}

impl Error {
    pub fn from_bits(v: u32) -> Option<Self> {
        match v {
        0 => Some(Error::BadValue),
        1 => Some(Error::BadSize),
        2 => Some(Error::OutOfBuffer),
        3 => Some(Error::NoSurface),
        _ => None,
        }
    }

    pub fn bits(&self) -> u32 {
        *self as u32
    }
}
impl Into<Arg> for Error {
    fn into(self) -> Arg {
        Arg::Uint(self.bits())
    }
}
} // mod wp_viewport

pub use crate::wp_viewport::WpViewport;
pub use crate::wp_viewport::Request as WpViewportRequest;
pub use crate::wp_viewport::Event as WpViewportEvent;