robertphillips@google.com | 7fa1876 | 2012-09-11 13:02:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | #include "GrPath.h" |
bsalomon | 7bffcd2 | 2016-09-15 13:55:33 -0700 | [diff] [blame] | 9 | #include "GrShape.h" |
robertphillips@google.com | 7fa1876 | 2012-09-11 13:02:31 +0000 | [diff] [blame] | 10 | |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 11 | static inline void write_style_key(uint32_t* key, const GrStyle& style) { |
| 12 | // Pass 1 for the scale since the GPU will apply the style not GrStyle::applyToPath(). |
| 13 | GrStyle::WriteKey(key, style, GrStyle::Apply::kPathEffectAndStrokeRec, SK_Scalar1); |
| 14 | } |
kkinnunen | 070e010 | 2015-05-21 00:37:30 -0700 | [diff] [blame] | 15 | |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 16 | |
| 17 | void GrPath::ComputeKey(const GrShape& shape, GrUniqueKey* key, bool* outIsVolatile) { |
| 18 | int geoCnt = shape.unstyledKeySize(); |
| 19 | int styleCnt = GrStyle::KeySize(shape.style(), GrStyle::Apply::kPathEffectAndStrokeRec); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 20 | // This should only fail for an arbitrary path effect, and we should not have gotten |
| 21 | // here with anything other than a dash path effect. |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 22 | SkASSERT(styleCnt >= 0); |
| 23 | if (geoCnt < 0) { |
| 24 | *outIsVolatile = true; |
| 25 | return; |
bsalomon | 7bffcd2 | 2016-09-15 13:55:33 -0700 | [diff] [blame] | 26 | } |
kkinnunen | 070e010 | 2015-05-21 00:37:30 -0700 | [diff] [blame] | 27 | static const GrUniqueKey::Domain kGeneralPathDomain = GrUniqueKey::GenerateDomain(); |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 28 | GrUniqueKey::Builder builder(key, kGeneralPathDomain, geoCnt + styleCnt, "Path"); |
bsalomon | 7bffcd2 | 2016-09-15 13:55:33 -0700 | [diff] [blame] | 29 | shape.writeUnstyledKey(&builder[0]); |
| 30 | if (styleCnt) { |
| 31 | write_style_key(&builder[geoCnt], shape.style()); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 32 | } |
bsalomon | 67fa4e3 | 2016-09-21 08:26:57 -0700 | [diff] [blame] | 33 | *outIsVolatile = false; |
kkinnunen | 070e010 | 2015-05-21 00:37:30 -0700 | [diff] [blame] | 34 | } |
| 35 | |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 36 | #ifdef SK_DEBUG |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 37 | bool GrPath::isEqualTo(const SkPath& path, const GrStyle& style) const { |
| 38 | // Since this is only called in debug we don't care about performance. |
| 39 | int cnt0 = GrStyle::KeySize(fStyle, GrStyle::Apply::kPathEffectAndStrokeRec); |
| 40 | int cnt1 = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec); |
| 41 | if (cnt0 < 0 || cnt1 < 0 || cnt0 != cnt1) { |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 42 | return false; |
| 43 | } |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 44 | if (cnt0) { |
| 45 | SkAutoTArray<uint32_t> key0(cnt0); |
| 46 | SkAutoTArray<uint32_t> key1(cnt0); |
| 47 | write_style_key(key0.get(), fStyle); |
| 48 | write_style_key(key1.get(), style); |
| 49 | if (0 != memcmp(key0.get(), key1.get(), cnt0)) { |
| 50 | return false; |
| 51 | } |
| 52 | } |
fmalita | fbe1c11 | 2015-11-18 20:12:56 -0800 | [diff] [blame] | 53 | return fSkPath == path; |
| 54 | } |
| 55 | #endif |