Commit f0b48e83 authored by Alexander Alekseev's avatar Alexander Alekseev Committed by Commit Bot

Chrome OS: Add viz debug options to Ash HUD overlay.

This Cl exposes viz::DebugRendererSettings members as checkboxes in
ash HUD overlay.

Bug: 1085288,1085287,1085279
Change-Id: Id6ad4aa632cb552277ba47d076056b5ca0cc51f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303468Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789701}
parent 05f99980
...@@ -5,8 +5,12 @@ ...@@ -5,8 +5,12 @@
#include "ash/hud_display/hud_settings_view.h" #include "ash/hud_display/hud_settings_view.h"
#include "ash/hud_display/hud_properties.h" #include "ash/hud_display/hud_properties.h"
#include "base/bind.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "components/viz/common/display/renderer_settings.h"
#include "components/viz/host/host_frame_sink_manager.h"
#include "ui/aura/env.h"
#include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
...@@ -14,6 +18,63 @@ ...@@ -14,6 +18,63 @@
namespace ash { namespace ash {
namespace hud_display { namespace hud_display {
class HUDCheckboxHandler {
public:
HUDCheckboxHandler(
views::Checkbox* checkbox,
base::RepeatingCallback<void(views::Checkbox*)> update_state,
base::RepeatingCallback<void(views::Checkbox*)> handle_click)
: checkbox_(checkbox),
update_state_(update_state),
handle_click_(handle_click) {}
HUDCheckboxHandler(const HUDCheckboxHandler&) = delete;
HUDCheckboxHandler& operator=(const HUDCheckboxHandler&) = delete;
void UpdateState() const { update_state_.Run(checkbox_); }
void HandleClick() const { handle_click_.Run(checkbox_); }
const views::Checkbox* checkbox() const { return checkbox_; }
private:
views::Checkbox* const checkbox_; // not owned.
base::RepeatingCallback<void(views::Checkbox*)> update_state_;
base::RepeatingCallback<void(views::Checkbox*)> handle_click_;
};
namespace {
base::RepeatingCallback<void(views::Checkbox*)> GetUpdateStateCallback(
const bool viz::DebugRendererSettings::*field) {
return base::BindRepeating(
[](const bool viz::DebugRendererSettings::*field,
views::Checkbox* checkbox) {
checkbox->SetChecked(aura::Env::GetInstance()
->context_factory()
->GetHostFrameSinkManager()
->debug_renderer_settings().*
field);
},
field);
}
base::RepeatingCallback<void(views::Checkbox*)> GetHandleClickCallback(
bool viz::DebugRendererSettings::*field) {
return base::BindRepeating(
[](bool viz::DebugRendererSettings::*field, views::Checkbox* checkbox) {
viz::HostFrameSinkManager* manager = aura::Env::GetInstance()
->context_factory()
->GetHostFrameSinkManager();
viz::DebugRendererSettings debug_settings =
manager->debug_renderer_settings();
debug_settings.*field = checkbox->GetChecked();
manager->UpdateDebugRendererSettings(debug_settings);
},
field);
}
} // anonymous namespace
BEGIN_METADATA(HUDSettingsView) BEGIN_METADATA(HUDSettingsView)
METADATA_PARENT_CLASS(View) METADATA_PARENT_CLASS(View)
END_METADATA() END_METADATA()
...@@ -30,33 +91,57 @@ HUDSettingsView::HUDSettingsView() { ...@@ -30,33 +91,57 @@ HUDSettingsView::HUDSettingsView() {
SetLayoutManager(std::move(layout_manager)); SetLayoutManager(std::move(layout_manager));
SetBorder(views::CreateSolidBorder(1, kDefaultColor)); SetBorder(views::CreateSolidBorder(1, kDefaultColor));
// Use this to add checkboxes like:
// add_checkbox(this, base::ASCIIToUTF16("test1"));
auto add_checkbox = [](HUDSettingsView* self, auto add_checkbox = [](HUDSettingsView* self,
const base::string16& text) -> const views::Checkbox* { const base::string16& text) -> views::Checkbox* {
auto checkbox = std::make_unique<views::Checkbox>(text, self); auto checkbox = std::make_unique<views::Checkbox>(text, self);
const views::Checkbox* result = checkbox.get(); views::Checkbox* result = checkbox.get();
checkbox->SetEnabledTextColors(kDefaultColor); checkbox->SetEnabledTextColors(kDefaultColor);
checkbox->SetProperty(kHUDClickHandler, HTCLIENT); checkbox->SetProperty(kHUDClickHandler, HTCLIENT);
self->AddChildView(std::move(checkbox)); self->AddChildView(std::move(checkbox));
return result; return result;
}; };
// No checkboxes for now. checkbox_handlers_.push_back(std::make_unique<HUDCheckboxHandler>(
ALLOW_UNUSED_LOCAL(add_checkbox); add_checkbox(this, base::ASCIIToUTF16("Tint composited content")),
GetUpdateStateCallback(
&viz::DebugRendererSettings::tint_composited_content),
GetHandleClickCallback(
&viz::DebugRendererSettings::tint_composited_content)));
checkbox_handlers_.push_back(std::make_unique<HUDCheckboxHandler>(
add_checkbox(this, base::ASCIIToUTF16("Show overdraw feedback")),
GetUpdateStateCallback(
&viz::DebugRendererSettings::show_overdraw_feedback),
GetHandleClickCallback(
&viz::DebugRendererSettings::show_overdraw_feedback)));
checkbox_handlers_.push_back(std::make_unique<HUDCheckboxHandler>(
add_checkbox(this, base::ASCIIToUTF16("Show DC layer debug borders")),
GetUpdateStateCallback(
&viz::DebugRendererSettings::show_dc_layer_debug_borders),
GetHandleClickCallback(
&viz::DebugRendererSettings::show_dc_layer_debug_borders)));
} }
HUDSettingsView::~HUDSettingsView() = default; HUDSettingsView::~HUDSettingsView() = default;
void HUDSettingsView::ButtonPressed(views::Button* sender, void HUDSettingsView::ButtonPressed(views::Button* sender,
const ui::Event& /*event*/) { const ui::Event& /*event*/) {
const views::Checkbox* checkbox = static_cast<views::Checkbox*>(sender); for (const auto& handler : checkbox_handlers_) {
DVLOG(1) << "HUDSettingsView::ButtonPressed(): " if (sender != handler->checkbox())
<< (checkbox->GetChecked() ? "Checked" : "Uncheked"); continue;
handler->HandleClick();
break;
}
} }
void HUDSettingsView::ToggleVisibility() { void HUDSettingsView::ToggleVisibility() {
SetVisible(!GetVisible()); const bool is_shown = !GetVisible();
if (is_shown) {
for (const auto& handler : checkbox_handlers_) {
handler->UpdateState();
}
}
SetVisible(is_shown);
} }
} // namespace hud_display } // namespace hud_display
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#ifndef ASH_HUD_DISPLAY_HUD_SETTINGS_VIEW_H_ #ifndef ASH_HUD_DISPLAY_HUD_SETTINGS_VIEW_H_
#define ASH_HUD_DISPLAY_HUD_SETTINGS_VIEW_H_ #define ASH_HUD_DISPLAY_HUD_SETTINGS_VIEW_H_
#include <memory>
#include <vector>
#include "ash/hud_display/hud_constants.h" #include "ash/hud_display/hud_constants.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
...@@ -13,6 +16,8 @@ ...@@ -13,6 +16,8 @@
namespace ash { namespace ash {
namespace hud_display { namespace hud_display {
class HUDCheckboxHandler;
class HUDSettingsView : public views::ButtonListener, public views::View { class HUDSettingsView : public views::ButtonListener, public views::View {
public: public:
METADATA_HEADER(HUDSettingsView); METADATA_HEADER(HUDSettingsView);
...@@ -32,6 +37,9 @@ class HUDSettingsView : public views::ButtonListener, public views::View { ...@@ -32,6 +37,9 @@ class HUDSettingsView : public views::ButtonListener, public views::View {
// Shows/hides the view. // Shows/hides the view.
void ToggleVisibility(); void ToggleVisibility();
private:
std::vector<std::unique_ptr<HUDCheckboxHandler>> checkbox_handlers_;
}; };
} // namespace hud_display } // namespace hud_display
......
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