@@ -59,23 +59,30 @@ Add to your `Cargo.toml`:
5959
6060``` toml
6161[dependencies ]
62- screencapturekit = " 1 "
62+ screencapturekit = " 2 "
6363```
6464
6565For async support:
6666
6767``` toml
6868[dependencies ]
69- screencapturekit = { version = " 1 " , features = [" async" ] }
69+ screencapturekit = { version = " 2 " , features = [" async" ] }
7070```
7171
7272For latest macOS features:
7373
7474``` toml
7575[dependencies ]
76- screencapturekit = { version = " 1 " , features = [" macos_26_0" ] }
76+ screencapturekit = { version = " 2 " , features = [" macos_26_0" ] }
7777```
7878
79+ > ** Upgrading from 1.x?** See [ ` docs/MIGRATION.md ` ] ( docs/MIGRATION.md#migrating-from-1x-to-20 )
80+ > for the full list of 2.0 breaking changes — most notable are the new
81+ > ` Send + Sync ` bound on output / delegate traits, the ` #[non_exhaustive] `
82+ > attribute on ` PixelFormat ` and ` SCStreamErrorCode ` , and the new
83+ > ` PixelFormat::Unknown(FourCharCode) ` variant for codes the binding does
84+ > not yet name.
85+
7986## 🚀 Quick Start
8087
8188### Basic Screen Capture
@@ -91,6 +98,10 @@ impl SCStreamOutputTrait for Handler {
9198 }
9299}
93100
101+ // Note: as of 2.0, `SCStreamOutputTrait` (and `SCStreamDelegateTrait`)
102+ // require `Send + Sync` — handlers run on Apple's dispatch queues and may
103+ // be invoked concurrently from arbitrary threads.
104+
94105fn main () -> Result <(), Box <dyn std :: error :: Error >> {
95106 // Get available displays
96107 let content = SCShareableContent :: get ()? ;
@@ -463,6 +474,8 @@ config.set_should_be_opaque(true);
463474| ` SCDisplay ` | Display information (resolution, ID, frame) |
464475| ` SCWindow ` | Window information (title, bounds, owner, layer) |
465476| ` SCRunningApplication ` | Application information (name, bundle ID, PID) |
477+ | ` ContentSnapshot ` | Plain-data batch of all displays, windows, applications (one FFI round-trip) |
478+ | ` AudioInputDevice ` | Microphone enumeration via ` AVFoundation ` (used with ` with_microphone_capture_device_id ` ) |
466479
467480### Media Types
468481
@@ -491,12 +504,16 @@ config.set_should_be_opaque(true);
491504
492505| Type | Description |
493506| ------| -------------|
494- | ` PixelFormat ` | BGRA, ` YCbCr420v ` , ` YCbCr420f ` , l10r (10-bit) |
507+ | ` PixelFormat ` | BGRA, ` YCbCr420v ` , ` YCbCr420f ` , l10r (10-bit), ` Unknown(FourCharCode) ` for forward-compat |
508+ | ` FourCharCode ` | Apple OSType four-char code helper used by ` PixelFormat::Unknown ` |
495509| ` SCPresenterOverlayAlertSetting ` | Privacy alert behavior |
496510| ` SCCaptureDynamicRange ` | HDR/SDR modes (macOS 15.0+) |
497511| ` SCScreenshotConfiguration ` | Advanced screenshot config (macOS 26.0+) |
498512| ` SCScreenshotDynamicRange ` | SDR/HDR screenshot output (macOS 26.0+) |
499513
514+ > ** 2.0 note:** ` PixelFormat ` and ` SCStreamErrorCode ` are ` #[non_exhaustive] ` .
515+ > ` match ` arms over either of them must include a wildcard ` _ => … ` arm.
516+
500517## 🏃 Examples
501518
502519The [ ` examples/ ` ] ( examples/ ) directory contains focused API demonstrations:
@@ -744,14 +761,16 @@ for w in &windows {
744761```
745762
746763Same idea on a video sample buffer — read every attachment in one CF→Swift
747- bridge cast instead of one cast per attribute:
764+ bridge cast instead of one cast per attribute (this includes the new-in-2.0
765+ ` presenter_overlay_content_rect ` field for Presenter Overlay layouts):
748766
749767``` rust,no_run
750768# use screencapturekit::cm::CMSampleBuffer;
751769# fn example(sample: &CMSampleBuffer) {
752770if let Some(info) = sample.frame_info() {
753- println!("status={:?} time={:?} content={:?}",
754- info.frame_status, info.display_time, info.content_rect);
771+ println!("status={:?} time={:?} content={:?} overlay={:?}",
772+ info.frame_status, info.display_time, info.content_rect,
773+ info.presenter_overlay_content_rect);
755774}
756775# }
757776```
@@ -774,17 +793,46 @@ let pixels = img.bgra_data()?; // ~5% faster than rgba_data() at 1080p
774793# }
775794```
776795
796+ For sustained screenshot loops, the new (2.1+) ` *_data_into ` variants
797+ write into a caller-supplied buffer so you only pay the
798+ ` width × height × 4 ` byte allocation once instead of per frame
799+ (~ 33 MB / call at 4K):
800+
801+ ``` rust,no_run
802+ # #[cfg(feature = "macos_14_0")]
803+ # fn example(
804+ # filter: &screencapturekit::stream::content_filter::SCContentFilter,
805+ # config: &screencapturekit::stream::configuration::SCStreamConfiguration,
806+ # ) -> Result<(), Box<dyn std::error::Error>> {
807+ use screencapturekit::screenshot_manager::SCScreenshotManager;
808+ let mut buffer: Vec<u8> = vec![0; 1920 * 1080 * 4];
809+ for _ in 0..100 {
810+ let img = SCScreenshotManager::capture_image(filter, config)?;
811+ img.bgra_data_into(&mut buffer)?; // reuse the same allocation
812+ // ... process `buffer` ...
813+ }
814+ # Ok(())
815+ # }
816+ ```
817+
777818See [ ` examples/24_batched_apis_showcase.rs ` ] ( examples/24_batched_apis_showcase.rs )
778819for a side-by-side comparison that benchmarks all three APIs against the
779820legacy per-element pattern on your machine.
780821
781822## 🔄 Migration
782823
783824Upgrading from an older version? See [ ` docs/MIGRATION.md ` ] ( docs/MIGRATION.md ) for:
784- - API changes between versions
825+ - API changes between versions (including the ** 1.x → 2.0 ** upgrade path)
785826- Code examples for common migrations
786827- Deprecated API replacements
787828
829+ ** Highlights of 2.0 breaking changes:**
830+ - ` SCStreamOutputTrait ` and ` SCStreamDelegateTrait ` now require ` Send + Sync `
831+ - ` PixelFormat ` is ` #[non_exhaustive] ` and gained a ` Unknown(FourCharCode) ` variant
832+ - ` SCStreamErrorCode ` is ` #[non_exhaustive] `
833+ - ` PartialEq ` / ` Hash ` for ` PixelFormat ` now normalise through ` FourCharCode `
834+ - Every ` macos_* ` Cargo feature now propagates to the Swift bridge build (build will fail loudly if SDK detection fails)
835+
788836## 🤝 Contributing
789837
790838Contributions welcome! Please:
0 commit comments