aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webgl2renderingcontext.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-10-02 09:07:04 -0400
committerGitHub <noreply@github.com>2019-10-02 09:07:04 -0400
commit13a43e69e0fa16540ec02b6fc3569202470e9e5d (patch)
tree2156ca28bf21ec26a41bca94a0cc5ec0a8610ec3 /components/script/dom/webgl2renderingcontext.rs
parentb6df281b80927621a8c7b2eca7c5f7b24511e525 (diff)
parent248545ddda503e06bc59b5274c63a6c25da4b355 (diff)
downloadservo-13a43e69e0fa16540ec02b6fc3569202470e9e5d.tar.gz
servo-13a43e69e0fa16540ec02b6fc3569202470e9e5d.zip
Auto merge of #24250 - imiklos:webglsync, r=jdm
Initial implementation of WebGLSync This patch adds initial support for [WebGLSync](https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.14). Note: There is no test for the isSync, deleteSync and waitSync functions in the `conformance2/sync/sync-webgl-specific.html`. --- <!-- 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 <!-- Either: --> - [X] There are tests for these changes <!-- 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. --> <!-- 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/24250) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/webgl2renderingcontext.rs')
-rw-r--r--components/script/dom/webgl2renderingcontext.rs132
1 files changed, 128 insertions, 4 deletions
diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs
index f33b10f7931..ec959177d32 100644
--- a/components/script/dom/webgl2renderingcontext.rs
+++ b/components/script/dom/webgl2renderingcontext.rs
@@ -28,17 +28,18 @@ use crate::dom::webglrenderingcontext::{
};
use crate::dom::webglshader::WebGLShader;
use crate::dom::webglshaderprecisionformat::WebGLShaderPrecisionFormat;
+use crate::dom::webglsync::WebGLSync;
use crate::dom::webgltexture::WebGLTexture;
use crate::dom::webgluniformlocation::WebGLUniformLocation;
use crate::dom::window::Window;
use crate::script_runtime::JSContext;
-/// https://www.khronos.org/registry/webgl/specs/latest/2.0/webgl.idl
use canvas_traits::webgl::WebGLError::*;
-use canvas_traits::webgl::{GLContextAttributes, WebGLVersion};
+/// https://www.khronos.org/registry/webgl/specs/latest/2.0/webgl.idl
+use canvas_traits::webgl::{webgl_channel, GLContextAttributes, WebGLCommand, WebGLVersion};
use dom_struct::dom_struct;
use euclid::default::Size2D;
use js::jsapi::JSObject;
-use js::jsval::{BooleanValue, JSVal, NullValue, UInt32Value};
+use js::jsval::{BooleanValue, Int32Value, JSVal, NullValue, UInt32Value};
use js::rust::CustomAutoRooterGuard;
use js::typedarray::ArrayBufferView;
use script_layout_interface::HTMLCanvasDataSource;
@@ -125,7 +126,12 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
#[allow(unsafe_code)]
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
fn GetParameter(&self, cx: JSContext, parameter: u32) -> JSVal {
- self.base.GetParameter(cx, parameter)
+ match parameter {
+ constants::MAX_CLIENT_WAIT_TIMEOUT_WEBGL => {
+ Int32Value(self.base.limits().max_client_wait_timeout_webgl.as_nanos() as i32)
+ },
+ _ => self.base.GetParameter(cx, parameter),
+ }
}
/// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
@@ -1197,6 +1203,124 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
},
}
}
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.14
+ fn FenceSync(&self, condition: u32, flags: u32) -> Option<DomRoot<WebGLSync>> {
+ if flags != 0 {
+ self.base.webgl_error(InvalidValue);
+ return None;
+ }
+ if condition != constants::SYNC_GPU_COMMANDS_COMPLETE {
+ self.base.webgl_error(InvalidEnum);
+ return None;
+ }
+
+ Some(WebGLSync::new(&self.base))
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.14
+ fn IsSync(&self, sync: Option<&WebGLSync>) -> bool {
+ match sync {
+ Some(sync) => {
+ if !sync.is_valid() {
+ return false;
+ }
+ handle_potential_webgl_error!(
+ self.base,
+ self.base.validate_ownership(sync),
+ return false
+ );
+ let (sender, receiver) = webgl_channel().unwrap();
+ self.base
+ .send_command(WebGLCommand::IsSync(sync.id(), sender));
+ receiver.recv().unwrap()
+ },
+ None => false,
+ }
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.14
+ fn ClientWaitSync(&self, sync: &WebGLSync, flags: u32, timeout: u64) -> u32 {
+ if !sync.is_valid() {
+ self.base.webgl_error(InvalidOperation);
+ return constants::WAIT_FAILED;
+ }
+ handle_potential_webgl_error!(
+ self.base,
+ self.base.validate_ownership(sync),
+ return constants::WAIT_FAILED
+ );
+ if flags != 0 && flags != constants::SYNC_FLUSH_COMMANDS_BIT {
+ self.base.webgl_error(InvalidValue);
+ return constants::WAIT_FAILED;
+ }
+ if timeout > self.base.limits().max_client_wait_timeout_webgl.as_nanos() as u64 {
+ self.base.webgl_error(InvalidOperation);
+ return constants::WAIT_FAILED;
+ }
+
+ match sync.client_wait_sync(&self.base, flags, timeout) {
+ Some(status) => status,
+ None => constants::WAIT_FAILED,
+ }
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.14
+ fn WaitSync(&self, sync: &WebGLSync, flags: u32, timeout: i64) {
+ if !sync.is_valid() {
+ self.base.webgl_error(InvalidOperation);
+ return;
+ }
+ handle_potential_webgl_error!(self.base, self.base.validate_ownership(sync), return);
+ if flags != 0 {
+ self.base.webgl_error(InvalidValue);
+ return;
+ }
+ if timeout != constants::TIMEOUT_IGNORED {
+ self.base.webgl_error(InvalidValue);
+ return;
+ }
+
+ self.base
+ .send_command(WebGLCommand::WaitSync(sync.id(), flags, timeout));
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.14
+ fn GetSyncParameter(&self, _cx: JSContext, sync: &WebGLSync, pname: u32) -> JSVal {
+ if !sync.is_valid() {
+ self.base.webgl_error(InvalidOperation);
+ return NullValue();
+ }
+ handle_potential_webgl_error!(
+ self.base,
+ self.base.validate_ownership(sync),
+ return NullValue()
+ );
+ match pname {
+ constants::OBJECT_TYPE | constants::SYNC_CONDITION | constants::SYNC_FLAGS => {
+ let (sender, receiver) = webgl_channel().unwrap();
+ self.base
+ .send_command(WebGLCommand::GetSyncParameter(sync.id(), pname, sender));
+ UInt32Value(receiver.recv().unwrap())
+ },
+ constants::SYNC_STATUS => match sync.get_sync_status(pname, &self.base) {
+ Some(status) => UInt32Value(status),
+ None => UInt32Value(constants::UNSIGNALED),
+ },
+ _ => {
+ self.base.webgl_error(InvalidEnum);
+ NullValue()
+ },
+ }
+ }
+
+ /// https://www.khronos.org/registry/webgl/specs/latest/2.0/#3.7.14
+ fn DeleteSync(&self, sync: Option<&WebGLSync>) {
+ if let Some(sync) = sync {
+ handle_potential_webgl_error!(self.base, self.base.validate_ownership(sync), return);
+ sync.delete(false);
+ }
+ }
}
impl LayoutCanvasWebGLRenderingContextHelpers for LayoutDom<WebGL2RenderingContext> {