Skip to content

Commit

Permalink
auto merge of #1445 : webconv/servo/PR_android, r=kmcallister
Browse files Browse the repository at this point in the history
1. We've aimed to android 4.3 Jellybean devices like Galaxy 10.1 and Galaxy Nexus, etc. I think it could still support android 4.1
2. Needs android ndk r9(not r9b) and latest android sdk
3. Needs some device list update on sdk for apk build.
4. Currently we can not build android port on mac because compiler build problem like rust-lang/rust#10921. Hopefully I expect that it could be resolved at next rust upgrade.
  • Loading branch information
bors-servo committed Jan 3, 2014
2 parents da14203 + f2f9084 commit 90f4473
Show file tree
Hide file tree
Showing 19 changed files with 173 additions and 93 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Expand Up @@ -110,3 +110,9 @@
path = src/support/encoding/rust-encoding
url = https://github.com/mozilla-servo/rust-encoding.git
branch = rust-servo
[submodule "src/support/egl/rust-egl"]
path = src/support/egl/rust-egl
url = https://github.com/webconvforge/rust-egl.git
[submodule "src/platform/android/servo-android-glue"]
path = src/platform/android/servo-android-glue
url = https://github.com/webconvforge/servo-android-glue.git
25 changes: 20 additions & 5 deletions Makefile.in
Expand Up @@ -55,10 +55,6 @@ export CFG_ENABLE_DEBUG
export CFG_ENABLE_DEBUG_SKIA
export RUSTC=$(CFG_RUSTC)
export RUSTFLAGS=$(CFG_RUSTC_FLAGS)
export CC=$(CFG_CC)
export CXX=$(CFG_CXX)
export LD=$(CFG_LD)
export AR=$(CFG_AR)
export RANLIB=$(CFG_RANLIB)
export PYTHON=$(CFG_PYTHON2)
export PATH=$(CFG_PATH)
Expand Down Expand Up @@ -95,7 +91,7 @@ $(S)config.stamp : $(S)configure $(S)Makefile.in
ifneq ($(CFG_LOCAL_RUSTC),1)
$(CFG_RUSTC): $(B)src/compiler/rust/rust-auto-clean-stamp
@$(call E, building rustc)
$(Q)CFG_RUSTC_FLAGS= CFG_ENABLE_DEBUG= RUSTFLAGS= $(MAKE) -C "$(CFG_BUILD_DIR)src/compiler/rust" CC=gcc CXX=g++ LD=ld AR=ar
$(Q)CFG_RUSTC_FLAGS= CFG_ENABLE_DEBUG= RUSTFLAGS= $(MAKE) -C "$(CFG_BUILD_DIR)src/compiler/rust"

clean-rust:
@$(call E, cleaning rustc)
Expand Down Expand Up @@ -180,6 +176,11 @@ endif

$(eval $(call DEF_SUBMODULE_DEPS,$(1)))

CROSS_COMPILER_CC = CC=$(CFG_CC)
CROSS_COMPILER_CXX = CXX=$(CFG_CXX)
CROSS_COMPILER_LD = LD=$(CFG_LD)
CROSS_COMPILER_AR = AR=$(CFG_AR)

$$(DONE_$(1)) : $$(DONE_DEPS_$(1)) $$(ROUGH_DEPS_$(1)) $$(RUSTC_DEP_$(1))
# @$$(call E, make: $(1))
# @$$(call E, $(1) deps= $$(DEPS_$(1)))
Expand All @@ -191,6 +192,10 @@ $$(DONE_$(1)) : $$(DONE_DEPS_$(1)) $$(ROUGH_DEPS_$(1)) $$(RUSTC_DEP_$(1))
$$(ENV_CFLAGS_$(1)) \
$$(ENV_CXXFLAGS_$(1)) \
$$(ENV_RFLAGS_$(1)) \
$$(CROSS_COMPILER_CC) \
$$(CROSS_COMPILER_CXX) \
$$(CROSS_COMPILER_LD) \
$$(CROSS_COMPILER_AR) \
$$(MAKE) -C $$(B)src/$$(PATH_$(1)) && touch $$(DONE_$(1))

