| 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" | 9 #include "FloatQuad.h" |
| 10 #include "FloatSize.h" | 10 #include "FloatSize.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // implicit definition of w = 1; | 33 // implicit definition of w = 1; |
| 34 | 34 |
| 35 double outX = x * transform.m11() + y * transform.m21() + z * transform.m31(
) + transform.m41(); | 35 double outX = x * transform.m11() + y * transform.m21() + z * transform.m31(
) + transform.m41(); |
| 36 double outY = x * transform.m12() + y * transform.m22() + z * transform.m32(
) + transform.m42(); | 36 double outY = x * transform.m12() + y * transform.m22() + z * transform.m32(
) + transform.m42(); |
| 37 double outZ = x * transform.m13() + y * transform.m23() + z * transform.m33(
) + transform.m43(); | 37 double outZ = x * transform.m13() + y * transform.m23() + z * transform.m33(
) + transform.m43(); |
| 38 double outW = x * transform.m14() + y * transform.m24() + z * transform.m34(
) + transform.m44(); | 38 double outW = x * transform.m14() + y * transform.m24() + z * transform.m34(
) + transform.m44(); |
| 39 | 39 |
| 40 return HomogeneousCoordinate(outX, outY, outZ, outW); | 40 return HomogeneousCoordinate(outX, outY, outZ, outW); |
| 41 } | 41 } |
| 42 | 42 |
| 43 static HomogeneousCoordinate mapHomogeneousPoint(const WebTransformationMatrix&
transform, const FloatPoint3D& p) | 43 static HomogeneousCoordinate mapHomogeneousPoint(const WebTransformationMatrix&
transform, const gfx::Point3F& p) |
| 44 { | 44 { |
| 45 double x = p.x(); | 45 double x = p.x(); |
| 46 double y = p.y(); | 46 double y = p.y(); |
| 47 double z = p.z(); | 47 double z = p.z(); |
| 48 // implicit definition of w = 1; | 48 // implicit definition of w = 1; |
| 49 | 49 |
| 50 double outX = x * transform.m11() + y * transform.m21() + z * transform.m31(
) + transform.m41(); | 50 double outX = x * transform.m11() + y * transform.m21() + z * transform.m31(
) + transform.m41(); |
| 51 double outY = x * transform.m12() + y * transform.m22() + z * transform.m32(
) + transform.m42(); | 51 double outY = x * transform.m12() + y * transform.m22() + z * transform.m32(
) + transform.m42(); |
| 52 double outZ = x * transform.m13() + y * transform.m23() + z * transform.m33(
) + transform.m43(); | 52 double outZ = x * transform.m13() + y * transform.m23() + z * transform.m33(
) + transform.m43(); |
| 53 double outW = x * transform.m14() + y * transform.m24() + z * transform.m34(
) + transform.m44(); | 53 double outW = x * transform.m14() + y * transform.m24() + z * transform.m34(
) + transform.m44(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 FloatQuad q = FloatQuad(gfx::RectF(srcRect)); |
| 116 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, q.p1()); | 116 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1(
))); |
| 117 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, q.p2()); | 117 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2(
))); |
| 118 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, q.p3()); | 118 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3(
))); |
| 119 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, 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 FloatQuad q = FloatQuad(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 Fl
oatQuad& srcQuad, gfx::PointF clippedQuad[8], int& numVerticesInClippedQuad) |
| 137 { | 137 { |
| 138 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, srcQuad.p1()); | 138 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p1())); |
| 139 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, srcQuad.p2()); | 139 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p2())); |
| 140 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, srcQuad.p3()); | 140 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(srcQu
ad.p3())); |
| 141 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, srcQuad.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 |
| 147 if (!h1.shouldBeClipped()) | 147 if (!h1.shouldBeClipped()) |
| 148 addVertexToClippedQuad(h1.cartesianPoint2d(), clippedQuad, numVerticesIn
ClippedQuad); | 148 addVertexToClippedQuad(h1.cartesianPoint2d(), clippedQuad, numVerticesIn
ClippedQuad); |
| 149 | 149 |
| 150 if (h1.shouldBeClipped() ^ h2.shouldBeClipped()) | 150 if (h1.shouldBeClipped() ^ h2.shouldBeClipped()) |
| 151 addVertexToClippedQuad(computeClippedPointForEdge(h1, h2).cartesianPoint
2d(), clippedQuad, numVerticesInClippedQuad); | 151 addVertexToClippedQuad(computeClippedPointForEdge(h1, h2).cartesianPoint
2d(), clippedQuad, numVerticesInClippedQuad); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 239 |
| 240 FloatQuad MathUtil::mapQuad(const WebTransformationMatrix& transform, const Floa
tQuad& q, bool& clipped) | 240 FloatQuad MathUtil::mapQuad(const WebTransformationMatrix& transform, const Floa
tQuad& q, bool& clipped) |
| 241 { | 241 { |
| 242 if (transform.isIdentityOrTranslation()) { | 242 if (transform.isIdentityOrTranslation()) { |
| 243 FloatQuad mappedQuad(q); | 243 FloatQuad mappedQuad(q); |
| 244 mappedQuad.move(static_cast<float>(transform.m41()), static_cast<float>(
transform.m42())); | 244 mappedQuad.move(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, q.p1()); | 249 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, gfx::Point3F(q.p1(
))); |
| 250 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, q.p2()); | 250 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, gfx::Point3F(q.p2(
))); |
| 251 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, q.p3()); | 251 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, gfx::Point3F(q.p3(
))); |
| 252 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, 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 FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoint2d(), h3.cartesianP
oint2d(), 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, cc::FloatPoint(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 } |
| 268 | 268 |
| 269 // The cartesian coordinates will be invalid after dividing by w. | 269 // The cartesian coordinates will be invalid after dividing by w. |
| 270 clipped = true; | 270 clipped = true; |
| 271 | 271 |
| 272 // Avoid dividing by w if w == 0. | 272 // Avoid dividing by w if w == 0. |
| 273 if (!h.w) | 273 if (!h.w) |
| 274 return gfx::PointF(); | 274 return gfx::PointF(); |
| 275 | 275 |
| 276 // This return value will be invalid because clipped == true, but (1) users
of this | 276 // This return value will be invalid because clipped == true, but (1) users
of this |
| 277 // code should be ignoring the return value when clipped == true anyway, and
(2) this | 277 // code should be ignoring the return value when clipped == true anyway, and
(2) this |
| 278 // behavior is more consistent with existing behavior of WebKit transforms i
f the user | 278 // behavior is more consistent with existing behavior of WebKit transforms i
f the user |
| 279 // really does not ignore the return value. | 279 // really does not ignore the return value. |
| 280 return h.cartesianPoint2d(); | 280 return h.cartesianPoint2d(); |
| 281 } | 281 } |
| 282 | 282 |
| 283 FloatPoint3D MathUtil::mapPoint(const WebTransformationMatrix& transform, const
FloatPoint3D& p, bool& clipped) | 283 gfx::Point3F MathUtil::mapPoint(const WebTransformationMatrix& transform, const
gfx::Point3F& p, bool& clipped) |
| 284 { | 284 { |
| 285 HomogeneousCoordinate h = mapHomogeneousPoint(transform, p); | 285 HomogeneousCoordinate h = mapHomogeneousPoint(transform, p); |
| 286 | 286 |
| 287 if (h.w > 0) { | 287 if (h.w > 0) { |
| 288 clipped = false; | 288 clipped = false; |
| 289 return h.cartesianPoint3d(); | 289 return h.cartesianPoint3d(); |
| 290 } | 290 } |
| 291 | 291 |
| 292 // The cartesian coordinates will be invalid after dividing by w. | 292 // The cartesian coordinates will be invalid after dividing by w. |
| 293 clipped = true; | 293 clipped = true; |
| 294 | 294 |
| 295 // Avoid dividing by w if w == 0. | 295 // Avoid dividing by w if w == 0. |
| 296 if (!h.w) | 296 if (!h.w) |
| 297 return FloatPoint3D(); | 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 FloatQuad MathUtil::projectQuad(const WebTransformationMatrix& transform, const
FloatQuad& q, bool& clipped) |
| 307 { | 307 { |
| (...skipping 79 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 |