aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webglrenderingcontext.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-10-16 15:36:42 -0500
committerGitHub <noreply@github.com>2017-10-16 15:36:42 -0500
commit3209d22968046b5c3d29a37b79a655497db2050a (patch)
tree143e736c18adfee6de958614129690250b265a0a /components/script/dom/webglrenderingcontext.rs
parentd3d2b0261a8aacd4f74e330f8c007a91f829a96e (diff)
parent8ae0739bab8a3c74e0685d9f53bbb155e4458aba (diff)
downloadservo-3209d22968046b5c3d29a37b79a655497db2050a.tar.gz
servo-3209d22968046b5c3d29a37b79a655497db2050a.zip
Auto merge of #18592 - MortimerGoro:dom_texture, r=jdm
Implement DOM to texture <!-- Please describe your changes on the following line: --> This is a prototype of the WebGL DOMToTexture feature. The API should be fine as a privileged extension for now due to security concerns. The working group has been investigating the viability of unprivileged usage but the spec is not ready yet. Demo video: https://www.youtube.com/watch?v=hpZqEM5hPao --- <!-- 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. --> <!-- 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/18592) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/webglrenderingcontext.rs')
-rw-r--r--components/script/dom/webglrenderingcontext.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index c20b2273123..d4624d3eb85 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -6,6 +6,7 @@ use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use canvas_traits::canvas::{byte_swap, multiply_u8_pixel};
use canvas_traits::webgl::{WebGLContextShareMode, WebGLCommand, WebGLError};
use canvas_traits::webgl::{WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender, WebGLParameter, WebVRCommand};
+use canvas_traits::webgl::DOMToTextureCommand;
use canvas_traits::webgl::WebGLError::*;
use canvas_traits::webgl::webgl_channel;
use core::cell::Ref;
@@ -25,6 +26,7 @@ use dom::bindings::str::DOMString;
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::htmlcanvaselement::HTMLCanvasElement;
use dom::htmlcanvaselement::utils as canvas_utils;
+use dom::htmliframeelement::HTMLIFrameElement;
use dom::node::{Node, NodeDamage, window_from_node};
use dom::webgl_extensions::WebGLExtensions;
use dom::webgl_validations::WebGLValidator;
@@ -3261,6 +3263,45 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
+ fn TexImageDOM(&self,
+ target: u32,
+ level: i32,
+ internal_format: u32,
+ width: i32,
+ height: i32,
+ format: u32,
+ data_type: u32,
+ source: &HTMLIFrameElement) -> Fallible<()> {
+ // Currently DOMToTexture only supports TEXTURE_2D, RGBA, UNSIGNED_BYTE and no levels.
+ if target != constants::TEXTURE_2D || level != 0 || internal_format != constants::RGBA ||
+ format != constants::RGBA || data_type != constants::UNSIGNED_BYTE {
+ return Ok(self.webgl_error(InvalidValue));
+ }
+
+ // Get bound texture
+ let texture = match self.bound_texture(constants::TEXTURE_2D) {
+ Some(texture) => texture,
+ None => {
+ return Ok(self.webgl_error(InvalidOperation));
+ }
+ };
+
+ let pipeline_id = source.pipeline_id().ok_or(Error::InvalidState)?;
+ let document_id = self.global().downcast::<Window>().ok_or(Error::InvalidState)?.webrender_document();
+
+ texture.set_attached_to_dom();
+
+ let command = DOMToTextureCommand::Attach(self.webgl_sender.context_id(),
+ texture.id(),
+ document_id,
+ pipeline_id.to_webrender(),
+ Size2D::new(width, height));
+ self.webgl_sender.send_dom_to_texture(command).unwrap();
+
+ Ok(())
+ }
+
+ // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
#[allow(unsafe_code)]
unsafe fn TexSubImage2D(&self,
cx: *mut JSContext,