Commit c3e9dc09 authored by Biao She's avatar Biao She Committed by Commit Bot

Hide printing code for binding behind DEBUG flag in template (reduced 20k binary size)

We only print bindings in DEBUG build. However, we generate code for
printing bindings in release build for each new binding we create.
This CL simply hides all printing related code behind DEBUG build. It
reduces the native binary size about 20k.

Bug: NONE
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr
Change-Id: Ie6b6c6148369717b89c1e4f68336c0950954cc06
Reviewed-on: https://chromium-review.googlesource.com/1076308
Commit-Queue: Biao She <bshe@chromium.org>
Commit-Queue: Christopher Grant <cjgrant@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562556}
parent 5730340b
......@@ -27,15 +27,7 @@ namespace vr {
template <typename T>
class Binding : public BindingBase {
public:
Binding(const base::RepeatingCallback<T()>& getter,
const base::RepeatingCallback<void(const T&)>& setter)
: getter_(getter), setter_(setter) {}
Binding(const base::RepeatingCallback<T()>& getter,
const base::RepeatingCallback<void(const base::Optional<T>&,
const T&)>& setter)
: getter_(getter), historic_setter_(setter) {}
#ifndef NDEBUG
Binding(const base::RepeatingCallback<T()>& getter,
const std::string& getter_text,
const base::RepeatingCallback<void(const T&)>& setter,
......@@ -54,6 +46,17 @@ class Binding : public BindingBase {
historic_setter_(setter),
getter_text_(getter_text),
setter_text_(setter_text) {}
#else
Binding(const base::RepeatingCallback<T()>& getter,
const base::RepeatingCallback<void(const T&)>& setter)
: getter_(getter), setter_(setter) {}
Binding(const base::RepeatingCallback<T()>& getter,
const base::RepeatingCallback<void(const base::Optional<T>&,
const T&)>& setter)
: getter_(getter), historic_setter_(setter) {}
#endif
~Binding() override = default;
// This function will check if the getter is producing a different value than
......@@ -72,11 +75,15 @@ class Binding : public BindingBase {
}
std::string ToString() override {
#ifndef NDEBUG
if (getter_text_.empty() && setter_text_.empty())
return "";
return base::StringPrintf("%s => %s", getter_text_.c_str(),
setter_text_.c_str());
#else
return "";
#endif
}
private:
......@@ -86,8 +93,10 @@ class Binding : public BindingBase {
historic_setter_;
base::Optional<T> last_value_;
#ifndef NDEBUG
std::string getter_text_;
std::string setter_text_;
#endif
DISALLOW_COPY_AND_ASSIGN(Binding);
};
......@@ -148,7 +157,11 @@ class Binding : public BindingBase {
#define VR_BIND_FIELD(T, M, m, Get, V, v, f) \
VR_BIND(T, M, m, Get, V, v, view->f = value)
#ifndef NDEBUG
#define VR_BIND_LAMBDA(...) base::BindRepeating(__VA_ARGS__), #__VA_ARGS__
#else
#define VR_BIND_LAMBDA(...) base::BindRepeating(__VA_ARGS__)
#endif
} // namespace vr
......
......@@ -56,8 +56,11 @@ void OnModelAdded(ViewRegistry* registry, ElemBinding* element) {
std::unique_ptr<View> view = std::make_unique<View>();
element->set_view(view.get());
element->bindings().push_back(std::make_unique<Binding<int>>(
base::BindRepeating(&GetValue, base::Unretained(element)),
base::BindRepeating(&SetValue, base::Unretained(element))));
VR_BIND_LAMBDA([](ElemBinding* e) { return GetValue(e); },
base::Unretained(element)),
VR_BIND_LAMBDA(
[](ElemBinding* e, const int& value) { SetValue(e, value); },
base::Unretained(element))));
registry->AddView(std::move(view));
}
......
......@@ -444,9 +444,9 @@ TEST(UiElement, CoordinatedVisibilityTransitions) {
parent->SetVisible(false);
parent->SetTransitionedProperties({OPACITY});
parent->AddBinding(std::make_unique<Binding<bool>>(
base::BindRepeating([](bool* value) { return *value; },
base::Unretained(&value)),
base::BindRepeating(
VR_BIND_LAMBDA([](bool* value) { return *value; },
base::Unretained(&value)),
VR_BIND_LAMBDA(
[](UiElement* e, const bool& value) { e->SetVisible(value); },
parent_ptr)));
......@@ -455,9 +455,9 @@ TEST(UiElement, CoordinatedVisibilityTransitions) {
child->SetVisible(false);
child->SetTransitionedProperties({OPACITY});
child->AddBinding(std::make_unique<Binding<bool>>(
base::BindRepeating([](bool* value) { return *value; },
base::Unretained(&value)),
base::BindRepeating(
VR_BIND_LAMBDA([](bool* value) { return *value; },
base::Unretained(&value)),
VR_BIND_LAMBDA(
[](UiElement* e, const bool& value) { e->SetVisible(value); },
child_ptr)));
......
......@@ -92,18 +92,20 @@ void BindColor(Model* model,
view->AddBinding(std::make_unique<Binding<SkColor>>(
base::BindRepeating([](Model* m, C c) { return (m->color_scheme()).*c; },
base::Unretained(model), color),
#ifndef NDEBUG
color_string,
#endif
base::BindRepeating(
[](V* v, S s, const SkColor& value) { (v->*s)(value); },
base::Unretained(view), setter),
setter_string));
base::Unretained(view), setter)
#ifndef NDEBUG
,
setter_string
#endif
));
}
#ifndef NDEBUG
#define VR_BIND_COLOR(m, v, c, s) BindColor(m, v, c, #c, s, #s)
#else
#define VR_BIND_COLOR(m, v, c, s) BindColor(m, v, c, "", s, "")
#endif
template <typename V, typename C, typename S>
void BindButtonColors(Model* model,
......@@ -115,18 +117,20 @@ void BindButtonColors(Model* model,
view->AddBinding(std::make_unique<Binding<ButtonColors>>(
base::BindRepeating([](Model* m, C c) { return (m->color_scheme()).*c; },
base::Unretained(model), colors),
#ifndef NDEBUG
colors_string,
#endif
base::BindRepeating(
[](V* v, S s, const ButtonColors& value) { (v->*s)(value); },
base::Unretained(view), setter),
setter_string));
base::Unretained(view), setter)
#ifndef NDEBUG
,
setter_string
#endif
));
}
#ifndef NDEBUG
#define VR_BIND_BUTTON_COLORS(m, v, c, s) BindButtonColors(m, v, c, #c, s, #s)
#else
#define VR_BIND_BUTTON_COLORS(m, v, c, s) BindButtonColors(m, v, c, "", s, "")
#endif
#define VR_BIND_VISIBILITY(v, c) \
v->AddBinding( \
......@@ -808,7 +812,7 @@ std::unique_ptr<UiElement> CreateHostedUi(
hosted_ui.get(),
view->SetTranslate(0, 0, value ? 0 : kHostedUiShadowOffset)));
hosted_ui->AddBinding(std::make_unique<Binding<std::pair<bool, gfx::SizeF>>>(
base::BindRepeating(
VR_BIND_LAMBDA(
[](Model* m) {
return std::pair<bool, gfx::SizeF>(
m->hosted_platform_ui.floating,
......@@ -816,7 +820,7 @@ std::unique_ptr<UiElement> CreateHostedUi(
m->hosted_platform_ui.rect.height()));
},
base::Unretained(model)),
base::BindRepeating(
VR_BIND_LAMBDA(
[](PlatformUiElement* dialog,
const std::pair<bool, gfx::SizeF>& value) {
if (!value.first && value.second.width() > 0) {
......@@ -840,7 +844,7 @@ std::unique_ptr<UiElement> CreateHostedUi(
shadow->SetTransitionedProperties({OPACITY});
shadow->AddChild(std::move(hosted_ui));
shadow->AddBinding(std::make_unique<Binding<std::pair<bool, gfx::PointF>>>(
base::BindRepeating(
VR_BIND_LAMBDA(
[](Model* m) {
return std::pair<bool, gfx::PointF>(
m->hosted_platform_ui.floating,
......@@ -848,7 +852,7 @@ std::unique_ptr<UiElement> CreateHostedUi(
m->hosted_platform_ui.rect.y()));
},
base::Unretained(model)),
base::BindRepeating(
VR_BIND_LAMBDA(
[](Shadow* shadow, const std::pair<bool, gfx::PointF>& value) {
if (value.first /* floating */) {
shadow->set_x_centering(LEFT);
......
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