Home | History | Annotate | Download | only in tests
      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 "PathOpsExtendedTest.h"
      8 #include "PathOpsThreadedCommon.h"
      9 #include "SkString.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 int loopNo = 6;
     19 
     20 static void testPathOpsRectsMain(PathOpsThreadState* data)
     21 {
     22     SkASSERT(data);
     23     PathOpsThreadState& state = *data;
     24     SkString pathStr;
     25     for (int a = 0 ; a < 6; ++a) {
     26         for (int b = a + 1 ; b < 7; ++b) {
     27             for (int c = 0 ; c < 6; ++c) {
     28                 for (int d = c + 1 ; d < 7; ++d) {
     29                     for (int e = SkPath::kWinding_FillType ; e <= SkPath::kEvenOdd_FillType; ++e) {
     30     for (int f = SkPath::kWinding_FillType ; f <= SkPath::kEvenOdd_FillType; ++f)   {
     31         SkPath pathA, pathB;
     32         pathA.setFillType((SkPath::FillType) e);
     33         pathA.addRect(SkIntToScalar(state.fA), SkIntToScalar(state.fA), SkIntToScalar(state.fB),
     34                 SkIntToScalar(state.fB), SkPath::kCW_Direction);
     35         pathA.addRect(SkIntToScalar(state.fC), SkIntToScalar(state.fC), SkIntToScalar(state.fD),
     36                 SkIntToScalar(state.fD), SkPath::kCW_Direction);
     37         pathA.close();
     38         pathB.setFillType((SkPath::FillType) f);
     39         pathB.addRect(SkIntToScalar(a), SkIntToScalar(a), SkIntToScalar(b),
     40                 SkIntToScalar(b), SkPath::kCW_Direction);
     41         pathB.addRect(SkIntToScalar(c), SkIntToScalar(c), SkIntToScalar(d),
     42                 SkIntToScalar(d), SkPath::kCW_Direction);
     43         pathB.close();
     44         for (int op = 0 ; op <= kXOR_SkPathOp; ++op)    {
     45             if (state.fReporter->verbose()) {
     46                 pathStr.printf(
     47                         "static void rects%d(skiatest::Reporter* reporter,"
     48                         "const char* filename) {\n", loopNo);
     49                 pathStr.appendf("    SkPath path, pathB;");
     50                 pathStr.appendf("    path.setFillType(SkPath::k%s_FillType);\n",
     51                         e == SkPath::kWinding_FillType ? "Winding" : e == SkPath::kEvenOdd_FillType
     52                         ? "EvenOdd" : "?UNDEFINED");
     53                 pathStr.appendf("    path.addRect(%d, %d, %d, %d,"
     54                         " SkPath::kCW_Direction);\n", state.fA, state.fA, state.fB, state.fB);
     55                 pathStr.appendf("    path.addRect(%d, %d, %d, %d,"
     56                         " SkPath::kCW_Direction);\n", state.fC, state.fC, state.fD, state.fD);
     57                 pathStr.appendf("    pathB.setFillType(SkPath::k%s_FillType);\n",
     58                         f == SkPath::kWinding_FillType ? "Winding" : f == SkPath::kEvenOdd_FillType
     59                         ? "EvenOdd" : "?UNDEFINED");
     60                 pathStr.appendf("    pathB.addRect(%d, %d, %d, %d,"
     61                         " SkPath::kCW_Direction);\n", a, a, b, b);
     62                 pathStr.appendf("    pathB.addRect(%d, %d, %d, %d,"
     63                         " SkPath::kCW_Direction);\n", c, c, d, d);
     64                 pathStr.appendf("    testPathOp(reporter, path, pathB, %s, filename);\n",
     65                         SkPathOpsDebug::OpStr((SkPathOp) op));
     66                 pathStr.appendf("}\n\n");
     67                 state.outputProgress(pathStr.c_str(), (SkPathOp) op);
     68             }
     69             if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "rects")) {
     70                 if (state.fReporter->verbose()) {
     71                     ++loopNo;
     72                     goto skipToNext;
     73                 }
     74             }
     75         }
     76     }
     77                     }
     78 skipToNext: ;
     79                 }
     80             }
     81         }
     82     }
     83 }
     84 
     85 DEF_TEST(PathOpsRectsThreaded, reporter) {
     86     initializeTests(reporter, "testOp");
     87     PathOpsThreadedTestRunner testRunner(reporter);
     88     for (int a = 0; a < 6; ++a) {  // outermost
     89         for (int b = a + 1; b < 7; ++b) {
     90             for (int c = 0 ; c < 6; ++c) {
     91                 for (int d = c + 1; d < 7; ++d) {
     92                     *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
     93                             &testPathOpsRectsMain, a, b, c, d, &testRunner);
     94                 }
     95             }
     96             if (!reporter->allowExtendedTest()) goto finish;
     97        }
     98     }
     99 finish:
    100     testRunner.render();
    101 }
    102