@@ -12,7 +12,7 @@ use ironrdp_pdu::surface_commands::{ExtendedBitmapDataPdu, SurfaceBitsPdu, Surfa
12
12
use self :: bitmap:: BitmapEncoder ;
13
13
use self :: rfx:: RfxEncoder ;
14
14
use super :: BitmapUpdate ;
15
- use crate :: { ColorPointer , Framebuffer , RGBAPointer } ;
15
+ use crate :: { time_warn , ColorPointer , DisplayUpdate , Framebuffer , RGBAPointer } ;
16
16
17
17
mod bitmap;
18
18
mod fast_path;
@@ -59,12 +59,19 @@ impl UpdateEncoder {
59
59
}
60
60
}
61
61
62
+ pub ( crate ) fn update ( & mut self , update : DisplayUpdate ) -> EncoderIter < ' _ > {
63
+ EncoderIter {
64
+ encoder : self ,
65
+ update : Some ( update) ,
66
+ }
67
+ }
68
+
62
69
pub ( crate ) fn set_desktop_size ( & mut self , size : DesktopSize ) {
63
70
self . desktop_size = size;
64
71
}
65
72
66
73
#[ allow( clippy:: unused_self) ]
67
- pub ( crate ) fn rgba_pointer ( & mut self , ptr : RGBAPointer ) -> Result < UpdateFragmenter > {
74
+ fn rgba_pointer ( & self , ptr : RGBAPointer ) -> Result < UpdateFragmenter > {
68
75
let xor_mask = ptr. data ;
69
76
70
77
let hot_spot = Point16 {
@@ -87,7 +94,7 @@ impl UpdateEncoder {
87
94
}
88
95
89
96
#[ allow( clippy:: unused_self) ]
90
- pub ( crate ) fn color_pointer ( & mut self , ptr : ColorPointer ) -> Result < UpdateFragmenter > {
97
+ fn color_pointer ( & self , ptr : ColorPointer ) -> Result < UpdateFragmenter > {
91
98
let hot_spot = Point16 {
92
99
x : ptr. hot_x ,
93
100
y : ptr. hot_y ,
@@ -104,22 +111,28 @@ impl UpdateEncoder {
104
111
}
105
112
106
113
#[ allow( clippy:: unused_self) ]
107
- pub ( crate ) fn default_pointer ( & mut self ) -> Result < UpdateFragmenter > {
114
+ fn default_pointer ( & self ) -> Result < UpdateFragmenter > {
108
115
Ok ( UpdateFragmenter :: new ( UpdateCode :: DefaultPointer , vec ! [ ] ) )
109
116
}
110
117
111
118
#[ allow( clippy:: unused_self) ]
112
- pub ( crate ) fn hide_pointer ( & mut self ) -> Result < UpdateFragmenter > {
119
+ fn hide_pointer ( & self ) -> Result < UpdateFragmenter > {
113
120
Ok ( UpdateFragmenter :: new ( UpdateCode :: HiddenPointer , vec ! [ ] ) )
114
121
}
115
122
116
123
#[ allow( clippy:: unused_self) ]
117
- pub ( crate ) fn pointer_position ( & mut self , pos : PointerPositionAttribute ) -> Result < UpdateFragmenter > {
124
+ fn pointer_position ( & self , pos : PointerPositionAttribute ) -> Result < UpdateFragmenter > {
118
125
Ok ( UpdateFragmenter :: new ( UpdateCode :: PositionPointer , encode_vec ( & pos) ?) )
119
126
}
120
127
121
- pub ( crate ) fn bitmap ( & mut self , bitmap : BitmapUpdate ) -> Result < UpdateFragmenter > {
122
- let res = self . bitmap_updater . handle ( & bitmap) ;
128
+ async fn bitmap ( & mut self , bitmap : BitmapUpdate ) -> Result < UpdateFragmenter > {
129
+ // Clone to satisfy spawn_blocking 'static requirement
130
+ // this should be cheap, even if using bitmap, since vec![] will be empty
131
+ let mut updater = self . bitmap_updater . clone ( ) ;
132
+ let ( res, bitmap) =
133
+ tokio:: task:: spawn_blocking ( move || time_warn ! ( "Encoding bitmap" , 10 , ( updater. handle( & bitmap) , bitmap) ) )
134
+ . await
135
+ . unwrap ( ) ;
123
136
if bitmap. x == 0
124
137
&& bitmap. y == 0
125
138
&& bitmap. width . get ( ) == self . desktop_size . width
@@ -134,7 +147,31 @@ impl UpdateEncoder {
134
147
}
135
148
}
136
149
137
- #[ derive( Debug ) ]
150
+ pub ( crate ) struct EncoderIter < ' a > {
151
+ encoder : & ' a mut UpdateEncoder ,
152
+ update : Option < DisplayUpdate > ,
153
+ }
154
+
155
+ impl EncoderIter < ' _ > {
156
+ pub ( crate ) async fn next ( & mut self ) -> Option < Result < UpdateFragmenter > > {
157
+ let update = self . update . take ( ) ?;
158
+ let encoder = & mut self . encoder ;
159
+
160
+ let res = match update {
161
+ DisplayUpdate :: Bitmap ( bitmap) => encoder. bitmap ( bitmap) . await ,
162
+ DisplayUpdate :: PointerPosition ( pos) => encoder. pointer_position ( pos) ,
163
+ DisplayUpdate :: RGBAPointer ( ptr) => encoder. rgba_pointer ( ptr) ,
164
+ DisplayUpdate :: ColorPointer ( ptr) => encoder. color_pointer ( ptr) ,
165
+ DisplayUpdate :: HidePointer => encoder. hide_pointer ( ) ,
166
+ DisplayUpdate :: DefaultPointer => encoder. default_pointer ( ) ,
167
+ DisplayUpdate :: Resize ( _) => return None ,
168
+ } ;
169
+
170
+ Some ( res)
171
+ }
172
+ }
173
+
174
+ #[ derive( Debug , Clone ) ]
138
175
enum BitmapUpdater {
139
176
None ( NoneHandler ) ,
140
177
Bitmap ( BitmapHandler ) ,
@@ -155,7 +192,7 @@ trait BitmapUpdateHandler {
155
192
fn handle ( & mut self , bitmap : & BitmapUpdate ) -> Result < UpdateFragmenter > ;
156
193
}
157
194
158
- #[ derive( Debug ) ]
195
+ #[ derive( Clone , Debug ) ]
159
196
struct NoneHandler ;
160
197
161
198
impl BitmapUpdateHandler for NoneHandler {
@@ -169,6 +206,7 @@ impl BitmapUpdateHandler for NoneHandler {
169
206
}
170
207
}
171
208
209
+ #[ derive( Clone ) ]
172
210
struct BitmapHandler {
173
211
bitmap : BitmapEncoder ,
174
212
}
@@ -209,7 +247,7 @@ impl BitmapUpdateHandler for BitmapHandler {
209
247
}
210
248
}
211
249
212
- #[ derive( Debug ) ]
250
+ #[ derive( Debug , Clone ) ]
213
251
struct RemoteFxHandler {
214
252
remotefx : RfxEncoder ,
215
253
codec_id : u8 ,
0 commit comments