Skip to content

Commit

Permalink
ui: Add debug flag to show composited layer borders in ChromeOS UI.
Browse files Browse the repository at this point in the history
This adds an entry to chrome://flags that allows layer borders to be
enabled for Chrome OS UI.

It also makes the debug border setting a bitset so borders for individual
layer types can be enabled. This makes the debug flag more useful when
debugging a specific layer type (e.g. render surface layers).

BUG=678236
TEST=chrome --ui-show-composited-layer-borders=renderpass
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2795703002
Cr-Commit-Position: refs/heads/master@{#464640}
  • Loading branch information
reveman-chromium authored and Commit bot committed Apr 14, 2017
1 parent fcfe426 commit 5be07ac
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ash/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace debug {

void ToggleShowDebugBorders() {
aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
std::unique_ptr<bool> value;
std::unique_ptr<cc::DebugBorderTypes> value;
for (aura::Window::Windows::iterator it = root_windows.begin();
it != root_windows.end(); ++it) {
ui::Compositor* compositor = (*it)->GetHost()->compositor();
cc::LayerTreeDebugState state = compositor->GetLayerTreeDebugState();
if (!value.get())
value.reset(new bool(!state.show_debug_borders));
value.reset(new cc::DebugBorderTypes(state.show_debug_borders.flip()));
state.show_debug_borders = *value.get();
compositor->SetLayerTreeDebugState(state);
}
Expand Down
3 changes: 3 additions & 0 deletions cc/base/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const char kEnableSurfaceSynchronization[] = "enable-surface-synchronization";
// layer compositing.
const char kShowCompositedLayerBorders[] = "show-composited-layer-borders";
const char kUIShowCompositedLayerBorders[] = "ui-show-layer-borders";
const char kCompositedRenderPassBorders[] = "renderpass";
const char kCompositedSurfaceBorders[] = "surface";
const char kCompositedLayerBorders[] = "layer";

// Renders a green border around GL composited texture quads to help
// debug and study overlay support.
Expand Down
3 changes: 3 additions & 0 deletions cc/base/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ CC_BASE_EXPORT extern const char kUIShowScreenSpaceRects[];
CC_BASE_EXPORT extern const char kEnableLayerLists[];
CC_BASE_EXPORT extern const char kUIEnableLayerLists[];
CC_BASE_EXPORT extern const char kShowOverdrawFeedback[];
CC_BASE_EXPORT extern const char kCompositedRenderPassBorders[];
CC_BASE_EXPORT extern const char kCompositedSurfaceBorders[];
CC_BASE_EXPORT extern const char kCompositedLayerBorders[];

// Unit test related.
CC_BASE_EXPORT extern const char kCCLayerTreeTestNoTimeout[];
Expand Down
12 changes: 11 additions & 1 deletion cc/debug/layer_tree_debug_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef CC_DEBUG_LAYER_TREE_DEBUG_STATE_H_
#define CC_DEBUG_LAYER_TREE_DEBUG_STATE_H_

#include <bitset>

#include "cc/debug/debug_export.h"

namespace cc {
Expand All @@ -13,14 +15,22 @@ namespace proto {
class LayerTreeDebugState;
} // namespace proto

enum DebugBorderType {
RENDERPASS = 0,
SURFACE,
LAYER,
LAST_DEBUG_BORDER_TYPE = LAYER
};
using DebugBorderTypes = std::bitset<LAST_DEBUG_BORDER_TYPE + 1>;

class CC_DEBUG_EXPORT LayerTreeDebugState {
public:
LayerTreeDebugState();
LayerTreeDebugState(const LayerTreeDebugState& other);
~LayerTreeDebugState();

bool show_fps_counter;
bool show_debug_borders;
DebugBorderTypes show_debug_borders;

bool show_paint_rects;
bool show_property_changed_rects;
Expand Down
6 changes: 3 additions & 3 deletions cc/layers/layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ void LayerImpl::DidDraw(ResourceProvider* resource_provider) {
current_draw_mode_ = DRAW_MODE_NONE;
}

bool LayerImpl::ShowDebugBorders() const {
return layer_tree_impl()->debug_state().show_debug_borders;
bool LayerImpl::ShowDebugBorders(DebugBorderType type) const {
return layer_tree_impl()->debug_state().show_debug_borders.test(type);
}

void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const {
Expand Down Expand Up @@ -229,7 +229,7 @@ void LayerImpl::AppendDebugBorderQuad(RenderPass* render_pass,
AppendQuadsData* append_quads_data,
SkColor color,
float width) const {
if (!ShowDebugBorders())
if (!ShowDebugBorders(DebugBorderType::LAYER))
return;

gfx::Rect quad_rect(bounds);
Expand Down
3 changes: 2 additions & 1 deletion cc/layers/layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "cc/base/region.h"
#include "cc/base/synced_property.h"
#include "cc/cc_export.h"
#include "cc/debug/layer_tree_debug_state.h"
#include "cc/input/input_handler.h"
#include "cc/layers/draw_properties.h"
#include "cc/layers/layer_collections.h"
Expand Down Expand Up @@ -217,7 +218,7 @@ class CC_EXPORT LayerImpl {
return should_check_backface_visibility_;
}

bool ShowDebugBorders() const;
bool ShowDebugBorders(DebugBorderType type) const;

// TODO(http://crbug.com/557160): Currently SPv2 creates dummy layers for the
// sole purpose of representing a render surface. Once that dependency is
Expand Down
4 changes: 2 additions & 2 deletions cc/layers/picture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
AppendDebugBorderQuad(render_pass, shared_quad_state->quad_layer_bounds,
shared_quad_state, append_quads_data);

if (ShowDebugBorders()) {
if (ShowDebugBorders(DebugBorderType::LAYER)) {
for (PictureLayerTilingSet::CoverageIterator iter(
tilings_.get(), max_contents_scale,
shared_quad_state->visible_quad_layer_rect, ideal_contents_scale_);
Expand Down Expand Up @@ -383,7 +383,7 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
if (!has_draw_quad) {
// Checkerboard.
SkColor color = SafeOpaqueBackgroundColor();
if (ShowDebugBorders()) {
if (ShowDebugBorders(DebugBorderType::LAYER)) {
// Fill the whole tile with the missing tile color.
color = DebugColors::OOMTileBorderColor();
}
Expand Down
3 changes: 2 additions & 1 deletion cc/layers/render_surface_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ void RenderSurfaceImpl::AppendQuads(RenderPass* render_pass,
draw_properties_.clip_rect, draw_properties_.is_clipped,
draw_properties_.draw_opacity, BlendMode(), sorting_context_id);

if (layer_tree_impl_->debug_state().show_debug_borders) {
if (layer_tree_impl_->debug_state().show_debug_borders.test(
DebugBorderType::RENDERPASS)) {
DebugBorderDrawQuad* debug_border_quad =
render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
debug_border_quad->SetNew(shared_quad_state, content_rect(),
Expand Down
2 changes: 1 addition & 1 deletion cc/layers/surface_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color,
}

void SurfaceLayerImpl::AppendRainbowDebugBorder(RenderPass* render_pass) {
if (!ShowDebugBorders())
if (!ShowDebugBorders(DebugBorderType::SURFACE))
return;

SharedQuadState* shared_quad_state =
Expand Down
18 changes: 18 additions & 0 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,20 @@ const FeatureEntry::Choice kDataSaverPromptChoices[] = {
chromeos::switches::kEnableDataSaverPrompt,
chromeos::switches::kDataSaverPromptDemoMode},
};

const FeatureEntry::Choice kUiShowCompositedLayerBordersChoices[] = {
{flags_ui::kGenericExperimentChoiceDefault, "", ""},
{flag_descriptions::kUiShowCompositedLayerBordersRenderPass,
cc::switches::kUIShowCompositedLayerBorders,
cc::switches::kCompositedRenderPassBorders},
{flag_descriptions::kUiShowCompositedLayerBordersSurface,
cc::switches::kUIShowCompositedLayerBorders,
cc::switches::kCompositedSurfaceBorders},
{flag_descriptions::kUiShowCompositedLayerBordersLayer,
cc::switches::kUIShowCompositedLayerBorders,
cc::switches::kCompositedLayerBorders},
{flag_descriptions::kUiShowCompositedLayerBordersAll,
cc::switches::kUIShowCompositedLayerBorders, ""}};
#endif // OS_CHROMEOS

const FeatureEntry::Choice kV8CacheOptionsChoices[] = {
Expand Down Expand Up @@ -1255,6 +1269,10 @@ const FeatureEntry kFeatureEntries[] = {
{"ui-slow-animations", flag_descriptions::kUiSlowAnimationsName,
flag_descriptions::kUiSlowAnimationsDescription, kOsCrOS,
SINGLE_VALUE_TYPE(switches::kUISlowAnimations)},
{"ui-show-composited-layer-borders",
flag_descriptions::kUiShowCompositedLayerBordersName,
flag_descriptions::kUiShowCompositedLayerBordersDescription, kOsCrOS,
MULTI_VALUE_TYPE(kUiShowCompositedLayerBordersChoices)},
{"disable-cloud-import", flag_descriptions::kCloudImport,
flag_descriptions::kCloudImportDescription, kOsCrOS,
SINGLE_DISABLE_VALUE_TYPE(chromeos::switches::kDisableCloudImport)},
Expand Down
14 changes: 14 additions & 0 deletions chrome/browser/flag_descriptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,20 @@ const char kUiSlowAnimationsName[] = "Slow UI animations";

const char kUiSlowAnimationsDescription[] = "Makes all UI animations slow.";

const char kUiShowCompositedLayerBordersName[] =
"Show UI composited layer borders";

const char kUiShowCompositedLayerBordersDescription[] =
"Show border around composited layers created by UI.";

const char kUiShowCompositedLayerBordersRenderPass[] = "RenderPass";

const char kUiShowCompositedLayerBordersSurface[] = "Surface";

const char kUiShowCompositedLayerBordersLayer[] = "Layer";

const char kUiShowCompositedLayerBordersAll[] = "All";

#endif // defined(USE_ASH)

const char kJavascriptHarmonyShippingName[] =
Expand Down
18 changes: 18 additions & 0 deletions chrome/browser/flag_descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,24 @@ extern const char kUiSlowAnimationsName[];
// Description for the flag that enables slow UI animations.
extern const char kUiSlowAnimationsDescription[];

// Name for the flag to show UI composited layer borders.
extern const char kUiShowCompositedLayerBordersName[];

// Description for the flag to show UI composited layer borders.
extern const char kUiShowCompositedLayerBordersDescription[];

// Description of the flag option to show renderpass borders.
extern const char kUiShowCompositedLayerBordersRenderPass[];

// Description of the flag option to show surface borders.
extern const char kUiShowCompositedLayerBordersSurface[];

// Description of the flag option to show layer borders.
extern const char kUiShowCompositedLayerBordersLayer[];

// Description of the flag option to show all borders.
extern const char kUiShowCompositedLayerBordersAll[];

#endif // defined(USE_ASH)

// Title for the flag for latest (non-experimental) JavaScript fatures
Expand Down
4 changes: 2 additions & 2 deletions content/renderer/gpu/render_widget_compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ cc::LayerTreeSettings RenderWidgetCompositor::GenerateLayerTreeSettings(
settings.single_thread_proxy_scheduler = false;

// These flags should be mirrored by UI versions in ui/compositor/.
settings.initial_debug_state.show_debug_borders =
cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders);
if (cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders))
settings.initial_debug_state.show_debug_borders.set();
settings.initial_debug_state.show_layer_animation_bounds_rects =
cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds);
settings.initial_debug_state.show_paint_rects =
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101520,6 +101520,7 @@ from previous Chrome versions.
<int value="-1310737697" label="MaterialDesignSettings:enabled"/>
<int value="-1302904242" label="enable-navigation-tracing"/>
<int value="-1289678848" label="SystemDownloadManager:enabled"/>
<int value="-1289373013" label="ui-show-layer-borders"/>
<int value="-1285021473" label="save-page-as-mhtml"/>
<int value="-1276912933" label="enable-quick-unlock-pin"/>
<int value="-1271563519" label="enable-appcontainer"/>
Expand Down
31 changes: 28 additions & 3 deletions ui/compositor/compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/sys_info.h"
#include "base/trace_event/trace_event.h"
Expand Down Expand Up @@ -108,9 +109,33 @@ Compositor::Compositor(const cc::FrameSinkId& frame_sink_id,
settings.renderer_settings.show_overdraw_feedback =
command_line->HasSwitch(cc::switches::kShowOverdrawFeedback);

// These flags should be mirrored by renderer versions in content/renderer/.
settings.initial_debug_state.show_debug_borders =
command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders);
if (command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders)) {
std::string layer_borders_string = command_line->GetSwitchValueASCII(
cc::switches::kUIShowCompositedLayerBorders);
std::vector<base::StringPiece> entries = base::SplitStringPiece(
layer_borders_string, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
if (entries.empty()) {
settings.initial_debug_state.show_debug_borders.set();
} else {
for (const auto& entry : entries) {
const struct {
const char* name;
cc::DebugBorderType type;
} kBorders[] = {{cc::switches::kCompositedRenderPassBorders,
cc::DebugBorderType::RENDERPASS},
{cc::switches::kCompositedSurfaceBorders,
cc::DebugBorderType::SURFACE},
{cc::switches::kCompositedLayerBorders,
cc::DebugBorderType::LAYER}};
for (const auto& border : kBorders) {
if (border.name == entry) {
settings.initial_debug_state.show_debug_borders.set(border.type);
break;
}
}
}
}
}
settings.initial_debug_state.show_fps_counter =
command_line->HasSwitch(cc::switches::kUIShowFPSCounter);
settings.initial_debug_state.show_layer_animation_bounds_rects =
Expand Down

0 comments on commit 5be07ac

Please sign in to comment.