| 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 "src/gpu/GrPath.h" |
| 9 | #include "src/gpu/geometry/GrShape.h" |
| 10 | |
| 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 | } |
| 15 | |
| 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); |
| 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. |
| 22 | SkASSERT(styleCnt >= 0); |
| 23 | if (geoCnt < 0) { |
| 24 | *outIsVolatile = true; |
| 25 | return; |
| 26 | } |
| 27 | static const GrUniqueKey::Domain kGeneralPathDomain = GrUniqueKey::GenerateDomain(); |
| 28 | GrUniqueKey::Builder builder(key, kGeneralPathDomain, geoCnt + styleCnt, "Path" ); |
| 29 | shape.writeUnstyledKey(&builder[0]); |
| 30 | if (styleCnt) { |
| 31 | write_style_key(&builder[geoCnt], shape.style()); |
| 32 | } |
| 33 | *outIsVolatile = false; |
| 34 | } |
| 35 | |
| 36 | #ifdef SK_DEBUG |
| 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) { |
| 42 | return false; |
| 43 | } |
| 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 | } |
| 53 | return fSkPath == path; |
| 54 | } |
| 55 | #endif |
| 56 | |