This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #50 - pcwalton:regions, r=metajack
Add some bindings to the private `CGSRegion` APIs. These enable us to tell the window server about the opaque regions of the window so that it can perform occlusion culling. See https://github.com/NUIKit/CGSInternal/blob/master/CGSRegion.h r? @metajack <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-graphics-rs/50) <!-- Reviewable:end -->
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ pub mod data_provider; | |
pub mod display; | ||
pub mod font; | ||
pub mod geometry; | ||
pub mod private; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2016 The Servo Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! Evil private APIs. | ||
//! | ||
//! These are liable to change at any time. Use with caution! | ||
use geometry::CGRect; | ||
use std::ptr; | ||
|
||
pub struct CGSRegion { | ||
region: ffi::CGSRegion, | ||
} | ||
|
||
impl Drop for CGSRegion { | ||
fn drop(&mut self) { | ||
unsafe { | ||
ffi::CGSRegionRelease(self.region) | ||
} | ||
} | ||
} | ||
|
||
impl CGSRegion { | ||
#[inline] | ||
pub fn from_rect(rect: &CGRect) -> CGSRegion { | ||
unsafe { | ||
let mut region = ptr::null_mut(); | ||
assert!(ffi::CGSNewRegionWithRect(rect, &mut region) == 0); | ||
CGSRegion { | ||
region: region, | ||
} | ||
} | ||
} | ||
} | ||
|
||
mod ffi { | ||
use geometry::CGRect; | ||
|
||
// This is an enum so that we can't easily make instances of this opaque type. | ||
enum CGSRegionObject {} | ||
|
||
pub type CGSRegion = *mut CGSRegionObject; | ||
pub type OSStatus = i32; | ||
|
||
#[link(name = "ApplicationServices", kind = "framework")] | ||
extern { | ||
pub fn CGSRegionRelease(region: CGSRegion); | ||
pub fn CGSNewRegionWithRect(rect: *const CGRect, region: *mut CGSRegion) -> OSStatus; | ||
} | ||
} | ||
|