diff --git a/frontend/src/pages/page_vnc.rs b/frontend/src/pages/page_vnc.rs index cb3e877..f7fcf1d 100644 --- a/frontend/src/pages/page_vnc.rs +++ b/frontend/src/pages/page_vnc.rs @@ -256,17 +256,40 @@ impl PageVnc { } }; - let data = ImageData::new_with_u8_clamped_array_and_sh( - Clamped(&cr.data), - cr.width as u32, - cr.height as u32, - ) - .unwrap(); - // ConsoleService::log(&format!( - // "renderring at ({}, {}), width {}, height {}", - // cr.x, cr.y, cr.width, cr.height - // )); - let _ = ctx.put_image_data(&data, cr.x as f64, cr.y as f64); + match cr.type_ { + 1 => { + //copy + let sx = (cr.data[0] as u16) << 8 | cr.data[1] as u16; + let sy = (cr.data[2] as u16) << 8 | cr.data[3] as u16; + + let _ = ctx. + draw_image_with_html_canvas_element_and_sw_and_sh_and_dx_and_dy_and_dw_and_dh( + &canvas, + sx as f64, + sy as f64, + cr.width as f64, + cr.height as f64, + cr.x as f64, + cr.y as f64, + cr.width as f64, + cr.height as f64 + ); + } + _ => { + let data = ImageData::new_with_u8_clamped_array_and_sh( + Clamped(&cr.data), + cr.width as u32, + cr.height as u32, + ) + .unwrap(); + // ConsoleService::log(&format!( + // "renderring at ({}, {}), width {}, height {}", + // cr.x, cr.y, cr.width, cr.height + // )); + let _ = ctx.put_image_data(&data, cr.x as f64, cr.y as f64); + } + } + should_render = true; } ProtocalHandlerOutput::SetCanvas(width, height) => { diff --git a/frontend/src/protocal/common.rs b/frontend/src/protocal/common.rs index 18f7f46..e66dceb 100644 --- a/frontend/src/protocal/common.rs +++ b/frontend/src/protocal/common.rs @@ -1,6 +1,7 @@ use std::{rc::Rc, sync::Mutex}; pub struct CanvasData { + pub type_: u32, pub x: u16, pub y: u16, pub width: u16, diff --git a/frontend/src/protocal/vnc/vnc.rs b/frontend/src/protocal/vnc/vnc.rs index 51737e4..f587bc2 100644 --- a/frontend/src/protocal/vnc/vnc.rs +++ b/frontend/src/protocal/vnc/vnc.rs @@ -23,6 +23,7 @@ pub enum SecurityType { // VeNCrypt = 19, } +#[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(i32)] pub enum VncEncoding { @@ -79,7 +80,7 @@ impl ProtocalImpl for VncHandler { state: VncState::Init, supported_encodings: vec![ VncEncoding::Raw, - // VncEncoding::CopyRect, + VncEncoding::CopyRect, // VncEncoding::RRE, // VncEncoding::Hextile, // VncEncoding::TRLE, @@ -554,10 +555,15 @@ impl VncHandler { } } } + 1 => { + // copy rectangle + self.read_exact_vec(&mut image_data, 4); + } _ => unimplemented!(), } self.outs .push(ProtocalHandlerOutput::RenderCanvas(CanvasData { + type_: rect.encoding_type, x: rect.x, y: rect.y, width: rect.width, @@ -649,19 +655,31 @@ impl VncHandler { width, height, encoding_type: 0, - encoding_data: Vec::new(), // we donnot need to store the data }); } - fn handle_copy_rect_encoding(&mut self, _x: u16, _y: u16, _width: u16, _height: u16) { - unimplemented!() + fn handle_copy_rect_encoding(&mut self, x: u16, y: u16, width: u16, height: u16) { + ConsoleService::log(&format!("VNC: CopyRect {} {} {} {}", x, y, width, height)); + self.require = 4; + self.padding_rect = Some(VncRect { + x, + y, + width, + height, + encoding_type: 1, + }); } fn handle_rre_encoding(&mut self, _x: u16, _y: u16, _width: u16, _height: u16) { + // Note: RRE encoding is obsolescent. In general, ZRLE and TRLE + // encodings are more compact. + unimplemented!() } fn handle_hextile_encoding(&mut self, _x: u16, _y: u16, _width: u16, _height: u16) { + // Note: Hextile encoding is obsolescent. In general, ZRLE and TRLE + // encodings are more compact. unimplemented!() } @@ -800,5 +818,4 @@ struct VncRect { width: u16, height: u16, encoding_type: u32, - encoding_data: Vec, }