Changeset 96337 in webkit


Ignore:
Timestamp:
Sep 29, 2011 10:05:41 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Add unit test for CCLayerSorter
https://bugs.webkit.org/show_bug.cgi?id=68622

Source/WebCore:

Minor refactoring for testability:

  • Made pointInTriangle public.
  • Added LayerShape to decouple LayerIntersector and GraphNode.
  • Added a public wrapper function for LayerIntersector.

Patch by Iain Merrick <husky@google.com> on 2011-09-29
Reviewed by James Robinson.

  • platform/graphics/chromium/cc/CCLayerSorter.cpp:

(WebCore::CCLayerSorter::pointInTriangle):
(WebCore::CCLayerSorter::calculateZDiff):
(WebCore::CCLayerSorter::LayerIntersector::LayerIntersector):
(WebCore::CCLayerSorter::LayerIntersector::go):
(WebCore::CCLayerSorter::LayerIntersector::checkZDiff):
(WebCore::CCLayerSorter::LayerIntersector::layerZFromProjectedPoint):
(WebCore::CCLayerSorter::checkOverlap):
(WebCore::CCLayerSorter::LayerShape::LayerShape):
(WebCore::CCLayerSorter::createGraphNodes):

  • platform/graphics/chromium/cc/CCLayerSorter.h:

(WebCore::CCLayerSorter::LayerShape::LayerShape):
(WebCore::CCLayerSorter::GraphNode::GraphNode):

Source/WebKit/chromium:

Patch by Iain Merrick <husky@google.com> on 2011-09-29
Reviewed by James Robinson.

  • WebKit.gypi:
  • tests/CCLayerSorterTest.cpp: Added.

(WebCore::TEST):

Location:
trunk/Source
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r96326 r96337  
     12011-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
    1272011-09-29  Ilya Tikhonovsky  <loislo@chromium.org>
    228
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerSorter.cpp

    r95901 r96337  
    4646namespace WebCore {
    4747
    48 static bool pointInTriangle(const FloatPoint& point,
    49                             const FloatPoint& a,
    50                             const FloatPoint& b,
    51                             const FloatPoint& c)
     48bool CCLayerSorter::pointInTriangle(const FloatPoint& point,
     49                                    const FloatPoint& a,
     50                                    const FloatPoint& b,
     51                                    const FloatPoint& c)
    5252{
    5353    // Algorithm from http://www.blackpawn.com/texts/pointinpoly/default.html
     
    144144}
    145145
    146 CCLayerSorter::LayerIntersector::LayerIntersector(GraphNode* nodeA, GraphNode* nodeB, float earlyExitThreshold)
    147     : nodeA(nodeA)
    148     , nodeB(nodeB)
     146float 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
     153CCLayerSorter::LayerIntersector::LayerIntersector(const LayerShape& layerA, const LayerShape& layerB, float earlyExitThreshold)
     154    : layerA(layerA)
     155    , layerB(layerB)
    149156    , zDiff(0)
    150157    , earlyExitThreshold(earlyExitThreshold)
     
    154161void CCLayerSorter::LayerIntersector::go()
    155162{
    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}
    162168
    163169// Checks if segment pq intersects any of the sides of triangle abc.
     
    205211bool CCLayerSorter::LayerIntersector::checkZDiff(const FloatPoint& p)
    206212{
    207     float za = layerZFromProjectedPoint(nodeA, p);
    208     float zb = layerZFromProjectedPoint(nodeB, p);
     213    float za = layerZFromProjectedPoint(layerA, p);
     214    float zb = layerZFromProjectedPoint(layerB, p);
    209215
    210216    float diff = za - zb;
     
    226232// intersection of a line starting from p along the Z axis and the plane
    227233// of the layer.
    228 float CCLayerSorter::LayerIntersector::layerZFromProjectedPoint(GraphNode* layer, const FloatPoint& p)
     234float CCLayerSorter::LayerIntersector::layerZFromProjectedPoint(const LayerShape& layer, const FloatPoint& p)
    229235{
    230236    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);
    235241
    236242    // Check if layer is parallel to the z = 0 axis
    237243    if (!d)
    238         return layer->origin.z();
     244        return layer.origin.z();
    239245
    240246    // The intersection point would be given by:
     
    244250}
    245251
    246 
    247252CCLayerSorter::CCLayerSorter()
    248253    : m_zRange(0)
     
    252257CCLayerSorter::ABCompareResult CCLayerSorter::checkOverlap(GraphNode* a, GraphNode* b)
    253258{
    254     if (!a->boundingBox.intersects(b->boundingBox))
     259    if (!a->shape.boundingBox.intersects(b->shape.boundingBox))
    255260        return None;
    256261
    257262    // Make the early exit threshold proportional to the total Z range.
    258263    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)
    264267        return BBeforeA;
    265     if (intersector.zDiff < 0)
     268    if (zDiff < 0)
    266269        return ABeforeB;
    267270
    268271    return None;
     272}
     273
     274CCLayerSorter::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);
    269283}
    270284
     
    303317        FloatPoint3D c3 = drawTransform.mapPoint(FloatPoint3D(layerWidth, -layerHeight, 0));
    304318        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);
    312320   
    313321        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  
    4343
    4444    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
    4562private:
    4663    struct GraphEdge;
    4764
    4865    struct GraphNode {
    49         GraphNode(CCLayerImpl* cclayer) : layer(cclayer) { };
     66        explicit GraphNode(CCLayerImpl* cclayer) : layer(cclayer) { }
     67
    5068        CCLayerImpl* layer;
    51         FloatPoint c1, c2, c3, c4;
    52         FloatPoint3D normal;
    53         FloatPoint3D origin;
    54         FloatRect boundingBox;
     69        LayerShape shape;
    5570        Vector<GraphEdge*> incoming;
    5671        Vector<GraphEdge*> outgoing;
     
    6580
    6681    struct LayerIntersector {
    67         LayerIntersector(GraphNode*, GraphNode*, float);
     82        LayerIntersector(const LayerShape&, const LayerShape&, float);
    6883
    6984        void go();
    7085
    71         float layerZFromProjectedPoint(GraphNode*, const FloatPoint&);
     86        float layerZFromProjectedPoint(const LayerShape&, const FloatPoint&);
    7287        bool triangleTriangleTest(const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&);
    7388        bool edgeTriangleTest(const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&, const FloatPoint&);
     
    7590
    7691        FloatPoint intersectionPoint;
    77         GraphNode* nodeA;
    78         GraphNode* nodeB;
     92        const LayerShape& layerA;
     93        const LayerShape& layerB;
    7994        float zDiff;
    8095        float earlyExitThreshold;
  • trunk/Source/WebKit/chromium/ChangeLog

    r96322 r96337  
     12011-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
    1122011-09-29  Hans Wennborg  <hans@chromium.org>
    213
  • trunk/Source/WebKit/chromium/WebKit.gypi

    r94199 r96337  
    5555            'tests/ArenaTestHelpers.h',
    5656            'tests/AssociatedURLLoaderTest.cpp',
     57            'tests/CCLayerSorterTest.cpp',
    5758            'tests/CCLayerTreeHostTest.cpp',
    5859            'tests/CCThreadTaskTest.cpp',
Note: See TracChangeset for help on using the changeset viewer.