Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: cc/base/math_util.cc

Issue 380763002: Add builders for tracing event's structural arguments (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/base/math_util.h" 5 #include "cc/base/math_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
11 #include "base/debug/trace_event_argument.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "ui/gfx/quad_f.h" 13 #include "ui/gfx/quad_f.h"
13 #include "ui/gfx/rect.h" 14 #include "ui/gfx/rect.h"
14 #include "ui/gfx/rect_conversions.h" 15 #include "ui/gfx/rect_conversions.h"
15 #include "ui/gfx/rect_f.h" 16 #include "ui/gfx/rect_f.h"
16 #include "ui/gfx/transform.h" 17 #include "ui/gfx/transform.h"
17 #include "ui/gfx/vector2d_f.h" 18 #include "ui/gfx/vector2d_f.h"
18 19
19 namespace cc { 20 namespace cc {
20 21
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 scoped_ptr<base::ListValue> res(new base::ListValue()); 643 scoped_ptr<base::ListValue> res(new base::ListValue());
643 res->AppendInteger(box.x()); 644 res->AppendInteger(box.x());
644 res->AppendInteger(box.y()); 645 res->AppendInteger(box.y());
645 res->AppendInteger(box.z()); 646 res->AppendInteger(box.z());
646 res->AppendInteger(box.width()); 647 res->AppendInteger(box.width());
647 res->AppendInteger(box.height()); 648 res->AppendInteger(box.height());
648 res->AppendInteger(box.depth()); 649 res->AppendInteger(box.depth());
649 return res.PassAs<base::Value>(); 650 return res.PassAs<base::Value>();
650 } 651 }
651 652
653 void MathUtil::AddToTracedValue(const gfx::Size& s,
654 base::debug::TracedValue* res) {
655 res->SetDouble("width", s.width());
656 res->SetDouble("height", s.height());
657 }
658
659 void MathUtil::AddToTracedValue(const gfx::SizeF& s,
660 base::debug::TracedValue* res) {
661 res->SetDouble("width", s.width());
662 res->SetDouble("height", s.height());
663 }
664
665 void MathUtil::AddToTracedValue(const gfx::Rect& r,
666 base::debug::TracedValue* res) {
667 res->AppendInteger(r.x());
668 res->AppendInteger(r.y());
669 res->AppendInteger(r.width());
670 res->AppendInteger(r.height());
671 }
672
673 void MathUtil::AddToTracedValue(const gfx::PointF& pt,
674 base::debug::TracedValue* res) {
675 res->AppendDouble(pt.x());
676 res->AppendDouble(pt.y());
677 }
678
679 void MathUtil::AddToTracedValue(const gfx::Point3F& pt,
680 base::debug::TracedValue* res) {
681 res->AppendDouble(pt.x());
682 res->AppendDouble(pt.y());
683 res->AppendDouble(pt.z());
684 }
685
686 void MathUtil::AddToTracedValue(const gfx::Vector2d& v,
687 base::debug::TracedValue* res) {
688 res->AppendInteger(v.x());
689 res->AppendInteger(v.y());
690 }
691
692 void MathUtil::AddToTracedValue(const gfx::QuadF& q,
693 base::debug::TracedValue* res) {
694 res->AppendDouble(q.p1().x());
695 res->AppendDouble(q.p1().y());
696 res->AppendDouble(q.p2().x());
697 res->AppendDouble(q.p2().y());
698 res->AppendDouble(q.p3().x());
699 res->AppendDouble(q.p3().y());
700 res->AppendDouble(q.p4().x());
701 res->AppendDouble(q.p4().y());
702 }
703
704 void MathUtil::AddToTracedValue(const gfx::RectF& rect,
705 base::debug::TracedValue* res) {
706 res->AppendDouble(rect.x());
707 res->AppendDouble(rect.y());
708 res->AppendDouble(rect.width());
709 res->AppendDouble(rect.height());
710 }
711
712 void MathUtil::AddToTracedValue(const gfx::Transform& transform,
713 base::debug::TracedValue* res) {
714 const SkMatrix44& m = transform.matrix();
715 for (int row = 0; row < 4; ++row) {
716 for (int col = 0; col < 4; ++col)
717 res->AppendDouble(m.getDouble(row, col));
718 }
719 }
720
721 void MathUtil::AddToTracedValue(const gfx::BoxF& box,
722 base::debug::TracedValue* res) {
723 res->AppendInteger(box.x());
724 res->AppendInteger(box.y());
725 res->AppendInteger(box.z());
726 res->AppendInteger(box.width());
727 res->AppendInteger(box.height());
728 res->AppendInteger(box.depth());
729 }
730
652 scoped_ptr<base::Value> MathUtil::AsValueSafely(double value) { 731 scoped_ptr<base::Value> MathUtil::AsValueSafely(double value) {
653 return scoped_ptr<base::Value>(new base::FundamentalValue( 732 return scoped_ptr<base::Value>(new base::FundamentalValue(
654 std::min(value, std::numeric_limits<double>::max()))); 733 std::min(value, std::numeric_limits<double>::max())));
655 } 734 }
656 735
657 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { 736 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) {
658 return scoped_ptr<base::Value>(new base::FundamentalValue( 737 return scoped_ptr<base::Value>(new base::FundamentalValue(
659 std::min(value, std::numeric_limits<float>::max()))); 738 std::min(value, std::numeric_limits<float>::max())));
660 } 739 }
661 740
741 double MathUtil::AsDoubleSafely(double value) {
742 return std::min(value, std::numeric_limits<double>::max());
743 }
744
745 float MathUtil::AsFloatSafely(float value) {
746 return std::min(value, std::numeric_limits<float>::max());
747 }
748
662 } // namespace cc 749 } // namespace cc
OLDNEW
« cc/base/math_util.h ('K') | « cc/base/math_util.h ('k') | cc/base/region.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698