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
|
@ -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