From 8c8a643ccec7c37cce42f2daae7e63caa444bf85 Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Sat, 19 Oct 2024 10:57:42 +0800 Subject: [PATCH] fix: workaround physical display rotation (#9696) Signed-off-by: fufesou --- libs/scrap/src/common/mod.rs | 8 ++++---- libs/scrap/src/common/vram.rs | 7 ++++++- libs/scrap/src/dxgi/mod.rs | 12 +++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/libs/scrap/src/common/mod.rs b/libs/scrap/src/common/mod.rs index d6060e131..635f0ec26 100644 --- a/libs/scrap/src/common/mod.rs +++ b/libs/scrap/src/common/mod.rs @@ -156,7 +156,7 @@ pub trait TraitPixelBuffer { #[cfg(not(any(target_os = "ios")))] pub enum Frame<'a> { PixelBuffer(PixelBuffer<'a>), - Texture(*mut c_void), + Texture((*mut c_void, usize)), } #[cfg(not(any(target_os = "ios")))] @@ -164,7 +164,7 @@ impl Frame<'_> { pub fn valid<'a>(&'a self) -> bool { match self { Frame::PixelBuffer(pixelbuffer) => !pixelbuffer.data().is_empty(), - Frame::Texture(texture) => !texture.is_null(), + Frame::Texture((texture, _)) => !texture.is_null(), } } @@ -186,7 +186,7 @@ impl Frame<'_> { pub enum EncodeInput<'a> { YUV(&'a [u8]), - Texture(*mut c_void), + Texture((*mut c_void, usize)), } impl<'a> EncodeInput<'a> { @@ -197,7 +197,7 @@ impl<'a> EncodeInput<'a> { } } - pub fn texture(&self) -> ResultType<*mut c_void> { + pub fn texture(&self) -> ResultType<(*mut c_void, usize)> { match self { Self::Texture(f) => Ok(*f), _ => bail!("not texture frame"), diff --git a/libs/scrap/src/common/vram.rs b/libs/scrap/src/common/vram.rs index a2b4d348c..aae961df6 100644 --- a/libs/scrap/src/common/vram.rs +++ b/libs/scrap/src/common/vram.rs @@ -101,7 +101,12 @@ impl EncoderApi for VRamEncoder { frame: EncodeInput, ms: i64, ) -> ResultType { - let texture = frame.texture()?; + let (texture, rotation) = frame.texture()?; + if rotation != 0 { + // to-do: support rotation + // Both the encoder and display(w,h) information need to be changed. + bail!("rotation not supported"); + } let mut vf = VideoFrame::new(); let mut frames = Vec::new(); for frame in self diff --git a/libs/scrap/src/dxgi/mod.rs b/libs/scrap/src/dxgi/mod.rs index abd1f5026..33a60e7d9 100644 --- a/libs/scrap/src/dxgi/mod.rs +++ b/libs/scrap/src/dxgi/mod.rs @@ -253,7 +253,17 @@ impl Capturer { pub fn frame<'a>(&'a mut self, timeout: UINT) -> io::Result> { if self.output_texture { - Ok(Frame::Texture(self.get_texture(timeout)?)) + let rotation = match self.display.rotation() { + DXGI_MODE_ROTATION_IDENTITY | DXGI_MODE_ROTATION_UNSPECIFIED => 0, + DXGI_MODE_ROTATION_ROTATE90 => 90, + DXGI_MODE_ROTATION_ROTATE180 => 180, + DXGI_MODE_ROTATION_ROTATE270 => 270, + _ => { + // Unsupported rotation, try anyway + 0 + } + }; + Ok(Frame::Texture((self.get_texture(timeout)?, rotation))) } else { let width = self.width; let height = self.height;