caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 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 | #include "SkBitmap.h" |
| 11 | #include "SkCanvas.h" |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 12 | #include "SkStream.h" |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | #include <pthread.h> |
| 15 | |
| 16 | // four rects, of four sizes |
| 17 | // for 3 smaller sizes, tall, wide |
| 18 | // top upper mid lower bottom aligned (3 bits, 5 values) |
| 19 | // same with x (3 bits, 5 values) |
| 20 | // not included, square, tall, wide (2 bits) |
| 21 | // cw or ccw (1 bit) |
| 22 | |
| 23 | static void* testSimplify4x4RectsMain(void* data) |
| 24 | { |
| 25 | char pathStr[1024]; // gdb: set print elements 400 |
| 26 | bzero(pathStr, sizeof(pathStr)); |
| 27 | SkASSERT(data); |
| 28 | State4& state = *(State4*) data; |
| 29 | int aShape = state.a & 0x03; |
| 30 | int aCW = state.a >> 1; |
| 31 | int bShape = state.b & 0x03; |
| 32 | int bCW = state.b >> 1; |
| 33 | int cShape = state.c & 0x03; |
| 34 | int cCW = state.c >> 1; |
| 35 | int dShape = state.d & 0x03; |
| 36 | int dCW = state.d >> 1; |
| 37 | for (int aXAlign = 0 ; aXAlign < 5; ++aXAlign) { |
| 38 | for (int aYAlign = 0 ; aYAlign < 5; ++aYAlign) { |
| 39 | for (int bXAlign = 0 ; bXAlign < 5; ++bXAlign) { |
| 40 | for (int bYAlign = 0 ; bYAlign < 5; ++bYAlign) { |
| 41 | for (int cXAlign = 0 ; cXAlign < 5; ++cXAlign) { |
| 42 | for (int cYAlign = 0 ; cYAlign < 5; ++cYAlign) { |
| 43 | for (int dXAlign = 0 ; dXAlign < 5; ++dXAlign) { |
| 44 | for (int dYAlign = 0 ; dYAlign < 5; ++dYAlign) { |
| 45 | SkPath path, out; |
| 46 | char* str = pathStr; |
| 47 | path.setFillType(SkPath::kWinding_FillType); |
| 48 | int l, t, r, b; |
| 49 | if (aShape) { |
| 50 | switch (aShape) { |
| 51 | case 1: // square |
| 52 | l = 0; r = 60; |
| 53 | t = 0; b = 60; |
| 54 | aXAlign = 5; |
| 55 | aYAlign = 5; |
| 56 | break; |
| 57 | case 2: |
| 58 | l = aXAlign * 12; |
| 59 | r = l + 30; |
| 60 | t = 0; b = 60; |
| 61 | aYAlign = 5; |
| 62 | break; |
| 63 | case 3: |
| 64 | l = 0; r = 60; |
| 65 | t = aYAlign * 12; |
| 66 | b = l + 30; |
| 67 | aXAlign = 5; |
| 68 | break; |
| 69 | } |
| 70 | path.addRect(l, t, r, b, (SkPath::Direction) aCW); |
| 71 | str += sprintf(str, " path.addRect(%d, %d, %d, %d," |
| 72 | " (SkPath::Direction) %d);\n", l, t, r, b, aCW); |
| 73 | } else { |
| 74 | aXAlign = 5; |
| 75 | aYAlign = 5; |
| 76 | } |
| 77 | if (bShape) { |
| 78 | switch (bShape) { |
| 79 | case 1: // square |
| 80 | l = bXAlign * 10; |
| 81 | r = l + 20; |
| 82 | t = bYAlign * 10; |
| 83 | b = l + 20; |
| 84 | break; |
| 85 | case 2: |
| 86 | l = bXAlign * 10; |
| 87 | r = l + 20; |
| 88 | t = 10; b = 40; |
| 89 | bYAlign = 5; |
| 90 | break; |
| 91 | case 3: |
| 92 | l = 10; r = 40; |
| 93 | t = bYAlign * 10; |
| 94 | b = l + 20; |
| 95 | bXAlign = 5; |
| 96 | break; |
| 97 | } |
| 98 | path.addRect(l, t, r, b, (SkPath::Direction) bCW); |
| 99 | str += sprintf(str, " path.addRect(%d, %d, %d, %d," |
| 100 | " (SkPath::Direction) %d);\n", l, t, r, b, bCW); |
| 101 | } else { |
| 102 | bXAlign = 5; |
| 103 | bYAlign = 5; |
| 104 | } |
| 105 | if (cShape) { |
| 106 | switch (cShape) { |
| 107 | case 1: // square |
| 108 | l = cXAlign * 6; |
| 109 | r = l + 12; |
| 110 | t = cYAlign * 6; |
| 111 | b = l + 12; |
| 112 | break; |
| 113 | case 2: |
| 114 | l = cXAlign * 6; |
| 115 | r = l + 12; |
| 116 | t = 20; b = 30; |
| 117 | cYAlign = 5; |
| 118 | break; |
| 119 | case 3: |
| 120 | l = 20; r = 30; |
| 121 | t = cYAlign * 6; |
| 122 | b = l + 20; |
| 123 | cXAlign = 5; |
| 124 | break; |
| 125 | } |
| 126 | path.addRect(l, t, r, b, (SkPath::Direction) cCW); |
| 127 | str += sprintf(str, " path.addRect(%d, %d, %d, %d," |
| 128 | " (SkPath::Direction) %d);\n", l, t, r, b, cCW); |
| 129 | } else { |
| 130 | cXAlign = 5; |
| 131 | cYAlign = 5; |
| 132 | } |
| 133 | if (dShape) { |
| 134 | switch (dShape) { |
| 135 | case 1: // square |
| 136 | l = dXAlign * 4; |
| 137 | r = l + 9; |
| 138 | t = dYAlign * 4; |
| 139 | b = l + 9; |
| 140 | break; |
| 141 | case 2: |
| 142 | l = dXAlign * 6; |
| 143 | r = l + 9; |
| 144 | t = 32; b = 36; |
| 145 | dYAlign = 5; |
| 146 | break; |
| 147 | case 3: |
| 148 | l = 32; r = 36; |
| 149 | t = dYAlign * 6; |
| 150 | b = l + 9; |
| 151 | dXAlign = 5; |
| 152 | break; |
| 153 | } |
| 154 | path.addRect(l, t, r, b, (SkPath::Direction) dCW); |
| 155 | str += sprintf(str, " path.addRect(%d, %d, %d, %d," |
| 156 | " (SkPath::Direction) %d);\n", l, t, r, b, dCW); |
| 157 | } else { |
| 158 | dXAlign = 5; |
| 159 | dYAlign = 5; |
| 160 | } |
| 161 | path.close(); |
| 162 | SkDebugf("%s", pathStr); |
| 163 | if (!testSimplifyx(path, out, state.bitmap, state.canvas)) { |
| 164 | SkDebugf("*/\n{ %s %d, %d, %d, %d, %d, %d, %d, %d," |
| 165 | " %d, %d, %d, %d },\n/*\n", |
| 166 | __FUNCTION__, state.a, state.b, state.c, state.d, |
| 167 | aXAlign, aYAlign, bXAlign, bYAlign, |
| 168 | cXAlign, cYAlign, dXAlign, dYAlign); |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 169 | SkFILEStream inFile("../../experimental/Intersection/op.htm"); |
| 170 | if (!inFile.isValid()) { |
| 171 | continue; |
| 172 | } |
| 173 | SkTDArray<char> inData; |
| 174 | inData.setCount(inFile.getLength()); |
| 175 | size_t inLen = inData.count(); |
| 176 | inFile.read(inData.begin(), inLen); |
| 177 | inFile.setPath(NULL); |
| 178 | SkFILEWStream outFile("../../experimental/Intersection/xop.htm"); |
| 179 | if (!outFile.isValid()) { |
| 180 | continue; |
| 181 | } |
| 182 | const char marker[] = |
| 183 | "</div>\n" |
| 184 | "\n" |
| 185 | "<script type=\"text/javascript\">\n" |
| 186 | "\n" |
| 187 | "var testDivs = [\n"; |
| 188 | const char testLineStr[] = " testLine"; |
| 189 | char* insert = strstr(inData.begin(), marker); |
| 190 | if (!insert) { |
| 191 | continue; |
| 192 | } |
| 193 | size_t startLen = insert - inData.begin(); |
| 194 | insert += sizeof(marker); |
| 195 | const char* numLoc = insert + sizeof(testLineStr); |
| 196 | int testNumber = atoi(numLoc) + 1; |
| 197 | outFile.write(inData.begin(), startLen); |
| 198 | outFile.writeText("<div id=\"testLine"); |
| 199 | outFile.writeDecAsText(testNumber); |
| 200 | outFile.writeText("\">\n"); |
| 201 | outFile.writeText(pathStr); |
| 202 | outFile.writeText("</div>\n\n"); |
| 203 | outFile.writeText(marker); |
| 204 | outFile.writeText(testLineStr); |
| 205 | outFile.writeDecAsText(testNumber); |
| 206 | outFile.writeText(",\n"); |
| 207 | outFile.write(insert, inLen - startLen - sizeof(marker)); |
| 208 | outFile.flush(); |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | return NULL; |
| 219 | } |
| 220 | |
| 221 | const int maxThreads = 1; // gRunTestsInOneThread ? 1 : 24; |
| 222 | |
| 223 | void Simplify4x4RectsThreaded_Test() |
| 224 | { |
| 225 | State4 threadState[maxThreads]; |
| 226 | int threadIndex = 0; |
| 227 | for (int a = 0; a < 8; ++a) { // outermost |
| 228 | for (int b = a ; b < 8; ++b) { |
| 229 | for (int c = b ; c < 8; ++c) { |
| 230 | for (int d = c; d < 8; ++d) { |
| 231 | State4* statePtr = &threadState[threadIndex]; |
| 232 | statePtr->a = a; |
| 233 | statePtr->b = b; |
| 234 | statePtr->c = c; |
| 235 | statePtr->d = d; |
| 236 | if (maxThreads > 1) { |
| 237 | createThread(statePtr, testSimplify4x4RectsMain); |
| 238 | if (++threadIndex >= maxThreads) { |
| 239 | waitForCompletion(threadState, threadIndex); |
| 240 | } |
| 241 | } else { |
| 242 | testSimplify4x4RectsMain(statePtr); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | waitForCompletion(threadState, threadIndex); |
| 249 | } |
| 250 | |