2018-07-11 18:09:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "fuzz/Fuzz.h"
|
2019-08-02 13:57:04 +00:00
|
|
|
|
2022-04-28 15:04:30 +00:00
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/private/SkTDArray.h"
|
2019-08-02 13:57:04 +00:00
|
|
|
#include "include/private/SkTemplates.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/utils/SkPolyUtils.h"
|
2018-07-11 18:09:09 +00:00
|
|
|
|
|
|
|
void inline ignoreResult(bool ) {}
|
|
|
|
|
2022-01-10 16:56:17 +00:00
|
|
|
// clamps the point to the nearest 16th of a pixel
|
|
|
|
static SkPoint sanitize_point(const SkPoint& in) {
|
|
|
|
SkPoint out;
|
|
|
|
out.fX = SkScalarRoundToScalar(16.f*in.fX)*0.0625f;
|
|
|
|
out.fY = SkScalarRoundToScalar(16.f*in.fY)*0.0625f;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-07-11 18:09:09 +00:00
|
|
|
DEF_FUZZ(PolyUtils, fuzz) {
|
|
|
|
int count;
|
|
|
|
fuzz->nextRange(&count, 0, 512);
|
|
|
|
SkAutoSTMalloc<64, SkPoint> polygon(count);
|
|
|
|
for (int index = 0; index < count; ++index) {
|
|
|
|
fuzz->next(&polygon[index].fX, &polygon[index].fY);
|
2022-01-10 16:56:17 +00:00
|
|
|
polygon[index] = sanitize_point(polygon[index]);
|
2018-07-11 18:09:09 +00:00
|
|
|
}
|
2019-05-01 17:28:07 +00:00
|
|
|
SkRect bounds;
|
|
|
|
bounds.setBoundsCheck(polygon, count);
|
2018-07-11 18:09:09 +00:00
|
|
|
|
|
|
|
ignoreResult(SkGetPolygonWinding(polygon, count));
|
2022-01-13 20:29:24 +00:00
|
|
|
bool isConvex = SkIsConvexPolygon(polygon, count);
|
|
|
|
bool isSimple = SkIsSimplePolygon(polygon, count);
|
2018-07-11 18:09:09 +00:00
|
|
|
|
|
|
|
SkTDArray<SkPoint> output;
|
2022-01-13 20:29:24 +00:00
|
|
|
if (isConvex) {
|
|
|
|
SkScalar inset;
|
|
|
|
fuzz->next(&inset);
|
|
|
|
ignoreResult(SkInsetConvexPolygon(polygon, count, inset, &output));
|
|
|
|
}
|
2018-07-11 18:09:09 +00:00
|
|
|
|
2022-01-13 20:29:24 +00:00
|
|
|
if (isSimple) {
|
|
|
|
SkScalar offset;
|
2022-01-20 20:25:14 +00:00
|
|
|
// Limit this to prevent timeouts.
|
|
|
|
// This should be fine, as this is roughly the range we expect from the shadow algorithm.
|
|
|
|
fuzz->nextRange(&offset, -1000, 1000);
|
2022-01-13 20:29:24 +00:00
|
|
|
ignoreResult(SkOffsetSimplePolygon(polygon, count, bounds, offset, &output));
|
|
|
|
|
|
|
|
SkAutoSTMalloc<64, uint16_t> indexMap(count);
|
|
|
|
for (int index = 0; index < count; ++index) {
|
|
|
|
fuzz->next(&indexMap[index]);
|
|
|
|
}
|
|
|
|
SkTDArray<uint16_t> outputIndices;
|
|
|
|
ignoreResult(SkTriangulateSimplePolygon(polygon, indexMap, count, &outputIndices));
|
2018-07-11 18:09:09 +00:00
|
|
|
}
|
|
|
|
}
|