Skip to content

Commit

Permalink
auto merge of #515 : pcwalton/servo/master, r=metajack
Browse files Browse the repository at this point in the history
Changes authored by me have not yet been reviewed; the other changes have.

r? @metajack
  • Loading branch information
bors-servo committed Jun 14, 2013
2 parents e5c0021 + c35abb2 commit 96731e9
Show file tree
Hide file tree
Showing 33 changed files with 765 additions and 211 deletions.
10 changes: 10 additions & 0 deletions src/components/gfx/compositor.rs
Expand Up @@ -12,6 +12,8 @@ pub struct LayerBuffer {
// The rect in the containing RenderLayer that this represents.
rect: Rect<uint>,

screen_pos: Rect<uint>,

// NB: stride is in pixels, like OpenGL GL_UNPACK_ROW_LENGTH.
stride: uint
}
Expand All @@ -22,9 +24,17 @@ pub struct LayerBufferSet {
buffers: ~[LayerBuffer]
}

/// The status of the renderer.
#[deriving(Eq)]
pub enum RenderState {
IdleRenderState,
RenderingRenderState,
}

/// The interface used to by the renderer to acquire draw targets for each rendered frame and
/// submit them to be drawn to the display.
pub trait Compositor {
fn paint(&self, layer_buffer_set: LayerBufferSet, new_size: Size2D<uint>);
fn set_render_state(&self, render_state: RenderState);
}

16 changes: 12 additions & 4 deletions src/components/gfx/font.rs
Expand Up @@ -18,6 +18,8 @@ use azure::scaled_font::ScaledFont;
use azure::azure_hl::{BackendType, ColorPattern};
use geom::{Point2D, Rect, Size2D};

use servo_util::time::ProfilerChan;

// FontHandle encapsulates access to the platform's font API,
// e.g. quartz, FreeType. It provides access to metrics and tables
// needed by the text shaper as well as access to the underlying font
Expand Down Expand Up @@ -210,13 +212,15 @@ pub struct Font {
style: UsedFontStyle,
metrics: FontMetrics,
backend: BackendType,
profiler_chan: ProfilerChan,
}

pub impl Font {
fn new_from_buffer(ctx: &FontContext,
buffer: ~[u8],
style: &SpecifiedFontStyle,
backend: BackendType)
backend: BackendType,
profiler_chan: ProfilerChan)
-> Result<@mut Font, ()> {
let handle = FontHandleMethods::new_from_buffer(&ctx.handle, buffer, style);
let handle: FontHandle = if handle.is_ok() {
Expand All @@ -235,11 +239,13 @@ pub impl Font {
style: copy *style,
metrics: metrics,
backend: backend,
profiler_chan: profiler_chan,
});
}

fn new_from_adopted_handle(_fctx: &FontContext, handle: FontHandle,
style: &SpecifiedFontStyle, backend: BackendType) -> @mut Font {
style: &SpecifiedFontStyle, backend: BackendType,
profiler_chan: ProfilerChan) -> @mut Font {
let metrics = handle.get_metrics();

@mut Font {
Expand All @@ -249,19 +255,21 @@ pub impl Font {
style: copy *style,
metrics: metrics,
backend: backend,
profiler_chan: profiler_chan,
}
}

fn new_from_existing_handle(fctx: &FontContext, handle: &FontHandle,
style: &SpecifiedFontStyle, backend: BackendType) -> Result<@mut Font,()> {
style: &SpecifiedFontStyle, backend: BackendType,
profiler_chan: ProfilerChan) -> Result<@mut Font,()> {

// TODO(Issue #179): convert between specified and used font style here?
let styled_handle = match handle.clone_with_style(&fctx.handle, style) {
Ok(result) => result,
Err(()) => return Err(())
};

return Ok(Font::new_from_adopted_handle(fctx, styled_handle, style, backend));
return Ok(Font::new_from_adopted_handle(fctx, styled_handle, style, backend, profiler_chan));
}

priv fn get_shaper(@mut self) -> @Shaper {
Expand Down
22 changes: 16 additions & 6 deletions src/components/gfx/font_context.rs
Expand Up @@ -40,17 +40,18 @@ pub struct FontContext {
handle: FontContextHandle,
backend: BackendType,
generic_fonts: HashMap<~str,~str>,
profiler_chan: ProfilerChan,
}

#[allow(non_implicitly_copyable_typarams)]
pub impl<'self> FontContext {
fn new(backend: BackendType,
needs_font_list: bool,
prof_chan: ProfilerChan)
profiler_chan: ProfilerChan)
-> FontContext {
let handle = FontContextHandle::new();
let font_list = if needs_font_list {
Some(FontList::new(&handle, prof_chan.clone())) }
Some(FontList::new(&handle, profiler_chan.clone())) }
else { None };

// TODO: Allow users to specify these.
Expand All @@ -69,6 +70,7 @@ pub impl<'self> FontContext {
handle: handle,
backend: backend,
generic_fonts: generic_fonts,
profiler_chan: profiler_chan,
}
}

