Home | History | Annotate | Download | only in Intersection
      1 /*
      2  * Copyright 2012 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 #include "EdgeWalker_Test.h"
      8 #include "Intersection_Tests.h"
      9 #include "ShapeOps.h"
     10 
     11 // four rects, of four sizes
     12 // for 3 smaller sizes, tall, wide
     13     // top upper mid lower bottom aligned (3 bits, 5 values)
     14     // same with x (3 bits, 5 values)
     15 // not included, square, tall, wide (2 bits)
     16 // cw or ccw (1 bit)
     17 
     18 static void* testSimplify4x4RectsMain(void* data)
     19 {
     20     SkASSERT(data);
     21     State4& state = *(State4*) data;
     22     char pathStr[1024]; // gdb: set print elements 400
     23     bzero(pathStr, sizeof(pathStr));
     24     do {
     25         int aShape = state.a & 0x03;
     26         SkPath::Direction aCW = state.a >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
     27         int bShape = state.b & 0x03;
     28         SkPath::Direction bCW = state.b >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
     29         int cShape = state.c & 0x03;
     30         SkPath::Direction cCW = state.c >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
     31         int dShape = state.d & 0x03;
     32         SkPath::Direction dCW = state.d >> 2 ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
     33         for (int aXAlign = 0 ; aXAlign < 5; ++aXAlign) {
     34         for (int aYAlign = 0 ; aYAlign < 5; ++aYAlign)      {
     35         for (int bXAlign = 0 ; bXAlign < 5; ++bXAlign)          {
     36         for (int bYAlign = 0 ; bYAlign < 5; ++bYAlign)              {
     37         for (int cXAlign = 0 ; cXAlign < 5; ++cXAlign)                  {
     38         for (int cYAlign = 0 ; cYAlign < 5; ++cYAlign)                      {
     39         for (int dXAlign = 0 ; dXAlign < 5; ++dXAlign)                          {
     40         for (int dYAlign = 0 ; dYAlign < 5; ++dYAlign)                              {
     41             SkPath path, out;
     42             char* str = pathStr;
     43             path.setFillType(SkPath::kWinding_FillType);
     44             int l, t, r, b;
     45             if (aShape) {
     46                 switch (aShape) {
     47                     case 1: // square
     48                         l =  0; r = 60;
     49                         t =  0; b = 60;
     50                         aXAlign = 5;
     51                         aYAlign = 5;
     52                         break;
     53                     case 2:
     54                         l =  aXAlign * 12;
     55                         r =  l + 30;
     56                         t =  0; b = 60;
     57                         aYAlign = 5;
     58                         break;
     59                     case 3:
     60                         l =  0; r = 60;
     61                         t =  aYAlign * 12;
     62                         b =  l + 30;
     63                         aXAlign = 5;
     64                         break;
     65                 }
     66                 path.addRect(l, t, r, b, aCW);
     67                 str += sprintf(str, "    path.addRect(%d, %d, %d, %d,"
     68                         " SkPath::kC%sW_Direction);\n", l, t, r, b, aCW ? "C" : "");
     69             } else {
     70                 aXAlign = 5;
     71                 aYAlign = 5;
     72             }
     73             if (bShape) {
     74                 switch (bShape) {
     75                     case 1: // square
     76                         l =  bXAlign * 10;
     77                         r =  l + 20;
     78                         t =  bYAlign * 10;
     79                         b =  l + 20;
     80                         break;
     81                     case 2:
     82                         l =  bXAlign * 10;
     83                         r =  l + 20;
     84                         t =  10; b = 40;
     85                         bYAlign = 5;
     86                         break;
     87                     case 3:
     88                         l =  10; r = 40;
     89                         t =  bYAlign * 10;
     90                         b =  l + 20;
     91                         bXAlign = 5;
     92                         break;
     93                 }
     94                 path.addRect(l, t, r, b, bCW);
     95                 str += sprintf(str, "    path.addRect(%d, %d, %d, %d,"
     96                         " SkPath::kC%sW_Direction);\n", l, t, r, b, bCW ? "C" : "");
     97             } else {
     98                 bXAlign = 5;
     99                 bYAlign = 5;
    100             }
    101             if (cShape) {
    102                 switch (cShape) {
    103                     case 1: // square
    104                         l =  cXAlign * 6;
    105                         r =  l + 12;
    106                         t =  cYAlign * 6;
    107                         b =  l + 12;
    108                         break;
    109                     case 2:
    110                         l =  cXAlign * 6;
    111                         r =  l + 12;
    112                         t =  20; b = 30;
    113                         cYAlign = 5;
    114                         break;
    115                     case 3:
    116                         l =  20; r = 30;
    117                         t =  cYAlign * 6;
    118                         b =  l + 20;
    119                         cXAlign = 5;
    120                         break;
    121                 }
    122                 path.addRect(l, t, r, b, cCW);
    123                 str += sprintf(str, "    path.addRect(%d, %d, %d, %d,"
    124                         " SkPath::kC%sW_Direction);\n", l, t, r, b, cCW ? "C" : "");
    125             } else {
    126                 cXAlign = 5;
    127                 cYAlign = 5;
    128             }
    129             if (dShape) {
    130                 switch (dShape) {
    131                     case 1: // square
    132                         l =  dXAlign * 4;
    133                         r =  l + 9;
    134                         t =  dYAlign * 4;
    135                         b =  l + 9;
    136                         break;
    137                     case 2:
    138                         l =  dXAlign * 6;
    139                         r =  l + 9;
    140                         t =  32; b = 36;
    141                         dYAlign = 5;
    142                         break;
    143                     case 3:
    144                         l =  32; r = 36;
    145                         t =  dYAlign * 6;
    146                         b =  l + 9;
    147                         dXAlign = 5;
    148                         break;
    149                 }
    150                 path.addRect(l, t, r, b, dCW);
    151                 str += sprintf(str, "    path.addRect(%d, %d, %d, %d,"
    152                         " SkPath::kC%sW_Direction);\n", l, t, r, b, dCW ? "C" : "");
    153             } else {
    154                 dXAlign = 5;
    155                 dYAlign = 5;
    156             }
    157             path.close();
    158             outputProgress(state, pathStr, SkPath::kWinding_FillType);
    159             testSimplifyx(path, false, out, state, pathStr);
    160             state.testsRun++;
    161             outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
    162             testSimplifyx(path, true, out, state, pathStr);
    163             state.testsRun++;
    164                                     }
    165                                 }
    166                             }
    167                         }
    168                     }
    169                 }
    170             }
    171         }
    172     } while (runNextTestSet(state));
    173     return NULL;
    174 }
    175 
    176 void Simplify4x4RectsThreaded_Test(int& testsRun)
    177 {
    178     SkDebugf("%s\n", __FUNCTION__);
    179 #ifdef SK_DEBUG
    180     gDebugMaxWindSum = 4;
    181     gDebugMaxWindValue = 4;
    182 #endif
    183     const char testLineStr[] = "testLine";
    184     initializeTests(testLineStr, sizeof(testLineStr));
    185     int testsStart = testsRun;
    186     for (int a = 0; a < 8; ++a) { // outermost
    187         for (int b = a ; b < 8; ++b) {
    188             for (int c = b ; c < 8; ++c) {
    189                 for (int d = c; d < 8; ++d) {
    190                     testsRun += dispatchTest4(testSimplify4x4RectsMain, a, b, c, d);
    191                 }
    192                 if (!gRunTestsInOneThread) SkDebugf(".");
    193             }
    194             if (!gRunTestsInOneThread) SkDebugf("%d", b);
    195         }
    196         if (!gRunTestsInOneThread) SkDebugf("\n%d", a);
    197     }
    198     testsRun += waitForCompletion();
    199     SkDebugf("%s tests=%d total=%d\n", __FUNCTION__, testsRun - testsStart, testsRun);
    200 }
    201