mirror of
https://github.com/netbirdio/IronRDP.git
synced 2026-05-22 18:43:12 -07:00
feat(session)!: make DecodedImage Send
This will allow to share it between different threads. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
committed by
Benoît Cortier
parent
7507a152f1
commit
45f66117ba
@@ -1,4 +1,4 @@
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use ironrdp_connector::connection_activation::ConnectionActivationSequence;
|
||||
use ironrdp_connector::ConnectionResult;
|
||||
@@ -254,7 +254,7 @@ pub enum ActiveStageOutput {
|
||||
PointerDefault,
|
||||
PointerHidden,
|
||||
PointerPosition { x: u16, y: u16 },
|
||||
PointerBitmap(Rc<DecodedPointer>),
|
||||
PointerBitmap(Arc<DecodedPointer>),
|
||||
Terminate(GracefulDisconnectReason),
|
||||
DeactivateAll(Box<ConnectionActivationSequence>),
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use ironrdp_core::{decode_cursor, DecodeErrorKind, ReadCursor, WriteBuf};
|
||||
use ironrdp_graphics::image_processing::PixelFormat;
|
||||
@@ -24,7 +24,7 @@ pub enum UpdateKind {
|
||||
PointerDefault,
|
||||
PointerHidden,
|
||||
PointerPosition { x: u16, y: u16 },
|
||||
PointerBitmap(Rc<DecodedPointer>),
|
||||
PointerBitmap(Arc<DecodedPointer>),
|
||||
}
|
||||
|
||||
pub struct Processor {
|
||||
@@ -216,17 +216,17 @@ impl Processor {
|
||||
PointerUpdateData::Color(pointer) => {
|
||||
let cache_index = pointer.cache_index;
|
||||
|
||||
let decoded_pointer = Rc::new(
|
||||
let decoded_pointer = Arc::new(
|
||||
DecodedPointer::decode_color_pointer_attribute(&pointer, bitmap_target)
|
||||
.expect("Failed to decode color pointer attribute"),
|
||||
);
|
||||
|
||||
let _ = self
|
||||
.pointer_cache
|
||||
.insert(usize::from(cache_index), Rc::clone(&decoded_pointer));
|
||||
.insert(usize::from(cache_index), Arc::clone(&decoded_pointer));
|
||||
|
||||
if !self.pointer_software_rendering {
|
||||
processor_updates.push(UpdateKind::PointerBitmap(Rc::clone(&decoded_pointer)));
|
||||
processor_updates.push(UpdateKind::PointerBitmap(Arc::clone(&decoded_pointer)));
|
||||
} else if let Some(rect) = image.update_pointer(decoded_pointer)? {
|
||||
processor_updates.push(UpdateKind::Region(rect));
|
||||
}
|
||||
@@ -240,7 +240,7 @@ impl Processor {
|
||||
self.use_system_pointer = false;
|
||||
// Send graphics update
|
||||
if !self.pointer_software_rendering {
|
||||
processor_updates.push(UpdateKind::PointerBitmap(Rc::clone(&cached_pointer)));
|
||||
processor_updates.push(UpdateKind::PointerBitmap(Arc::clone(&cached_pointer)));
|
||||
} else if let Some(rect) = image.update_pointer(cached_pointer)? {
|
||||
processor_updates.push(UpdateKind::Region(rect));
|
||||
} else {
|
||||
@@ -256,17 +256,17 @@ impl Processor {
|
||||
PointerUpdateData::New(pointer) => {
|
||||
let cache_index = pointer.color_pointer.cache_index;
|
||||
|
||||
let decoded_pointer = Rc::new(
|
||||
let decoded_pointer = Arc::new(
|
||||
DecodedPointer::decode_pointer_attribute(&pointer, bitmap_target)
|
||||
.expect("Failed to decode pointer attribute"),
|
||||
);
|
||||
|
||||
let _ = self
|
||||
.pointer_cache
|
||||
.insert(usize::from(cache_index), Rc::clone(&decoded_pointer));
|
||||
.insert(usize::from(cache_index), Arc::clone(&decoded_pointer));
|
||||
|
||||
if !self.pointer_software_rendering {
|
||||
processor_updates.push(UpdateKind::PointerBitmap(Rc::clone(&decoded_pointer)));
|
||||
processor_updates.push(UpdateKind::PointerBitmap(Arc::clone(&decoded_pointer)));
|
||||
} else if let Some(rect) = image.update_pointer(decoded_pointer)? {
|
||||
processor_updates.push(UpdateKind::Region(rect));
|
||||
}
|
||||
@@ -274,17 +274,17 @@ impl Processor {
|
||||
PointerUpdateData::Large(pointer) => {
|
||||
let cache_index = pointer.cache_index;
|
||||
|
||||
let decoded_pointer: Rc<DecodedPointer> = Rc::new(
|
||||
let decoded_pointer: Arc<DecodedPointer> = Arc::new(
|
||||
DecodedPointer::decode_large_pointer_attribute(&pointer, bitmap_target)
|
||||
.expect("Failed to decode large pointer attribute"),
|
||||
);
|
||||
|
||||
let _ = self
|
||||
.pointer_cache
|
||||
.insert(usize::from(cache_index), Rc::clone(&decoded_pointer));
|
||||
.insert(usize::from(cache_index), Arc::clone(&decoded_pointer));
|
||||
|
||||
if !self.pointer_software_rendering {
|
||||
processor_updates.push(UpdateKind::PointerBitmap(Rc::clone(&decoded_pointer)));
|
||||
processor_updates.push(UpdateKind::PointerBitmap(Arc::clone(&decoded_pointer)));
|
||||
} else if let Some(rect) = image.update_pointer(decoded_pointer)? {
|
||||
processor_updates.push(UpdateKind::Region(rect));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use ironrdp_core::assert_impl;
|
||||
use ironrdp_graphics::color_conversion::rdp_16bit_to_rgb;
|
||||
use ironrdp_graphics::image_processing::{ImageRegion, ImageRegionMut, PixelFormat};
|
||||
use ironrdp_graphics::pointer::DecodedPointer;
|
||||
@@ -24,7 +25,7 @@ pub struct DecodedImage {
|
||||
pointer_x: u16,
|
||||
pointer_y: u16,
|
||||
|
||||
pointer: Option<Rc<DecodedPointer>>,
|
||||
pointer: Option<Arc<DecodedPointer>>,
|
||||
/// Image data, overridden by pointer. Used to restore image after pointer was hidden or moved
|
||||
pointer_backbuffer: Vec<u8>,
|
||||
/// Whether to show pointer or not
|
||||
@@ -36,6 +37,8 @@ pub struct DecodedImage {
|
||||
height: u16,
|
||||
}
|
||||
|
||||
assert_impl!(DecodedImage: Send);
|
||||
|
||||
impl core::fmt::Debug for DecodedImage {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
f.debug_struct("DecodedImage")
|
||||
@@ -384,7 +387,7 @@ impl DecodedImage {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn update_pointer(&mut self, pointer: Rc<DecodedPointer>) -> SessionResult<Option<InclusiveRectangle>> {
|
||||
pub(crate) fn update_pointer(&mut self, pointer: Arc<DecodedPointer>) -> SessionResult<Option<InclusiveRectangle>> {
|
||||
self.show_pointer = true;
|
||||
|
||||
// Remove old pointer from frame buffer
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use ironrdp_graphics::pointer::DecodedPointer;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct PointerCache {
|
||||
// TODO(@pacancoder) maybe use Vec<Optional<...>> instead?
|
||||
cache: HashMap<usize, Rc<DecodedPointer>>,
|
||||
cache: HashMap<usize, Arc<DecodedPointer>>,
|
||||
}
|
||||
|
||||
impl PointerCache {
|
||||
pub fn insert(&mut self, id: usize, pointer: Rc<DecodedPointer>) -> Option<Rc<DecodedPointer>> {
|
||||
pub fn insert(&mut self, id: usize, pointer: Arc<DecodedPointer>) -> Option<Arc<DecodedPointer>> {
|
||||
self.cache.insert(id, pointer)
|
||||
}
|
||||
|
||||
pub fn get(&self, id: usize) -> Option<Rc<DecodedPointer>> {
|
||||
pub fn get(&self, id: usize) -> Option<Arc<DecodedPointer>> {
|
||||
self.cache.get(&id).cloned()
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
#[diplomat::bridge]
|
||||
pub mod ffi {
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::utils::ffi::BytesSlice;
|
||||
|
||||
#[diplomat::opaque]
|
||||
pub struct DecodedPointer(pub Rc<ironrdp::graphics::pointer::DecodedPointer>);
|
||||
pub struct DecodedPointer(pub Arc<ironrdp::graphics::pointer::DecodedPointer>);
|
||||
|
||||
impl DecodedPointer {
|
||||
pub fn get_width(&self) -> u16 {
|
||||
|
||||
@@ -225,7 +225,7 @@ pub mod ffi {
|
||||
pub fn get_pointer_bitmap(&self) -> Result<Box<DecodedPointer>, Box<IronRdpError>> {
|
||||
match &self.0 {
|
||||
ironrdp::session::ActiveStageOutput::PointerBitmap(decoded_pointer) => {
|
||||
Ok(DecodedPointer(std::rc::Rc::clone(decoded_pointer)))
|
||||
Ok(DecodedPointer(std::sync::Arc::clone(decoded_pointer)))
|
||||
}
|
||||
_ => Err(IncorrectEnumTypeError::on_variant("PointerBitmap")
|
||||
.of_enum("ActiveStageOutput")
|
||||
|
||||
Reference in New Issue
Block a user