-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: window添加refresh方法 * fix: 修复macos window内存泄漏 * chore: 更新版本号
- Loading branch information
Showing
9 changed files
with
239 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use fs_extra::dir; | ||
use std::{ | ||
thread, | ||
time::{Duration, Instant}, | ||
}; | ||
use xcap::Window; | ||
|
||
fn main() { | ||
let windows = Window::all().unwrap(); | ||
|
||
dir::create_all("target/windows", true).unwrap(); | ||
|
||
let mut i = 0; | ||
for window in &windows { | ||
// 最小化的窗口不能截屏 | ||
if window.is_minimized() { | ||
continue; | ||
} | ||
|
||
if window.title().contains("Chrome") { | ||
break; | ||
} | ||
|
||
println!( | ||
"Window: {:?} {:?} {:?}", | ||
window.title(), | ||
(window.x(), window.y(), window.width(), window.height()), | ||
(window.is_minimized(), window.is_maximized()) | ||
); | ||
|
||
i += 1; | ||
} | ||
|
||
let mut win = windows.get(i).unwrap().clone(); | ||
println!("{:?}", win); | ||
|
||
let mut i = 0; | ||
let frame = 20; | ||
let start = Instant::now(); | ||
let fps = 1000 / frame; | ||
|
||
loop { | ||
i += 1; | ||
let time = Instant::now(); | ||
win.refresh().unwrap(); | ||
let image = win.capture_image().unwrap(); | ||
image | ||
.save(format!("target/windows/window-{}.png", i,)) | ||
.unwrap(); | ||
let sleep_time = fps * i - start.elapsed().as_millis() as i128; | ||
println!( | ||
"sleep_time: {:?} current_step_time: {:?}", | ||
sleep_time, | ||
time.elapsed() | ||
); | ||
if sleep_time > 0 { | ||
thread::sleep(Duration::from_millis(sleep_time as u64)); | ||
} | ||
|
||
if i >= 900 { | ||
break; | ||
} | ||
} | ||
|
||
println!("time {:?}", start.elapsed()); | ||
let actual_fps = 900 / start.elapsed().as_secs(); | ||
println!("actual fps: {}", actual_fps); | ||
|
||
// ffmpeg -framerate {actual_fps} -i window-%d.png -c:v libx264 -pix_fmt yuv420p output.mp4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use core_foundation::{ | ||
array::CFArrayRef, | ||
base::{CFRelease, ToVoid}, | ||
}; | ||
use std::ops::Deref; | ||
|
||
#[derive(Debug)] | ||
pub(super) struct BoxCFArrayRef { | ||
cf_array_ref: CFArrayRef, | ||
} | ||
|
||
impl Deref for BoxCFArrayRef { | ||
type Target = CFArrayRef; | ||
fn deref(&self) -> &Self::Target { | ||
&self.cf_array_ref | ||
} | ||
} | ||
|
||
impl Drop for BoxCFArrayRef { | ||
fn drop(&mut self) { | ||
unsafe { | ||
CFRelease(self.cf_array_ref.to_void()); | ||
} | ||
} | ||
} | ||
|
||
impl BoxCFArrayRef { | ||
pub fn new(cf_array_ref: CFArrayRef) -> Self { | ||
BoxCFArrayRef { cf_array_ref } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod boxed; | ||
mod capture; | ||
|
||
pub mod impl_monitor; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters