Commit 73314490 authored by kylechar's avatar kylechar Committed by Commit Bot

Add flag to visualize aggregated damage

Add --show-aggregated-damage command line flag which activates a red
highlight around the damage rect for the final aggregated
CompositorFrame.  It can be difficult to diagnose damage rect related
problems so this may prove useful for debugging.

DamageFrameAnnotator has the ability to draw an arbitrary number of
DebugBorderDrawQuads even though it only produces one. This is
intentional so it can easily be extended for other debugging tasks.

Bug: none
Change-Id: I4f97009b139978b228eaf58d70ebdc5c88f88f6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1717230Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarJonathan Ross <jonross@chromium.org>
Commit-Queue: kylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682281}
parent 7d71ee6c
...@@ -31,6 +31,7 @@ class VIZ_COMMON_EXPORT RendererSettings { ...@@ -31,6 +31,7 @@ class VIZ_COMMON_EXPORT RendererSettings {
bool release_overlay_resources_after_gpu_query = false; bool release_overlay_resources_after_gpu_query = false;
bool tint_gl_composited_content = false; bool tint_gl_composited_content = false;
bool show_overdraw_feedback = false; bool show_overdraw_feedback = false;
bool show_aggregated_damage = false;
bool use_skia_renderer = false; bool use_skia_renderer = false;
bool allow_overlays = true; bool allow_overlays = true;
bool dont_round_texture_sizes_for_pixel_tests = false; bool dont_round_texture_sizes_for_pixel_tests = false;
......
...@@ -37,6 +37,12 @@ const char kEnableVizHitTestDebug[] = "enable-viz-hit-test-debug"; ...@@ -37,6 +37,12 @@ const char kEnableVizHitTestDebug[] = "enable-viz-hit-test-debug";
const char kRunAllCompositorStagesBeforeDraw[] = const char kRunAllCompositorStagesBeforeDraw[] =
"run-all-compositor-stages-before-draw"; "run-all-compositor-stages-before-draw";
// Adds a DebugBorderDrawQuad to the top of the root RenderPass showing the
// damage rect after surface aggregation. Note that when enabled this feature
// sets the entire output rect as damaged after adding the quad to highlight the
// real damage rect, which could hide damage rect problems.
const char kShowAggregatedDamage[] = "show-aggregated-damage";
// Enables the viz hit-test logic (HitTestAggregator and HitTestQuery), with // Enables the viz hit-test logic (HitTestAggregator and HitTestQuery), with
// hit-test data coming from surface layer. // hit-test data coming from surface layer.
const char kUseVizHitTestSurfaceLayer[] = "use-viz-hit-test-surface-layer"; const char kUseVizHitTestSurfaceLayer[] = "use-viz-hit-test-surface-layer";
......
...@@ -20,6 +20,7 @@ VIZ_COMMON_EXPORT extern const char kEnableHardwareOverlays[]; ...@@ -20,6 +20,7 @@ VIZ_COMMON_EXPORT extern const char kEnableHardwareOverlays[];
VIZ_COMMON_EXPORT extern const char kEnableVizDevTools[]; VIZ_COMMON_EXPORT extern const char kEnableVizDevTools[];
VIZ_COMMON_EXPORT extern const char kEnableVizHitTestDebug[]; VIZ_COMMON_EXPORT extern const char kEnableVizHitTestDebug[];
VIZ_COMMON_EXPORT extern const char kRunAllCompositorStagesBeforeDraw[]; VIZ_COMMON_EXPORT extern const char kRunAllCompositorStagesBeforeDraw[];
VIZ_COMMON_EXPORT extern const char kShowAggregatedDamage[];
VIZ_COMMON_EXPORT extern const char kUseVizHitTestSurfaceLayer[]; VIZ_COMMON_EXPORT extern const char kUseVizHitTestSurfaceLayer[];
VIZ_COMMON_EXPORT base::Optional<uint32_t> GetDeadlineToSynchronizeSurfaces(); VIZ_COMMON_EXPORT base::Optional<uint32_t> GetDeadlineToSynchronizeSurfaces();
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/viz/common/display/overlay_strategy.h" #include "components/viz/common/display/overlay_strategy.h"
#include "components/viz/common/display/renderer_settings.h" #include "components/viz/common/display/renderer_settings.h"
#include "components/viz/common/features.h" #include "components/viz/common/features.h"
#include "components/viz/common/switches.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
...@@ -18,7 +19,6 @@ ...@@ -18,7 +19,6 @@
#endif #endif
#if defined(USE_OZONE) #if defined(USE_OZONE)
#include "components/viz/common/switches.h"
#include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/ozone_platform.h"
#endif #endif
...@@ -61,6 +61,8 @@ RendererSettings CreateRendererSettings() { ...@@ -61,6 +61,8 @@ RendererSettings CreateRendererSettings() {
command_line->HasSwitch(switches::kTintGlCompositedContent); command_line->HasSwitch(switches::kTintGlCompositedContent);
renderer_settings.show_overdraw_feedback = renderer_settings.show_overdraw_feedback =
command_line->HasSwitch(switches::kShowOverdrawFeedback); command_line->HasSwitch(switches::kShowOverdrawFeedback);
renderer_settings.show_aggregated_damage =
command_line->HasSwitch(switches::kShowAggregatedDamage);
renderer_settings.allow_antialiasing = renderer_settings.allow_antialiasing =
!command_line->HasSwitch(switches::kDisableCompositedAntialiasing); !command_line->HasSwitch(switches::kDisableCompositedAntialiasing);
renderer_settings.use_skia_renderer = features::IsUsingSkiaRenderer(); renderer_settings.use_skia_renderer = features::IsUsingSkiaRenderer();
......
...@@ -21,6 +21,8 @@ viz_component("service") { ...@@ -21,6 +21,8 @@ viz_component("service") {
"display/ca_layer_overlay.h", "display/ca_layer_overlay.h",
"display/color_lut_cache.cc", "display/color_lut_cache.cc",
"display/color_lut_cache.h", "display/color_lut_cache.h",
"display/damage_frame_annotator.cc",
"display/damage_frame_annotator.h",
"display/dc_layer_overlay.cc", "display/dc_layer_overlay.cc",
"display/dc_layer_overlay.h", "display/dc_layer_overlay.h",
"display/direct_renderer.cc", "display/direct_renderer.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/viz/service/display/damage_frame_annotator.h"
#include <algorithm>
#include <utility>
#include "cc/base/math_util.h"
#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/quads/debug_border_draw_quad.h"
#include "components/viz/common/quads/render_pass.h"
#include "components/viz/common/quads/shared_quad_state.h"
namespace viz {
DamageFrameAnnotator::DamageFrameAnnotator() = default;
DamageFrameAnnotator::~DamageFrameAnnotator() = default;
void DamageFrameAnnotator::AnnotateAggregatedFrame(CompositorFrame* frame) {
DCHECK(frame);
auto* root_render_pass = frame->render_pass_list.back().get();
const gfx::Rect& damage_rect = root_render_pass->damage_rect;
gfx::Transform transform;
transform.Translate(damage_rect.x(), damage_rect.y());
annotations_.push_back(
AnnotationData{gfx::Rect(damage_rect.size()), transform,
Highlight{SkColorSetARGB(128, 255, 0, 0), 4}});
AnnotateRootRenderPass(root_render_pass);
annotations_.clear();
}
void DamageFrameAnnotator::AnnotateRootRenderPass(RenderPass* render_pass) {
const size_t num_quads_to_add = annotations_.size();
// Insert |num_quads_to_add| new SharedQuadState at the start of the list.
// This will invalidate all the existing SharedQuadState* in DrawQuads.
auto sqs_iter =
render_pass->shared_quad_state_list
.InsertBeforeAndInvalidateAllPointers<SharedQuadState>(
render_pass->shared_quad_state_list.begin(), num_quads_to_add);
// Insert |num_quads_to_add| new DebugBorderDrawQuad at start of list. The
// quads will be drawn on top of the original quads.
auto quad_iter =
render_pass->quad_list
.InsertBeforeAndInvalidateAllPointers<DebugBorderDrawQuad>(
render_pass->quad_list.begin(), num_quads_to_add);
// Initialize the SharedQuadStates and DebugBorderDrawQuads.
for (auto& annotation : annotations_) {
gfx::Rect output_rect = cc::MathUtil::MapEnclosingClippedRect(
annotation.transform, annotation.rect);
SharedQuadState* new_sqs = *sqs_iter;
new_sqs->SetAll(annotation.transform, output_rect, output_rect,
gfx::RRectF(), output_rect, true, false, 1.f,
SkBlendMode::kSrcOver, 0);
DebugBorderDrawQuad* new_quad =
static_cast<DebugBorderDrawQuad*>(*quad_iter);
new_quad->SetNew(new_sqs, annotation.rect, annotation.rect,
annotation.highlight.color, annotation.highlight.width);
++sqs_iter;
++quad_iter;
}
// At this point |quad_iter| points to the first DrawQuad that needs
// |shared_quad_state| fixed. |sqs_iter| points to the new address for the
// first original SharedQuadState. Iterate through all DrawQuads updating
// |shared_quad_state|.
const SharedQuadState* last_quad_from_sqs = (*quad_iter)->shared_quad_state;
while (quad_iter != render_pass->quad_list.end()) {
DrawQuad* quad = *quad_iter;
const SharedQuadState* from_sqs = quad->shared_quad_state;
// If |shared_quad_state| of the current quad is different than the last
// quad we know to advance |sqs_iter| as well.
if (from_sqs != last_quad_from_sqs) {
DCHECK(sqs_iter != render_pass->shared_quad_state_list.end());
++sqs_iter;
last_quad_from_sqs = from_sqs;
}
quad->shared_quad_state = *sqs_iter;
++quad_iter;
}
DCHECK(++sqs_iter == render_pass->shared_quad_state_list.end());
// Set the entire frame as damaged.
render_pass->damage_rect = render_pass->output_rect;
}
} // namespace viz
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_DAMAGE_FRAME_ANNOTATOR_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_DAMAGE_FRAME_ANNOTATOR_H_
#include <vector>
#include "components/viz/service/display/surface_aggregator.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/transform.h"
namespace viz {
class CompositorFrame;
class RenderPass;
// Draws a red outline around the root RenderPasses damage rect.
class DamageFrameAnnotator : public SurfaceAggregator::FrameAnnotator {
public:
DamageFrameAnnotator();
~DamageFrameAnnotator() override;
// SurfaceAggregator::FrameAnnotator implementation.
void AnnotateAggregatedFrame(CompositorFrame* frame) override;
private:
struct Highlight {
SkColor color;
int width;
};
struct AnnotationData {
gfx::Rect rect;
gfx::Transform transform;
Highlight highlight;
};
void AnnotateRootRenderPass(RenderPass* render_pass);
std::vector<AnnotationData> annotations_;
DISALLOW_COPY_AND_ASSIGN(DamageFrameAnnotator);
};
} // namespace viz
#endif // COMPONENTS_VIZ_SERVICE_DISPLAY_DAMAGE_FRAME_ANNOTATOR_H_
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "components/viz/common/quads/compositor_frame.h" #include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/quads/draw_quad.h" #include "components/viz/common/quads/draw_quad.h"
#include "components/viz/common/quads/shared_quad_state.h" #include "components/viz/common/quads/shared_quad_state.h"
#include "components/viz/service/display/damage_frame_annotator.h"
#include "components/viz/service/display/direct_renderer.h" #include "components/viz/service/display/direct_renderer.h"
#include "components/viz/service/display/display_client.h" #include "components/viz/service/display/display_client.h"
#include "components/viz/service/display/display_scheduler.h" #include "components/viz/service/display/display_scheduler.h"
...@@ -378,9 +379,12 @@ void Display::InitializeRenderer(bool enable_shared_images) { ...@@ -378,9 +379,12 @@ void Display::InitializeRenderer(bool enable_shared_images) {
renderer_->use_partial_swap() && !renderer_->has_overlay_validator(); renderer_->use_partial_swap() && !renderer_->has_overlay_validator();
bool needs_surface_occluding_damage_rect = bool needs_surface_occluding_damage_rect =
renderer_->OverlayNeedsSurfaceOccludingDamageRect(); renderer_->OverlayNeedsSurfaceOccludingDamageRect();
aggregator_.reset(new SurfaceAggregator( aggregator_ = std::make_unique<SurfaceAggregator>(
surface_manager_, resource_provider_.get(), output_partial_list, surface_manager_, resource_provider_.get(), output_partial_list,
needs_surface_occluding_damage_rect)); needs_surface_occluding_damage_rect);
if (settings_.show_aggregated_damage)
aggregator_->SetFrameAnnotator(std::make_unique<DamageFrameAnnotator>());
aggregator_->set_output_is_secure(output_is_secure_); aggregator_->set_output_is_secure(output_is_secure_);
aggregator_->SetOutputColorSpace(device_color_space_); aggregator_->SetOutputColorSpace(device_color_space_);
// Consider adding a softare limit as well. // Consider adding a softare limit as well.
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "cc/base/math_util.h" #include "cc/base/math_util.h"
#include "components/viz/common/quads/compositor_frame.h" #include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/quads/debug_border_draw_quad.h"
#include "components/viz/common/quads/draw_quad.h" #include "components/viz/common/quads/draw_quad.h"
#include "components/viz/common/quads/render_pass_draw_quad.h" #include "components/viz/common/quads/render_pass_draw_quad.h"
#include "components/viz/common/quads/shared_quad_state.h" #include "components/viz/common/quads/shared_quad_state.h"
...@@ -1557,6 +1558,10 @@ CompositorFrame SurfaceAggregator::Aggregate( ...@@ -1557,6 +1558,10 @@ CompositorFrame SurfaceAggregator::Aggregate(
break; break;
} }
} }
if (frame_annotator_)
frame_annotator_->AnnotateAggregatedFrame(&frame);
return frame; return frame;
} }
...@@ -1612,6 +1617,12 @@ bool SurfaceAggregator::NotifySurfaceDamageAndCheckForDisplayDamage( ...@@ -1612,6 +1617,12 @@ bool SurfaceAggregator::NotifySurfaceDamageAndCheckForDisplayDamage(
return false; return false;
} }
void SurfaceAggregator::SetFrameAnnotator(
std::unique_ptr<FrameAnnotator> frame_annotator) {
DCHECK(!frame_annotator_);
frame_annotator_ = std::move(frame_annotator);
}
bool SurfaceAggregator::IsRootSurface(const Surface* surface) const { bool SurfaceAggregator::IsRootSurface(const Surface* surface) const {
return surface->surface_id() == root_surface_id_; return surface->surface_id() == root_surface_id_;
} }
......
...@@ -35,6 +35,15 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator { ...@@ -35,6 +35,15 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator {
using SurfaceIndexMap = base::flat_map<SurfaceId, uint64_t>; using SurfaceIndexMap = base::flat_map<SurfaceId, uint64_t>;
using FrameSinkIdMap = base::flat_map<FrameSinkId, LocalSurfaceId>; using FrameSinkIdMap = base::flat_map<FrameSinkId, LocalSurfaceId>;
// Interface that can modify the aggregated CompositorFrame to annotate it.
// For example it could add extra quads.
class FrameAnnotator {
public:
virtual ~FrameAnnotator() = default;
virtual void AnnotateAggregatedFrame(CompositorFrame* frame) = 0;
};
SurfaceAggregator(SurfaceManager* manager, SurfaceAggregator(SurfaceManager* manager,
DisplayResourceProvider* provider, DisplayResourceProvider* provider,
bool aggregate_only_damaged, bool aggregate_only_damaged,
...@@ -63,6 +72,8 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator { ...@@ -63,6 +72,8 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator {
bool NotifySurfaceDamageAndCheckForDisplayDamage(const SurfaceId& surface_id); bool NotifySurfaceDamageAndCheckForDisplayDamage(const SurfaceId& surface_id);
void SetFrameAnnotator(std::unique_ptr<FrameAnnotator> frame_annotator);
private: private:
struct ClipData { struct ClipData {
ClipData() : is_clipped(false) {} ClipData() : is_clipped(false) {}
...@@ -326,6 +337,9 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator { ...@@ -326,6 +337,9 @@ class VIZ_SERVICE_EXPORT SurfaceAggregator {
// the display if they're damaged. // the display if they're damaged.
base::flat_map<FrameSinkId, std::vector<SurfaceRange>> damage_ranges_; base::flat_map<FrameSinkId, std::vector<SurfaceRange>> damage_ranges_;
// Used to annotate the aggregated frame for debugging.
std::unique_ptr<FrameAnnotator> frame_annotator_;
int64_t display_trace_id_ = -1; int64_t display_trace_id_ = -1;
base::flat_set<SurfaceId> undrawn_surfaces_; base::flat_set<SurfaceId> undrawn_surfaces_;
......
...@@ -18,6 +18,7 @@ struct RendererSettings { ...@@ -18,6 +18,7 @@ struct RendererSettings {
bool release_overlay_resources_after_gpu_query; bool release_overlay_resources_after_gpu_query;
bool should_clear_root_render_pass; bool should_clear_root_render_pass;
bool show_overdraw_feedback; bool show_overdraw_feedback;
bool show_aggregated_damage;
int32 slow_down_compositing_scale_factor; int32 slow_down_compositing_scale_factor;
bool use_skia_renderer; bool use_skia_renderer;
bool record_sk_picture; bool record_sk_picture;
......
...@@ -25,6 +25,7 @@ bool StructTraits<viz::mojom::RendererSettingsDataView, viz::RendererSettings>:: ...@@ -25,6 +25,7 @@ bool StructTraits<viz::mojom::RendererSettingsDataView, viz::RendererSettings>::
data.release_overlay_resources_after_gpu_query(); data.release_overlay_resources_after_gpu_query();
out->tint_gl_composited_content = data.tint_gl_composited_content(); out->tint_gl_composited_content = data.tint_gl_composited_content();
out->show_overdraw_feedback = data.show_overdraw_feedback(); out->show_overdraw_feedback = data.show_overdraw_feedback();
out->show_aggregated_damage = data.show_aggregated_damage();
out->highp_threshold_min = data.highp_threshold_min(); out->highp_threshold_min = data.highp_threshold_min();
out->slow_down_compositing_scale_factor = out->slow_down_compositing_scale_factor =
data.slow_down_compositing_scale_factor(); data.slow_down_compositing_scale_factor();
......
...@@ -54,6 +54,10 @@ struct StructTraits<viz::mojom::RendererSettingsDataView, ...@@ -54,6 +54,10 @@ struct StructTraits<viz::mojom::RendererSettingsDataView,
return input.show_overdraw_feedback; return input.show_overdraw_feedback;
} }
static bool show_aggregated_damage(const viz::RendererSettings& input) {
return input.show_aggregated_damage;
}
static int highp_threshold_min(const viz::RendererSettings& input) { static int highp_threshold_min(const viz::RendererSettings& input) {
return input.highp_threshold_min; return input.highp_threshold_min;
} }
......
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