| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 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 #ifndef SkClipStack_DEFINED | 8 #ifndef SkClipStack_DEFINED |
| 9 #define SkClipStack_DEFINED | 9 #define SkClipStack_DEFINED |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } | 51 } |
| 52 | 52 |
| 53 Element(const SkRect& rect, SkRegion::Op op, bool doAA) { | 53 Element(const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 54 this->initRect(0, rect, op, doAA); | 54 this->initRect(0, rect, op, doAA); |
| 55 } | 55 } |
| 56 | 56 |
| 57 Element(const SkPath& path, SkRegion::Op op, bool doAA) { | 57 Element(const SkPath& path, SkRegion::Op op, bool doAA) { |
| 58 this->initPath(0, path, op, doAA); | 58 this->initPath(0, path, op, doAA); |
| 59 } | 59 } |
| 60 | 60 |
| 61 //<! Constructor for elements that are not stored in the clip stack. |
| 62 Element(const SkRect& rect, SkRegion::Op op, bool doAA, int32_t genID) { |
| 63 this->initRect(0, rect, op, doAA); |
| 64 fGenID = genID; |
| 65 } |
| 66 |
| 61 bool operator== (const Element& element) const { | 67 bool operator== (const Element& element) const { |
| 62 if (this == &element) { | 68 if (this == &element) { |
| 63 return true; | 69 return true; |
| 64 } | 70 } |
| 65 if (fOp != element.fOp || | 71 if (fOp != element.fOp || |
| 66 fType != element.fType || | 72 fType != element.fType || |
| 67 fDoAA != element.fDoAA || | 73 fDoAA != element.fDoAA || |
| 68 fSaveCount != element.fSaveCount) { | 74 fSaveCount != element.fSaveCount) { |
| 69 return false; | 75 return false; |
| 70 } | 76 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 void invertShapeFillType(); | 108 void invertShapeFillType(); |
| 103 | 109 |
| 104 //!< Sets the set operation represented by the element. | 110 //!< Sets the set operation represented by the element. |
| 105 void setOp(SkRegion::Op op) { fOp = op; } | 111 void setOp(SkRegion::Op op) { fOp = op; } |
| 106 | 112 |
| 107 /** The GenID can be used by clip stack clients to cache representations
of the clip. The | 113 /** The GenID can be used by clip stack clients to cache representations
of the clip. The |
| 108 ID corresponds to the set of clip elements up to and including this
element within the | 114 ID corresponds to the set of clip elements up to and including this
element within the |
| 109 stack not to the element itself. That is the same clip path in diffe
rent stacks will | 115 stack not to the element itself. That is the same clip path in diffe
rent stacks will |
| 110 have a different ID since the elements produce different clip result
in the context of | 116 have a different ID since the elements produce different clip result
in the context of |
| 111 their stacks. */ | 117 their stacks. */ |
| 112 int32_t getGenID() const { return fGenID; } | 118 int32_t getGenID() const { SkASSERT(kInvalidGenID != fGenID); return fGe
nID; } |
| 113 | 119 |
| 114 /** | 120 /** |
| 115 * Gets the bounds of the clip element, either the rect or path bounds.
(Whether the shape | 121 * Gets the bounds of the clip element, either the rect or path bounds.
(Whether the shape |
| 116 * is inverse filled is not considered.) | 122 * is inverse filled is not considered.) |
| 117 */ | 123 */ |
| 118 const SkRect& getBounds() const { | 124 const SkRect& getBounds() const { |
| 119 static const SkRect kEmpty = { 0, 0, 0, 0 }; | 125 static const SkRect kEmpty = { 0, 0, 0, 0 }; |
| 120 switch (fType) { | 126 switch (fType) { |
| 121 case kRect_Type: | 127 case kRect_Type: |
| 122 return fRect; | 128 return fRect; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // An optimized version of clipDevRect(emptyRect, kIntersect, ...) | 315 // An optimized version of clipDevRect(emptyRect, kIntersect, ...) |
| 310 void clipEmpty(); | 316 void clipEmpty(); |
| 311 | 317 |
| 312 /** | 318 /** |
| 313 * isWideOpen returns true if the clip state corresponds to the infinite | 319 * isWideOpen returns true if the clip state corresponds to the infinite |
| 314 * plane (i.e., draws are not limited at all) | 320 * plane (i.e., draws are not limited at all) |
| 315 */ | 321 */ |
| 316 bool isWideOpen() const; | 322 bool isWideOpen() const; |
| 317 | 323 |
| 318 /** | 324 /** |
| 319 * Add a callback function that will be called whenever a clip state | |
| 320 * is no longer viable. This will occur whenever restore | |
| 321 * is called or when a clipDevRect or clipDevPath call updates the | |
| 322 * clip within an existing save/restore state. Each clip state is | |
| 323 * represented by a unique generation ID. | |
| 324 */ | |
| 325 typedef void (*PFPurgeClipCB)(int genID, void* data); | |
| 326 void addPurgeClipCallback(PFPurgeClipCB callback, void* data) const; | |
| 327 | |
| 328 /** | |
| 329 * Remove a callback added earlier via addPurgeClipCallback | |
| 330 */ | |
| 331 void removePurgeClipCallback(PFPurgeClipCB callback, void* data) const; | |
| 332 | |
| 333 /** | |
| 334 * The generation ID has three reserved values to indicate special | 325 * The generation ID has three reserved values to indicate special |
| 335 * (potentially ignorable) cases | 326 * (potentially ignorable) cases |
| 336 */ | 327 */ |
| 337 static const int32_t kInvalidGenID = 0; | 328 static const int32_t kInvalidGenID = 0; //!< Invalid id that is never re
turned by |
| 329 //!< SkClipStack. Useful when ca
ching clips |
| 330 //!< based on GenID. |
| 338 static const int32_t kEmptyGenID = 1; // no pixels writeable | 331 static const int32_t kEmptyGenID = 1; // no pixels writeable |
| 339 static const int32_t kWideOpenGenID = 2; // all pixels writeable | 332 static const int32_t kWideOpenGenID = 2; // all pixels writeable |
| 340 | 333 |
| 341 int32_t getTopmostGenID() const; | 334 int32_t getTopmostGenID() const; |
| 342 | 335 |
| 343 public: | 336 public: |
| 344 class Iter { | 337 class Iter { |
| 345 public: | 338 public: |
| 346 enum IterStart { | 339 enum IterStart { |
| 347 kBottom_IterStart = SkDeque::Iter::kFront_IterStart, | 340 kBottom_IterStart = SkDeque::Iter::kFront_IterStart, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 friend class Iter; | 426 friend class Iter; |
| 434 | 427 |
| 435 SkDeque fDeque; | 428 SkDeque fDeque; |
| 436 int fSaveCount; | 429 int fSaveCount; |
| 437 | 430 |
| 438 // Generation ID for the clip stack. This is incremented for each | 431 // Generation ID for the clip stack. This is incremented for each |
| 439 // clipDevRect and clipDevPath call. 0 is reserved to indicate an | 432 // clipDevRect and clipDevPath call. 0 is reserved to indicate an |
| 440 // invalid ID. | 433 // invalid ID. |
| 441 static int32_t gGenID; | 434 static int32_t gGenID; |
| 442 | 435 |
| 443 struct ClipCallbackData { | |
| 444 PFPurgeClipCB fCallback; | |
| 445 void* fData; | |
| 446 | |
| 447 friend bool operator==(const ClipCallbackData& a, | |
| 448 const ClipCallbackData& b) { | |
| 449 return a.fCallback == b.fCallback && a.fData == b.fData; | |
| 450 } | |
| 451 }; | |
| 452 | |
| 453 mutable SkTDArray<ClipCallbackData> fCallbackData; | |
| 454 | |
| 455 /** | 436 /** |
| 456 * Restore the stack back to the specified save count. | 437 * Restore the stack back to the specified save count. |
| 457 */ | 438 */ |
| 458 void restoreTo(int saveCount); | 439 void restoreTo(int saveCount); |
| 459 | 440 |
| 460 /** | 441 /** |
| 461 * Invoke all the purge callbacks passing in element's generation ID. | |
| 462 */ | |
| 463 void purgeClip(Element* element); | |
| 464 | |
| 465 /** | |
| 466 * Return the next unique generation ID. | 442 * Return the next unique generation ID. |
| 467 */ | 443 */ |
| 468 static int32_t GetNextGenID(); | 444 static int32_t GetNextGenID(); |
| 469 }; | 445 }; |
| 470 | 446 |
| 471 #endif | 447 #endif |
| OLD | NEW |