aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorImanol Fernandez <mortimergoro@gmail.com>2016-12-01 00:39:32 +0100
committerImanol Fernandez <mortimergoro@gmail.com>2016-12-01 00:56:59 +0100
commit8ba75c0545f26b7577a70aff71aa619128dc870b (patch)
tree998b35b85f53481bee1325d6544f60700812bc4b
parentb3cdcfaa39a7933a9f87a6881f5d58e5afe94086 (diff)
downloadservo-8ba75c0545f26b7577a70aff71aa619128dc870b.tar.gz
servo-8ba75c0545f26b7577a70aff71aa619128dc870b.zip
Implement WebGLContext resize, r=emilio
-rw-r--r--Cargo.lock16
-rw-r--r--components/canvas/webgl_paint_thread.rs4
-rw-r--r--components/script/dom/webglrenderingcontext.rs24
3 files changed, 34 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 595920a4445..b6feed22ff0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -243,7 +243,7 @@ dependencies = [
"ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
- "offscreen_gl_context 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "offscreen_gl_context 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",
"util 0.0.1",
"webrender_traits 0.11.0 (git+https://github.com/servo/webrender)",
@@ -388,7 +388,7 @@ dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",
- "offscreen_gl_context 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "offscreen_gl_context 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",
"profile_traits 0.0.1",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1801,7 +1801,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "offscreen_gl_context"
-version = "0.5.0"
+version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2191,7 +2191,7 @@ dependencies = [
"msg 0.0.1",
"net_traits 0.0.1",
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
- "offscreen_gl_context 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "offscreen_gl_context 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2279,7 +2279,7 @@ dependencies = [
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",
- "offscreen_gl_context 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "offscreen_gl_context 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",
"profile_traits 0.0.1",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3065,7 +3065,7 @@ dependencies = [
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
- "offscreen_gl_context 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "offscreen_gl_context 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_traits 0.11.0 (git+https://github.com/servo/webrender)",
@@ -3084,7 +3084,7 @@ dependencies = [
"gleam 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "offscreen_gl_context 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "offscreen_gl_context 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.18 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 0.8.18 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -3329,7 +3329,7 @@ dependencies = [
"checksum num_cpus 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8890e6084723d57d0df8d2720b0d60c6ee67d6c93e7169630e4371e88765dcad"
"checksum objc 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7c9311aa5acd7bee14476afa0f0557f564e9d0d61218a8b833d9b1f871fa5fba"
"checksum odds 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "f3701cfdec1676e319ad37ff96c31de39df8c92006032976153366f52693bf40"
-"checksum offscreen_gl_context 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9da33a538d9c8fc81102e5d5c1ed844568b400d86c22413550a9b8474be62ba3"
+"checksum offscreen_gl_context 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2fe2fe54ba2b6ea8f43a17b16c13168c5bbf008e0fc91b34122a11f637e2728a"
"checksum ogg 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "426d8dc59cdd206be1925461087350385c0a02f291d87625829c6d08e72b457b"
"checksum ogg_metadata 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e755cc735fa6faa709cb23048433d9201d6caa85fa96215386ccdd5e9b40ad01"
"checksum open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c228597177bc4a6876e278f7c7948ac033bfcb4d163ccdd5a009557c8fe5fa1e"
diff --git a/components/canvas/webgl_paint_thread.rs b/components/canvas/webgl_paint_thread.rs
index 13a69718f2d..8a080aa639a 100644
--- a/components/canvas/webgl_paint_thread.rs
+++ b/components/canvas/webgl_paint_thread.rs
@@ -251,8 +251,8 @@ impl WebGLPaintThread {
unsafe { gl::Scissor(0, 0, size.width, size.height); }
}
}
- WebGLPaintTaskData::WebRender(_, _) => {
- // TODO
+ WebGLPaintTaskData::WebRender(ref api, id) => {
+ api.resize_webgl_context(id, &size);
}
}
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index f43576fba63..4f87e2e9339 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -132,6 +132,10 @@ pub struct WebGLRenderingContext {
current_program: MutNullableHeap<JS<WebGLProgram>>,
#[ignore_heap_size_of = "Because it's small"]
current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,
+ #[ignore_heap_size_of = "Because it's small"]
+ current_scissor: Cell<(i32, i32, i32, i32)>,
+ #[ignore_heap_size_of = "Because it's small"]
+ current_clear_color: Cell<(f32, f32, f32, f32)>,
}
impl WebGLRenderingContext {
@@ -162,6 +166,8 @@ impl WebGLRenderingContext {
bound_renderbuffer: MutNullableHeap::new(None),
current_program: MutNullableHeap::new(None),
current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)),
+ current_scissor: Cell::new((0, 0, size.width, size.height)),
+ current_clear_color: Cell::new((0.0, 0.0, 0.0, 0.0))
}
})
}
@@ -202,6 +208,22 @@ impl WebGLRenderingContext {
pub fn recreate(&self, size: Size2D<i32>) {
self.ipc_renderer.send(CanvasMsg::Common(CanvasCommonMsg::Recreate(size))).unwrap();
+
+ // ClearColor needs to be restored because after a resize the GLContext is recreated
+ // and the framebuffer is cleared using the default black transparent color.
+ let color = self.current_clear_color.get();
+ self.ipc_renderer
+ .send(CanvasMsg::WebGL(WebGLCommand::ClearColor(color.0, color.1, color.2, color.3)))
+ .unwrap();
+
+ // WebGL Spec: Scissor rect must not change if the canvas is resized.
+ // See: webgl/conformance-1.0.3/conformance/rendering/gl-scissor-canvas-dimensions.html
+ // NativeContext handling library changes the scissor after a resize, so we need to reset the
+ // default scissor when the canvas was created or the last scissor that the user set.
+ let rect = self.current_scissor.get();
+ self.ipc_renderer
+ .send(CanvasMsg::WebGL(WebGLCommand::Scissor(rect.0, rect.1, rect.2, rect.3)))
+ .unwrap()
}
pub fn ipc_renderer(&self) -> IpcSender<CanvasMsg> {
@@ -1135,6 +1157,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn ClearColor(&self, red: f32, green: f32, blue: f32, alpha: f32) {
+ self.current_clear_color.set((red, green, blue, alpha));
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::ClearColor(red, green, blue, alpha)))
.unwrap()
@@ -1902,6 +1925,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
return self.webgl_error(InvalidValue)
}
+ self.current_scissor.set((x, y, width, height));
self.ipc_renderer
.send(CanvasMsg::WebGL(WebGLCommand::Scissor(x, y, width, height)))
.unwrap()