mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implement WebGLContext resize, r=emilio
This commit is contained in:
parent
b3cdcfaa39
commit
8ba75c0545
3 changed files with 34 additions and 10 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -243,7 +243,7 @@ dependencies = [
|
||||||
"ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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",
|
"plugins 0.0.1",
|
||||||
"util 0.0.1",
|
"util 0.0.1",
|
||||||
"webrender_traits 0.11.0 (git+https://github.com/servo/webrender)",
|
"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)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
"net_traits 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",
|
"plugins 0.0.1",
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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]]
|
[[package]]
|
||||||
name = "offscreen_gl_context"
|
name = "offscreen_gl_context"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2191,7 +2191,7 @@ dependencies = [
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
"net_traits 0.0.1",
|
"net_traits 0.0.1",
|
||||||
"num-traits 0.1.35 (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)",
|
||||||
"open 1.1.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)",
|
"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)",
|
"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)",
|
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
"net_traits 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",
|
"plugins 0.0.1",
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"webrender_traits 0.11.0 (git+https://github.com/servo/webrender)",
|
"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)",
|
"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)",
|
"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)",
|
"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 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)",
|
"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 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 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 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 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 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"
|
"checksum open 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c228597177bc4a6876e278f7c7948ac033bfcb4d163ccdd5a009557c8fe5fa1e"
|
||||||
|
|
|
@ -251,8 +251,8 @@ impl WebGLPaintThread {
|
||||||
unsafe { gl::Scissor(0, 0, size.width, size.height); }
|
unsafe { gl::Scissor(0, 0, size.width, size.height); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WebGLPaintTaskData::WebRender(_, _) => {
|
WebGLPaintTaskData::WebRender(ref api, id) => {
|
||||||
// TODO
|
api.resize_webgl_context(id, &size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,10 @@ pub struct WebGLRenderingContext {
|
||||||
current_program: MutNullableHeap<JS<WebGLProgram>>,
|
current_program: MutNullableHeap<JS<WebGLProgram>>,
|
||||||
#[ignore_heap_size_of = "Because it's small"]
|
#[ignore_heap_size_of = "Because it's small"]
|
||||||
current_vertex_attrib_0: Cell<(f32, f32, f32, f32)>,
|
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 {
|
impl WebGLRenderingContext {
|
||||||
|
@ -162,6 +166,8 @@ impl WebGLRenderingContext {
|
||||||
bound_renderbuffer: MutNullableHeap::new(None),
|
bound_renderbuffer: MutNullableHeap::new(None),
|
||||||
current_program: MutNullableHeap::new(None),
|
current_program: MutNullableHeap::new(None),
|
||||||
current_vertex_attrib_0: Cell::new((0f32, 0f32, 0f32, 1f32)),
|
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>) {
|
pub fn recreate(&self, size: Size2D<i32>) {
|
||||||
self.ipc_renderer.send(CanvasMsg::Common(CanvasCommonMsg::Recreate(size))).unwrap();
|
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> {
|
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
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
|
||||||
fn ClearColor(&self, red: f32, green: f32, blue: f32, alpha: f32) {
|
fn ClearColor(&self, red: f32, green: f32, blue: f32, alpha: f32) {
|
||||||
|
self.current_clear_color.set((red, green, blue, alpha));
|
||||||
self.ipc_renderer
|
self.ipc_renderer
|
||||||
.send(CanvasMsg::WebGL(WebGLCommand::ClearColor(red, green, blue, alpha)))
|
.send(CanvasMsg::WebGL(WebGLCommand::ClearColor(red, green, blue, alpha)))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -1902,6 +1925,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
return self.webgl_error(InvalidValue)
|
return self.webgl_error(InvalidValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.current_scissor.set((x, y, width, height));
|
||||||
self.ipc_renderer
|
self.ipc_renderer
|
||||||
.send(CanvasMsg::WebGL(WebGLCommand::Scissor(x, y, width, height)))
|
.send(CanvasMsg::WebGL(WebGLCommand::Scissor(x, y, width, height)))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue