refactor DST_STRIDE_RGBA

This commit is contained in:
rustdesk
2023-03-03 14:02:49 +08:00
parent 4351272297
commit b8941c15c0
8 changed files with 48 additions and 23 deletions

View File

@@ -44,8 +44,7 @@ pub use helper::*;
use scrap::{
codec::{Decoder, DecoderCfg},
record::{Recorder, RecorderContext},
VpxDecoderConfig, VpxVideoCodecId,
ImageFormat,
ImageFormat, VpxDecoderConfig, VpxVideoCodecId,
};
use crate::{
@@ -944,12 +943,11 @@ 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,
(ImageFormat::ARGB, crate::DST_STRIDE_RGBA),
&mut self.rgb,
);
if self.record {
self.recorder
.lock()
@@ -2038,7 +2036,7 @@ pub trait Interface: Send + Clone + 'static + Sized {
fn is_force_relay(&self) -> bool {
self.get_login_config_handler().read().unwrap().force_relay
}
fn swap_modifier_mouse(&self, _msg : &mut hbb_common::protos::message::MouseEvent) {}
fn swap_modifier_mouse(&self, _msg: &mut hbb_common::protos::message::MouseEvent) {}
}
/// Data used by the client interface.

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

@@ -153,8 +153,13 @@ 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);
pub type FlutterRgbaRendererPluginOnRgba = unsafe extern "C" fn(
texture_rgba: *mut c_void,
buffer: *const u8,
width: c_int,
height: c_int,
dst_rgba_stride: c_int,
);
// Video Texture Renderer in Flutter
#[cfg(feature = "flutter_texture_render")]
@@ -206,7 +211,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::DST_STRIDE_RGBA - 1;
let row_bytes = (width as usize * 4 + sa1) & !sa1;
row_bytes * height as usize
} else {
0
};
@@ -223,6 +230,7 @@ impl VideoRenderer {
rgba.as_ptr() as _,
self.width as _,
self.height as _,
crate::DST_STRIDE_RGBA as _,
)
};
}