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

Side by Side Diff: gm/convexpolyclip.cpp

Issue 2355483002: abstract name of clipping ops, to transtion to a more restricted set (Closed)
Patch Set: no need for ifdef for globals Created 4 years, 3 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
« no previous file with comments | « gm/complexclip_blur_tiled.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 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...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, nullptr); 171 canvas->saveLayer(&bounds, nullptr);
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, SkCanvas::kIntersect_Op, 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, nullptr); 194 canvas->saveLayer(&bounds, nullptr);
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, SkCanvas::kIntersect_Op, 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 bool runAsBench() const override { return true; } 217 bool runAsBench() const override { return true; }
218 218
219 private: 219 private:
220 class Clip { 220 class Clip {
221 public: 221 public:
222 enum ClipType { 222 enum ClipType {
223 kNone_ClipType, 223 kNone_ClipType,
224 kPath_ClipType, 224 kPath_ClipType,
225 kRect_ClipType 225 kRect_ClipType
226 }; 226 };
227 227
228 Clip () : fClipType(kNone_ClipType) {} 228 Clip () : fClipType(kNone_ClipType) {}
229 229
230 void setOnCanvas(SkCanvas* canvas, SkRegion::Op op, bool aa) const { 230 void setOnCanvas(SkCanvas* canvas, SkCanvas::ClipOp op, bool aa) const {
231 switch (fClipType) { 231 switch (fClipType) {
232 case kPath_ClipType: 232 case kPath_ClipType:
233 canvas->clipPath(fPath, op, aa); 233 canvas->clipPath(fPath, op, aa);
234 break; 234 break;
235 case kRect_ClipType: 235 case kRect_ClipType:
236 canvas->clipRect(fRect, op, aa); 236 canvas->clipRect(fRect, op, aa);
237 break; 237 break;
238 case kNone_ClipType: 238 case kNone_ClipType:
239 SkDEBUGFAIL("Uninitialized Clip."); 239 SkDEBUGFAIL("Uninitialized Clip.");
240 break; 240 break;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 292
293 typedef SkTLList<Clip, 1> ClipList; 293 typedef SkTLList<Clip, 1> ClipList;
294 ClipList fClips; 294 ClipList fClips;
295 SkBitmap fBmp; 295 SkBitmap fBmp;
296 296
297 typedef GM INHERITED; 297 typedef GM INHERITED;
298 }; 298 };
299 299
300 DEF_GM(return new ConvexPolyClip;) 300 DEF_GM(return new ConvexPolyClip;)
301 } 301 }
OLDNEW
« no previous file with comments | « gm/complexclip_blur_tiled.cpp ('k') | gm/distantclip.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698