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" |
| 12 | #include <assert.h> |
| 13 | #include <pthread.h> |
| 14 | |
| 15 | // four rects, of four sizes |
| 16 | // for 3 smaller sizes, tall, wide |
| 17 | // top upper mid lower bottom aligned (3 bits, 5 values) |
| 18 | // same with x (3 bits, 5 values) |
| 19 | // not included, square, tall, wide (2 bits) |
| 20 | // cw or ccw (1 bit) |
| 21 | |
| 22 | static void* testSimplify4x4RectsMain(void* data) |
| 23 | { |
| 24 | char pathStr[1024]; // gdb: set print elements 400 |
| 25 | bzero(pathStr, sizeof(pathStr)); |
| 26 | SkASSERT(data); |
| 27 | State4& state = *(State4*) data; |
| 28 | int aShape = state.a & 0x03; |
| 29 | int aCW = state.a >> 1; |
| 30 | int bShape = state.b & 0x03; |
| 31 | int bCW = state.b >> 1; |
| 32 | int cShape = state.c & 0x03; |
| 33 | int cCW = state.c >> 1; |
| 34 | int dShape = state.d & 0x03; |
| 35 | int dCW = state.d >> 1; |
| 36 | for (int aXAlign = 0 ; aXAlign < 5; ++aXAlign) { |
| 37 | for (int aYAlign = 0 ; aYAlign < 5; ++aYAlign) { |
| 38 | for (int bXAlign = 0 ; bXAlign < 5; ++bXAlign) { |
| 39 | for (int bYAlign = 0 ; bYAlign < 5; ++bYAlign) { |
| 40 | for (int cXAlign = 0 ; cXAlign < 5; ++cXAlign) { |
| 41 | for (int cYAlign = 0 ; cYAlign < 5; ++cYAlign) { |
| 42 | for (int dXAlign = 0 ; dXAlign < 5; ++dXAlign) { |
| 43 | for (int dYAlign = 0 ; dYAlign < 5; ++dYAlign) { |
| 44 | SkPath path, out; |
| 45 | char* str = pathStr; |
| 46 | path.setFillType(SkPath::kWinding_FillType); |
| 47 | int l, t, r, b; |
| 48 | if (aShape) { |
| 49 | switch (aShape) { |
| 50 | case 1: // square |
| 51 | l = 0; r = 60; |
| 52 | t = 0; b = 60; |
| 53 | aXAlign = 5; |
| 54 | aYAlign = 5; |
| 55 | break; |
| 56 | case 2: |
| 57 | l = aXAlign * 12; |
| 58 | r = l + 30; |
| 59 | t = 0; b = 60; |
| 60 | aYAlign = 5; |
| 61 | break; |
| 62 | case 3: |
| 63 | l = 0; r = 60; |
| 64 | t = aYAlign * 12; |
| 65 | b = l + 30; |
| 66 | aXAlign = 5; |
| 67 | break; |
| 68 | } |
| 69 | path.addRect(l, t, r, b, (SkPath::Direction) aCW); |
| 70 | str += sprintf(str, " path.addRect(%d, %d, %d, %d," |
| 71 | " (SkPath::Direction) %d);\n", l, t, r, b, aCW); |
| 72 | } else { |
| 73 | aXAlign = 5; |
| 74 | aYAlign = 5; |
| 75 | } |
| 76 | if (bShape) { |
| 77 | switch (bShape) { |
| 78 | case 1: // square |
| 79 | l = bXAlign * 10; |
| 80 | r = l + 20; |
| 81 | t = bYAlign * 10; |
| 82 | b = l + 20; |
| 83 | break; |
| 84 | case 2: |
| 85 | l = bXAlign * 10; |
| 86 | r = l + 20; |
| 87 | t = 10; b = 40; |
| 88 | bYAlign = 5; |
| 89 | break; |
| 90 | case 3: |
| 91 | l = 10; r = 40; |
| 92 | t = bYAlign * 10; |
| 93 | b = l + 20; |
| 94 | bXAlign = 5; |
| 95 | break; |
| 96 | } |
| 97 | path.addRect(l, t, r, b, (SkPath::Direction) bCW); |
| 98 | str += sprintf(str, " path.addRect(%d, %d, %d, %d," |
| 99 | " (SkPath::Direction) %d);\n", l, t, r, b, bCW); |
| 100 | } else { |
| 101 | bXAlign = 5; |
| 102 | bYAlign = 5; |
| 103 | } |
| 104 | if (cShape) { |
| 105 | switch (cShape) { |
| 106 | case 1: // square |
| 107 | l = cXAlign * 6; |
| 108 | r = l + 12; |
| 109 | t = cYAlign * 6; |
| 110 | b = l + 12; |
| 111 | break; |
| 112 | case 2: |
| 113 | l = cXAlign * 6; |
| 114 | r = l + 12; |
| 115 | t = 20; b = 30; |
| 116 | cYAlign = 5; |
| 117 | break; |
| 118 | case 3: |
| 119 | l = 20; r = 30; |
| 120 | t = cYAlign * 6; |
| 121 | b = l + 20; |
| 122 | cXAlign = 5; |
| 123 | break; |
| 124 | } |
| 125 | path.addRect(l, t, r, b, (SkPath::Direction) cCW); |
| 126 | str += sprintf(str, " path.addRect(%d, %d, %d, %d," |
| 127 | " (SkPath::Direction) %d);\n", l, t, r, b, cCW); |
| 128 | } else { |
| 129 | cXAlign = 5; |
| 130 | cYAlign = 5; |
| 131 | } |
| 132 | if (dShape) { |
| 133 | switch (dShape) { |
| 134 | case 1: // square |
| 135 | l = dXAlign * 4; |
| 136 | r = l + 9; |
| 137 | t = dYAlign * 4; |
| 138 | b = l + 9; |
| 139 | break; |
| 140 | case 2: |
| 141 | l = dXAlign * 6; |
| 142 | r = l + 9; |
| 143 | t = 32; b = 36; |
| 144 | dYAlign = 5; |
| 145 | break; |
| 146 | case 3: |
| 147 | l = 32; r = 36; |
| 148 | t = dYAlign * 6; |
| 149 | b = l + 9; |
| 150 | dXAlign = 5; |
| 151 | break; |
| 152 | } |
| 153 | path.addRect(l, t, r, b, (SkPath::Direction) dCW); |
| 154 | str += sprintf(str, " path.addRect(%d, %d, %d, %d," |
| 155 | " (SkPath::Direction) %d);\n", l, t, r, b, dCW); |
| 156 | } else { |
| 157 | dXAlign = 5; |
| 158 | dYAlign = 5; |
| 159 | } |
| 160 | path.close(); |
| 161 | SkDebugf("%s", pathStr); |
| 162 | if (!testSimplifyx(path, out, state.bitmap, state.canvas)) { |
| 163 | SkDebugf("*/\n{ %s %d, %d, %d, %d, %d, %d, %d, %d," |
| 164 | " %d, %d, %d, %d },\n/*\n", |
| 165 | __FUNCTION__, state.a, state.b, state.c, state.d, |
| 166 | aXAlign, aYAlign, bXAlign, bYAlign, |
| 167 | cXAlign, cYAlign, dXAlign, dYAlign); |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | return NULL; |
| 178 | } |
| 179 | |
| 180 | const int maxThreads = 1; // gRunTestsInOneThread ? 1 : 24; |
| 181 | |
| 182 | void Simplify4x4RectsThreaded_Test() |
| 183 | { |
| 184 | State4 threadState[maxThreads]; |
| 185 | int threadIndex = 0; |
| 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 | State4* statePtr = &threadState[threadIndex]; |
| 191 | statePtr->a = a; |
| 192 | statePtr->b = b; |
| 193 | statePtr->c = c; |
| 194 | statePtr->d = d; |
| 195 | if (maxThreads > 1) { |
| 196 | createThread(statePtr, testSimplify4x4RectsMain); |
| 197 | if (++threadIndex >= maxThreads) { |
| 198 | waitForCompletion(threadState, threadIndex); |
| 199 | } |
| 200 | } else { |
| 201 | testSimplify4x4RectsMain(statePtr); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | waitForCompletion(threadState, threadIndex); |
| 208 | } |
| 209 | |