blob: e4b3c8b0465d9b25bf90864f4e8f10ad96a25758 [file] [log] [blame]
Jim Van Verth061cc212018-07-11 14:09:09 -04001/*
2 * Copyright 2018 Google LLC
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "fuzz/Fuzz.h"
Michael Ludwig8ee6cf32019-08-02 09:57:04 -04009
10#include "include/private/SkTemplates.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/utils/SkPolyUtils.h"
Jim Van Verth061cc212018-07-11 14:09:09 -040012
13void inline ignoreResult(bool ) {}
14
15DEF_FUZZ(PolyUtils, fuzz) {
16 int count;
17 fuzz->nextRange(&count, 0, 512);
18 SkAutoSTMalloc<64, SkPoint> polygon(count);
19 for (int index = 0; index < count; ++index) {
20 fuzz->next(&polygon[index].fX, &polygon[index].fY);
21 }
Jim Van Vertha5ef3972019-05-01 13:28:07 -040022 SkRect bounds;
23 bounds.setBoundsCheck(polygon, count);
Jim Van Verth061cc212018-07-11 14:09:09 -040024
25 ignoreResult(SkGetPolygonWinding(polygon, count));
26 ignoreResult(SkIsConvexPolygon(polygon, count));
27 ignoreResult(SkIsSimplePolygon(polygon, count));
28
29 SkScalar inset;
30 fuzz->next(&inset);
31 SkTDArray<SkPoint> output;
32 ignoreResult(SkInsetConvexPolygon(polygon, count, inset, &output));
Jim Van Verth061cc212018-07-11 14:09:09 -040033
34 SkScalar offset;
35 fuzz->next(&offset);
Jim Van Vertha5ef3972019-05-01 13:28:07 -040036 ignoreResult(SkOffsetSimplePolygon(polygon, count, bounds, offset, &output));
Jim Van Verth061cc212018-07-11 14:09:09 -040037
38 SkAutoSTMalloc<64, uint16_t> indexMap(count);
39 for (int index = 0; index < count; ++index) {
40 fuzz->next(&indexMap[index]);
41 }
42 SkTDArray<uint16_t> outputIndices;
43 ignoreResult(SkTriangulateSimplePolygon(polygon, indexMap, count, &outputIndices));
44}