mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
webgl: Implement multiple calls and improve error detection
This commit implements WebGL's: * cullFace * frontFace * enable * disable * depthMask * colorMask * clearDepth * clearStencil * depthFunc * depthRange * hint * lineWidth * pixelStorei * polygonOffset * texParameteri * texParameterf * texImage2D (partially) It inlines a lot of OpenGL calls to keep the file `components/canvas/webgl_paint_task.rs` as small as possible while keeping readability. It also improves error detection on previous calls, and sets node damage on the canvas in the drawing calls. It adds a `TexImage2D` reftest, even though it's not enabled because: * WebGL paints the image when it loads (asynchronously), so the reftest doesn't wait for it and it finishes early * If we change the source for the base64 src of the image it works as expected in non-headless mode, but the test harness locks
This commit is contained in:
parent
af3310f149
commit
6341c77700
12 changed files with 763 additions and 226 deletions
|
@ -17,11 +17,16 @@ use dom::bindings::num::Finite;
|
|||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::canvasgradient::{CanvasGradient, CanvasGradientStyle, ToFillOrStrokeStyle};
|
||||
use dom::canvaspattern::CanvasPattern;
|
||||
use dom::htmlcanvaselement::utils as canvas_utils;
|
||||
use dom::htmlcanvaselement::{HTMLCanvasElement, HTMLCanvasElementHelpers};
|
||||
use dom::htmlimageelement::{HTMLImageElement, HTMLImageElementHelpers};
|
||||
use dom::imagedata::{ImageData, ImageDataHelpers};
|
||||
use dom::node::{window_from_node, NodeHelpers, NodeDamage};
|
||||
|
||||
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||
use net_traits::image::base::PixelFormat;
|
||||
use net_traits::image_cache_task::ImageResponse;
|
||||
|
||||
use cssparser::Color as CSSColor;
|
||||
use cssparser::{Parser, RGBA};
|
||||
use euclid::matrix2d::Matrix2D;
|
||||
|
@ -34,10 +39,6 @@ use canvas_traits::{CanvasMsg, Canvas2dMsg, CanvasCommonMsg};
|
|||
use canvas_traits::{FillOrStrokeStyle, LinearGradientStyle, RadialGradientStyle, RepetitionStyle};
|
||||
use canvas_traits::{LineCapStyle, LineJoinStyle, CompositionOrBlending};
|
||||
|
||||
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||
use net_traits::image::base::PixelFormat;
|
||||
use net_traits::image_cache_task::{ImageCacheChan, ImageResponse};
|
||||
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use num::{Float, ToPrimitive};
|
||||
use std::borrow::ToOwned;
|
||||
|
@ -201,7 +202,7 @@ impl CanvasRenderingContext2D {
|
|||
Size2D::new(source_rect_clipped.size.width,
|
||||
source_rect_clipped.size.height));
|
||||
|
||||
return (source_rect, dest_rect)
|
||||
(source_rect, dest_rect)
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -364,9 +365,10 @@ impl CanvasRenderingContext2D {
|
|||
PixelFormat::KA8 => panic!("KA8 color type not supported"),
|
||||
};
|
||||
|
||||
return Some((image_data, image_size));
|
||||
Some((image_data, image_size))
|
||||
}
|
||||
|
||||
// TODO(ecoal95): Move this to `HTMLCanvasElement`, and support WebGL contexts
|
||||
fn fetch_canvas_data(&self,
|
||||
canvas_element: &HTMLCanvasElement,
|
||||
source_rect: Rect<f64>)
|
||||
|
@ -385,18 +387,14 @@ impl CanvasRenderingContext2D {
|
|||
renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::GetImageData(source_rect.to_i32(),
|
||||
image_size, sender))).unwrap();
|
||||
|
||||
return Some((receiver.recv().unwrap(), image_size));
|
||||
Some((receiver.recv().unwrap(), image_size))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn request_image_from_cache(&self, url: Url) -> ImageResponse {
|
||||
let canvas = self.canvas.root();
|
||||
let window = window_from_node(canvas.r());
|
||||
let window = window.r();
|
||||
let image_cache = window.image_cache_task();
|
||||
let (response_chan, response_port) = ipc::channel().unwrap();
|
||||
image_cache.request_image(url, ImageCacheChan(response_chan), None);
|
||||
let result = response_port.recv().unwrap();
|
||||
result.image_response
|
||||
canvas_utils::request_image_from_cache(window.r(), url)
|
||||
}
|
||||
|
||||
fn create_drawable_rect(&self, x: f64, y: f64, w: f64, h: f64) -> Option<Rect<f32>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue