Skip to content

Commit

Permalink
Provide webrender_api::RenderApiSender to ScriptThread and DOM Window
Browse files Browse the repository at this point in the history
This will allow the HTMLMediaElement later to get a handle to the
RenderApi for rendering video frames.

At a later time, all media handling should be moved to its own
thread/process that is communicated with via IPC. At that point this
can be removed again.

Original-patch-by: Sebastian Dröge <sebastian@centricular.com>
  • Loading branch information
ceyusa authored and ferjm committed Oct 8, 2018
1 parent 77c7eda commit 781b3b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/constellation/pipeline.rs
Expand Up @@ -517,6 +517,7 @@ impl UnprivilegedPipelineContent {
webgl_chan: self.webgl_chan,
webvr_chan: self.webvr_chan,
webrender_document: self.webrender_document,
webrender_api_sender: self.webrender_api_sender.clone(),
},
self.load_data.clone(),
);
Expand Down
21 changes: 20 additions & 1 deletion components/script/dom/window.rs
Expand Up @@ -132,7 +132,9 @@ use time;
use timers::{IsInterval, TimerCallback};
use url::Position;
use webdriver_handlers::jsval_to_webdriver;
use webrender_api::{ExternalScrollId, DeviceIntPoint, DeviceUintSize, DocumentId};
use webrender_api::{
DeviceIntPoint, DeviceUintSize, DocumentId, ExternalScrollId, RenderApiSender,
};
use webvr_traits::WebVRMsg;

/// Current state of the window object
Expand Down Expand Up @@ -308,6 +310,17 @@ pub struct Window {

/// Flag to identify whether mutation observers are present(true)/absent(false)
exists_mut_observer: Cell<bool>,
/// Webrender API Sender
#[ignore_malloc_size_of = "defined in webrender_api"]
webrender_api_sender: RenderApiSender,
}

// FIXME(victor): this doesn't belong here
#[allow(unsafe_code)]
unsafe impl ::dom::bindings::trace::JSTraceable for RenderApiSender {
unsafe fn trace(&self, _trc: *mut ::js::jsapi::JSTracer) {
// Do nothing
}
}

impl Window {
Expand Down Expand Up @@ -483,6 +496,10 @@ impl Window {
}
self.add_pending_reflow();
}

pub fn get_webrender_api_sender(&self) -> RenderApiSender {
self.webrender_api_sender.clone()
}
}

// https://html.spec.whatwg.org/multipage/#atob
Expand Down Expand Up @@ -2083,6 +2100,7 @@ impl Window {
webvr_chan: Option<IpcSender<WebVRMsg>>,
microtask_queue: Rc<MicrotaskQueue>,
webrender_document: DocumentId,
webrender_api_sender: RenderApiSender,
) -> DomRoot<Self> {
let layout_rpc: Box<LayoutRPC + Send> = {
let (rpc_send, rpc_recv) = channel();
Expand Down Expand Up @@ -2161,6 +2179,7 @@ impl Window {
paint_worklet: Default::default(),
webrender_document,
exists_mut_observer: Cell::new(false),
webrender_api_sender,
});

unsafe { WindowBinding::Wrap(runtime.cx(), win) }
Expand Down
7 changes: 6 additions & 1 deletion components/script/script_thread.rs
Expand Up @@ -130,7 +130,7 @@ use time::{get_time, precise_time_ns, Tm};
use url::Position;
use url::percent_encoding::percent_decode;
use webdriver_handlers;
use webrender_api::DocumentId;
use webrender_api::{DocumentId, RenderApiSender};
use webvr_traits::{WebVREvent, WebVRMsg};

pub type ImageCacheMsg = (PipelineId, PendingImageResponse);
Expand Down Expand Up @@ -591,6 +591,9 @@ pub struct ScriptThread {

/// The Webrender Document ID associated with this thread.
webrender_document: DocumentId,

/// FIXME(victor):
webrender_api_sender: RenderApiSender,
}

/// In the event of thread panic, all data on the stack runs its destructor. However, there
Expand Down Expand Up @@ -1063,6 +1066,7 @@ impl ScriptThread {
custom_element_reaction_stack: CustomElementReactionStack::new(),

webrender_document: state.webrender_document,
webrender_api_sender: state.webrender_api_sender,
}
}

Expand Down Expand Up @@ -2584,6 +2588,7 @@ impl ScriptThread {
self.webvr_chan.clone(),
self.microtask_queue.clone(),
self.webrender_document,
self.webrender_api_sender.clone(),
);

// Initialize the browsing context for the window.
Expand Down
6 changes: 5 additions & 1 deletion components/script_traits/lib.rs
Expand Up @@ -72,7 +72,9 @@ use style_traits::CSSPixel;
use style_traits::SpeculativePainter;
use style_traits::cursor::CursorKind;
use webdriver_msg::{LoadStatus, WebDriverScriptCommand};
use webrender_api::{ExternalScrollId, DevicePixel, DeviceUintSize, DocumentId, ImageKey};
use webrender_api::{
DevicePixel, DeviceUintSize, DocumentId, ExternalScrollId, ImageKey, RenderApiSender,
};
use webvr_traits::{WebVREvent, WebVRMsg};

pub use script_msg::{LayoutMsg, ScriptMsg, EventResult, LogEntry};
Expand Down Expand Up @@ -588,6 +590,8 @@ pub struct InitialScriptState {
pub webvr_chan: Option<IpcSender<WebVRMsg>>,
/// The Webrender document ID associated with this thread.
pub webrender_document: DocumentId,
/// FIXME(victor): The Webrender API sender in this constellation's pipeline
pub webrender_api_sender: RenderApiSender,
}

/// This trait allows creating a `ScriptThread` without depending on the `script`
Expand Down

0 comments on commit 781b3b7

Please sign in to comment.