FuzzPathMeasure.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright 2018 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 "fuzz/Fuzz.h"
  8. #include "fuzz/FuzzCommon.h"
  9. #include "include/core/SkPathMeasure.h"
  10. void inline ignoreResult(bool ) {}
  11. DEF_FUZZ(PathMeasure, fuzz) {
  12. uint8_t bits;
  13. fuzz->next(&bits);
  14. SkScalar distance[6];
  15. for (auto index = 0; index < 6; ++index) {
  16. fuzz->next(&distance[index]);
  17. }
  18. SkPath path;
  19. FuzzEvilPath(fuzz, &path, SkPath::Verb::kDone_Verb);
  20. SkRect bounds = path.getBounds();
  21. SkScalar maxDim = SkTMax(bounds.width(), bounds.height());
  22. SkScalar resScale = maxDim / 1000;
  23. SkPathMeasure measure(path, bits & 1, resScale);
  24. SkPoint position;
  25. SkVector tangent;
  26. ignoreResult(measure.getPosTan(distance[0], &position, &tangent));
  27. SkPath dst;
  28. ignoreResult(measure.getSegment(distance[1], distance[2], &dst, (bits >> 1) & 1));
  29. ignoreResult(measure.nextContour());
  30. ignoreResult(measure.getPosTan(distance[3], &position, &tangent));
  31. ignoreResult(measure.getSegment(distance[4], distance[5], &dst, (bits >> 2) & 1));
  32. }