wp_viewporter_client_protocol/wp_viewporter_client_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 = Event;
62 type Outgoing = Request;
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: NewId,
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 Request {
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 Request::Destroy {
137 } => {
138 header.opcode = 0;
139 },
140 Request::GetViewport {
141 id,
142 surface,
143 } => {
144 msg.write_arg(Arg::NewId(id))?;
145 msg.write_arg(Arg::Object(surface))?;
146 header.opcode = 1;
147 },
148 }
149 header.length = msg.bytes().len() as u16;
150 msg.rewind();
151 msg.write_header(&header)?;
152 Ok(msg)
153 }
154}
155impl FromArgs for Event {
156 fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
157 match op {
158 _ => {
159 Err(DecodeError::InvalidOpcode(op).into())
160 },
161 }
162 }
163}
164#[derive(Copy, Clone, Debug, Eq, PartialEq)]
165#[repr(u32)]
166pub enum Error {
167 /// the surface already has a viewport object associated,
168 ViewportExists = 0,
169}
170
171impl Error {
172 pub fn from_bits(v: u32) -> Option<Self> {
173 match v {
174 0 => Some(Error::ViewportExists),
175 _ => None,
176 }
177 }
178
179 pub fn bits(&self) -> u32 {
180 *self as u32
181 }
182}
183impl Into<Arg> for Error {
184 fn into(self) -> Arg {
185 Arg::Uint(self.bits())
186 }
187}
188} // mod wp_viewporter
189
190pub use crate::wp_viewporter::WpViewporter;
191pub use crate::wp_viewporter::Request as WpViewporterRequest;
192pub use crate::wp_viewporter::Event as WpViewporterEvent;
193pub mod wp_viewport {
194use super::*;
195
196/// crop and scale interface to a wl_surface
197///
198/// An additional interface to a wl_surface object, which allows the
199/// client to specify the cropping and scaling of the surface
200/// contents.
201///
202/// This interface works with two concepts: the source rectangle (src_x,
203/// src_y, src_width, src_height), and the destination size (dst_width,
204/// dst_height). The contents of the source rectangle are scaled to the
205/// destination size, and content outside the source rectangle is ignored.
206/// This state is double-buffered, and is applied on the next
207/// wl_surface.commit.
208///
209/// The two parts of crop and scale state are independent: the source
210/// rectangle, and the destination size. Initially both are unset, that
211/// is, no scaling is applied. The whole of the current wl_buffer is
212/// used as the source, and the surface size is as defined in
213/// wl_surface.attach.
214///
215/// If the destination size is set, it causes the surface size to become
216/// dst_width, dst_height. The source (rectangle) is scaled to exactly
217/// this size. This overrides whatever the attached wl_buffer size is,
218/// unless the wl_buffer is NULL. If the wl_buffer is NULL, the surface
219/// has no content and therefore no size. Otherwise, the size is always
220/// at least 1x1 in surface local coordinates.
221///
222/// If the source rectangle is set, it defines what area of the wl_buffer is
223/// taken as the source. If the source rectangle is set and the destination
224/// size is not set, then src_width and src_height must be integers, and the
225/// surface size becomes the source rectangle size. This results in cropping
226/// without scaling. If src_width or src_height are not integers and
227/// destination size is not set, the bad_size protocol error is raised when
228/// the surface state is applied.
229///
230/// The coordinate transformations from buffer pixel coordinates up to
231/// the surface-local coordinates happen in the following order:
232/// 1. buffer_transform (wl_surface.set_buffer_transform)
233/// 2. buffer_scale (wl_surface.set_buffer_scale)
234/// 3. crop and scale (wp_viewport.set*)
235/// This means, that the source rectangle coordinates of crop and scale
236/// are given in the coordinates after the buffer transform and scale,
237/// i.e. in the coordinates that would be the surface-local coordinates
238/// if the crop and scale was not applied.
239///
240/// If src_x or src_y are negative, the bad_value protocol error is raised.
241/// Otherwise, if the source rectangle is partially or completely outside of
242/// the non-NULL wl_buffer, then the out_of_buffer protocol error is raised
243/// when the surface state is applied. A NULL wl_buffer does not raise the
244/// out_of_buffer error.
245///
246/// The x, y arguments of wl_surface.attach are applied as normal to
247/// the surface. They indicate how many pixels to remove from the
248/// surface size from the left and the top. In other words, they are
249/// still in the surface-local coordinate system, just like dst_width
250/// and dst_height are.
251///
252/// If the wl_surface associated with the wp_viewport is destroyed,
253/// all wp_viewport requests except 'destroy' raise the protocol error
254/// no_surface.
255///
256/// If the wp_viewport object is destroyed, the crop and scale
257/// state is removed from the wl_surface. The change will be applied
258/// on the next wl_surface.commit.
259#[derive(Debug)]
260pub struct WpViewport;
261
262impl Interface for WpViewport {
263 const NAME: &'static str = "wp_viewport";
264 const VERSION: u32 = 1;
265 const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
266 // destroy
267 MessageSpec(&[
268 ]),
269 // set_source
270 MessageSpec(&[
271 ArgKind::Fixed,
272 ArgKind::Fixed,
273 ArgKind::Fixed,
274 ArgKind::Fixed,
275 ]),
276 // set_destination
277 MessageSpec(&[
278 ArgKind::Int,
279 ArgKind::Int,
280 ]),
281 ]);
282 const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
283 ]);
284 type Incoming = Event;
285 type Outgoing = Request;
286}
287
288#[derive(Debug)]
289pub enum Request {
290
291 /// remove scaling and cropping from the surface
292 ///
293 /// The associated wl_surface's crop and scale state is removed.
294 /// The change is applied on the next wl_surface.commit.
295 Destroy,
296
297 /// set the source rectangle for cropping
298 ///
299 /// Set the source rectangle of the associated wl_surface. See
300 /// wp_viewport for the description, and relation to the wl_buffer
301 /// size.
302 ///
303 /// If all of x, y, width and height are -1.0, the source rectangle is
304 /// unset instead. Any other set of values where width or height are zero
305 /// or negative, or x or y are negative, raise the bad_value protocol
306 /// error.
307 ///
308 /// The crop and scale state is double-buffered state, and will be
309 /// applied on the next wl_surface.commit.
310 SetSource {
311 /// source rectangle x
312 x: Fixed,
313 /// source rectangle y
314 y: Fixed,
315 /// source rectangle width
316 width: Fixed,
317 /// source rectangle height
318 height: Fixed,
319 },
320
321 /// set the surface size for scaling
322 ///
323 /// Set the destination size of the associated wl_surface. See
324 /// wp_viewport for the description, and relation to the wl_buffer
325 /// size.
326 ///
327 /// If width is -1 and height is -1, the destination size is unset
328 /// instead. Any other pair of values for width and height that
329 /// contains zero or negative values raises the bad_value protocol
330 /// error.
331 ///
332 /// The crop and scale state is double-buffered state, and will be
333 /// applied on the next wl_surface.commit.
334 SetDestination {
335 /// surface width
336 width: i32,
337 /// surface height
338 height: i32,
339 },
340}
341
342impl MessageType for Request {
343 fn log(&self, this: ObjectId) -> String {
344 match *self {
345 Request::Destroy {
346 } => {
347 format!("wp_viewport@{:?}::destroy()", this)
348 }
349 Request::SetSource {
350 ref x,
351 ref y,
352 ref width,
353 ref height,
354 } => {
355 format!("wp_viewport@{:?}::set_source(x: {:?}, y: {:?}, width: {:?}, height: {:?})", this, x, y, width, height)
356 }
357 Request::SetDestination {
358 ref width,
359 ref height,
360 } => {
361 format!("wp_viewport@{:?}::set_destination(width: {:?}, height: {:?})", this, width, height)
362 }
363 }
364 }
365 fn message_name(&self) -> &'static std::ffi::CStr{
366 match *self {
367 Request::Destroy { .. } => c"wp_viewport::destroy",
368 Request::SetSource { .. } => c"wp_viewport::set_source",
369 Request::SetDestination { .. } => c"wp_viewport::set_destination",
370 }
371 }
372}
373#[derive(Debug)]
374pub enum Event {
375}
376
377impl MessageType for Event {
378 fn log(&self, this: ObjectId) -> String {
379 match *self {
380 }
381 }
382 fn message_name(&self) -> &'static std::ffi::CStr{
383 match *self {
384 }
385 }
386}
387impl IntoMessage for Request {
388 type Error = EncodeError;
389 fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
390 let mut header = MessageHeader {
391 sender: id,
392 opcode: 0,
393 length: 0,
394 };
395 let mut msg = Message::new();
396 msg.write_header(&header)?;
397 match self {
398 Request::Destroy {
399 } => {
400 header.opcode = 0;
401 },
402 Request::SetSource {
403 x,
404 y,
405 width,
406 height,
407 } => {
408 msg.write_arg(Arg::Fixed(x))?;
409 msg.write_arg(Arg::Fixed(y))?;
410 msg.write_arg(Arg::Fixed(width))?;
411 msg.write_arg(Arg::Fixed(height))?;
412 header.opcode = 1;
413 },
414 Request::SetDestination {
415 width,
416 height,
417 } => {
418 msg.write_arg(Arg::Int(width))?;
419 msg.write_arg(Arg::Int(height))?;
420 header.opcode = 2;
421 },
422 }
423 header.length = msg.bytes().len() as u16;
424 msg.rewind();
425 msg.write_header(&header)?;
426 Ok(msg)
427 }
428}
429impl FromArgs for Event {
430 fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
431 match op {
432 _ => {
433 Err(DecodeError::InvalidOpcode(op).into())
434 },
435 }
436 }
437}
438#[derive(Copy, Clone, Debug, Eq, PartialEq)]
439#[repr(u32)]
440pub enum Error {
441 /// negative or zero values in width or height,
442 BadValue = 0,
443 /// destination size is not integer,
444 BadSize = 1,
445 /// source rectangle extends outside of the content area,
446 OutOfBuffer = 2,
447 /// the wl_surface was destroyed,
448 NoSurface = 3,
449}
450
451impl Error {
452 pub fn from_bits(v: u32) -> Option<Self> {
453 match v {
454 0 => Some(Error::BadValue),
455 1 => Some(Error::BadSize),
456 2 => Some(Error::OutOfBuffer),
457 3 => Some(Error::NoSurface),
458 _ => None,
459 }
460 }
461
462 pub fn bits(&self) -> u32 {
463 *self as u32
464 }
465}
466impl Into<Arg> for Error {
467 fn into(self) -> Arg {
468 Arg::Uint(self.bits())
469 }
470}
471} // mod wp_viewport
472
473pub use crate::wp_viewport::WpViewport;
474pub use crate::wp_viewport::Request as WpViewportRequest;
475pub use crate::wp_viewport::Event as WpViewportEvent;