Skip to content

Commit

Permalink
Auto merge of #16073 - glennw:update-wr-glfns, r=mrobinson
Browse files Browse the repository at this point in the history
Update WR (gl trait, scroll roots)

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16073)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Mar 23, 2017
2 parents 301ba36 + fe75382 commit c99289a
Show file tree
Hide file tree
Showing 23 changed files with 386 additions and 338 deletions.
146 changes: 73 additions & 73 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions components/canvas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ azure = {git = "https://github.com/servo/rust-azure"}
canvas_traits = {path = "../canvas_traits"}
cssparser = "0.12"
euclid = "0.11"
gleam = "0.2.8"
gleam = "0.4"
ipc-channel = "0.7"
log = "0.3.5"
num-traits = "0.1.32"
offscreen_gl_context = "0.6"
offscreen_gl_context = "0.8"
servo_config = {path = "../config"}
webrender_traits = {git = "https://github.com/servo/webrender", features = ["ipc"]}
41 changes: 29 additions & 12 deletions components/canvas/webgl_paint_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ enum GLContextWrapper {

impl GLContextWrapper {
fn new(size: Size2D<i32>,
attributes: GLContextAttributes) -> Result<GLContextWrapper, &'static str> {
attributes: GLContextAttributes,
gl_type: gl::GlType) -> Result<GLContextWrapper, &'static str> {
if opts::get().should_use_osmesa() {
let ctx = GLContext::<OSMesaContext>::new(size,
attributes,
ColorAttachmentType::Texture,
gl_type,
None);
ctx.map(GLContextWrapper::OSMesa)
} else {
let ctx = GLContext::<NativeGLContext>::new(size,
attributes,
ColorAttachmentType::Texture,
gl_type,
None);
ctx.map(GLContextWrapper::Native)
}
Expand Down Expand Up @@ -62,6 +65,17 @@ impl GLContextWrapper {
}
}

fn gl(&self) -> &gl::Gl {
match *self {
GLContextWrapper::Native(ref ctx) => {
ctx.gl()
}
GLContextWrapper::OSMesa(ref ctx) => {
ctx.gl()
}
}
}

