mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add GLPlayerThreads in canvas
This factory will launch a GLPlayerThread from the application main thread. And add GLPlayerThread, the multiplexor for media players' video renderers. This thread will receive commands from htmlmedialement and webrenderer. This code is also inspired by webgl_threads and WebGLThread.
This commit is contained in:
parent
0d52d5d304
commit
43467b4290
4 changed files with 91 additions and 0 deletions
|
@ -16,5 +16,7 @@ mod raqote_backend;
|
|||
pub mod canvas_data;
|
||||
pub mod canvas_paint_thread;
|
||||
pub mod gl_context;
|
||||
mod media_mode;
|
||||
pub mod media_thread;
|
||||
mod webgl_mode;
|
||||
pub mod webgl_thread;
|
||||
|
|
30
components/canvas/media_mode/inprocess.rs
Normal file
30
components/canvas/media_mode/inprocess.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::media_thread::GLPlayerThread;
|
||||
use canvas_traits::media::{GLPlayerChan, GLPlayerMsg, GLPlayerPipeline, GLPlayerSender};
|
||||
|
||||
/// GLPlayer Threading API entry point that lives in the constellation.
|
||||
pub struct GLPlayerThreads(GLPlayerSender<GLPlayerMsg>);
|
||||
|
||||
impl GLPlayerThreads {
|
||||
pub fn new() -> GLPlayerThreads {
|
||||
let channel = GLPlayerThread::start();
|
||||
GLPlayerThreads(channel)
|
||||
}
|
||||
|
||||
/// Gets the GLPlayerThread handle for each script pipeline.
|
||||
pub fn pipeline(&self) -> GLPlayerPipeline {
|
||||
// This mode creates a single thread, so the existing
|
||||
// GLPlayerChan is just cloned.
|
||||
GLPlayerPipeline(GLPlayerChan(self.0.clone()))
|
||||
}
|
||||
|
||||
/// Sends an exit message to close the GLPlayerThreads
|
||||
pub fn exit(&self) -> Result<(), &'static str> {
|
||||
self.0
|
||||
.send(GLPlayerMsg::Exit)
|
||||
.map_err(|_| "Failed to send Exit message")
|
||||
}
|
||||
}
|
6
components/canvas/media_mode/mod.rs
Normal file
6
components/canvas/media_mode/mod.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
mod inprocess;
|
||||
pub use self::inprocess::GLPlayerThreads;
|
53
components/canvas/media_thread.rs
Normal file
53
components/canvas/media_thread.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use canvas_traits::media::*;
|
||||
use std::thread;
|
||||
|
||||
/// GL player threading API entry point that lives in the
|
||||
/// constellation.
|
||||
///
|
||||
/// It allows to get a GLPlayerThead handle for each script pipeline.
|
||||
pub use crate::media_mode::GLPlayerThreads;
|
||||
|
||||
/// A GLPlayerThrx1ead manages the life cycle and message multiplexign of
|
||||
/// a set of video players with GL render.
|
||||
pub struct GLPlayerThread ();
|
||||
|
||||
impl GLPlayerThread {
|
||||
pub fn new() -> Self {
|
||||
GLPlayerThread()
|
||||
}
|
||||
|
||||
pub fn start() -> GLPlayerSender<GLPlayerMsg> {
|
||||
let (sender, receiver) = glplayer_channel::<GLPlayerMsg>().unwrap();
|
||||
thread::Builder::new()
|
||||
.name("GLPlayerThread".to_owned())
|
||||
.spawn(move || {
|
||||
let renderer = GLPlayerThread::new();
|
||||
loop {
|
||||
let msg = receiver.recv().unwrap();
|
||||
let exit = renderer.handle_msg(msg);
|
||||
if exit {
|
||||
return;
|
||||
}
|
||||
}
|
||||
})
|
||||
.expect("Thread spawning failed");
|
||||
|
||||
sender
|
||||
}
|
||||
|
||||
/// Handles a generic WebGLMsg message
|
||||
#[inline]
|
||||
fn handle_msg(&self, msg: GLPlayerMsg) -> bool {
|
||||
trace!("processing {:?}", msg);
|
||||
match msg {
|
||||
GLPlayerMsg::Exit => return true,
|
||||
_ => (),
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue