caryclark | a8d2ffb | 2014-06-24 07:55:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 "SkOpEdgeBuilder.h" |
| 8 | #include "SkPathOpsCommon.h" |
| 9 | |
| 10 | bool TightBounds(const SkPath& path, SkRect* result) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 11 | SkChunkAlloc allocator(4096); // FIXME: constant-ize, tune |
| 12 | SkOpContour contour; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 13 | SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour); |
caryclark | dae6b97 | 2016-06-08 04:28:19 -0700 | [diff] [blame] | 14 | SkOpGlobalState globalState(nullptr, contourList SkDEBUGPARAMS(false) |
| 15 | SkDEBUGPARAMS(nullptr)); |
caryclark | a8d2ffb | 2014-06-24 07:55:11 -0700 | [diff] [blame] | 16 | // turn path into list of segments |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 17 | SkOpEdgeBuilder builder(path, &contour, &allocator, &globalState); |
| 18 | if (!builder.finish(&allocator)) { |
caryclark | a8d2ffb | 2014-06-24 07:55:11 -0700 | [diff] [blame] | 19 | return false; |
| 20 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 21 | if (!SortContourList(&contourList, false, false)) { |
| 22 | result->setEmpty(); |
caryclark | a8d2ffb | 2014-06-24 07:55:11 -0700 | [diff] [blame] | 23 | return true; |
| 24 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 25 | SkOpContour* current = contourList; |
caryclark | a8d2ffb | 2014-06-24 07:55:11 -0700 | [diff] [blame] | 26 | SkPathOpsBounds bounds = current->bounds(); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 27 | while ((current = current->next())) { |
caryclark | a8d2ffb | 2014-06-24 07:55:11 -0700 | [diff] [blame] | 28 | bounds.add(current->bounds()); |
| 29 | } |
| 30 | *result = bounds; |
| 31 | return true; |
| 32 | } |