Skip to content

Commit

Permalink
Removes unused dependencies, cleans up code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaiah Becker-Mayer committed Apr 30, 2024
1 parent f2a51ed commit 8501e00
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 53 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions lib/srv/desktop/rdp/rdpclient/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ tokio = { version = "1.37", features = ["full"] }
tokio-boring = { git = "https://github.com/gravitational/boring", rev="605253d99d5e363e178bcf97e1d4622e33844cd5", optional = true }
utf16string = "0.2.0"
uuid = { version = "1.8.0", features = ["v4"] }
tracing-subscriber = "0.3.17"
tracing = { version = "0.1", features = ["log-always" ] }

[build-dependencies]
cbindgen = "0.26.0"
Expand Down
59 changes: 12 additions & 47 deletions web/packages/teleport/src/ironrdp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#![allow(clippy::new_without_default)]

use ironrdp_graphics::image_processing::PixelFormat;
use ironrdp_pdu::cursor::ReadCursor;
use ironrdp_pdu::decode_cursor;
use ironrdp_pdu::fast_path::UpdateCode::{Bitmap, SurfaceCommands};
use ironrdp_pdu::fast_path::{FastPathHeader, FastPathUpdatePdu};
use ironrdp_pdu::geometry::{InclusiveRectangle, Rectangle};
use ironrdp_pdu::write_buf::WriteBuf;
use ironrdp_session::fast_path::UpdateKind;
Expand All @@ -32,11 +36,6 @@ use log::{debug, warn};
use wasm_bindgen::{prelude::*, Clamped};
use web_sys::ImageData;

use ironrdp_pdu::cursor::ReadCursor;
use ironrdp_pdu::decode_cursor;
use ironrdp_pdu::fast_path::UpdateCode::{Bitmap, SurfaceCommands};
use ironrdp_pdu::fast_path::{FastPathHeader, FastPathUpdatePdu};

#[wasm_bindgen]
pub fn init_wasm_log(log_level: &str) {
use tracing::Level;
Expand Down Expand Up @@ -67,7 +66,6 @@ pub fn init_wasm_log(log_level: &str) {
.init();

debug!("WASM log is ready");
// TODO(isaiah): is it possible to set up logging for IronRDP trace logs like so: https://github.com/Devolutions/IronRDP/blob/c71ada5783fee13eea512d5d3d8ac79606716dc5/crates/ironrdp-client/src/main.rs#L47-L78
}
}

Expand All @@ -92,45 +90,7 @@ impl BitmapFrame {

#[wasm_bindgen(getter)]
pub fn image_data(&self) -> ImageData {
self.image_data.clone() // todo(isaiah): bad, see below for a potential approach:

// You can pass the `&[u8]` from Rust to JavaScript without copying it by using the `wasm_bindgen::memory`
// function to directly access the WebAssembly linear memory. Here's how you can achieve this:

// 1. Get a pointer to the data and its length.
// 2. Create a `Uint8Array` that directly refers to the WebAssembly linear memory.
// 3. Use the `subarray` method to create a new view that refers to the desired data without copying it.

// ```rust
// #[wasm_bindgen(getter)]
// pub fn image_data(&self) -> JsValue {
// let data = self.image_data.data();
// let data_ptr = data.as_ptr() as u32;
// let data_len = data.len() as u32;

// let memory_buffer = wasm_bindgen::memory()
// .dyn_into::<WebAssembly::Memory>()
// .unwrap()
// .buffer();

// let data_array = js_sys::Uint8Array::new(&memory_buffer).subarray(data_ptr, data_ptr + data_len);

// let obj = js_sys::Object::new();
// js_sys::Reflect::set(&obj, &"data".into(), &data_array).unwrap();
// js_sys::Reflect::set(&obj, &"width".into(), &JsValue::from(self.image_data.width())).unwrap();
// js_sys::Reflect::set(&obj, &"height".into(), &JsValue::from(self.image_data.height())).unwrap();

// obj.into()
// }
// ```

// This implementation should pass the data from Rust to JavaScript without copying it.
// Note that the returned `Uint8Array` is a view over the WebAssembly linear memory, so
// you need to make sure that the data is not modified on the Rust side while it's being
// used in JavaScript. Also, keep in mind that the lifetime of the `Uint8Array` is tied
// to the lifetime of the `ImageData` object in Rust. If the `ImageData` object is dropped,
// the underlying data may be deallocated, and the `Uint8Array` in JavaScript may become
// invalid.
self.image_data.clone() // TODO(isaiah): can we remove this clone?
}
}

Expand Down Expand Up @@ -343,6 +303,7 @@ impl FastPathProcessor {
}
}

/// Taken from https://github.com/Devolutions/IronRDP/blob/35839459aa58c5c42cd686b39b63a7944285c0de/crates/ironrdp-web/src/image.rs#L6
pub fn extract_partial_image(
image: &DecodedImage,
region: InclusiveRectangle,
Expand All @@ -355,7 +316,9 @@ pub fn extract_partial_image(
}
}

// Faster for low-height and smaller images
/// Faster for low-height and smaller images
///
/// https://github.com/Devolutions/IronRDP/blob/35839459aa58c5c42cd686b39b63a7944285c0de/crates/ironrdp-web/src/image.rs#L16
fn extract_smallest_rectangle(
image: &DecodedImage,
region: InclusiveRectangle,
Expand Down Expand Up @@ -391,7 +354,9 @@ fn extract_smallest_rectangle(
(region, dst)
}

// Faster for high-height and bigger images
/// Faster for high-height and bigger images
///
/// https://github.com/Devolutions/IronRDP/blob/35839459aa58c5c42cd686b39b63a7944285c0de/crates/ironrdp-web/src/image.rs#L49
fn extract_whole_rows(
image: &DecodedImage,
region: InclusiveRectangle,
Expand Down

0 comments on commit 8501e00

Please sign in to comment.