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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/math_util.h" | 7 #include "cc/math_util.h" |
8 | 8 |
9 #include "FloatQuad.h" | |
10 #include "FloatSize.h" | 9 #include "FloatSize.h" |
| 10 #include "ui/gfx/quad_f.h" |
11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
12 #include "ui/gfx/rect_conversions.h" | 12 #include "ui/gfx/rect_conversions.h" |
13 #include "ui/gfx/rect_f.h" | 13 #include "ui/gfx/rect_f.h" |
14 #include <cmath> | 14 #include <cmath> |
15 #include <public/WebTransformationMatrix.h> | 15 #include <public/WebTransformationMatrix.h> |
16 | 16 |
17 using WebKit::WebTransformationMatrix; | 17 using WebKit::WebTransformationMatrix; |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 gfx::RectF MathUtil::mapClippedRect(const WebTransformationMatrix& transform, co
nst gfx::RectF& srcRect) | 106 gfx::RectF MathUtil::mapClippedRect(const WebTransformationMatrix& transform, co
nst gfx::RectF& srcRect) |
107 { | 107 { |
108 if (transform.isIdentityOrTranslation()) { | 108 if (transform.isIdentityOrTranslation()) { |
109 gfx::RectF mappedRect(srcRect); | 109 gfx::RectF mappedRect(srcRect); |
110 mappedRect.Offset(static_cast<float>(transform.m41()), static_cast<float
>(transform.m42())); | 110 mappedRect.Offset(static_cast<float>(transform.m41()), static_cast<float
>(transform.m42())); |
111 return mappedRect; | 111 return mappedRect; |
112 } | 112 } |
113 | 113 |
114 // Apply the transform, but retain the result in homogeneous coordinates. | 114 // Apply the transform, but retain the result in homogeneous coordinates. |
115 FloatQuad q = FloatQuad(gfx::RectF(srcRect)); | 115 gfx::QuadF q = gfx::QuadF(gfx::RectF(srcRect)); |
116 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1(
))); | 116 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1(
))); |
117 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2(
))); | 117 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2(
))); |
118 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3(
))); | 118 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3(
))); |
119 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(q.p4(
))); | 119 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(q.p4(
))); |
120 | 120 |
121 return computeEnclosingClippedRect(h1, h2, h3, h4); | 121 return computeEnclosingClippedRect(h1, h2, h3, h4); |
122 } | 122 } |
123 | 123 |
124 gfx::RectF MathUtil::projectClippedRect(const WebTransformationMatrix& transform
, const gfx::RectF& srcRect) | 124 gfx::RectF MathUtil::projectClippedRect(const WebTransformationMatrix& transform
, const gfx::RectF& srcRect) |
125 { | 125 { |
126 // Perform the projection, but retain the result in homogeneous coordinates. | 126 // Perform the projection, but retain the result in homogeneous coordinates. |
127 FloatQuad q = FloatQuad(gfx::RectF(srcRect)); | 127 gfx::QuadF q = gfx::QuadF(gfx::RectF(srcRect)); |
128 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); | 128 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); |
129 HomogeneousCoordinate h2 = projectHomogeneousPoint(transform, q.p2()); | 129 HomogeneousCoordinate h2 = projectHomogeneousPoint(transform, q.p2()); |
130 HomogeneousCoordinate h3 = projectHomogeneousPoint(transform, q.p3()); | 130 HomogeneousCoordinate h3 = projectHomogeneousPoint(transform, q.p3()); |
131 HomogeneousCoordinate h4 = projectHomogeneousPoint(transform, q.p4()); | 131 HomogeneousCoordinate h4 = projectHomogeneousPoint(transform, q.p4()); |
132 | 132 |
133 return computeEnclosingClippedRect(h1, h2, h3, h4); | 133 return computeEnclosingClippedRect(h1, h2, h3, h4); |
134 } | 134 } |
135 | 135 |
136 void MathUtil::mapClippedQuad(const WebTransformationMatrix& transform, const Fl
oatQuad& srcQuad, gfx::PointF clippedQuad[8], int& numVerticesInClippedQuad) | 136 void MathUtil::mapClippedQuad(const WebTransformationMatrix& transform, const gf
x::QuadF& srcQuad, gfx::PointF clippedQuad[8], int& numVerticesInClippedQuad) |
137 { | 137 { |
138 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p1())); | 138 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p1())); |
139 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p2())); | 139 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p2())); |
140 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p3())); | 140 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p3())); |
141 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p4())); | 141 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p4())); |
142 | 142 |
143 // The order of adding the vertices to the array is chosen so that clockwise
/ counter-clockwise orientation is retained. | 143 // The order of adding the vertices to the array is chosen so that clockwise
/ counter-clockwise orientation is retained. |
144 | 144 |
145 numVerticesInClippedQuad = 0; | 145 numVerticesInClippedQuad = 0; |
146 | 146 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 gfx::RectF MathUtil::computeEnclosingClippedRect(const HomogeneousCoordinate& h1
, const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homoge
neousCoordinate& h4) | 190 gfx::RectF MathUtil::computeEnclosingClippedRect(const HomogeneousCoordinate& h1
, const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homoge
neousCoordinate& h4) |
191 { | 191 { |
192 // This function performs clipping as necessary and computes the enclosing 2
d | 192 // This function performs clipping as necessary and computes the enclosing 2
d |
193 // gfx::RectF of the vertices. Doing these two steps simultaneously allows u
s to avoid | 193 // gfx::RectF of the vertices. Doing these two steps simultaneously allows u
s to avoid |
194 // the overhead of storing an unknown number of clipped vertices. | 194 // the overhead of storing an unknown number of clipped vertices. |
195 | 195 |
196 // If no vertices on the quad are clipped, then we can simply return the enc
losing rect directly. | 196 // If no vertices on the quad are clipped, then we can simply return the enc
losing rect directly. |
197 bool somethingClipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.s
houldBeClipped() || h4.shouldBeClipped(); | 197 bool somethingClipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.s
houldBeClipped() || h4.shouldBeClipped(); |
198 if (!somethingClipped) { | 198 if (!somethingClipped) { |
199 FloatQuad mappedQuad = FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoin
t2d(), h3.cartesianPoint2d(), h4.cartesianPoint2d()); | 199 gfx::QuadF mappedQuad = gfx::QuadF(h1.cartesianPoint2d(), h2.cartesianPo
int2d(), h3.cartesianPoint2d(), h4.cartesianPoint2d()); |
200 return mappedQuad.boundingBox(); | 200 return mappedQuad.BoundingBox(); |
201 } | 201 } |
202 | 202 |
203 bool everythingClipped = h1.shouldBeClipped() && h2.shouldBeClipped() && h3.
shouldBeClipped() && h4.shouldBeClipped(); | 203 bool everythingClipped = h1.shouldBeClipped() && h2.shouldBeClipped() && h3.
shouldBeClipped() && h4.shouldBeClipped(); |
204 if (everythingClipped) | 204 if (everythingClipped) |
205 return gfx::RectF(); | 205 return gfx::RectF(); |
206 | 206 |
207 | 207 |
208 float xmin = std::numeric_limits<float>::max(); | 208 float xmin = std::numeric_limits<float>::max(); |
209 float xmax = -std::numeric_limits<float>::max(); | 209 float xmax = -std::numeric_limits<float>::max(); |
210 float ymin = std::numeric_limits<float>::max(); | 210 float ymin = std::numeric_limits<float>::max(); |
(...skipping 19 matching lines...) Expand all Loading... |
230 | 230 |
231 if (!h4.shouldBeClipped()) | 231 if (!h4.shouldBeClipped()) |
232 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, h4.cartesianPoint2d()
); | 232 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, h4.cartesianPoint2d()
); |
233 | 233 |
234 if (h4.shouldBeClipped() ^ h1.shouldBeClipped()) | 234 if (h4.shouldBeClipped() ^ h1.shouldBeClipped()) |
235 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, computeClippedPointFo
rEdge(h4, h1).cartesianPoint2d()); | 235 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, computeClippedPointFo
rEdge(h4, h1).cartesianPoint2d()); |
236 | 236 |
237 return gfx::RectF(gfx::PointF(xmin, ymin), gfx::SizeF(xmax - xmin, ymax - ym
in)); | 237 return gfx::RectF(gfx::PointF(xmin, ymin), gfx::SizeF(xmax - xmin, ymax - ym
in)); |
238 } | 238 } |
239 | 239 |
240 FloatQuad MathUtil::mapQuad(const WebTransformationMatrix& transform, const Floa
tQuad& q, bool& clipped) | 240 gfx::QuadF MathUtil::mapQuad(const WebTransformationMatrix& transform, const gfx
::QuadF& q, bool& clipped) |
241 { | 241 { |
242 if (transform.isIdentityOrTranslation()) { | 242 if (transform.isIdentityOrTranslation()) { |
243 FloatQuad mappedQuad(q); | 243 gfx::QuadF mappedQuad(q); |
244 mappedQuad.move(static_cast<float>(transform.m41()), static_cast<float>(
transform.m42())); | 244 mappedQuad += gfx::Vector2dF(static_cast<float>(transform.m41()), static
_cast<float>(transform.m42())); |
245 clipped = false; | 245 clipped = false; |
246 return mappedQuad; | 246 return mappedQuad; |
247 } | 247 } |
248 | 248 |
249 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1(
))); | 249 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1(
))); |
250 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2(
))); | 250 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2(
))); |
251 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3(
))); | 251 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3(
))); |
252 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(q.p4(
))); | 252 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, gfx::Point3F(q.p4(
))); |
253 | 253 |
254 clipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.shouldBeClipped
() || h4.shouldBeClipped(); | 254 clipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.shouldBeClipped
() || h4.shouldBeClipped(); |
255 | 255 |
256 // Result will be invalid if clipped == true. But, compute it anyway just in
case, to emulate existing behavior. | 256 // Result will be invalid if clipped == true. But, compute it anyway just in
case, to emulate existing behavior. |
257 return FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoint2d(), h3.cartesianP
oint2d(), h4.cartesianPoint2d()); | 257 return gfx::QuadF(h1.cartesianPoint2d(), h2.cartesianPoint2d(), h3.cartesian
Point2d(), h4.cartesianPoint2d()); |
258 } | 258 } |
259 | 259 |
260 gfx::PointF MathUtil::mapPoint(const WebTransformationMatrix& transform, const g
fx::PointF& p, bool& clipped) | 260 gfx::PointF MathUtil::mapPoint(const WebTransformationMatrix& transform, const g
fx::PointF& p, bool& clipped) |
261 { | 261 { |
262 HomogeneousCoordinate h = mapHomogeneousPoint(transform, gfx::Point3F(p)); | 262 HomogeneousCoordinate h = mapHomogeneousPoint(transform, gfx::Point3F(p)); |
263 | 263 |
264 if (h.w > 0) { | 264 if (h.w > 0) { |
265 clipped = false; | 265 clipped = false; |
266 return h.cartesianPoint2d(); | 266 return h.cartesianPoint2d(); |
267 } | 267 } |
(...skipping 28 matching lines...) Expand all Loading... |
296 if (!h.w) | 296 if (!h.w) |
297 return gfx::Point3F(); | 297 return gfx::Point3F(); |
298 | 298 |
299 // This return value will be invalid because clipped == true, but (1) users
of this | 299 // This return value will be invalid because clipped == true, but (1) users
of this |
300 // code should be ignoring the return value when clipped == true anyway, and
(2) this | 300 // code should be ignoring the return value when clipped == true anyway, and
(2) this |
301 // behavior is more consistent with existing behavior of WebKit transforms i
f the user | 301 // behavior is more consistent with existing behavior of WebKit transforms i
f the user |
302 // really does not ignore the return value. | 302 // really does not ignore the return value. |
303 return h.cartesianPoint3d(); | 303 return h.cartesianPoint3d(); |
304 } | 304 } |
305 | 305 |
306 FloatQuad MathUtil::projectQuad(const WebTransformationMatrix& transform, const
FloatQuad& q, bool& clipped) | 306 gfx::QuadF MathUtil::projectQuad(const WebTransformationMatrix& transform, const
gfx::QuadF& q, bool& clipped) |
307 { | 307 { |
308 FloatQuad projectedQuad; | 308 gfx::QuadF projectedQuad; |
309 bool clippedPoint; | 309 bool clippedPoint; |
310 projectedQuad.setP1(projectPoint(transform, q.p1(), clippedPoint)); | 310 projectedQuad.set_p1(projectPoint(transform, q.p1(), clippedPoint)); |
311 clipped = clippedPoint; | 311 clipped = clippedPoint; |
312 projectedQuad.setP2(projectPoint(transform, q.p2(), clippedPoint)); | 312 projectedQuad.set_p2(projectPoint(transform, q.p2(), clippedPoint)); |
313 clipped |= clippedPoint; | 313 clipped |= clippedPoint; |
314 projectedQuad.setP3(projectPoint(transform, q.p3(), clippedPoint)); | 314 projectedQuad.set_p3(projectPoint(transform, q.p3(), clippedPoint)); |
315 clipped |= clippedPoint; | 315 clipped |= clippedPoint; |
316 projectedQuad.setP4(projectPoint(transform, q.p4(), clippedPoint)); | 316 projectedQuad.set_p4(projectPoint(transform, q.p4(), clippedPoint)); |
317 clipped |= clippedPoint; | 317 clipped |= clippedPoint; |
318 | 318 |
319 return projectedQuad; | 319 return projectedQuad; |
320 } | 320 } |
321 | 321 |
322 gfx::PointF MathUtil::projectPoint(const WebTransformationMatrix& transform, con
st gfx::PointF& p, bool& clipped) | 322 gfx::PointF MathUtil::projectPoint(const WebTransformationMatrix& transform, con
st gfx::PointF& p, bool& clipped) |
323 { | 323 { |
324 HomogeneousCoordinate h = projectHomogeneousPoint(transform, p); | 324 HomogeneousCoordinate h = projectHomogeneousPoint(transform, p); |
325 | 325 |
326 if (h.w > 0) { | 326 if (h.w > 0) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 387 } |
388 | 388 |
389 FloatSize MathUtil::projectVector(const FloatSize& source, const FloatSize& dest
ination) | 389 FloatSize MathUtil::projectVector(const FloatSize& source, const FloatSize& dest
ination) |
390 { | 390 { |
391 float sourceDotDestination = source.width() * destination.width() + source.h
eight() * destination.height(); | 391 float sourceDotDestination = source.width() * destination.width() + source.h
eight() * destination.height(); |
392 float projectedLength = sourceDotDestination / destination.diagonalLengthSqu
ared(); | 392 float projectedLength = sourceDotDestination / destination.diagonalLengthSqu
ared(); |
393 return FloatSize(projectedLength * destination.width(), projectedLength * de
stination.height()); | 393 return FloatSize(projectedLength * destination.width(), projectedLength * de
stination.height()); |
394 } | 394 } |
395 | 395 |
396 } // namespace cc | 396 } // namespace cc |
OLD | NEW |