OLD | NEW |
---|---|
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/math_util.h" | 5 #include "cc/math_util.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "ui/gfx/quad_f.h" | 10 #include "ui/gfx/quad_f.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 | 102 |
103 gfx::Rect MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx::R ect& srcRect) | 103 gfx::Rect MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx::R ect& srcRect) |
104 { | 104 { |
105 return gfx::ToEnclosingRect(mapClippedRect(transform, gfx::RectF(srcRect))); | 105 return gfx::ToEnclosingRect(mapClippedRect(transform, gfx::RectF(srcRect))); |
106 } | 106 } |
107 | 107 |
108 gfx::RectF MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx:: RectF& srcRect) | 108 gfx::RectF MathUtil::mapClippedRect(const gfx::Transform& transform, const gfx:: RectF& srcRect) |
109 { | 109 { |
110 if (transform.IsIdentityOrTranslation()) | 110 if (transform.IsIdentityOrTranslation()) |
111 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); | 111 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); |
112 | |
113 // Apply the transform, but retain the result in homogeneous coordinates. | |
112 | 114 |
113 // Apply the transform, but retain the result in homogeneous coordinates. | 115 double quad[4 * 2]; // input: 4 x 2D point |
114 gfx::QuadF q = gfx::QuadF(srcRect); | 116 quad[0] = srcRect.x(); quad[1] = srcRect.y(); |
shawnsingh
2012/12/06 03:00:55
nit: point --> points
reed1
2012/12/06 05:50:20
Done.
| |
115 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1( ))); | 117 quad[2] = srcRect.right(); quad[3] = srcRect.y(); |
116 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2( ))); | 118 quad[4] = srcRect.x(); quad[5] = srcRect.bottom(); |
117 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3( ))); | 119 quad[6] = srcRect.right(); quad[7] = srcRect.bottom(); |
118 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(q.p4( ))); | |
119 | 120 |
120 return computeEnclosingClippedRect(h1, h2, h3, h4); | 121 double result[4 * 4]; // output: 4 x 4D homogeneous point |
122 transform.matrix().map2(quad, 4, result); | |
123 | |
124 if (!(transform.matrix().getType() & SkMatrix44::kPerspective_Mask)) { | |
125 const SkPoint pts[] = { | |
126 { result[0], result[1] }, { result[4], result[5] }, | |
127 { result[8], result[8] }, { result[12], result[13] }, | |
128 }; | |
129 SkRect r; | |
130 r.set(pts, 4); | |
131 return gfx::RectF(r.x(), r.y(), r.width(), r.height()); | |
132 } | |
133 | |
134 return computeEnclosingClippedRect(*(const HomogeneousCoordinate*)&result[0] , | |
135 *(const HomogeneousCoordinate*)&result[4] , | |
136 *(const HomogeneousCoordinate*)&result[8] , | |
137 *(const HomogeneousCoordinate*)&result[12 ]); | |
121 } | 138 } |
122 | 139 |
123 gfx::RectF MathUtil::projectClippedRect(const gfx::Transform& transform, const g fx::RectF& srcRect) | 140 gfx::RectF MathUtil::projectClippedRect(const gfx::Transform& transform, const g fx::RectF& srcRect) |
124 { | 141 { |
125 if (transform.IsIdentityOrTranslation()) | 142 if (transform.IsIdentityOrTranslation()) |
126 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); | 143 return srcRect + gfx::Vector2dF(static_cast<float>(transform.matrix().ge tDouble(0, 3)), static_cast<float>(transform.matrix().getDouble(1, 3))); |
127 | 144 |
128 // Perform the projection, but retain the result in homogeneous coordinates. | 145 // Perform the projection, but retain the result in homogeneous coordinates. |
129 gfx::QuadF q = gfx::QuadF(srcRect); | 146 gfx::QuadF q = gfx::QuadF(srcRect); |
130 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); | 147 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 matrix.setDouble(1, 0, b); | 499 matrix.setDouble(1, 0, b); |
483 matrix.setDouble(0, 1, c); | 500 matrix.setDouble(0, 1, c); |
484 matrix.setDouble(1, 1, d); | 501 matrix.setDouble(1, 1, d); |
485 matrix.setDouble(0, 3, e); | 502 matrix.setDouble(0, 3, e); |
486 matrix.setDouble(1, 3, f); | 503 matrix.setDouble(1, 3, f); |
487 | 504 |
488 return result; | 505 return result; |
489 } | 506 } |
490 | 507 |
491 } // namespace cc | 508 } // namespace cc |
OLD | NEW |