# main submodule target
Expand Down Expand Up @@ -338,6 +343,16 @@ package: servo
cp $(B)src/platform/macos/rust-cocoa/lib*.dylib Servo.app/Contents/MacOS/src/platform/macos/rust-cocoa/
cp $(B)src/support/azure/rust-azure/lib*.dylib Servo.app/Contents/MacOS/src/support/azure/rust-azure/

else ifeq ($(CFG_OSTYPE),linux-androideabi)
package: servo
mkdir -p sofile
-exec cp -f {} $(CFG_BUILD_HOME)sofile \;
find . ! \( \( -type d -path './sofile' -o -path './$(CFG_TARGET_TRIPLES)/src/compiler/rust' \) -prune \) -name '*.so' -type f | xargs cp -f -t $(CFG_BUILD_HOME)sofile
find $(CFG_RUST_HOME)/lib/rustc/$(CFG_TARGET_TRIPLES)/lib/ -name '*.so' -type f -size +1c | xargs cp -f -t $(CFG_BUILD_HOME)sofile
cd $(S)src/platform/android/servo-android-glue && make with-libs
cd $(CFG_BUILD_HOME)
cp $(S)src/platform/android/servo-android-glue/bin/ServoAndroid-debug.apk -t $(CFG_BUILD_HOME)

else

bindings: $(AUTOGEN_SRC_script)
Expand Down
3 changes: 2 additions & 1 deletion configure
Expand Up @@ -374,7 +374,7 @@ probe_need CFG_AUTOCONF213 autoconf213 \
step_msg "looking for build programs"
case ${TARGET_OSTYPE} in
android)
CFG_PATH="${CFG_ANDROID_CROSS_PATH}/bin":$PATH
CFG_PATH=$PATH:"${CFG_ANDROID_CROSS_PATH}/bin"
OLD_PATH=$PATH
export PATH=${CFG_PATH}

Expand Down Expand Up @@ -535,6 +535,7 @@ if [ $CFG_OSTYPE = "linux-androideabi" ]
then
CFG_SUBMODULES="\
support/glut/rust-glut \
support/egl/rust-egl \
platform/android/libexpat \
platform/android/libfreetype2 \
platform/android/fontconfig \
Expand Down
2 changes: 2 additions & 0 deletions mk/sub.mk
Expand Up @@ -171,6 +171,7 @@ endif

ifeq ($(CFG_OSTYPE),linux-androideabi)
DEPS_rust-azure += \
rust-egl \
rust-freetype \
rust-fontconfig \
fontconfig \
Expand All @@ -181,6 +182,7 @@ DEPS_rust-azure += \

# See note at top of file
DEPS_rust-layers += \
rust-egl \
rust-freetype \
rust-fontconfig \
rust-xlib \
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/rust
Submodule rust updated from 67d7be to f6b236
2 changes: 1 addition & 1 deletion src/compiler/rust-auto-clean-trigger
@@ -1,4 +1,4 @@
# If this file is modified, then rust will be forcibly cleaned and then rebuilt.
# The actual contents of this file do not matter, but to trigger a change on the
# build bots then the contents should be changed so git updates the mtime.
2013-10-31
2014-01-02
58 changes: 28 additions & 30 deletions src/components/gfx/platform/android/font.rs
Expand Up @@ -28,11 +28,11 @@ use std::cast;
use std::ptr;
use std::str;

fn float_to_fixed_ft(f: float) -> i32 {
fn float_to_fixed_ft(f: f64) -> i32 {
float_to_fixed(6, f)
}

fn fixed_to_float_ft(f: i32) -> float {
fn fixed_to_float_ft(f: i32) -> f64 {
fixed_to_float(6, f)
}

Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct FontHandle {
#[unsafe_destructor]
impl Drop for FontHandle {
#[fixed_stack_segment]
fn drop(&self) {
fn drop(&mut self) {
assert!(self.face.is_not_null());
unsafe {
if !FT_Done_Face(self.face).succeeded() {
Expand All @@ -77,7 +77,7 @@ impl FontHandleMethods for FontHandle {
buf: ~[u8],
style: &SpecifiedFontStyle)
-> Result<FontHandle, ()> {
let ft_ctx: FT_Library = fctx.ctx.ctx;
let ft_ctx: FT_Library = fctx.ctx.borrow().ctx;
if ft_ctx.is_null() { return Err(()); }

let face_result = do buf.as_imm_buf |bytes: *u8, len: uint| {
Expand All @@ -92,18 +92,16 @@ impl FontHandleMethods for FontHandle {
let handle = FontHandle {
face: face,
source: FontSourceMem(buf),
handle: *fctx
handle: fctx.clone()
};
Ok(handle)
}
Err(()) => Err(())
};

#[fixed_stack_segment]
fn create_face_from_buffer(lib: FT_Library,
cbuf: *u8, cbuflen: uint, pt_size: float)
-> Result<FT_Face, ()> {

fn create_face_from_buffer(lib: FT_Library, cbuf: *u8, cbuflen: uint, pt_size: f64)
-> Result<FT_Face, ()> {
unsafe {
let mut face: FT_Face = ptr::null();
let face_index = 0 as FT_Long;
Expand Down Expand Up @@ -206,7 +204,7 @@ impl FontHandleMethods for FontHandle {
let void_glyph = (*self.face).glyph;
let slot: FT_GlyphSlot = cast::transmute(void_glyph);
assert!(slot.is_not_null());
debug!("metrics: {}", (*slot).metrics);
debug!("metrics: {:?}", (*slot).metrics);
let advance = (*slot).metrics.horiAdvance;
debug!("h_advance for {} is {}", glyph, advance);
let advance = advance as i32;
Expand All @@ -223,20 +221,20 @@ impl FontHandleMethods for FontHandle {
/* TODO(Issue #76): complete me */
let face = self.get_face_rec();

let underline_size = self.font_units_to_au(face.underline_thickness as float);
let underline_offset = self.font_units_to_au(face.underline_position as float);
let em_size = self.font_units_to_au(face.units_per_EM as float);
let ascent = self.font_units_to_au(face.ascender as float);
let descent = self.font_units_to_au(face.descender as float);
let max_advance = self.font_units_to_au(face.max_advance_width as float);
let underline_size = self.font_units_to_au(face.underline_thickness as f64);
let underline_offset = self.font_units_to_au(face.underline_position as f64);
let em_size = self.font_units_to_au(face.units_per_EM as f64);
let ascent = self.font_units_to_au(face.ascender as f64);
let descent = self.font_units_to_au(face.descender as f64);
let max_advance = self.font_units_to_au(face.max_advance_width as f64);

// 'leading' is supposed to be the vertical distance between two baselines,
// reflected by the height attibute in freetype. On OS X (w/ CTFont),
// leading represents the distance between the bottom of a line descent to
// the top of the next line's ascent or: (line_height - ascent - descent),
// see http://stackoverflow.com/a/5635981 for CTFont implementation.
// Convert using a formular similar to what CTFont returns for consistency.
let height = self.font_units_to_au(face.height as float);
let height = self.font_units_to_au(face.height as f64);
let leading = height - (ascent + descent);

let mut strikeout_size = geometry::from_pt(0.0);
Expand All @@ -246,9 +244,9 @@ impl FontHandleMethods for FontHandle {
let os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2) as *TT_OS2;
let valid = os2.is_not_null() && (*os2).version != 0xffff;
if valid {
strikeout_size = self.font_units_to_au((*os2).yStrikeoutSize as float);
strikeout_offset = self.font_units_to_au((*os2).yStrikeoutPosition as float);
x_height = self.font_units_to_au((*os2).sxHeight as float);
strikeout_size = self.font_units_to_au((*os2).yStrikeoutSize as f64);
strikeout_offset = self.font_units_to_au((*os2).yStrikeoutPosition as f64);
x_height = self.font_units_to_au((*os2).sxHeight as f64);
}
}

Expand Down Expand Up @@ -276,7 +274,7 @@ impl FontHandleMethods for FontHandle {

impl<'self> FontHandle {
#[fixed_stack_segment]
fn set_char_size(face: FT_Face, pt_size: float) -> Result<(), ()>{
fn set_char_size(face: FT_Face, pt_size: f64) -> Result<(), ()>{
let char_width = float_to_fixed_ft(pt_size) as FT_F26Dot6;
let char_height = float_to_fixed_ft(pt_size) as FT_F26Dot6;
let h_dpi = 72;
Expand All @@ -289,10 +287,10 @@ impl<'self> FontHandle {
}

#[fixed_stack_segment]
pub fn new_from_file(fctx: &FontContextHandle, file: ~str,
pub fn new_from_file(fctx: &FontContextHandle, file: &str,
style: &SpecifiedFontStyle) -> Result<FontHandle, ()> {
unsafe {
let ft_ctx: FT_Library = fctx.ctx.ctx;
let ft_ctx: FT_Library = fctx.ctx.borrow().ctx;
if ft_ctx.is_null() { return Err(()); }

let mut face: FT_Face = ptr::null();
Expand All @@ -306,9 +304,9 @@ impl<'self> FontHandle {
}
if FontHandle::set_char_size(face, style.pt_size).is_ok() {
Ok(FontHandle {
source: FontSourceFile(file),
source: FontSourceFile(file.to_str()),
face: face,
handle: *fctx
handle: fctx.clone()
})
} else {
Err(())
Expand All @@ -320,7 +318,7 @@ impl<'self> FontHandle {
pub fn new_from_file_unstyled(fctx: &FontContextHandle, file: ~str)
-> Result<FontHandle, ()> {
unsafe {
let ft_ctx: FT_Library = fctx.ctx.ctx;
let ft_ctx: FT_Library = fctx.ctx.borrow().ctx;
if ft_ctx.is_null() { return Err(()); }

let mut face: FT_Face = ptr::null();
Expand All @@ -336,7 +334,7 @@ impl<'self> FontHandle {
Ok(FontHandle {
source: FontSourceFile(file),
face: face,
handle: *fctx
handle: fctx.clone()
})
}
}
Expand All @@ -347,16 +345,16 @@ impl<'self> FontHandle {
}
}

fn font_units_to_au(&self, value: float) -> Au {
fn font_units_to_au(&self, value: f64) -> Au {
let face = self.get_face_rec();

// face.size is a *c_void in the bindings, presumably to avoid
// recursive structural types
let size: &FT_SizeRec = unsafe { cast::transmute(&(*face.size)) };
let metrics: &FT_Size_Metrics = &(*size).metrics;

let em_size = face.units_per_EM as float;
let x_scale = (metrics.x_ppem as float) / em_size as float;
let em_size = face.units_per_EM as f64;
let x_scale = (metrics.x_ppem as f64) / em_size as f64;

// If this isn't true then we're scaling one of the axes wrong
assert!(metrics.x_ppem == metrics.y_ppem);
Expand Down
34 changes: 15 additions & 19 deletions src/components/gfx/platform/android/font_context.rs
Expand Up @@ -11,51 +11,47 @@ use freetype::freetype::{FTErrorMethods, FT_Library};
use freetype::freetype::{FT_Done_FreeType, FT_Init_FreeType};

use std::ptr;
use std::rc::Rc;

#[deriving(Clone)]
struct FreeTypeLibraryHandle {
ctx: FT_Library,
}

#[deriving(Clone)]
pub struct FontContextHandle {
ctx: Rc<FreeTypeLibraryHandle>,
}

impl Drop for FreeTypeLibraryHandle {
#[fixed_stack_segment]
fn drop(&self) {
fn drop(&mut self) {
assert!(self.ctx.is_not_null());
unsafe {
FT_Done_FreeType(self.ctx);
}
unsafe { FT_Done_FreeType(self.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 },
let result = FT_Init_FreeType(&ctx);
if !result.succeeded() { fail!("Unable to initialize FreeType library"); }
FontContextHandle {
ctx: Rc::new(FreeTypeLibraryHandle { ctx: ctx }),
}
}
}
}

impl FontContextHandleMethods for FontContextHandle {
fn clone(&self) -> FontContextHandle {
FontContextHandle { ctx: self.ctx }
}

fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle)
-> Result<FontHandle, ()> {
debug!("Creating font handle for {:s}", name);
do path_from_identifier(name, &style).chain |file_name| {
do path_from_identifier(name, &style).and_then |file_name| {
debug!("Opening font face {:s}", file_name);
FontHandle::new_from_file(self, file_name, &style)
FontHandle::new_from_file(self, file_name.to_owned(), &style)
}
}
}
Expand Down

0 comments on commit 90f4473

Please sign in to comment.