| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkBuffer.h" | 10 #include "SkBuffer.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 212 |
| 213 // flag to require a moveTo if we begin with something else, like lineTo etc. | 213 // flag to require a moveTo if we begin with something else, like lineTo etc. |
| 214 #define INITIAL_LASTMOVETOINDEX_VALUE ~0 | 214 #define INITIAL_LASTMOVETOINDEX_VALUE ~0 |
| 215 | 215 |
| 216 SkPath::SkPath() | 216 SkPath::SkPath() |
| 217 #if SK_DEBUG_PATH_REF | 217 #if SK_DEBUG_PATH_REF |
| 218 : fPathRef(SkPathRef::CreateEmpty(), this) | 218 : fPathRef(SkPathRef::CreateEmpty(), this) |
| 219 #else | 219 #else |
| 220 : fPathRef(SkPathRef::CreateEmpty()) | 220 : fPathRef(SkPathRef::CreateEmpty()) |
| 221 #endif | 221 #endif |
| 222 , fFillType(kWinding_FillType) | 222 #ifdef SK_BUILD_FOR_ANDROID |
| 223 , fBoundsIsDirty(true) { | 223 , fGenerationID(0) |
| 224 #endif |
| 225 { |
| 226 this->resetFields(); |
| 227 } |
| 228 |
| 229 void SkPath::resetFields() { |
| 230 //fPathRef is assumed to have been emptied by the caller. |
| 231 fLastMoveToIndex = INITIAL_LASTMOVETOINDEX_VALUE; |
| 232 fFillType = kWinding_FillType; |
| 233 fSegmentMask = 0; |
| 234 fBoundsIsDirty = true; |
| 224 fConvexity = kUnknown_Convexity; | 235 fConvexity = kUnknown_Convexity; |
| 225 fDirection = kUnknown_Direction; | 236 fDirection = kUnknown_Direction; |
| 226 fSegmentMask = 0; | 237 fIsFinite = false; |
| 227 fLastMoveToIndex = INITIAL_LASTMOVETOINDEX_VALUE; | |
| 228 fIsOval = false; | 238 fIsOval = false; |
| 229 fIsFinite = false; // gets computed when we know our bounds | |
| 230 #ifdef SK_BUILD_FOR_ANDROID | 239 #ifdef SK_BUILD_FOR_ANDROID |
| 231 fGenerationID = 0; | 240 GEN_ID_INC; |
| 232 fSourcePath = NULL; | 241 fSourcePath = NULL; |
| 233 #endif | 242 #endif |
| 234 } | 243 } |
| 235 | 244 |
| 236 SkPath::SkPath(const SkPath& src) | 245 SkPath::SkPath(const SkPath& that) |
| 237 #if SK_DEBUG_PATH_REF | 246 #if SK_DEBUG_PATH_REF |
| 238 : fPathRef(this) | 247 : fPathRef(this) |
| 248 #else |
| 249 : fPathRef(SkRef(that.fPathRef.get())) |
| 250 #endif |
| 251 #ifdef SK_BUILD_FOR_ANDROID |
| 252 , fGenerationID(0) |
| 239 #endif | 253 #endif |
| 240 { | 254 { |
| 241 SkDEBUGCODE(src.validate();) | 255 this->copyFields(that); |
| 242 src.fPathRef.get()->ref(); | 256 SkDEBUGCODE(that.validate();) |
| 243 fPathRef.reset(src.fPathRef.get()); | |
| 244 fBounds = src.fBounds; | |
| 245 fFillType = src.fFillType; | |
| 246 fBoundsIsDirty = src.fBoundsIsDirty; | |
| 247 fConvexity = src.fConvexity; | |
| 248 fDirection = src.fDirection; | |
| 249 fIsFinite = src.fIsFinite; | |
| 250 fSegmentMask = src.fSegmentMask; | |
| 251 fLastMoveToIndex = src.fLastMoveToIndex; | |
| 252 fIsOval = src.fIsOval; | |
| 253 #ifdef SK_BUILD_FOR_ANDROID | |
| 254 fGenerationID = src.fGenerationID; | |
| 255 fSourcePath = NULL; | |
| 256 #endif | |
| 257 } | 257 } |
| 258 | 258 |
| 259 SkPath::~SkPath() { | 259 SkPath::~SkPath() { |
| 260 SkDEBUGCODE(this->validate();) | 260 SkDEBUGCODE(this->validate();) |
| 261 } | 261 } |
| 262 | 262 |
| 263 SkPath& SkPath::operator=(const SkPath& src) { | 263 SkPath& SkPath::operator=(const SkPath& that) { |
| 264 SkDEBUGCODE(src.validate();) | 264 SkDEBUGCODE(that.validate();) |
| 265 | 265 |
| 266 if (this != &src) { | 266 if (this != &that) { |
| 267 src.fPathRef.get()->ref(); | 267 fPathRef.reset(SkRef(that.fPathRef.get())); |
| 268 fPathRef.reset(src.fPathRef.get()); | 268 this->copyFields(that); |
| 269 fBounds = src.fBounds; | |
| 270 fFillType = src.fFillType; | |
| 271 fBoundsIsDirty = src.fBoundsIsDirty; | |
| 272 fConvexity = src.fConvexity; | |
| 273 fDirection = src.fDirection; | |
| 274 fIsFinite = src.fIsFinite; | |
| 275 fSegmentMask = src.fSegmentMask; | |
| 276 fLastMoveToIndex = src.fLastMoveToIndex; | |
| 277 fIsOval = src.fIsOval; | |
| 278 GEN_ID_INC; | |
| 279 } | 269 } |
| 280 SkDEBUGCODE(this->validate();) | 270 SkDEBUGCODE(this->validate();) |
| 281 return *this; | 271 return *this; |
| 282 } | 272 } |
| 283 | 273 |
| 274 void SkPath::copyFields(const SkPath& that) { |
| 275 //fPathRef is assumed to have been set by the caller. |
| 276 fBounds = that.fBounds; |
| 277 fLastMoveToIndex = that.fLastMoveToIndex; |
| 278 fFillType = that.fFillType; |
| 279 fSegmentMask = that.fSegmentMask; |
| 280 fBoundsIsDirty = that.fBoundsIsDirty; |
| 281 fConvexity = that.fConvexity; |
| 282 fDirection = that.fDirection; |
| 283 fIsFinite = that.fIsFinite; |
| 284 fIsOval = that.fIsOval; |
| 285 #ifdef SK_BUILD_FOR_ANDROID |
| 286 GEN_ID_INC; |
| 287 fSourcePath = NULL; |
| 288 #endif |
| 289 } |
| 290 |
| 284 SK_API bool operator==(const SkPath& a, const SkPath& b) { | 291 SK_API bool operator==(const SkPath& a, const SkPath& b) { |
| 285 // note: don't need to look at isConvex or bounds, since just comparing the | 292 // note: don't need to look at isConvex or bounds, since just comparing the |
| 286 // raw data is sufficient. | 293 // raw data is sufficient. |
| 287 | 294 |
| 288 // We explicitly check fSegmentMask as a quick-reject. We could skip it, | 295 // We explicitly check fSegmentMask as a quick-reject. We could skip it, |
| 289 // since it is only a cache of info in the fVerbs, but its a fast way to | 296 // since it is only a cache of info in the fVerbs, but its a fast way to |
| 290 // notice a difference | 297 // notice a difference |
| 291 | 298 |
| 292 return &a == &b || | 299 return &a == &b || |
| 293 (a.fFillType == b.fFillType && a.fSegmentMask == b.fSegmentMask && | 300 (a.fFillType == b.fFillType && a.fSegmentMask == b.fSegmentMask && |
| 294 *a.fPathRef.get() == *b.fPathRef.get()); | 301 *a.fPathRef.get() == *b.fPathRef.get()); |
| 295 } | 302 } |
| 296 | 303 |
| 297 void SkPath::swap(SkPath& other) { | 304 void SkPath::swap(SkPath& that) { |
| 298 SkASSERT(&other != NULL); | 305 SkASSERT(&that != NULL); |
| 299 | 306 |
| 300 if (this != &other) { | 307 if (this != &that) { |
| 301 SkTSwap<SkRect>(fBounds, other.fBounds); | 308 fPathRef.swap(&that.fPathRef); |
| 302 fPathRef.swap(&other.fPathRef); | 309 SkTSwap<SkRect>(fBounds, that.fBounds); |
| 303 SkTSwap<uint8_t>(fFillType, other.fFillType); | 310 SkTSwap<int>(fLastMoveToIndex, that.fLastMoveToIndex); |
| 304 SkTSwap<uint8_t>(fBoundsIsDirty, other.fBoundsIsDirty); | 311 SkTSwap<uint8_t>(fFillType, that.fFillType); |
| 305 SkTSwap<uint8_t>(fConvexity, other.fConvexity); | 312 SkTSwap<uint8_t>(fSegmentMask, that.fSegmentMask); |
| 306 SkTSwap<uint8_t>(fDirection, other.fDirection); | 313 SkTSwap<uint8_t>(fBoundsIsDirty, that.fBoundsIsDirty); |
| 307 SkTSwap<uint8_t>(fSegmentMask, other.fSegmentMask); | 314 SkTSwap<uint8_t>(fConvexity, that.fConvexity); |
| 308 SkTSwap<int>(fLastMoveToIndex, other.fLastMoveToIndex); | 315 SkTSwap<uint8_t>(fDirection, that.fDirection); |
| 309 SkTSwap<SkBool8>(fIsOval, other.fIsOval); | 316 SkTSwap<SkBool8>(fIsFinite, that.fIsFinite); |
| 310 SkTSwap<SkBool8>(fIsFinite, other.fIsFinite); | 317 SkTSwap<SkBool8>(fIsOval, that.fIsOval); |
| 311 GEN_ID_INC; | 318 GEN_ID_INC; |
| 319 GEN_ID_PTR_INC(&that); |
| 312 } | 320 } |
| 313 } | 321 } |
| 314 | 322 |
| 315 static inline bool check_edge_against_rect(const SkPoint& p0, | 323 static inline bool check_edge_against_rect(const SkPoint& p0, |
| 316 const SkPoint& p1, | 324 const SkPoint& p1, |
| 317 const SkRect& rect, | 325 const SkRect& rect, |
| 318 SkPath::Direction dir) { | 326 SkPath::Direction dir) { |
| 319 const SkPoint* edgeBegin; | 327 const SkPoint* edgeBegin; |
| 320 SkVector v; | 328 SkVector v; |
| 321 if (SkPath::kCW_Direction == dir) { | 329 if (SkPath::kCW_Direction == dir) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 412 |
| 405 void SkPath::setSourcePath(const SkPath* path) { | 413 void SkPath::setSourcePath(const SkPath* path) { |
| 406 fSourcePath = path; | 414 fSourcePath = path; |
| 407 } | 415 } |
| 408 #endif | 416 #endif |
| 409 | 417 |
| 410 void SkPath::reset() { | 418 void SkPath::reset() { |
| 411 SkDEBUGCODE(this->validate();) | 419 SkDEBUGCODE(this->validate();) |
| 412 | 420 |
| 413 fPathRef.reset(SkPathRef::CreateEmpty()); | 421 fPathRef.reset(SkPathRef::CreateEmpty()); |
| 414 GEN_ID_INC; | 422 this->resetFields(); |
| 415 fBoundsIsDirty = true; | |
| 416 fConvexity = kUnknown_Convexity; | |
| 417 fDirection = kUnknown_Direction; | |
| 418 fSegmentMask = 0; | |
| 419 fLastMoveToIndex = INITIAL_LASTMOVETOINDEX_VALUE; | |
| 420 fIsOval = false; | |
| 421 } | 423 } |
| 422 | 424 |
| 423 void SkPath::rewind() { | 425 void SkPath::rewind() { |
| 424 SkDEBUGCODE(this->validate();) | 426 SkDEBUGCODE(this->validate();) |
| 425 | 427 |
| 426 SkPathRef::Rewind(&fPathRef); | 428 SkPathRef::Rewind(&fPathRef); |
| 427 GEN_ID_INC; | 429 this->resetFields(); |
| 428 fConvexity = kUnknown_Convexity; | |
| 429 fBoundsIsDirty = true; | |
| 430 fSegmentMask = 0; | |
| 431 fLastMoveToIndex = INITIAL_LASTMOVETOINDEX_VALUE; | |
| 432 fIsOval = false; | |
| 433 } | 430 } |
| 434 | 431 |
| 435 bool SkPath::isEmpty() const { | 432 bool SkPath::isEmpty() const { |
| 436 SkDEBUGCODE(this->validate();) | 433 SkDEBUGCODE(this->validate();) |
| 437 return 0 == fPathRef->countVerbs(); | 434 return 0 == fPathRef->countVerbs(); |
| 438 } | 435 } |
| 439 | 436 |
| 440 bool SkPath::isLine(SkPoint line[2]) const { | 437 bool SkPath::isLine(SkPoint line[2]) const { |
| 441 int verbCount = fPathRef->countVerbs(); | 438 int verbCount = fPathRef->countVerbs(); |
| 442 int ptCount = fPathRef->countVerbs(); | 439 int ptCount = fPathRef->countVerbs(); |
| (...skipping 2612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3055 switch (this->getFillType()) { | 3052 switch (this->getFillType()) { |
| 3056 case SkPath::kEvenOdd_FillType: | 3053 case SkPath::kEvenOdd_FillType: |
| 3057 case SkPath::kInverseEvenOdd_FillType: | 3054 case SkPath::kInverseEvenOdd_FillType: |
| 3058 w &= 1; | 3055 w &= 1; |
| 3059 break; | 3056 break; |
| 3060 default: | 3057 default: |
| 3061 break; | 3058 break; |
| 3062 } | 3059 } |
| 3063 return SkToBool(w); | 3060 return SkToBool(w); |
| 3064 } | 3061 } |
| OLD | NEW |