Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Rewrite all the bindings with the new CF bindings #58

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ authors = ["The Servo Project Developers"]
license = "MIT / Apache-2.0"

[dependencies]
libc = "0.2"
core-foundation = "0.2"
serde = "0.8"
core-foundation-sys = {path = "../core-foundation-rs/core-foundation-sys"}
21 changes: 9 additions & 12 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]

use libc;
use std::os::raw;

#[cfg(target_pointer_width = "64")]
pub type CGFloat = f64;
#[cfg(not(target_pointer_width = "64"))]
pub type CGFloat = f32;

#[cfg(any(target_arch = "x86",
target_arch = "arm",
target_arch = "aarch64"))]
pub type boolean_t = libc::c_int;
pub type boolean_t = raw::c_int;
#[cfg(target_arch = "x86_64")]
pub type boolean_t = libc::c_uint;

#[cfg(target_pointer_width = "64")]
pub type CGFloat = libc::c_double;
#[cfg(not(target_pointer_width = "64"))]
pub type CGFloat = libc::c_float;
pub type boolean_t = raw::c_uint;

pub type CGError = libc::int32_t;

pub type CGAffineTransform = ();
pub type CGError = i32;

pub const kCGImageAlphaNone: u32 = 0;
pub const kCGImageAlphaPremultipliedLast: u32 = 1;
Expand All @@ -37,4 +35,3 @@ pub const kCGImageAlphaLast: u32 = 3;
pub const kCGImageAlphaFirst: u32 = 4;
pub const kCGImageAlphaNoneSkipLast: u32 = 5;
pub const kCGImageAlphaNoneSkipFirst: u32 = 6;

75 changes: 17 additions & 58 deletions src/color_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,39 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use core_foundation::base::{CFRelease, CFRetain, CFTypeID, CFTypeRef, TCFType};
use std::mem;
use core_foundation_sys::base::{CFDowncast, CFObject, CFType, CFTypeID};
use core_foundation_sys::sync::{CFRef, CFShared};

#[repr(C)]
pub struct __CGColorSpace;

pub type CGColorSpaceRef = *const __CGColorSpace;

pub struct CGColorSpace {
obj: CGColorSpaceRef,
}
pub type CGColorSpaceRef = CFRef<CGColorSpace>;

impl Drop for CGColorSpace {
fn drop(&mut self) {
unsafe {
CFRelease(self.as_CFTypeRef())
}
}
}

impl Clone for CGColorSpace {
fn clone(&self) -> CGColorSpace {
unsafe {
TCFType::wrap_under_get_rule(self.as_concrete_TypeRef())
}
}
}

impl TCFType<CGColorSpaceRef> for CGColorSpace {
#[inline]
fn as_concrete_TypeRef(&self) -> CGColorSpaceRef {
self.obj
}

#[inline]
unsafe fn wrap_under_get_rule(reference: CGColorSpaceRef) -> CGColorSpace {
let reference: CGColorSpaceRef = mem::transmute(CFRetain(mem::transmute(reference)));
TCFType::wrap_under_create_rule(reference)
}
#[repr(C)]
pub struct CGColorSpace { obj: CFObject }

#[inline]
fn as_CFTypeRef(&self) -> CFTypeRef {
unsafe {
mem::transmute(self.as_concrete_TypeRef())
}
}
unsafe impl Send for CGColorSpace {}
unsafe impl Sync for CGColorSpace {}

unsafe impl CFType for CGColorSpace {
#[inline]
unsafe fn wrap_under_create_rule(obj: CGColorSpaceRef) -> CGColorSpace {
CGColorSpace {
obj: obj,
}
fn as_object(&self) -> &CFObject {
&self.obj
}
}

unsafe impl CFDowncast for CGColorSpace {
#[inline]
fn type_id() -> CFTypeID {
unsafe {
CGColorSpaceGetTypeID()
}
unsafe { CGColorSpaceGetTypeID() }
}
}

impl CGColorSpace {
pub fn create_device_rgb() -> CGColorSpace {
unsafe {
let result = CGColorSpaceCreateDeviceRGB();
TCFType::wrap_under_create_rule(result)
}
#[inline]
pub fn new_device_rgb() -> CGColorSpaceRef {
unsafe { CFRef::from_retained(CGColorSpaceCreateDeviceRGB()) }
}
}

#[link(name = "ApplicationServices", kind = "framework")]
extern {
fn CGColorSpaceCreateDeviceRGB() -> CGColorSpaceRef;
fn CGColorSpaceCreateDeviceRGB() -> *const CFShared<CGColorSpace>;
fn CGColorSpaceGetTypeID() -> CFTypeID;
}

179 changes: 0 additions & 179 deletions src/context.rs

This file was deleted.

Loading