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

Side by Side Diff: tools/debugger/SkDebugCanvas.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 | « tools/debugger/SkDebugCanvas.h ('k') | tools/debugger/SkDrawCommand.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 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkCanvasPriv.h" 8 #include "SkCanvasPriv.h"
9 #include "SkClipStack.h" 9 #include "SkClipStack.h"
10 #include "SkDebugCanvas.h" 10 #include "SkDebugCanvas.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // rounded out. The following code creates a nearly maximal rect that will 100 // rounded out. The following code creates a nearly maximal rect that will
101 // not get collapsed by the coming conversions (Due to precision loss the 101 // not get collapsed by the coming conversions (Due to precision loss the
102 // inset has to be surprisingly large). 102 // inset has to be surprisingly large).
103 SkIRect largeIRect = SkIRect::MakeLargest(); 103 SkIRect largeIRect = SkIRect::MakeLargest();
104 largeIRect.inset(1024, 1024); 104 largeIRect.inset(1024, 1024);
105 SkRect large = SkRect::Make(largeIRect); 105 SkRect large = SkRect::Make(largeIRect);
106 #ifdef SK_DEBUG 106 #ifdef SK_DEBUG
107 SkASSERT(!large.roundOut().isEmpty()); 107 SkASSERT(!large.roundOut().isEmpty());
108 #endif 108 #endif
109 // call the base class' version to avoid adding a draw command 109 // call the base class' version to avoid adding a draw command
110 this->INHERITED::onClipRect(large, SkRegion::kReplace_Op, kHard_ClipEdgeStyl e); 110 this->INHERITED::onClipRect(large, kReplace_Op, kHard_ClipEdgeStyle);
111 } 111 }
112 112
113 SkDebugCanvas::~SkDebugCanvas() { 113 SkDebugCanvas::~SkDebugCanvas() {
114 fCommandVector.deleteAll(); 114 fCommandVector.deleteAll();
115 } 115 }
116 116
117 void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) { 117 void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) {
118 fCommandVector.push(command); 118 fCommandVector.push(command);
119 } 119 }
120 120
(...skipping 27 matching lines...) Expand all
148 } 148 }
149 prev = bitmap.getColor(0,0); 149 prev = bitmap.getColor(0,0);
150 } 150 }
151 return layer; 151 return layer;
152 } 152 }
153 153
154 class SkDebugClipVisitor : public SkCanvas::ClipVisitor { 154 class SkDebugClipVisitor : public SkCanvas::ClipVisitor {
155 public: 155 public:
156 SkDebugClipVisitor(SkCanvas* canvas) : fCanvas(canvas) {} 156 SkDebugClipVisitor(SkCanvas* canvas) : fCanvas(canvas) {}
157 157
158 void clipRect(const SkRect& r, SkRegion::Op, bool doAA) override { 158 void clipRect(const SkRect& r, SkCanvas::ClipOp, bool doAA) override {
159 SkPaint p; 159 SkPaint p;
160 p.setColor(SK_ColorRED); 160 p.setColor(SK_ColorRED);
161 p.setStyle(SkPaint::kStroke_Style); 161 p.setStyle(SkPaint::kStroke_Style);
162 p.setAntiAlias(doAA); 162 p.setAntiAlias(doAA);
163 fCanvas->drawRect(r, p); 163 fCanvas->drawRect(r, p);
164 } 164 }
165 void clipRRect(const SkRRect& rr, SkRegion::Op, bool doAA) override { 165 void clipRRect(const SkRRect& rr, SkCanvas::ClipOp, bool doAA) override {
166 SkPaint p; 166 SkPaint p;
167 p.setColor(SK_ColorGREEN); 167 p.setColor(SK_ColorGREEN);
168 p.setStyle(SkPaint::kStroke_Style); 168 p.setStyle(SkPaint::kStroke_Style);
169 p.setAntiAlias(doAA); 169 p.setAntiAlias(doAA);
170 fCanvas->drawRRect(rr, p); 170 fCanvas->drawRRect(rr, p);
171 } 171 }
172 void clipPath(const SkPath& path, SkRegion::Op, bool doAA) override { 172 void clipPath(const SkPath& path, SkCanvas::ClipOp, bool doAA) override {
173 SkPaint p; 173 SkPaint p;
174 p.setColor(SK_ColorBLUE); 174 p.setColor(SK_ColorBLUE);
175 p.setStyle(SkPaint::kStroke_Style); 175 p.setStyle(SkPaint::kStroke_Style);
176 p.setAntiAlias(doAA); 176 p.setAntiAlias(doAA);
177 fCanvas->drawPath(path, p); 177 fCanvas->drawPath(path, p);
178 } 178 }
179 179
180 protected: 180 protected:
181 SkCanvas* fCanvas; 181 SkCanvas* fCanvas;
182 182
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 int saveCount = canvas->save(); 215 int saveCount = canvas->save();
216 216
217 SkRect windowRect = SkRect::MakeWH(SkIntToScalar(canvas->getBaseLayerSize(). width()), 217 SkRect windowRect = SkRect::MakeWH(SkIntToScalar(canvas->getBaseLayerSize(). width()),
218 SkIntToScalar(canvas->getBaseLayerSize(). height())); 218 SkIntToScalar(canvas->getBaseLayerSize(). height()));
219 219
220 bool pathOpsMode = getAllowSimplifyClip(); 220 bool pathOpsMode = getAllowSimplifyClip();
221 canvas->setAllowSimplifyClip(pathOpsMode); 221 canvas->setAllowSimplifyClip(pathOpsMode);
222 canvas->clear(SK_ColorWHITE); 222 canvas->clear(SK_ColorWHITE);
223 canvas->resetMatrix(); 223 canvas->resetMatrix();
224 if (!windowRect.isEmpty()) { 224 if (!windowRect.isEmpty()) {
225 canvas->clipRect(windowRect, SkRegion::kReplace_Op); 225 canvas->clipRect(windowRect, SkCanvas::kReplace_Op);
226 } 226 }
227 this->applyUserTransform(canvas); 227 this->applyUserTransform(canvas);
228 228
229 if (fPaintFilterCanvas) { 229 if (fPaintFilterCanvas) {
230 fPaintFilterCanvas->addCanvas(canvas); 230 fPaintFilterCanvas->addCanvas(canvas);
231 canvas = fPaintFilterCanvas.get(); 231 canvas = fPaintFilterCanvas.get();
232 232
233 } 233 }
234 234
235 if (fMegaVizMode) { 235 if (fMegaVizMode) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 if (at && acb) { 277 if (at && acb) {
278 delete acb; 278 delete acb;
279 } 279 }
280 #endif 280 #endif
281 } 281 }
282 282
283 if (SkColorGetA(fClipVizColor) != 0) { 283 if (SkColorGetA(fClipVizColor) != 0) {
284 canvas->save(); 284 canvas->save();
285 #define LARGE_COORD 1000000000 285 #define LARGE_COORD 1000000000
286 canvas->clipRect(SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COOR D, LARGE_COORD), 286 canvas->clipRect(SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COOR D, LARGE_COORD),
287 SkRegion::kReverseDifference_Op); 287 SkCanvas::kReverseDifference_Op);
288 SkPaint clipPaint; 288 SkPaint clipPaint;
289 clipPaint.setColor(fClipVizColor); 289 clipPaint.setColor(fClipVizColor);
290 canvas->drawPaint(clipPaint); 290 canvas->drawPaint(clipPaint);
291 canvas->restore(); 291 canvas->restore();
292 } 292 }
293 293
294 if (fMegaVizMode) { 294 if (fMegaVizMode) {
295 canvas->save(); 295 canvas->save();
296 // nuke the CTM 296 // nuke the CTM
297 canvas->resetMatrix(); 297 canvas->resetMatrix();
298 // turn off clipping 298 // turn off clipping
299 if (!windowRect.isEmpty()) { 299 if (!windowRect.isEmpty()) {
300 SkRect r = windowRect; 300 SkRect r = windowRect;
301 r.outset(SK_Scalar1, SK_Scalar1); 301 r.outset(SK_Scalar1, SK_Scalar1);
302 canvas->clipRect(r, SkRegion::kReplace_Op); 302 canvas->clipRect(r, SkCanvas::kReplace_Op);
303 } 303 }
304 // visualize existing clips 304 // visualize existing clips
305 SkDebugClipVisitor visitor(canvas); 305 SkDebugClipVisitor visitor(canvas);
306 306
307 canvas->replayClips(&visitor); 307 canvas->replayClips(&visitor);
308 308
309 canvas->restore(); 309 canvas->restore();
310 } 310 }
311 if (pathOpsMode) { 311 if (pathOpsMode) {
312 this->resetClipStackData(); 312 this->resetClipStackData();
313 const SkClipStack* clipStack = canvas->getClipStack(); 313 const SkClipStack* clipStack = canvas->getClipStack();
314 SkClipStack::Iter iter(*clipStack, SkClipStack::Iter::kBottom_IterStart) ; 314 SkClipStack::Iter iter(*clipStack, SkClipStack::Iter::kBottom_IterStart) ;
315 const SkClipStack::Element* element; 315 const SkClipStack::Element* element;
316 SkPath devPath; 316 SkPath devPath;
317 while ((element = iter.next())) { 317 while ((element = iter.next())) {
318 SkClipStack::Element::Type type = element->getType(); 318 SkClipStack::Element::Type type = element->getType();
319 SkPath operand; 319 SkPath operand;
320 if (type != SkClipStack::Element::kEmpty_Type) { 320 if (type != SkClipStack::Element::kEmpty_Type) {
321 element->asPath(&operand); 321 element->asPath(&operand);
322 } 322 }
323 SkRegion::Op elementOp = element->getOp(); 323 SkCanvas::ClipOp elementOp = element->getOp();
324 this->addClipStackData(devPath, operand, elementOp); 324 this->addClipStackData(devPath, operand, elementOp);
325 if (elementOp == SkRegion::kReplace_Op) { 325 if (elementOp == SkCanvas::kReplace_Op) {
326 devPath = operand; 326 devPath = operand;
327 } else { 327 } else {
328 Op(devPath, operand, (SkPathOp) elementOp, &devPath); 328 Op(devPath, operand, (SkPathOp) elementOp, &devPath);
329 } 329 }
330 } 330 }
331 this->lastClipStackData(devPath); 331 this->lastClipStackData(devPath);
332 } 332 }
333 fMatrix = canvas->getTotalMatrix(); 333 fMatrix = canvas->getTotalMatrix();
334 if (!canvas->getClipDeviceBounds(&fClip)) { 334 if (!canvas->getClipDeviceBounds(&fClip)) {
335 fClip.setEmpty(); 335 fClip.setEmpty();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkFilterQual ity quality) { 536 void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkFilterQual ity quality) {
537 if (fOverrideFilterQuality == overrideTexFiltering && fFilterQuality == qual ity) { 537 if (fOverrideFilterQuality == overrideTexFiltering && fFilterQuality == qual ity) {
538 return; 538 return;
539 } 539 }
540 540
541 fOverrideFilterQuality = overrideTexFiltering; 541 fOverrideFilterQuality = overrideTexFiltering;
542 fFilterQuality = quality; 542 fFilterQuality = quality;
543 this->updatePaintFilterCanvas(); 543 this->updatePaintFilterCanvas();
544 } 544 }
545 545
546 void SkDebugCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyl e edgeStyle) { 546 void SkDebugCanvas::onClipPath(const SkPath& path, ClipOp op, ClipEdgeStyle edge Style) {
547 this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle)); 547 this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle));
548 } 548 }
549 549
550 void SkDebugCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyl e edgeStyle) { 550 void SkDebugCanvas::onClipRect(const SkRect& rect, ClipOp op, ClipEdgeStyle edge Style) {
551 this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle)); 551 this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle));
552 } 552 }
553 553
554 void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeS tyle edgeStyle) { 554 void SkDebugCanvas::onClipRRect(const SkRRect& rrect, ClipOp op, ClipEdgeStyle e dgeStyle) {
555 this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle = = edgeStyle)); 555 this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle = = edgeStyle));
556 } 556 }
557 557
558 void SkDebugCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) { 558 void SkDebugCanvas::onClipRegion(const SkRegion& region, ClipOp op) {
559 this->addDrawCommand(new SkClipRegionCommand(region, op)); 559 this->addDrawCommand(new SkClipRegionCommand(region, op));
560 } 560 }
561 561
562 void SkDebugCanvas::didConcat(const SkMatrix& matrix) { 562 void SkDebugCanvas::didConcat(const SkMatrix& matrix) {
563 this->addDrawCommand(new SkConcatCommand(matrix)); 563 this->addDrawCommand(new SkConcatCommand(matrix));
564 this->INHERITED::didConcat(matrix); 564 this->INHERITED::didConcat(matrix);
565 } 565 }
566 566
567 void SkDebugCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkDat a* value) { 567 void SkDebugCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkDat a* value) {
568 this->addDrawCommand(new SkDrawAnnotationCommand(rect, key, sk_ref_sp(value) )); 568 this->addDrawCommand(new SkDrawAnnotationCommand(rect, key, sk_ref_sp(value) ));
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 fClipStackData.appendf("%s%s.close();<br>", kHTML4SpaceIndent, p athName); 821 fClipStackData.appendf("%s%s.close();<br>", kHTML4SpaceIndent, p athName);
822 break; 822 break;
823 default: 823 default:
824 SkDEBUGFAIL("bad verb"); 824 SkDEBUGFAIL("bad verb");
825 return; 825 return;
826 } 826 }
827 } 827 }
828 } 828 }
829 829
830 void SkDebugCanvas::addClipStackData(const SkPath& devPath, const SkPath& operan d, 830 void SkDebugCanvas::addClipStackData(const SkPath& devPath, const SkPath& operan d,
831 SkRegion::Op elementOp) { 831 SkCanvas::ClipOp elementOp) {
832 if (elementOp == SkRegion::kReplace_Op) { 832 if (elementOp == SkCanvas::kReplace_Op) {
833 if (!lastClipStackData(devPath)) { 833 if (!lastClipStackData(devPath)) {
834 fSaveDevPath = operand; 834 fSaveDevPath = operand;
835 } 835 }
836 fCalledAddStackData = false; 836 fCalledAddStackData = false;
837 } else { 837 } else {
838 fClipStackData.appendf("<br>static void test(skiatest::Reporter* reporte r," 838 fClipStackData.appendf("<br>static void test(skiatest::Reporter* reporte r,"
839 " const char* filename) {<br>"); 839 " const char* filename) {<br>");
840 addPathData(fCalledAddStackData ? devPath : fSaveDevPath, "path"); 840 addPathData(fCalledAddStackData ? devPath : fSaveDevPath, "path");
841 addPathData(operand, "pathB"); 841 addPathData(operand, "pathB");
842 fClipStackData.appendf("%stestPathOp(reporter, path, pathB, %s, filename );<br>", 842 fClipStackData.appendf("%stestPathOp(reporter, path, pathB, %s, filename );<br>",
843 kHTML4SpaceIndent, gOpStrs[elementOp]); 843 kHTML4SpaceIndent, gOpStrs[elementOp]);
844 fClipStackData.appendf("}<br>"); 844 fClipStackData.appendf("}<br>");
845 fCalledAddStackData = true; 845 fCalledAddStackData = true;
846 } 846 }
847 } 847 }
848 848
849 bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) { 849 bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) {
850 if (fCalledAddStackData) { 850 if (fCalledAddStackData) {
851 fClipStackData.appendf("<br>"); 851 fClipStackData.appendf("<br>");
852 addPathData(devPath, "pathOut"); 852 addPathData(devPath, "pathOut");
853 return true; 853 return true;
854 } 854 }
855 return false; 855 return false;
856 } 856 }
OLDNEW
« no previous file with comments | « tools/debugger/SkDebugCanvas.h ('k') | tools/debugger/SkDrawCommand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698