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

Side by Side Diff: gm/convexpolyclip.cpp

Issue 777643003: use ClipOp instead of SkRegion for clipping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « gm/complexclip2.cpp ('k') | gm/distantclip.cpp » ('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 2014 Google Inc. 3 * Copyright 2014 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 8
9 #include "gm.h" 9 #include "gm.h"
10 10
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if (doLayer) { 166 if (doLayer) {
167 SkRect bounds; 167 SkRect bounds;
168 clip->getBounds(&bounds); 168 clip->getBounds(&bounds);
169 bounds.outset(2, 2); 169 bounds.outset(2, 2);
170 bounds.offset(x, y); 170 bounds.offset(x, y);
171 canvas->saveLayer(&bounds, NULL); 171 canvas->saveLayer(&bounds, NULL);
172 } else { 172 } else {
173 canvas->save(); 173 canvas->save();
174 } 174 }
175 canvas->translate(x, y); 175 canvas->translate(x, y);
176 clip->setOnCanvas(canvas, SkRegion::kIntersect_Op, SkToBool( aa)); 176 clip->setOnCanvas(canvas, kIntersect_SkClipOp, SkToBool(aa)) ;
177 canvas->drawBitmap(fBmp, 0, 0); 177 canvas->drawBitmap(fBmp, 0, 0);
178 canvas->restore(); 178 canvas->restore();
179 x += fBmp.width() + kMargin; 179 x += fBmp.width() + kMargin;
180 } 180 }
181 for (int aa = 0; aa < 2; ++aa) { 181 for (int aa = 0; aa < 2; ++aa) {
182 182
183 SkPaint clipOutlinePaint; 183 SkPaint clipOutlinePaint;
184 clipOutlinePaint.setAntiAlias(true); 184 clipOutlinePaint.setAntiAlias(true);
185 clipOutlinePaint.setColor(0x50505050); 185 clipOutlinePaint.setColor(0x50505050);
186 clipOutlinePaint.setStyle(SkPaint::kStroke_Style); 186 clipOutlinePaint.setStyle(SkPaint::kStroke_Style);
187 clipOutlinePaint.setStrokeWidth(0); 187 clipOutlinePaint.setStrokeWidth(0);
188 188
189 if (doLayer) { 189 if (doLayer) {
190 SkRect bounds; 190 SkRect bounds;
191 clip->getBounds(&bounds); 191 clip->getBounds(&bounds);
192 bounds.outset(2, 2); 192 bounds.outset(2, 2);
193 bounds.offset(x, y); 193 bounds.offset(x, y);
194 canvas->saveLayer(&bounds, NULL); 194 canvas->saveLayer(&bounds, NULL);
195 } else { 195 } else {
196 canvas->save(); 196 canvas->save();
197 } 197 }
198 canvas->translate(x, y); 198 canvas->translate(x, y);
199 SkPath closedClipPath; 199 SkPath closedClipPath;
200 clip->asClosedPath(&closedClipPath); 200 clip->asClosedPath(&closedClipPath);
201 canvas->drawPath(closedClipPath, clipOutlinePaint); 201 canvas->drawPath(closedClipPath, clipOutlinePaint);
202 clip->setOnCanvas(canvas, SkRegion::kIntersect_Op, SkToBool( aa)); 202 clip->setOnCanvas(canvas, kIntersect_SkClipOp, SkToBool(aa)) ;
203 canvas->scale(1.f, 1.8f); 203 canvas->scale(1.f, 1.8f);
204 canvas->drawText(kTxt, SK_ARRAY_COUNT(kTxt)-1, 204 canvas->drawText(kTxt, SK_ARRAY_COUNT(kTxt)-1,
205 0, 1.5f * txtPaint.getTextSize(), 205 0, 1.5f * txtPaint.getTextSize(),
206 txtPaint); 206 txtPaint);
207 canvas->restore(); 207 canvas->restore();
208 x += textW + 2 * kMargin; 208 x += textW + 2 * kMargin;
209 } 209 }
210 y += fBmp.height() + kMargin; 210 y += fBmp.height() + kMargin;
211 } 211 }
212 y = 0; 212 y = 0;
213 startX += 2 * fBmp.width() + SkScalarCeilToInt(2 * textW) + 6 * kMar gin; 213 startX += 2 * fBmp.width() + SkScalarCeilToInt(2 * textW) + 6 * kMar gin;
214 } 214 }
215 } 215 }
216 216
217 virtual uint32_t onGetFlags() const { 217 virtual uint32_t onGetFlags() const {
218 return kAsBench_Flag | kSkipTiled_Flag; 218 return kAsBench_Flag | kSkipTiled_Flag;
219 } 219 }
220 220
221 private: 221 private:
222 class Clip { 222 class Clip {
223 public: 223 public:
224 enum ClipType { 224 enum ClipType {
225 kNone_ClipType, 225 kNone_ClipType,
226 kPath_ClipType, 226 kPath_ClipType,
227 kRect_ClipType 227 kRect_ClipType
228 }; 228 };
229 229
230 Clip () : fClipType(kNone_ClipType) {} 230 Clip () : fClipType(kNone_ClipType) {}
231 231
232 void setOnCanvas(SkCanvas* canvas, SkRegion::Op op, bool aa) const { 232 void setOnCanvas(SkCanvas* canvas, SkClipOp op, bool aa) const {
233 switch (fClipType) { 233 switch (fClipType) {
234 case kPath_ClipType: 234 case kPath_ClipType:
235 canvas->clipPath(fPath, op, aa); 235 canvas->clipPath(fPath, op, aa);
236 break; 236 break;
237 case kRect_ClipType: 237 case kRect_ClipType:
238 canvas->clipRect(fRect, op, aa); 238 canvas->clipRect(fRect, op, aa);
239 break; 239 break;
240 case kNone_ClipType: 240 case kNone_ClipType:
241 SkDEBUGFAIL("Uninitialized Clip."); 241 SkDEBUGFAIL("Uninitialized Clip.");
242 break; 242 break;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 294
295 SkTLList<Clip> fClips; 295 SkTLList<Clip> fClips;
296 SkBitmap fBmp; 296 SkBitmap fBmp;
297 297
298 typedef GM INHERITED; 298 typedef GM INHERITED;
299 }; 299 };
300 300
301 DEF_GM( return SkNEW(ConvexPolyClip); ) 301 DEF_GM( return SkNEW(ConvexPolyClip); )
302 302
303 } 303 }
OLDNEW
« no previous file with comments | « gm/complexclip2.cpp ('k') | gm/distantclip.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698