зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #518 - Switch to GPU rendering (from metajack:gpu-rendering); r=pcwalton
This uses Skia GL to render to offscreen FBOs and then passes the resulting textures directly to the compositor. It depends on https://github.com/mozilla-servo/rust-azure/pull/26 and https://github.com/mozilla-servo/skia/pull/14 r? @pcwalton Source-Repo: https://github.com/servo/servo Source-Revision: 93eea6b2e87adedf833790d045bf69417ca9b7e3
This commit is contained in:
Родитель
9730fd6169
Коммит
970f788ef7
|
@ -17,9 +17,9 @@ config.mk
|
|||
config.stamp
|
||||
config.tmp
|
||||
parser.out
|
||||
src/components/servo/dom/bindings/codegen/*.rs
|
||||
src/components/servo/dom/bindings/codegen/_cache/
|
||||
src/components/servo/dom/bindings/codegen/test/*.rs
|
||||
src/components/servo/dom/bindings/codegen/PrototypeList.h
|
||||
src/components/servo/dom/bindings/codegen/UnionTypes.h
|
||||
src/components/servo/dom/bindings/codegen/UnionConversions.h
|
||||
src/components/script/dom/bindings/codegen/*.rs
|
||||
src/components/script/dom/bindings/codegen/_cache/
|
||||
src/components/script/dom/bindings/codegen/test/*.rs
|
||||
src/components/script/dom/bindings/codegen/PrototypeList.h
|
||||
src/components/script/dom/bindings/codegen/UnionTypes.h
|
||||
src/components/script/dom/bindings/codegen/UnionConversions.h
|
||||
|
|
|
@ -199,7 +199,7 @@ SRC_script = $(call rwildcard,$(S)src/components/script/,*.rs) $(AUTOGEN_SRC_scr
|
|||
CRATE_script = $(S)src/components/script/script.rc
|
||||
DONE_script = $(B)src/components/script/libscript.dummy
|
||||
|
||||
DEPS_script = $(CRATE_script) $(SRC_script) $(DONE_SUBMODULES) $(DONE_util) $(DONE_net)
|
||||
DEPS_script = $(CRATE_script) $(SRC_script) $(DONE_SUBMODULES) $(DONE_util) $(DONE_net) $(DONE_gfx)
|
||||
|
||||
RFLAGS_servo = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/gfx -L $(B)src/components/util -L $(B)src/components/net -L $(B)src/components/script
|
||||
|
||||
|
|
|
@ -26,16 +26,16 @@ clean-fast: $(DEPS_CLEAN_TARGETS_FAST) clean-servo
|
|||
$(Q)echo "$(filter-out $(SLOW_BUILDS),$(DEPS_CLEAN_ALL))"
|
||||
|
||||
clean-util:
|
||||
cd $(B)/src/components/util/ && rm -rf libservo_util*.dylib $(DONE_servo_util)
|
||||
cd $(B)/src/components/util/ && rm -rf libutil*.dylib $(DONE_util)
|
||||
|
||||
clean-net:
|
||||
cd $(B)/src/components/net/ && rm -rf libservo_net*.dylib $(DONE_servo_net)
|
||||
cd $(B)/src/components/net/ && rm -rf libnet*.dylib $(DONE_net)
|
||||
|
||||
clean-gfx:
|
||||
cd $(B)/src/components/gfx/ && rm -rf libservo_gfx*.dylib $(DONE_servo_gfx)
|
||||
cd $(B)/src/components/gfx/ && rm -rf libgfx*.dylib $(DONE_gfx)
|
||||
|
||||
clean-script:
|
||||
cd $(B)/src/components/script/ && rm -rf libservo_script*.dylib $(DONE_servo_script)
|
||||
cd $(B)/src/components/script/ && rm -rf libscript*.dylib $(DONE_script)
|
||||
|
||||
clean-servo: clean-gfx clean-util clean-net clean-script
|
||||
rm -f servo servo-test
|
||||
|
|
|
@ -38,6 +38,9 @@ NATIVE_BUILDS += \
|
|||
# NB. This should not be a problem once a real package system exists.
|
||||
|
||||
DEPS_rust-azure += \
|
||||
rust-opengles \
|
||||
rust-layers \
|
||||
rust-glut \
|
||||
rust-geom \
|
||||
skia \
|
||||
$(NULL)
|
||||
|
@ -47,12 +50,9 @@ DEPS_rust-glut += \
|
|||
$(NULL)
|
||||
|
||||
DEPS_rust-layers += \
|
||||
rust-azure \
|
||||
rust-cocoa \
|
||||
rust-geom \
|
||||
rust-glut \
|
||||
rust-opengles \
|
||||
skia \
|
||||
$(NULL)
|
||||
|
||||
DEPS_sharegl += \
|
||||
|
@ -105,7 +105,7 @@ DEPS_rust-azure += \
|
|||
rust-core-graphics \
|
||||
rust-core-text \
|
||||
rust-core-foundation \
|
||||
skia \
|
||||
rust-cocoa \
|
||||
$(NULL)
|
||||
|
||||
DEPS_rust-io-surface += \
|
||||
|
@ -135,6 +135,7 @@ DEPS_rust-layers += \
|
|||
rust-core-foundation \
|
||||
rust-core-graphics \
|
||||
rust-core-text \
|
||||
rust-cocoa \
|
||||
$(NULL)
|
||||
|
||||
DEPS_rust-glut += \
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
* 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 azure::azure_hl::{DrawTarget};
|
||||
use azure::azure_hl::DrawTarget;
|
||||
use azure::azure::AzGLContext;
|
||||
use geom::rect::Rect;
|
||||
use geom::size::Size2D;
|
||||
|
||||
|
@ -34,6 +35,7 @@ pub enum RenderState {
|
|||
/// 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 get_gl_context(&self) -> AzGLContext;
|
||||
fn paint(&self, layer_buffer_set: LayerBufferSet, new_size: Size2D<uint>);
|
||||
fn set_render_state(&self, render_state: RenderState);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ pub impl<'self> RenderContext<'self> {
|
|||
}
|
||||
|
||||
pub fn draw_solid_color(&self, bounds: &Rect<Au>, color: Color) {
|
||||
self.canvas.draw_target.make_current();
|
||||
self.canvas.draw_target.fill_rect(&bounds.to_azure_rect(), &ColorPattern(color));
|
||||
}
|
||||
|
||||
|
@ -46,6 +47,7 @@ pub impl<'self> RenderContext<'self> {
|
|||
let stroke_opts = StrokeOptions(width_px as AzFloat, 10 as AzFloat, stroke_fields);
|
||||
let draw_opts = DrawOptions(1 as AzFloat, 0 as uint16_t);
|
||||
|
||||
self.canvas.draw_target.make_current();
|
||||
self.canvas.draw_target.stroke_rect(&rect, &pattern, &stroke_opts, &draw_opts);
|
||||
}
|
||||
|
||||
|
@ -54,6 +56,7 @@ pub impl<'self> RenderContext<'self> {
|
|||
let size = Size2D(image.width as i32, image.height as i32);
|
||||
let stride = image.width * 4;
|
||||
|
||||
self.canvas.draw_target.make_current();
|
||||
let draw_target_ref = &self.canvas.draw_target;
|
||||
let azure_surface = draw_target_ref.create_source_surface_from_data(image.data, size,
|
||||
stride as i32, B8G8R8A8);
|
||||
|
@ -75,6 +78,7 @@ pub impl<'self> RenderContext<'self> {
|
|||
self.canvas.rect.origin.y as AzFloat),
|
||||
Size2D(self.canvas.rect.size.width as AzFloat,
|
||||
self.canvas.rect.size.height as AzFloat));
|
||||
self.canvas.draw_target.make_current();
|
||||
self.canvas.draw_target.fill_rect(&rect, &pattern);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use servo_util::time;
|
|||
use servo_util::time::ProfilerChan;
|
||||
|
||||
use azure::azure_hl::{B8G8R8A8, DrawTarget};
|
||||
use azure::azure::{AzGLContext};
|
||||
use core::comm::Chan;
|
||||
use geom::point::Point2D;
|
||||
use geom::rect::Rect;
|
||||
|
@ -34,6 +35,7 @@ type RenderFn<'self> = &'self fn(layer: *RenderLayer,
|
|||
pub fn render_layers(layer_ref: *RenderLayer,
|
||||
opts: &Opts,
|
||||
prof_chan: ProfilerChan,
|
||||
share_gl_context: AzGLContext,
|
||||
f: RenderFn)
|
||||
-> LayerBufferSet {
|
||||
let tile_size = opts.tile_size;
|
||||
|
@ -55,19 +57,8 @@ pub fn render_layers(layer_ref: *RenderLayer,
|
|||
let width = right - x;
|
||||
let height = bottom - y;
|
||||
|
||||
// Round the width up the nearest 32 pixels for DMA on the Mac.
|
||||
let aligned_width = if width % 32 == 0 {
|
||||
width
|
||||
} else {
|
||||
(width & !(32 - 1)) + 32
|
||||
};
|
||||
assert!(aligned_width % 32 == 0);
|
||||
assert!(aligned_width >= width);
|
||||
|
||||
debug!("tile aligned_width %u", aligned_width);
|
||||
|
||||
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 tile_rect = Rect(Point2D(x / scale, y / scale), Size2D(width, height)); //change this
|
||||
let screen_rect = Rect(Point2D(x, y), Size2D(width, height)); //change this
|
||||
|
||||
let buffer;
|
||||
// FIXME: Try harder to search for a matching tile.
|
||||
|
@ -79,40 +70,14 @@ pub fn render_layers(layer_ref: *RenderLayer,
|
|||
// Create a new buffer.
|
||||
debug!("creating tile, (%u, %u)", x, y);
|
||||
|
||||
let size = Size2D(aligned_width as i32, height as i32);
|
||||
// FIXME: This may not be always true.
|
||||
let stride = (aligned_width as i32) * 4;
|
||||
|
||||
let mut data: ~[u8] = ~[0];
|
||||
let offset;
|
||||
unsafe {
|
||||
// FIXME: Evil black magic to ensure that we don't perform a slow memzero
|
||||
// of this buffer. This should be made safe.
|
||||
|
||||
let align = 256;
|
||||
|
||||
let len = ((stride * size.height) as uint) + align;
|
||||
vec::reserve(&mut data, len);
|
||||
vec::raw::set_len(&mut data, len);
|
||||
|
||||
// Round up to the nearest 32-byte-aligned address for DMA on the Mac.
|
||||
let addr: uint = cast::transmute(ptr::to_unsafe_ptr(&data[0]));
|
||||
if addr % align == 0 {
|
||||
offset = 0;
|
||||
} else {
|
||||
offset = align - addr % align;
|
||||
}
|
||||
|
||||
debug!("tile offset is %u, expected addr is %x", offset, addr + offset);
|
||||
}
|
||||
let stride = width * 4;
|
||||
|
||||
buffer = LayerBuffer {
|
||||
draw_target: DrawTarget::new_with_data(opts.render_backend,
|
||||
data,
|
||||
offset,
|
||||
size,
|
||||
stride,
|
||||
B8G8R8A8),
|
||||
draw_target: DrawTarget::new_with_fbo(opts.render_backend,
|
||||
share_gl_context,
|
||||
Size2D(width as i32, height as i32),
|
||||
B8G8R8A8),
|
||||
rect: tile_rect,
|
||||
screen_pos: screen_rect,
|
||||
stride: stride as uint
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
// The task that handles all rendering/painting.
|
||||
|
||||
use azure::AzFloat;
|
||||
use azure::{AzFloat, AzGLContext};
|
||||
use compositor::{Compositor, IdleRenderState, RenderingRenderState};
|
||||
use font_context::FontContext;
|
||||
use geom::matrix2d::Matrix2D;
|
||||
|
@ -16,6 +16,7 @@ use core::cell::Cell;
|
|||
use core::comm::{Chan, Port, SharedChan};
|
||||
use core::task::SingleThreaded;
|
||||
use std::task_pool::TaskPool;
|
||||
|
||||
use servo_net::util::spawn_listener;
|
||||
|
||||
use servo_util::time::{ProfilerChan, profile};
|
||||
|
@ -43,6 +44,7 @@ impl RenderTask {
|
|||
|
||||
do spawn {
|
||||
let compositor = compositor_cell.take();
|
||||
let share_gl_context = compositor.get_gl_context();
|
||||
|
||||
// FIXME: Annoying three-cell dance here. We need one-shot closures.
|
||||
let opts = opts_cell.with_ref(|o| copy *o);
|
||||
|
@ -77,6 +79,7 @@ impl RenderTask {
|
|||
thread_pool: thread_pool,
|
||||
opts: opts_cell.take(),
|
||||
profiler_chan: profiler_chan_copy,
|
||||
share_gl_context: share_gl_context,
|
||||
};
|
||||
|
||||
renderer.start();
|
||||
|
@ -103,6 +106,8 @@ priv struct Renderer<C> {
|
|||
|
||||
/// A channel to the profiler.
|
||||
profiler_chan: ProfilerChan,
|
||||
|
||||
share_gl_context: AzGLContext,
|
||||
}
|
||||
|
||||
impl<C: Compositor + Owned> Renderer<C> {
|
||||
|
@ -126,7 +131,8 @@ impl<C: Compositor + Owned> Renderer<C> {
|
|||
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,
|
||||
self.profiler_chan.clone(),
|
||||
self.share_gl_context) |render_layer_ref,
|
||||
layer_buffer,
|
||||
buffer_chan| {
|
||||
let layer_buffer_cell = Cell(layer_buffer);
|
||||
|
@ -147,7 +153,6 @@ impl<C: Compositor + Owned> Renderer<C> {
|
|||
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.
|
||||
|
@ -160,6 +165,7 @@ impl<C: Compositor + Owned> Renderer<C> {
|
|||
};
|
||||
|
||||
render_layer.display_list.draw_into_context(&ctx);
|
||||
ctx.canvas.draw_target.flush();
|
||||
}
|
||||
|
||||
// Send back the buffer.
|
||||
|
|
|
@ -13,7 +13,8 @@ use script::dom::event::{Event, ClickEvent, MouseDownEvent, MouseUpEvent};
|
|||
use script::compositor_interface::{ReadyState, CompositorInterface};
|
||||
use script::compositor_interface;
|
||||
|
||||
use azure::azure_hl::{DataSourceSurface, DrawTarget, SourceSurfaceMethods};
|
||||
use azure::azure_hl::{DataSourceSurface, DrawTarget, SourceSurfaceMethods, current_gl_context};
|
||||
use azure::azure::AzGLContext;
|
||||
use core::cell::Cell;
|
||||
use core::comm::{Chan, SharedChan, Port};
|
||||
use core::num::Orderable;
|
||||
|
@ -22,8 +23,9 @@ use geom::matrix::identity;
|
|||
use geom::point::Point2D;
|
||||
use geom::size::Size2D;
|
||||
use gfx::compositor::{Compositor, LayerBufferSet, RenderState};
|
||||
use layers::layers::{ARGB32Format, BasicImageData, ContainerLayer, ContainerLayerKind, Format};
|
||||
use layers::layers::{Image, ImageData, ImageLayer, ImageLayerKind, RGB24Format, WithDataFn};
|
||||
use layers::layers::{ARGB32Format, ContainerLayer, ContainerLayerKind, Format};
|
||||
use layers::layers::{ImageData, WithDataFn};
|
||||
use layers::layers::{TextureLayerKind, TextureLayer, TextureManager};
|
||||
use layers::rendergl;
|
||||
use layers::scene::Scene;
|
||||
use servo_util::{time, url};
|
||||
|
@ -74,6 +76,8 @@ impl CompositorTask {
|
|||
pub enum Msg {
|
||||
/// Requests that the compositor shut down.
|
||||
Exit,
|
||||
/// Requests the compositors GL context.
|
||||
GetGLContext(Chan<AzGLContext>),
|
||||
/// Requests that the compositor paint the given layer buffer set for the given page size.
|
||||
Paint(LayerBufferSet, Size2D<uint>),
|
||||
/// Alerts the compositor to the current status of page loading.
|
||||
|
@ -86,7 +90,7 @@ pub enum Msg {
|
|||
struct AzureDrawTargetImageData {
|
||||
draw_target: DrawTarget,
|
||||
data_source_surface: DataSourceSurface,
|
||||
size: Size2D<uint>
|
||||
size: Size2D<uint>,
|
||||
}
|
||||
|
||||
impl ImageData for AzureDrawTargetImageData {
|
||||
|
@ -121,16 +125,6 @@ fn run_main_loop(port: Port<Msg>,
|
|||
// list. This is only here because we don't have that logic in the renderer yet.
|
||||
let context = rendergl::init_render_context();
|
||||
let root_layer = @mut ContainerLayer();
|
||||
let original_layer_transform;
|
||||
{
|
||||
let image_data = @BasicImageData::new(Size2D(0, 0), 0, RGB24Format, ~[]);
|
||||
let image = @mut Image::new(image_data as @ImageData);
|
||||
let image_layer = @mut ImageLayer(image);
|
||||
original_layer_transform = image_layer.common.transform;
|
||||
image_layer.common.set_transform(original_layer_transform.scale(800.0, 600.0, 1.0));
|
||||
root_layer.add_child(ImageLayerKind(image_layer));
|
||||
}
|
||||
|
||||
let scene = @mut Scene(ContainerLayerKind(root_layer), Size2D(800.0, 600.0), identity());
|
||||
let done = @mut false;
|
||||
|
||||
|
@ -155,6 +149,8 @@ fn run_main_loop(port: Port<Msg>,
|
|||
ChangeReadyState(ready_state) => window.set_ready_state(ready_state),
|
||||
ChangeRenderState(render_state) => window.set_render_state(render_state),
|
||||
|
||||
GetGLContext(chan) => chan.send(current_gl_context()),
|
||||
|
||||
Paint(new_layer_buffer_set, new_size) => {
|
||||
debug!("osmain: received new frame");
|
||||
|
||||
|
@ -175,25 +171,19 @@ fn run_main_loop(port: Port<Msg>,
|
|||
|
||||
debug!("osmain: compositing buffer rect %?", &buffer.rect);
|
||||
|
||||
let image_data = @AzureDrawTargetImageData {
|
||||
draw_target: buffer.draw_target.clone(),
|
||||
data_source_surface: buffer.draw_target.snapshot().get_data_surface(),
|
||||
size: Size2D(width, height)
|
||||
};
|
||||
let image = @mut Image::new(image_data as @ImageData);
|
||||
|
||||
// Find or create an image layer.
|
||||
let image_layer;
|
||||
// Find or create a texture layer.
|
||||
let texture_layer;
|
||||
current_layer_child = match current_layer_child {
|
||||
None => {
|
||||
debug!("osmain: adding new image layer");
|
||||
image_layer = @mut ImageLayer(image);
|
||||
root_layer.add_child(ImageLayerKind(image_layer));
|
||||
debug!("osmain: adding new texture layer");
|
||||
texture_layer = @mut TextureLayer::new(@buffer.draw_target.clone() as @TextureManager,
|
||||
buffer.rect.size);
|
||||
root_layer.add_child(TextureLayerKind(texture_layer));
|
||||
None
|
||||
}
|
||||
Some(ImageLayerKind(existing_image_layer)) => {
|
||||
image_layer = existing_image_layer;
|
||||
image_layer.set_image(image);
|
||||
Some(TextureLayerKind(existing_texture_layer)) => {
|
||||
texture_layer = existing_texture_layer;
|
||||
texture_layer.manager = @buffer.draw_target.clone() as @TextureManager;
|
||||
|
||||
// Move on to the next sibling.
|
||||
do current_layer_child.get().with_common |common| {
|
||||
|
@ -207,17 +197,15 @@ fn run_main_loop(port: Port<Msg>,
|
|||
let origin = Point2D(origin.x as f32, origin.y as f32);
|
||||
|
||||
// Set the layer's transform.
|
||||
let transform = original_layer_transform.translate(origin.x,
|
||||
origin.y,
|
||||
0.0);
|
||||
let transform = identity().translate(origin.x, origin.y, 0.0);
|
||||
let transform = transform.scale(width as f32, height as f32, 1.0);
|
||||
image_layer.common.set_transform(transform)
|
||||
texture_layer.common.set_transform(transform);
|
||||
}
|
||||
|
||||
// TODO: Recycle the old buffers; send them back to the renderer to reuse if
|
||||
// it wishes.
|
||||
|
||||
window.set_needs_display()
|
||||
window.set_needs_display();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -356,6 +344,12 @@ fn run_main_loop(port: Port<Msg>,
|
|||
|
||||
/// Implementation of the abstract `Compositor` interface.
|
||||
impl Compositor for CompositorTask {
|
||||
fn get_gl_context(&self) -> AzGLContext {
|
||||
let (port, chan) = comm::stream();
|
||||
self.chan.send(GetGLContext(chan));
|
||||
port.recv()
|
||||
}
|
||||
|
||||
fn paint(&self, layer_buffer_set: LayerBufferSet, new_size: Size2D<uint>) {
|
||||
self.chan.send(Paint(layer_buffer_set, new_size))
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ impl WindowMethods<Application> for Window {
|
|||
/// Creates a new window.
|
||||
pub fn new(_: &Application) -> @mut Window {
|
||||
// Create the GLUT window.
|
||||
unsafe { glut::bindgen::glutInitWindowSize(800, 600); }
|
||||
let glut_window = glut::create_window(~"Servo");
|
||||
glut::reshape_window(glut_window, 800, 600);
|
||||
|
||||
// Create our window object.
|
||||
let window = @mut Window {
|
||||
|
|
Загрузка…
Ссылка в новой задаче