pub struct DxgiDuplicationApi { /* private fields */ }展开描述
一个最小化、易用的 DXGI 桌面复制 API 包装器,用于捕获显示器画面。
该包装器力求贴近原生 API,同时提供简洁的 Rust 接口。
它与 crate::monitor::Monitor 集成以选择目标输出。
实现§
Source§impl DxgiDuplicationApi
impl DxgiDuplicationApi
Sourcepub fn new(monitor: Monitor) -> Result<Self, Error>
pub fn new(monitor: Monitor) -> Result<Self, Error>
为指定的显示器构造一个新的复制会话。
内部使用本 crate 的 d3d11 模块创建 Direct3D 11 设备和即时上下文。
Sourcepub fn new_options(
monitor: Monitor,
supported_formats: &[DxgiDuplicationFormat],
) -> Result<Self, Error>
pub fn new_options( monitor: Monitor, supported_formats: &[DxgiDuplicationFormat], ) -> Result<Self, Error>
为指定的显示器构造一个新的复制会话,使用自定义的 DXGI 支持格式列表。
该方法允许直接接收正在运行的全屏应用程序所使用的原始后缓冲格式。
会额外插入 Bgra8,因为它被广泛支持,可作为可靠的回退选项。
Sourcepub fn recreate(self) -> Result<Self, Error>
pub fn recreate(self) -> Result<Self, Error>
重新创建复制接口,主要在 DxgiDuplicationApi::acquire_next_frame 返回 Error::AccessLost
错误之后调用。
Sourcepub fn recreate_options(
self,
supported_formats: &[DxgiDuplicationFormat],
) -> Result<Self, Error>
pub fn recreate_options( self, supported_formats: &[DxgiDuplicationFormat], ) -> Result<Self, Error>
使用自定义的 DXGI 支持格式列表重新创建复制接口,主要在
DxgiDuplicationApi::acquire_next_frame 返回 Error::AccessLost 错误之后调用。
Sourcepub const fn device(&self) -> &ID3D11Device
pub const fn device(&self) -> &ID3D11Device
获取与该对象关联的底层 [windows::Win32::Graphics::Direct3D11::ID3D11Device]。
Sourcepub const fn device_context(&self) -> &ID3D11DeviceContext
pub const fn device_context(&self) -> &ID3D11DeviceContext
获取用于 GPU 操作的底层 [windows::Win32::Graphics::Direct3D11::ID3D11DeviceContext]。
Sourcepub const fn duplication(&self) -> &IDXGIOutputDuplication
pub const fn duplication(&self) -> &IDXGIOutputDuplication
获取底层的 [windows::Win32::Graphics::Dxgi::IDXGIOutputDuplication] 接口。
Sourcepub const fn duplication_desc(&self) -> &DXGI_OUTDUPL_DESC
pub const fn duplication_desc(&self) -> &DXGI_OUTDUPL_DESC
获取该复制的 [windows::Win32::Graphics::Dxgi::DXGI_OUTDUPL_DESC]。
Sourcepub const fn dxgi_device(&self) -> &IDXGIDevice4
pub const fn dxgi_device(&self) -> &IDXGIDevice4
获取底层的 [windows::Win32::Graphics::Dxgi::IDXGIDevice4] 接口。
Sourcepub const fn output(&self) -> &IDXGIOutput6
pub const fn output(&self) -> &IDXGIOutput6
获取底层的 [windows::Win32::Graphics::Dxgi::IDXGIOutput6] 接口。
Sourcepub const fn format(&self) -> DxgiDuplicationFormat
pub const fn format(&self) -> DxgiDuplicationFormat
获取该复制的像素格式。
Sourcepub const fn refresh_rate(&self) -> (u32, u32)
pub const fn refresh_rate(&self) -> (u32, u32)
以(分子, 分母)的形式获取该复制的刷新率。
Sourcepub fn acquire_next_frame(
&mut self,
timeout_ms: u32,
) -> Result<DxgiDuplicationFrame<'_>, Error>
pub fn acquire_next_frame( &mut self, timeout_ms: u32, ) -> Result<DxgiDuplicationFrame<'_>, Error>
获取下一帧并更新内部纹理。
此调用最多阻塞 timeout_ms 毫秒。若在超时前没有新帧到达,则返回 Error::Timeout。
若复制访问权限丢失,则返回 Error::AccessLost,此时应重新创建一次复制。
Error::AccessLost 的主要原因包括:
- 该输出的显示模式发生改变(例如分辨率或颜色格式变化)。
- 用户切换到了不同的桌面(例如通过 Ctrl+Alt+Del 或快速用户切换)。
- DWM 开/关状态切换,或其他全屏应用
返回的 DxgiDuplicationFrame 允许你通过
DxgiDuplicationFrame::buffer 映射当前完整桌面图像。它包含该帧所报告的脏矩形列表。
§错误
- 当
timeout_ms内没有帧到达时,返回Error::Timeout - 当复制访问权限丢失且必须重新创建时,返回
Error::AccessLost - 当帧获取过程中发生其他 Windows API 错误时,返回
Error::WindowsError
自动 Trait 实现§
impl Freeze for DxgiDuplicationApi
impl RefUnwindSafe for DxgiDuplicationApi
impl Send for DxgiDuplicationApi
impl Sync for DxgiDuplicationApi
impl Unpin for DxgiDuplicationApi
impl UnsafeUnpin for DxgiDuplicationApi
impl UnwindSafe for DxgiDuplicationApi
通用实现§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
into_left 为 true,则将 self 转换为 Left 变体
(属于 Either<Self, Self>)。
否则将 self 转换为 Right 变体
(属于 Either<Self, Self>)。阅读更多Source§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
into_left(&self) 返回 true,则将 self 转换为 Left 变体
(属于 Either<Self, Self>)。
否则将 self 转换为 Right 变体
(属于 Either<Self, Self>)。阅读更多