@@ -57,7 +57,7 @@ Snapshot::Snapshot(const sp<Snapshot>& s, int saveFlags):
5757 clipRect = &mClipRectRoot ;
5858#if STENCIL_BUFFER_SIZE
5959 if (s->clipRegion ) {
60- mClipRegionRoot .merge (*s->clipRegion );
60+ mClipRegionRoot .op (*s->clipRegion , SkRegion:: kUnion_Op );
6161 clipRegion = &mClipRegionRoot ;
6262 }
6363#endif
@@ -84,20 +84,19 @@ void Snapshot::ensureClipRegion() {
8484#if STENCIL_BUFFER_SIZE
8585 if (!clipRegion) {
8686 clipRegion = &mClipRegionRoot ;
87- android::Rect tmp (clipRect->left , clipRect->top , clipRect->right , clipRect->bottom );
88- clipRegion->set (tmp);
87+ clipRegion->setRect (clipRect->left , clipRect->top , clipRect->right , clipRect->bottom );
8988 }
9089#endif
9190}
9291
9392void Snapshot::copyClipRectFromRegion () {
9493#if STENCIL_BUFFER_SIZE
9594 if (!clipRegion->isEmpty ()) {
96- android::Rect bounds ( clipRegion->bounds () );
97- clipRect->set (bounds.left , bounds.top , bounds.right , bounds.bottom );
95+ const SkIRect& bounds = clipRegion->getBounds ( );
96+ clipRect->set (bounds.fLeft , bounds.fTop , bounds.fRight , bounds.fBottom );
9897
9998 if (clipRegion->isRect ()) {
100- clipRegion->clear ();
99+ clipRegion->setEmpty ();
101100 clipRegion = NULL ;
102101 }
103102 } else {
@@ -107,43 +106,11 @@ void Snapshot::copyClipRectFromRegion() {
107106#endif
108107}
109108
110- bool Snapshot::clipRegionOr (float left, float top, float right, float bottom) {
109+ bool Snapshot::clipRegionOp (float left, float top, float right, float bottom, SkRegion::Op op ) {
111110#if STENCIL_BUFFER_SIZE
112- android::Rect tmp (left, top, right, bottom);
113- clipRegion->orSelf (tmp);
114- copyClipRectFromRegion ();
115- return true ;
116- #else
117- return false ;
118- #endif
119- }
120-
121- bool Snapshot::clipRegionXor (float left, float top, float right, float bottom) {
122- #if STENCIL_BUFFER_SIZE
123- android::Rect tmp (left, top, right, bottom);
124- clipRegion->xorSelf (tmp);
125- copyClipRectFromRegion ();
126- return true ;
127- #else
128- return false ;
129- #endif
130- }
131-
132- bool Snapshot::clipRegionAnd (float left, float top, float right, float bottom) {
133- #if STENCIL_BUFFER_SIZE
134- android::Rect tmp (left, top, right, bottom);
135- clipRegion->andSelf (tmp);
136- copyClipRectFromRegion ();
137- return true ;
138- #else
139- return false ;
140- #endif
141- }
142-
143- bool Snapshot::clipRegionNand (float left, float top, float right, float bottom) {
144- #if STENCIL_BUFFER_SIZE
145- android::Rect tmp (left, top, right, bottom);
146- clipRegion->subtractSelf (tmp);
111+ SkIRect tmp;
112+ tmp.set (left, top, right, bottom);
113+ clipRegion->op (tmp, op);
147114 copyClipRectFromRegion ();
148115 return true ;
149116#else
@@ -161,14 +128,9 @@ bool Snapshot::clipTransformed(const Rect& r, SkRegion::Op op) {
161128 bool clipped = false ;
162129
163130 switch (op) {
164- case SkRegion::kDifference_Op : {
165- ensureClipRegion ();
166- clipped = clipRegionNand (r.left , r.top , r.right , r.bottom );
167- break ;
168- }
169131 case SkRegion::kIntersect_Op : {
170132 if (CC_UNLIKELY (clipRegion)) {
171- clipped = clipRegionOr (r.left , r.top , r.right , r.bottom );
133+ clipped = clipRegionOp (r.left , r.top , r.right , r.bottom , SkRegion:: kIntersect_Op );
172134 } else {
173135 clipped = clipRect->intersect (r);
174136 if (!clipped) {
@@ -180,26 +142,22 @@ bool Snapshot::clipTransformed(const Rect& r, SkRegion::Op op) {
180142 }
181143 case SkRegion::kUnion_Op : {
182144 if (CC_UNLIKELY (clipRegion)) {
183- clipped = clipRegionAnd (r.left , r.top , r.right , r.bottom );
145+ clipped = clipRegionOp (r.left , r.top , r.right , r.bottom , SkRegion:: kUnion_Op );
184146 } else {
185147 clipped = clipRect->unionWith (r);
186148 }
187149 break ;
188150 }
189- case SkRegion::kXOR_Op : {
190- ensureClipRegion ();
191- clipped = clipRegionXor (r.left , r.top , r.right , r.bottom );
192- break ;
193- }
194- case SkRegion::kReverseDifference_Op : {
195- // TODO!!!!!!!
196- break ;
197- }
198151 case SkRegion::kReplace_Op : {
199152 setClip (r.left , r.top , r.right , r.bottom );
200153 clipped = true ;
201154 break ;
202155 }
156+ default : {
157+ ensureClipRegion ();
158+ clipped = clipRegionOp (r.left , r.top , r.right , r.bottom , op);
159+ break ;
160+ }
203161 }
204162
205163 if (clipped) {
@@ -213,7 +171,7 @@ void Snapshot::setClip(float left, float top, float right, float bottom) {
213171 clipRect->set (left, top, right, bottom);
214172#if STENCIL_BUFFER_SIZE
215173 if (clipRegion) {
216- clipRegion->clear ();
174+ clipRegion->setEmpty ();
217175 clipRegion = NULL ;
218176 }
219177#endif
0 commit comments