| 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 #ifndef CCMathUtil_h | 5 // Temporary forwarding header |
| 6 #define CCMathUtil_h | 6 #include "cc/math_util.h" |
| 7 | |
| 8 #include "FloatPoint.h" | |
| 9 #include "FloatPoint3D.h" | |
| 10 | |
| 11 namespace WebKit { | |
| 12 class WebTransformationMatrix; | |
| 13 } | |
| 14 | |
| 15 namespace cc { | |
| 16 | |
| 17 class IntRect; | |
| 18 class FloatRect; | |
| 19 class FloatQuad; | |
| 20 | |
| 21 struct HomogeneousCoordinate { | |
| 22 HomogeneousCoordinate(double newX, double newY, double newZ, double newW) | |
| 23 : x(newX) | |
| 24 , y(newY) | |
| 25 , z(newZ) | |
| 26 , w(newW) | |
| 27 { | |
| 28 } | |
| 29 | |
| 30 bool shouldBeClipped() const | |
| 31 { | |
| 32 return w <= 0; | |
| 33 } | |
| 34 | |
| 35 FloatPoint cartesianPoint2d() const | |
| 36 { | |
| 37 if (w == 1) | |
| 38 return FloatPoint(x, y); | |
| 39 | |
| 40 // For now, because this code is used privately only by CCMathUtil, it s
hould never be called when w == 0, and we do not yet need to handle that case. | |
| 41 ASSERT(w); | |
| 42 double invW = 1.0 / w; | |
| 43 return FloatPoint(x * invW, y * invW); | |
| 44 } | |
| 45 | |
| 46 FloatPoint3D cartesianPoint3d() const | |
| 47 { | |
| 48 if (w == 1) | |
| 49 return FloatPoint3D(x, y, z); | |
| 50 | |
| 51 // For now, because this code is used privately only by CCMathUtil, it s
hould never be called when w == 0, and we do not yet need to handle that case. | |
| 52 ASSERT(w); | |
| 53 double invW = 1.0 / w; | |
| 54 return FloatPoint3D(x * invW, y * invW, z * invW); | |
| 55 } | |
| 56 | |
| 57 double x; | |
| 58 double y; | |
| 59 double z; | |
| 60 double w; | |
| 61 }; | |
| 62 | |
| 63 class CCMathUtil { | |
| 64 public: | |
| 65 | |
| 66 // Background: WebTransformationMatrix code in WebCore does not do the right
thing in | |
| 67 // mapRect / mapQuad / projectQuad when there is a perspective projection th
at causes | |
| 68 // one of the transformed vertices to go to w < 0. In those cases, it is nec
essary to | |
| 69 // perform clipping in homogeneous coordinates, after applying the transform
, before | |
| 70 // dividing-by-w to convert to cartesian coordinates. | |
| 71 // | |
| 72 // These functions return the axis-aligned rect that encloses the correctly
clipped, | |
| 73 // transformed polygon. | |
| 74 static IntRect mapClippedRect(const WebKit::WebTransformationMatrix&, const
IntRect&); | |
| 75 static FloatRect mapClippedRect(const WebKit::WebTransformationMatrix&, cons
t FloatRect&); | |
| 76 static FloatRect projectClippedRect(const WebKit::WebTransformationMatrix&,
const FloatRect&); | |
| 77 | |
| 78 // Returns an array of vertices that represent the clipped polygon. After re
turning, indexes from | |
| 79 // 0 to numVerticesInClippedQuad are valid in the clippedQuad array. Note th
at | |
| 80 // numVerticesInClippedQuad may be zero, which means the entire quad was cli
pped, and | |
| 81 // none of the vertices in the array are valid. | |
| 82 static void mapClippedQuad(const WebKit::WebTransformationMatrix&, const Flo
atQuad& srcQuad, FloatPoint clippedQuad[8], int& numVerticesInClippedQuad); | |
| 83 | |
| 84 static FloatRect computeEnclosingRectOfVertices(FloatPoint vertices[], int n
umVertices); | |
| 85 static FloatRect computeEnclosingClippedRect(const HomogeneousCoordinate& h1
, const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homoge
neousCoordinate& h4); | |
| 86 | |
| 87 // NOTE: These functions do not do correct clipping against w = 0 plane, but
they | |
| 88 // correctly detect the clipped condition via the boolean clipped. | |
| 89 static FloatQuad mapQuad(const WebKit::WebTransformationMatrix&, const Float
Quad&, bool& clipped); | |
| 90 static FloatPoint mapPoint(const WebKit::WebTransformationMatrix&, const Flo
atPoint&, bool& clipped); | |
| 91 static FloatPoint3D mapPoint(const WebKit::WebTransformationMatrix&, const F
loatPoint3D&, bool& clipped); | |
| 92 static FloatQuad projectQuad(const WebKit::WebTransformationMatrix&, const F
loatQuad&, bool& clipped); | |
| 93 static FloatPoint projectPoint(const WebKit::WebTransformationMatrix&, const
FloatPoint&, bool& clipped); | |
| 94 | |
| 95 static void flattenTransformTo2d(WebKit::WebTransformationMatrix&); | |
| 96 | |
| 97 // Returns the smallest angle between the given two vectors in degrees. Neit
her vector is | |
| 98 // assumed to be normalized. | |
| 99 static float smallestAngleBetweenVectors(const FloatSize&, const FloatSize&)
; | |
| 100 | |
| 101 // Projects the |source| vector onto |destination|. Neither vector is assume
d to be normalized. | |
| 102 static FloatSize projectVector(const FloatSize& source, const FloatSize& des
tination); | |
| 103 }; | |
| 104 | |
| 105 } // namespace cc | |
| 106 | |
| 107 #endif // #define CCMathUtil_h | |
| OLD | NEW |