Merge pull request #3477 from fufesou/fix/macos_texture_stride_align

Fix/macos texture stride align
This commit is contained in:
RustDesk
2023-03-03 11:54:20 +08:00
committed by GitHub
12 changed files with 65 additions and 52 deletions

View File

@@ -49,7 +49,7 @@ use scrap::{
};
use crate::{
common::{self, is_keyboard_mode_supported},
common::{self, is_keyboard_mode_supported, DST_STRIDE_RGBA},
server::video_service::{SCRAP_X11_REF_URL, SCRAP_X11_REQUIRED},
};
@@ -944,12 +944,7 @@ impl VideoHandler {
}
match &vf.union {
Some(frame) => {
// windows && flutter_texture_render, fmt is ImageFormat::ABGR
#[cfg(all(target_os = "windows", feature = "flutter_texture_render"))]
let fmt = ImageFormat::ABGR;
#[cfg(not(all(target_os = "windows", feature = "flutter_texture_render")))]
let fmt = ImageFormat::ARGB;
let res = self.decoder.handle_video_frame(frame, fmt, &mut self.rgb);
let res = self.decoder.handle_video_frame(frame, DST_STRIDE_RGBA, ImageFormat::ARGB, &mut self.rgb);
if self.record {
self.recorder
.lock()

View File

@@ -39,6 +39,13 @@ pub const CLIPBOARD_INTERVAL: u64 = 333;
pub const SYNC_PEER_INFO_DISPLAYS: i32 = 1;
#[cfg(all(target_os = "macos", feature = "flutter_texture_render"))]
// https://developer.apple.com/forums/thread/712709
// Memory alignment should be multiple of 64.
pub const DST_STRIDE_RGBA: usize = 64;
#[cfg(not(all(target_os = "macos", feature = "flutter_texture_render")))]
pub const DST_STRIDE_RGBA: usize = 1;
// the executable name of the portable version
pub const PORTABLE_APPNAME_RUNTIME_ENV_KEY: &str = "RUSTDESK_APPNAME";

View File

@@ -154,7 +154,7 @@ pub struct FlutterHandler {
#[cfg(feature = "flutter_texture_render")]
pub type FlutterRgbaRendererPluginOnRgba =
unsafe extern "C" fn(texture_rgba: *mut c_void, buffer: *const u8, width: c_int, height: c_int);
unsafe extern "C" fn(texture_rgba: *mut c_void, buffer: *const u8, len: c_int, width: c_int, height: c_int, stride: c_int);
// Video Texture Renderer in Flutter
#[cfg(feature = "flutter_texture_render")]
@@ -206,7 +206,9 @@ impl VideoRenderer {
self.width = width;
self.height = height;
self.data_len = if width > 0 && height > 0 {
(width * height * 4) as usize
let sa1 = crate::common::DST_STRIDE_RGBA - 1;
let row_bytes = (width as usize * 4 + sa1) & !sa1;
row_bytes * height as usize
} else {
0
};
@@ -221,8 +223,10 @@ impl VideoRenderer {
func(
self.ptr as _,
rgba.as_ptr() as _,
rgba.len() as _,
self.width as _,
self.height as _,
crate::common::DST_STRIDE_RGBA as _,
)
};
}