diff options
author | yurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-01 13:10:38 +0000 |
---|---|---|
committer | yurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-01 13:10:38 +0000 |
commit | d12aa932d3555eda2c011022e94df82023fa191d (patch) | |
tree | f1f9244b6beccfd2797d74fc1d1acea896d2a601 /cc/base | |
parent | 59d75c8166ae16a7879c11595fbde2ab1cffad3b (diff) | |
download | chromium_src-d12aa932d3555eda2c011022e94df82023fa191d.zip chromium_src-d12aa932d3555eda2c011022e94df82023fa191d.tar.gz chromium_src-d12aa932d3555eda2c011022e94df82023fa191d.tar.bz2 |
Add builders for tracing event's structural arguments
The new classes allow building JSON-like structural arguments. Current implementation uses base::Value as backing store but that can be replaced in the future with something more efficient without changing client code.
All clients of cc/debug/traced_value.h should eventually switch to use the new builders.
BUG=361045
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=286849
R=alph@chromium.org, dsinclair@chromium.org, nduca@chromium.org, willchan@chromium.org
Review URL: https://codereview.chromium.org/380763002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286984 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/base')
-rw-r--r-- | cc/base/math_util.cc | 74 | ||||
-rw-r--r-- | cc/base/math_util.h | 39 | ||||
-rw-r--r-- | cc/base/region.cc | 11 | ||||
-rw-r--r-- | cc/base/region.h | 4 |
4 files changed, 87 insertions, 41 deletions
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc index 07ad77b..fd8e796 100644 --- a/cc/base/math_util.cc +++ b/cc/base/math_util.cc @@ -8,6 +8,7 @@ #include <cmath> #include <limits> +#include "base/debug/trace_event_argument.h" #include "base/values.h" #include "ui/gfx/quad_f.h" #include "ui/gfx/rect.h" @@ -547,13 +548,6 @@ scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Size& s) { return res.PassAs<base::Value>(); } -scoped_ptr<base::Value> MathUtil::AsValue(const gfx::SizeF& s) { - scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); - res->SetDouble("width", s.width()); - res->SetDouble("height", s.height()); - return res.PassAs<base::Value>(); -} - scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Rect& r) { scoped_ptr<base::ListValue> res(new base::ListValue()); res->AppendInteger(r.x()); @@ -591,23 +585,47 @@ scoped_ptr<base::Value> MathUtil::AsValue(const gfx::PointF& pt) { return res.PassAs<base::Value>(); } -scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Point3F& pt) { - scoped_ptr<base::ListValue> res(new base::ListValue()); +void MathUtil::AddToTracedValue(const gfx::Size& s, + base::debug::TracedValue* res) { + res->SetDouble("width", s.width()); + res->SetDouble("height", s.height()); +} + +void MathUtil::AddToTracedValue(const gfx::SizeF& s, + base::debug::TracedValue* res) { + res->SetDouble("width", s.width()); + res->SetDouble("height", s.height()); +} + +void MathUtil::AddToTracedValue(const gfx::Rect& r, + base::debug::TracedValue* res) { + res->AppendInteger(r.x()); + res->AppendInteger(r.y()); + res->AppendInteger(r.width()); + res->AppendInteger(r.height()); +} + +void MathUtil::AddToTracedValue(const gfx::PointF& pt, + base::debug::TracedValue* res) { + res->AppendDouble(pt.x()); + res->AppendDouble(pt.y()); +} + +void MathUtil::AddToTracedValue(const gfx::Point3F& pt, + base::debug::TracedValue* res) { res->AppendDouble(pt.x()); res->AppendDouble(pt.y()); res->AppendDouble(pt.z()); - return res.PassAs<base::Value>(); } -scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Vector2d& v) { - scoped_ptr<base::ListValue> res(new base::ListValue()); +void MathUtil::AddToTracedValue(const gfx::Vector2d& v, + base::debug::TracedValue* res) { res->AppendInteger(v.x()); res->AppendInteger(v.y()); - return res.PassAs<base::Value>(); } -scoped_ptr<base::Value> MathUtil::AsValue(const gfx::QuadF& q) { - scoped_ptr<base::ListValue> res(new base::ListValue()); +void MathUtil::AddToTracedValue(const gfx::QuadF& q, + base::debug::TracedValue* res) { res->AppendDouble(q.p1().x()); res->AppendDouble(q.p1().y()); res->AppendDouble(q.p2().x()); @@ -616,47 +634,41 @@ scoped_ptr<base::Value> MathUtil::AsValue(const gfx::QuadF& q) { res->AppendDouble(q.p3().y()); res->AppendDouble(q.p4().x()); res->AppendDouble(q.p4().y()); - return res.PassAs<base::Value>(); } -scoped_ptr<base::Value> MathUtil::AsValue(const gfx::RectF& rect) { - scoped_ptr<base::ListValue> res(new base::ListValue()); +void MathUtil::AddToTracedValue(const gfx::RectF& rect, + base::debug::TracedValue* res) { res->AppendDouble(rect.x()); res->AppendDouble(rect.y()); res->AppendDouble(rect.width()); res->AppendDouble(rect.height()); - return res.PassAs<base::Value>(); } -scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Transform& transform) { - scoped_ptr<base::ListValue> res(new base::ListValue()); +void MathUtil::AddToTracedValue(const gfx::Transform& transform, + base::debug::TracedValue* res) { const SkMatrix44& m = transform.matrix(); for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) res->AppendDouble(m.getDouble(row, col)); } - return res.PassAs<base::Value>(); } -scoped_ptr<base::Value> MathUtil::AsValue(const gfx::BoxF& box) { - scoped_ptr<base::ListValue> res(new base::ListValue()); +void MathUtil::AddToTracedValue(const gfx::BoxF& box, + base::debug::TracedValue* res) { res->AppendInteger(box.x()); res->AppendInteger(box.y()); res->AppendInteger(box.z()); res->AppendInteger(box.width()); res->AppendInteger(box.height()); res->AppendInteger(box.depth()); - return res.PassAs<base::Value>(); } -scoped_ptr<base::Value> MathUtil::AsValueSafely(double value) { - return scoped_ptr<base::Value>(new base::FundamentalValue( - std::min(value, std::numeric_limits<double>::max()))); +double MathUtil::AsDoubleSafely(double value) { + return std::min(value, std::numeric_limits<double>::max()); } -scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { - return scoped_ptr<base::Value>(new base::FundamentalValue( - std::min(value, std::numeric_limits<float>::max()))); +float MathUtil::AsFloatSafely(float value) { + return std::min(value, std::numeric_limits<float>::max()); } } // namespace cc diff --git a/cc/base/math_util.h b/cc/base/math_util.h index 3af2102..4301add 100644 --- a/cc/base/math_util.h +++ b/cc/base/math_util.h @@ -17,7 +17,12 @@ #include "ui/gfx/size.h" #include "ui/gfx/transform.h" -namespace base { class Value; } +namespace base { +class Value; +namespace debug { +class TracedValue; +} +} namespace gfx { class QuadF; @@ -174,21 +179,35 @@ class CC_EXPORT MathUtil { // Conversion to value. static scoped_ptr<base::Value> AsValue(const gfx::Size& s); - static scoped_ptr<base::Value> AsValue(const gfx::SizeF& s); static scoped_ptr<base::Value> AsValue(const gfx::Rect& r); static bool FromValue(const base::Value*, gfx::Rect* out_rect); static scoped_ptr<base::Value> AsValue(const gfx::PointF& q); - static scoped_ptr<base::Value> AsValue(const gfx::Point3F&); - static scoped_ptr<base::Value> AsValue(const gfx::Vector2d& v); - static scoped_ptr<base::Value> AsValue(const gfx::QuadF& q); - static scoped_ptr<base::Value> AsValue(const gfx::RectF& rect); - static scoped_ptr<base::Value> AsValue(const gfx::Transform& transform); - static scoped_ptr<base::Value> AsValue(const gfx::BoxF& box); + + static void AddToTracedValue(const gfx::Size& s, + base::debug::TracedValue* res); + static void AddToTracedValue(const gfx::SizeF& s, + base::debug::TracedValue* res); + static void AddToTracedValue(const gfx::Rect& r, + base::debug::TracedValue* res); + static void AddToTracedValue(const gfx::PointF& q, + base::debug::TracedValue* res); + static void AddToTracedValue(const gfx::Point3F&, + base::debug::TracedValue* res); + static void AddToTracedValue(const gfx::Vector2d& v, + base::debug::TracedValue* res); + static void AddToTracedValue(const gfx::QuadF& q, + base::debug::TracedValue* res); + static void AddToTracedValue(const gfx::RectF& rect, + base::debug::TracedValue* res); + static void AddToTracedValue(const gfx::Transform& transform, + base::debug::TracedValue* res); + static void AddToTracedValue(const gfx::BoxF& box, + base::debug::TracedValue* res); // Returns a base::Value representation of the floating point value. // If the value is inf, returns max double/float representation. - static scoped_ptr<base::Value> AsValueSafely(double value); - static scoped_ptr<base::Value> AsValueSafely(float value); + static double AsDoubleSafely(double value); + static float AsFloatSafely(float value); }; } // namespace cc diff --git a/cc/base/region.cc b/cc/base/region.cc index 906bc6e..79c30ec 100644 --- a/cc/base/region.cc +++ b/cc/base/region.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "cc/base/region.h" +#include "base/debug/trace_event_argument.h" #include "base/values.h" namespace cc { @@ -120,6 +121,16 @@ scoped_ptr<base::Value> Region::AsValue() const { return result.PassAs<base::Value>(); } +void Region::AsValueInto(base::debug::TracedValue* result) const { + for (Iterator it(*this); it.has_rect(); it.next()) { + gfx::Rect rect(it.rect()); + result->AppendInteger(rect.x()); + result->AppendInteger(rect.y()); + result->AppendInteger(rect.width()); + result->AppendInteger(rect.height()); + } +} + Region::Iterator::Iterator() { } diff --git a/cc/base/region.h b/cc/base/region.h index 06fe731..3ef32db 100644 --- a/cc/base/region.h +++ b/cc/base/region.h @@ -16,6 +16,9 @@ namespace base { class Value; +namespace debug { +class TracedValue; +} } namespace cc { @@ -59,6 +62,7 @@ class CC_EXPORT Region { std::string ToString() const; scoped_ptr<base::Value> AsValue() const; + void AsValueInto(base::debug::TracedValue* array) const; class CC_EXPORT Iterator { public: |