From 3c14075da577395c6378d905638ca16c6aa27296 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 19 Aug 2024 08:23:35 -0400 Subject: [PATCH 1/3] Ensure bytes per row value meets alignment requirements for macOS surfaces. --- src/platform/macos/system/surface.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/platform/macos/system/surface.rs b/src/platform/macos/system/surface.rs index ed42c4f8..c1ba91e5 100644 --- a/src/platform/macos/system/surface.rs +++ b/src/platform/macos/system/surface.rs @@ -15,7 +15,7 @@ use cocoa::quartzcore::{transaction, CALayer, CATransform3D}; use core_foundation::base::TCFType; use core_foundation::dictionary::CFDictionary; use core_foundation::number::CFNumber; -use core_foundation::string::CFString; +use core_foundation::string::{CFString, CFStringRef}; use core_graphics::geometry::{CGRect, CGSize, CG_ZERO_POINT}; use euclid::default::Size2D; use io_surface::{self, kIOSurfaceBytesPerElement, kIOSurfaceBytesPerRow, IOSurface, IOSurfaceRef}; @@ -29,6 +29,11 @@ use std::slice; use std::sync::{Arc, Condvar, Mutex}; use std::thread; +#[link(name = "IOSurface", kind = "framework")] +extern "C" { + fn IOSurfaceAlignProperty(property: CFStringRef, value: usize) -> usize; +} + const BYTES_PER_PIXEL: i32 = 4; /// Represents a hardware buffer of pixels that can be rendered to via the CPU or GPU and either @@ -319,6 +324,7 @@ impl Device { }; unsafe { + let bytes_per_row = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, (size.width * BYTES_PER_PIXEL) as usize) as i32; let properties = CFDictionary::from_CFType_pairs(&[ ( CFString::wrap_under_get_rule(kIOSurfaceWidth), @@ -334,7 +340,7 @@ impl Device { ), ( CFString::wrap_under_get_rule(kIOSurfaceBytesPerRow), - CFNumber::from(size.width * BYTES_PER_PIXEL).as_CFType(), + CFNumber::from(bytes_per_row).as_CFType(), ), ( CFString::wrap_under_get_rule(kIOSurfacePixelFormat), From be8cc98d5f1fbbc2e8b1c8b0bb0b06d500c51739 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 19 Aug 2024 11:39:10 -0400 Subject: [PATCH 2/3] Formatting. --- src/platform/macos/system/surface.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/platform/macos/system/surface.rs b/src/platform/macos/system/surface.rs index c1ba91e5..3c4992d2 100644 --- a/src/platform/macos/system/surface.rs +++ b/src/platform/macos/system/surface.rs @@ -324,7 +324,10 @@ impl Device { }; unsafe { - let bytes_per_row = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, (size.width * BYTES_PER_PIXEL) as usize) as i32; + let bytes_per_row = IOSurfaceAlignProperty( + kIOSurfaceBytesPerRow, + (size.width * BYTES_PER_PIXEL) as usize, + ) as i32; let properties = CFDictionary::from_CFType_pairs(&[ ( CFString::wrap_under_get_rule(kIOSurfaceWidth), From 46c05dc11b23ad57421e2e4d607ba8f6d0de9d93 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 19 Aug 2024 11:40:09 -0400 Subject: [PATCH 3/3] Publish 0.9.8. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 99906ac5..d6035660 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "surfman" license = "MIT OR Apache-2.0 OR MPL-2.0" edition = "2018" -version = "0.9.6" +version = "0.9.7" authors = [ "Patrick Walton ", "Emilio Cobos Álvarez ",