egdaniel | a22ea18 | 2014-06-11 06:51:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | |
| 8 | #ifndef SkDashPathPriv_DEFINED |
| 9 | #define SkDashPathPriv_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkPathEffect.h" |
egdaniel | a22ea18 | 2014-06-11 06:51:51 -0700 | [diff] [blame] | 12 | |
| 13 | namespace SkDashPath { |
bsalomon | 398e3f4 | 2016-06-13 10:22:48 -0700 | [diff] [blame] | 14 | /** |
egdaniel | a22ea18 | 2014-06-11 06:51:51 -0700 | [diff] [blame] | 15 | * Calculates the initialDashLength, initialDashIndex, and intervalLength based on the |
| 16 | * inputed phase and intervals. If adjustedPhase is passed in, then the phase will be |
| 17 | * adjusted to be between 0 and intervalLength. The result will be stored in adjustedPhase. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 18 | * If adjustedPhase is nullptr then it is assumed phase is already between 0 and intervalLength |
caryclark | eb75c7d | 2016-03-18 06:04:26 -0700 | [diff] [blame] | 19 | * |
| 20 | * Caller should have already used ValidDashPath to exclude invalid data. |
egdaniel | a22ea18 | 2014-06-11 06:51:51 -0700 | [diff] [blame] | 21 | */ |
| 22 | void CalcDashParameters(SkScalar phase, const SkScalar intervals[], int32_t count, |
| 23 | SkScalar* initialDashLength, int32_t* initialDashIndex, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 24 | SkScalar* intervalLength, SkScalar* adjustedPhase = nullptr); |
egdaniel | a22ea18 | 2014-06-11 06:51:51 -0700 | [diff] [blame] | 25 | |
| 26 | bool FilterDashPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*, |
egdaniel | a22ea18 | 2014-06-11 06:51:51 -0700 | [diff] [blame] | 27 | const SkPathEffect::DashInfo& info); |
caryclark | eb75c7d | 2016-03-18 06:04:26 -0700 | [diff] [blame] | 28 | |
Michael Ludwig | db285de | 2021-09-16 11:46:13 -0400 | [diff] [blame] | 29 | #ifdef SK_BUILD_FOR_FUZZER |
| 30 | const SkScalar kMaxDashCount = 10000; |
| 31 | #else |
lsalzman | f41ae2f | 2016-07-21 09:37:59 -0700 | [diff] [blame] | 32 | const SkScalar kMaxDashCount = 1000000; |
Michael Ludwig | db285de | 2021-09-16 11:46:13 -0400 | [diff] [blame] | 33 | #endif |
lsalzman | f41ae2f | 2016-07-21 09:37:59 -0700 | [diff] [blame] | 34 | |
bsalomon | 398e3f4 | 2016-06-13 10:22:48 -0700 | [diff] [blame] | 35 | /** See comments for InternalFilter */ |
| 36 | enum class StrokeRecApplication { |
| 37 | kDisallow, |
| 38 | kAllow, |
| 39 | }; |
| 40 | |
| 41 | /** |
| 42 | * Caller should have already used ValidDashPath to exclude invalid data. Typically, this leaves |
| 43 | * the strokeRec unmodified. However, for some simple shapes (e.g. a line) it may directly |
| 44 | * evaluate the dash and stroke to produce a stroked output path with a fill strokeRec. Passing |
| 45 | * true for disallowStrokeRecApplication turns this behavior off. |
caryclark | eb75c7d | 2016-03-18 06:04:26 -0700 | [diff] [blame] | 46 | */ |
| 47 | bool InternalFilter(SkPath* dst, const SkPath& src, SkStrokeRec* rec, |
| 48 | const SkRect* cullRect, const SkScalar aIntervals[], |
| 49 | int32_t count, SkScalar initialDashLength, int32_t initialDashIndex, |
bsalomon | 398e3f4 | 2016-06-13 10:22:48 -0700 | [diff] [blame] | 50 | SkScalar intervalLength, |
| 51 | StrokeRecApplication = StrokeRecApplication::kAllow); |
caryclark | eb75c7d | 2016-03-18 06:04:26 -0700 | [diff] [blame] | 52 | |
| 53 | bool ValidDashPath(SkScalar phase, const SkScalar intervals[], int32_t count); |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 54 | } // namespace SkDashPath |
egdaniel | a22ea18 | 2014-06-11 06:51:51 -0700 | [diff] [blame] | 55 | |
| 56 | #endif |