Jim Van Verth | 061cc21 | 2018-07-11 14:09:09 -0400 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "fuzz/Fuzz.h" |
| 9 | #include "src/utils/SkPolyUtils.h" |
Jim Van Verth | 061cc21 | 2018-07-11 14:09:09 -0400 | [diff] [blame] | 10 | |
| 11 | void inline ignoreResult(bool ) {} |
| 12 | |
| 13 | DEF_FUZZ(PolyUtils, fuzz) { |
| 14 | int count; |
| 15 | fuzz->nextRange(&count, 0, 512); |
| 16 | SkAutoSTMalloc<64, SkPoint> polygon(count); |
| 17 | for (int index = 0; index < count; ++index) { |
| 18 | fuzz->next(&polygon[index].fX, &polygon[index].fY); |
| 19 | } |
Jim Van Verth | a5ef397 | 2019-05-01 13:28:07 -0400 | [diff] [blame] | 20 | SkRect bounds; |
| 21 | bounds.setBoundsCheck(polygon, count); |
Jim Van Verth | 061cc21 | 2018-07-11 14:09:09 -0400 | [diff] [blame] | 22 | |
| 23 | ignoreResult(SkGetPolygonWinding(polygon, count)); |
| 24 | ignoreResult(SkIsConvexPolygon(polygon, count)); |
| 25 | ignoreResult(SkIsSimplePolygon(polygon, count)); |
| 26 | |
| 27 | SkScalar inset; |
| 28 | fuzz->next(&inset); |
| 29 | SkTDArray<SkPoint> output; |
| 30 | ignoreResult(SkInsetConvexPolygon(polygon, count, inset, &output)); |
Jim Van Verth | 061cc21 | 2018-07-11 14:09:09 -0400 | [diff] [blame] | 31 | |
| 32 | SkScalar offset; |
| 33 | fuzz->next(&offset); |
Jim Van Verth | a5ef397 | 2019-05-01 13:28:07 -0400 | [diff] [blame] | 34 | ignoreResult(SkOffsetSimplePolygon(polygon, count, bounds, offset, &output)); |
Jim Van Verth | 061cc21 | 2018-07-11 14:09:09 -0400 | [diff] [blame] | 35 | |
| 36 | SkAutoSTMalloc<64, uint16_t> indexMap(count); |
| 37 | for (int index = 0; index < count; ++index) { |
| 38 | fuzz->next(&indexMap[index]); |
| 39 | } |
| 40 | SkTDArray<uint16_t> outputIndices; |
| 41 | ignoreResult(SkTriangulateSimplePolygon(polygon, indexMap, count, &outputIndices)); |
| 42 | } |