FuzzPolyUtils.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "fuzz/Fuzz.h"
  8. #include "src/utils/SkPolyUtils.h"
  9. void inline ignoreResult(bool ) {}
  10. DEF_FUZZ(PolyUtils, fuzz) {
  11. int count;
  12. fuzz->nextRange(&count, 0, 512);
  13. SkAutoSTMalloc<64, SkPoint> polygon(count);
  14. for (int index = 0; index < count; ++index) {
  15. fuzz->next(&polygon[index].fX, &polygon[index].fY);
  16. }
  17. SkRect bounds;
  18. bounds.setBoundsCheck(polygon, count);
  19. ignoreResult(SkGetPolygonWinding(polygon, count));
  20. ignoreResult(SkIsConvexPolygon(polygon, count));
  21. ignoreResult(SkIsSimplePolygon(polygon, count));
  22. SkScalar inset;
  23. fuzz->next(&inset);
  24. SkTDArray<SkPoint> output;
  25. ignoreResult(SkInsetConvexPolygon(polygon, count, inset, &output));
  26. SkScalar offset;
  27. fuzz->next(&offset);
  28. ignoreResult(SkOffsetSimplePolygon(polygon, count, bounds, offset, &output));
  29. SkAutoSTMalloc<64, uint16_t> indexMap(count);
  30. for (int index = 0; index < count; ++index) {
  31. fuzz->next(&indexMap[index]);
  32. }
  33. SkTDArray<uint16_t> outputIndices;
  34. ignoreResult(SkTriangulateSimplePolygon(polygon, indexMap, count, &outputIndices));
  35. }