Skip to main content

ferroui_remote_protocol/
viewport_messages.rs

1use crate::{bson_class, bson_enum, ferro_remote_message_guid};
2
3#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
4#[repr(i32)]
5pub enum PixelFormat {
6    #[default]
7    Rgb565 = 0,
8    Rgba8888 = 1,
9    Bgra8888 = 2,
10}
11
12#[allow(non_upper_case_globals)]
13impl PixelFormat {
14    pub const MaxValue: PixelFormat = PixelFormat::Bgra8888;
15
16    /// The member with the given numeric value, if one is defined.
17    pub fn from_value(value: i32) -> Option<PixelFormat> {
18        match value {
19            0 => Some(PixelFormat::Rgb565),
20            1 => Some(PixelFormat::Rgba8888),
21            2 => Some(PixelFormat::Bgra8888),
22            _ => None,
23        }
24    }
25}
26
27bson_enum!(PixelFormat);
28
29#[derive(Clone, Debug, Default, PartialEq)]
30pub struct MeasureViewportMessage {
31    pub width: f64,
32    pub height: f64,
33}
34
35ferro_remote_message_guid!(MeasureViewportMessage, "6E3C5310-E2B1-4C3D-8688-01183AA48C5B");
36bson_class!(MeasureViewportMessage as "MeasureViewportMessage" {
37    "Width" => width: f64,
38    "Height" => height: f64,
39});
40
41#[derive(Clone, Debug, Default, PartialEq)]
42pub struct ClientViewportAllocatedMessage {
43    pub width: f64,
44    pub height: f64,
45    pub dpi_x: f64,
46    pub dpi_y: f64,
47}
48
49ferro_remote_message_guid!(ClientViewportAllocatedMessage, "BD7A8DE6-3DB8-4A13-8583-D6D4AB189A31");
50bson_class!(ClientViewportAllocatedMessage as "ClientViewportAllocatedMessage" {
51    "Width" => width: f64,
52    "Height" => height: f64,
53    "DpiX" => dpi_x: f64,
54    "DpiY" => dpi_y: f64,
55});
56
57#[derive(Clone, Debug, Default, PartialEq)]
58pub struct RequestViewportResizeMessage {
59    pub width: f64,
60    pub height: f64,
61}
62
63ferro_remote_message_guid!(RequestViewportResizeMessage, "9B47B3D8-61DF-4C38-ACD4-8C1BB72554AC");
64bson_class!(RequestViewportResizeMessage as "RequestViewportResizeMessage" {
65    "Width" => width: f64,
66    "Height" => height: f64,
67});
68
69#[derive(Clone, Debug, Default, PartialEq)]
70pub struct ClientSupportedPixelFormatsMessage {
71    pub formats: Option<Vec<PixelFormat>>,
72}
73
74ferro_remote_message_guid!(ClientSupportedPixelFormatsMessage, "63481025-7016-43FE-BADC-F2FD0F88609E");
75bson_class!(ClientSupportedPixelFormatsMessage as "ClientSupportedPixelFormatsMessage" {
76    "Formats" => formats: Option<Vec<PixelFormat>>,
77});
78
79#[derive(Clone, Debug, Default, PartialEq)]
80pub struct ClientRenderInfoMessage {
81    pub dpi_x: f64,
82    pub dpi_y: f64,
83}
84
85ferro_remote_message_guid!(ClientRenderInfoMessage, "7A3c25d3-3652-438D-8EF1-86E942CC96C0");
86bson_class!(ClientRenderInfoMessage as "ClientRenderInfoMessage" {
87    "DpiX" => dpi_x: f64,
88    "DpiY" => dpi_y: f64,
89});
90
91#[derive(Clone, Debug, Default, PartialEq)]
92pub struct FrameReceivedMessage {
93    pub sequence_id: i64,
94}
95
96ferro_remote_message_guid!(FrameReceivedMessage, "68014F8A-289D-4851-8D34-5367EDA7F827");
97bson_class!(FrameReceivedMessage as "FrameReceivedMessage" {
98    "SequenceId" => sequence_id: i64,
99});
100
101#[derive(Clone, Debug, Default, PartialEq)]
102pub struct FrameMessage {
103    pub sequence_id: i64,
104    pub format: PixelFormat,
105    pub data: Option<Vec<u8>>,
106    pub width: i32,
107    pub height: i32,
108    pub stride: i32,
109    pub dpi_x: f64,
110    pub dpi_y: f64,
111}
112
113ferro_remote_message_guid!(FrameMessage, "F58313EE-FE69-4536-819D-F52EDF201A0E");
114bson_class!(FrameMessage as "FrameMessage" {
115    "SequenceId" => sequence_id: i64,
116    "Format" => format: PixelFormat,
117    "Data" => data: Option<Vec<u8>>,
118    "Width" => width: i32,
119    "Height" => height: i32,
120    "Stride" => stride: i32,
121    "DpiX" => dpi_x: f64,
122    "DpiY" => dpi_y: f64,
123});