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" |
Michael Ludwig | 8ee6cf3 | 2019-08-02 09:57:04 -0400 | [diff] [blame] | 9 | |
| 10 | #include "include/private/SkTemplates.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/utils/SkPolyUtils.h" |
Jim Van Verth | 061cc21 | 2018-07-11 14:09:09 -0400 | [diff] [blame] | 12 | |
| 13 | void inline ignoreResult(bool ) {} |
| 14 | |
| 15 | DEF_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 Verth | a5ef397 | 2019-05-01 13:28:07 -0400 | [diff] [blame] | 22 | SkRect bounds; |
| 23 | bounds.setBoundsCheck(polygon, count); |
Jim Van Verth | 061cc21 | 2018-07-11 14:09:09 -0400 | [diff] [blame] | 24 | |
| 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 Verth | 061cc21 | 2018-07-11 14:09:09 -0400 | [diff] [blame] | 33 | |
| 34 | SkScalar offset; |
| 35 | fuzz->next(&offset); |
Jim Van Verth | a5ef397 | 2019-05-01 13:28:07 -0400 | [diff] [blame] | 36 | ignoreResult(SkOffsetSimplePolygon(polygon, count, bounds, offset, &output)); |
Jim Van Verth | 061cc21 | 2018-07-11 14:09:09 -0400 | [diff] [blame] | 37 | |
| 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 | } |