blob: ac5d6aae0b3e90c695fa0d3538405cb6576742d7 [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);
Tom Hudson2880df22015-10-29 09:55:42 -040014 SkOpGlobalState globalState(nullptr, contourList SkDEBUGPARAMS(nullptr));
caryclarka8d2ffb2014-06-24 07:55:11 -070015 // turn path into list of segments
caryclark54359292015-03-26 07:52:43 -070016 SkOpEdgeBuilder builder(path, &contour, &allocator, &globalState);
17 if (!builder.finish(&allocator)) {
caryclarka8d2ffb2014-06-24 07:55:11 -070018 return false;
19 }
caryclark624637c2015-05-11 07:21:27 -070020 if (!SortContourList(&contourList, false, false)) {
21 result->setEmpty();
caryclarka8d2ffb2014-06-24 07:55:11 -070022 return true;
23 }
caryclark624637c2015-05-11 07:21:27 -070024 SkOpContour* current = contourList;
caryclarka8d2ffb2014-06-24 07:55:11 -070025 SkPathOpsBounds bounds = current->bounds();
caryclark624637c2015-05-11 07:21:27 -070026 while ((current = current->next())) {
caryclarka8d2ffb2014-06-24 07:55:11 -070027 bounds.add(current->bounds());
28 }
29 *result = bounds;
30 return true;
31}