aboutsummaryrefslogtreecommitdiffstats
path: root/components/compositing/compositor_thread.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/compositing/compositor_thread.rs')
-rw-r--r--components/compositing/compositor_thread.rs141
1 files changed, 98 insertions, 43 deletions
diff --git a/components/compositing/compositor_thread.rs b/components/compositing/compositor_thread.rs
index 08ecfef50d2..03a7b46c7c0 100644
--- a/components/compositing/compositor_thread.rs
+++ b/components/compositing/compositor_thread.rs
@@ -29,6 +29,45 @@ pub trait EventLoopWaker : 'static + Send {
fn wake(&self);
}
+/// Sends messages to the embedder.
+pub struct EmbedderProxy {
+ pub sender: Sender<EmbedderMsg>,
+ pub event_loop_waker: Box<EventLoopWaker>,
+}
+
+impl EmbedderProxy {
+ pub fn send(&self, msg: EmbedderMsg) {
+ // Send a message and kick the OS event loop awake.
+ if let Err(err) = self.sender.send(msg) {
+ warn!("Failed to send response ({}).", err);
+ }
+ self.event_loop_waker.wake();
+ }
+}
+
+impl Clone for EmbedderProxy {
+ fn clone(&self) -> EmbedderProxy {
+ EmbedderProxy {
+ sender: self.sender.clone(),
+ event_loop_waker: self.event_loop_waker.clone(),
+ }
+ }
+}
+
+/// The port that the embedder receives messages on.
+pub struct EmbedderReceiver {
+ pub receiver: Receiver<EmbedderMsg>
+}
+
+impl EmbedderReceiver {
+ pub fn try_recv_embedder_msg(&mut self) -> Option<EmbedderMsg> {
+ self.receiver.try_recv().ok()
+ }
+ pub fn recv_embedder_msg(&mut self) -> EmbedderMsg {
+ self.receiver.recv().unwrap()
+ }
+}
+
/// Sends messages to the compositor.
pub struct CompositorProxy {
pub sender: Sender<Msg>,
@@ -43,7 +82,10 @@ impl CompositorProxy {
}
self.event_loop_waker.wake();
}
- pub fn clone_compositor_proxy(&self) -> CompositorProxy {
+}
+
+impl Clone for CompositorProxy {
+ fn clone(&self) -> CompositorProxy {
CompositorProxy {
sender: self.sender.clone(),
event_loop_waker: self.event_loop_waker.clone(),
@@ -75,6 +117,37 @@ impl RenderListener for CompositorProxy {
}
}
+pub enum EmbedderMsg {
+ /// A status message to be displayed by the browser chrome.
+ Status(TopLevelBrowsingContextId, Option<String>),
+ /// Alerts the embedder that the current page has changed its title.
+ ChangePageTitle(TopLevelBrowsingContextId, Option<String>),
+ /// Move the window to a point
+ MoveTo(TopLevelBrowsingContextId, Point2D<i32>),
+ /// Resize the window to size
+ ResizeTo(TopLevelBrowsingContextId, Size2D<u32>),
+ /// Get Window Informations size and position
+ GetClientWindow(TopLevelBrowsingContextId, IpcSender<(Size2D<u32>, Point2D<i32>)>),
+ /// Wether or not to follow a link
+ AllowNavigation(TopLevelBrowsingContextId, ServoUrl, IpcSender<bool>),
+ /// Sends an unconsumed key event back to the embedder.
+ KeyEvent(Option<TopLevelBrowsingContextId>, Option<char>, Key, KeyState, KeyModifiers),
+ /// Changes the cursor.
+ SetCursor(Cursor),
+ /// A favicon was detected
+ NewFavicon(TopLevelBrowsingContextId, ServoUrl),
+ /// <head> tag finished parsing
+ HeadParsed(TopLevelBrowsingContextId),
+ /// The history state has changed.
+ HistoryChanged(TopLevelBrowsingContextId, Vec<LoadData>, usize),
+ /// Enter or exit fullscreen
+ SetFullscreenState(TopLevelBrowsingContextId, bool),
+ /// The load of a page has begun
+ LoadStart(TopLevelBrowsingContextId),
+ /// The load of a page has completed
+ LoadComplete(TopLevelBrowsingContextId),
+}
+
/// Messages from the painting thread and the constellation thread to the compositor thread.
pub enum Msg {
/// Requests that the compositor shut down.
@@ -87,46 +160,20 @@ pub enum Msg {
/// Scroll a page in a window
ScrollFragmentPoint(webrender_api::ClipId, Point2D<f32>, bool),
- /// Alerts the compositor that the current page has changed its title.
- ChangePageTitle(TopLevelBrowsingContextId, Option<String>),
/// Alerts the compositor that the given pipeline has changed whether it is running animations.
ChangeRunningAnimationsState(PipelineId, AnimationState),
/// Replaces the current frame tree, typically called during main frame navigation.
SetFrameTree(SendableFrameTree),
- /// The load of a page has begun
- LoadStart(TopLevelBrowsingContextId),
- /// The load of a page has completed
- LoadComplete(TopLevelBrowsingContextId),
- /// The history state has changed.
- HistoryChanged(TopLevelBrowsingContextId, Vec<LoadData>, usize),
- /// Wether or not to follow a link
- AllowNavigation(TopLevelBrowsingContextId, ServoUrl, IpcSender<bool>),
/// Composite.
Recomposite(CompositingReason),
- /// Sends an unconsumed key event back to the compositor.
- KeyEvent(Option<TopLevelBrowsingContextId>, Option<char>, Key, KeyState, KeyModifiers),
/// Script has handled a touch event, and either prevented or allowed default actions.
TouchEventProcessed(EventResult),
- /// Changes the cursor.
- SetCursor(Cursor),
/// Composite to a PNG file and return the Image over a passed channel.
CreatePng(IpcSender<Option<Image>>),
/// Alerts the compositor that the viewport has been constrained in some manner
ViewportConstrained(PipelineId, ViewportConstraints),
/// A reply to the compositor asking if the output image is stable.
IsReadyToSaveImageReply(bool),
- /// A favicon was detected
- NewFavicon(TopLevelBrowsingContextId, ServoUrl),
- /// <head> tag finished parsing
- HeadParsed(TopLevelBrowsingContextId),
- /// A status message to be displayed by the browser chrome.
- Status(TopLevelBrowsingContextId, Option<String>),
- /// Get Window Informations size and position
- GetClientWindow(TopLevelBrowsingContextId, IpcSender<(Size2D<u32>, Point2D<i32>)>),
- /// Move the window to a point
- MoveTo(TopLevelBrowsingContextId, Point2D<i32>),
- /// Resize the window to size
- ResizeTo(TopLevelBrowsingContextId, Size2D<u32>),
/// Pipeline visibility changed
PipelineVisibilityChanged(PipelineId, bool),
/// WebRender has successfully processed a scroll. The boolean specifies whether a composite is
@@ -142,12 +189,12 @@ pub enum Msg {
/// It's used to dispatch functions from webrender to the main thread's event loop.
/// Required to allow WGL GLContext sharing in Windows.
Dispatch(Box<Fn() + Send>),
- /// Enter or exit fullscreen
- SetFullscreenState(TopLevelBrowsingContextId, bool),
/// Indicates to the compositor that it needs to record the time when the frame with
/// the given ID (epoch) is painted and report it to the layout thread of the given
/// pipeline ID.
PendingPaintMetric(PipelineId, Epoch),
+ /// The load of a page has completed
+ LoadComplete(TopLevelBrowsingContextId),
}
impl Debug for Msg {
@@ -157,31 +204,39 @@ impl Debug for Msg {
Msg::ShutdownComplete => write!(f, "ShutdownComplete"),
Msg::ScrollFragmentPoint(..) => write!(f, "ScrollFragmentPoint"),
Msg::ChangeRunningAnimationsState(..) => write!(f, "ChangeRunningAnimationsState"),
- Msg::ChangePageTitle(..) => write!(f, "ChangePageTitle"),
Msg::SetFrameTree(..) => write!(f, "SetFrameTree"),
- Msg::LoadComplete(..) => write!(f, "LoadComplete"),
- Msg::AllowNavigation(..) => write!(f, "AllowNavigation"),
- Msg::LoadStart(..) => write!(f, "LoadStart"),
- Msg::HistoryChanged(..) => write!(f, "HistoryChanged"),
Msg::Recomposite(..) => write!(f, "Recomposite"),
- Msg::KeyEvent(..) => write!(f, "KeyEvent"),
Msg::TouchEventProcessed(..) => write!(f, "TouchEventProcessed"),
- Msg::SetCursor(..) => write!(f, "SetCursor"),
Msg::CreatePng(..) => write!(f, "CreatePng"),
Msg::ViewportConstrained(..) => write!(f, "ViewportConstrained"),
Msg::IsReadyToSaveImageReply(..) => write!(f, "IsReadyToSaveImageReply"),
- Msg::NewFavicon(..) => write!(f, "NewFavicon"),
- Msg::HeadParsed(..) => write!(f, "HeadParsed"),
- Msg::Status(..) => write!(f, "Status"),
- Msg::GetClientWindow(..) => write!(f, "GetClientWindow"),
- Msg::MoveTo(..) => write!(f, "MoveTo"),
- Msg::ResizeTo(..) => write!(f, "ResizeTo"),
Msg::PipelineVisibilityChanged(..) => write!(f, "PipelineVisibilityChanged"),
Msg::PipelineExited(..) => write!(f, "PipelineExited"),
Msg::NewScrollFrameReady(..) => write!(f, "NewScrollFrameReady"),
Msg::Dispatch(..) => write!(f, "Dispatch"),
- Msg::SetFullscreenState(..) => write!(f, "SetFullscreenState"),
Msg::PendingPaintMetric(..) => write!(f, "PendingPaintMetric"),
+ Msg::LoadComplete(..) => write!(f, "LoadComplete"),
+ }
+ }
+}
+
+impl Debug for EmbedderMsg {
+ fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
+ match *self {
+ EmbedderMsg::Status(..) => write!(f, "Status"),
+ EmbedderMsg::ChangePageTitle(..) => write!(f, "ChangePageTitle"),
+ EmbedderMsg::MoveTo(..) => write!(f, "MoveTo"),
+ EmbedderMsg::ResizeTo(..) => write!(f, "ResizeTo"),
+ EmbedderMsg::GetClientWindow(..) => write!(f, "GetClientWindow"),
+ EmbedderMsg::AllowNavigation(..) => write!(f, "AllowNavigation"),
+ EmbedderMsg::KeyEvent(..) => write!(f, "KeyEvent"),
+ EmbedderMsg::SetCursor(..) => write!(f, "SetCursor"),
+ EmbedderMsg::NewFavicon(..) => write!(f, "NewFavicon"),
+ EmbedderMsg::HeadParsed(..) => write!(f, "HeadParsed"),
+ EmbedderMsg::HistoryChanged(..) => write!(f, "HistoryChanged"),
+ EmbedderMsg::SetFullscreenState(..) => write!(f, "SetFullscreenState"),
+ EmbedderMsg::LoadStart(..) => write!(f, "LoadStart"),
+ EmbedderMsg::LoadComplete(..) => write!(f, "LoadComplete"),
}
}
}