Skip to content

Commit

Permalink
Pass GLPlayerThreads to constellation
Browse files Browse the repository at this point in the history
Create the thread only if the GL context is known.
  • Loading branch information
ceyusa authored and ferjm committed Jul 4, 2019
1 parent 43467b4 commit dd01728
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions components/canvas_traits/media.rs
Expand Up @@ -66,6 +66,8 @@ pub struct WindowGLContext {
pub gl_api: GlApi,
/// Application's native display
pub native_display: NativeDisplay,
/// A channel to the GLPlayer thread.
pub glplayer_chan: Option<GLPlayerPipeline>,
}

impl PlayerGLContext for WindowGLContext {
Expand Down
14 changes: 14 additions & 0 deletions components/constellation/constellation.rs
Expand Up @@ -104,6 +104,7 @@ use background_hang_monitor::HangMonitorRegister;
use backtrace::Backtrace;
use bluetooth_traits::BluetoothRequest;
use canvas::canvas_paint_thread::CanvasPaintThread;
use canvas::media_thread::GLPlayerThreads;
use canvas::webgl_thread::WebGLThreads;
use canvas_traits::canvas::CanvasId;
use canvas_traits::canvas::CanvasMsg;
Expand Down Expand Up @@ -411,6 +412,9 @@ pub struct Constellation<Message, LTF, STF> {
/// results are required.
enable_canvas_antialiasing: bool,

/// Entry point to create and get channels to a GLPlayerThread.
glplayer_threads: Option<GLPlayerThreads>,

/// Application window's GL Context for Media player
player_context: WindowGLContext,
}
Expand Down Expand Up @@ -461,6 +465,8 @@ pub struct InitialConstellationState {

/// The XR device registry
pub webxr_registry: webxr_api::Registry,

pub glplayer_threads: Option<GLPlayerThreads>,

/// Application window's GL Context for Media player
pub player_context: WindowGLContext,
Expand Down Expand Up @@ -760,6 +766,7 @@ where
is_running_problem_test,
hard_fail,
enable_canvas_antialiasing,
glplayer_threads: state.glplayer_threads,
player_context: state.player_context,
};

Expand Down Expand Up @@ -1804,6 +1811,13 @@ where
}
}

debug!("Exiting GLPlayer thread.");
if let Some(glplayer_threads) = self.glplayer_threads.as_ref() {
if let Err(e) = glplayer_threads.exit() {
warn!("Exit GLPlayer Thread failed ({})", e);
}
}

debug!("Exiting timer scheduler.");
if let Err(e) = self.scheduler_chan.send(TimerSchedulerMsg::Exit) {
warn!("Exit timer scheduler failed ({})", e);
Expand Down
13 changes: 12 additions & 1 deletion components/servo/lib.rs
Expand Up @@ -63,6 +63,7 @@ fn webdriver(_port: u16, _constellation: Sender<ConstellationMsg>) {}
use bluetooth::BluetoothThreadFactory;
use bluetooth_traits::BluetoothRequest;
use canvas::gl_context::GLContextFactory;
use canvas::media_thread::GLPlayerThreads;
use canvas::webgl_thread::WebGLThreads;
use canvas_traits::media::WindowGLContext;
use compositing::compositor_thread::{
Expand Down Expand Up @@ -104,6 +105,7 @@ use profile_traits::time;
use script_traits::{ConstellationMsg, SWManagerSenders, ScriptToConstellationChan};
use servo_config::opts;
use servo_config::{pref, prefs};
use servo_media::player::context::GlContext;
use servo_media::ServoMedia;
use std::borrow::Cow;
use std::cmp::max;
Expand Down Expand Up @@ -304,10 +306,16 @@ where
None
};

let gl_context = window.get_gl_context();
let glplayer_threads = match gl_context {
GlContext::Unknown => None,
_ => Some(GLPlayerThreads::new()),
};
let player_context = WindowGLContext {
gl_context: window.get_gl_context(),
gl_context,
native_display: window.get_native_display(),
gl_api: window.get_gl_api(),
glplayer_chan: glplayer_threads.as_ref().map(|threads| threads.pipeline()),
};

// Create the constellation, which maintains the engine
Expand All @@ -328,6 +336,7 @@ where
window.gl(),
webvr_services,
webxr_registry,
glplayer_threads,
player_context,
);

Expand Down Expand Up @@ -639,6 +648,7 @@ fn create_constellation(
window_gl: Rc<dyn gl::Gl>,
webvr_services: Option<VRServiceManager>,
webxr_registry: webxr_api::Registry,
glplayer_threads: Option<GLPlayerThreads>,
player_context: WindowGLContext,
) -> (Sender<ConstellationMsg>, SWManagerSenders) {
// Global configuration options, parsed from the command line.
Expand Down Expand Up @@ -721,6 +731,7 @@ fn create_constellation(
webgl_threads,
webvr_chan,
webxr_registry,
glplayer_threads,
player_context,
};
let (constellation_chan, from_swmanager_sender) = Constellation::<
Expand Down

0 comments on commit dd01728

Please sign in to comment.