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

Side by Side Diff: src/core/SkPathRef.cpp

Issue 89123002: Move fIsOval from SkPath to SkPathRef (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Updated to add backwards compatibility from v16 to v15 Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkPath.cpp ('k') | src/core/SkPicture.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 2013 Google Inc. 2 * Copyright 2013 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 "SkBuffer.h" 8 #include "SkBuffer.h"
9 #include "SkOnce.h" 9 #include "SkOnce.h"
10 #include "SkPath.h" 10 #include "SkPath.h"
11 #include "SkPathRef.h" 11 #include "SkPathRef.h"
12 12
13 SK_DEFINE_INST_COUNT(SkPathRef); 13 SK_DEFINE_INST_COUNT(SkPathRef);
14 14
15 ////////////////////////////////////////////////////////////////////////////// 15 //////////////////////////////////////////////////////////////////////////////
16 SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef, 16 SkPathRef::Editor::Editor(SkAutoTUnref<SkPathRef>* pathRef,
17 int incReserveVerbs, 17 int incReserveVerbs,
18 int incReservePoints) 18 int incReservePoints)
19 { 19 {
20 if ((*pathRef)->unique()) { 20 if ((*pathRef)->unique()) {
21 (*pathRef)->incReserve(incReserveVerbs, incReservePoints); 21 (*pathRef)->incReserve(incReserveVerbs, incReservePoints);
22 } else { 22 } else {
23 SkPathRef* copy = SkNEW(SkPathRef); 23 SkPathRef* copy = SkNEW(SkPathRef);
24 copy->copy(**pathRef, incReserveVerbs, incReservePoints); 24 copy->copy(**pathRef, incReserveVerbs, incReservePoints);
25 pathRef->reset(copy); 25 pathRef->reset(copy);
26 } 26 }
27 fPathRef = *pathRef; 27 fPathRef = *pathRef;
28 fPathRef->fGenerationID = 0; 28 fPathRef->fGenerationID = 0;
29 fPathRef->fIsOval = false;
29 SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);) 30 SkDEBUGCODE(sk_atomic_inc(&fPathRef->fEditorsAttached);)
30 } 31 }
31 32
32 SkPoint* SkPathRef::Editor::growForConic(SkScalar w) { 33 SkPoint* SkPathRef::Editor::growForConic(SkScalar w) {
33 SkDEBUGCODE(fPathRef->validate();) 34 SkDEBUGCODE(fPathRef->validate();)
34 SkPoint* pts = fPathRef->growForVerb(SkPath::kConic_Verb); 35 SkPoint* pts = fPathRef->growForVerb(SkPath::kConic_Verb);
35 *fPathRef->fConicWeights.append() = w; 36 *fPathRef->fConicWeights.append() = w;
36 return pts; 37 return pts;
37 } 38 }
38 39
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 (*dst)->fBounds.setEmpty(); 94 (*dst)->fBounds.setEmpty();
94 } 95 }
95 } else { 96 } else {
96 (*dst)->fIsFinite = false; 97 (*dst)->fIsFinite = false;
97 (*dst)->fBounds.setEmpty(); 98 (*dst)->fBounds.setEmpty();
98 } 99 }
99 } else { 100 } else {
100 (*dst)->fBoundsIsDirty = true; 101 (*dst)->fBoundsIsDirty = true;
101 } 102 }
102 103
104 // It's an oval only if it stays a rect.
105 (*dst)->fIsOval = src.fIsOval && matrix.rectStaysRect();
106
103 SkDEBUGCODE((*dst)->validate();) 107 SkDEBUGCODE((*dst)->validate();)
104 } 108 }
105 109
106 SkPathRef* SkPathRef::CreateFromBuffer(SkRBuffer* buffer 110 SkPathRef* SkPathRef::CreateFromBuffer(SkRBuffer* buffer
107 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O 111 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TO O
108 , bool newFormat, int32_t oldPacked 112 , bool newFormat, int32_t oldPacked
109 #endif 113 #endif
110 ) { 114 ) {
111 SkPathRef* ref = SkNEW(SkPathRef); 115 SkPathRef* ref = SkNEW(SkPathRef);
112 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O 116 bool isOval;
117
118 int32_t packed;
119 if (!buffer->readS32(&packed)) {
120 SkDELETE(ref);
121 return NULL;
122 }
123
124 ref->fIsFinite = (packed >> kIsFinite_SerializationShift) & 1;
125
126 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TO O
113 if (newFormat) { 127 if (newFormat) {
114 #endif 128 #endif
115 int32_t packed; 129 isOval = (packed >> kIsOval_SerializationShift) & 1;
116 if (!buffer->readS32(&packed)) { 130 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TO O
117 SkDELETE(ref);
118 return NULL;
119 }
120
121 ref->fIsFinite = (packed >> kIsFinite_SerializationShift) & 1;
122 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O
123 } else { 131 } else {
124 ref->fIsFinite = (oldPacked >> SkPath::kOldIsFinite_SerializationShift) & 1; 132 isOval = (oldPacked >> SkPath::kOldIsOval_SerializationShift) & 1;
125 } 133 }
126 #endif 134 #endif
127 135
128 int32_t verbCount, pointCount, conicCount; 136 int32_t verbCount, pointCount, conicCount;
129 if (!buffer->readU32(&(ref->fGenerationID)) || 137 if (!buffer->readU32(&(ref->fGenerationID)) ||
130 !buffer->readS32(&verbCount) || 138 !buffer->readS32(&verbCount) ||
131 !buffer->readS32(&pointCount) || 139 !buffer->readS32(&pointCount) ||
132 !buffer->readS32(&conicCount)) { 140 !buffer->readS32(&conicCount)) {
133 SkDELETE(ref); 141 SkDELETE(ref);
134 return NULL; 142 return NULL;
135 } 143 }
136 144
137 ref->resetToSize(verbCount, pointCount, conicCount); 145 ref->resetToSize(verbCount, pointCount, conicCount);
138 SkASSERT(verbCount == ref->countVerbs()); 146 SkASSERT(verbCount == ref->countVerbs());
139 SkASSERT(pointCount == ref->countPoints()); 147 SkASSERT(pointCount == ref->countPoints());
140 SkASSERT(conicCount == ref->fConicWeights.count()); 148 SkASSERT(conicCount == ref->fConicWeights.count());
141 149
142 if (!buffer->read(ref->verbsMemWritable(), verbCount * sizeof(uint8_t)) || 150 if (!buffer->read(ref->verbsMemWritable(), verbCount * sizeof(uint8_t)) ||
143 !buffer->read(ref->fPoints, pointCount * sizeof(SkPoint)) || 151 !buffer->read(ref->fPoints, pointCount * sizeof(SkPoint)) ||
144 !buffer->read(ref->fConicWeights.begin(), conicCount * sizeof(SkScalar)) || 152 !buffer->read(ref->fConicWeights.begin(), conicCount * sizeof(SkScalar)) ||
145 !buffer->read(&ref->fBounds, sizeof(SkRect))) { 153 !buffer->read(&ref->fBounds, sizeof(SkRect))) {
146 SkDELETE(ref); 154 SkDELETE(ref);
147 return NULL; 155 return NULL;
148 } 156 }
149 ref->fBoundsIsDirty = false; 157 ref->fBoundsIsDirty = false;
158 ref->fIsOval = isOval;
150 return ref; 159 return ref;
151 } 160 }
152 161
153 void SkPathRef::Rewind(SkAutoTUnref<SkPathRef>* pathRef) { 162 void SkPathRef::Rewind(SkAutoTUnref<SkPathRef>* pathRef) {
154 if ((*pathRef)->unique()) { 163 if ((*pathRef)->unique()) {
155 SkDEBUGCODE((*pathRef)->validate();) 164 SkDEBUGCODE((*pathRef)->validate();)
156 (*pathRef)->fBoundsIsDirty = true; // this also invalidates fIsFinite 165 (*pathRef)->fBoundsIsDirty = true; // this also invalidates fIsFinite
157 (*pathRef)->fVerbCnt = 0; 166 (*pathRef)->fVerbCnt = 0;
158 (*pathRef)->fPointCnt = 0; 167 (*pathRef)->fPointCnt = 0;
159 (*pathRef)->fFreeSpace = (*pathRef)->currSize(); 168 (*pathRef)->fFreeSpace = (*pathRef)->currSize();
160 (*pathRef)->fGenerationID = 0; 169 (*pathRef)->fGenerationID = 0;
161 (*pathRef)->fConicWeights.rewind(); 170 (*pathRef)->fConicWeights.rewind();
171 (*pathRef)->fIsOval = false;
162 SkDEBUGCODE((*pathRef)->validate();) 172 SkDEBUGCODE((*pathRef)->validate();)
163 } else { 173 } else {
164 int oldVCnt = (*pathRef)->countVerbs(); 174 int oldVCnt = (*pathRef)->countVerbs();
165 int oldPCnt = (*pathRef)->countPoints(); 175 int oldPCnt = (*pathRef)->countPoints();
166 pathRef->reset(SkNEW(SkPathRef)); 176 pathRef->reset(SkNEW(SkPathRef));
167 (*pathRef)->resetToSize(0, 0, 0, oldVCnt, oldPCnt); 177 (*pathRef)->resetToSize(0, 0, 0, oldVCnt, oldPCnt);
168 } 178 }
169 } 179 }
170 180
171 bool SkPathRef::operator== (const SkPathRef& ref) const { 181 bool SkPathRef::operator== (const SkPathRef& ref) const {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 219 }
210 220
211 void SkPathRef::writeToBuffer(SkWBuffer* buffer) { 221 void SkPathRef::writeToBuffer(SkWBuffer* buffer) {
212 SkDEBUGCODE(this->validate();) 222 SkDEBUGCODE(this->validate();)
213 SkDEBUGCODE(size_t beforePos = buffer->pos();) 223 SkDEBUGCODE(size_t beforePos = buffer->pos();)
214 224
215 // Call getBounds() to ensure (as a side-effect) that fBounds 225 // Call getBounds() to ensure (as a side-effect) that fBounds
216 // and fIsFinite are computed. 226 // and fIsFinite are computed.
217 const SkRect& bounds = this->getBounds(); 227 const SkRect& bounds = this->getBounds();
218 228
219 int32_t packed = ((fIsFinite & 1) << kIsFinite_SerializationShift); 229 int32_t packed = ((fIsFinite & 1) << kIsFinite_SerializationShift) |
230 ((fIsOval & 1) << kIsOval_SerializationShift);
220 buffer->write32(packed); 231 buffer->write32(packed);
221 232
222 // TODO: write gen ID here. Problem: We don't know if we're cross process or not from 233 // TODO: write gen ID here. Problem: We don't know if we're cross process or not from
223 // SkWBuffer. Until this is fixed we write 0. 234 // SkWBuffer. Until this is fixed we write 0.
224 buffer->write32(0); 235 buffer->write32(0);
225 buffer->write32(fVerbCnt); 236 buffer->write32(fVerbCnt);
226 buffer->write32(fPointCnt); 237 buffer->write32(fPointCnt);
227 buffer->write32(fConicWeights.count()); 238 buffer->write32(fConicWeights.count());
228 buffer->write(verbsMemBegin(), fVerbCnt * sizeof(uint8_t)); 239 buffer->write(verbsMemBegin(), fVerbCnt * sizeof(uint8_t));
229 buffer->write(fPoints, fPointCnt * sizeof(SkPoint)); 240 buffer->write(fPoints, fPointCnt * sizeof(SkPoint));
(...skipping 21 matching lines...) Expand all
251 memcpy(this->fPoints, ref.fPoints, ref.fPointCnt * sizeof(SkPoint)); 262 memcpy(this->fPoints, ref.fPoints, ref.fPointCnt * sizeof(SkPoint));
252 fConicWeights = ref.fConicWeights; 263 fConicWeights = ref.fConicWeights;
253 // We could call genID() here to force a real ID (instead of 0). However, if we're making 264 // We could call genID() here to force a real ID (instead of 0). However, if we're making
254 // a copy then presumably we intend to make a modification immediately after wards. 265 // a copy then presumably we intend to make a modification immediately after wards.
255 fGenerationID = ref.fGenerationID; 266 fGenerationID = ref.fGenerationID;
256 fBoundsIsDirty = ref.fBoundsIsDirty; 267 fBoundsIsDirty = ref.fBoundsIsDirty;
257 if (!fBoundsIsDirty) { 268 if (!fBoundsIsDirty) {
258 fBounds = ref.fBounds; 269 fBounds = ref.fBounds;
259 fIsFinite = ref.fIsFinite; 270 fIsFinite = ref.fIsFinite;
260 } 271 }
272 fIsOval = ref.fIsOval;
261 SkDEBUGCODE(this->validate();) 273 SkDEBUGCODE(this->validate();)
262 } 274 }
263 275
264 SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb) { 276 SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb) {
265 SkDEBUGCODE(this->validate();) 277 SkDEBUGCODE(this->validate();)
266 int pCnt; 278 int pCnt;
279 bool dirtyAfterEdit = true;
267 switch (verb) { 280 switch (verb) {
268 case SkPath::kMove_Verb: 281 case SkPath::kMove_Verb:
269 pCnt = 1; 282 pCnt = 1;
283 dirtyAfterEdit = false;
270 break; 284 break;
271 case SkPath::kLine_Verb: 285 case SkPath::kLine_Verb:
272 pCnt = 1; 286 pCnt = 1;
273 break; 287 break;
274 case SkPath::kQuad_Verb: 288 case SkPath::kQuad_Verb:
275 // fall through 289 // fall through
276 case SkPath::kConic_Verb: 290 case SkPath::kConic_Verb:
277 pCnt = 2; 291 pCnt = 2;
278 break; 292 break;
279 case SkPath::kCubic_Verb: 293 case SkPath::kCubic_Verb:
280 pCnt = 3; 294 pCnt = 3;
281 break; 295 break;
282 case SkPath::kClose_Verb: 296 case SkPath::kClose_Verb:
283 pCnt = 0; 297 pCnt = 0;
298 dirtyAfterEdit = false;
284 break; 299 break;
285 case SkPath::kDone_Verb: 300 case SkPath::kDone_Verb:
286 SkDEBUGFAIL("growForVerb called for kDone"); 301 SkDEBUGFAIL("growForVerb called for kDone");
287 // fall through 302 // fall through
288 default: 303 default:
289 SkDEBUGFAIL("default is not reached"); 304 SkDEBUGFAIL("default is not reached");
305 dirtyAfterEdit = false;
290 pCnt = 0; 306 pCnt = 0;
291 } 307 }
292 size_t space = sizeof(uint8_t) + pCnt * sizeof (SkPoint); 308 size_t space = sizeof(uint8_t) + pCnt * sizeof (SkPoint);
293 this->makeSpace(space); 309 this->makeSpace(space);
294 this->fVerbs[~fVerbCnt] = verb; 310 this->fVerbs[~fVerbCnt] = verb;
295 SkPoint* ret = fPoints + fPointCnt; 311 SkPoint* ret = fPoints + fPointCnt;
296 fVerbCnt += 1; 312 fVerbCnt += 1;
297 fPointCnt += pCnt; 313 fPointCnt += pCnt;
298 fFreeSpace -= space; 314 fFreeSpace -= space;
299 fBoundsIsDirty = true; // this also invalidates fIsFinite 315 fBoundsIsDirty = true; // this also invalidates fIsFinite
316 if (dirtyAfterEdit) {
317 fIsOval = false;
318 }
300 SkDEBUGCODE(this->validate();) 319 SkDEBUGCODE(this->validate();)
301 return ret; 320 return ret;
302 } 321 }
303 322
304 uint32_t SkPathRef::genID() const { 323 uint32_t SkPathRef::genID() const {
305 SkASSERT(!fEditorsAttached); 324 SkASSERT(!fEditorsAttached);
306 static const uint32_t kMask = (static_cast<int64_t>(1) << SkPath::kPathRefGe nIDBitCnt) - 1; 325 static const uint32_t kMask = (static_cast<int64_t>(1) << SkPath::kPathRefGe nIDBitCnt) - 1;
307 if (!fGenerationID) { 326 if (!fGenerationID) {
308 if (0 == fPointCnt && 0 == fVerbCnt) { 327 if (0 == fPointCnt && 0 == fVerbCnt) {
309 fGenerationID = kEmptyGenID; 328 fGenerationID = kEmptyGenID;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 fBounds.fTop - fPoints[i].fY < SK_ScalarNearlyZero && 360 fBounds.fTop - fPoints[i].fY < SK_ScalarNearlyZero &&
342 fPoints[i].fY - fBounds.fBottom < SK_ScalarNearlyZero)); 361 fPoints[i].fY - fBounds.fBottom < SK_ScalarNearlyZero));
343 if (!fPoints[i].isFinite()) { 362 if (!fPoints[i].isFinite()) {
344 isFinite = false; 363 isFinite = false;
345 } 364 }
346 } 365 }
347 SkASSERT(SkToBool(fIsFinite) == isFinite); 366 SkASSERT(SkToBool(fIsFinite) == isFinite);
348 } 367 }
349 } 368 }
350 #endif 369 #endif
OLDNEW
« no previous file with comments | « src/core/SkPath.cpp ('k') | src/core/SkPicture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698