Kevin Lubick | 2541edf | 2018-01-11 10:27:14 -0500 | [diff] [blame] | 1 | /* |
Kevin Lubick | db1e5c6 | 2018-02-27 08:30:43 -0500 | [diff] [blame] | 2 | * Copyright 2018 Google, LLC |
Kevin Lubick | 2541edf | 2018-01-11 10:27:14 -0500 | [diff] [blame] | 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 | |
Cary Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame^] | 8 | #ifndef FuzzCommon_DEFINED |
| 9 | #define FuzzCommon_DEFINED |
| 10 | |
Kevin Lubick | 2541edf | 2018-01-11 10:27:14 -0500 | [diff] [blame] | 11 | #include "Fuzz.h" |
| 12 | #include "SkPath.h" |
| 13 | #include "SkRegion.h" |
| 14 | |
| 15 | // We don't always want to test NaNs and infinities. |
Cary Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame^] | 16 | static inline void fuzz_nice_float(Fuzz* fuzz, float* f) { |
Kevin Lubick | 2541edf | 2018-01-11 10:27:14 -0500 | [diff] [blame] | 17 | 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 | |
| 23 | template <typename... Args> |
| 24 | inline 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 Lubick | 2541edf | 2018-01-11 10:27:14 -0500 | [diff] [blame] | 29 | template <> |
| 30 | inline 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 Clark | 91390c8 | 2018-03-09 14:02:46 -0500 | [diff] [blame^] | 44 | |
| 45 | // allows some float values for path points |
| 46 | void FuzzPath(Fuzz* fuzz, SkPath* path, int maxOps); |
| 47 | // allows all float values for path points |
| 48 | void BuildPath(Fuzz* fuzz, SkPath* path, int last_verb); |
| 49 | |
| 50 | #endif |