diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-12-01 03:04:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-01 03:04:49 -0800 |
commit | 94eefc4001e0998fcea5a35943da73624ea82b13 (patch) | |
tree | f3f89f11b11473c6cd86e7eefaebcaa4547906ab /components/script/dom/webglrenderingcontext.rs | |
parent | 0d896a8d820e31037d536f133b5a8b8c43c2e1a2 (diff) | |
parent | 8ba75c0545f26b7577a70aff71aa619128dc870b (diff) | |
download | servo-94eefc4001e0998fcea5a35943da73624ea82b13.tar.gz servo-94eefc4001e0998fcea5a35943da73624ea82b13.zip |
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 -->
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 706dee4834b..76bfd9e10ce 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -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() |