Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing C libraries with Rust equivalents - student project #4215

Closed
wants to merge 29 commits into from
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c4156d4
Initial commit for migrating to freetype-rs library from rust-freetype
ankit3005 Nov 29, 2014
66623ea
added constant to freetype_rs library ft_sfnt_os2
ankit3005 Nov 29, 2014
ff891d8
Changed freetyp-rs dependency to local fork on github
ankit3005 Nov 29, 2014
754a841
Changes to use DynamicImage type from the new rust image library
anishashetty Nov 30, 2014
254e9c9
fix in Cargo.lock after updating freetype-rs dependency
ankit3005 Nov 30, 2014
552cc7b
Replaced png::Image references with DynamicImage
ynandak Dec 1, 2014
f712870
Small fix in gfx/render_context.rs
ynandak Dec 1, 2014
dbd681a
Replaced certain instances of png::Image use - build successful
ynandak Dec 1, 2014
82d3720
Minor change to render_context.rs::draw_image()
ynandak Dec 2, 2014
61557e5
Added changes to accept ImageFormat
anishashetty Dec 2, 2014
d2d9a99
Changes to fix runtime data.len() assertion crash
ynandak Dec 3, 2014
1a0f513
Minor fix in render_context
ynandak Dec 3, 2014
1bca917
Changes to base.rs to resolve ImageFormat based on file extension
anishashetty Dec 3, 2014
0954f6d
Merge branch 'master' of https://github.com/ankit3005/servo
anishashetty Dec 3, 2014
8ce5e11
Updated RGB in draw_image()
ynandak Dec 3, 2014
169160a
net component compiles with profiler in place
ankit3005 Dec 3, 2014
91f719e
whitespace changes to clean up mach test-tidy
ankit3005 Dec 3, 2014
7f20adc
Minor cleanup. Removed unnecessary line
ankit3005 Dec 3, 2014
4c33555
Changed freetype-rs dependency from fork to upstream repo
ankit3005 Dec 3, 2014
b7b50f8
Changed freetype-rs version to old working commit
ankit3005 Dec 4, 2014
ba24947
Clean up commented code
ankit3005 Dec 4, 2014
3d518cd
Add profiling to image decoding
ankit3005 Dec 4, 2014
d6bb6b4
Code clean up. Removed unused functions and imports
ankit3005 Dec 4, 2014
ad709d6
minor cleanup
ankit3005 Dec 4, 2014
d1aaa2c
Remove a println statement
ankit3005 Dec 4, 2014
dfa0b92
Fixed image rendering. Now working as intended
ynandak Dec 4, 2014
85b5efc
Updated Cargo.lock
ynandak Dec 4, 2014
9e2b0c7
Removed debugging println!
ynandak Dec 4, 2014
768709a
whitespace changes to clean up test-tidy
ankit3005 Dec 4, 2014
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -47,8 +47,9 @@ git = "https://github.com/servo/rust-harfbuzz"
[dependencies.fontconfig]
git = "https://github.com/servo/rust-fontconfig"

[dependencies.freetype]
git = "https://github.com/servo/rust-freetype"
[dependencies.freetype-rs]
git = "https://github.com/PistonDevelopers/freetype-rs"
ver = "753496406098651c83cdaf63db9f75dc42da17c7"

[dependencies.core_foundation]
git = "https://github.com/servo/rust-core-foundation"
@@ -61,4 +62,3 @@ git = "https://github.com/servo/rust-core-text"

[dependencies.script_traits]
path = "../script_traits"

