Commit f03a9dba authored by Saman Sami's avatar Saman Sami Committed by Commit Bot

Use primary surface in TakeFallbackContentFrom when there is no fallback

Also when a fallback exists but has a different FrameSinkId or embed token
than the primary, don't use the fallback because the resulting range in
the new view will not cover any surface with the FrameSinkId or embed
token of the old view's primary.

Bug: 857575,870456
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: Ia4736f354160dfd510793bf35ae4292c276bf115
Reviewed-on: https://chromium-review.googlesource.com/1236456Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarFady Samuel <fsamuel@chromium.org>
Commit-Queue: Saman Sami <samans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593598}
parent 4264ffe8
...@@ -38,4 +38,8 @@ bool LocalSurfaceId::IsSameOrNewerThan(const LocalSurfaceId& other) const { ...@@ -38,4 +38,8 @@ bool LocalSurfaceId::IsSameOrNewerThan(const LocalSurfaceId& other) const {
return IsNewerThan(other) || *this == other; return IsNewerThan(other) || *this == other;
} }
LocalSurfaceId LocalSurfaceId::ToSmallestId() const {
return LocalSurfaceId(1, 1, embed_token_);
}
} // namespace viz } // namespace viz
...@@ -144,6 +144,10 @@ class VIZ_COMMON_EXPORT LocalSurfaceId { ...@@ -144,6 +144,10 @@ class VIZ_COMMON_EXPORT LocalSurfaceId {
// it. // it.
bool IsSameOrNewerThan(const LocalSurfaceId& other) const; bool IsSameOrNewerThan(const LocalSurfaceId& other) const;
// Returns the smallest valid LocalSurfaceId with the same embed token as this
// LocalSurfaceID.
LocalSurfaceId ToSmallestId() const;
private: private:
friend struct mojo::StructTraits<mojom::LocalSurfaceIdDataView, friend struct mojo::StructTraits<mojom::LocalSurfaceIdDataView,
LocalSurfaceId>; LocalSurfaceId>;
......
...@@ -32,6 +32,10 @@ uint32_t SurfaceId::ManhattanDistanceTo(const SurfaceId& other) const { ...@@ -32,6 +32,10 @@ uint32_t SurfaceId::ManhattanDistanceTo(const SurfaceId& other) const {
other.local_surface_id().child_sequence_number())); other.local_surface_id().child_sequence_number()));
} }
SurfaceId SurfaceId::ToSmallestId() const {
return SurfaceId(frame_sink_id_, local_surface_id_.ToSmallestId());
}
std::ostream& operator<<(std::ostream& out, const SurfaceId& surface_id) { std::ostream& operator<<(std::ostream& out, const SurfaceId& surface_id) {
return out << surface_id.ToString(); return out << surface_id.ToString();
} }
...@@ -42,4 +46,8 @@ bool SurfaceId::IsNewerThan(const SurfaceId& other) const { ...@@ -42,4 +46,8 @@ bool SurfaceId::IsNewerThan(const SurfaceId& other) const {
return local_surface_id_.IsNewerThan(other.local_surface_id()); return local_surface_id_.IsNewerThan(other.local_surface_id());
} }
bool SurfaceId::IsSameOrNewerThan(const SurfaceId& other) const {
return (*this == other) || IsNewerThan(other);
}
} // namespace viz } // namespace viz
...@@ -62,10 +62,18 @@ class VIZ_COMMON_EXPORT SurfaceId { ...@@ -62,10 +62,18 @@ class VIZ_COMMON_EXPORT SurfaceId {
// Returns whether this SurfaceId was generated after |other|. // Returns whether this SurfaceId was generated after |other|.
bool IsNewerThan(const SurfaceId& other) const; bool IsNewerThan(const SurfaceId& other) const;
// Returns whether this SurfaceId is the same as or was generated after
// |other|.
bool IsSameOrNewerThan(const SurfaceId& other) const;
// Compare this SurfaceId with |other| and returns the difference between the // Compare this SurfaceId with |other| and returns the difference between the
// parent sequence numbers plus the difference between child sequence numbers. // parent sequence numbers plus the difference between child sequence numbers.
uint32_t ManhattanDistanceTo(const SurfaceId& other) const; uint32_t ManhattanDistanceTo(const SurfaceId& other) const;
// Returns the smallest valid SurfaceId with the same FrameSinkId and embed
// token as this SurfaceId.
SurfaceId ToSmallestId() const;
bool operator==(const SurfaceId& other) const { bool operator==(const SurfaceId& other) const {
return frame_sink_id_ == other.frame_sink_id_ && return frame_sink_id_ == other.frame_sink_id_ &&
local_surface_id_ == other.local_surface_id_; local_surface_id_ == other.local_surface_id_;
......
...@@ -484,20 +484,45 @@ void DelegatedFrameHost::WindowTitleChanged(const std::string& title) { ...@@ -484,20 +484,45 @@ void DelegatedFrameHost::WindowTitleChanged(const std::string& title) {
} }
void DelegatedFrameHost::TakeFallbackContentFrom(DelegatedFrameHost* other) { void DelegatedFrameHost::TakeFallbackContentFrom(DelegatedFrameHost* other) {
if (!other->HasFallbackSurface() || HasFallbackSurface()) // If the other view is not showing anything, we can't obtain a fallback.
if (!other->HasPrimarySurface())
return; return;
// This method should not overwrite the existing fallback. This method is only
// supposed to be called when the view was just created and there is no
// existing fallback.
if (HasFallbackSurface())
return;
const viz::SurfaceId* other_primary =
other->client_->DelegatedFrameHostGetLayer()->GetPrimarySurfaceId();
const viz::SurfaceId* other_fallback =
other->client_->DelegatedFrameHostGetLayer()->GetFallbackSurfaceId();
// In two cases we need to obtain a new fallback from the primary id of the
// other view instead of using its fallback:
// - When the other view has no fallback,
// - When a fallback exists but has a different FrameSinkId or embed token
// than the primary. If we use the fallback, then the resulting SurfaceRange
// in this view will not cover any surface with the FrameSinkId / embed token
// of the old view's primary.
viz::SurfaceId desired_fallback;
if (!other_fallback || !other_primary->IsSameOrNewerThan(*other_fallback)) {
desired_fallback = other_primary->ToSmallestId();
} else {
desired_fallback = *other_fallback;
}
if (!HasPrimarySurface()) { if (!HasPrimarySurface()) {
client_->DelegatedFrameHostGetLayer()->SetShowPrimarySurface( client_->DelegatedFrameHostGetLayer()->SetShowPrimarySurface(
*other->client_->DelegatedFrameHostGetLayer()->GetFallbackSurfaceId(), desired_fallback, other->client_->DelegatedFrameHostGetLayer()->size(),
other->client_->DelegatedFrameHostGetLayer()->size(),
other->client_->DelegatedFrameHostGetLayer()->background_color(), other->client_->DelegatedFrameHostGetLayer()->background_color(),
cc::DeadlinePolicy::UseDefaultDeadline(), cc::DeadlinePolicy::UseDefaultDeadline(),
false /* stretch_content_to_fill_bounds */); false /* stretch_content_to_fill_bounds */);
} }
client_->DelegatedFrameHostGetLayer()->SetFallbackSurfaceId( client_->DelegatedFrameHostGetLayer()->SetFallbackSurfaceId(desired_fallback);
*other->client_->DelegatedFrameHostGetLayer()->GetFallbackSurfaceId());
} }
} // namespace content } // namespace content
...@@ -470,6 +470,10 @@ viz::SurfaceId DelegatedFrameHostAndroid::SurfaceId() const { ...@@ -470,6 +470,10 @@ viz::SurfaceId DelegatedFrameHostAndroid::SurfaceId() const {
: viz::SurfaceId(); : viz::SurfaceId();
} }
bool DelegatedFrameHostAndroid::HasPrimarySurface() const {
return content_layer_ && content_layer_->primary_surface_id().is_valid();
}
bool DelegatedFrameHostAndroid::HasFallbackSurface() const { bool DelegatedFrameHostAndroid::HasFallbackSurface() const {
return content_layer_ && content_layer_->fallback_surface_id() && return content_layer_ && content_layer_->fallback_surface_id() &&
content_layer_->fallback_surface_id()->is_valid(); content_layer_->fallback_surface_id()->is_valid();
...@@ -477,27 +481,42 @@ bool DelegatedFrameHostAndroid::HasFallbackSurface() const { ...@@ -477,27 +481,42 @@ bool DelegatedFrameHostAndroid::HasFallbackSurface() const {
void DelegatedFrameHostAndroid::TakeFallbackContentFrom( void DelegatedFrameHostAndroid::TakeFallbackContentFrom(
DelegatedFrameHostAndroid* other) { DelegatedFrameHostAndroid* other) {
if (HasFallbackSurface() || !other->HasFallbackSurface()) if (HasFallbackSurface() || !other->HasPrimarySurface())
return; return;
if (!enable_surface_synchronization_) { if (enable_surface_synchronization_) {
if (content_layer_) { const viz::SurfaceId& other_primary =
content_layer_->SetPrimarySurfaceId( other->content_layer_->primary_surface_id();
*other->content_layer_->fallback_surface_id(), const base::Optional<viz::SurfaceId>& other_fallback =
cc::DeadlinePolicy::UseDefaultDeadline()); other->content_layer_->fallback_surface_id();
viz::SurfaceId desired_fallback;
if (!other->HasFallbackSurface() ||
!other_primary.IsSameOrNewerThan(*other_fallback)) {
desired_fallback = other_primary.ToSmallestId();
} else { } else {
const auto& surface_id = other->SurfaceId(); desired_fallback = *other_fallback;
active_local_surface_id_ = surface_id.local_surface_id();
pending_local_surface_id_ = active_local_surface_id_;
active_device_scale_factor_ = other->active_device_scale_factor_;
pending_surface_size_in_pixels_ = other->pending_surface_size_in_pixels_;
has_transparent_background_ = other->has_transparent_background_;
content_layer_ = CreateSurfaceLayer(
surface_id, surface_id, other->content_layer_->bounds(),
cc::DeadlinePolicy::UseDefaultDeadline(),
other->content_layer_->contents_opaque());
view_->GetLayer()->AddChild(content_layer_);
} }
content_layer_->SetFallbackSurfaceId(
other->content_layer_->primary_surface_id().ToSmallestId());
return;
}
if (content_layer_) {
content_layer_->SetPrimarySurfaceId(
*other->content_layer_->fallback_surface_id(),
cc::DeadlinePolicy::UseDefaultDeadline());
} else {
const auto& surface_id = other->SurfaceId();
active_local_surface_id_ = surface_id.local_surface_id();
pending_local_surface_id_ = active_local_surface_id_;
active_device_scale_factor_ = other->active_device_scale_factor_;
pending_surface_size_in_pixels_ = other->pending_surface_size_in_pixels_;
has_transparent_background_ = other->has_transparent_background_;
content_layer_ = CreateSurfaceLayer(
surface_id, surface_id, other->content_layer_->bounds(),
cc::DeadlinePolicy::UseDefaultDeadline(),
other->content_layer_->contents_opaque());
view_->GetLayer()->AddChild(content_layer_);
} }
content_layer_->SetFallbackSurfaceId( content_layer_->SetFallbackSurfaceId(
*other->content_layer_->fallback_surface_id()); *other->content_layer_->fallback_surface_id());
......
...@@ -134,6 +134,7 @@ class UI_ANDROID_EXPORT DelegatedFrameHostAndroid ...@@ -134,6 +134,7 @@ class UI_ANDROID_EXPORT DelegatedFrameHostAndroid
// Returns the ID for the current Surface. Returns an invalid ID if no // Returns the ID for the current Surface. Returns an invalid ID if no
// surface exists (!HasDelegatedContent()). // surface exists (!HasDelegatedContent()).
viz::SurfaceId SurfaceId() const; viz::SurfaceId SurfaceId() const;
bool HasPrimarySurface() const;
bool HasFallbackSurface() const; bool HasFallbackSurface() const;
void TakeFallbackContentFrom(DelegatedFrameHostAndroid* other); void TakeFallbackContentFrom(DelegatedFrameHostAndroid* other);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment