Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide window #25799

Merged
merged 2 commits into from Feb 20, 2020
Merged

Hide window #25799

Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -110,6 +110,8 @@ pub enum ConstellationMsg {
ExitFullScreen(TopLevelBrowsingContextId),
/// Media session action.
MediaSessionAction(MediaSessionActionType),
/// Toggle browser visibility.
ChangeBrowserVisibility(TopLevelBrowsingContextId, bool),
}

impl fmt::Debug for ConstellationMsg {
@@ -141,6 +143,7 @@ impl fmt::Debug for ConstellationMsg {
DisableProfiler => "DisableProfiler",
ExitFullScreen(..) => "ExitFullScreen",
MediaSessionAction(..) => "MediaSessionAction",
ChangeBrowserVisibility(..) => "ChangeBrowserVisibility",
};
write!(formatter, "ConstellationMsg::{}", variant)
}
@@ -105,6 +105,8 @@ pub enum WindowEvent {
/// Sent when the user triggers a media action through the UA exposed media UI
/// (play, pause, seek, etc.).
MediaSessionAction(MediaSessionActionType),
/// Set browser visibility. A hidden browser will not tick the animations.
ChangeBrowserVisibility(TopLevelBrowsingContextId, bool),
}

impl Debug for WindowEvent {
@@ -136,6 +138,7 @@ impl Debug for WindowEvent {
WindowEvent::ToggleSamplingProfiler(..) => write!(f, "ToggleSamplingProfiler"),
WindowEvent::ExitFullScreen(..) => write!(f, "ExitFullScreen"),
WindowEvent::MediaSessionAction(..) => write!(f, "MediaSessionAction"),
WindowEvent::ChangeBrowserVisibility(..) => write!(f, "ChangeBrowserVisibility"),
}
}
}
@@ -1681,6 +1681,9 @@ where
FromCompositorMsg::MediaSessionAction(action) => {
self.handle_media_session_action_msg(action);
},
FromCompositorMsg::ChangeBrowserVisibility(top_level_browsing_context_id, visible) => {
self.handle_change_browser_visibility(top_level_browsing_context_id, visible);
},
}
}

@@ -4276,6 +4279,32 @@ where
}
}

fn handle_change_browser_visibility(
&mut self,
top_level_browsing_context_id: TopLevelBrowsingContextId,
visible: bool,
) {
let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id);
let pipeline_id = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context.pipeline_id,
None => {
return warn!(
"Browsing context {} got visibility change event after closure.",
browsing_context_id
);
},
};
match self.pipelines.get(&pipeline_id) {
None => {
return warn!(
"Pipeline {} got visibility change event after closure.",
pipeline_id
)
},
Some(pipeline) => pipeline.notify_visibility(visible),
};
}

fn notify_history_changed(&self, top_level_browsing_context_id: TopLevelBrowsingContextId) {
// Send a flat projection of the history to embedder.
// The final vector is a concatenation of the LoadData of the past
@@ -735,6 +735,19 @@ where
);
}
},

WindowEvent::ChangeBrowserVisibility(top_level_browsing_context_id, visible) => {
let msg = ConstellationMsg::ChangeBrowserVisibility(
top_level_browsing_context_id,
visible,
);
if let Err(e) = self.constellation_chan.send(msg) {
warn!(
"Sending ChangeBrowserVisibility to constellation failed ({:?}).",
e
);
}
},
}
}

@@ -487,6 +487,17 @@ impl ServoGlue {
self.process_event(WindowEvent::MediaSessionAction(action))
}

pub fn change_visibility(&mut self, visible: bool) -> Result<(), &'static str> {
info!("change_visibility");
if let Ok(id) = self.get_browser_id() {
let event = WindowEvent::ChangeBrowserVisibility(id, visible);
self.process_event(event)
} else {
// Ignore visibility change if no browser has been created yet.
Ok(())
}
}

fn process_event(&mut self, event: WindowEvent) -> Result<(), &'static str> {
self.events.push(event);
if !self.batch_mode {
@@ -686,6 +686,14 @@ pub extern "C" fn media_session_action(action: CMediaSessionActionType) {
});
}

#[no_mangle]
pub extern "C" fn change_visibility(visible: bool) {
catch_any_panic(|| {
debug!("change_visibility");
call(|s| s.change_visibility(visible));
});
}

pub struct WakeupCallback(extern "C" fn());

impl WakeupCallback {
@@ -71,6 +71,10 @@ void BrowserPage::BindServoEvents() {
? Visibility::Collapsed
: Visibility::Visible);
});
Window::Current().VisibilityChanged(

This comment has been minimized.

Copy link
@Manishearth

Manishearth Feb 19, 2020

Member

I assume this gets called when we enter immersive mode on the hololens as well, right? Is there an FPS improvement?

This comment has been minimized.

Copy link
@paulrouget

paulrouget Feb 20, 2020

Author Contributor

I assume this gets called when we enter immersive mode on the hololens as well, right?

Yes.

Is there an FPS improvement?

I haven't looked.

This comment has been minimized.

Copy link
@paulrouget

paulrouget Feb 20, 2020

Author Contributor

I don't see obvious improvements, but the emulator is probably not the best way of measure that.

[=](const auto &, const VisibilityChangedEventArgs &args) {
servoControl().ChangeVisibility(args.Visible());
});
}

void BrowserPage::OnURLFocused(Windows::Foundation::IInspectable const &) {
@@ -14,7 +14,7 @@
<ApplicationType>Windows Store</ApplicationType>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.17763.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformMinVersion>10.0.17134.0</WindowsTargetPlatformMinVersion>
<WindowsTargetPlatformMinVersion>10.0.17763.0</WindowsTargetPlatformMinVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<ItemGroup Label="ProjectConfigurations">
@@ -56,6 +56,7 @@ class Servo {
void Reload() { capi::reload(); }
void Stop() { capi::stop(); }
bool LoadUri(hstring uri) { return capi::load_uri(*hstring2char(uri)); }
void ChangeVisibility(bool visible) { capi::change_visibility(visible); }
bool IsUriValid(hstring uri) {
return capi::is_uri_valid(*hstring2char(uri));
}
@@ -247,6 +247,9 @@ void ServoControl::GoForward() {
void ServoControl::Reload() {
RunOnGLThread([=] { mServo->Reload(); });
}
void ServoControl::ChangeVisibility(bool visible) {
RunOnGLThread([=] { mServo->ChangeVisibility(visible); });
}
void ServoControl::Stop() {
RunOnGLThread([=] { mServo->Stop(); });
}
@@ -13,6 +13,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
void GoForward();
void Reload();
void Stop();
void ChangeVisibility(bool);
void Shutdown();
hstring LoadURIOrSearch(hstring);
void SendMediaSessionAction(int32_t);
@@ -14,6 +14,7 @@ namespace ServoApp {
void SetTransientMode(Boolean transient);
void SetArgs(String args);
void Shutdown();
void ChangeVisibility(Boolean visible);
void SendMediaSessionAction(UInt32 action);
event EventDelegate OnLoadStarted;
event EventDelegate OnLoadEnded;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.