@@ -27,7 +27,7 @@ use libc::uintptr_t;
use render_task::RenderLayer;
use script_traits::UntrustedNodeAddress;
use servo_msg::compositor_msg::LayerId;
use servo_net::image::base::Image;
use servo_net::image::base::DynamicImage;
use servo_util::dlist as servo_dlist;
use servo_util::geometry::{mod, Au};
use servo_util::range::Range;
@@ -447,7 +447,7 @@ pub enum TextOrientation {
#[deriving(Clone)]
pub struct ImageDisplayItem {
pub base: BaseDisplayItem,
pub image: Arc<Box<Image>>,
pub image: Arc<Box<DynamicImage>>,

/// The dimensions to which the image display item should be stretched. If this is smaller than
/// the bounds of this display item, then the image will be repeated in the appropriate
@@ -553,7 +553,6 @@ impl DisplayItem {
bounds.origin.x = bounds.origin.x + x_offset;
bounds.origin.y = bounds.origin.y + y_offset;
bounds.size = image_item.stretch_size;

render_context.draw_image(bounds, image_item.image.clone());

x_offset = x_offset + image_item.stretch_size.width;
@@ -33,6 +33,7 @@ extern crate style;
extern crate sync;
extern crate time;
extern crate url;
extern crate "image" as servo_image;

// Eventually we would like the shaper to be pluggable, as many operating systems have their own
// shapers. For now, however, this is a hard dependency.
@@ -43,7 +44,7 @@ extern crate harfbuzz;
extern crate fontconfig;

#[cfg(any(target_os="linux", target_os = "android"))]
extern crate freetype;
extern crate freetype_rs;

// Mac OS-specific library dependencies
#[cfg(target_os="macos")] extern crate core_foundation;
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

extern crate freetype;
extern crate freetype_rs;

use font::{FontHandleMethods, FontMetrics, FontTableMethods};
use font::{FontTableTag, FractionalPixel};
@@ -14,16 +14,16 @@ use text::util::{float_to_fixed, fixed_to_float};
use style::computed_values::font_weight;
use platform::font_template::FontTemplateData;

use freetype::freetype::{FT_Get_Char_Index, FT_Get_Postscript_Name};
use freetype::freetype::{FT_Load_Glyph, FT_Set_Char_Size};
use freetype::freetype::{FT_Get_Kerning, FT_Get_Sfnt_Table};
use freetype::freetype::{FT_New_Memory_Face, FT_Done_Face};
use freetype::freetype::{FTErrorMethods, FT_F26Dot6, FT_Face, FT_FaceRec};
use freetype::freetype::{FT_GlyphSlot, FT_Library, FT_Long, FT_ULong};
use freetype::freetype::{FT_KERNING_DEFAULT, FT_STYLE_FLAG_ITALIC, FT_STYLE_FLAG_BOLD};
use freetype::freetype::{FT_SizeRec, FT_UInt, FT_Size_Metrics, struct_FT_Vector_};
use freetype::freetype::{ft_sfnt_os2};
use freetype::tt_os2::TT_OS2;
use freetype_rs::ffi::{FT_Get_Char_Index, FT_Get_Postscript_Name};
use freetype_rs::ffi::{FT_Load_Glyph, FT_Set_Char_Size};
use freetype_rs::ffi::{FT_Get_Kerning, FT_Get_Sfnt_Table};
use freetype_rs::ffi::{FT_New_Memory_Face, FT_Done_Face};
use freetype_rs::ffi::{FTErrorMethods, FT_F26Dot6, FT_Face, FT_FaceRec};
use freetype_rs::ffi::{FT_GlyphSlot, FT_Library, FT_Long, FT_ULong};
use freetype_rs::ffi::{FT_KERNING_DEFAULT, FT_STYLE_FLAG_ITALIC, FT_STYLE_FLAG_BOLD};
use freetype_rs::ffi::{FT_SizeRec, FT_UInt, FT_Size_Metrics, FT_Vector};
use freetype_rs::ffi::{ft_sfnt_os2};
use freetype_rs::ffi::TT_OS2;

use std::mem;
use std::ptr;
@@ -174,7 +174,7 @@ impl FontHandleMethods for FontHandle {
fn glyph_h_kerning(&self, first_glyph: GlyphId, second_glyph: GlyphId)
-> FractionalPixel {
assert!(self.face.is_not_null());
let mut delta = struct_FT_Vector_ { x: 0, y: 0 };
let mut delta = FT_Vector { x: 0, y: 0 };
unsafe {
FT_Get_Kerning(self.face, first_glyph, second_glyph, FT_KERNING_DEFAULT, &mut delta);
}
@@ -2,13 +2,26 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use freetype::freetype::FTErrorMethods;
use freetype::freetype::FT_Add_Default_Modules;
use freetype::freetype::FT_Done_FreeType;
use freetype::freetype::FT_Library;
use freetype::freetype::FT_Memory;
use freetype::freetype::FT_New_Library;
use freetype::freetype::struct_FT_MemoryRec_;
//use freetype::freetype::FTErrorMethods;
use freetype_rs::ffi::FTErrorMethods;

//use freetype::freetype::FT_Add_Default_Modules;
use freetype_rs::ffi::FT_Add_Default_Modules;

//use freetype::freetype::FT_Done_FreeType;
use freetype_rs::ffi::FT_Done_FreeType;

//use freetype::freetype::FT_Library;
use freetype_rs::ffi::FT_Library;

//use freetype::freetype::FT_Memory;
use freetype_rs::ffi::FT_Memory;

//use freetype::freetype::FT_New_Library;
use freetype_rs::ffi::FT_New_Library;

//use freetype::freetype::struct_FT_MemoryRec_;
use freetype_rs::ffi::FT_MemoryRec;

use std::ptr;
use std::rc::Rc;
@@ -58,9 +71,9 @@ impl FontContextHandle {
pub fn new() -> FontContextHandle {
unsafe {

let ptr = libc::malloc(mem::size_of::<struct_FT_MemoryRec_>() as size_t);
let allocator: &mut struct_FT_MemoryRec_ = mem::transmute(ptr);
ptr::write(allocator, struct_FT_MemoryRec_ {
let ptr = libc::malloc(mem::size_of::<FT_MemoryRec>() as size_t);
let allocator: &mut FT_MemoryRec = mem::transmute(ptr);
ptr::write(allocator, FT_MemoryRec {
user: ptr::null_mut(),
alloc: ft_alloc,
free: ft_free,
@@ -19,8 +19,8 @@ use geom::side_offsets::SideOffsets2D;
use geom::size::Size2D;
use libc::size_t;
use libc::types::common::c99::{uint16_t, uint32_t};
use png::{RGB8, RGBA8, K8, KA8};
use servo_net::image::base::Image;
use servo_image::DynamicImage::{ImageLuma8, ImageLumaA8, ImageRgb8, ImageRgba8};
use servo_net::image::base::{DynamicImage};
use servo_util::geometry::Au;
use servo_util::opts;
use servo_util::range::Range;
@@ -30,6 +30,7 @@ use style::computed_values::border_style;
use sync::Arc;
use text::TextRun;
use text::glyph::CharIndex;
use servo_image::{GenericImage, ImageDecoder};

pub struct RenderContext<'a> {
pub draw_target: &'a DrawTarget,
@@ -109,24 +110,24 @@ impl<'a> RenderContext<'a> {
self.draw_target.pop_clip();
}

pub fn draw_image(&self, bounds: Rect<Au>, image: Arc<Box<Image>>) {
let size = Size2D(image.width as i32, image.height as i32);
let (pixel_width, pixels, source_format) = match image.pixels {
RGBA8(ref pixels) => (4, pixels.as_slice(), B8G8R8A8),
K8(ref pixels) => (1, pixels.as_slice(), A8),
RGB8(_) => panic!("RGB8 color type not supported"),
KA8(_) => panic!("KA8 color type not supported"),
pub fn draw_image(&self, bounds: Rect<Au>, image: Arc<Box<DynamicImage>>) {
let (image_width, image_height) = image.dimensions();
let size = Size2D(image_width as i32, image_height as i32);
let (pixel_width, pixels, source_format) = match **image {
ImageRgba8(ref pixels) => (4, pixels.rawbuf(), B8G8R8A8),
ImageLuma8(ref pixels) => (1, pixels.rawbuf(), A8),
ImageRgb8(_) => panic!("RGB8 color type not supported"),
ImageLumaA8(_) => panic!("K8 color type not supported"),
};
let stride = image.width * pixel_width;

let stride = image_width * pixel_width;
self.draw_target.make_current();
let draw_target_ref = &self.draw_target;
let azure_surface = draw_target_ref.create_source_surface_from_data(pixels,
size,
stride as i32,
source_format);
let source_rect = Rect(Point2D(0u as AzFloat, 0u as AzFloat),
Size2D(image.width as AzFloat, image.height as AzFloat));
Size2D(image_width as AzFloat, image_height as AzFloat));
let dest_rect = bounds.to_azure_rect();
let draw_surface_options = DrawSurfaceOptions::new(Linear, true);
let draw_options = DrawOptions::new(1.0f64 as AzFloat, 0);
@@ -45,6 +45,7 @@ use style::computed_values::{visibility};
use style::{ComputedValues, Bottom, Left, RGBA, Right, Top};
use sync::Arc;
use url::Url;
use servo_image::GenericImage;

/// The results of display list building for a single flow.
pub enum DisplayListBuildingResult {
@@ -218,8 +219,10 @@ impl FragmentDisplayListBuilding for Fragment {
};
debug!("(building display list) building background image");

let image_width = Au::from_px(image.width as int);
let image_height = Au::from_px(image.height as int);
let (img_width, img_height) = image.dimensions();

let image_width = Au::from_px(img_width as int);
let image_height = Au::from_px(img_height as int);
let mut bounds = *absolute_bounds;

// Clip.
@@ -258,28 +261,28 @@ impl FragmentDisplayListBuilding for Fragment {
bounds.origin.y = abs_y;
bounds.size.height = image_height;
ImageFragmentInfo::tile_image(&mut bounds.origin.x, &mut bounds.size.width,
abs_x, image.width);
abs_x, img_width);
}
background_repeat::repeat_y => {
bounds.origin.x = abs_x;
bounds.size.width = image_width;
ImageFragmentInfo::tile_image(&mut bounds.origin.y, &mut bounds.size.height,
abs_y, image.height);
abs_y, img_height);
}
background_repeat::repeat => {
ImageFragmentInfo::tile_image(&mut bounds.origin.x, &mut bounds.size.width,
abs_x, image.width);
abs_x, img_width);
ImageFragmentInfo::tile_image(&mut bounds.origin.y, &mut bounds.size.height,
abs_y, image.height);
abs_y, img_height);
}
};

// Create the image display item.
display_list.push(ImageDisplayItemClass(box ImageDisplayItem {
base: BaseDisplayItem::new(bounds, self.node, clip_rect),
image: image.clone(),
stretch_size: Size2D(Au::from_px(image.width as int),
Au::from_px(image.height as int)),
stretch_size: Size2D(Au::from_px(img_width as int),
Au::from_px(img_height as int)),
}), level);
}

@@ -27,6 +27,7 @@ extern crate "net" as servo_net;
extern crate "msg" as servo_msg;
#[phase(plugin, link)]
extern crate "util" as servo_util;
extern crate "image" as servo_image;

#[phase(plugin)]
extern crate string_cache_macros;
@@ -25,3 +25,6 @@ git = "https://github.com/servo/rust-stb-image"

[dependencies.url]
git = "https://github.com/servo/rust-url"

[dependencies.image]
git = "https://github.com/PistonDevelopers/image"
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.