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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 void invertShapeFillType(); | 102 void invertShapeFillType(); |
103 | 103 |
104 //!< Sets the set operation represented by the element. | 104 //!< Sets the set operation represented by the element. |
105 void setOp(SkRegion::Op op) { fOp = op; } | 105 void setOp(SkRegion::Op op) { fOp = op; } |
106 | 106 |
107 /** The GenID can be used by clip stack clients to cache representations
of the clip. The | 107 /** 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 | 108 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 | 109 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 | 110 have a different ID since the elements produce different clip result
in the context of |
111 their stacks. */ | 111 their stacks. */ |
112 int32_t getGenID() const { return fGenID; } | 112 int32_t getGenID() const { SkASSERT(kInvalidGenID != fGenID); return fGe
nID; } |
113 | 113 |
114 /** | 114 /** |
115 * Gets the bounds of the clip element, either the rect or path bounds.
(Whether the shape | 115 * Gets the bounds of the clip element, either the rect or path bounds.
(Whether the shape |
116 * is inverse filled is not considered.) | 116 * is inverse filled is not considered.) |
117 */ | 117 */ |
118 const SkRect& getBounds() const { | 118 const SkRect& getBounds() const { |
119 static const SkRect kEmpty = { 0, 0, 0, 0 }; | 119 static const SkRect kEmpty = { 0, 0, 0, 0 }; |
120 switch (fType) { | 120 switch (fType) { |
121 case kRect_Type: | 121 case kRect_Type: |
122 return fRect; | 122 return fRect; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 // An optimized version of clipDevRect(emptyRect, kIntersect, ...) | 309 // An optimized version of clipDevRect(emptyRect, kIntersect, ...) |
310 void clipEmpty(); | 310 void clipEmpty(); |
311 | 311 |
312 /** | 312 /** |
313 * isWideOpen returns true if the clip state corresponds to the infinite | 313 * isWideOpen returns true if the clip state corresponds to the infinite |
314 * plane (i.e., draws are not limited at all) | 314 * plane (i.e., draws are not limited at all) |
315 */ | 315 */ |
316 bool isWideOpen() const; | 316 bool isWideOpen() const; |
317 | 317 |
318 /** | 318 /** |
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 | 319 * The generation ID has three reserved values to indicate special |
335 * (potentially ignorable) cases | 320 * (potentially ignorable) cases |
336 */ | 321 */ |
337 static const int32_t kInvalidGenID = 0; | 322 static const int32_t kInvalidGenID = 0; //!< Invalid id that is never re
turned by |
| 323 //!< SkClipStack. Useful when ca
ching clips |
| 324 //!< based on GenID. |
338 static const int32_t kEmptyGenID = 1; // no pixels writeable | 325 static const int32_t kEmptyGenID = 1; // no pixels writeable |
339 static const int32_t kWideOpenGenID = 2; // all pixels writeable | 326 static const int32_t kWideOpenGenID = 2; // all pixels writeable |
340 | 327 |
341 int32_t getTopmostGenID() const; | 328 int32_t getTopmostGenID() const; |
342 | 329 |
343 public: | 330 public: |
344 class Iter { | 331 class Iter { |
345 public: | 332 public: |
346 enum IterStart { | 333 enum IterStart { |
347 kBottom_IterStart = SkDeque::Iter::kFront_IterStart, | 334 kBottom_IterStart = SkDeque::Iter::kFront_IterStart, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 friend class Iter; | 420 friend class Iter; |
434 | 421 |
435 SkDeque fDeque; | 422 SkDeque fDeque; |
436 int fSaveCount; | 423 int fSaveCount; |
437 | 424 |
438 // Generation ID for the clip stack. This is incremented for each | 425 // Generation ID for the clip stack. This is incremented for each |
439 // clipDevRect and clipDevPath call. 0 is reserved to indicate an | 426 // clipDevRect and clipDevPath call. 0 is reserved to indicate an |
440 // invalid ID. | 427 // invalid ID. |
441 static int32_t gGenID; | 428 static int32_t gGenID; |
442 | 429 |
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 /** | 430 /** |
456 * Restore the stack back to the specified save count. | 431 * Restore the stack back to the specified save count. |
457 */ | 432 */ |
458 void restoreTo(int saveCount); | 433 void restoreTo(int saveCount); |
459 | 434 |
460 /** | 435 /** |
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. | 436 * Return the next unique generation ID. |
467 */ | 437 */ |
468 static int32_t GetNextGenID(); | 438 static int32_t GetNextGenID(); |
469 }; | 439 }; |
470 | 440 |
471 #endif | 441 #endif |
OLD | NEW |