forked from mirrors/gecko-dev
<!-- Please describe your changes on the following line: --> Info about the big picture and the goals of the WebGL refactor in this thread: https://groups.google.com/forum/#!topic/mozilla.dev.servo/0WMGz60kKzQ I tried to reduce this PR as much as possible as requested in the thread. I'll do separate PRs for other features (e.g.: Batch messages or use shared memory to improve frame times) or fixes. Some tips to ease the review process: - Most changes in DOM objects follow the same pattern (remove CanvasMsg wrapper and use the new sender method). - WebGLCommands are the same ones as before (moved from webrender_api). So those lines are already reviewed. - See WebGL traits in [components/canvas_traits/webgl.rs](https://github.com/servo/servo/pull/17891/files#diff-8701045d01505418701d0631d4d45562) - See WebGLThread and WR External Image bridge in [components/canvas/webgl_thread.rs](https://github.com/servo/servo/pull/17891/files#diff-281554879f39a2a041f7a69d442a5d2e) - The implementation submitted in this PR creates a single `WebGLThread` for all ScriptThread/Pipelines. See that in [components/canvas/webgl_mode/inprocess.rs](https://github.com/servo/servo/pull/17891/files#diff-250070c6c5a38c7f9fa0f5b3c101f68b) The conformance tests will help to guarantee that we don't miss anything. --- <!-- 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 _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 90f55ea4580e2a15f7d70d0491444f18b972d450 --HG-- rename : servo/tests/unit/style/rule_tree/mod.rs => servo/components/canvas/webgl_mode/mod.rs rename : servo/components/canvas_traits/lib.rs => servo/components/canvas_traits/canvas.rs extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : d476816b29986c4abfd61ff3c7b46aa189f2f50a
117 lines
3.8 KiB
Rust
117 lines
3.8 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
|
|
use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLRenderbufferId, WebGLResult};
|
|
use dom::bindings::codegen::Bindings::WebGLRenderbufferBinding;
|
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
|
use dom::bindings::js::Root;
|
|
use dom::bindings::reflector::reflect_dom_object;
|
|
use dom::webglobject::WebGLObject;
|
|
use dom::window::Window;
|
|
use dom_struct::dom_struct;
|
|
use std::cell::Cell;
|
|
|
|
#[dom_struct]
|
|
pub struct WebGLRenderbuffer {
|
|
webgl_object: WebGLObject,
|
|
id: WebGLRenderbufferId,
|
|
ever_bound: Cell<bool>,
|
|
is_deleted: Cell<bool>,
|
|
size: Cell<Option<(i32, i32)>>,
|
|
internal_format: Cell<Option<u32>>,
|
|
#[ignore_heap_size_of = "Defined in ipc-channel"]
|
|
renderer: WebGLMsgSender,
|
|
}
|
|
|
|
impl WebGLRenderbuffer {
|
|
fn new_inherited(renderer: WebGLMsgSender,
|
|
id: WebGLRenderbufferId)
|
|
-> WebGLRenderbuffer {
|
|
WebGLRenderbuffer {
|
|
webgl_object: WebGLObject::new_inherited(),
|
|
id: id,
|
|
ever_bound: Cell::new(false),
|
|
is_deleted: Cell::new(false),
|
|
renderer: renderer,
|
|
internal_format: Cell::new(None),
|
|
size: Cell::new(None),
|
|
}
|
|
}
|
|
|
|
pub fn maybe_new(window: &Window, renderer: WebGLMsgSender)
|
|
-> Option<Root<WebGLRenderbuffer>> {
|
|
let (sender, receiver) = webgl_channel().unwrap();
|
|
renderer.send(WebGLCommand::CreateRenderbuffer(sender)).unwrap();
|
|
|
|
let result = receiver.recv().unwrap();
|
|
result.map(|renderbuffer_id| WebGLRenderbuffer::new(window, renderer, renderbuffer_id))
|
|
}
|
|
|
|
pub fn new(window: &Window,
|
|
renderer: WebGLMsgSender,
|
|
id: WebGLRenderbufferId)
|
|
-> Root<WebGLRenderbuffer> {
|
|
reflect_dom_object(box WebGLRenderbuffer::new_inherited(renderer, id),
|
|
window,
|
|
WebGLRenderbufferBinding::Wrap)
|
|
}
|
|
}
|
|
|
|
|
|
impl WebGLRenderbuffer {
|
|
pub fn id(&self) -> WebGLRenderbufferId {
|
|
self.id
|
|
}
|
|
|
|
pub fn size(&self) -> Option<(i32, i32)> {
|
|
self.size.get()
|
|
}
|
|
|
|
pub fn bind(&self, target: u32) {
|
|
self.ever_bound.set(true);
|
|
let msg = WebGLCommand::BindRenderbuffer(target, Some(self.id));
|
|
self.renderer.send(msg).unwrap();
|
|
}
|
|
|
|
pub fn delete(&self) {
|
|
if !self.is_deleted.get() {
|
|
self.is_deleted.set(true);
|
|
let _ = self.renderer.send(WebGLCommand::DeleteRenderbuffer(self.id));
|
|
}
|
|
}
|
|
|
|
pub fn is_deleted(&self) -> bool {
|
|
self.is_deleted.get()
|
|
}
|
|
|
|
pub fn ever_bound(&self) -> bool {
|
|
self.ever_bound.get()
|
|
}
|
|
|
|
pub fn storage(&self, internal_format: u32, width: i32, height: i32) -> WebGLResult<()> {
|
|
// Validate the internal_format, and save it for completeness
|
|
// validation.
|
|
match internal_format {
|
|
constants::RGBA4 |
|
|
constants::DEPTH_STENCIL |
|
|
constants::DEPTH_COMPONENT16 |
|
|
constants::STENCIL_INDEX8 =>
|
|
self.internal_format.set(Some(internal_format)),
|
|
|
|
_ => return Err(WebGLError::InvalidEnum),
|
|
};
|
|
|
|
// FIXME: Check that w/h are < MAX_RENDERBUFFER_SIZE
|
|
|
|
// FIXME: Invalidate completeness after the call
|
|
|
|
let msg = WebGLCommand::RenderbufferStorage(constants::RENDERBUFFER, internal_format, width, height);
|
|
self.renderer.send(msg).unwrap();
|
|
|
|
self.size.set(Some((width, height)));
|
|
|
|
Ok(())
|
|
}
|
|
}
|