Enable SurfaceLayerForVideo for PIP only.
This CL adds a new flag, UseSurfaceLayerForVideoPIP, which will
switch to SurfaceLayer only when entering PIP mode. The player does
not switch back when exiting PIP.
When doing this, the VideoFrameCompositor, VFS, etc. all run on
the compositor impl thread rather than a dedicated media thread.
This is to simplify the switchover.
This CL also changes the default from Use...Video to Use...PIP.
This is based on
https://chromium-review.googlesource.com/c/chromium/src/+/1219948
Bug: 883931
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ibb612d83df721712929aeab42aba790e32c1a8ea
Reviewed-on: https://chromium-review.googlesource.com/1220562
Reviewed-by: Fady Samuel <[email protected]>
Reviewed-by: François Doray <[email protected]>
Reviewed-by: Bo <[email protected]>
Reviewed-by: Kenneth Russell <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Mounir Lamouri <[email protected]>
Reviewed-by: Dale Curtis <[email protected]>
Commit-Queue: Frank Liberato <[email protected]>
Cr-Commit-Position: refs/heads/master@{#594459}
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
index d8a90a5..253f3fd 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -270,7 +270,7 @@
params->enable_instant_source_buffer_gc()),
embedded_media_experience_enabled_(
params->embedded_media_experience_enabled()),
- surface_layer_for_video_enabled_(params->use_surface_layer_for_video()),
+ surface_layer_mode_(params->use_surface_layer_for_video()),
create_bridge_callback_(params->create_bridge_callback()),
request_routing_token_cb_(params->request_routing_token_cb()),
overlay_routing_token_(OverlayInfo::RoutingToken()),
@@ -818,6 +818,9 @@
void WebMediaPlayerImpl::EnterPictureInPicture(
blink::WebMediaPlayer::PipWindowOpenedCallback callback) {
+ if (!surface_layer_for_video_enabled_)
+ ActivateSurfaceLayerForVideo();
+
DCHECK(bridge_);
const viz::SurfaceId& surface_id = bridge_->GetSurfaceId();
@@ -1669,7 +1672,8 @@
DisableOverlay();
}
- if (!surface_layer_for_video_enabled_) {
+ if (surface_layer_mode_ !=
+ WebMediaPlayerParams::SurfaceLayerMode::kAlways) {
DCHECK(!video_layer_);
video_layer_ = cc::VideoLayer::Create(
compositor_.get(),
@@ -1677,35 +1681,7 @@
video_layer_->SetContentsOpaque(opaque_);
client_->SetCcLayer(video_layer_.get());
} else {
- DCHECK(!bridge_);
-
- bridge_ = std::move(create_bridge_callback_)
- .Run(this, compositor_->GetUpdateSubmissionStateCallback());
- bridge_->CreateSurfaceLayer();
-
- vfc_task_runner_->PostTask(
- FROM_HERE,
- base::BindOnce(
- &VideoFrameCompositor::EnableSubmission,
- base::Unretained(compositor_.get()), bridge_->GetSurfaceId(),
- pipeline_metadata_.video_decoder_config.video_rotation(),
- IsInPictureInPicture(), opaque_,
- BindToCurrentLoop(base::BindRepeating(
- &WebMediaPlayerImpl::OnFrameSinkDestroyed, AsWeakPtr()))));
- bridge_->SetContentsOpaque(opaque_);
-
- // If the element is already in Picture-in-Picture mode, it means that it
- // was set in this mode prior to this load, with a different
- // WebMediaPlayerImpl. The new player needs to send its id, size and
- // surface id to the browser process to make sure the states are properly
- // updated.
- // TODO(872056): the surface should be activated but for some reasons, it
- // does not. It is possible that this will no longer be neded after 872056
- // is fixed.
- if (client_->DisplayType() ==
- WebMediaPlayer::DisplayType::kPictureInPicture) {
- OnSurfaceIdUpdated(bridge_->GetSurfaceId());
- }
+ ActivateSurfaceLayerForVideo();
}
}
@@ -1721,6 +1697,47 @@
UpdatePlayState();
}
+void WebMediaPlayerImpl::ActivateSurfaceLayerForVideo() {
+ // Note that we might or might not already be in VideoLayer mode.
+ DCHECK(!bridge_);
+
+ surface_layer_for_video_enabled_ = true;
+
+ // If we're in VideoLayer mode, then get rid of the layer.
+ if (video_layer_) {
+ client_->SetCcLayer(nullptr);
+ video_layer_ = nullptr;
+ }
+
+ bridge_ = std::move(create_bridge_callback_)
+ .Run(this, compositor_->GetUpdateSubmissionStateCallback());
+ bridge_->CreateSurfaceLayer();
+
+ vfc_task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(
+ &VideoFrameCompositor::EnableSubmission,
+ base::Unretained(compositor_.get()), bridge_->GetSurfaceId(),
+ pipeline_metadata_.video_decoder_config.video_rotation(),
+ IsInPictureInPicture(), opaque_,
+ BindToCurrentLoop(base::BindRepeating(
+ &WebMediaPlayerImpl::OnFrameSinkDestroyed, AsWeakPtr()))));
+ bridge_->SetContentsOpaque(opaque_);
+
+ // If the element is already in Picture-in-Picture mode, it means that it
+ // was set in this mode prior to this load, with a different
+ // WebMediaPlayerImpl. The new player needs to send its id, size and
+ // surface id to the browser process to make sure the states are properly
+ // updated.
+ // TODO(872056): the surface should be activated but for some reasons, it
+ // does not. It is possible that this will no longer be needed after 872056
+ // is fixed.
+ if (client_->DisplayType() ==
+ WebMediaPlayer::DisplayType::kPictureInPicture) {
+ OnSurfaceIdUpdated(bridge_->GetSurfaceId());
+ }
+}
+
void WebMediaPlayerImpl::OnFrameSinkDestroyed() {
bridge_->ClearSurfaceId();
}