MCPcopy Create free account
hub / github.com/Recordscript/recordscript / new

Method new

libs/scrap/src/quartz/capturer.rs:24–81  ·  view source on GitHub ↗
(
        display: Display,
        width: usize,
        height: usize,
        format: PixelFormat,
        config: Config,
        handler: F,
    )

Source from the content-addressed store, hash-verified

22
23impl Capturer {
24 pub fn new<F: Fn(Frame) + 'static>(
25 display: Display,
26 width: usize,
27 height: usize,
28 format: PixelFormat,
29 config: Config,
30 handler: F,
31 ) -> Result<Capturer, CGError> {
32 let stopped = Arc::new(Mutex::new(false));
33 let cloned_stopped = stopped.clone();
34 let handler: FrameAvailableHandler = ConcreteBlock::new(move |status, _, surface, _| {
35 use self::CGDisplayStreamFrameStatus::*;
36 if status == Stopped {
37 let mut lock = cloned_stopped.lock().unwrap();
38 *lock = true;
39 return;
40 }
41 if status == FrameComplete {
42 handler(unsafe { Frame::new(surface) });
43 }
44 })
45 .copy();
46
47 let queue = unsafe {
48 dispatch_queue_create(
49 b"quadrupleslap.scrap\0".as_ptr() as *const i8,
50 ptr::null_mut(),
51 )
52 };
53
54 let stream = unsafe {
55 let config = config.build();
56 let stream = CGDisplayStreamCreateWithDispatchQueue(
57 display.id(),
58 width,
59 height,
60 format,
61 config,
62 queue,
63 &*handler as *const Block<_, _> as *const c_void,
64 );
65 CFRelease(config);
66 stream
67 };
68
69 match unsafe { CGDisplayStreamStart(stream) } {
70 CGError::Success => Ok(Capturer {
71 stream,
72 queue,
73 width,
74 height,
75 format,
76 display,
77 stopped,
78 }),
79 x => Err(x),
80 }
81 }

Callers

nothing calls this directly

Calls 3

buildMethod · 0.80
cloneMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected