2018-01-11 15:27:14 +00:00
|
|
|
/*
|
2018-02-27 13:30:43 +00:00
|
|
|
* Copyright 2018 Google, LLC
|
2018-01-11 15:27:14 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-03-09 19:02:46 +00:00
|
|
|
#ifndef FuzzCommon_DEFINED
|
|
|
|
#define FuzzCommon_DEFINED
|
|
|
|
|
2018-01-11 15:27:14 +00:00
|
|
|
#include "Fuzz.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
|
|
|
|
// We don't always want to test NaNs and infinities.
|
2018-03-09 19:02:46 +00:00
|
|
|
static inline void fuzz_nice_float(Fuzz* fuzz, float* f) {
|
2018-01-11 15:27:14 +00:00
|
|
|
float v;
|
|
|
|
fuzz->next(&v);
|
|
|
|
constexpr float kLimit = 1.0e35f; // FLT_MAX?
|
|
|
|
*f = (v == v && v <= kLimit && v >= -kLimit) ? v : 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
inline void fuzz_nice_float(Fuzz* fuzz, float* f, Args... rest) {
|
|
|
|
fuzz_nice_float(fuzz, f);
|
|
|
|
fuzz_nice_float(fuzz, rest...);
|
|
|
|
}
|
|
|
|
|
2018-04-06 14:25:12 +00:00
|
|
|
template <typename T, typename Min, typename Max>
|
|
|
|
inline void fuzz_enum_range(Fuzz* fuzz, T* value, Min rmin, Max rmax) {
|
|
|
|
using U = skstd::underlying_type_t<T>;
|
|
|
|
fuzz->nextRange((U*)value, (U)rmin, (U)rmax);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void fuzz_region(Fuzz* fuzz, SkRegion* region, int maxN) {
|
2018-01-11 15:27:14 +00:00
|
|
|
uint8_t N;
|
2018-04-06 14:25:12 +00:00
|
|
|
fuzz->nextRange(&N, 0, maxN);
|
2018-01-11 15:27:14 +00:00
|
|
|
for (uint8_t i = 0; i < N; ++i) {
|
|
|
|
SkIRect r;
|
2018-04-06 14:25:12 +00:00
|
|
|
SkRegion::Op op;
|
|
|
|
// Avoid the sentinal value used by Region.
|
|
|
|
fuzz->nextRange(&r.fLeft, -2147483646, 2147483646);
|
|
|
|
fuzz->nextRange(&r.fTop, -2147483646, 2147483646);
|
|
|
|
fuzz->nextRange(&r.fRight, -2147483646, 2147483646);
|
|
|
|
fuzz->nextRange(&r.fBottom, -2147483646, 2147483646);
|
2018-01-11 15:27:14 +00:00
|
|
|
r.sort();
|
2018-04-06 14:25:12 +00:00
|
|
|
fuzz_enum_range(fuzz, &op, (SkRegion::Op)0, SkRegion::kLastOp);
|
|
|
|
if (!region->op(r, op)) {
|
2018-01-11 15:27:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-09 19:02:46 +00:00
|
|
|
|
2018-04-06 14:25:12 +00:00
|
|
|
template <>
|
|
|
|
inline void Fuzz::next(SkRegion* region) { fuzz_region(this, region, 10); }
|
|
|
|
|
2018-03-09 19:02:46 +00:00
|
|
|
// allows some float values for path points
|
|
|
|
void FuzzPath(Fuzz* fuzz, SkPath* path, int maxOps);
|
|
|
|
// allows all float values for path points
|
|
|
|
void BuildPath(Fuzz* fuzz, SkPath* path, int last_verb);
|
|
|
|
|
|
|
|
#endif
|
2018-06-05 21:21:30 +00:00
|
|
|
|