mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implement DOM to texture
This commit is contained in:
parent
a9022be0c3
commit
8ae0739bab
17 changed files with 238 additions and 13 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -312,6 +312,7 @@ dependencies = [
|
||||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"offscreen_gl_context 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"offscreen_gl_context 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"servo_config 0.0.1",
|
||||||
"webrender 0.52.1 (git+https://github.com/servo/webrender)",
|
"webrender 0.52.1 (git+https://github.com/servo/webrender)",
|
||||||
"webrender_api 0.52.1 (git+https://github.com/servo/webrender)",
|
"webrender_api 0.52.1 (git+https://github.com/servo/webrender)",
|
||||||
]
|
]
|
||||||
|
|
|
@ -21,5 +21,6 @@ ipc-channel = "0.8"
|
||||||
log = "0.3.5"
|
log = "0.3.5"
|
||||||
num-traits = "0.1.32"
|
num-traits = "0.1.32"
|
||||||
offscreen_gl_context = { version = "0.11", features = ["serde", "osmesa"] }
|
offscreen_gl_context = { version = "0.11", features = ["serde", "osmesa"] }
|
||||||
|
servo_config = {path = "../config"}
|
||||||
webrender = {git = "https://github.com/servo/webrender"}
|
webrender = {git = "https://github.com/servo/webrender"}
|
||||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
|
|
|
@ -15,6 +15,7 @@ extern crate ipc_channel;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate num_traits;
|
extern crate num_traits;
|
||||||
extern crate offscreen_gl_context;
|
extern crate offscreen_gl_context;
|
||||||
|
extern crate servo_config;
|
||||||
extern crate webrender;
|
extern crate webrender;
|
||||||
extern crate webrender_api;
|
extern crate webrender_api;
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,12 @@ use ::gl_context::GLContextFactory;
|
||||||
use ::webgl_thread::{WebGLExternalImageApi, WebGLExternalImageHandler, WebGLThreadObserver, WebGLThread};
|
use ::webgl_thread::{WebGLExternalImageApi, WebGLExternalImageHandler, WebGLThreadObserver, WebGLThread};
|
||||||
use canvas_traits::webgl::{WebGLChan, WebGLContextId, WebGLMsg, WebGLPipeline, WebGLReceiver};
|
use canvas_traits::webgl::{WebGLChan, WebGLContextId, WebGLMsg, WebGLPipeline, WebGLReceiver};
|
||||||
use canvas_traits::webgl::{WebGLSender, WebVRCommand, WebVRRenderHandler};
|
use canvas_traits::webgl::{WebGLSender, WebVRCommand, WebVRRenderHandler};
|
||||||
|
use canvas_traits::webgl::DOMToTextureCommand;
|
||||||
use canvas_traits::webgl::webgl_channel;
|
use canvas_traits::webgl::webgl_channel;
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
|
use fnv::FnvHashMap;
|
||||||
use gleam::gl;
|
use gleam::gl;
|
||||||
|
use servo_config::prefs::PREFS;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use webrender;
|
use webrender;
|
||||||
|
@ -23,14 +26,19 @@ impl WebGLThreads {
|
||||||
webrender_gl: Rc<gl::Gl>,
|
webrender_gl: Rc<gl::Gl>,
|
||||||
webrender_api_sender: webrender_api::RenderApiSender,
|
webrender_api_sender: webrender_api::RenderApiSender,
|
||||||
webvr_compositor: Option<Box<WebVRRenderHandler>>)
|
webvr_compositor: Option<Box<WebVRRenderHandler>>)
|
||||||
-> (WebGLThreads, Box<webrender::ExternalImageHandler>) {
|
-> (WebGLThreads, Box<webrender::ExternalImageHandler>, Option<Box<webrender::OutputImageHandler>>) {
|
||||||
// This implementation creates a single `WebGLThread` for all the pipelines.
|
// This implementation creates a single `WebGLThread` for all the pipelines.
|
||||||
let channel = WebGLThread::start(gl_factory,
|
let channel = WebGLThread::start(gl_factory,
|
||||||
webrender_api_sender,
|
webrender_api_sender,
|
||||||
webvr_compositor.map(|c| WebVRRenderWrapper(c)),
|
webvr_compositor.map(|c| WebVRRenderWrapper(c)),
|
||||||
PhantomData);
|
PhantomData);
|
||||||
|
let output_handler = if PREFS.is_dom_to_texture_enabled() {
|
||||||
|
Some(Box::new(OutputHandler::new(webrender_gl.clone(), channel.clone())))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
let external = WebGLExternalImageHandler::new(WebGLExternalImages::new(webrender_gl, channel.clone()));
|
let external = WebGLExternalImageHandler::new(WebGLExternalImages::new(webrender_gl, channel.clone()));
|
||||||
(WebGLThreads(channel), Box::new(external))
|
(WebGLThreads(channel), Box::new(external), output_handler.map(|b| b as Box<_>))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the WebGLThread handle for each script pipeline.
|
/// Gets the WebGLThread handle for each script pipeline.
|
||||||
|
@ -105,3 +113,47 @@ impl WebVRRenderHandler for WebVRRenderWrapper {
|
||||||
self.0.handle(command, texture);
|
self.0.handle(command, texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// struct used to implement DOMToTexture feature and webrender::OutputImageHandler trait.
|
||||||
|
type OutputHandlerData = Option<(u32, Size2D<i32>)>;
|
||||||
|
struct OutputHandler {
|
||||||
|
webrender_gl: Rc<gl::Gl>,
|
||||||
|
webgl_channel: WebGLSender<WebGLMsg>,
|
||||||
|
// Used to avoid creating a new channel on each received WebRender request.
|
||||||
|
lock_channel: (WebGLSender<OutputHandlerData>, WebGLReceiver<OutputHandlerData>),
|
||||||
|
sync_objects: FnvHashMap<webrender_api::PipelineId, gl::GLsync>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OutputHandler {
|
||||||
|
fn new(webrender_gl: Rc<gl::Gl>, channel: WebGLSender<WebGLMsg>) -> Self {
|
||||||
|
Self {
|
||||||
|
webrender_gl,
|
||||||
|
webgl_channel: channel,
|
||||||
|
lock_channel: webgl_channel().unwrap(),
|
||||||
|
sync_objects: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bridge between the WR frame outputs and WebGL to implement DOMToTexture synchronization.
|
||||||
|
impl webrender::OutputImageHandler for OutputHandler {
|
||||||
|
fn lock(&mut self, id: webrender_api::PipelineId) -> Option<(u32, webrender_api::DeviceIntSize)> {
|
||||||
|
// Insert a fence in the WR command queue
|
||||||
|
let gl_sync = self.webrender_gl.fence_sync(gl::SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||||
|
// The lock command adds a WaitSync call on the WebGL command flow.
|
||||||
|
let command = DOMToTextureCommand::Lock(id, gl_sync as usize, self.lock_channel.0.clone());
|
||||||
|
self.webgl_channel.send(WebGLMsg::DOMToTextureCommand(command)).unwrap();
|
||||||
|
self.lock_channel.1.recv().unwrap().map(|(tex_id, size)| {
|
||||||
|
(tex_id, webrender_api::DeviceIntSize::new(size.width, size.height))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unlock(&mut self, id: webrender_api::PipelineId) {
|
||||||
|
if let Some(gl_sync) = self.sync_objects.remove(&id) {
|
||||||
|
// Flush the Sync object into the GPU's command queue to guarantee that it it's signaled.
|
||||||
|
self.webrender_gl.flush();
|
||||||
|
// Mark the sync object for deletion.
|
||||||
|
self.webrender_gl.delete_sync(gl_sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ pub struct WebGLThread<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver
|
||||||
webvr_compositor: Option<VR>,
|
webvr_compositor: Option<VR>,
|
||||||
/// Generic observer that listens WebGLContext creation, resize or removal events.
|
/// Generic observer that listens WebGLContext creation, resize or removal events.
|
||||||
observer: OB,
|
observer: OB,
|
||||||
|
/// Texture ids and sizes used in DOM to texture outputs.
|
||||||
|
dom_outputs: FnvHashMap<webrender_api::PipelineId, DOMToTextureData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR, OB> {
|
impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR, OB> {
|
||||||
|
@ -52,6 +54,7 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
next_webgl_id: 0,
|
next_webgl_id: 0,
|
||||||
webvr_compositor,
|
webvr_compositor,
|
||||||
observer: observer,
|
observer: observer,
|
||||||
|
dom_outputs: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +120,9 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
WebGLMsg::UpdateWebRenderImage(ctx_id, sender) => {
|
WebGLMsg::UpdateWebRenderImage(ctx_id, sender) => {
|
||||||
self.handle_update_wr_image(ctx_id, sender);
|
self.handle_update_wr_image(ctx_id, sender);
|
||||||
},
|
},
|
||||||
|
WebGLMsg::DOMToTextureCommand(command) => {
|
||||||
|
self.handle_dom_to_texture(command);
|
||||||
|
},
|
||||||
WebGLMsg::Exit => {
|
WebGLMsg::Exit => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -323,6 +329,54 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
|
||||||
sender.send(image_key).unwrap();
|
sender.send(image_key).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_dom_to_texture(&mut self, command: DOMToTextureCommand) {
|
||||||
|
match command {
|
||||||
|
DOMToTextureCommand::Attach(context_id, texture_id, document_id, pipeline_id, size) => {
|
||||||
|
let ctx = Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id)
|
||||||
|
.expect("WebGLContext not found in a WebGL DOMToTextureCommand::Attach command");
|
||||||
|
// Initialize the texture that WR will use for frame outputs.
|
||||||
|
ctx.gl().tex_image_2d(gl::TEXTURE_2D,
|
||||||
|
0,
|
||||||
|
gl::RGBA as gl::GLint,
|
||||||
|
size.width,
|
||||||
|
size.height,
|
||||||
|
0,
|
||||||
|
gl::RGBA,
|
||||||
|
gl::UNSIGNED_BYTE,
|
||||||
|
None);
|
||||||
|
self.dom_outputs.insert(pipeline_id, DOMToTextureData {
|
||||||
|
context_id, texture_id, document_id, size
|
||||||
|
});
|
||||||
|
self.webrender_api.enable_frame_output(document_id, pipeline_id, true);
|
||||||
|
},
|
||||||
|
DOMToTextureCommand::Lock(pipeline_id, gl_sync, sender) => {
|
||||||
|
let contexts = &self.contexts;
|
||||||
|
let bound_context_id = &mut self.bound_context_id;
|
||||||
|
let result = self.dom_outputs.get(&pipeline_id).and_then(|data| {
|
||||||
|
let ctx = Self::make_current_if_needed(data.context_id, contexts, bound_context_id);
|
||||||
|
ctx.and_then(|ctx| {
|
||||||
|
// The next glWaitSync call is used to synchronize the two flows of
|
||||||
|
// OpenGL commands (WR and WebGL) in order to avoid using semi-ready WR textures.
|
||||||
|
// glWaitSync doesn't block WebGL CPU thread.
|
||||||
|
ctx.gl().wait_sync(gl_sync as gl::GLsync, 0, gl::TIMEOUT_IGNORED);
|
||||||
|
Some((data.texture_id.get(), data.size))
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// Send the texture id and size to WR.
|
||||||
|
sender.send(result).unwrap();
|
||||||
|
},
|
||||||
|
DOMToTextureCommand::Detach(texture_id) => {
|
||||||
|
if let Some((pipeline_id, document_id)) = self.dom_outputs.iter()
|
||||||
|
.find(|&(_, v)| v.texture_id == texture_id)
|
||||||
|
.map(|(k, v)| (*k, v.document_id)) {
|
||||||
|
self.webrender_api.enable_frame_output(document_id, pipeline_id, false);
|
||||||
|
self.dom_outputs.remove(&pipeline_id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets a reference to a GLContextWrapper for a given WebGLContextId and makes it current if required.
|
/// Gets a reference to a GLContextWrapper for a given WebGLContextId and makes it current if required.
|
||||||
fn make_current_if_needed<'a>(context_id: WebGLContextId,
|
fn make_current_if_needed<'a>(context_id: WebGLContextId,
|
||||||
contexts: &'a FnvHashMap<WebGLContextId, GLContextWrapper>,
|
contexts: &'a FnvHashMap<WebGLContextId, GLContextWrapper>,
|
||||||
|
@ -552,6 +606,14 @@ impl<T: WebGLExternalImageApi> webrender::ExternalImageHandler for WebGLExternal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Data about the linked DOM<->WebGLTexture elements.
|
||||||
|
struct DOMToTextureData {
|
||||||
|
context_id: WebGLContextId,
|
||||||
|
texture_id: WebGLTextureId,
|
||||||
|
document_id: webrender_api::DocumentId,
|
||||||
|
size: Size2D<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
/// WebGL Commands Implementation
|
/// WebGL Commands Implementation
|
||||||
pub struct WebGLImpl;
|
pub struct WebGLImpl;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use euclid::Size2D;
|
||||||
use nonzero::NonZeroU32;
|
use nonzero::NonZeroU32;
|
||||||
use offscreen_gl_context::{GLContextAttributes, GLLimits};
|
use offscreen_gl_context::{GLContextAttributes, GLLimits};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use webrender_api;
|
use webrender_api::{DocumentId, ImageKey, PipelineId};
|
||||||
|
|
||||||
/// Sender type used in WebGLCommands.
|
/// Sender type used in WebGLCommands.
|
||||||
pub use ::webgl_channel::WebGLSender;
|
pub use ::webgl_channel::WebGLSender;
|
||||||
|
@ -46,7 +46,9 @@ pub enum WebGLMsg {
|
||||||
/// Unlock messages are always sent after a Lock message.
|
/// Unlock messages are always sent after a Lock message.
|
||||||
Unlock(WebGLContextId),
|
Unlock(WebGLContextId),
|
||||||
/// Creates or updates the image keys required for WebRender.
|
/// 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.
|
/// Frees all resources and closes the thread.
|
||||||
Exit,
|
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
|
/// Send a WebGLCommand message
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn send(&self, command: WebGLCommand) -> WebGLSendResult {
|
pub fn send(&self, command: WebGLCommand) -> WebGLSendResult {
|
||||||
|
@ -113,9 +120,13 @@ impl WebGLMsgSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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))
|
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
|
/// 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>)>);
|
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 {
|
impl fmt::Debug for WebGLCommand {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::WebGLCommand::*;
|
use self::WebGLCommand::*;
|
||||||
|
|
|
@ -273,4 +273,8 @@ impl Preferences {
|
||||||
pub fn is_webvr_enabled(&self) -> bool {
|
pub fn is_webvr_enabled(&self) -> bool {
|
||||||
self.get("dom.webvr.enabled").as_boolean().unwrap_or(false)
|
self.get("dom.webvr.enabled").as_boolean().unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_dom_to_texture_enabled(&self) -> bool {
|
||||||
|
self.get("dom.webgl.dom_to_texture.enabled").as_boolean().unwrap_or(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -511,6 +511,7 @@ impl UnprivilegedPipelineContent {
|
||||||
content_process_shutdown_chan: self.script_content_process_shutdown_chan,
|
content_process_shutdown_chan: self.script_content_process_shutdown_chan,
|
||||||
webgl_chan: self.webgl_chan,
|
webgl_chan: self.webgl_chan,
|
||||||
webvr_chan: self.webvr_chan,
|
webvr_chan: self.webvr_chan,
|
||||||
|
webrender_document: self.webrender_document,
|
||||||
}, self.load_data.clone());
|
}, self.load_data.clone());
|
||||||
|
|
||||||
LTF::create(self.id,
|
LTF::create(self.id,
|
||||||
|
|
|
@ -110,7 +110,7 @@ use style::stylesheets::keyframes_rule::Keyframe;
|
||||||
use style::values::specified::Length;
|
use style::values::specified::Length;
|
||||||
use time::Duration;
|
use time::Duration;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use webrender_api::ImageKey;
|
use webrender_api::{DocumentId, ImageKey};
|
||||||
use webvr_traits::WebVRGamepadHand;
|
use webvr_traits::WebVRGamepadHand;
|
||||||
|
|
||||||
/// A trait to allow tracing (only) DOM objects.
|
/// A trait to allow tracing (only) DOM objects.
|
||||||
|
@ -397,6 +397,7 @@ unsafe_no_jsmanaged_fields!(OpaqueStyleAndLayoutData);
|
||||||
unsafe_no_jsmanaged_fields!(PathBuf);
|
unsafe_no_jsmanaged_fields!(PathBuf);
|
||||||
unsafe_no_jsmanaged_fields!(CSSErrorReporter);
|
unsafe_no_jsmanaged_fields!(CSSErrorReporter);
|
||||||
unsafe_no_jsmanaged_fields!(DrawAPaintImageResult);
|
unsafe_no_jsmanaged_fields!(DrawAPaintImageResult);
|
||||||
|
unsafe_no_jsmanaged_fields!(DocumentId);
|
||||||
unsafe_no_jsmanaged_fields!(ImageKey);
|
unsafe_no_jsmanaged_fields!(ImageKey);
|
||||||
unsafe_no_jsmanaged_fields!(WebGLBufferId);
|
unsafe_no_jsmanaged_fields!(WebGLBufferId);
|
||||||
unsafe_no_jsmanaged_fields!(WebGLChan);
|
unsafe_no_jsmanaged_fields!(WebGLChan);
|
||||||
|
|
|
@ -6,6 +6,7 @@ use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use canvas_traits::canvas::{byte_swap, multiply_u8_pixel};
|
use canvas_traits::canvas::{byte_swap, multiply_u8_pixel};
|
||||||
use canvas_traits::webgl::{WebGLContextShareMode, WebGLCommand, WebGLError};
|
use canvas_traits::webgl::{WebGLContextShareMode, WebGLCommand, WebGLError};
|
||||||
use canvas_traits::webgl::{WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender, WebGLParameter, WebVRCommand};
|
use canvas_traits::webgl::{WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender, WebGLParameter, WebVRCommand};
|
||||||
|
use canvas_traits::webgl::DOMToTextureCommand;
|
||||||
use canvas_traits::webgl::WebGLError::*;
|
use canvas_traits::webgl::WebGLError::*;
|
||||||
use canvas_traits::webgl::webgl_channel;
|
use canvas_traits::webgl::webgl_channel;
|
||||||
use core::cell::Ref;
|
use core::cell::Ref;
|
||||||
|
@ -25,6 +26,7 @@ use dom::bindings::str::DOMString;
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::htmlcanvaselement::HTMLCanvasElement;
|
use dom::htmlcanvaselement::HTMLCanvasElement;
|
||||||
use dom::htmlcanvaselement::utils as canvas_utils;
|
use dom::htmlcanvaselement::utils as canvas_utils;
|
||||||
|
use dom::htmliframeelement::HTMLIFrameElement;
|
||||||
use dom::node::{Node, NodeDamage, window_from_node};
|
use dom::node::{Node, NodeDamage, window_from_node};
|
||||||
use dom::webgl_extensions::WebGLExtensions;
|
use dom::webgl_extensions::WebGLExtensions;
|
||||||
use dom::webgl_validations::WebGLValidator;
|
use dom::webgl_validations::WebGLValidator;
|
||||||
|
@ -3260,6 +3262,45 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn TexSubImage2D(&self,
|
unsafe fn TexSubImage2D(&self,
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
|
||||||
|
|
||||||
use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLResult, WebGLTextureId};
|
use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLResult, WebGLTextureId};
|
||||||
|
use canvas_traits::webgl::DOMToTextureCommand;
|
||||||
use dom::bindings::cell::DomRefCell;
|
use dom::bindings::cell::DomRefCell;
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||||
use dom::bindings::codegen::Bindings::WebGLTextureBinding;
|
use dom::bindings::codegen::Bindings::WebGLTextureBinding;
|
||||||
|
@ -45,6 +46,8 @@ pub struct WebGLTexture {
|
||||||
mag_filter: Cell<Option<u32>>,
|
mag_filter: Cell<Option<u32>>,
|
||||||
#[ignore_heap_size_of = "Defined in ipc-channel"]
|
#[ignore_heap_size_of = "Defined in ipc-channel"]
|
||||||
renderer: WebGLMsgSender,
|
renderer: WebGLMsgSender,
|
||||||
|
/// True if this texture is used for the DOMToTexture feature.
|
||||||
|
attached_to_dom: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebGLTexture {
|
impl WebGLTexture {
|
||||||
|
@ -62,6 +65,7 @@ impl WebGLTexture {
|
||||||
mag_filter: Cell::new(None),
|
mag_filter: Cell::new(None),
|
||||||
image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]),
|
image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]),
|
||||||
renderer: renderer,
|
renderer: renderer,
|
||||||
|
attached_to_dom: Cell::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,6 +183,10 @@ impl WebGLTexture {
|
||||||
pub fn delete(&self) {
|
pub fn delete(&self) {
|
||||||
if !self.is_deleted.get() {
|
if !self.is_deleted.get() {
|
||||||
self.is_deleted.set(true);
|
self.is_deleted.set(true);
|
||||||
|
// Notify WR to release the frame output when using DOMToTexture feature
|
||||||
|
if self.attached_to_dom.get() {
|
||||||
|
let _ = self.renderer.send_dom_to_texture(DOMToTextureCommand::Detach(self.id));
|
||||||
|
}
|
||||||
let _ = self.renderer.send(WebGLCommand::DeleteTexture(self.id));
|
let _ = self.renderer.send(WebGLCommand::DeleteTexture(self.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -374,6 +382,10 @@ impl WebGLTexture {
|
||||||
|
|
||||||
Some(self.image_info_at_face(0, self.base_mipmap_level))
|
Some(self.image_info_at_face(0, self.base_mipmap_level))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_attached_to_dom(&self) {
|
||||||
|
self.attached_to_dom.set(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for WebGLTexture {
|
impl Drop for WebGLTexture {
|
||||||
|
|
|
@ -654,6 +654,9 @@ interface WebGLRenderingContextBase
|
||||||
[Throws]
|
[Throws]
|
||||||
void texImage2D(GLenum target, GLint level, GLenum internalformat,
|
void texImage2D(GLenum target, GLint level, GLenum internalformat,
|
||||||
GLenum format, GLenum type, TexImageSource? source); // May throw DOMException
|
GLenum format, GLenum type, TexImageSource? source); // May throw DOMException
|
||||||
|
[Throws, Pref="dom.webgl.dom_to_texture.enabled"]
|
||||||
|
void texImageDOM(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
|
||||||
|
GLenum format, GLenum type, HTMLIFrameElement source); // May throw DOMException
|
||||||
|
|
||||||
void texParameterf(GLenum target, GLenum pname, GLfloat param);
|
void texParameterf(GLenum target, GLenum pname, GLfloat param);
|
||||||
void texParameteri(GLenum target, GLenum pname, GLint param);
|
void texParameteri(GLenum target, GLenum pname, GLint param);
|
||||||
|
|
|
@ -123,7 +123,7 @@ use timers::{IsInterval, TimerCallback};
|
||||||
use tinyfiledialogs::{self, MessageBoxIcon};
|
use tinyfiledialogs::{self, MessageBoxIcon};
|
||||||
use url::Position;
|
use url::Position;
|
||||||
use webdriver_handlers::jsval_to_webdriver;
|
use webdriver_handlers::jsval_to_webdriver;
|
||||||
use webrender_api::ClipId;
|
use webrender_api::{ClipId, DocumentId};
|
||||||
use webvr_traits::WebVRMsg;
|
use webvr_traits::WebVRMsg;
|
||||||
|
|
||||||
/// Current state of the window object
|
/// Current state of the window object
|
||||||
|
@ -289,6 +289,9 @@ pub struct Window {
|
||||||
test_worklet: MutNullableDom<Worklet>,
|
test_worklet: MutNullableDom<Worklet>,
|
||||||
/// https://drafts.css-houdini.org/css-paint-api-1/#paint-worklet
|
/// https://drafts.css-houdini.org/css-paint-api-1/#paint-worklet
|
||||||
paint_worklet: MutNullableDom<Worklet>,
|
paint_worklet: MutNullableDom<Worklet>,
|
||||||
|
/// The Webrender Document id associated with this window.
|
||||||
|
#[ignore_heap_size_of = "defined in webrender_api"]
|
||||||
|
webrender_document: DocumentId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
|
@ -1760,6 +1763,10 @@ impl Window {
|
||||||
.send(msg)
|
.send(msg)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn webrender_document(&self) -> DocumentId {
|
||||||
|
self.webrender_document
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
|
@ -1794,6 +1801,7 @@ impl Window {
|
||||||
webgl_chan: WebGLChan,
|
webgl_chan: WebGLChan,
|
||||||
webvr_chan: Option<IpcSender<WebVRMsg>>,
|
webvr_chan: Option<IpcSender<WebVRMsg>>,
|
||||||
microtask_queue: Rc<MicrotaskQueue>,
|
microtask_queue: Rc<MicrotaskQueue>,
|
||||||
|
webrender_document: DocumentId,
|
||||||
) -> DomRoot<Self> {
|
) -> DomRoot<Self> {
|
||||||
let layout_rpc: Box<LayoutRPC + Send> = {
|
let layout_rpc: Box<LayoutRPC + Send> = {
|
||||||
let (rpc_send, rpc_recv) = channel();
|
let (rpc_send, rpc_recv) = channel();
|
||||||
|
@ -1868,6 +1876,7 @@ impl Window {
|
||||||
unminified_js_dir: Default::default(),
|
unminified_js_dir: Default::default(),
|
||||||
test_worklet: Default::default(),
|
test_worklet: Default::default(),
|
||||||
paint_worklet: Default::default(),
|
paint_worklet: Default::default(),
|
||||||
|
webrender_document,
|
||||||
});
|
});
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -124,6 +124,7 @@ use time::{get_time, precise_time_ns, Tm};
|
||||||
use url::Position;
|
use url::Position;
|
||||||
use url::percent_encoding::percent_decode;
|
use url::percent_encoding::percent_decode;
|
||||||
use webdriver_handlers;
|
use webdriver_handlers;
|
||||||
|
use webrender_api::DocumentId;
|
||||||
use webvr_traits::{WebVREvent, WebVRMsg};
|
use webvr_traits::{WebVREvent, WebVRMsg};
|
||||||
|
|
||||||
pub type ImageCacheMsg = (PipelineId, PendingImageResponse);
|
pub type ImageCacheMsg = (PipelineId, PendingImageResponse);
|
||||||
|
@ -495,6 +496,9 @@ pub struct ScriptThread {
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#custom-element-reactions-stack
|
/// https://html.spec.whatwg.org/multipage/#custom-element-reactions-stack
|
||||||
custom_element_reaction_stack: CustomElementReactionStack,
|
custom_element_reaction_stack: CustomElementReactionStack,
|
||||||
|
|
||||||
|
/// The Webrender Document ID associated with this thread.
|
||||||
|
webrender_document: DocumentId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// In the event of thread panic, all data on the stack runs its destructor. However, there
|
/// In the event of thread panic, all data on the stack runs its destructor. However, there
|
||||||
|
@ -871,6 +875,8 @@ impl ScriptThread {
|
||||||
transitioning_nodes: Default::default(),
|
transitioning_nodes: Default::default(),
|
||||||
|
|
||||||
custom_element_reaction_stack: CustomElementReactionStack::new(),
|
custom_element_reaction_stack: CustomElementReactionStack::new(),
|
||||||
|
|
||||||
|
webrender_document: state.webrender_document,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2062,6 +2068,7 @@ impl ScriptThread {
|
||||||
self.webgl_chan.channel(),
|
self.webgl_chan.channel(),
|
||||||
self.webvr_chan.clone(),
|
self.webvr_chan.clone(),
|
||||||
self.microtask_queue.clone(),
|
self.microtask_queue.clone(),
|
||||||
|
self.webrender_document,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Initialize the browsing context for the window.
|
// Initialize the browsing context for the window.
|
||||||
|
|
|
@ -69,7 +69,7 @@ use std::sync::mpsc::{Receiver, Sender, RecvTimeoutError};
|
||||||
use style_traits::CSSPixel;
|
use style_traits::CSSPixel;
|
||||||
use style_traits::SpeculativePainter;
|
use style_traits::SpeculativePainter;
|
||||||
use webdriver_msg::{LoadStatus, WebDriverScriptCommand};
|
use webdriver_msg::{LoadStatus, WebDriverScriptCommand};
|
||||||
use webrender_api::{ClipId, DevicePixel, ImageKey};
|
use webrender_api::{ClipId, DevicePixel, DocumentId, ImageKey};
|
||||||
use webvr_traits::{WebVREvent, WebVRMsg};
|
use webvr_traits::{WebVREvent, WebVRMsg};
|
||||||
|
|
||||||
pub use script_msg::{LayoutMsg, ScriptMsg, EventResult, LogEntry};
|
pub use script_msg::{LayoutMsg, ScriptMsg, EventResult, LogEntry};
|
||||||
|
@ -554,7 +554,9 @@ pub struct InitialScriptState {
|
||||||
/// A channel to the webgl thread used in this pipeline.
|
/// A channel to the webgl thread used in this pipeline.
|
||||||
pub webgl_chan: WebGLPipeline,
|
pub webgl_chan: WebGLPipeline,
|
||||||
/// A channel to the webvr thread, if available.
|
/// A channel to the webvr thread, if available.
|
||||||
pub webvr_chan: Option<IpcSender<WebVRMsg>>
|
pub webvr_chan: Option<IpcSender<WebVRMsg>>,
|
||||||
|
/// The Webrender document ID associated with this thread.
|
||||||
|
pub webrender_document: DocumentId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This trait allows creating a `ScriptThread` without depending on the `script`
|
/// This trait allows creating a `ScriptThread` without depending on the `script`
|
||||||
|
|
|
@ -553,13 +553,18 @@ fn create_constellation(user_agent: Cow<'static, str>,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize WebGL Thread entry point.
|
// Initialize WebGL Thread entry point.
|
||||||
let (webgl_threads, image_handler) = WebGLThreads::new(gl_factory,
|
let (webgl_threads, image_handler, output_handler) = WebGLThreads::new(gl_factory,
|
||||||
window_gl,
|
window_gl,
|
||||||
webrender_api_sender.clone(),
|
webrender_api_sender.clone(),
|
||||||
webvr_compositor.map(|c| c as Box<_>));
|
webvr_compositor.map(|c| c as Box<_>));
|
||||||
// Set webrender external image handler for WebGL textures
|
// Set webrender external image handler for WebGL textures
|
||||||
webrender.set_external_image_handler(image_handler);
|
webrender.set_external_image_handler(image_handler);
|
||||||
|
|
||||||
|
// Set DOM to texture handler, if enabled.
|
||||||
|
if let Some(output_handler) = output_handler {
|
||||||
|
webrender.set_output_image_handler(output_handler);
|
||||||
|
}
|
||||||
|
|
||||||
let initial_state = InitialConstellationState {
|
let initial_state = InitialConstellationState {
|
||||||
compositor_proxy,
|
compositor_proxy,
|
||||||
embedder_proxy,
|
embedder_proxy,
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
"dom.servoparser.async_html_tokenizer.enabled": false,
|
"dom.servoparser.async_html_tokenizer.enabled": false,
|
||||||
"dom.testable_crash.enabled": false,
|
"dom.testable_crash.enabled": false,
|
||||||
"dom.testbinding.enabled": false,
|
"dom.testbinding.enabled": false,
|
||||||
|
"dom.webgl.dom_to_texture.enabled": false,
|
||||||
"dom.webvr.enabled": false,
|
"dom.webvr.enabled": false,
|
||||||
"dom.webvr.event_polling_interval": 500,
|
"dom.webvr.event_polling_interval": 500,
|
||||||
"js.asmjs.enabled": true,
|
"js.asmjs.enabled": true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue