@@ -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 .op (*s->clipRegion , SkRegion:: kUnion_Op );
60+ mClipRegionRoot .merge (*s->clipRegion );
6161 clipRegion = &mClipRegionRoot ;
6262 }
6363#endif
@@ -84,19 +84,20 @@ void Snapshot::ensureClipRegion() {
8484#if STENCIL_BUFFER_SIZE
8585 if (!clipRegion) {
8686 clipRegion = &mClipRegionRoot ;
87- clipRegion->setRect (clipRect->left , clipRect->top , clipRect->right , clipRect->bottom );
87+ android::Rect tmp (clipRect->left , clipRect->top , clipRect->right , clipRect->bottom );
88+ clipRegion->set (tmp);
8889 }
8990#endif
9091}
9192
9293void Snapshot::copyClipRectFromRegion () {
9394#if STENCIL_BUFFER_SIZE
9495 if (!clipRegion->isEmpty ()) {
95- const SkIRect& bounds = clipRegion->getBounds ( );
96- clipRect->set (bounds.fLeft , bounds.fTop , bounds.fRight , bounds.fBottom );
96+ android::Rect bounds ( clipRegion->bounds () );
97+ clipRect->set (bounds.left , bounds.top , bounds.right , bounds.bottom );
9798
9899 if (clipRegion->isRect ()) {
99- clipRegion->setEmpty ();
100+ clipRegion->clear ();
100101 clipRegion = NULL ;
101102 }
102103 } else {
@@ -106,11 +107,43 @@ void Snapshot::copyClipRectFromRegion() {
106107#endif
107108}
108109
109- bool Snapshot::clipRegionOp (float left, float top, float right, float bottom, SkRegion::Op op ) {
110+ bool Snapshot::clipRegionOr (float left, float top, float right, float bottom) {
110111#if STENCIL_BUFFER_SIZE
111- SkIRect tmp;
112- tmp.set (left, top, right, bottom);
113- clipRegion->op (tmp, op);
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);
114147 copyClipRectFromRegion ();
115148 return true ;
116149#else
@@ -128,9 +161,14 @@ bool Snapshot::clipTransformed(const Rect& r, SkRegion::Op op) {
128161 bool clipped = false ;
129162
130163 switch (op) {
164+ case SkRegion::kDifference_Op : {
165+ ensureClipRegion ();
166+ clipped = clipRegionNand (r.left , r.top , r.right , r.bottom );
167+ break ;
168+ }
131169 case SkRegion::kIntersect_Op : {
132170 if (CC_UNLIKELY (clipRegion)) {
133- clipped = clipRegionOp (r.left , r.top , r.right , r.bottom , SkRegion:: kIntersect_Op );
171+ clipped = clipRegionOr (r.left , r.top , r.right , r.bottom );
134172 } else {
135173 clipped = clipRect->intersect (r);
136174 if (!clipped) {
@@ -142,22 +180,26 @@ bool Snapshot::clipTransformed(const Rect& r, SkRegion::Op op) {
142180 }
143181 case SkRegion::kUnion_Op : {
144182 if (CC_UNLIKELY (clipRegion)) {
145- clipped = clipRegionOp (r.left , r.top , r.right , r.bottom , SkRegion:: kUnion_Op );
183+ clipped = clipRegionAnd (r.left , r.top , r.right , r.bottom );
146184 } else {
147185 clipped = clipRect->unionWith (r);
148186 }
149187 break ;
150188 }
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+ }
151198 case SkRegion::kReplace_Op : {
152199 setClip (r.left , r.top , r.right , r.bottom );
153200 clipped = true ;
154201 break ;
155202 }
156- default : {
157- ensureClipRegion ();
158- clipped = clipRegionOp (r.left , r.top , r.right , r.bottom , op);
159- break ;
160- }
161203 }
162204
163205 if (clipped) {
@@ -171,7 +213,7 @@ void Snapshot::setClip(float left, float top, float right, float bottom) {
171213 clipRect->set (left, top, right, bottom);
172214#if STENCIL_BUFFER_SIZE
173215 if (clipRegion) {
174- clipRegion->setEmpty ();
216+ clipRegion->clear ();
175217 clipRegion = NULL ;
176218 }
177219#endif
0 commit comments