@@ -15,7 +15,7 @@ use cocoa::quartzcore::{transaction, CALayer, CATransform3D};
15
15
use core_foundation:: base:: TCFType ;
16
16
use core_foundation:: dictionary:: CFDictionary ;
17
17
use core_foundation:: number:: CFNumber ;
18
- use core_foundation:: string:: CFString ;
18
+ use core_foundation:: string:: { CFString , CFStringRef } ;
19
19
use core_graphics:: geometry:: { CGRect , CGSize , CG_ZERO_POINT } ;
20
20
use euclid:: default:: Size2D ;
21
21
use io_surface:: { self , kIOSurfaceBytesPerElement, kIOSurfaceBytesPerRow, IOSurface , IOSurfaceRef } ;
@@ -29,6 +29,11 @@ use std::slice;
29
29
use std:: sync:: { Arc , Condvar , Mutex } ;
30
30
use std:: thread;
31
31
32
+ #[ link( name = "IOSurface" , kind = "framework" ) ]
33
+ extern "C" {
34
+ fn IOSurfaceAlignProperty ( property : CFStringRef , value : usize ) -> usize ;
35
+ }
36
+
32
37
const BYTES_PER_PIXEL : i32 = 4 ;
33
38
34
39
/// Represents a hardware buffer of pixels that can be rendered to via the CPU or GPU and either
@@ -319,6 +324,7 @@ impl Device {
319
324
} ;
320
325
321
326
unsafe {
327
+ let bytes_per_row = IOSurfaceAlignProperty ( kIOSurfaceBytesPerRow, ( size. width * BYTES_PER_PIXEL ) as usize ) as i32 ;
322
328
let properties = CFDictionary :: from_CFType_pairs ( & [
323
329
(
324
330
CFString :: wrap_under_get_rule ( kIOSurfaceWidth) ,
@@ -334,7 +340,7 @@ impl Device {
334
340
) ,
335
341
(
336
342
CFString :: wrap_under_get_rule ( kIOSurfaceBytesPerRow) ,
337
- CFNumber :: from ( size . width * BYTES_PER_PIXEL ) . as_CFType ( ) ,
343
+ CFNumber :: from ( bytes_per_row ) . as_CFType ( ) ,
338
344
) ,
339
345
(
340
346
CFString :: wrap_under_get_rule ( kIOSurfacePixelFormat) ,
0 commit comments