Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Side by Side Diff: src/gpu/GrStyle.cpp

Issue 1949193002: Make cap only affect the keys of GrShapes that are possibly-open (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: due Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrStyle.h ('k') | tests/GrShapeTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrStyle.h" 8 #include "GrStyle.h"
9 9
10 int GrStyle::KeySize(const GrStyle &style, Apply apply) { 10 int GrStyle::KeySize(const GrStyle &style, Apply apply, uint32_t flags) {
11 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(SkScalar)); 11 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(SkScalar));
12 int size = 0; 12 int size = 0;
13 if (style.isDashed()) { 13 if (style.isDashed()) {
14 // One scalar for dash phase and one for each dash value. 14 // One scalar for dash phase and one for each dash value.
15 size += 1 + style.dashIntervalCnt(); 15 size += 1 + style.dashIntervalCnt();
16 } else if (style.pathEffect()) { 16 } else if (style.pathEffect()) {
17 // No key for a generic path effect. 17 // No key for a generic path effect.
18 return -1; 18 return -1;
19 } 19 }
20 20
21 if (Apply::kPathEffectOnly == apply) { 21 if (Apply::kPathEffectOnly == apply) {
22 return size; 22 return size;
23 } 23 }
24 24
25 if (style.strokeRec().needToApply()) { 25 if (style.strokeRec().needToApply()) {
26 // One for style/cap/join, 2 for miter and width. 26 // One for style/cap/join, 2 for miter and width.
27 size += 3; 27 size += 3;
28 } 28 }
29 return size; 29 return size;
30 } 30 }
31 31
32 void GrStyle::WriteKey(uint32_t *key, const GrStyle &style, Apply apply) { 32 void GrStyle::WriteKey(uint32_t *key, const GrStyle &style, Apply apply, uint32_ t flags) {
33 SkASSERT(key); 33 SkASSERT(key);
34 SkASSERT(KeySize(style, apply) >= 0); 34 SkASSERT(KeySize(style, apply) >= 0);
35 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(SkScalar)); 35 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(SkScalar));
36 36
37 int i = 0; 37 int i = 0;
38 if (style.isDashed()) { 38 if (style.isDashed()) {
39 GR_STATIC_ASSERT(sizeof(style.dashPhase()) == sizeof(uint32_t)); 39 GR_STATIC_ASSERT(sizeof(style.dashPhase()) == sizeof(uint32_t));
40 SkScalar phase = style.dashPhase(); 40 SkScalar phase = style.dashPhase();
41 memcpy(&key[i++], &phase, sizeof(SkScalar)); 41 memcpy(&key[i++], &phase, sizeof(SkScalar));
42 42
(...skipping 13 matching lines...) Expand all
56 kStyleBits = 2, 56 kStyleBits = 2,
57 kJoinBits = 2, 57 kJoinBits = 2,
58 kCapBits = 32 - kStyleBits - kJoinBits, 58 kCapBits = 32 - kStyleBits - kJoinBits,
59 59
60 kJoinShift = kStyleBits, 60 kJoinShift = kStyleBits,
61 kCapShift = kJoinShift + kJoinBits, 61 kCapShift = kJoinShift + kJoinBits,
62 }; 62 };
63 GR_STATIC_ASSERT(SkStrokeRec::kStyleCount <= (1 << kStyleBits)); 63 GR_STATIC_ASSERT(SkStrokeRec::kStyleCount <= (1 << kStyleBits));
64 GR_STATIC_ASSERT(SkPaint::kJoinCount <= (1 << kJoinBits)); 64 GR_STATIC_ASSERT(SkPaint::kJoinCount <= (1 << kJoinBits));
65 GR_STATIC_ASSERT(SkPaint::kCapCount <= (1 << kCapBits)); 65 GR_STATIC_ASSERT(SkPaint::kCapCount <= (1 << kCapBits));
66 // The cap type only matters for unclosed shapes. However, a path effect could unclose
67 // the shape before it is stroked.
68 SkPaint::Cap cap;
69 if ((flags & kClosed_KeyFlag) && !style.pathEffect()) {
70 cap = SkPaint::kButt_Cap;
71 } else {
72 cap = style.strokeRec().getCap();
73 }
66 key[i++] = style.strokeRec().getStyle() | 74 key[i++] = style.strokeRec().getStyle() |
67 style.strokeRec().getJoin() << kJoinShift | 75 style.strokeRec().getJoin() << kJoinShift |
68 style.strokeRec().getCap() << kCapShift; 76 cap << kCapShift;
69 77
70 SkScalar scalar; 78 SkScalar scalar;
71 // Miter limit only affects miter joins 79 // Miter limit only affects miter joins
72 scalar = SkPaint::kMiter_Join == style.strokeRec().getJoin() 80 scalar = SkPaint::kMiter_Join == style.strokeRec().getJoin()
73 ? style.strokeRec().getMiter() 81 ? style.strokeRec().getMiter()
74 : -1.f; 82 : -1.f;
75 memcpy(&key[i++], &scalar, sizeof(scalar)); 83 memcpy(&key[i++], &scalar, sizeof(scalar));
76 84
77 scalar = style.strokeRec().getWidth(); 85 scalar = style.strokeRec().getWidth();
78 memcpy(&key[i++], &scalar, sizeof(scalar)); 86 memcpy(&key[i++], &scalar, sizeof(scalar));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 *style = SkStrokeRec::kFill_InitStyle; 147 *style = SkStrokeRec::kFill_InitStyle;
140 } else { 148 } else {
141 SkASSERT(SkStrokeRec::kFill_Style == strokeRec.getStyle() || 149 SkASSERT(SkStrokeRec::kFill_Style == strokeRec.getStyle() ||
142 SkStrokeRec::kHairline_Style == strokeRec.getStyle()); 150 SkStrokeRec::kHairline_Style == strokeRec.getStyle());
143 *style = strokeRec.getStyle() == SkStrokeRec::kFill_Style 151 *style = strokeRec.getStyle() == SkStrokeRec::kFill_Style
144 ? SkStrokeRec::kFill_InitStyle 152 ? SkStrokeRec::kFill_InitStyle
145 : SkStrokeRec::kHairline_InitStyle; 153 : SkStrokeRec::kHairline_InitStyle;
146 } 154 }
147 return true; 155 return true;
148 } 156 }
OLDNEW
« no previous file with comments | « src/gpu/GrStyle.h ('k') | tests/GrShapeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698