Changeset 96337 in webkit
- Timestamp:
- Sep 29, 2011 10:05:41 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r96326 r96337 1 2011-09-29 Iain Merrick <husky@google.com> 2 3 Add unit test for CCLayerSorter 4 https://bugs.webkit.org/show_bug.cgi?id=68622 5 6 Minor refactoring for testability: 7 - Made pointInTriangle public. 8 - Added LayerShape to decouple LayerIntersector and GraphNode. 9 - Added a public wrapper function for LayerIntersector. 10 11 Reviewed by James Robinson. 12 13 * platform/graphics/chromium/cc/CCLayerSorter.cpp: 14 (WebCore::CCLayerSorter::pointInTriangle): 15 (WebCore::CCLayerSorter::calculateZDiff): 16 (WebCore::CCLayerSorter::LayerIntersector::LayerIntersector): 17 (WebCore::CCLayerSorter::LayerIntersector::go): 18 (WebCore::CCLayerSorter::LayerIntersector::checkZDiff): 19 (WebCore::CCLayerSorter::LayerIntersector::layerZFromProjectedPoint): 20 (WebCore::CCLayerSorter::checkOverlap): 21 (WebCore::CCLayerSorter::LayerShape::LayerShape): 22 (WebCore::CCLayerSorter::createGraphNodes): 23 * platform/graphics/chromium/cc/CCLayerSorter.h: 24 (WebCore::CCLayerSorter::LayerShape::LayerShape): 25 (WebCore::CCLayerSorter::GraphNode::GraphNode): 26 1 27 2011-09-29 Ilya Tikhonovsky <loislo@chromium.org> 2 28 -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerSorter.cpp
r95901 r96337 46 46 namespace WebCore { 47 47 48 static boolpointInTriangle(const FloatPoint& point,49 const FloatPoint& a,50 const FloatPoint& b,51 const FloatPoint& c)48 bool CCLayerSorter::pointInTriangle(const FloatPoint& point, 49 const FloatPoint& a, 50 const FloatPoint& b, 51 const FloatPoint& c) 52 52 { 53 53 // Algorithm from http://www.blackpawn.com/texts/pointinpoly/default.html … … 144 144 } 145 145 146 CCLayerSorter::LayerIntersector::LayerIntersector(GraphNode* nodeA, GraphNode* nodeB, float earlyExitThreshold) 147 : nodeA(nodeA) 148 , nodeB(nodeB) 146 float CCLayerSorter::calculateZDiff(const LayerShape& layerA, const LayerShape& layerB, float earlyExitThreshold) 147 { 148 LayerIntersector intersector(layerA, layerB, earlyExitThreshold); 149 intersector.go(); 150 return intersector.zDiff; 151 } 152 153 CCLayerSorter::LayerIntersector::LayerIntersector(const LayerShape& layerA, const LayerShape& layerB, float earlyExitThreshold) 154 : layerA(layerA) 155 , layerB(layerB) 149 156 , zDiff(0) 150 157 , earlyExitThreshold(earlyExitThreshold) … … 154 161 void CCLayerSorter::LayerIntersector::go() 155 162 { 156 (triangleTriangleTest(nodeA->c1, nodeA->c2, nodeA->c3, nodeB->c1, nodeB->c2, nodeB->c3) 157 || triangleTriangleTest(nodeA->c3, nodeA->c4, nodeA->c1, nodeB->c1, nodeB->c2, nodeB->c3) 158 || triangleTriangleTest(nodeA->c1, nodeA->c2, nodeA->c3, nodeB->c3, nodeB->c4, nodeB->c1) 159 || triangleTriangleTest(nodeA->c3, nodeA->c4, nodeA->c1, nodeB->c3, nodeB->c4, nodeB->c1)); 160 } 161 163 (triangleTriangleTest(layerA.c1, layerA.c2, layerA.c3, layerB.c1, layerB.c2, layerB.c3) 164 || triangleTriangleTest(layerA.c3, layerA.c4, layerA.c1, layerB.c1, layerB.c2, layerB.c3) 165 || triangleTriangleTest(layerA.c1, layerA.c2, layerA.c3, layerB.c3, layerB.c4, layerB.c1) 166 || triangleTriangleTest(layerA.c3, layerA.c4, layerA.c1, layerB.c3, layerB.c4, layerB.c1)); 167 } 162 168 163 169 // Checks if segment pq intersects any of the sides of triangle abc. … … 205 211 bool CCLayerSorter::LayerIntersector::checkZDiff(const FloatPoint& p) 206 212 { 207 float za = layerZFromProjectedPoint( nodeA, p);208 float zb = layerZFromProjectedPoint( nodeB, p);213 float za = layerZFromProjectedPoint(layerA, p); 214 float zb = layerZFromProjectedPoint(layerB, p); 209 215 210 216 float diff = za - zb; … … 226 232 // intersection of a line starting from p along the Z axis and the plane 227 233 // of the layer. 228 float CCLayerSorter::LayerIntersector::layerZFromProjectedPoint( GraphNode*layer, const FloatPoint& p)234 float CCLayerSorter::LayerIntersector::layerZFromProjectedPoint(const LayerShape& layer, const FloatPoint& p) 229 235 { 230 236 const FloatPoint3D zAxis(0, 0, 1); 231 FloatPoint3D w = FloatPoint3D(p.x(), p.y(), 0) - layer ->origin;232 233 float d = layer ->normal.dot(zAxis);234 float n = -layer ->normal.dot(w);237 FloatPoint3D w = FloatPoint3D(p.x(), p.y(), 0) - layer.origin; 238 239 float d = layer.normal.dot(zAxis); 240 float n = -layer.normal.dot(w); 235 241 236 242 // Check if layer is parallel to the z = 0 axis 237 243 if (!d) 238 return layer ->origin.z();244 return layer.origin.z(); 239 245 240 246 // The intersection point would be given by: … … 244 250 } 245 251 246 247 252 CCLayerSorter::CCLayerSorter() 248 253 : m_zRange(0) … … 252 257 CCLayerSorter::ABCompareResult CCLayerSorter::checkOverlap(GraphNode* a, GraphNode* b) 253 258 { 254 if (!a-> boundingBox.intersects(b->boundingBox))259 if (!a->shape.boundingBox.intersects(b->shape.boundingBox)) 255 260 return None; 256 261 257 262 // Make the early exit threshold proportional to the total Z range. 258 263 float exitThreshold = m_zRange * 0.01; 259 260 LayerIntersector intersector(a, b, exitThreshold); 261 intersector.go(); 262 263 if (intersector.zDiff > 0) 264 float zDiff = calculateZDiff(a->shape, b->shape, exitThreshold); 265 266 if (zDiff > 0) 264 267 return BBeforeA; 265 if ( intersector.zDiff < 0)268 if (zDiff < 0) 266 269 return ABeforeB; 267 270 268 271 return None; 272 } 273 274 CCLayerSorter::LayerShape::LayerShape(const FloatPoint3D& p1, const FloatPoint3D& p2, const FloatPoint3D& p3, const FloatPoint3D& p4) 275 : normal((p2 - p1).cross(p3 - p1)) 276 , c1(FloatPoint(p1.x(), p1.y())) 277 , c2(FloatPoint(p2.x(), p2.y())) 278 , c3(FloatPoint(p3.x(), p3.y())) 279 , c4(FloatPoint(p4.x(), p4.y())) 280 , origin(p1) 281 { 282 boundingBox.fitToPoints(c1, c2, c3, c4); 269 283 } 270 284 … … 303 317 FloatPoint3D c3 = drawTransform.mapPoint(FloatPoint3D(layerWidth, -layerHeight, 0)); 304 318 FloatPoint3D c4 = drawTransform.mapPoint(FloatPoint3D(-layerWidth, -layerHeight, 0)); 305 node.normal = (c2 - c1).cross(c3 - c1); 306 node.c1 = FloatPoint(c1.x(), c1.y()); 307 node.c2 = FloatPoint(c2.x(), c2.y()); 308 node.c3 = FloatPoint(c3.x(), c3.y()); 309 node.c4 = FloatPoint(c4.x(), c4.y()); 310 node.origin = c1; 311 node.boundingBox.fitToPoints(node.c1, node.c2, node.c3, node.c4); 319 node.shape = LayerShape(c1, c2, c3, c4); 312 320 313 321 maxZ = max(c4.z(), max(c3.z(), max(c2.z(), max(maxZ, c1.z())))); -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerSorter.h
r95901 r96337 43 43 44 44 void sort(LayerList::iterator first, LayerList::iterator last); 45 46 // Helper methods, public for unit testing. 47 static bool pointInTriangle(const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&); 48 49 // Holds various useful properties derived from a layer's 3D outline. 50 struct LayerShape { 51 LayerShape() { } 52 LayerShape(const FloatPoint3D&, const FloatPoint3D&, const FloatPoint3D&, const FloatPoint3D&); 53 54 FloatPoint3D normal; 55 FloatPoint c1, c2, c3, c4; 56 FloatPoint3D origin; 57 FloatRect boundingBox; 58 }; 59 60 static float calculateZDiff(const LayerShape&, const LayerShape&, float earlyExitThreshold); 61 45 62 private: 46 63 struct GraphEdge; 47 64 48 65 struct GraphNode { 49 GraphNode(CCLayerImpl* cclayer) : layer(cclayer) { }; 66 explicit GraphNode(CCLayerImpl* cclayer) : layer(cclayer) { } 67 50 68 CCLayerImpl* layer; 51 FloatPoint c1, c2, c3, c4; 52 FloatPoint3D normal; 53 FloatPoint3D origin; 54 FloatRect boundingBox; 69 LayerShape shape; 55 70 Vector<GraphEdge*> incoming; 56 71 Vector<GraphEdge*> outgoing; … … 65 80 66 81 struct LayerIntersector { 67 LayerIntersector( GraphNode*, GraphNode*, float);82 LayerIntersector(const LayerShape&, const LayerShape&, float); 68 83 69 84 void go(); 70 85 71 float layerZFromProjectedPoint( GraphNode*, const FloatPoint&);86 float layerZFromProjectedPoint(const LayerShape&, const FloatPoint&); 72 87 bool triangleTriangleTest(const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&); 73 88 bool edgeTriangleTest(const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&); … … 75 90 76 91 FloatPoint intersectionPoint; 77 GraphNode* nodeA;78 GraphNode* nodeB;92 const LayerShape& layerA; 93 const LayerShape& layerB; 79 94 float zDiff; 80 95 float earlyExitThreshold; -
trunk/Source/WebKit/chromium/ChangeLog
r96322 r96337 1 2011-09-29 Iain Merrick <husky@google.com> 2 3 Add unit test for CCLayerSorter 4 https://bugs.webkit.org/show_bug.cgi?id=68622 5 6 Reviewed by James Robinson. 7 8 * WebKit.gypi: 9 * tests/CCLayerSorterTest.cpp: Added. 10 (WebCore::TEST): 11 1 12 2011-09-29 Hans Wennborg <hans@chromium.org> 2 13 -
trunk/Source/WebKit/chromium/WebKit.gypi
r94199 r96337 55 55 'tests/ArenaTestHelpers.h', 56 56 'tests/AssociatedURLLoaderTest.cpp', 57 'tests/CCLayerSorterTest.cpp', 57 58 'tests/CCLayerTreeHostTest.cpp', 58 59 'tests/CCThreadTaskTest.cpp',
Note: See TracChangeset
for help on using the changeset viewer.