From de4165d6f070077bd6a934542fca3dff3feb25e7 Mon Sep 17 00:00:00 2001 From: NiiightmareXD Date: Tue, 6 Aug 2024 02:32:11 +0330 Subject: [PATCH] =?UTF-8?q?Updated=20dependencies=20=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 32 +++++++++++++++--------------- Cargo.toml | 2 +- src/capture.rs | 10 ++++++++++ src/d3d11.rs | 4 ++++ src/encoder.rs | 19 +++++++++++------- src/frame.rs | 33 +++++++++++++++++++++++++++++-- src/graphics_capture_api.rs | 9 +++++++++ src/monitor.rs | 14 +++++++++++++ src/settings.rs | 4 ++++ src/window.rs | 11 +++++++++++ windows-capture-python/Cargo.toml | 4 ++-- windows-capture-python/src/lib.rs | 11 +++++++++++ 12 files changed, 125 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5733fbb..1a10f81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,9 +134,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.22.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e99090d12f6182924499253aaa1e73bf15c69cea8d2774c3c781e35badc3548" +checksum = "831e8e819a138c36e212f3af3fd9eeffed6bf1510a805af35b0edee5ffa59433" dependencies = [ "cfg-if", "indoc", @@ -152,9 +152,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7879eb018ac754bba32cb0eec7526391c02c14a093121857ed09fbf1d1057d41" +checksum = "1e8730e591b14492a8945cdff32f089250b05f5accecf74aeddf9e8272ce1fa8" dependencies = [ "once_cell", "target-lexicon", @@ -162,9 +162,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.22.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce2baa5559a411fc1cf519295f24c34b53d5d725818bc96b5abf94762da09041" +checksum = "5e97e919d2df92eb88ca80a037969f44e5e70356559654962cbb3316d00300c6" dependencies = [ "libc", "pyo3-build-config", @@ -172,9 +172,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.22.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "049621c20a23f2def20f4fe67978d1da8d8a883d64b9c21362f3b776e254edc7" +checksum = "eb57983022ad41f9e683a599f2fd13c3664d7063a3ac5714cae4b7bee7d3f206" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.22.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e969ee2e025435f1819d31a275ba4bb9cbbdf3ac535227fdbd85b9322ffe144" +checksum = "ec480c0c51ddec81019531705acac51bcdbeae563557c982aa8263bb96880372" dependencies = [ "heck", "proc-macro2", @@ -247,9 +247,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.70" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -264,18 +264,18 @@ checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2" [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 98e0344..f70509f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,7 @@ parking_lot = "0.12.3" rayon = "1.10.0" # Error handling -thiserror = "1.0.61" +thiserror = "1.0.63" [package.metadata.docs.rs] default-target = "x86_64-pc-windows-msvc" diff --git a/src/capture.rs b/src/capture.rs index cdbbdf9..1d09ba9 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -68,6 +68,7 @@ impl CaptureControl { /// /// The newly created CaptureControl struct. #[must_use] + #[inline] pub fn new( thread_handle: JoinHandle>>, halt_handle: Arc, @@ -86,6 +87,7 @@ impl CaptureControl { /// /// `true` if the capture thread is finished, `false` otherwise. #[must_use] + #[inline] pub fn is_finished(&self) -> bool { self.thread_handle .as_ref() @@ -98,6 +100,7 @@ impl CaptureControl { /// /// The join handle for the capture thread. #[must_use] + #[inline] pub fn into_thread_handle(self) -> JoinHandle>> { self.thread_handle.unwrap() } @@ -108,6 +111,7 @@ impl CaptureControl { /// /// The halt handle used to pause the capture thread. #[must_use] + #[inline] pub fn halt_handle(&self) -> Arc { self.halt_handle.clone() } @@ -118,6 +122,7 @@ impl CaptureControl { /// /// The callback struct used to call struct methods directly. #[must_use] + #[inline] pub fn callback(&self) -> Arc> { self.callback.clone() } @@ -127,6 +132,7 @@ impl CaptureControl { /// # Returns /// /// `Ok(())` if the capturing thread stops successfully, an error otherwise. + #[inline] pub fn wait(mut self) -> Result<(), CaptureControlError> { if let Some(thread_handle) = self.thread_handle.take() { match thread_handle.join() { @@ -147,6 +153,7 @@ impl CaptureControl { /// # Returns /// /// `Ok(())` if the capture thread stops successfully, an error otherwise. + #[inline] pub fn stop(mut self) -> Result<(), CaptureControlError> { self.halt_handle.store(true, atomic::Ordering::Relaxed); @@ -226,6 +233,7 @@ pub trait GraphicsCaptureApiHandler: Sized { /// # Returns /// /// Returns `Ok(())` if the capture was successful, otherwise returns an error of type `GraphicsCaptureApiError`. + #[inline] fn start>( settings: Settings, ) -> Result<(), GraphicsCaptureApiError> @@ -332,6 +340,7 @@ pub trait GraphicsCaptureApiHandler: Sized { /// # Returns /// /// Returns `Ok(CaptureControl)` if the capture was successful, otherwise returns an error of type `GraphicsCaptureApiError`. + #[inline] fn start_free_threaded + Send + 'static>( settings: Settings, ) -> Result, GraphicsCaptureApiError> @@ -499,6 +508,7 @@ pub trait GraphicsCaptureApiHandler: Sized { /// # Returns /// /// Returns `Ok(())` if the handler execution was successful, otherwise returns an error of type `Self::Error`. + #[inline] fn on_closed(&mut self) -> Result<(), Self::Error> { Ok(()) } diff --git a/src/d3d11.rs b/src/d3d11.rs index 8670ac5..fbfa636 100644 --- a/src/d3d11.rs +++ b/src/d3d11.rs @@ -39,6 +39,8 @@ impl SendDirectX { /// # Returns /// /// Returns A New `SendDirectX` Instance + #[must_use] + #[inline] pub const fn new(device: T) -> Self { Self(device) } @@ -48,6 +50,7 @@ impl SendDirectX { unsafe impl Send for SendDirectX {} /// Create `ID3D11Device` and `ID3D11DeviceContext` +#[inline] pub fn create_d3d_device() -> Result<(ID3D11Device, ID3D11DeviceContext), Error> { // Array of Direct3D feature levels. // The feature levels are listed in descending order of capability. @@ -88,6 +91,7 @@ pub fn create_d3d_device() -> Result<(ID3D11Device, ID3D11DeviceContext), Error> } /// Create `IDirect3DDevice` From `ID3D11Device` +#[inline] pub fn create_direct3d_device(d3d_device: &ID3D11Device) -> Result { let dxgi_device: IDXGIDevice = d3d_device.cast()?; let inspectable = unsafe { CreateDirect3D11DeviceFromDXGIDevice(&dxgi_device)? }; diff --git a/src/encoder.rs b/src/encoder.rs index 172d352..94c016e 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -68,6 +68,8 @@ impl ImageEncoder { /// # Returns /// /// A new `ImageEncoder` instance. + #[must_use] + #[inline] pub const fn new(format: ImageFormat, color_format: ColorFormat) -> Self { Self { format, @@ -90,6 +92,7 @@ impl ImageEncoder { /// # Errors /// /// Returns an `Error` if the encoding fails or if the color format is unsupported. + #[inline] pub fn encode( &self, image_buffer: &[u8], @@ -210,6 +213,7 @@ impl VideoEncoder { /// /// Returns a `Result` containing the `VideoEncoder` instance if successful, or a /// `VideoEncoderError` if an error occurs. + #[inline] pub fn new>( encoder_type: VideoEncoderType, encoder_quality: VideoEncoderQuality, @@ -240,12 +244,8 @@ impl VideoEncoder { MediaEncodingProfile::CreateVp9(VideoEncodingQuality(encoder_quality as i32))? } }; - media_encoding_profile - .Video()? - .SetWidth(width)?; - media_encoding_profile - .Video()? - .SetHeight(height)?; + media_encoding_profile.Video()?.SetWidth(width)?; + media_encoding_profile.Video()?.SetHeight(height)?; if fps.is_some() { media_encoding_profile .Video()? @@ -256,7 +256,7 @@ impl VideoEncoder { .FrameRate()? .SetDenominator(1)?; } - + let video_encoding_properties = VideoEncodingProperties::CreateUncompressed( &MediaEncodingSubtypes::Bgra8()?, width, @@ -402,6 +402,7 @@ impl VideoEncoder { /// /// Returns a `Result` containing the `VideoEncoder` instance if successful, or a /// `VideoEncoderError` if an error occurs. + #[inline] pub fn new_from_stream>( encoder_type: VideoEncoderType, encoder_quality: VideoEncoderQuality, @@ -562,6 +563,7 @@ impl VideoEncoder { /// /// Returns `Ok(())` if the frame is successfully sent for encoding, or a `VideoEncoderError` /// if an error occurs. + #[inline] pub fn send_frame(&mut self, frame: &mut Frame) -> Result<(), VideoEncoderError> { let timespan = match self.first_timespan { Some(timespan) => TimeSpan { @@ -608,6 +610,7 @@ impl VideoEncoder { /// /// Returns `Ok(())` if the frame is successfully sent for encoding, or a `VideoEncoderError` /// if an error occurs. + #[inline] pub fn send_frame_buffer( &mut self, buffer: &[u8], @@ -655,6 +658,7 @@ impl VideoEncoder { /// /// Returns `Ok(())` if the encoding is successfully finished, or a `VideoEncoderError` if an /// error occurs. + #[inline] pub fn finish(mut self) -> Result<(), VideoEncoderError> { self.frame_sender.send(None)?; @@ -673,6 +677,7 @@ impl VideoEncoder { } impl Drop for VideoEncoder { + #[inline] fn drop(&mut self) { let _ = self.frame_sender.send(None); diff --git a/src/frame.rs b/src/frame.rs index 2701a7a..fc9679b 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -88,6 +88,7 @@ impl<'a> Frame<'a> { /// A new Frame instance. #[allow(clippy::too_many_arguments)] #[must_use] + #[inline] pub fn new( d3d_device: &'a ID3D11Device, frame_surface: IDirect3DSurface, @@ -118,6 +119,7 @@ impl<'a> Frame<'a> { /// /// The width of the frame. #[must_use] + #[inline] pub const fn width(&self) -> u32 { self.width } @@ -128,6 +130,7 @@ impl<'a> Frame<'a> { /// /// The height of the frame. #[must_use] + #[inline] pub const fn height(&self) -> u32 { self.height } @@ -138,10 +141,22 @@ impl<'a> Frame<'a> { /// /// The time of the frame. #[must_use] + #[inline] pub const fn timespan(&self) -> TimeSpan { self.time } + /// Get the color format of the frame. + /// + /// # Returns + /// + /// The color format of the frame. + #[must_use] + #[inline] + pub const fn color_format(&self) -> ColorFormat { + self.color_format + } + /// Get the raw surface of the frame. /// /// # Returns @@ -152,6 +167,7 @@ impl<'a> Frame<'a> { /// /// This method is unsafe because it returns a raw pointer to the IDirect3DSurface. #[must_use] + #[inline] pub unsafe fn as_raw_surface(&self) -> IDirect3DSurface { self.frame_surface.clone() } @@ -161,6 +177,7 @@ impl<'a> Frame<'a> { /// # Returns /// /// The ID3D11Texture2D representing the raw texture of the frame. + #[inline] pub fn texture(&self) -> Result { // Texture Settings let texture_desc = D3D11_TEXTURE2D_DESC { @@ -185,9 +202,9 @@ impl<'a> Frame<'a> { self.d3d_device .CreateTexture2D(&texture_desc, None, Some(&mut texture))?; }; - + let texture = texture.unwrap(); - + // Copy the real texture to copy texture unsafe { self.context.CopyResource(&texture, &self.frame_texture); @@ -201,6 +218,7 @@ impl<'a> Frame<'a> { /// # Returns /// /// The FrameBuffer containing the frame data. + #[inline] pub fn buffer(&mut self) -> Result { let texture = self.texture()?; @@ -250,6 +268,7 @@ impl<'a> Frame<'a> { /// # Returns /// /// The FrameBuffer containing the cropped frame data. + #[inline] pub fn buffer_crop( &mut self, start_width: u32, @@ -357,6 +376,7 @@ impl<'a> Frame<'a> { /// # Returns /// /// An empty Result if successful, or an Error if there was an issue saving the image. + #[inline] pub fn save_as_image>( &mut self, path: T, @@ -405,6 +425,7 @@ impl<'a> FrameBuffer<'a> { /// /// A new `FrameBuffer` instance. #[must_use] + #[inline] pub fn new( raw_buffer: &'a mut [u8], buffer: &'a mut Vec, @@ -427,36 +448,42 @@ impl<'a> FrameBuffer<'a> { /// Get the width of the frame buffer. #[must_use] + #[inline] pub const fn width(&self) -> u32 { self.width } /// Get the height of the frame buffer. #[must_use] + #[inline] pub const fn height(&self) -> u32 { self.height } /// Get the row pitch of the frame buffer. #[must_use] + #[inline] pub const fn row_pitch(&self) -> u32 { self.row_pitch } /// Get the depth pitch of the frame buffer. #[must_use] + #[inline] pub const fn depth_pitch(&self) -> u32 { self.depth_pitch } /// Check if the buffer has padding. #[must_use] + #[inline] pub const fn has_padding(&self) -> bool { self.width * 4 != self.row_pitch } /// Get the raw pixel data with possible padding. #[must_use] + #[inline] pub fn as_raw_buffer(&mut self) -> &mut [u8] { self.raw_buffer } @@ -466,6 +493,7 @@ impl<'a> FrameBuffer<'a> { /// # Returns /// /// A mutable reference to the buffer containing pixel data without padding. + #[inline] pub fn as_raw_nopadding_buffer(&mut self) -> Result<&mut [u8], Error> { if !self.has_padding() { return Ok(self.raw_buffer); @@ -510,6 +538,7 @@ impl<'a> FrameBuffer<'a> { /// # Returns /// /// An `Ok` result if the image is successfully saved, or an `Err` result if there was an error. + #[inline] pub fn save_as_image>( &mut self, path: T, diff --git a/src/graphics_capture_api.rs b/src/graphics_capture_api.rs index dfaf757..a7a98ec 100644 --- a/src/graphics_capture_api.rs +++ b/src/graphics_capture_api.rs @@ -60,11 +60,13 @@ impl InternalCaptureControl { /// /// A new instance of `InternalCaptureControl`. #[must_use] + #[inline] pub fn new(stop: Arc) -> Self { Self { stop } } /// Gracefully stop the capture thread. + #[inline] pub fn stop(self) { self.stop.store(true, atomic::Ordering::Relaxed); } @@ -110,6 +112,7 @@ impl GraphicsCaptureApi { /// # Returns /// /// Returns a `Result` containing the new `GraphicsCaptureApi` struct if successful, or an `Error` if an error occurred. + #[inline] pub fn new< T: GraphicsCaptureApiHandler + Send + 'static, E: Send + Sync + 'static, @@ -340,6 +343,7 @@ impl GraphicsCaptureApi { /// # Returns /// /// Returns `Ok(())` if the capture started successfully, or an `Error` if an error occurred. + #[inline] pub fn start_capture(&mut self) -> Result<(), Error> { if self.active { return Err(Error::AlreadyStarted); @@ -352,6 +356,7 @@ impl GraphicsCaptureApi { } /// Stop the capture. + #[inline] pub fn stop_capture(mut self) { if let Some(frame_pool) = self.frame_pool.take() { frame_pool @@ -376,6 +381,7 @@ impl GraphicsCaptureApi { /// /// Returns an `Arc` representing the halt handle. #[must_use] + #[inline] pub fn halt_handle(&self) -> Arc { self.halt.clone() } @@ -385,6 +391,7 @@ impl GraphicsCaptureApi { /// # Returns /// /// Returns `Ok(true)` if the API is supported, `Ok(false)` if the API is not supported, or an `Error` if an error occurred. + #[inline] pub fn is_supported() -> Result { Ok(ApiInformation::IsApiContractPresentByMajor( &HSTRING::from("Windows.Foundation.UniversalApiContract"), @@ -397,6 +404,7 @@ impl GraphicsCaptureApi { /// # Returns /// /// Returns `true` if toggling the cursor capture is supported, `false` otherwise. + #[inline] pub fn is_cursor_settings_supported() -> Result { Ok(ApiInformation::IsPropertyPresent( &HSTRING::from("Windows.Graphics.Capture.GraphicsCaptureSession"), @@ -409,6 +417,7 @@ impl GraphicsCaptureApi { /// # Returns /// /// Returns `true` if toggling the border capture is supported, `false` otherwise. + #[inline] pub fn is_border_settings_supported() -> Result { Ok(ApiInformation::IsPropertyPresent( &HSTRING::from("Windows.Graphics.Capture.GraphicsCaptureSession"), diff --git a/src/monitor.rs b/src/monitor.rs index 578a615..548a74e 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -69,6 +69,7 @@ impl Monitor { /// # Errors /// /// Returns an `Error::NotFound` if there is no primary monitor. + #[inline] pub fn primary() -> Result { let point = POINT { x: 0, y: 0 }; let monitor = unsafe { MonitorFromPoint(point, MONITOR_DEFAULTTONULL) }; @@ -90,6 +91,7 @@ impl Monitor { /// /// Returns an `Error::IndexIsLowerThanOne` if the index is less than 1. /// Returns an `Error::NotFound` if the monitor at the specified index is not found. + #[inline] pub fn from_index(index: usize) -> Result { if index < 1 { return Err(Error::IndexIsLowerThanOne); @@ -109,6 +111,7 @@ impl Monitor { /// # Errors /// /// Returns an `Error` if there is an error retrieving the monitor index. + #[inline] pub fn index(&self) -> Result { let device_name = self.device_name()?; Ok(device_name.replace("\\\\.\\DISPLAY", "").parse()?) @@ -119,6 +122,7 @@ impl Monitor { /// # Errors /// /// Returns an `Error` if there is an error retrieving the monitor name. + #[inline] pub fn name(&self) -> Result { let mut monitor_info = MONITORINFOEXW { monitorInfo: MONITORINFO { @@ -232,6 +236,7 @@ impl Monitor { /// # Errors /// /// Returns an `Error` if there is an error retrieving the monitor device name. + #[inline] pub fn device_name(&self) -> Result { let mut monitor_info = MONITORINFOEXW { monitorInfo: MONITORINFO { @@ -270,6 +275,7 @@ impl Monitor { /// # Errors /// /// Returns an `Error` if there is an error retrieving the monitor device string. + #[inline] pub fn device_string(&self) -> Result { let mut monitor_info = MONITORINFOEXW { monitorInfo: MONITORINFO { @@ -329,6 +335,7 @@ impl Monitor { /// # Errors /// /// Returns an `Error` if there is an error retrieving the monitor refresh rate. + #[inline] pub fn refresh_rate(&self) -> Result { let mut device_mode = DEVMODEW { dmSize: u16::try_from(mem::size_of::()).unwrap(), @@ -354,6 +361,7 @@ impl Monitor { /// # Errors /// /// Returns an `Error` if there is an error retrieving the monitor width. + #[inline] pub fn width(&self) -> Result { let mut device_mode = DEVMODEW { dmSize: u16::try_from(mem::size_of::()).unwrap(), @@ -379,6 +387,7 @@ impl Monitor { /// # Errors /// /// Returns an `Error` if there is an error retrieving the monitor height. + #[inline] pub fn height(&self) -> Result { let mut device_mode = DEVMODEW { dmSize: u16::try_from(mem::size_of::()).unwrap(), @@ -404,6 +413,7 @@ impl Monitor { /// # Errors /// /// Returns an `Error` if there is an error enumerating the monitors. + #[inline] pub fn enumerate() -> Result, Error> { let mut monitors: Vec = Vec::new(); @@ -426,6 +436,7 @@ impl Monitor { /// /// * `hmonitor` - The raw HMONITOR. #[must_use] + #[inline] pub const fn from_raw_hmonitor(monitor: *mut std::ffi::c_void) -> Self { Self { monitor: HMONITOR(monitor), @@ -434,11 +445,13 @@ impl Monitor { /// Returns the raw HMONITOR of the monitor. #[must_use] + #[inline] pub const fn as_raw_hmonitor(&self) -> *mut std::ffi::c_void { self.monitor.0 } // Callback Used For Enumerating All Monitors + #[inline] unsafe extern "system" fn enum_monitors_callback( monitor: HMONITOR, _: HDC, @@ -457,6 +470,7 @@ impl Monitor { impl TryFrom for GraphicsCaptureItem { type Error = Error; + #[inline] fn try_from(value: Monitor) -> Result { let monitor = HMONITOR(value.as_raw_hmonitor()); diff --git a/src/settings.rs b/src/settings.rs index 3d2914d..a6677f8 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -8,6 +8,8 @@ pub enum ColorFormat { } impl Default for ColorFormat { + #[must_use] + #[inline] fn default() -> Self { Self::Rgba8 } @@ -52,6 +54,8 @@ impl> Settings { /// * `draw_border` - Whether to draw a border around the captured region or not. /// * `color_format` - The desired color format for the captured frame. /// * `flags` - Additional flags for the capture settings that will be passed to user defined `new` function. + #[must_use] + #[inline] pub const fn new( item: T, cursor_capture: CursorCaptureSettings, diff --git a/src/window.rs b/src/window.rs index 4318a74..100fa06 100644 --- a/src/window.rs +++ b/src/window.rs @@ -57,6 +57,7 @@ impl Window { /// # Errors /// /// Returns an `Error::NoActiveWindow` if there is no active window. + #[inline] pub fn foreground() -> Result { let window = unsafe { GetForegroundWindow() }; @@ -76,6 +77,7 @@ impl Window { /// # Errors /// /// Returns an `Error::NotFound` if the window is not found. + #[inline] pub fn from_name(title: &str) -> Result { let hstring_title = HSTRING::from(title); let window = unsafe { FindWindowW(None, &hstring_title)? }; @@ -96,6 +98,7 @@ impl Window { /// # Errors /// /// Returns an `Error::NotFound` if no window with a matching name substring is found. + #[inline] pub fn from_contains_name(title: &str) -> Result { let windows = Self::enumerate()?; @@ -115,6 +118,7 @@ impl Window { /// # Errors /// /// Returns an `Error` if there is an error retrieving the window title. + #[inline] pub fn title(&self) -> Result { let len = unsafe { GetWindowTextLengthW(self.window) }; @@ -142,6 +146,7 @@ impl Window { /// /// Returns `None` if the window doesn't intersect with any monitor. #[must_use] + #[inline] pub fn monitor(&self) -> Option { let window = self.window; @@ -160,6 +165,7 @@ impl Window { /// /// Returns `true` if the window is valid, `false` otherwise. #[must_use] + #[inline] pub fn is_valid(&self) -> bool { if !unsafe { IsWindowVisible(self.window).as_bool() } { return false; @@ -195,6 +201,7 @@ impl Window { /// # Errors /// /// Returns an `Error` if there is an error enumerating the windows. + #[inline] pub fn enumerate() -> Result, Error> { let mut windows: Vec = Vec::new(); @@ -216,17 +223,20 @@ impl Window { /// /// * `hwnd` - The raw HWND. #[must_use] + #[inline] pub const fn from_raw_hwnd(hwnd: *mut std::ffi::c_void) -> Self { Self { window: HWND(hwnd) } } /// Returns the raw HWND of the window. #[must_use] + #[inline] pub const fn as_raw_hwnd(&self) -> *mut std::ffi::c_void { self.window.0 } // Callback used for enumerating all windows. + #[inline] unsafe extern "system" fn enum_windows_callback(window: HWND, vec: LPARAM) -> BOOL { let windows = &mut *(vec.0 as *mut Vec); @@ -242,6 +252,7 @@ impl Window { impl TryFrom for GraphicsCaptureItem { type Error = Error; + #[inline] fn try_from(value: Window) -> Result { let window = HWND(value.as_raw_hwnd()); diff --git a/windows-capture-python/Cargo.toml b/windows-capture-python/Cargo.toml index 24b6f5b..9464392 100644 --- a/windows-capture-python/Cargo.toml +++ b/windows-capture-python/Cargo.toml @@ -21,11 +21,11 @@ name = "windows_capture" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.22.1", features = [ +pyo3 = { version = "0.22.2", features = [ "extension-module", "auto-initialize", "abi3", "abi3-py39", ] } -thiserror = "1.0.61" +thiserror = "1.0.63" windows-capture = { path = ".." } diff --git a/windows-capture-python/src/lib.rs b/windows-capture-python/src/lib.rs index c1d562e..c47476d 100644 --- a/windows-capture-python/src/lib.rs +++ b/windows-capture-python/src/lib.rs @@ -33,6 +33,8 @@ pub struct NativeCaptureControl { } impl NativeCaptureControl { + #[must_use] + #[inline] const fn new( capture_control: CaptureControl, ) -> Self { @@ -45,12 +47,14 @@ impl NativeCaptureControl { #[pymethods] impl NativeCaptureControl { #[must_use] + #[inline] pub fn is_finished(&self) -> bool { self.capture_control .as_ref() .map_or(true, CaptureControl::is_finished) } + #[inline] pub fn wait(&mut self, py: Python) -> PyResult<()> { // But Honestly WTF Is This? You Know How Much Time It Took Me To Debug This? // Just Why? Who Decided This BS Threading Shit? @@ -83,6 +87,7 @@ impl NativeCaptureControl { Ok(()) } + #[inline] pub fn stop(&mut self, py: Python) -> PyResult<()> { // But Honestly WTF Is This? You Know How Much Time It Took Me To Debug This? // Just Why? Who TF Decided This BS Threading Shit? @@ -131,6 +136,7 @@ pub struct NativeWindowsCapture { impl NativeWindowsCapture { #[new] #[pyo3(signature = (on_frame_arrived_callback, on_closed, cursor_capture=None, draw_border=None, monitor_index=None, window_name=None))] + #[inline] pub fn new( on_frame_arrived_callback: PyObject, on_closed: PyObject, @@ -172,6 +178,7 @@ impl NativeWindowsCapture { } /// Start Capture + #[inline] pub fn start(&mut self) -> PyResult<()> { if self.window_name.is_some() { let window = match Window::from_contains_name(self.window_name.as_ref().unwrap()) { @@ -255,6 +262,7 @@ impl NativeWindowsCapture { } /// Start Capture On A Dedicated Thread + #[inline] pub fn start_free_threaded(&mut self) -> PyResult { let capture_control = if self.window_name.is_some() { let window = match Window::from_contains_name(self.window_name.as_ref().unwrap()) { @@ -359,6 +367,7 @@ impl GraphicsCaptureApiHandler for InnerNativeWindowsCapture { type Flags = (Arc, Arc); type Error = InnerNativeWindowsCaptureError; + #[inline] fn new((on_frame_arrived_callback, on_closed): Self::Flags) -> Result { Ok(Self { on_frame_arrived_callback, @@ -366,6 +375,7 @@ impl GraphicsCaptureApiHandler for InnerNativeWindowsCapture { }) } + #[inline] fn on_frame_arrived( &mut self, frame: &mut Frame, @@ -411,6 +421,7 @@ impl GraphicsCaptureApiHandler for InnerNativeWindowsCapture { Ok(()) } + #[inline] fn on_closed(&mut self) -> Result<(), Self::Error> { Python::with_gil(|py| self.on_closed.call0(py)) .map_err(InnerNativeWindowsCaptureError::PythonError)?;