Share some code between 2D canvas and WebGL

This commit is contained in:
Anthony Ramine 2018-10-08 13:49:58 +02:00
parent 05ef233097
commit 6c469b90b1
6 changed files with 58 additions and 84 deletions

View file

@ -6,7 +6,6 @@ use canvas_traits::webgl::*;
use euclid::Size2D;
use fnv::FnvHashMap;
use gleam::gl;
use ipc_channel::ipc::IpcBytesSender;
use offscreen_gl_context::{GLContext, GLContextAttributes, GLLimits, NativeGLContextMethods};
use pixels;
use std::thread;
@ -791,8 +790,16 @@ impl WebGLImpl {
ctx.gl().pixel_store_i(name, val),
WebGLCommand::PolygonOffset(factor, units) =>
ctx.gl().polygon_offset(factor, units),
WebGLCommand::ReadPixels(x, y, width, height, format, pixel_type, ref chan) => {
Self::read_pixels(ctx.gl(), x, y, width, height, format, pixel_type, chan)
WebGLCommand::ReadPixels(rect, format, pixel_type, ref sender) => {
let pixels = ctx.gl().read_pixels(
rect.origin.x as i32,
rect.origin.y as i32,
rect.size.width as i32,
rect.size.height as i32,
format,
pixel_type,
);
sender.send(&pixels).unwrap();
}
WebGLCommand::RenderbufferStorage(target, format, width, height) =>
ctx.gl().renderbuffer_storage(target, format, width, height),
@ -1335,20 +1342,6 @@ impl WebGLImpl {
}
}
fn read_pixels(
gl: &gl::Gl,
x: i32,
y: i32,
width: i32,
height: i32,
format: u32,
pixel_type: u32,
chan: &IpcBytesSender,
) {
let result = gl.read_pixels(x, y, width, height, format, pixel_type);
chan.send(&result).unwrap()
}
fn finish(gl: &gl::Gl, chan: &WebGLSender<()>) {
gl.finish();
chan.send(()).unwrap();