Skip to content

Commit

Permalink
Update WR (gl/es runtime table, scroll roots).
Browse files Browse the repository at this point in the history
  • Loading branch information
gw3583 committed Mar 23, 2017
1 parent 9d72e89 commit fe75382
Show file tree
Hide file tree
Showing 19 changed files with 212 additions and 174 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
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
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
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
67 changes: 35 additions & 32 deletions components/compositing/compositor.rs
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 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 @@ -1532,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 @@ -1596,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
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
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
2 changes: 1 addition & 1 deletion components/script/Cargo.toml
Expand Up @@ -60,7 +60,7 @@ mime_guess = "1.8.0"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
num-traits = "0.1.32"
offscreen_gl_context = "0.6"
offscreen_gl_context = "0.8"
open = "1.1.1"
parking_lot = "0.3"
phf = "0.7.18"
Expand Down
2 changes: 1 addition & 1 deletion components/script_traits/Cargo.toml
Expand Up @@ -25,7 +25,7 @@ ipc-channel = "0.7"
libc = "0.2"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
offscreen_gl_context = "0.6"
offscreen_gl_context = "0.8"
profile_traits = {path = "../profile_traits"}
rustc-serialize = "0.3.4"
serde = "0.9"
Expand Down
2 changes: 1 addition & 1 deletion components/servo/Cargo.toml
Expand Up @@ -32,7 +32,7 @@ devtools_traits = {path = "../devtools_traits"}
env_logger = "0.4"
euclid = "0.11"
gfx = {path = "../gfx"}
gleam = "0.2"
gleam = "0.4"
ipc-channel = "0.7"
layout_thread = {path = "../layout_thread"}
log = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion components/servo/lib.rs
Expand Up @@ -177,7 +177,7 @@ impl<Window> Browser<Window> where Window: WindowMethods + 'static {
let framebuffer_size = webrender_traits::DeviceUintSize::new(framebuffer_size.width,
framebuffer_size.height);

webrender::Renderer::new(webrender::RendererOptions {
webrender::Renderer::new(window.gl(), webrender::RendererOptions {
device_pixel_ratio: device_pixel_ratio,
resource_override_path: Some(resource_path),
enable_aa: opts.enable_text_antialiasing,
Expand Down
2 changes: 1 addition & 1 deletion ports/cef/Cargo.toml
Expand Up @@ -21,7 +21,7 @@ debugmozjs = ["libservo/debugmozjs"]
compositing = {path = "../../components/compositing"}
devtools = {path = "../../components/devtools"}
euclid = "0.11"
gleam = "0.2.8"
gleam = "0.4"
glutin_app = {path = "../glutin"}
libc = "0.2"
libservo = {path = "../../components/servo"}
Expand Down

0 comments on commit fe75382

Please sign in to comment.