mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Webrender external image handler demux
This commit is contained in:
parent
7d589ed4f5
commit
ba9cf85fb3
11 changed files with 172 additions and 126 deletions
|
@ -37,3 +37,4 @@ serde_bytes = "0.10"
|
|||
servo_config = {path = "../config"}
|
||||
webrender = {git = "https://github.com/servo/webrender"}
|
||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||
webrender_traits = {path = "../webrender_traits"}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::gl_context::GLContextFactory;
|
||||
use crate::webgl_thread::{WebGLExternalImageApi, WebGLExternalImageHandler, WebGLThread};
|
||||
use crate::webgl_thread::WebGLThread;
|
||||
use canvas_traits::webgl::webgl_channel;
|
||||
use canvas_traits::webgl::DOMToTextureCommand;
|
||||
use canvas_traits::webgl::{WebGLChan, WebGLContextId, WebGLMsg, WebGLPipeline, WebGLReceiver};
|
||||
|
@ -13,6 +13,7 @@ use fnv::FnvHashMap;
|
|||
use gleam::gl;
|
||||
use servo_config::pref;
|
||||
use std::rc::Rc;
|
||||
use webrender_traits::WebrenderExternalImageApi;
|
||||
|
||||
/// WebGL Threading API entry point that lives in the constellation.
|
||||
pub struct WebGLThreads(WebGLSender<WebGLMsg>);
|
||||
|
@ -26,7 +27,7 @@ impl WebGLThreads {
|
|||
webvr_compositor: Option<Box<dyn WebVRRenderHandler>>,
|
||||
) -> (
|
||||
WebGLThreads,
|
||||
Box<dyn webrender::ExternalImageHandler>,
|
||||
Box<dyn WebrenderExternalImageApi>,
|
||||
Option<Box<dyn webrender::OutputImageHandler>>,
|
||||
) {
|
||||
// This implementation creates a single `WebGLThread` for all the pipelines.
|
||||
|
@ -43,8 +44,7 @@ impl WebGLThreads {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
let external =
|
||||
WebGLExternalImageHandler::new(WebGLExternalImages::new(webrender_gl, channel.clone()));
|
||||
let external = WebGLExternalImages::new(webrender_gl, channel.clone());
|
||||
(
|
||||
WebGLThreads(channel),
|
||||
Box::new(external),
|
||||
|
@ -87,12 +87,15 @@ impl WebGLExternalImages {
|
|||
}
|
||||
}
|
||||
|
||||
impl WebGLExternalImageApi for WebGLExternalImages {
|
||||
fn lock(&mut self, ctx_id: WebGLContextId) -> (u32, Size2D<i32>) {
|
||||
impl WebrenderExternalImageApi for WebGLExternalImages {
|
||||
fn lock(&mut self, id: u64) -> (u32, Size2D<i32>) {
|
||||
// WebGL Thread has it's own GL command queue that we need to synchronize with the WR GL command queue.
|
||||
// The WebGLMsg::Lock message inserts a fence in the WebGL command queue.
|
||||
self.webgl_channel
|
||||
.send(WebGLMsg::Lock(ctx_id, self.lock_channel.0.clone()))
|
||||
.send(WebGLMsg::Lock(
|
||||
WebGLContextId(id as usize),
|
||||
self.lock_channel.0.clone(),
|
||||
))
|
||||
.unwrap();
|
||||
let (image_id, size, gl_sync) = self.lock_channel.1.recv().unwrap();
|
||||
// The next glWaitSync call is run on the WR thread and it's used to synchronize the two
|
||||
|
@ -103,8 +106,10 @@ impl WebGLExternalImageApi for WebGLExternalImages {
|
|||
(image_id, size)
|
||||
}
|
||||
|
||||
fn unlock(&mut self, ctx_id: WebGLContextId) {
|
||||
self.webgl_channel.send(WebGLMsg::Unlock(ctx_id)).unwrap();
|
||||
fn unlock(&mut self, id: u64) {
|
||||
self.webgl_channel
|
||||
.send(WebGLMsg::Unlock(WebGLContextId(id as usize)))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -730,53 +730,6 @@ struct WebGLContextInfo {
|
|||
render_state: ContextRenderState,
|
||||
}
|
||||
|
||||
/// This trait is used as a bridge between the `WebGLThreads` implementation and
|
||||
/// the WR ExternalImageHandler API implemented in the `WebGLExternalImageHandler` struct.
|
||||
/// `WebGLExternalImageHandler<T>` takes care of type conversions between WR and WebGL info (e.g keys, uvs).
|
||||
/// It uses this trait to notify lock/unlock messages and get the required info that WR needs.
|
||||
/// `WebGLThreads` receives lock/unlock message notifications and takes care of sending
|
||||
/// the unlock/lock messages to the appropiate `WebGLThread`.
|
||||
pub trait WebGLExternalImageApi {
|
||||
fn lock(&mut self, ctx_id: WebGLContextId) -> (u32, Size2D<i32>);
|
||||
fn unlock(&mut self, ctx_id: WebGLContextId);
|
||||
}
|
||||
|
||||
/// WebRender External Image Handler implementation
|
||||
pub struct WebGLExternalImageHandler<T: WebGLExternalImageApi> {
|
||||
handler: T,
|
||||
}
|
||||
|
||||
impl<T: WebGLExternalImageApi> WebGLExternalImageHandler<T> {
|
||||
pub fn new(handler: T) -> Self {
|
||||
Self { handler: handler }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: WebGLExternalImageApi> webrender::ExternalImageHandler for WebGLExternalImageHandler<T> {
|
||||
/// Lock the external image. Then, WR could start to read the image content.
|
||||
/// The WR client should not change the image content until the unlock() call.
|
||||
fn lock(
|
||||
&mut self,
|
||||
key: webrender_api::ExternalImageId,
|
||||
_channel_index: u8,
|
||||
_rendering: webrender_api::ImageRendering,
|
||||
) -> webrender::ExternalImage {
|
||||
let ctx_id = WebGLContextId(key.0 as _);
|
||||
let (texture_id, size) = self.handler.lock(ctx_id);
|
||||
|
||||
webrender::ExternalImage {
|
||||
uv: webrender_api::TexelRect::new(0.0, size.height as f32, size.width as f32, 0.0),
|
||||
source: webrender::ExternalImageSource::NativeTexture(texture_id),
|
||||
}
|
||||
}
|
||||
/// Unlock the external image. The WR should not read the image content
|
||||
/// after this call.
|
||||
fn unlock(&mut self, key: webrender_api::ExternalImageId, _channel_index: u8) {
|
||||
let ctx_id = WebGLContextId(key.0 as _);
|
||||
self.handler.unlock(ctx_id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Data about the linked DOM<->WebGLTexture elements.
|
||||
struct DOMToTextureData {
|
||||
context_id: WebGLContextId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue