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 ", diff --git a/src/platform/macos/system/surface.rs b/src/platform/macos/system/surface.rs index ed42c4f8..3c4992d2 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,10 @@ 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 +343,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),