OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef sk_tool_utils_DEFINED | 8 #ifndef sk_tool_utils_DEFINED |
9 #define sk_tool_utils_DEFINED | 9 #define sk_tool_utils_DEFINED |
10 | 10 |
11 #include "SkColor.h" | 11 #include "SkColor.h" |
12 #include "SkImageEncoder.h" | 12 #include "SkImageEncoder.h" |
13 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
14 #include "SkPixelSerializer.h" | 14 #include "SkPixelSerializer.h" |
| 15 #include "SkRandom.h" |
| 16 #include "SkTDArray.h" |
15 #include "SkTypeface.h" | 17 #include "SkTypeface.h" |
16 | 18 |
17 class SkBitmap; | 19 class SkBitmap; |
18 class SkCanvas; | 20 class SkCanvas; |
19 class SkPaint; | 21 class SkPaint; |
20 class SkPath; | 22 class SkPath; |
21 class SkShader; | 23 class SkShader; |
22 class SkTestFont; | 24 class SkTestFont; |
23 class SkTextBlobBuilder; | 25 class SkTextBlobBuilder; |
24 | 26 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 void create_frustum_normal_map(SkBitmap* bm, const SkIRect& dst); | 135 void create_frustum_normal_map(SkBitmap* bm, const SkIRect& dst); |
134 | 136 |
135 void create_tetra_normal_map(SkBitmap* bm, const SkIRect& dst); | 137 void create_tetra_normal_map(SkBitmap* bm, const SkIRect& dst); |
136 | 138 |
137 void make_big_path(SkPath& path); | 139 void make_big_path(SkPath& path); |
138 | 140 |
139 // Return a blurred version of 'src'. This doesn't use a separable filter | 141 // Return a blurred version of 'src'. This doesn't use a separable filter |
140 // so it is slow! | 142 // so it is slow! |
141 SkBitmap slow_blur(const SkBitmap& src, float sigma); | 143 SkBitmap slow_blur(const SkBitmap& src, float sigma); |
142 | 144 |
| 145 // A helper object to test the topological sorting code (TopoSortBench.cpp &
TopoSortTest.cpp) |
| 146 class TopoTestNode { |
| 147 public: |
| 148 TopoTestNode(int id) : fID(id), fOutputPos(-1), fTempMark(false) { } |
| 149 |
| 150 void dependsOn(TopoTestNode* src) { |
| 151 *fDependencies.append() = src; |
| 152 } |
| 153 |
| 154 int id() const { return fID; } |
| 155 void reset() { fOutputPos = -1; } |
| 156 |
| 157 int outputPos() const { return fOutputPos; } |
| 158 |
| 159 // check that the topological sort is valid for this node |
| 160 bool check() { |
| 161 if (-1 == fOutputPos) { |
| 162 return false; |
| 163 } |
| 164 |
| 165 for (int i = 0; i < fDependencies.count(); ++i) { |
| 166 if (-1 == fDependencies[i]->outputPos()) { |
| 167 return false; |
| 168 } |
| 169 // This node should've been output after all the nodes on which
it depends |
| 170 if (fOutputPos < fDependencies[i]->outputPos()) { |
| 171 return false; |
| 172 } |
| 173 } |
| 174 |
| 175 return true; |
| 176 } |
| 177 |
| 178 // The following 7 methods are needed by the topological sort |
| 179 static void SetTempMark(TopoTestNode* node) { node->fTempMark = true; } |
| 180 static void ResetTempMark(TopoTestNode* node) { node->fTempMark = false;
} |
| 181 static bool IsTempMarked(TopoTestNode* node) { return node->fTempMark; } |
| 182 static void Output(TopoTestNode* node, int outputPos) { |
| 183 SkASSERT(-1 != outputPos); |
| 184 node->fOutputPos = outputPos; |
| 185 } |
| 186 static bool WasOutput(TopoTestNode* node) { return (-1 != node->fOutputP
os); } |
| 187 static int NumDependencies(TopoTestNode* node) { return node->fDependenc
ies.count(); } |
| 188 static TopoTestNode* Dependency(TopoTestNode* node, int index) { |
| 189 return node->fDependencies[index]; |
| 190 } |
| 191 |
| 192 // Helper functions for TopoSortBench & TopoSortTest |
| 193 static void AllocNodes(SkTDArray<TopoTestNode*>* graph, int num) { |
| 194 graph->setReserve(num); |
| 195 |
| 196 for (int i = 0; i < num; ++i) { |
| 197 *graph->append() = new TopoTestNode(i); |
| 198 } |
| 199 } |
| 200 |
| 201 static void DeallocNodes(SkTDArray<TopoTestNode*>* graph) { |
| 202 for (int i = 0; i < graph->count(); ++i) { |
| 203 delete (*graph)[i]; |
| 204 } |
| 205 } |
| 206 |
| 207 #ifdef SK_DEBUG |
| 208 static void Print(const SkTDArray<TopoTestNode*>& graph) { |
| 209 for (int i = 0; i < graph.count(); ++i) { |
| 210 SkDebugf("%d, ", graph[i]->id()); |
| 211 } |
| 212 SkDebugf("\n"); |
| 213 } |
| 214 #endif |
| 215 |
| 216 // randomize the array |
| 217 static void Shuffle(SkTDArray<TopoTestNode*>* graph, SkRandom* rand) { |
| 218 for (int i = graph->count()-1; i > 0; --i) { |
| 219 int swap = rand->nextU() % (i+1); |
| 220 |
| 221 TopoTestNode* tmp = (*graph)[i]; |
| 222 (*graph)[i] = (*graph)[swap]; |
| 223 (*graph)[swap] = tmp; |
| 224 } |
| 225 } |
| 226 |
| 227 private: |
| 228 int fID; |
| 229 int fOutputPos; |
| 230 bool fTempMark; |
| 231 |
| 232 SkTDArray<TopoTestNode*> fDependencies; |
| 233 }; |
| 234 |
143 } // namespace sk_tool_utils | 235 } // namespace sk_tool_utils |
144 | 236 |
145 #endif // sk_tool_utils_DEFINED | 237 #endif // sk_tool_utils_DEFINED |
OLD | NEW |