blob: 19593c228b9b5d93492a9fe93123923a4bc8acc4 [file] [log] [blame]
caryclarka8d2ffb2014-06-24 07:55:11 -07001/*
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
10bool TightBounds(const SkPath& path, SkRect* result) {
caryclark54359292015-03-26 07:52:43 -070011 SkChunkAlloc allocator(4096); // FIXME: constant-ize, tune
12 SkOpContour contour;
caryclark624637c2015-05-11 07:21:27 -070013 SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour);
caryclarkdae6b972016-06-08 04:28:19 -070014 SkOpGlobalState globalState(nullptr, contourList SkDEBUGPARAMS(false)
15 SkDEBUGPARAMS(nullptr));
caryclarka8d2ffb2014-06-24 07:55:11 -070016 // turn path into list of segments
caryclark54359292015-03-26 07:52:43 -070017 SkOpEdgeBuilder builder(path, &contour, &allocator, &globalState);
18 if (!builder.finish(&allocator)) {
caryclarka8d2ffb2014-06-24 07:55:11 -070019 return false;
20 }
caryclark624637c2015-05-11 07:21:27 -070021 if (!SortContourList(&contourList, false, false)) {
22 result->setEmpty();
caryclarka8d2ffb2014-06-24 07:55:11 -070023 return true;
24 }
caryclark624637c2015-05-11 07:21:27 -070025 SkOpContour* current = contourList;
caryclarka8d2ffb2014-06-24 07:55:11 -070026 SkPathOpsBounds bounds = current->bounds();
caryclark624637c2015-05-11 07:21:27 -070027 while ((current = current->next())) {
caryclarka8d2ffb2014-06-24 07:55:11 -070028 bounds.add(current->bounds());
29 }
30 *result = bounds;
31 return true;
32}