aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatrick kim <ksh8281@gmail.com>2013-12-03 20:02:22 +0900
committerpatrick kim <ksh8281@gmail.com>2013-12-07 09:48:19 +0900
commitc60ab361a5a74b91c6a236674df2a1f82d9aa2ea (patch)
treebfb7e2ba6c9a49223f88c69eac290bb6358987f4
parentdda6d2b53c8a4822612af7c88214cbdde1f2a34b (diff)
downloadservo-c60ab361a5a74b91c6a236674df2a1f82d9aa2ea.tar.gz
servo-c60ab361a5a74b91c6a236674df2a1f82d9aa2ea.zip
remove @ from FontContextHandle in linux
-rw-r--r--src/components/gfx/platform/linux/font.rs7
-rw-r--r--src/components/gfx/platform/linux/font_context.rs52
2 files changed, 42 insertions, 17 deletions
diff --git a/src/components/gfx/platform/linux/font.rs b/src/components/gfx/platform/linux/font.rs
index 29e81ddaaee..04b288ee8c9 100644
--- a/src/components/gfx/platform/linux/font.rs
+++ b/src/components/gfx/platform/linux/font.rs
@@ -8,6 +8,7 @@ use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods};
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
use font::{FontWeight700, FontWeight800, FontWeight900};
+use font_context::FontContextHandleMethods;
use servo_util::geometry::Au;
use servo_util::geometry;
use platform::font_context::FontContextHandle;
@@ -93,7 +94,7 @@ impl FontHandleMethods for FontHandle {
let handle = FontHandle {
face: face,
source: FontSourceMem(buf),
- handle: *fctx
+ handle: fctx.clone()
};
Ok(handle)
}
@@ -295,7 +296,7 @@ impl<'self> FontHandle {
Ok(FontHandle {
source: FontSourceFile(file.to_str()),
face: face,
- handle: *fctx
+ handle: fctx.clone()
})
} else {
Err(())
@@ -323,7 +324,7 @@ impl<'self> FontHandle {
Ok(FontHandle {
source: FontSourceFile(file),
face: face,
- handle: *fctx
+ handle: fctx.clone()
})
}
}
diff --git a/src/components/gfx/platform/linux/font_context.rs b/src/components/gfx/platform/linux/font_context.rs
index 313082309d5..eee240cfc78 100644
--- a/src/components/gfx/platform/linux/font_context.rs
+++ b/src/components/gfx/platform/linux/font_context.rs
@@ -12,34 +12,53 @@ use freetype::freetype::{FT_Done_FreeType, FT_Init_FreeType};
use std::ptr;
+#[deriving(Clone)]
struct FreeTypeLibraryHandle {
ctx: FT_Library,
}
-impl Drop for FreeTypeLibraryHandle {
+// FIXME(ksh8281) this value have to use atomic operation for counting ref
+static mut font_context_ref_count: uint = 0;
+static mut ft_pointer: Option<FT_Library> = None;
+pub struct FontContextHandle {
+ ctx: FreeTypeLibraryHandle,
+}
+
+impl Drop for FontContextHandle {
#[fixed_stack_segment]
fn drop(&mut self) {
- assert!(self.ctx.is_not_null());
+ assert!(self.ctx.ctx.is_not_null());
unsafe {
- FT_Done_FreeType(self.ctx);
+ 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);
+ }
}
}
}
-pub struct FontContextHandle {
- ctx: @FreeTypeLibraryHandle,
-}
-
impl FontContextHandle {
#[fixed_stack_segment]
pub fn new() -> FontContextHandle {
unsafe {
- let ctx: FT_Library = ptr::null();
- let result = FT_Init_FreeType(ptr::to_unsafe_ptr(&ctx));
- if !result.succeeded() { fail!(); }
-
- FontContextHandle {
- ctx: @FreeTypeLibraryHandle { ctx: ctx },
+ 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 result = FT_Init_FreeType(ptr::to_unsafe_ptr(&ctx));
+ if !result.succeeded() { fail!(); }
+ ft_pointer = Some(ctx);
+ font_context_ref_count = font_context_ref_count + 1;
+ FontContextHandle {
+ ctx: FreeTypeLibraryHandle { ctx: ctx },
+ }
+ }
}
}
}
@@ -47,7 +66,12 @@ impl FontContextHandle {
impl FontContextHandleMethods for 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)