blob: bea5a30f8683d561a7fcaaaa9eeec7fa20d8d4f7 [file] [log] [blame]
Kevin Lubick2541edf2018-01-11 10:27:14 -05001/*
Kevin Lubickdb1e5c62018-02-27 08:30:43 -05002 * Copyright 2018 Google, LLC
Kevin Lubick2541edf2018-01-11 10:27:14 -05003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Cary Clark91390c82018-03-09 14:02:46 -05008#ifndef FuzzCommon_DEFINED
9#define FuzzCommon_DEFINED
10
Kevin Lubick2541edf2018-01-11 10:27:14 -050011#include "Fuzz.h"
12#include "SkPath.h"
13#include "SkRegion.h"
14
15// We don't always want to test NaNs and infinities.
Cary Clark91390c82018-03-09 14:02:46 -050016static inline void fuzz_nice_float(Fuzz* fuzz, float* f) {
Kevin Lubick2541edf2018-01-11 10:27:14 -050017 float v;
18 fuzz->next(&v);
19 constexpr float kLimit = 1.0e35f; // FLT_MAX?
20 *f = (v == v && v <= kLimit && v >= -kLimit) ? v : 0.0f;
21}
22
23template <typename... Args>
24inline void fuzz_nice_float(Fuzz* fuzz, float* f, Args... rest) {
25 fuzz_nice_float(fuzz, f);
26 fuzz_nice_float(fuzz, rest...);
27}
28
Kevin Lubick2541edf2018-01-11 10:27:14 -050029template <>
30inline void Fuzz::next(SkRegion* region) {
31 uint8_t N;
32 this->nextRange(&N, 0, 10);
33 for (uint8_t i = 0; i < N; ++i) {
34 SkIRect r;
35 uint8_t op;
36 this->next(&r);
37 r.sort();
38 this->nextRange(&op, 0, (uint8_t)SkRegion::kLastOp);
39 if (!region->op(r, (SkRegion::Op)op)) {
40 return;
41 }
42 }
43}
Cary Clark91390c82018-03-09 14:02:46 -050044
45// allows some float values for path points
46void FuzzPath(Fuzz* fuzz, SkPath* path, int maxOps);
47// allows all float values for path points
48void BuildPath(Fuzz* fuzz, SkPath* path, int last_verb);
49
50#endif