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 #include "SkOpEdgeBuilder.h" | 7 #include "SkOpEdgeBuilder.h" |
8 #include "SkPathOpsCommon.h" | 8 #include "SkPathOpsCommon.h" |
9 | 9 |
10 bool TightBounds(const SkPath& path, SkRect* result) { | 10 bool TightBounds(const SkPath& path, SkRect* result) { |
11 SkChunkAlloc allocator(4096); // FIXME: constant-ize, tune | 11 SkChunkAlloc allocator(4096); // FIXME: constant-ize, tune |
12 SkOpContour contour; | 12 SkOpContour contour; |
13 SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour); | 13 SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour); |
14 SkOpGlobalState globalState(nullptr, contourList SkDEBUGPARAMS(false) | 14 SkOpGlobalState globalState(contourList, &allocator SkDEBUGPARAMS(false) |
15 SkDEBUGPARAMS(nullptr)); | 15 SkDEBUGPARAMS(nullptr)); |
16 // turn path into list of segments | 16 // turn path into list of segments |
17 SkOpEdgeBuilder builder(path, &contour, &allocator, &globalState); | 17 SkScalar scaleFactor = ScaleFactor(path); |
18 if (!builder.finish(&allocator)) { | 18 SkPath scaledPath; |
| 19 const SkPath* workingPath; |
| 20 if (scaleFactor > SK_Scalar1) { |
| 21 ScalePath(path, 1.f / scaleFactor, &scaledPath); |
| 22 workingPath = &scaledPath; |
| 23 } else { |
| 24 workingPath = &path; |
| 25 } |
| 26 SkOpEdgeBuilder builder(*workingPath, &contour, &globalState); |
| 27 if (!builder.finish()) { |
19 return false; | 28 return false; |
20 } | 29 } |
21 if (!SortContourList(&contourList, false, false)) { | 30 if (!SortContourList(&contourList, false, false)) { |
22 result->setEmpty(); | 31 result->setEmpty(); |
23 return true; | 32 return true; |
24 } | 33 } |
25 SkOpContour* current = contourList; | 34 SkOpContour* current = contourList; |
26 SkPathOpsBounds bounds = current->bounds(); | 35 SkPathOpsBounds bounds = current->bounds(); |
27 while ((current = current->next())) { | 36 while ((current = current->next())) { |
28 bounds.add(current->bounds()); | 37 bounds.add(current->bounds()); |
29 } | 38 } |
30 *result = bounds; | 39 *result = bounds; |
31 return true; | 40 return true; |
32 } | 41 } |
OLD | NEW |