Expand Down Expand Up @@ -125,7 +127,8 @@ pub impl<'self> FontContext {
for result.each |font_entry| {
found = true;
// TODO(Issue #203): route this instantion through FontContext's Font instance cache.
let instance = Font::new_from_existing_handle(self, &font_entry.handle, style, self.backend);
let instance = Font::new_from_existing_handle(self, &font_entry.handle, style, self.backend,
self.profiler_chan.clone());
do result::iter(&instance) |font: &@mut Font| { fonts.push(*font); }
};

Expand All @@ -139,8 +142,14 @@ pub impl<'self> FontContext {
for last_resort.each |family| {
let result = list.find_font_in_family(*family,style);
for result.each |font_entry| {
let instance = Font::new_from_existing_handle(self, &font_entry.handle, style, self.backend);
do result::iter(&instance) |font: &@mut Font| { fonts.push(*font); }
let instance = Font::new_from_existing_handle(self,
&font_entry.handle,
style,
self.backend,
self.profiler_chan.clone());
do result::iter(&instance) |font: &@mut Font| {
fonts.push(*font);
}
}
}

Expand All @@ -163,7 +172,8 @@ pub impl<'self> FontContext {
Ok(Font::new_from_adopted_handle(self,
handle,
&desc.style,
self.backend))
self.backend,
self.profiler_chan.clone()))
})
}
};
Expand Down
22 changes: 21 additions & 1 deletion src/components/gfx/opts.rs
Expand Up @@ -13,6 +13,11 @@ pub struct Opts {
render_backend: BackendType,
n_render_threads: uint,
tile_size: uint,
profiler_period: Option<f64>,

/// A scale factor to apply to tiles, to allow rendering tiles at higher resolutions for
/// testing pan and zoom code.
zoom: uint,
}

#[allow(non_implicitly_copyable_typarams)]
Expand All @@ -26,13 +31,14 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts {
getopts::optopt(~"r"), // rendering backend
getopts::optopt(~"s"), // size of tiles
getopts::optopt(~"t"), // threads to render with
getopts::optflagopt(~"p"), // profiler flag and output interval
getopts::optopt(~"z"), // zoom level
];

let opt_match = match getopts::getopts(args, opts) {
result::Ok(m) => { copy m }
result::Err(f) => { fail!(getopts::fail_str(copy f)) }
};