pub fn make_current(&self) {
match *self {
GLContextWrapper::Native(ref ctx) => {
Expand Down Expand Up @@ -97,9 +111,10 @@ pub struct WebGLPaintThread {

fn create_readback_painter(size: Size2D<i32>,
attrs: GLContextAttributes,
webrender_api: webrender_traits::RenderApi)
webrender_api: webrender_traits::RenderApi,
gl_type: gl::GlType)
-> Result<(WebGLPaintThread, GLLimits), String> {
let context = try!(GLContextWrapper::new(size, attrs));
let context = try!(GLContextWrapper::new(size, attrs, gl_type));
let limits = context.get_limits();
let image_key = webrender_api.generate_image_key();
let painter = WebGLPaintThread {
Expand All @@ -113,7 +128,8 @@ fn create_readback_painter(size: Size2D<i32>,
impl WebGLPaintThread {
fn new(size: Size2D<i32>,
attrs: GLContextAttributes,
webrender_api_sender: webrender_traits::RenderApiSender)
webrender_api_sender: webrender_traits::RenderApiSender,
gl_type: gl::GlType)
-> Result<(WebGLPaintThread, GLLimits), String> {
let wr_api = webrender_api_sender.create_api();
let device_size = webrender_traits::DeviceIntSize::from_untyped(&size);
Expand All @@ -127,7 +143,7 @@ impl WebGLPaintThread {
},
Err(msg) => {
warn!("Initial context creation failed, falling back to readback: {}", msg);
create_readback_painter(size, attrs, wr_api)
create_readback_painter(size, attrs, wr_api, gl_type)
}
}
}
Expand Down Expand Up @@ -165,7 +181,8 @@ impl WebGLPaintThread {
let (sender, receiver) = ipc::channel::<CanvasMsg>().unwrap();
let (result_chan, result_port) = channel();
thread::Builder::new().name("WebGLThread".to_owned()).spawn(move || {
let mut painter = match WebGLPaintThread::new(size, attrs, webrender_api_sender) {
let gl_type = gl::GlType::default();
let mut painter = match WebGLPaintThread::new(size, attrs, webrender_api_sender, gl_type) {
Ok((thread, limits)) => {
result_chan.send(Ok(limits)).unwrap();
thread
Expand Down Expand Up @@ -212,14 +229,14 @@ impl WebGLPaintThread {

fn send_data(&mut self, chan: IpcSender<CanvasData>) {
match self.data {
WebGLPaintTaskData::Readback(_, ref webrender_api, image_key) => {
WebGLPaintTaskData::Readback(ref ctx, ref webrender_api, image_key) => {
let width = self.size.width as usize;
let height = self.size.height as usize;

let mut pixels = gl::read_pixels(0, 0,
self.size.width as gl::GLsizei,
self.size.height as gl::GLsizei,
gl::RGBA, gl::UNSIGNED_BYTE);
let mut pixels = ctx.gl().read_pixels(0, 0,
self.size.width as gl::GLsizei,
self.size.height as gl::GLsizei,
gl::RGBA, gl::UNSIGNED_BYTE);
// flip image vertically (texture is upside down)
let orig_pixels = pixels.clone();
let stride = width * 4;
Expand Down Expand Up @@ -267,7 +284,7 @@ impl WebGLPaintThread {
self.size = try!(context.resize(size));
} else {
self.size = size;
unsafe { gl::Scissor(0, 0, size.width, size.height); }
context.gl().scissor(0, 0, size.width, size.height);
}
}
WebGLPaintTaskData::WebRender(ref api, id) => {
Expand Down
2 changes: 1 addition & 1 deletion components/compositing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ path = "lib.rs"
[dependencies]
euclid = "0.11"
gfx_traits = {path = "../gfx_traits"}
gleam = "0.2.8"
gleam = "0.4"
image = "0.12"
ipc-channel = "0.7"
log = "0.3.5"
Expand Down
90 changes: 48 additions & 42 deletions components/compositing/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D;
use gfx_traits::{Epoch, ScrollRootId};
use gleam::gl;
use gleam::gl::types::{GLint, GLsizei};
use image::{DynamicImage, ImageFormat, RgbImage};
use ipc_channel::ipc::{self, IpcSender, IpcSharedMemory};
use msg::constellation_msg::{Key, KeyModifiers, KeyState, CONTROL};
Expand All @@ -40,7 +39,7 @@ use style_traits::viewport::ViewportConstraints;
use time::{precise_time_ns, precise_time_s};
use touch::{TouchHandler, TouchAction};
use webrender;
use webrender_traits::{self, ScrollEventPhase, ServoScrollRootId, LayoutPoint, ScrollLocation};
use webrender_traits::{self, LayoutPoint, ScrollEventPhase, ScrollLayerId, ScrollLocation};
use windowing::{self, MouseWindowEvent, WindowEvent, WindowMethods, WindowNavigateMsg};

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -77,9 +76,9 @@ trait ConvertScrollRootIdFromWebRender {
fn from_webrender(&self) -> ScrollRootId;
}

impl ConvertScrollRootIdFromWebRender for webrender_traits::ServoScrollRootId {
impl ConvertScrollRootIdFromWebRender for usize {
fn from_webrender(&self) -> ScrollRootId {
ScrollRootId(self.0)
ScrollRootId(*self)
}
}

Expand Down Expand Up @@ -208,6 +207,9 @@ pub struct IOCompositor<Window: WindowMethods> {

/// The webrender interface, if enabled.
webrender_api: webrender_traits::RenderApi,

/// GL functions interface (may be GL or GLES)
gl: Rc<gl::Gl>,
}

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -291,34 +293,34 @@ impl RenderTargetInfo {
}
}

fn initialize_png(width: usize, height: usize) -> RenderTargetInfo {
let framebuffer_ids = gl::gen_framebuffers(1);
gl::bind_framebuffer(gl::FRAMEBUFFER, framebuffer_ids[0]);
fn initialize_png(gl: &gl::Gl, width: usize, height: usize) -> RenderTargetInfo {
let framebuffer_ids = gl.gen_framebuffers(1);
gl.bind_framebuffer(gl::FRAMEBUFFER, framebuffer_ids[0]);

let texture_ids = gl::gen_textures(1);
gl::bind_texture(gl::TEXTURE_2D, texture_ids[0]);
let texture_ids = gl.gen_textures(1);
gl.bind_texture(gl::TEXTURE_2D, texture_ids[0]);

gl::tex_image_2d(gl::TEXTURE_2D, 0, gl::RGB as GLint, width as GLsizei,
height as GLsizei, 0, gl::RGB, gl::UNSIGNED_BYTE, None);
gl::tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST as GLint);
gl::tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST as GLint);
gl.tex_image_2d(gl::TEXTURE_2D, 0, gl::RGB as gl::GLint, width as gl::GLsizei,
height as gl::GLsizei, 0, gl::RGB, gl::UNSIGNED_BYTE, None);
gl.tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST as gl::GLint);
gl.tex_parameter_i(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST as gl::GLint);

gl::framebuffer_texture_2d(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D,
texture_ids[0], 0);
gl.framebuffer_texture_2d(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D,
texture_ids[0], 0);

gl::bind_texture(gl::TEXTURE_2D, 0);
gl.bind_texture(gl::TEXTURE_2D, 0);

let renderbuffer_ids = gl::gen_renderbuffers(1);
let renderbuffer_ids = gl.gen_renderbuffers(1);
let depth_rb = renderbuffer_ids[0];
gl::bind_renderbuffer(gl::RENDERBUFFER, depth_rb);
gl::renderbuffer_storage(gl::RENDERBUFFER,
gl::DEPTH_COMPONENT24,
width as gl::GLsizei,
height as gl::GLsizei);
gl::framebuffer_renderbuffer(gl::FRAMEBUFFER,
gl::DEPTH_ATTACHMENT,
gl::RENDERBUFFER,
depth_rb);
gl.bind_renderbuffer(gl::RENDERBUFFER, depth_rb);
gl.renderbuffer_storage(gl::RENDERBUFFER,
gl::DEPTH_COMPONENT24,
width as gl::GLsizei,
height as gl::GLsizei);
gl.framebuffer_renderbuffer(gl::FRAMEBUFFER,
gl::DEPTH_ATTACHMENT,
gl::RENDERBUFFER,
depth_rb);

RenderTargetInfo {
framebuffer_ids: framebuffer_ids,
Expand Down Expand Up @@ -373,6 +375,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
};

IOCompositor {
gl: window.gl(),
window: window,
port: state.receiver,
root_pipeline: None,
Expand Down Expand Up @@ -791,10 +794,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
pipeline_id: PipelineId,
scroll_root_id: ScrollRootId,
point: Point2D<f32>) {
self.webrender_api.scroll_layers_with_scroll_root_id(
LayoutPoint::from_untyped(&point),
pipeline_id.to_webrender(),
ServoScrollRootId(scroll_root_id.0));
let id = ScrollLayerId::new(scroll_root_id.0, pipeline_id.to_webrender());
self.webrender_api.scroll_layer_with_id(LayoutPoint::from_untyped(&point), id);
}

fn handle_window_message(&mut self, event: WindowEvent) {
Expand Down Expand Up @@ -1386,13 +1387,18 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn send_viewport_rects(&self) {
let mut stacking_context_scroll_states_per_pipeline = HashMap::new();
for scroll_layer_state in self.webrender_api.get_scroll_layer_state() {
let external_id = match scroll_layer_state.id.external_id() {
Some(id) => id,
None => continue,
};

let stacking_context_scroll_state = StackingContextScrollState {
scroll_root_id: scroll_layer_state.scroll_root_id.from_webrender(),
scroll_root_id: external_id.from_webrender(),
scroll_offset: scroll_layer_state.scroll_offset.to_untyped(),
};
let pipeline_id = scroll_layer_state.pipeline_id;

stacking_context_scroll_states_per_pipeline
.entry(pipeline_id)
.entry(scroll_layer_state.id.pipeline_id())
.or_insert(vec![])
.push(stacking_context_scroll_state);
}
Expand Down Expand Up @@ -1529,7 +1535,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {

let render_target_info = match target {
CompositeTarget::Window => RenderTargetInfo::empty(),
_ => initialize_png(width, height)
_ => initialize_png(&*self.gl, width, height)
};

profile(ProfilerCategory::Compositing, None, self.time_profiler_chan.clone(), || {
Expand Down Expand Up @@ -1593,16 +1599,16 @@ impl<Window: WindowMethods> IOCompositor<Window> {
width: usize,
height: usize)
-> RgbImage {
let mut pixels = gl::read_pixels(0, 0,
width as gl::GLsizei,
height as gl::GLsizei,
gl::RGB, gl::UNSIGNED_BYTE);
let mut pixels = self.gl.read_pixels(0, 0,
width as gl::GLsizei,
height as gl::GLsizei,
gl::RGB, gl::UNSIGNED_BYTE);

gl::bind_framebuffer(gl::FRAMEBUFFER, 0);
self.gl.bind_framebuffer(gl::FRAMEBUFFER, 0);

gl::delete_buffers(&render_target_info.texture_ids);
gl::delete_renderbuffers(&render_target_info.renderbuffer_ids);
gl::delete_frame_buffers(&render_target_info.framebuffer_ids);
self.gl.delete_buffers(&render_target_info.texture_ids);
self.gl.delete_renderbuffers(&render_target_info.renderbuffer_ids);
self.gl.delete_framebuffers(&render_target_info.framebuffer_ids);

// flip image vertically (texture is upside down)
let orig_pixels = pixels.clone();
Expand Down
5 changes: 5 additions & 0 deletions components/compositing/windowing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ use euclid::point::TypedPoint2D;
use euclid::rect::TypedRect;
use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D;
use gleam::gl;
use msg::constellation_msg::{Key, KeyModifiers, KeyState};
use net_traits::net_error_list::NetError;
use script_traits::{DevicePixel, MouseButton, TouchEventType, TouchId, TouchpadPressurePhase};
use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl;
use std::fmt::{Debug, Error, Formatter};
use std::rc::Rc;
use style_traits::cursor::Cursor;
use webrender_traits::ScrollLocation;

Expand Down Expand Up @@ -168,4 +170,7 @@ pub trait WindowMethods {

/// Add a favicon
fn set_favicon(&self, url: ServoUrl);

/// Return the GL function pointer trait.
fn gl(&self) -> Rc<gl::Gl>;
}
2 changes: 1 addition & 1 deletion components/constellation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ layout_traits = {path = "../layout_traits"}
log = "0.3.5"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
offscreen_gl_context = "0.6"
offscreen_gl_context = "0.8"
profile_traits = {path = "../profile_traits"}
script_traits = {path = "../script_traits"}
serde = "0.9"
Expand Down
1 change: 1 addition & 0 deletions components/gfx/display_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ impl StackingContext {
pub fn to_display_list_items(self) -> (DisplayItem, DisplayItem) {
let mut base_item = BaseDisplayItem::empty();
base_item.stacking_context_id = self.id;
base_item.scroll_root_id = self.parent_scroll_id;

let pop_item = DisplayItem::PopStackingContext(Box::new(
PopStackingContextItem {
Expand Down
5 changes: 3 additions & 2 deletions components/layout/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2233,10 +2233,11 @@ impl Flow for BlockFlow {

fn compute_overflow(&self) -> Overflow {
let flow_size = self.base.position.size.to_physical(self.base.writing_mode);
self.fragment.compute_overflow(&flow_size,
let overflow = self.fragment.compute_overflow(&flow_size,
&self.base
.early_absolute_position_info
.relative_containing_block_size)
.relative_containing_block_size);
overflow
}

fn iterate_through_fragment_border_boxes(&self,
Expand Down
Loading

0 comments on commit c99289a

Please sign in to comment.