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

Side by Side Diff: include/core/SkClipStack.h

Issue 178583002: Use SkTLazy to hold path in SkClipStack::Element (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add comment Created 6 years, 9 months 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 | « no previous file | include/core/SkTLazy.h » ('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 /* 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
11 #include "SkDeque.h" 11 #include "SkDeque.h"
12 #include "SkPath.h" 12 #include "SkPath.h"
13 #include "SkRect.h" 13 #include "SkRect.h"
14 #include "SkRRect.h" 14 #include "SkRRect.h"
15 #include "SkRegion.h" 15 #include "SkRegion.h"
16 #include "SkTDArray.h" 16 #include "SkTDArray.h"
17 #include "SkTLazy.h"
17 18
18 19
19 // Because a single save/restore state can have multiple clips, this class 20 // Because a single save/restore state can have multiple clips, this class
20 // stores the stack depth (fSaveCount) and clips (fDeque) separately. 21 // stores the stack depth (fSaveCount) and clips (fDeque) separately.
21 // Each clip in fDeque stores the stack state to which it belongs 22 // Each clip in fDeque stores the stack state to which it belongs
22 // (i.e., the fSaveCount in force when it was added). Restores are thus 23 // (i.e., the fSaveCount in force when it was added). Restores are thus
23 // implemented by removing clips from fDeque that have an fSaveCount larger 24 // implemented by removing clips from fDeque that have an fSaveCount larger
24 // then the freshly decremented count. 25 // then the freshly decremented count.
25 class SK_API SkClipStack { 26 class SK_API SkClipStack {
26 public: 27 public:
(...skipping 19 matching lines...) Expand all
46 kRRect_Type, 47 kRRect_Type,
47 //!< This element combines a path with the current clip using a set operation 48 //!< This element combines a path with the current clip using a set operation
48 kPath_Type, 49 kPath_Type,
49 }; 50 };
50 51
51 Element() { 52 Element() {
52 this->initCommon(0, SkRegion::kReplace_Op, false); 53 this->initCommon(0, SkRegion::kReplace_Op, false);
53 this->setEmpty(); 54 this->setEmpty();
54 } 55 }
55 56
57 Element(const Element&);
58
56 Element(const SkRect& rect, SkRegion::Op op, bool doAA) { 59 Element(const SkRect& rect, SkRegion::Op op, bool doAA) {
57 this->initRect(0, rect, op, doAA); 60 this->initRect(0, rect, op, doAA);
58 } 61 }
59 62
60 Element(const SkRRect& rrect, SkRegion::Op op, bool doAA) { 63 Element(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
61 this->initRRect(0, rrect, op, doAA); 64 this->initRRect(0, rrect, op, doAA);
62 } 65 }
63 66
64 Element(const SkPath& path, SkRegion::Op op, bool doAA) { 67 Element(const SkPath& path, SkRegion::Op op, bool doAA) {
65 this->initPath(0, path, op, doAA); 68 this->initPath(0, path, op, doAA);
66 } 69 }
67 70
68 bool operator== (const Element& element) const; 71 bool operator== (const Element& element) const;
69 bool operator!= (const Element& element) const { return !(*this == eleme nt); } 72 bool operator!= (const Element& element) const { return !(*this == eleme nt); }
70 73
71 //!< Call to get the type of the clip element. 74 //!< Call to get the type of the clip element.
72 Type getType() const { return fType; } 75 Type getType() const { return fType; }
73 76
74 //!< Call if getType() is kPath to get the path. 77 //!< Call if getType() is kPath to get the path.
75 const SkPath& getPath() const { SkASSERT(kPath_Type == fType); return fP ath; } 78 const SkPath& getPath() const { SkASSERT(kPath_Type == fType); return *f Path.get(); }
76 79
77 //!< Call if getType() is kRRect to get the round-rect. 80 //!< Call if getType() is kRRect to get the round-rect.
78 const SkRRect& getRRect() const { SkASSERT(kRRect_Type == fType); return fRRect; } 81 const SkRRect& getRRect() const { SkASSERT(kRRect_Type == fType); return fRRect; }
79 82
80 //!< Call if getType() is kRect to get the rect. 83 //!< Call if getType() is kRect to get the rect.
81 const SkRect& getRect() const { 84 const SkRect& getRect() const {
82 SkASSERT(kRect_Type == fType && (fRRect.isRect() || fRRect.isEmpty() )); 85 SkASSERT(kRect_Type == fType && (fRRect.isRect() || fRRect.isEmpty() ));
83 return fRRect.getBounds(); 86 return fRRect.getBounds();
84 } 87 }
85 88
(...skipping 24 matching lines...) Expand all
110 * Gets the bounds of the clip element, either the rect or path bounds. (Whether the shape 113 * Gets the bounds of the clip element, either the rect or path bounds. (Whether the shape
111 * is inverse filled is not considered.) 114 * is inverse filled is not considered.)
112 */ 115 */
113 const SkRect& getBounds() const { 116 const SkRect& getBounds() const {
114 static const SkRect kEmpty = { 0, 0, 0, 0 }; 117 static const SkRect kEmpty = { 0, 0, 0, 0 };
115 switch (fType) { 118 switch (fType) {
116 case kRect_Type: // fallthrough 119 case kRect_Type: // fallthrough
117 case kRRect_Type: 120 case kRRect_Type:
118 return fRRect.getBounds(); 121 return fRRect.getBounds();
119 case kPath_Type: 122 case kPath_Type:
120 return fPath.getBounds(); 123 return fPath.get()->getBounds();
121 case kEmpty_Type: 124 case kEmpty_Type:
122 return kEmpty; 125 return kEmpty;
123 default: 126 default:
124 SkDEBUGFAIL("Unexpected type."); 127 SkDEBUGFAIL("Unexpected type.");
125 return kEmpty; 128 return kEmpty;
126 } 129 }
127 } 130 }
128 131
129 /** 132 /**
130 * Conservatively checks whether the clip shape contains the rect param. (Whether the shape 133 * Conservatively checks whether the clip shape contains the rect param. (Whether the shape
131 * is inverse filled is not considered.) 134 * is inverse filled is not considered.)
132 */ 135 */
133 bool contains(const SkRect& rect) const { 136 bool contains(const SkRect& rect) const {
134 switch (fType) { 137 switch (fType) {
135 case kRect_Type: 138 case kRect_Type:
136 return this->getRect().contains(rect); 139 return this->getRect().contains(rect);
137 case kRRect_Type: 140 case kRRect_Type:
138 return fRRect.contains(rect); 141 return fRRect.contains(rect);
139 case kPath_Type: 142 case kPath_Type:
140 return fPath.conservativelyContainsRect(rect); 143 return fPath.get()->conservativelyContainsRect(rect);
141 case kEmpty_Type: 144 case kEmpty_Type:
142 return false; 145 return false;
143 default: 146 default:
144 SkDEBUGFAIL("Unexpected type."); 147 SkDEBUGFAIL("Unexpected type.");
145 return false; 148 return false;
146 } 149 }
147 } 150 }
148 151
149 /** 152 /**
150 * Is the clip shape inverse filled. 153 * Is the clip shape inverse filled.
151 */ 154 */
152 bool isInverseFilled() const { 155 bool isInverseFilled() const {
153 return kPath_Type == fType && fPath.isInverseFillType(); 156 return kPath_Type == fType && fPath.get()->isInverseFillType();
154 } 157 }
155 158
156 private: 159 private:
157 friend class SkClipStack; 160 friend class SkClipStack;
158 161
159 SkPath fPath; 162 SkTLazy<SkPath> fPath;
160 SkRRect fRRect; 163 SkRRect fRRect;
161 int fSaveCount; // save count of stack when this element was added. 164 int fSaveCount; // save count of stack when this element was added.
162 SkRegion::Op fOp; 165 SkRegion::Op fOp;
163 Type fType; 166 Type fType;
164 bool fDoAA; 167 bool fDoAA;
165 168
166 /* fFiniteBoundType and fFiniteBound are used to incrementally update th e clip stack's 169 /* fFiniteBoundType and fFiniteBound are used to incrementally update th e clip stack's
167 bound. When fFiniteBoundType is kNormal_BoundsType, fFiniteBound repr esents the 170 bound. When fFiniteBoundType is kNormal_BoundsType, fFiniteBound repr esents the
168 conservative bounding box of the pixels that aren't clipped (i.e., an y pixels that can be 171 conservative bounding box of the pixels that aren't clipped (i.e., an y pixels that can be
169 drawn to are inside the bound). When fFiniteBoundType is kInsideOut_B oundsType (which 172 drawn to are inside the bound). When fFiniteBoundType is kInsideOut_B oundsType (which
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 */ 442 */
440 void restoreTo(int saveCount); 443 void restoreTo(int saveCount);
441 444
442 /** 445 /**
443 * Return the next unique generation ID. 446 * Return the next unique generation ID.
444 */ 447 */
445 static int32_t GetNextGenID(); 448 static int32_t GetNextGenID();
446 }; 449 };
447 450
448 #endif 451 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkTLazy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698