blob: c0c56430a67cf915a21e7bc15513c30fd7641b31 [file] [log] [blame]
robertphillips@google.com7fa18762012-09-11 13:02:31 +00001/*
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"
bsalomon7bffcd22016-09-15 13:55:33 -07009#include "GrShape.h"
robertphillips@google.com7fa18762012-09-11 13:02:31 +000010
bsalomon67fa4e32016-09-21 08:26:57 -070011static 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}
kkinnunen070e0102015-05-21 00:37:30 -070015
bsalomon67fa4e32016-09-21 08:26:57 -070016
17void GrPath::ComputeKey(const GrShape& shape, GrUniqueKey* key, bool* outIsVolatile) {
18 int geoCnt = shape.unstyledKeySize();
19 int styleCnt = GrStyle::KeySize(shape.style(), GrStyle::Apply::kPathEffectAndStrokeRec);
bsalomon6663acf2016-05-10 09:14:17 -070020 // 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.
bsalomon67fa4e32016-09-21 08:26:57 -070022 SkASSERT(styleCnt >= 0);
23 if (geoCnt < 0) {
24 *outIsVolatile = true;
25 return;
bsalomon7bffcd22016-09-15 13:55:33 -070026 }
kkinnunen070e0102015-05-21 00:37:30 -070027 static const GrUniqueKey::Domain kGeneralPathDomain = GrUniqueKey::GenerateDomain();
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -040028 GrUniqueKey::Builder builder(key, kGeneralPathDomain, geoCnt + styleCnt, "Path");
bsalomon7bffcd22016-09-15 13:55:33 -070029 shape.writeUnstyledKey(&builder[0]);
30 if (styleCnt) {
31 write_style_key(&builder[geoCnt], shape.style());
cdaltonb85a0aa2014-07-21 15:32:44 -070032 }
bsalomon67fa4e32016-09-21 08:26:57 -070033 *outIsVolatile = false;
kkinnunen070e0102015-05-21 00:37:30 -070034}
35
fmalitafbe1c112015-11-18 20:12:56 -080036#ifdef SK_DEBUG
bsalomon6663acf2016-05-10 09:14:17 -070037bool 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) {
fmalitafbe1c112015-11-18 20:12:56 -080042 return false;
43 }
bsalomon6663acf2016-05-10 09:14:17 -070044 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 }
fmalitafbe1c112015-11-18 20:12:56 -080053 return fSkPath == path;
54}
55#endif