mirror of
https://github.com/servo/servo.git
synced 2025-08-16 19:05:33 +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
|
@ -21,3 +21,4 @@ servo_config = {path = "../config"}
|
|||
servo-media = {git = "https://github.com/servo/media"}
|
||||
webrender = {git = "https://github.com/servo/webrender"}
|
||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||
webrender_traits = {path = "../webrender_traits"}
|
||||
|
|
|
@ -13,16 +13,15 @@ extern crate log;
|
|||
#[macro_use]
|
||||
extern crate serde;
|
||||
|
||||
use euclid::Size2D;
|
||||
use servo_media::player::context::{GlApi, GlContext, NativeDisplay, PlayerGLContext};
|
||||
|
||||
mod media_channel;
|
||||
mod media_thread;
|
||||
|
||||
pub use crate::media_channel::glplayer_channel;
|
||||
|
||||
use crate::media_channel::{GLPlayerChan, GLPlayerPipeline, GLPlayerReceiver, GLPlayerSender};
|
||||
use crate::media_thread::{GLPlayerExternalImageApi, GLPlayerExternalImageHandler, GLPlayerThread};
|
||||
use crate::media_thread::GLPlayerThread;
|
||||
use euclid::Size2D;
|
||||
use servo_media::player::context::{GlApi, GlContext, NativeDisplay, PlayerGLContext};
|
||||
use webrender_traits::WebrenderExternalImageApi;
|
||||
|
||||
/// These are the messages that the GLPlayer thread will forward to
|
||||
/// the video player which lives in htmlmediaelement
|
||||
|
@ -100,10 +99,9 @@ impl PlayerGLContext for WindowGLContext {
|
|||
pub struct GLPlayerThreads(GLPlayerSender<GLPlayerMsg>);
|
||||
|
||||
impl GLPlayerThreads {
|
||||
pub fn new() -> (GLPlayerThreads, Box<dyn webrender::ExternalImageHandler>) {
|
||||
pub fn new() -> (GLPlayerThreads, Box<dyn WebrenderExternalImageApi>) {
|
||||
let channel = GLPlayerThread::start();
|
||||
let external =
|
||||
GLPlayerExternalImageHandler::new(GLPlayerExternalImages::new(channel.clone()));
|
||||
let external = GLPlayerExternalImages::new(channel.clone());
|
||||
(GLPlayerThreads(channel), Box::new(external))
|
||||
}
|
||||
|
||||
|
@ -146,7 +144,7 @@ impl GLPlayerExternalImages {
|
|||
}
|
||||
}
|
||||
|
||||
impl GLPlayerExternalImageApi for GLPlayerExternalImages {
|
||||
impl WebrenderExternalImageApi for GLPlayerExternalImages {
|
||||
fn lock(&mut self, id: u64) -> (u32, Size2D<i32>) {
|
||||
// The GLPlayerMsgForward::Lock message inserts a fence in the
|
||||
// GLPlayer command queue.
|
||||
|
|
|
@ -6,7 +6,6 @@ use crate::media_channel::{glplayer_channel, GLPlayerSender};
|
|||
/// GL player threading API entry point that lives in the
|
||||
/// constellation.
|
||||
use crate::{GLPlayerMsg, GLPlayerMsgForward};
|
||||
use euclid::Size2D;
|
||||
use fnv::FnvHashMap;
|
||||
use std::thread;
|
||||
|
||||
|
@ -78,60 +77,3 @@ impl GLPlayerThread {
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// This trait is used as a bridge between the `GLPlayerThreads`
|
||||
/// implementation and the WR ExternalImageHandler API implemented in
|
||||
/// the `GLPlayerExternalImageHandler` struct.
|
||||
//
|
||||
/// `GLPlayerExternalImageHandler<T>` takes care of type conversions
|
||||
/// between WR and GLPlayer info (e.g keys, uvs).
|
||||
//
|
||||
/// It uses this trait to notify lock/unlock messages and get the
|
||||
/// required info that WR needs.
|
||||
//
|
||||
/// `GLPlayerThreads` receives lock/unlock message notifications and
|
||||
/// takes care of sending the unlock/lock messages to the appropiate
|
||||
/// `GLPlayerThread`.
|
||||
pub trait GLPlayerExternalImageApi {
|
||||
fn lock(&mut self, id: u64) -> (u32, Size2D<i32>);
|
||||
fn unlock(&mut self, id: u64);
|
||||
}
|
||||
|
||||
/// WebRender External Image Handler implementation
|
||||
pub struct GLPlayerExternalImageHandler<T: GLPlayerExternalImageApi> {
|
||||
handler: T,
|
||||
}
|
||||
|
||||
impl<T: GLPlayerExternalImageApi> GLPlayerExternalImageHandler<T> {
|
||||
pub fn new(handler: T) -> Self {
|
||||
Self { handler: handler }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: GLPlayerExternalImageApi> webrender::ExternalImageHandler
|
||||
for GLPlayerExternalImageHandler<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 (texture_id, size) = self.handler.lock(key.0);
|
||||
|
||||
webrender::ExternalImage {
|
||||
uv: webrender_api::TexelRect::new(0.0, 0.0, size.width as f32, size.height as f32),
|
||||
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) {
|
||||
self.handler.unlock(key.0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue