blob: a510a1982a3c1ab6782ee1841e1ac3f0178b6a7c [file] [log] [blame]
bsalomon47cc7692016-04-26 12:56:00 -07001/*
2 * Copyright 2016 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
Michael Ludwig663afe52019-06-03 16:46:19 -04008#include "src/gpu/geometry/GrShape.h"
bsalomon47cc7692016-04-26 12:56:00 -07009
Ben Wagnerf08d1d02018-06-18 15:11:00 -040010#include <utility>
11
bsalomon47cc7692016-04-26 12:56:00 -070012GrShape& GrShape::operator=(const GrShape& that) {
bsalomon47cc7692016-04-26 12:56:00 -070013 fStyle = that.fStyle;
bsalomon728b0f72016-06-27 10:00:19 -070014 this->changeType(that.fType, Type::kPath == that.fType ? &that.path() : nullptr);
bsalomon47cc7692016-04-26 12:56:00 -070015 switch (fType) {
16 case Type::kEmpty:
bsalomon47cc7692016-04-26 12:56:00 -070017 break;
Brian Salomon085c0862017-08-31 15:44:51 -040018 case Type::kInvertedEmpty:
19 break;
bsalomon47cc7692016-04-26 12:56:00 -070020 case Type::kRRect:
bsalomon0a0f67e2016-06-28 11:56:42 -070021 fRRectData = that.fRRectData;
22 break;
Brian Salomone4949402018-04-26 15:22:04 -040023 case Type::kArc:
24 fArcData = that.fArcData;
25 break;
bsalomon0a0f67e2016-06-28 11:56:42 -070026 case Type::kLine:
27 fLineData = that.fLineData;
bsalomon47cc7692016-04-26 12:56:00 -070028 break;
29 case Type::kPath:
bsalomon728b0f72016-06-27 10:00:19 -070030 fPathData.fGenID = that.fPathData.fGenID;
bsalomon47cc7692016-04-26 12:56:00 -070031 break;
32 }
33 fInheritedKey.reset(that.fInheritedKey.count());
benjaminwagnerd9cca4a2016-05-04 11:06:19 -070034 sk_careful_memcpy(fInheritedKey.get(), that.fInheritedKey.get(),
35 sizeof(uint32_t) * fInheritedKey.count());
Brian Salomonda6d0722018-01-03 13:54:35 -050036 if (that.fInheritedPathForListeners.isValid()) {
37 fInheritedPathForListeners.set(*that.fInheritedPathForListeners.get());
38 } else {
39 fInheritedPathForListeners.reset();
40 }
bsalomon47cc7692016-04-26 12:56:00 -070041 return *this;
42}
43
Brian Salomon4f40caf2017-09-01 09:00:45 -040044static bool flip_inversion(bool originalIsInverted, GrShape::FillInversion inversion) {
45 switch (inversion) {
46 case GrShape::FillInversion::kPreserve:
47 return false;
48 case GrShape::FillInversion::kFlip:
49 return true;
50 case GrShape::FillInversion::kForceInverted:
51 return !originalIsInverted;
52 case GrShape::FillInversion::kForceNoninverted:
53 return originalIsInverted;
54 }
55 return false;
56}
57
58static bool is_inverted(bool originalIsInverted, GrShape::FillInversion inversion) {
59 switch (inversion) {
60 case GrShape::FillInversion::kPreserve:
61 return originalIsInverted;
62 case GrShape::FillInversion::kFlip:
63 return !originalIsInverted;
64 case GrShape::FillInversion::kForceInverted:
65 return true;
66 case GrShape::FillInversion::kForceNoninverted:
67 return false;
68 }
69 return false;
70}
71
72GrShape GrShape::MakeFilled(const GrShape& original, FillInversion inversion) {
73 if (original.style().isSimpleFill() && !flip_inversion(original.inverseFilled(), inversion)) {
74 // By returning the original rather than falling through we can preserve any inherited style
75 // key. Otherwise, we wipe it out below since the style change invalidates it.
76 return original;
77 }
78 GrShape result;
Brian Salomonda6d0722018-01-03 13:54:35 -050079 if (original.fInheritedPathForListeners.isValid()) {
80 result.fInheritedPathForListeners.set(*original.fInheritedPathForListeners.get());
81 }
Brian Salomon4f40caf2017-09-01 09:00:45 -040082 switch (original.fType) {
83 case Type::kRRect:
84 result.fType = original.fType;
85 result.fRRectData.fRRect = original.fRRectData.fRRect;
86 result.fRRectData.fDir = kDefaultRRectDir;
87 result.fRRectData.fStart = kDefaultRRectStart;
88 result.fRRectData.fInverted = is_inverted(original.fRRectData.fInverted, inversion);
89 break;
Brian Salomone4949402018-04-26 15:22:04 -040090 case Type::kArc:
91 result.fType = original.fType;
92 result.fArcData.fOval = original.fArcData.fOval;
93 result.fArcData.fStartAngleDegrees = original.fArcData.fStartAngleDegrees;
94 result.fArcData.fSweepAngleDegrees = original.fArcData.fSweepAngleDegrees;
95 result.fArcData.fUseCenter = original.fArcData.fUseCenter;
96 result.fArcData.fInverted = is_inverted(original.fArcData.fInverted, inversion);
97 break;
Brian Salomon4f40caf2017-09-01 09:00:45 -040098 case Type::kLine:
99 // Lines don't fill.
100 if (is_inverted(original.fLineData.fInverted, inversion)) {
101 result.fType = Type::kInvertedEmpty;
102 } else {
103 result.fType = Type::kEmpty;
104 }
105 break;
106 case Type::kEmpty:
107 result.fType = is_inverted(false, inversion) ? Type::kInvertedEmpty : Type::kEmpty;
108 break;
109 case Type::kInvertedEmpty:
110 result.fType = is_inverted(true, inversion) ? Type::kInvertedEmpty : Type::kEmpty;
111 break;
112 case Type::kPath:
113 result.initType(Type::kPath, &original.fPathData.fPath);
114 result.fPathData.fGenID = original.fPathData.fGenID;
115 if (flip_inversion(original.fPathData.fPath.isInverseFillType(), inversion)) {
116 result.fPathData.fPath.toggleInverseFillType();
117 }
118 if (!original.style().isSimpleFill()) {
119 // Going from a non-filled style to fill may allow additional simplifications (e.g.
120 // closing an open rect that wasn't closed in the original shape because it had
121 // stroke style).
122 result.attemptToSimplifyPath();
123 }
124 break;
125 }
126 // We don't copy the inherited key since it can contain path effect information that we just
127 // stripped.
128 return result;
129}
130
bsalomon0a0f67e2016-06-28 11:56:42 -0700131SkRect GrShape::bounds() const {
bsalomon0ae36a22016-07-18 07:31:13 -0700132 // Bounds where left == bottom or top == right can indicate a line or point shape. We return
133 // inverted bounds for a truly empty shape.
134 static constexpr SkRect kInverted = SkRect::MakeLTRB(1, 1, -1, -1);
bsalomon9fb42032016-05-13 09:23:38 -0700135 switch (fType) {
136 case Type::kEmpty:
bsalomon0ae36a22016-07-18 07:31:13 -0700137 return kInverted;
Brian Salomon085c0862017-08-31 15:44:51 -0400138 case Type::kInvertedEmpty:
139 return kInverted;
bsalomon0a0f67e2016-06-28 11:56:42 -0700140 case Type::kLine: {
141 SkRect bounds;
142 if (fLineData.fPts[0].fX < fLineData.fPts[1].fX) {
143 bounds.fLeft = fLineData.fPts[0].fX;
144 bounds.fRight = fLineData.fPts[1].fX;
145 } else {
146 bounds.fLeft = fLineData.fPts[1].fX;
147 bounds.fRight = fLineData.fPts[0].fX;
148 }
149 if (fLineData.fPts[0].fY < fLineData.fPts[1].fY) {
150 bounds.fTop = fLineData.fPts[0].fY;
151 bounds.fBottom = fLineData.fPts[1].fY;
152 } else {
153 bounds.fTop = fLineData.fPts[1].fY;
154 bounds.fBottom = fLineData.fPts[0].fY;
155 }
156 return bounds;
157 }
bsalomon9fb42032016-05-13 09:23:38 -0700158 case Type::kRRect:
bsalomon728b0f72016-06-27 10:00:19 -0700159 return fRRectData.fRRect.getBounds();
Brian Salomone4949402018-04-26 15:22:04 -0400160 case Type::kArc:
161 // Could make this less conservative by looking at angles.
162 return fArcData.fOval;
bsalomon9fb42032016-05-13 09:23:38 -0700163 case Type::kPath:
bsalomon728b0f72016-06-27 10:00:19 -0700164 return this->path().getBounds();
bsalomon9fb42032016-05-13 09:23:38 -0700165 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400166 SK_ABORT("Unknown shape type");
bsalomon9fb42032016-05-13 09:23:38 -0700167}
168
bsalomon0a0f67e2016-06-28 11:56:42 -0700169SkRect GrShape::styledBounds() const {
Brian Salomon085c0862017-08-31 15:44:51 -0400170 if (this->isEmpty() && !fStyle.hasNonDashPathEffect()) {
bsalomon0a0f67e2016-06-28 11:56:42 -0700171 return SkRect::MakeEmpty();
bsalomon9fb42032016-05-13 09:23:38 -0700172 }
Brian Salomon085c0862017-08-31 15:44:51 -0400173
bsalomon0a0f67e2016-06-28 11:56:42 -0700174 SkRect bounds;
175 fStyle.adjustBounds(&bounds, this->bounds());
176 return bounds;
bsalomon9fb42032016-05-13 09:23:38 -0700177}
178
bsalomon67fa4e32016-09-21 08:26:57 -0700179// If the path is small enough to be keyed from its data this returns key length, otherwise -1.
180static int path_key_from_data_size(const SkPath& path) {
181 const int verbCnt = path.countVerbs();
182 if (verbCnt > GrShape::kMaxKeyFromDataVerbCnt) {
183 return -1;
184 }
185 const int pointCnt = path.countPoints();
186 const int conicWeightCnt = SkPathPriv::ConicWeightCnt(path);
187
188 GR_STATIC_ASSERT(sizeof(SkPoint) == 2 * sizeof(uint32_t));
189 GR_STATIC_ASSERT(sizeof(SkScalar) == sizeof(uint32_t));
190 // 2 is for the verb cnt and a fill type. Each verb is a byte but we'll pad the verb data out to
191 // a uint32_t length.
192 return 2 + (SkAlign4(verbCnt) >> 2) + 2 * pointCnt + conicWeightCnt;
193}
194
195// Writes the path data key into the passed pointer.
bsalomon0e4a4662016-09-21 11:23:46 -0700196static void write_path_key_from_data(const SkPath& path, uint32_t* origKey) {
bsalomon67fa4e32016-09-21 08:26:57 -0700197 uint32_t* key = origKey;
198 // The check below should take care of negative values casted positive.
199 const int verbCnt = path.countVerbs();
200 const int pointCnt = path.countPoints();
201 const int conicWeightCnt = SkPathPriv::ConicWeightCnt(path);
202 SkASSERT(verbCnt <= GrShape::kMaxKeyFromDataVerbCnt);
203 SkASSERT(pointCnt && verbCnt);
Mike Reede1af4442019-09-13 15:58:25 -0400204 *key++ = (uint32_t)path.getFillType();
bsalomon67fa4e32016-09-21 08:26:57 -0700205 *key++ = verbCnt;
206 memcpy(key, SkPathPriv::VerbData(path), verbCnt * sizeof(uint8_t));
207 int verbKeySize = SkAlign4(verbCnt);
208 // pad out to uint32_t alignment using value that will stand out when debugging.
209 uint8_t* pad = reinterpret_cast<uint8_t*>(key)+ verbCnt;
210 memset(pad, 0xDE, verbKeySize - verbCnt);
211 key += verbKeySize >> 2;
212
213 memcpy(key, SkPathPriv::PointData(path), sizeof(SkPoint) * pointCnt);
214 GR_STATIC_ASSERT(sizeof(SkPoint) == 2 * sizeof(uint32_t));
215 key += 2 * pointCnt;
bsalomon0e4a4662016-09-21 11:23:46 -0700216 sk_careful_memcpy(key, SkPathPriv::ConicWeightData(path), sizeof(SkScalar) * conicWeightCnt);
bsalomon67fa4e32016-09-21 08:26:57 -0700217 GR_STATIC_ASSERT(sizeof(SkScalar) == sizeof(uint32_t));
218 SkDEBUGCODE(key += conicWeightCnt);
219 SkASSERT(key - origKey == path_key_from_data_size(path));
220}
221
bsalomon47cc7692016-04-26 12:56:00 -0700222int GrShape::unstyledKeySize() const {
223 if (fInheritedKey.count()) {
224 return fInheritedKey.count();
225 }
226 switch (fType) {
227 case Type::kEmpty:
228 return 1;
Brian Salomon085c0862017-08-31 15:44:51 -0400229 case Type::kInvertedEmpty:
230 return 1;
bsalomon47cc7692016-04-26 12:56:00 -0700231 case Type::kRRect:
232 SkASSERT(!fInheritedKey.count());
Brian Salomone4949402018-04-26 15:22:04 -0400233 GR_STATIC_ASSERT(0 == SkRRect::kSizeInMemory % sizeof(uint32_t));
bsalomon70493962016-06-10 08:05:14 -0700234 // + 1 for the direction, start index, and inverseness.
bsalomonee295642016-06-06 14:01:25 -0700235 return SkRRect::kSizeInMemory / sizeof(uint32_t) + 1;
Brian Salomone4949402018-04-26 15:22:04 -0400236 case Type::kArc:
237 SkASSERT(!fInheritedKey.count());
238 GR_STATIC_ASSERT(0 == sizeof(fArcData) % sizeof(uint32_t));
239 return sizeof(fArcData) / sizeof(uint32_t);
bsalomon0a0f67e2016-06-28 11:56:42 -0700240 case Type::kLine:
241 GR_STATIC_ASSERT(2 * sizeof(uint32_t) == sizeof(SkPoint));
242 // 4 for the end points and 1 for the inverseness
243 return 5;
bsalomon67fa4e32016-09-21 08:26:57 -0700244 case Type::kPath: {
bsalomonaa840642016-09-23 12:09:16 -0700245 if (0 == fPathData.fGenID) {
246 return -1;
247 }
bsalomon67fa4e32016-09-21 08:26:57 -0700248 int dataKeySize = path_key_from_data_size(fPathData.fPath);
249 if (dataKeySize >= 0) {
250 return dataKeySize;
251 }
bsalomon67fa4e32016-09-21 08:26:57 -0700252 // The key is the path ID and fill type.
253 return 2;
254 }
bsalomon47cc7692016-04-26 12:56:00 -0700255 }
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400256 SK_ABORT("Should never get here.");
bsalomon47cc7692016-04-26 12:56:00 -0700257}
258
259void GrShape::writeUnstyledKey(uint32_t* key) const {
260 SkASSERT(this->unstyledKeySize());
261 SkDEBUGCODE(uint32_t* origKey = key;)
262 if (fInheritedKey.count()) {
263 memcpy(key, fInheritedKey.get(), sizeof(uint32_t) * fInheritedKey.count());
264 SkDEBUGCODE(key += fInheritedKey.count();)
265 } else {
266 switch (fType) {
267 case Type::kEmpty:
268 *key++ = 1;
269 break;
Brian Salomon085c0862017-08-31 15:44:51 -0400270 case Type::kInvertedEmpty:
271 *key++ = 2;
272 break;
bsalomon47cc7692016-04-26 12:56:00 -0700273 case Type::kRRect:
bsalomon728b0f72016-06-27 10:00:19 -0700274 fRRectData.fRRect.writeToMemory(key);
bsalomon47cc7692016-04-26 12:56:00 -0700275 key += SkRRect::kSizeInMemory / sizeof(uint32_t);
Mike Reede1af4442019-09-13 15:58:25 -0400276 *key = (fRRectData.fDir == SkPathDirection::kCCW) ? (1 << 31) : 0;
bsalomon728b0f72016-06-27 10:00:19 -0700277 *key |= fRRectData.fInverted ? (1 << 30) : 0;
278 *key++ |= fRRectData.fStart;
279 SkASSERT(fRRectData.fStart < 8);
bsalomon47cc7692016-04-26 12:56:00 -0700280 break;
Brian Salomone4949402018-04-26 15:22:04 -0400281 case Type::kArc:
282 memcpy(key, &fArcData, sizeof(fArcData));
283 key += sizeof(fArcData) / sizeof(uint32_t);
284 break;
bsalomon0a0f67e2016-06-28 11:56:42 -0700285 case Type::kLine:
286 memcpy(key, fLineData.fPts, 2 * sizeof(SkPoint));
287 key += 4;
288 *key++ = fLineData.fInverted ? 1 : 0;
289 break;
bsalomon67fa4e32016-09-21 08:26:57 -0700290 case Type::kPath: {
bsalomonaa840642016-09-23 12:09:16 -0700291 SkASSERT(fPathData.fGenID);
bsalomon67fa4e32016-09-21 08:26:57 -0700292 int dataKeySize = path_key_from_data_size(fPathData.fPath);
293 if (dataKeySize >= 0) {
bsalomon0e4a4662016-09-21 11:23:46 -0700294 write_path_key_from_data(fPathData.fPath, key);
bsalomon67fa4e32016-09-21 08:26:57 -0700295 return;
296 }
bsalomon728b0f72016-06-27 10:00:19 -0700297 *key++ = fPathData.fGenID;
bsalomon70493962016-06-10 08:05:14 -0700298 // We could canonicalize the fill rule for paths that don't differentiate between
299 // even/odd or winding fill (e.g. convex).
Mike Reede1af4442019-09-13 15:58:25 -0400300 *key++ = (uint32_t)this->path().getFillType();
bsalomon47cc7692016-04-26 12:56:00 -0700301 break;
bsalomon67fa4e32016-09-21 08:26:57 -0700302 }
bsalomon47cc7692016-04-26 12:56:00 -0700303 }
304 }
305 SkASSERT(key - origKey == this->unstyledKeySize());
306}
307
bsalomon97fd2d42016-05-09 13:02:01 -0700308void GrShape::setInheritedKey(const GrShape &parent, GrStyle::Apply apply, SkScalar scale) {
bsalomon47cc7692016-04-26 12:56:00 -0700309 SkASSERT(!fInheritedKey.count());
310 // If the output shape turns out to be simple, then we will just use its geometric key
311 if (Type::kPath == fType) {
312 // We want ApplyFullStyle(ApplyPathEffect(shape)) to have the same key as
313 // ApplyFullStyle(shape).
314 // The full key is structured as (geo,path_effect,stroke).
Brian Salomon4f40caf2017-09-01 09:00:45 -0400315 // If we do ApplyPathEffect we get geo,path_effect as the inherited key. If we then
bsalomon47cc7692016-04-26 12:56:00 -0700316 // do ApplyFullStyle we'll memcpy geo,path_effect into the new inherited key
317 // and then append the style key (which should now be stroke only) at the end.
318 int parentCnt = parent.fInheritedKey.count();
319 bool useParentGeoKey = !parentCnt;
320 if (useParentGeoKey) {
321 parentCnt = parent.unstyledKeySize();
bsalomon72dc51c2016-04-27 06:46:23 -0700322 if (parentCnt < 0) {
323 // The parent's geometry has no key so we will have no key.
bsalomon728b0f72016-06-27 10:00:19 -0700324 fPathData.fGenID = 0;
bsalomon72dc51c2016-04-27 06:46:23 -0700325 return;
326 }
bsalomon47cc7692016-04-26 12:56:00 -0700327 }
bsalomon06077562016-05-04 13:50:29 -0700328 uint32_t styleKeyFlags = 0;
329 if (parent.knownToBeClosed()) {
330 styleKeyFlags |= GrStyle::kClosed_KeyFlag;
331 }
bsalomon0ae36a22016-07-18 07:31:13 -0700332 if (parent.asLine(nullptr, nullptr)) {
333 styleKeyFlags |= GrStyle::kNoJoins_KeyFlag;
334 }
bsalomon06077562016-05-04 13:50:29 -0700335 int styleCnt = GrStyle::KeySize(parent.fStyle, apply, styleKeyFlags);
bsalomon47cc7692016-04-26 12:56:00 -0700336 if (styleCnt < 0) {
bsalomon93f66bc2016-06-21 08:35:49 -0700337 // The style doesn't allow a key, set the path gen ID to 0 so that we fail when
bsalomon47cc7692016-04-26 12:56:00 -0700338 // we try to get a key for the shape.
bsalomon728b0f72016-06-27 10:00:19 -0700339 fPathData.fGenID = 0;
bsalomon72dc51c2016-04-27 06:46:23 -0700340 return;
bsalomon47cc7692016-04-26 12:56:00 -0700341 }
bsalomon72dc51c2016-04-27 06:46:23 -0700342 fInheritedKey.reset(parentCnt + styleCnt);
343 if (useParentGeoKey) {
344 // This will be the geo key.
345 parent.writeUnstyledKey(fInheritedKey.get());
346 } else {
347 // This should be (geo,path_effect).
348 memcpy(fInheritedKey.get(), parent.fInheritedKey.get(),
349 parentCnt * sizeof(uint32_t));
350 }
351 // Now turn (geo,path_effect) or (geo) into (geo,path_effect,stroke)
bsalomon97fd2d42016-05-09 13:02:01 -0700352 GrStyle::WriteKey(fInheritedKey.get() + parentCnt, parent.fStyle, apply, scale,
353 styleKeyFlags);
bsalomon47cc7692016-04-26 12:56:00 -0700354 }
355}
356
Brian Salomonda6d0722018-01-03 13:54:35 -0500357const SkPath* GrShape::originalPathForListeners() const {
358 if (fInheritedPathForListeners.isValid()) {
359 return fInheritedPathForListeners.get();
360 } else if (Type::kPath == fType && !fPathData.fPath.isVolatile()) {
361 return &fPathData.fPath;
362 }
363 return nullptr;
Brian Osmanf6f7cf62017-09-25 16:49:55 -0400364}
365
Chris Daltonafa11582018-06-08 12:00:44 -0600366void GrShape::addGenIDChangeListener(sk_sp<SkPathRef::GenIDChangeListener> listener) const {
Brian Salomonda6d0722018-01-03 13:54:35 -0500367 if (const auto* lp = this->originalPathForListeners()) {
Chris Daltonafa11582018-06-08 12:00:44 -0600368 SkPathPriv::AddGenIDChangeListener(*lp, std::move(listener));
Brian Salomonda6d0722018-01-03 13:54:35 -0500369 }
370}
371
Brian Salomone4949402018-04-26 15:22:04 -0400372GrShape GrShape::MakeArc(const SkRect& oval, SkScalar startAngleDegrees, SkScalar sweepAngleDegrees,
373 bool useCenter, const GrStyle& style) {
Brian Salomone4949402018-04-26 15:22:04 -0400374 GrShape result;
375 result.changeType(Type::kArc);
376 result.fArcData.fOval = oval;
377 result.fArcData.fStartAngleDegrees = startAngleDegrees;
378 result.fArcData.fSweepAngleDegrees = sweepAngleDegrees;
379 result.fArcData.fUseCenter = useCenter;
380 result.fArcData.fInverted = false;
381 result.fStyle = style;
382 result.attemptToSimplifyArc();
383 return result;
Brian Salomone4949402018-04-26 15:22:04 -0400384}
385
Brian Salomonda6d0722018-01-03 13:54:35 -0500386GrShape::GrShape(const GrShape& that) : fStyle(that.fStyle) {
bsalomon728b0f72016-06-27 10:00:19 -0700387 const SkPath* thatPath = Type::kPath == that.fType ? &that.fPathData.fPath : nullptr;
388 this->initType(that.fType, thatPath);
bsalomon47cc7692016-04-26 12:56:00 -0700389 switch (fType) {
390 case Type::kEmpty:
bsalomon93f66bc2016-06-21 08:35:49 -0700391 break;
Brian Salomon085c0862017-08-31 15:44:51 -0400392 case Type::kInvertedEmpty:
393 break;
bsalomon47cc7692016-04-26 12:56:00 -0700394 case Type::kRRect:
bsalomon0a0f67e2016-06-28 11:56:42 -0700395 fRRectData = that.fRRectData;
396 break;
Brian Salomone4949402018-04-26 15:22:04 -0400397 case Type::kArc:
398 fArcData = that.fArcData;
399 break;
bsalomon0a0f67e2016-06-28 11:56:42 -0700400 case Type::kLine:
401 fLineData = that.fLineData;
bsalomon93f66bc2016-06-21 08:35:49 -0700402 break;
bsalomon47cc7692016-04-26 12:56:00 -0700403 case Type::kPath:
bsalomon728b0f72016-06-27 10:00:19 -0700404 fPathData.fGenID = that.fPathData.fGenID;
bsalomon93f66bc2016-06-21 08:35:49 -0700405 break;
bsalomon47cc7692016-04-26 12:56:00 -0700406 }
407 fInheritedKey.reset(that.fInheritedKey.count());
bsalomon93f66bc2016-06-21 08:35:49 -0700408 sk_careful_memcpy(fInheritedKey.get(), that.fInheritedKey.get(),
409 sizeof(uint32_t) * fInheritedKey.count());
Brian Salomonda6d0722018-01-03 13:54:35 -0500410 if (that.fInheritedPathForListeners.isValid()) {
411 fInheritedPathForListeners.set(*that.fInheritedPathForListeners.get());
412 }
bsalomon47cc7692016-04-26 12:56:00 -0700413}
414
bsalomon97fd2d42016-05-09 13:02:01 -0700415GrShape::GrShape(const GrShape& parent, GrStyle::Apply apply, SkScalar scale) {
416 // TODO: Add some quantization of scale for better cache performance here or leave that up
417 // to caller?
418 // TODO: For certain shapes and stroke params we could ignore the scale. (e.g. miter or bevel
419 // stroke of a rect).
bsalomonfb083272016-05-04 08:27:41 -0700420 if (!parent.style().applies() ||
421 (GrStyle::Apply::kPathEffectOnly == apply && !parent.style().pathEffect())) {
bsalomon728b0f72016-06-27 10:00:19 -0700422 this->initType(Type::kEmpty);
bsalomonfb083272016-05-04 08:27:41 -0700423 *this = parent;
424 return;
425 }
426
bsalomon47cc7692016-04-26 12:56:00 -0700427 SkPathEffect* pe = parent.fStyle.pathEffect();
bsalomonfb083272016-05-04 08:27:41 -0700428 SkTLazy<SkPath> tmpPath;
429 const GrShape* parentForKey = &parent;
430 SkTLazy<GrShape> tmpParent;
bsalomon728b0f72016-06-27 10:00:19 -0700431 this->initType(Type::kPath);
432 fPathData.fGenID = 0;
bsalomon47cc7692016-04-26 12:56:00 -0700433 if (pe) {
bsalomon728b0f72016-06-27 10:00:19 -0700434 const SkPath* srcForPathEffect;
bsalomon47cc7692016-04-26 12:56:00 -0700435 if (parent.fType == Type::kPath) {
bsalomon728b0f72016-06-27 10:00:19 -0700436 srcForPathEffect = &parent.path();
bsalomon47cc7692016-04-26 12:56:00 -0700437 } else {
bsalomonfb083272016-05-04 08:27:41 -0700438 srcForPathEffect = tmpPath.init();
439 parent.asPath(tmpPath.get());
bsalomon47cc7692016-04-26 12:56:00 -0700440 }
441 // Should we consider bounds? Would have to include in key, but it'd be nice to know
442 // if the bounds actually modified anything before including in key.
bsalomonfb083272016-05-04 08:27:41 -0700443 SkStrokeRec strokeRec = parent.fStyle.strokeRec();
bsalomon728b0f72016-06-27 10:00:19 -0700444 if (!parent.fStyle.applyPathEffectToPath(&this->path(), &strokeRec, *srcForPathEffect,
bsalomon398e3f42016-06-13 10:22:48 -0700445 scale)) {
bsalomon0ae36a22016-07-18 07:31:13 -0700446 tmpParent.init(*srcForPathEffect, GrStyle(strokeRec, nullptr));
447 *this = tmpParent.get()->applyStyle(apply, scale);
448 return;
bsalomon47cc7692016-04-26 12:56:00 -0700449 }
bsalomon97fd2d42016-05-09 13:02:01 -0700450 // A path effect has access to change the res scale but we aren't expecting it to and it
451 // would mess up our key computation.
452 SkASSERT(scale == strokeRec.getResScale());
bsalomon1b28c1a2016-06-20 12:28:17 -0700453 if (GrStyle::Apply::kPathEffectAndStrokeRec == apply && strokeRec.needToApply()) {
454 // The intermediate shape may not be a general path. If we we're just applying
455 // the path effect then attemptToReduceFromPath would catch it. This means that
456 // when we subsequently applied the remaining strokeRec we would have a non-path
457 // parent shape that would be used to determine the the stroked path's key.
458 // We detect that case here and change parentForKey to a temporary that represents
459 // the simpler shape so that applying both path effect and the strokerec all at
460 // once produces the same key.
bsalomon728b0f72016-06-27 10:00:19 -0700461 tmpParent.init(this->path(), GrStyle(strokeRec, nullptr));
bsalomon1b28c1a2016-06-20 12:28:17 -0700462 tmpParent.get()->setInheritedKey(parent, GrStyle::Apply::kPathEffectOnly, scale);
463 if (!tmpPath.isValid()) {
464 tmpPath.init();
bsalomon72dc51c2016-04-27 06:46:23 -0700465 }
bsalomon1b28c1a2016-06-20 12:28:17 -0700466 tmpParent.get()->asPath(tmpPath.get());
467 SkStrokeRec::InitStyle fillOrHairline;
bsalomon0ae36a22016-07-18 07:31:13 -0700468 // The parent shape may have simplified away the strokeRec, check for that here.
469 if (tmpParent.get()->style().applies()) {
470 SkAssertResult(tmpParent.get()->style().applyToPath(&this->path(), &fillOrHairline,
471 *tmpPath.get(), scale));
472 } else if (tmpParent.get()->style().isSimpleFill()) {
473 fillOrHairline = SkStrokeRec::kFill_InitStyle;
474 } else {
475 SkASSERT(tmpParent.get()->style().isSimpleHairline());
476 fillOrHairline = SkStrokeRec::kHairline_InitStyle;
477 }
bsalomon1b28c1a2016-06-20 12:28:17 -0700478 fStyle.resetToInitStyle(fillOrHairline);
479 parentForKey = tmpParent.get();
bsalomonfb083272016-05-04 08:27:41 -0700480 } else {
481 fStyle = GrStyle(strokeRec, nullptr);
bsalomon72dc51c2016-04-27 06:46:23 -0700482 }
bsalomon47cc7692016-04-26 12:56:00 -0700483 } else {
bsalomon97fd2d42016-05-09 13:02:01 -0700484 const SkPath* srcForParentStyle;
bsalomonfb083272016-05-04 08:27:41 -0700485 if (parent.fType == Type::kPath) {
bsalomon728b0f72016-06-27 10:00:19 -0700486 srcForParentStyle = &parent.path();
bsalomonfb083272016-05-04 08:27:41 -0700487 } else {
bsalomon97fd2d42016-05-09 13:02:01 -0700488 srcForParentStyle = tmpPath.init();
bsalomonfb083272016-05-04 08:27:41 -0700489 parent.asPath(tmpPath.get());
490 }
bsalomon97fd2d42016-05-09 13:02:01 -0700491 SkStrokeRec::InitStyle fillOrHairline;
492 SkASSERT(parent.fStyle.applies());
493 SkASSERT(!parent.fStyle.pathEffect());
bsalomon728b0f72016-06-27 10:00:19 -0700494 SkAssertResult(parent.fStyle.applyToPath(&this->path(), &fillOrHairline, *srcForParentStyle,
bsalomon97fd2d42016-05-09 13:02:01 -0700495 scale));
496 fStyle.resetToInitStyle(fillOrHairline);
bsalomon47cc7692016-04-26 12:56:00 -0700497 }
Brian Salomonda6d0722018-01-03 13:54:35 -0500498 if (parent.fInheritedPathForListeners.isValid()) {
499 fInheritedPathForListeners.set(*parent.fInheritedPathForListeners.get());
500 } else if (Type::kPath == parent.fType && !parent.fPathData.fPath.isVolatile()) {
501 fInheritedPathForListeners.set(parent.fPathData.fPath);
502 }
bsalomon1b28c1a2016-06-20 12:28:17 -0700503 this->attemptToSimplifyPath();
bsalomon97fd2d42016-05-09 13:02:01 -0700504 this->setInheritedKey(*parentForKey, apply, scale);
bsalomon47cc7692016-04-26 12:56:00 -0700505}
bsalomonee295642016-06-06 14:01:25 -0700506
bsalomon1b28c1a2016-06-20 12:28:17 -0700507void GrShape::attemptToSimplifyPath() {
bsalomonee295642016-06-06 14:01:25 -0700508 SkRect rect;
bsalomon728b0f72016-06-27 10:00:19 -0700509 SkRRect rrect;
Mike Reede1af4442019-09-13 15:58:25 -0400510 SkPathDirection rrectDir;
bsalomon728b0f72016-06-27 10:00:19 -0700511 unsigned rrectStart;
512 bool inverted = this->path().isInverseFillType();
bsalomon0a0f67e2016-06-28 11:56:42 -0700513 SkPoint pts[2];
bsalomon728b0f72016-06-27 10:00:19 -0700514 if (this->path().isEmpty()) {
Brian Salomon085c0862017-08-31 15:44:51 -0400515 // Dashing ignores inverseness skbug.com/5421.
516 this->changeType(inverted && !this->style().isDashed() ? Type::kInvertedEmpty
517 : Type::kEmpty);
bsalomon0a0f67e2016-06-28 11:56:42 -0700518 } else if (this->path().isLine(pts)) {
519 this->changeType(Type::kLine);
520 fLineData.fPts[0] = pts[0];
521 fLineData.fPts[1] = pts[1];
522 fLineData.fInverted = inverted;
Mike Reed0c3137c2018-02-20 13:57:05 -0500523 } else if (SkPathPriv::IsRRect(this->path(), &rrect, &rrectDir, &rrectStart)) {
bsalomon728b0f72016-06-27 10:00:19 -0700524 this->changeType(Type::kRRect);
525 fRRectData.fRRect = rrect;
526 fRRectData.fDir = rrectDir;
527 fRRectData.fStart = rrectStart;
528 fRRectData.fInverted = inverted;
bsalomon728b0f72016-06-27 10:00:19 -0700529 SkASSERT(!fRRectData.fRRect.isEmpty());
Mike Reed0c3137c2018-02-20 13:57:05 -0500530 } else if (SkPathPriv::IsOval(this->path(), &rect, &rrectDir, &rrectStart)) {
bsalomon728b0f72016-06-27 10:00:19 -0700531 this->changeType(Type::kRRect);
532 fRRectData.fRRect.setOval(rect);
533 fRRectData.fDir = rrectDir;
534 fRRectData.fInverted = inverted;
bsalomon1b28c1a2016-06-20 12:28:17 -0700535 // convert from oval indexing to rrect indexiing.
bsalomon728b0f72016-06-27 10:00:19 -0700536 fRRectData.fStart = 2 * rrectStart;
537 } else if (SkPathPriv::IsSimpleClosedRect(this->path(), &rect, &rrectDir, &rrectStart)) {
538 this->changeType(Type::kRRect);
bsalomon1b28c1a2016-06-20 12:28:17 -0700539 // When there is a path effect we restrict rect detection to the narrower API that
540 // gives us the starting position. Otherwise, we will retry with the more aggressive
541 // isRect().
bsalomon728b0f72016-06-27 10:00:19 -0700542 fRRectData.fRRect.setRect(rect);
543 fRRectData.fInverted = inverted;
544 fRRectData.fDir = rrectDir;
bsalomon1b28c1a2016-06-20 12:28:17 -0700545 // convert from rect indexing to rrect indexiing.
bsalomon728b0f72016-06-27 10:00:19 -0700546 fRRectData.fStart = 2 * rrectStart;
bsalomon1b28c1a2016-06-20 12:28:17 -0700547 } else if (!this->style().hasPathEffect()) {
bsalomonee295642016-06-06 14:01:25 -0700548 bool closed;
bsalomon728b0f72016-06-27 10:00:19 -0700549 if (this->path().isRect(&rect, &closed, nullptr)) {
bsalomon1b28c1a2016-06-20 12:28:17 -0700550 if (closed || this->style().isSimpleFill()) {
bsalomon728b0f72016-06-27 10:00:19 -0700551 this->changeType(Type::kRRect);
552 fRRectData.fRRect.setRect(rect);
bsalomonee295642016-06-06 14:01:25 -0700553 // Since there is no path effect the dir and start index is immaterial.
bsalomon728b0f72016-06-27 10:00:19 -0700554 fRRectData.fDir = kDefaultRRectDir;
555 fRRectData.fStart = kDefaultRRectStart;
bsalomon1b28c1a2016-06-20 12:28:17 -0700556 // There isn't dashing so we will have to preserver inverseness.
bsalomon728b0f72016-06-27 10:00:19 -0700557 fRRectData.fInverted = inverted;
bsalomonee295642016-06-06 14:01:25 -0700558 }
559 }
560 }
bsalomon1b28c1a2016-06-20 12:28:17 -0700561 if (Type::kPath != fType) {
bsalomon1b28c1a2016-06-20 12:28:17 -0700562 fInheritedKey.reset(0);
Brian Osmanb379dcd2017-10-04 15:44:05 -0400563 // Whenever we simplify to a non-path, break the chain so we no longer refer to the
564 // original path. This prevents attaching genID listeners to temporary paths created when
565 // drawing simple shapes.
Brian Salomonda6d0722018-01-03 13:54:35 -0500566 fInheritedPathForListeners.reset();
bsalomon1b28c1a2016-06-20 12:28:17 -0700567 if (Type::kRRect == fType) {
568 this->attemptToSimplifyRRect();
bsalomon0a0f67e2016-06-28 11:56:42 -0700569 } else if (Type::kLine == fType) {
570 this->attemptToSimplifyLine();
bsalomon1b28c1a2016-06-20 12:28:17 -0700571 }
bsalomon93f66bc2016-06-21 08:35:49 -0700572 } else {
bsalomon728b0f72016-06-27 10:00:19 -0700573 if (fInheritedKey.count() || this->path().isVolatile()) {
574 fPathData.fGenID = 0;
bsalomon93f66bc2016-06-21 08:35:49 -0700575 } else {
bsalomon728b0f72016-06-27 10:00:19 -0700576 fPathData.fGenID = this->path().getGenerationID();
bsalomon93f66bc2016-06-21 08:35:49 -0700577 }
bsalomona4817af2016-06-23 11:48:26 -0700578 if (!this->style().hasNonDashPathEffect()) {
579 if (this->style().strokeRec().getStyle() == SkStrokeRec::kStroke_Style ||
580 this->style().strokeRec().getStyle() == SkStrokeRec::kHairline_Style) {
581 // Stroke styles don't differentiate between winding and even/odd.
582 // Moreover, dashing ignores inverseness (skbug.com/5421)
bsalomon728b0f72016-06-27 10:00:19 -0700583 bool inverse = !this->style().isDashed() && this->path().isInverseFillType();
bsalomona4817af2016-06-23 11:48:26 -0700584 if (inverse) {
bsalomon728b0f72016-06-27 10:00:19 -0700585 this->path().setFillType(kDefaultPathInverseFillType);
bsalomona4817af2016-06-23 11:48:26 -0700586 } else {
bsalomon728b0f72016-06-27 10:00:19 -0700587 this->path().setFillType(kDefaultPathFillType);
bsalomona4817af2016-06-23 11:48:26 -0700588 }
bsalomon728b0f72016-06-27 10:00:19 -0700589 } else if (this->path().isConvex()) {
bsalomona4817af2016-06-23 11:48:26 -0700590 // There is no distinction between even/odd and non-zero winding count for convex
591 // paths.
bsalomon728b0f72016-06-27 10:00:19 -0700592 if (this->path().isInverseFillType()) {
593 this->path().setFillType(kDefaultPathInverseFillType);
bsalomona4817af2016-06-23 11:48:26 -0700594 } else {
bsalomon728b0f72016-06-27 10:00:19 -0700595 this->path().setFillType(kDefaultPathFillType);
bsalomona4817af2016-06-23 11:48:26 -0700596 }
bsalomon93f66bc2016-06-21 08:35:49 -0700597 }
598 }
bsalomon1b28c1a2016-06-20 12:28:17 -0700599 }
600}
601
602void GrShape::attemptToSimplifyRRect() {
603 SkASSERT(Type::kRRect == fType);
604 SkASSERT(!fInheritedKey.count());
bsalomon728b0f72016-06-27 10:00:19 -0700605 if (fRRectData.fRRect.isEmpty()) {
Brian Salomon2fad74a2017-12-20 13:28:55 -0500606 // An empty filled rrect is equivalent to a filled empty path with inversion preserved.
607 if (fStyle.isSimpleFill()) {
608 fType = fRRectData.fInverted ? Type::kInvertedEmpty : Type::kEmpty;
609 fStyle = GrStyle::SimpleFill();
610 return;
611 }
612 // Dashing a rrect with no width or height is equivalent to filling an emtpy path.
613 // When skbug.com/7387 is fixed this should be modified or removed as a dashed zero length
614 // line will produce cap geometry if the effect begins in an "on" interval.
615 if (fStyle.isDashed() && !fRRectData.fRRect.width() && !fRRectData.fRRect.height()) {
616 // Dashing ignores the inverseness (currently). skbug.com/5421.
617 fType = Type::kEmpty;
618 fStyle = GrStyle::SimpleFill();
619 return;
620 }
bsalomon1b28c1a2016-06-20 12:28:17 -0700621 }
622 if (!this->style().hasPathEffect()) {
bsalomon728b0f72016-06-27 10:00:19 -0700623 fRRectData.fDir = kDefaultRRectDir;
624 fRRectData.fStart = kDefaultRRectStart;
bsalomon1b28c1a2016-06-20 12:28:17 -0700625 } else if (fStyle.isDashed()) {
626 // Dashing ignores the inverseness (currently). skbug.com/5421
bsalomon728b0f72016-06-27 10:00:19 -0700627 fRRectData.fInverted = false;
Brian Salomone4949402018-04-26 15:22:04 -0400628 // Possible TODO here: Check whether the dash results in a single arc or line.
bsalomon1b28c1a2016-06-20 12:28:17 -0700629 }
bsalomon487f8d32016-07-20 07:15:44 -0700630 // Turn a stroke-and-filled miter rect into a filled rect. TODO: more rrect stroke shortcuts.
631 if (!fStyle.hasPathEffect() &&
632 fStyle.strokeRec().getStyle() == SkStrokeRec::kStrokeAndFill_Style &&
633 fStyle.strokeRec().getJoin() == SkPaint::kMiter_Join &&
634 fStyle.strokeRec().getMiter() >= SK_ScalarSqrt2 &&
635 fRRectData.fRRect.isRect()) {
636 SkScalar r = fStyle.strokeRec().getWidth() / 2;
637 fRRectData.fRRect = SkRRect::MakeRect(fRRectData.fRRect.rect().makeOutset(r, r));
638 fStyle = GrStyle::SimpleFill();
639 }
bsalomonee295642016-06-06 14:01:25 -0700640}
bsalomon0a0f67e2016-06-28 11:56:42 -0700641
642void GrShape::attemptToSimplifyLine() {
bsalomon0ae36a22016-07-18 07:31:13 -0700643 SkASSERT(Type::kLine == fType);
644 SkASSERT(!fInheritedKey.count());
645 if (fStyle.isDashed()) {
Brian Salomon72f78c32017-12-21 11:56:42 -0500646 bool allOffsZero = true;
647 for (int i = 1; i < fStyle.dashIntervalCnt() && allOffsZero; i += 2) {
648 allOffsZero = !fStyle.dashIntervals()[i];
649 }
650 if (allOffsZero && this->attemptToSimplifyStrokedLineToRRect()) {
651 return;
652 }
bsalomon0ae36a22016-07-18 07:31:13 -0700653 // Dashing ignores inverseness.
654 fLineData.fInverted = false;
655 return;
656 } else if (fStyle.hasPathEffect()) {
657 return;
658 }
659 if (fStyle.strokeRec().getStyle() == SkStrokeRec::kStrokeAndFill_Style) {
660 // Make stroke + fill be stroke since the fill is empty.
661 SkStrokeRec rec = fStyle.strokeRec();
662 rec.setStrokeStyle(fStyle.strokeRec().getWidth(), false);
663 fStyle = GrStyle(rec, nullptr);
664 }
Brian Salomon085c0862017-08-31 15:44:51 -0400665 if (fStyle.isSimpleFill()) {
666 this->changeType(fLineData.fInverted ? Type::kInvertedEmpty : Type::kEmpty);
bsalomon0ae36a22016-07-18 07:31:13 -0700667 return;
668 }
Brian Salomon72f78c32017-12-21 11:56:42 -0500669 if (fStyle.strokeRec().getStyle() == SkStrokeRec::kStroke_Style &&
670 this->attemptToSimplifyStrokedLineToRRect()) {
671 return;
bsalomon0a0f67e2016-06-28 11:56:42 -0700672 }
bsalomon0ae36a22016-07-18 07:31:13 -0700673 // Only path effects could care about the order of the points. Otherwise canonicalize
674 // the point order.
Brian Salomon72f78c32017-12-21 11:56:42 -0500675 SkPoint* pts = fLineData.fPts;
bsalomon0ae36a22016-07-18 07:31:13 -0700676 if (pts[1].fY < pts[0].fY || (pts[1].fY == pts[0].fY && pts[1].fX < pts[0].fX)) {
Ben Wagnerf08d1d02018-06-18 15:11:00 -0400677 using std::swap;
678 swap(pts[0], pts[1]);
bsalomon0ae36a22016-07-18 07:31:13 -0700679 }
bsalomon0a0f67e2016-06-28 11:56:42 -0700680}
Brian Salomon72f78c32017-12-21 11:56:42 -0500681
Brian Salomone4949402018-04-26 15:22:04 -0400682void GrShape::attemptToSimplifyArc() {
683 SkASSERT(fType == Type::kArc);
684 SkASSERT(!fArcData.fInverted);
685 if (fArcData.fOval.isEmpty() || !fArcData.fSweepAngleDegrees) {
686 this->changeType(Type::kEmpty);
687 return;
688 }
689
690 // Assuming no path effect, a filled, stroked, hairline, or stroke-and-filled arc that traverses
691 // the full circle and doesn't use the center point is an oval. Unless it has square or round
692 // caps. They may protrude out of the oval. Round caps can't protrude out of a circle but we're
693 // ignoring that for now.
694 if (fStyle.isSimpleFill() || (!fStyle.pathEffect() && !fArcData.fUseCenter &&
695 fStyle.strokeRec().getCap() == SkPaint::kButt_Cap)) {
696 if (fArcData.fSweepAngleDegrees >= 360.f || fArcData.fSweepAngleDegrees <= -360.f) {
697 auto oval = fArcData.fOval;
698 this->changeType(Type::kRRect);
699 this->fRRectData.fRRect.setOval(oval);
700 this->fRRectData.fDir = kDefaultRRectDir;
701 this->fRRectData.fStart = kDefaultRRectStart;
702 this->fRRectData.fInverted = false;
703 return;
704 }
705 }
706 if (!fStyle.pathEffect()) {
707 // Canonicalize the arc such that the start is always in [0, 360) and the sweep is always
708 // positive.
709 if (fArcData.fSweepAngleDegrees < 0) {
710 fArcData.fStartAngleDegrees = fArcData.fStartAngleDegrees + fArcData.fSweepAngleDegrees;
711 fArcData.fSweepAngleDegrees = -fArcData.fSweepAngleDegrees;
712 }
713 }
714 if (this->fArcData.fStartAngleDegrees < 0 || this->fArcData.fStartAngleDegrees >= 360.f) {
715 this->fArcData.fStartAngleDegrees = SkScalarMod(this->fArcData.fStartAngleDegrees, 360.f);
716 }
717 // Possible TODOs here: Look at whether dash pattern results in a single dash and convert to
718 // non-dashed stroke. Stroke and fill can be fill if circular and no path effect. Just stroke
719 // could as well if the stroke fills the center.
720}
721
Brian Salomon72f78c32017-12-21 11:56:42 -0500722bool GrShape::attemptToSimplifyStrokedLineToRRect() {
723 SkASSERT(Type::kLine == fType);
724 SkASSERT(fStyle.strokeRec().getStyle() == SkStrokeRec::kStroke_Style);
725
726 SkRect rect;
727 SkVector outset;
728 // If we allowed a rotation angle for rrects we could capture all cases here.
729 if (fLineData.fPts[0].fY == fLineData.fPts[1].fY) {
730 rect.fLeft = SkTMin(fLineData.fPts[0].fX, fLineData.fPts[1].fX);
731 rect.fRight = SkTMax(fLineData.fPts[0].fX, fLineData.fPts[1].fX);
732 rect.fTop = rect.fBottom = fLineData.fPts[0].fY;
733 outset.fY = fStyle.strokeRec().getWidth() / 2.f;
734 outset.fX = SkPaint::kButt_Cap == fStyle.strokeRec().getCap() ? 0.f : outset.fY;
735 } else if (fLineData.fPts[0].fX == fLineData.fPts[1].fX) {
736 rect.fTop = SkTMin(fLineData.fPts[0].fY, fLineData.fPts[1].fY);
737 rect.fBottom = SkTMax(fLineData.fPts[0].fY, fLineData.fPts[1].fY);
738 rect.fLeft = rect.fRight = fLineData.fPts[0].fX;
739 outset.fX = fStyle.strokeRec().getWidth() / 2.f;
740 outset.fY = SkPaint::kButt_Cap == fStyle.strokeRec().getCap() ? 0.f : outset.fX;
741 } else {
742 return false;
743 }
744 rect.outset(outset.fX, outset.fY);
745 if (rect.isEmpty()) {
746 this->changeType(Type::kEmpty);
747 fStyle = GrStyle::SimpleFill();
748 return true;
749 }
750 SkRRect rrect;
751 if (fStyle.strokeRec().getCap() == SkPaint::kRound_Cap) {
752 SkASSERT(outset.fX == outset.fY);
753 rrect = SkRRect::MakeRectXY(rect, outset.fX, outset.fY);
754 } else {
755 rrect = SkRRect::MakeRect(rect);
756 }
757 bool inverted = fLineData.fInverted && !fStyle.hasPathEffect();
758 this->changeType(Type::kRRect);
759 fRRectData.fRRect = rrect;
760 fRRectData.fInverted = inverted;
761 fRRectData.fDir = kDefaultRRectDir;
762 fRRectData.fStart = kDefaultRRectStart;
763 fStyle = GrStyle::SimpleFill();
764 return true;
765}