Skip to content

Commit

Permalink
viz: Draw and swap after primary surface is available
Browse files Browse the repository at this point in the history
If fallback SurfaceId was used during aggregation and a newer Surface
becomes available later on, make sure we mark the display as damaged
to force a draw and swap.

Bug: 843290
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: Ie0d46b547ab0c983c21c0fe003af3fbf90759aba
Reviewed-on: https://chromium-review.googlesource.com/1062585
Reviewed-by: Fady Samuel <fsamuel@chromium.org>
Commit-Queue: Saman Sami <samans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560181}
  • Loading branch information
Saman Sami authored and Commit Bot committed May 19, 2018
1 parent 9d45b94 commit bdc9b10
Show file tree
Hide file tree
Showing 4 changed files with 577 additions and 274 deletions.
24 changes: 7 additions & 17 deletions components/viz/service/display/display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,25 +490,15 @@ void Display::SetNeedsRedrawRect(const gfx::Rect& damage_rect) {

bool Display::SurfaceDamaged(const SurfaceId& surface_id,
const BeginFrameAck& ack) {
if (!ack.has_damage)
return false;
bool display_damaged = false;
if (ack.has_damage) {
if (aggregator_ &&
aggregator_->previous_contained_surfaces().count(surface_id)) {
Surface* surface = surface_manager_->GetSurfaceForId(surface_id);
if (surface) {
DCHECK(surface->HasActiveFrame());
if (surface->GetActiveFrame().resource_list.empty())
aggregator_->ReleaseResources(surface_id);
}
display_damaged = true;
if (surface_id == current_surface_id_)
UpdateRootSurfaceResourcesLocked();
} else if (surface_id == current_surface_id_) {
display_damaged = true;
UpdateRootSurfaceResourcesLocked();
}
if (aggregator_)
aggregator_->SurfaceDamaged(surface_id, &display_damaged);
if (surface_id == current_surface_id_) {
display_damaged = true;
UpdateRootSurfaceResourcesLocked();
}

return display_damaged;
}

Expand Down
36 changes: 36 additions & 0 deletions components/viz/service/display/surface_aggregator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,19 @@ gfx::Rect SurfaceAggregator::PrewalkTree(Surface* surface,
// referenced_surfaces_.
referenced_surfaces_.insert(surface->surface_id());
for (const auto& surface_info : child_surfaces) {
if (will_draw) {
if (!surface_info.fallback_id ||
surface_info.fallback_id->frame_sink_id() !=
surface_info.primary_id.frame_sink_id()) {
damage_ranges_[surface_info.primary_id.frame_sink_id()] =
std::make_pair(surface_info.primary_id.local_surface_id(),
surface_info.primary_id.local_surface_id());
} else if (surface_info.fallback_id != surface_info.primary_id) {
damage_ranges_[surface_info.primary_id.frame_sink_id()] =
std::make_pair(surface_info.fallback_id->local_surface_id(),
surface_info.primary_id.local_surface_id());
}
}
Surface* child_surface = manager_->GetSurfaceForId(surface_info.primary_id);
gfx::Rect surface_damage;
if (!child_surface || !child_surface->HasActiveFrame()) {
Expand Down Expand Up @@ -1173,6 +1186,7 @@ CompositorFrame SurfaceAggregator::Aggregate(

valid_surfaces_.clear();
has_cached_render_passes_ = false;
damage_ranges_.clear();
PrewalkResult prewalk_result;
root_damage_rect_ =
PrewalkTree(surface, false, 0, true /* will_draw */, &prewalk_result);
Expand Down Expand Up @@ -1270,4 +1284,26 @@ void SurfaceAggregator::SetOutputColorSpace(
: gfx::ColorSpace::CreateSRGB();
}

void SurfaceAggregator::SurfaceDamaged(const SurfaceId& surface_id,
bool* is_display_damaged) {
if (previous_contained_surfaces_.count(surface_id)) {
Surface* surface = manager_->GetSurfaceForId(surface_id);
if (surface) {
DCHECK(surface->HasActiveFrame());
if (surface->GetActiveFrame().resource_list.empty())
ReleaseResources(surface_id);
}
*is_display_damaged = true;
return;
}
auto it = damage_ranges_.find(surface_id.frame_sink_id());
if (it == damage_ranges_.end()) {
*is_display_damaged = false;
return;
}
*is_display_damaged = (it->second.second == surface_id.local_surface_id()) ||
(it->second.second > surface_id.local_surface_id() &&
surface_id.local_surface_id() > it->second.first);
}

} // namespace viz
7 changes: 7 additions & 0 deletions components/viz/service/display/surface_aggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator {
void SetOutputColorSpace(const gfx::ColorSpace& blending_color_space,
const gfx::ColorSpace& output_color_space);

void SurfaceDamaged(const SurfaceId& surface_id, bool* is_display_damaged);

private:
struct ClipData {
ClipData() : is_clipped(false) {}
Expand Down Expand Up @@ -281,6 +283,11 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator {
// Tracks UMA stats for SurfaceDrawQuads during a call to Aggregate().
SurfaceDrawQuadUmaStats uma_stats_;

// For each FrameSinkId, contains a range of LocalSurfaceIds that will damage
// the display if they're damaged.
base::flat_map<FrameSinkId, std::pair<LocalSurfaceId, LocalSurfaceId>>
damage_ranges_;

base::WeakPtrFactory<SurfaceAggregator> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(SurfaceAggregator);
Expand Down
Loading

0 comments on commit bdc9b10

Please sign in to comment.