remove @ from FontContextHandle in linux

This commit is contained in:
patrick kim 2013-12-03 20:02:22 +09:00
parent dda6d2b53c
commit c60ab361a5
2 changed files with 45 additions and 20 deletions

View file

@ -8,6 +8,7 @@ use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods};
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100}; use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600}; use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
use font::{FontWeight700, FontWeight800, FontWeight900}; use font::{FontWeight700, FontWeight800, FontWeight900};
use font_context::FontContextHandleMethods;
use servo_util::geometry::Au; use servo_util::geometry::Au;
use servo_util::geometry; use servo_util::geometry;
use platform::font_context::FontContextHandle; use platform::font_context::FontContextHandle;
@ -93,7 +94,7 @@ impl FontHandleMethods for FontHandle {
let handle = FontHandle { let handle = FontHandle {
face: face, face: face,
source: FontSourceMem(buf), source: FontSourceMem(buf),
handle: *fctx handle: fctx.clone()
}; };
Ok(handle) Ok(handle)
} }
@ -295,7 +296,7 @@ impl<'self> FontHandle {
Ok(FontHandle { Ok(FontHandle {
source: FontSourceFile(file.to_str()), source: FontSourceFile(file.to_str()),
face: face, face: face,
handle: *fctx handle: fctx.clone()
}) })
} else { } else {
Err(()) Err(())
@ -323,7 +324,7 @@ impl<'self> FontHandle {
Ok(FontHandle { Ok(FontHandle {
source: FontSourceFile(file), source: FontSourceFile(file),
face: face, face: face,
handle: *fctx handle: fctx.clone()
}) })
} }
} }

View file

@ -12,34 +12,53 @@ use freetype::freetype::{FT_Done_FreeType, FT_Init_FreeType};
use std::ptr; use std::ptr;
#[deriving(Clone)]
struct FreeTypeLibraryHandle { struct FreeTypeLibraryHandle {
ctx: FT_Library, ctx: FT_Library,
} }
impl Drop for FreeTypeLibraryHandle { // FIXME(ksh8281) this value have to use atomic operation for counting ref
#[fixed_stack_segment] static mut font_context_ref_count: uint = 0;
fn drop(&mut self) { static mut ft_pointer: Option<FT_Library> = None;
assert!(self.ctx.is_not_null()); pub struct FontContextHandle {
unsafe { ctx: FreeTypeLibraryHandle,
FT_Done_FreeType(self.ctx);
}
}
} }
pub struct FontContextHandle { impl Drop for FontContextHandle {
ctx: @FreeTypeLibraryHandle, #[fixed_stack_segment]
fn drop(&mut self) {
assert!(self.ctx.ctx.is_not_null());
unsafe {
assert!(font_context_ref_count >= 1);
font_context_ref_count = font_context_ref_count - 1;
if font_context_ref_count == 0 {
FT_Done_FreeType(self.ctx.ctx);
}
}
}
} }
impl FontContextHandle { impl FontContextHandle {
#[fixed_stack_segment] #[fixed_stack_segment]
pub fn new() -> FontContextHandle { pub fn new() -> FontContextHandle {
unsafe { unsafe {
match ft_pointer {
Some(ref ctx) => {
font_context_ref_count = font_context_ref_count + 1;
FontContextHandle {
ctx: FreeTypeLibraryHandle { ctx: ctx.clone() },
}
},
None => {
let ctx: FT_Library = ptr::null(); let ctx: FT_Library = ptr::null();
let result = FT_Init_FreeType(ptr::to_unsafe_ptr(&ctx)); let result = FT_Init_FreeType(ptr::to_unsafe_ptr(&ctx));
if !result.succeeded() { fail!(); } if !result.succeeded() { fail!(); }
ft_pointer = Some(ctx);
font_context_ref_count = font_context_ref_count + 1;
FontContextHandle { FontContextHandle {
ctx: @FreeTypeLibraryHandle { ctx: ctx }, ctx: FreeTypeLibraryHandle { ctx: ctx },
}
}
} }
} }
} }
@ -47,7 +66,12 @@ impl FontContextHandle {
impl FontContextHandleMethods for FontContextHandle { impl FontContextHandleMethods for FontContextHandle {
fn clone(&self) -> FontContextHandle { fn clone(&self) -> FontContextHandle {
FontContextHandle { ctx: self.ctx } unsafe {
font_context_ref_count = font_context_ref_count + 1;
FontContextHandle{
ctx: self.ctx.clone()
}
}
} }
fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle) fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle)