mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Auto merge of #14075 - MortimerGoro:webgl-resize, r=MortimerGoro
Implement WebGLContext resize <!-- Please describe your changes on the following line: --> Related PR: https://github.com/servo/webrender/pull/519 Implement WebGLContext resize (canvas.width & canvas.height). I have tested: - Fixes WebGL apps that initialize canvas size after calling canvas.getContext("webgl") - Support WebGL apps that change the canvas size & viewport on window.onresize --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14075) <!-- Reviewable:end -->
This commit is contained in:
commit
94eefc4001
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)",
|
||||
"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"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -133,6 +133,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 {
|
||||
|
@ -163,6 +167,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))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -203,6 +209,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> {
|
||||
|
@ -1136,6 +1158,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()
|
||||
|
@ -1903,6 +1926,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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue