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 -->
This commit is contained in:
bors-servo 2017-10-16 15:36:42 -05:00 committed by GitHub
commit 3209d22968
17 changed files with 238 additions and 13 deletions

View file

@ -6,7 +6,7 @@ use euclid::Size2D;
use nonzero::NonZeroU32;
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use std::fmt;
use webrender_api;
use webrender_api::{DocumentId, ImageKey, PipelineId};
/// Sender type used in WebGLCommands.
pub use ::webgl_channel::WebGLSender;
@ -46,7 +46,9 @@ pub enum WebGLMsg {
/// Unlock messages are always sent after a Lock message.
Unlock(WebGLContextId),
/// Creates or updates the image keys required for WebRender.
UpdateWebRenderImage(WebGLContextId, WebGLSender<webrender_api::ImageKey>),
UpdateWebRenderImage(WebGLContextId, WebGLSender<ImageKey>),
/// Commands used for the DOMToTexture feature.
DOMToTextureCommand(DOMToTextureCommand),
/// Frees all resources and closes the thread.
Exit,
}
@ -86,6 +88,11 @@ impl WebGLMsgSender {
}
}
/// Returns the WebGLContextId associated to this sender
pub fn context_id(&self) -> WebGLContextId {
self.ctx_id
}
/// Send a WebGLCommand message
#[inline]
pub fn send(&self, command: WebGLCommand) -> WebGLSendResult {
@ -113,9 +120,13 @@ impl WebGLMsgSender {
}
#[inline]
pub fn send_update_wr_image(&self, sender: WebGLSender<webrender_api::ImageKey>) -> WebGLSendResult {
pub fn send_update_wr_image(&self, sender: WebGLSender<ImageKey>) -> WebGLSendResult {
self.sender.send(WebGLMsg::UpdateWebRenderImage(self.ctx_id, sender))
}
pub fn send_dom_to_texture(&self, command: DOMToTextureCommand) -> WebGLSendResult {
self.sender.send(WebGLMsg::DOMToTextureCommand(command))
}
}
/// WebGL Commands for a specific WebGLContext
@ -379,6 +390,17 @@ pub trait WebVRRenderHandler: Send {
fn handle(&mut self, command: WebVRCommand, texture: Option<(u32, Size2D<i32>)>);
}
/// WebGL commands required to implement DOMToTexture feature.
#[derive(Clone, Deserialize, Serialize)]
pub enum DOMToTextureCommand {
/// Attaches a HTMLIFrameElement to a WebGLTexture.
Attach(WebGLContextId, WebGLTextureId, DocumentId, PipelineId, Size2D<i32>),
/// Releases the HTMLIFrameElement to WebGLTexture attachment.
Detach(WebGLTextureId),
/// Lock message used for a correct synchronization with WebRender GL flow.
Lock(PipelineId, usize, WebGLSender<Option<(u32, Size2D<i32>)>>),
}
impl fmt::Debug for WebGLCommand {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::WebGLCommand::*;