7
7
// option. This file may not be copied, modified, or distributed
8
8
// except according to those terms.
9
9
10
+ #![ allow( non_upper_case_globals) ]
11
+
10
12
use core_foundation:: array:: { CFArray , CFArrayRef } ;
11
- use core_foundation:: base:: { CFTypeRef , TCFType } ;
13
+ use core_foundation:: base:: { CFType , CFTypeRef , TCFType } ;
12
14
use core_foundation:: date:: CFTimeInterval ;
13
15
use core_foundation:: dictionary:: { CFDictionary , CFDictionaryRef } ;
14
16
use core_foundation:: string:: { CFString , CFStringRef } ;
15
17
use core_graphics:: base:: CGFloat ;
16
18
use core_graphics:: color:: { CGColor , SysCGColorRef } ;
19
+ use core_graphics:: color_space:: CGColorSpace ;
17
20
use core_graphics:: context:: CGContext ;
18
21
use core_graphics:: geometry:: { CGAffineTransform , CGPoint , CGRect , CGSize } ;
19
22
use core_graphics:: path:: { CGPath , SysCGPathRef } ;
20
23
use foreign_types:: ForeignType ;
21
24
use std:: ops:: Mul ;
22
25
use std:: ptr;
23
26
27
+ use appkit:: CGLContextObj ;
24
28
use base:: { BOOL , id, nil, YES } ;
25
29
use foundation:: NSUInteger ;
26
30
31
+ // CABase.h
32
+
33
+ pub fn current_media_time ( ) -> CFTimeInterval {
34
+ unsafe {
35
+ CACurrentMediaTime ( )
36
+ }
37
+ }
38
+
27
39
// CALayer.h
28
40
29
41
pub struct CALayer ( id ) ;
@@ -1356,11 +1368,169 @@ bitflags! {
1356
1368
}
1357
1369
}
1358
1370
1371
+ // CARenderer.h
1372
+
1373
+ pub struct CARenderer ( id ) ;
1374
+
1375
+ unsafe impl Send for CARenderer { }
1376
+ unsafe impl Sync for CARenderer { }
1377
+
1378
+ impl Clone for CARenderer {
1379
+ #[ inline]
1380
+ fn clone ( & self ) -> CARenderer {
1381
+ unsafe {
1382
+ CARenderer ( msg_send ! [ self . id( ) , retain] )
1383
+ }
1384
+ }
1385
+ }
1386
+
1387
+ impl Drop for CARenderer {
1388
+ #[ inline]
1389
+ fn drop ( & mut self ) {
1390
+ unsafe {
1391
+ msg_send ! [ self . id( ) , release]
1392
+ }
1393
+ }
1394
+ }
1395
+
1396
+ impl CARenderer {
1397
+ #[ inline]
1398
+ pub fn id ( & self ) -> id {
1399
+ self . 0
1400
+ }
1401
+
1402
+ #[ inline]
1403
+ pub unsafe fn from_cgl_context ( context : CGLContextObj , color_space : Option < CGColorSpace > )
1404
+ -> CARenderer {
1405
+ let mut pairs: Vec < ( CFString , CFType ) > = vec ! [ ] ;
1406
+ if let Some ( color_space) = color_space {
1407
+ pairs. push ( ( CFString :: wrap_under_get_rule ( kCARendererColorSpace) ,
1408
+ CFType :: wrap_under_get_rule ( color_space. as_ptr ( ) as * const _ as * const _ ) ) )
1409
+ }
1410
+
1411
+ let options: CFDictionary < CFString , CFType > = CFDictionary :: from_CFType_pairs ( & pairs) ;
1412
+
1413
+ let renderer: id =
1414
+ msg_send ! [ class!( CARenderer ) , rendererWithCGLContext: context
1415
+ options: options. as_CFTypeRef( ) ] ;
1416
+ debug_assert ! ( renderer != nil) ;
1417
+ CARenderer ( renderer)
1418
+ }
1419
+
1420
+ #[ inline]
1421
+ pub unsafe fn from_metal_texture ( metal_texture : id ,
1422
+ metal_command_queue : id ,
1423
+ color_space : Option < CGColorSpace > )
1424
+ -> CARenderer {
1425
+ let mut pairs: Vec < ( CFString , CFType ) > = vec ! [
1426
+ ( CFString :: wrap_under_get_rule( kCARendererMetalCommandQueue) ,
1427
+ CFType :: wrap_under_get_rule( metal_command_queue as * const _ as * const _) ) ,
1428
+ ] ;
1429
+ if let Some ( color_space) = color_space {
1430
+ pairs. push ( ( CFString :: wrap_under_get_rule ( kCARendererColorSpace) ,
1431
+ CFType :: wrap_under_get_rule ( color_space. as_ptr ( ) as * const _ as * const _ ) ) )
1432
+ }
1433
+
1434
+ let options: CFDictionary < CFString , CFType > = CFDictionary :: from_CFType_pairs ( & pairs) ;
1435
+
1436
+ let renderer: id =
1437
+ msg_send ! [ class!( CARenderer ) , rendererWithMTLTexture: metal_texture
1438
+ options: options. as_CFTypeRef( ) ] ;
1439
+ debug_assert ! ( renderer != nil) ;
1440
+ CARenderer ( renderer)
1441
+ }
1442
+
1443
+ #[ inline]
1444
+ pub fn layer ( & self ) -> Option < CALayer > {
1445
+ unsafe {
1446
+ let layer: id = msg_send ! [ self . id( ) , layer] ;
1447
+ if layer. is_null ( ) {
1448
+ None
1449
+ } else {
1450
+ Some ( CALayer ( layer) )
1451
+ }
1452
+ }
1453
+ }
1454
+
1455
+ #[ inline]
1456
+ pub fn set_layer ( & self , layer : Option < CALayer > ) {
1457
+ unsafe {
1458
+ let layer = match layer {
1459
+ Some ( ref layer) => layer. id ( ) ,
1460
+ None => nil,
1461
+ } ;
1462
+ msg_send ! [ self . id( ) , setLayer: layer] ;
1463
+ }
1464
+ }
1465
+
1466
+ #[ inline]
1467
+ pub fn bounds ( & self ) -> CGRect {
1468
+ unsafe {
1469
+ msg_send ! [ self . id( ) , bounds]
1470
+ }
1471
+ }
1472
+
1473
+ #[ inline]
1474
+ pub fn set_bounds ( & self , bounds : CGRect ) {
1475
+ unsafe {
1476
+ msg_send ! [ self . id( ) , setBounds: bounds]
1477
+ }
1478
+ }
1479
+
1480
+ #[ inline]
1481
+ pub fn begin_frame_at ( & self , time : CFTimeInterval , timestamp : Option < & CVTimeStamp > ) {
1482
+ unsafe {
1483
+ msg_send ! [ self . id( ) , beginFrameAtTime: time timeStamp: timestamp]
1484
+ }
1485
+ }
1486
+
1487
+ #[ inline]
1488
+ pub fn update_bounds ( & self ) -> CGRect {
1489
+ unsafe {
1490
+ msg_send ! [ self . id( ) , updateBounds]
1491
+ }
1492
+ }
1493
+
1494
+ #[ inline]
1495
+ pub fn add_update_rect ( & self , rect : CGRect ) {
1496
+ unsafe {
1497
+ msg_send ! [ self . id( ) , addUpdateRect: rect]
1498
+ }
1499
+ }
1500
+
1501
+ #[ inline]
1502
+ pub fn render ( & self ) {
1503
+ unsafe {
1504
+ msg_send ! [ self . id( ) , render]
1505
+ }
1506
+ }
1507
+
1508
+ #[ inline]
1509
+ pub fn next_frame_time ( & self ) -> CFTimeInterval {
1510
+ unsafe {
1511
+ msg_send ! [ self . id( ) , nextFrameTime]
1512
+ }
1513
+ }
1514
+
1515
+ #[ inline]
1516
+ pub fn end_frame ( & self ) {
1517
+ unsafe {
1518
+ msg_send ! [ self . id( ) , endFrame]
1519
+ }
1520
+ }
1521
+
1522
+ #[ inline]
1523
+ pub unsafe fn set_destination ( & self , metal_texture : id ) {
1524
+ msg_send ! [ self . id( ) , setDestination: metal_texture]
1525
+ }
1526
+ }
1527
+
1359
1528
// CATransaction.h
1360
1529
1361
1530
// You can't actually construct any `CATransaction` objects, so that class is
1362
1531
// really just a module.
1363
1532
pub mod transaction {
1533
+ use block:: { Block , ConcreteBlock , IntoConcreteBlock , RcBlock } ;
1364
1534
use core_foundation:: date:: CFTimeInterval ;
1365
1535
use core_foundation:: string:: CFString ;
1366
1536
@@ -1442,8 +1612,27 @@ pub mod transaction {
1442
1612
}
1443
1613
}
1444
1614
1445
- // Omitted: `completionBlock`; depends on blocks.
1446
- // Omitted: `setCompletionBlock:`; depends on blocks.
1615
+ #[ inline]
1616
+ pub fn completion_block ( ) -> Option < RcBlock < ( ) , ( ) > > {
1617
+ unsafe {
1618
+ let completion_block: * mut Block < ( ) , ( ) > =
1619
+ msg_send ! [ class!( CATransaction ) , completionBlock] ;
1620
+ if completion_block. is_null ( ) {
1621
+ None
1622
+ } else {
1623
+ Some ( RcBlock :: new ( completion_block) )
1624
+ }
1625
+ }
1626
+ }
1627
+
1628
+ #[ inline]
1629
+ pub fn set_completion_block < F > ( block : ConcreteBlock < ( ) , ( ) , F > )
1630
+ where F : ' static + IntoConcreteBlock < ( ) , Ret = ( ) > {
1631
+ unsafe {
1632
+ let block = block. copy ( ) ;
1633
+ msg_send ! [ class!( CATransaction ) , setCompletionBlock: & * block]
1634
+ }
1635
+ }
1447
1636
1448
1637
#[ inline]
1449
1638
pub fn value_for_key ( key : & str ) -> id {
@@ -1581,6 +1770,11 @@ impl CATransform3D {
1581
1770
1582
1771
#[ link( name = "QuartzCore" , kind = "framework" ) ]
1583
1772
extern {
1773
+ static kCARendererColorSpace: CFStringRef ;
1774
+ static kCARendererMetalCommandQueue: CFStringRef ;
1775
+
1776
+ fn CACurrentMediaTime ( ) -> CFTimeInterval ;
1777
+
1584
1778
fn CATransform3DIsIdentity ( t : CATransform3D ) -> bool ;
1585
1779
fn CATransform3DEqualToTransform ( a : CATransform3D , b : CATransform3D ) -> bool ;
1586
1780
fn CATransform3DMakeTranslation ( tx : CGFloat , ty : CGFloat , tz : CGFloat ) -> CATransform3D ;
@@ -1599,3 +1793,67 @@ extern {
1599
1793
fn CATransform3DIsAffine ( t : CATransform3D ) -> bool ;
1600
1794
fn CATransform3DGetAffineTransform ( t : CATransform3D ) -> CGAffineTransform ;
1601
1795
}
1796
+
1797
+ // Miscellaneous structures in other frameworks.
1798
+ //
1799
+ // These should be moved elsewhere eventually.
1800
+
1801
+ // CoreVideo/CVBase.h
1802
+
1803
+ #[ repr( C ) ]
1804
+ #[ derive( Clone , Copy ) ]
1805
+ pub struct CVTimeStamp {
1806
+ pub version : u32 ,
1807
+ pub videoTimeScale : i32 ,
1808
+ pub videoTime : i64 ,
1809
+ pub hostTime : u64 ,
1810
+ pub rateScalar : f64 ,
1811
+ pub videoRefreshPeriod : i64 ,
1812
+ pub smpteTime : CVSMPTETime ,
1813
+ pub flags : u64 ,
1814
+ pub reserved : u64 ,
1815
+ }
1816
+
1817
+ pub type CVTimeStampFlags = u64 ;
1818
+
1819
+ pub const kCVTimeStampVideoTimeValid: CVTimeStampFlags = 1 << 0 ;
1820
+ pub const kCVTimeStampHostTimeValid: CVTimeStampFlags = 1 << 1 ;
1821
+ pub const kCVTimeStampSMPTETimeValid: CVTimeStampFlags = 1 << 2 ;
1822
+ pub const kCVTimeStampVideoRefreshPeriodValid: CVTimeStampFlags = 1 << 3 ;
1823
+ pub const kCVTimeStampRateScalarValid: CVTimeStampFlags = 1 << 4 ;
1824
+ pub const kCVTimeStampTopField: CVTimeStampFlags = 1 << 16 ;
1825
+ pub const kCVTimeStampBottomField: CVTimeStampFlags = 1 << 17 ;
1826
+ pub const kCVTimeStampVideoHostTimeValid: CVTimeStampFlags =
1827
+ kCVTimeStampVideoTimeValid | kCVTimeStampHostTimeValid;
1828
+ pub const kCVTimeStampIsInterlaced: CVTimeStampFlags =
1829
+ kCVTimeStampTopField | kCVTimeStampBottomField;
1830
+
1831
+ #[ repr( C ) ]
1832
+ #[ derive( Clone , Copy ) ]
1833
+ pub struct CVSMPTETime {
1834
+ pub subframes : i16 ,
1835
+ pub subframeDivisor : i16 ,
1836
+ pub counter : u32 ,
1837
+ pub time_type : u32 ,
1838
+ pub flags : u32 ,
1839
+ pub hours : i16 ,
1840
+ pub minutes : i16 ,
1841
+ pub seconds : i16 ,
1842
+ pub frames : i16 ,
1843
+ }
1844
+
1845
+ pub type CVSMPTETimeType = u32 ;
1846
+
1847
+ pub const kCVSMPTETimeType24: CVSMPTETimeType = 0 ;
1848
+ pub const kCVSMPTETimeType25: CVSMPTETimeType = 1 ;
1849
+ pub const kCVSMPTETimeType30Drop: CVSMPTETimeType = 2 ;
1850
+ pub const kCVSMPTETimeType30: CVSMPTETimeType = 3 ;
1851
+ pub const kCVSMPTETimeType2997: CVSMPTETimeType = 4 ;
1852
+ pub const kCVSMPTETimeType2997Drop: CVSMPTETimeType = 5 ;
1853
+ pub const kCVSMPTETimeType60: CVSMPTETimeType = 6 ;
1854
+ pub const kCVSMPTETimeType5994: CVSMPTETimeType = 7 ;
1855
+
1856
+ pub type CVSMPTETimeFlags = u32 ;
1857
+
1858
+ pub const kCVSMPTETimeValid: CVSMPTETimeFlags = 1 << 0 ;
1859
+ pub const kCVSMPTETimeRunning: CVSMPTETimeFlags = 1 << 1 ;
0 commit comments