let urls = if opt_match.free.is_empty() {
fail!(~"servo asks that you provide 1 or more URLs")
} else {
Expand Down Expand Up @@ -68,10 +74,24 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts {
None => 1, // FIXME: Number of cores.
};

let profiler_period: Option<f64> =
// if only flag is present, default to 5 second period
match getopts::opt_default(&opt_match, ~"p", ~"5") {
Some(period) => Some(f64::from_str(period).get()),
None => None,
};

let zoom: uint = match getopts::opt_maybe_str(&opt_match, ~"z") {
Some(zoom_str) => uint::from_str(zoom_str).get(),
None => 1,
};

Opts {
urls: urls,
render_backend: render_backend,
n_render_threads: n_render_threads,
tile_size: tile_size,
profiler_period: profiler_period,
zoom: zoom,
}
}
13 changes: 8 additions & 5 deletions src/components/gfx/render_layers.rs
Expand Up @@ -37,6 +37,7 @@ pub fn render_layers(layer_ref: *RenderLayer,
f: RenderFn)
-> LayerBufferSet {
let tile_size = opts.tile_size;
let scale = opts.zoom;

// FIXME: Try not to create a new array here.
let mut new_buffer_ports = ~[];
Expand All @@ -45,12 +46,12 @@ pub fn render_layers(layer_ref: *RenderLayer,
do time::profile(time::RenderingPrepBuffCategory, prof_chan.clone()) {
let layer: &RenderLayer = unsafe { cast::transmute(layer_ref) };
let mut y = 0;
while y < layer.size.height {
while y < layer.size.height * scale {
let mut x = 0;
while x < layer.size.width {
while x < layer.size.width * scale {
// Figure out the dimension of this tile.
let right = uint::min(x + tile_size, layer.size.width);
let bottom = uint::min(y + tile_size, layer.size.height);
let right = uint::min(x + tile_size, layer.size.width * scale);
let bottom = uint::min(y + tile_size, layer.size.height * scale);
let width = right - x;
let height = bottom - y;

Expand All @@ -65,7 +66,8 @@ pub fn render_layers(layer_ref: *RenderLayer,

debug!("tile aligned_width %u", aligned_width);

let tile_rect = Rect(Point2D(x, y), Size2D(aligned_width, height));
let tile_rect = Rect(Point2D(x / scale, y / scale), Size2D(aligned_width, height)); //change this
let screen_rect = Rect(Point2D(x, y), Size2D(aligned_width, height)); //change this

let buffer;
// FIXME: Try harder to search for a matching tile.
Expand Down Expand Up @@ -112,6 +114,7 @@ pub fn render_layers(layer_ref: *RenderLayer,
stride,
B8G8R8A8),
rect: tile_rect,
screen_pos: screen_rect,
stride: stride as uint
};
//}
Expand Down
21 changes: 14 additions & 7 deletions src/components/gfx/render_task.rs
Expand Up @@ -5,7 +5,7 @@
// The task that handles all rendering/painting.

use azure::AzFloat;
use compositor::Compositor;
use compositor::{Compositor, IdleRenderState, RenderingRenderState};
use font_context::FontContext;
use geom::matrix2d::Matrix2D;
use opts::Opts;
Expand All @@ -18,9 +18,7 @@ use core::task::SingleThreaded;
use std::task_pool::TaskPool;
use servo_net::util::spawn_listener;

use servo_util::time::ProfilerChan;
use servo_util::time::profile;
use servo_util::time::time;
use servo_util::time::{ProfilerChan, profile};
use servo_util::time;

pub enum Msg {
Expand Down Expand Up @@ -124,7 +122,8 @@ impl<C: Compositor + Owned> Renderer<C> {

fn render(&mut self, render_layer: RenderLayer) {
debug!("renderer: rendering");
do time("rendering") {
self.compositor.set_render_state(RenderingRenderState);
do profile(time::RenderingCategory, self.profiler_chan.clone()) {
let layer_buffer_set = do render_layers(&render_layer,
&self.opts,
self.profiler_chan.clone()) |render_layer_ref,
Expand All @@ -142,17 +141,24 @@ impl<C: Compositor + Owned> Renderer<C> {

// Apply the translation to render the tile we want.
let matrix: Matrix2D<AzFloat> = Matrix2D::identity();
let matrix = matrix.translate(&-(layer_buffer.rect.origin.x as AzFloat),
&-(layer_buffer.rect.origin.y as AzFloat));
let scale = thread_render_context.opts.zoom as f32;

let matrix = matrix.scale(scale as AzFloat, scale as AzFloat);
let matrix = matrix.translate(-(layer_buffer.rect.origin.x as f32) as AzFloat,
-(layer_buffer.rect.origin.y as f32) as AzFloat);


layer_buffer.draw_target.set_transform(&matrix);

// Clear the buffer.
ctx.clear();


// Draw the display list.
let render_layer: &RenderLayer = unsafe {
cast::transmute(render_layer_ref)
};

render_layer.display_list.draw_into_context(&ctx);
}

Expand All @@ -163,6 +169,7 @@ impl<C: Compositor + Owned> Renderer<C> {

debug!("renderer: returning surface");
self.compositor.paint(layer_buffer_set, render_layer.size);
self.compositor.set_render_state(IdleRenderState);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/gfx/text/text_run.rs
Expand Up @@ -6,6 +6,8 @@ use font_context::FontContext;
use geometry::Au;
use text::glyph::{BreakTypeNormal, GlyphStore};
use font::{Font, FontDescriptor, RunMetrics};
use servo_util::time;
use servo_util::time::profile;
use servo_util::range::Range;

/// A text run.
Expand Down Expand Up @@ -44,7 +46,9 @@ pub impl<'self> TextRun {
fn new(font: @mut Font, text: ~str, underline: bool) -> TextRun {
let mut glyph_store = GlyphStore::new(str::char_len(text));
TextRun::compute_potential_breaks(text, &mut glyph_store);
font.shape_text(text, &mut glyph_store);
do profile(time::LayoutShapingCategory, font.profiler_chan.clone()) {
font.shape_text(text, &mut glyph_store);
}

let run = TextRun {
text: text,
Expand Down

0 comments on commit 96731e9

Please sign in to comment.