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 {
return IsNewerThan(other) || *this == other;
}
LocalSurfaceId LocalSurfaceId::ToSmallestId() const {
return LocalSurfaceId(1, 1, embed_token_);
}
} // namespace viz
......@@ -144,6 +144,10 @@ class VIZ_COMMON_EXPORT LocalSurfaceId {
// it.
bool IsSameOrNewerThan(const LocalSurfaceId& other) const;
// Returns the smallest valid LocalSurfaceId with the same embed token as this
// LocalSurfaceID.
LocalSurfaceId ToSmallestId() const;
private:
friend struct mojo::StructTraits<mojom::LocalSurfaceIdDataView,
LocalSurfaceId>;
......
......@@ -32,6 +32,10 @@ uint32_t SurfaceId::ManhattanDistanceTo(const SurfaceId& other) const {
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) {
return out << surface_id.ToString();
}
......@@ -42,4 +46,8 @@ bool SurfaceId::IsNewerThan(const SurfaceId& other) const {
return local_surface_id_.IsNewerThan(other.local_surface_id());
}
bool SurfaceId::IsSameOrNewerThan(const SurfaceId& other) const {
return (*this == other) || IsNewerThan(other);
}
} // namespace viz
......@@ -62,10 +62,18 @@ class VIZ_COMMON_EXPORT SurfaceId {
// Returns whether this SurfaceId was generated after |other|.
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
// parent sequence numbers plus the difference between child sequence numbers.
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 {
return frame_sink_id_ == other.frame_sink_id_ &&
local_surface_id_ == other.local_surface_id_;
......
......@@ -484,20 +484,45 @@ void DelegatedFrameHost::WindowTitleChanged(const std::string& title) {
}
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;
// 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()) {
client_->DelegatedFrameHostGetLayer()->SetShowPrimarySurface(
*other->client_->DelegatedFrameHostGetLayer()->GetFallbackSurfaceId(),
other->client_->DelegatedFrameHostGetLayer()->size(),
desired_fallback, other->client_->DelegatedFrameHostGetLayer()->size(),
other->client_->DelegatedFrameHostGetLayer()->background_color(),
cc::DeadlinePolicy::UseDefaultDeadline(),
false /* stretch_content_to_fill_bounds */);
}
client_->DelegatedFrameHostGetLayer()->SetFallbackSurfaceId(
*other->client_->DelegatedFrameHostGetLayer()->GetFallbackSurfaceId());
client_->DelegatedFrameHostGetLayer()->SetFallbackSurfaceId(desired_fallback);
}
} // namespace content
......@@ -470,6 +470,10 @@ viz::SurfaceId DelegatedFrameHostAndroid::SurfaceId() const {
: viz::SurfaceId();
}
bool DelegatedFrameHostAndroid::HasPrimarySurface() const {
return content_layer_ && content_layer_->primary_surface_id().is_valid();
}
bool DelegatedFrameHostAndroid::HasFallbackSurface() const {
return content_layer_ && content_layer_->fallback_surface_id() &&
content_layer_->fallback_surface_id()->is_valid();
......@@ -477,10 +481,26 @@ bool DelegatedFrameHostAndroid::HasFallbackSurface() const {
void DelegatedFrameHostAndroid::TakeFallbackContentFrom(
DelegatedFrameHostAndroid* other) {
if (HasFallbackSurface() || !other->HasFallbackSurface())
if (HasFallbackSurface() || !other->HasPrimarySurface())
return;
if (!enable_surface_synchronization_) {
if (enable_surface_synchronization_) {
const viz::SurfaceId& other_primary =
other->content_layer_->primary_surface_id();
const base::Optional<viz::SurfaceId>& other_fallback =
other->content_layer_->fallback_surface_id();
viz::SurfaceId desired_fallback;
if (!other->HasFallbackSurface() ||
!other_primary.IsSameOrNewerThan(*other_fallback)) {
desired_fallback = other_primary.ToSmallestId();
} else {
desired_fallback = *other_fallback;
}
content_layer_->SetFallbackSurfaceId(
other->content_layer_->primary_surface_id().ToSmallestId());
return;
}
if (content_layer_) {
content_layer_->SetPrimarySurfaceId(
*other->content_layer_->fallback_surface_id(),
......@@ -498,7 +518,6 @@ void DelegatedFrameHostAndroid::TakeFallbackContentFrom(
other->content_layer_->contents_opaque());
view_->GetLayer()->AddChild(content_layer_);
}
}
content_layer_->SetFallbackSurfaceId(
*other->content_layer_->fallback_surface_id());
}
......
......@@ -134,6 +134,7 @@ class UI_ANDROID_EXPORT DelegatedFrameHostAndroid
// Returns the ID for the current Surface. Returns an invalid ID if no
// surface exists (!HasDelegatedContent()).
viz::SurfaceId SurfaceId() const;
bool HasPrimarySurface() const;
bool HasFallbackSurface() const;
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