Layerize canvas

Note that this keeps using readback right now, `NativeSurface` painting
will be implemented soon.

Also see https://github.com/servo/servo/issues/6142
This commit is contained in:
ecoal95 2015-05-20 10:29:08 +02:00
parent 6481058309
commit 3350522306
35 changed files with 769 additions and 500 deletions

View file

@ -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/. */
use canvas_msg::{CanvasMsg, CanvasWebGLMsg, CanvasCommonMsg};
use canvas_traits::{CanvasMsg, CanvasWebGLMsg, CanvasCommonMsg};
use geom::size::Size2D;
use gleam::gl;
@ -14,7 +14,8 @@ use std::borrow::ToOwned;
use std::slice::bytes::copy_memory;
use std::sync::mpsc::{channel, Sender};
use util::vec::byte_swap;
use offscreen_gl_context::{GLContext, GLContextAttributes};
use layers::platform::surface::NativeSurface;
use offscreen_gl_context::{GLContext, GLContextAttributes, ColorAttachmentType};
pub struct WebGLPaintTask {
size: Size2D<i32>,
@ -29,7 +30,9 @@ unsafe impl Send for WebGLPaintTask {}
impl WebGLPaintTask {
fn new(size: Size2D<i32>) -> Result<WebGLPaintTask, &'static str> {
// TODO(ecoal95): Get the GLContextAttributes from the `GetContext` call
let context = try!(GLContext::create_offscreen(size, GLContextAttributes::default()));
let context = try!(GLContext::create_offscreen_with_color_attachment(size,
GLContextAttributes::default(),
ColorAttachmentType::TextureWithSurface));
Ok(WebGLPaintTask {
size: size,
original_context_size: size,
@ -76,7 +79,10 @@ impl WebGLPaintTask {
CanvasMsg::Common(message) => {
match message {
CanvasCommonMsg::Close => break,
CanvasCommonMsg::SendPixelContents(chan) => painter.send_pixel_contents(chan),
CanvasCommonMsg::SendPixelContents(chan) =>
painter.send_pixel_contents(chan),
CanvasCommonMsg::SendNativeSurface(chan) =>
painter.send_native_surface(chan),
// TODO(ecoal95): handle error nicely
CanvasCommonMsg::Recreate(size) => painter.recreate(size).unwrap(),
}
@ -184,6 +190,12 @@ impl WebGLPaintTask {
chan.send(pixels).unwrap();
}
fn send_native_surface(&self, _: Sender<NativeSurface>) {
// FIXME(ecoal95): We need to make a clone of the surface in order to
// implement this
unimplemented!()
}
fn shader_source(&self, shader_id: u32, source_lines: Vec<String>) {
let mut lines: Vec<&[u8]> = source_lines.iter().map(|line| line.as_bytes()).collect();
gl::shader_source(shader_id, &mut lines);