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

Side by Side Diff: src/utils/debugger/SkDebugCanvas.cpp

Issue 282283002: add pathops to debugger (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: show clip stack only when pathops are enabled Created 6 years, 7 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
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 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 9
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 for (int i = 0; i < fActiveCulls.count(); ++i) { 233 for (int i = 0; i < fActiveCulls.count(); ++i) {
234 fActiveCulls[i]->setActive(true); 234 fActiveCulls[i]->setActive(true);
235 } 235 }
236 } 236 }
237 237
238 void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { 238 void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) {
239 SkASSERT(!fCommandVector.isEmpty()); 239 SkASSERT(!fCommandVector.isEmpty());
240 SkASSERT(index < fCommandVector.count()); 240 SkASSERT(index < fCommandVector.count());
241 int i = 0; 241 int i = 0;
242 242
243 bool pathOpsMode = getAllowSimplifyClip();
244 canvas->setAllowSimplifyClip(pathOpsMode);
243 // This only works assuming the canvas and device are the same ones that 245 // This only works assuming the canvas and device are the same ones that
244 // were previously drawn into because they need to preserve all saves 246 // were previously drawn into because they need to preserve all saves
245 // and restores. 247 // and restores.
246 // The visibility filter also requires a full re-draw - otherwise we can 248 // The visibility filter also requires a full re-draw - otherwise we can
247 // end up drawing the filter repeatedly. 249 // end up drawing the filter repeatedly.
248 if (fIndex < index && !fFilter && !fMegaVizMode) { 250 if (fIndex < index && !fFilter && !fMegaVizMode && !pathOpsMode) {
249 i = fIndex + 1; 251 i = fIndex + 1;
250 } else { 252 } else {
251 for (int j = 0; j < fOutstandingSaveCount; j++) { 253 for (int j = 0; j < fOutstandingSaveCount; j++) {
252 canvas->restore(); 254 canvas->restore();
253 } 255 }
254 canvas->clear(SK_ColorTRANSPARENT); 256 canvas->clear(SK_ColorTRANSPARENT);
255 canvas->resetMatrix(); 257 canvas->resetMatrix();
256 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), 258 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth),
257 SkIntToScalar(fHeight)); 259 SkIntToScalar(fHeight));
258 canvas->clipRect(rect, SkRegion::kReplace_Op ); 260 canvas->clipRect(rect, SkRegion::kReplace_Op );
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // turn off clipping 330 // turn off clipping
329 canvas->clipRect(r, SkRegion::kReplace_Op); 331 canvas->clipRect(r, SkRegion::kReplace_Op);
330 332
331 // visualize existing clips 333 // visualize existing clips
332 SkDebugClipVisitor visitor(canvas); 334 SkDebugClipVisitor visitor(canvas);
333 335
334 canvas->replayClips(&visitor); 336 canvas->replayClips(&visitor);
335 337
336 canvas->restore(); 338 canvas->restore();
337 } 339 }
340 if (pathOpsMode) {
robertphillips 2014/05/16 12:21:24 this-> ?
caryclark 2014/05/16 13:49:02 Done.
341 resetClipStackData();
342 const SkClipStack* clipStack = canvas->getClipStack();
343 SkClipStack::Iter iter(*clipStack, SkClipStack::Iter::kBottom_IterStart) ;
344 const SkClipStack::Element* element;
345 SkPath devPath;
346 while ((element = iter.next())) {
347 SkClipStack::Element::Type type = element->getType();
348 SkPath operand;
349 if (type != SkClipStack::Element::kEmpty_Type) {
350 element->asPath(&operand);
351 }
352 SkRegion::Op elementOp = element->getOp();
robertphillips 2014/05/16 12:21:24 this-> ?
caryclark 2014/05/16 13:49:02 Done.
353 addClipStackData(devPath, operand, elementOp);
354 if (elementOp == SkRegion::kReplace_Op) {
355 devPath = operand;
356 } else {
357 Op(devPath, operand, (SkPathOp) elementOp, &devPath);
358 }
359 }
robertphillips 2014/05/16 12:21:24 this-> ?
caryclark 2014/05/16 13:49:02 Done.
360 lastClipStackData(devPath);
361 }
338 fMatrix = canvas->getTotalMatrix(); 362 fMatrix = canvas->getTotalMatrix();
339 if (!canvas->getClipDeviceBounds(&fClip)) { 363 if (!canvas->getClipDeviceBounds(&fClip)) {
340 fClip.setEmpty(); 364 fClip.setEmpty();
341 } 365 }
342 fIndex = index; 366 fIndex = index;
343 } 367 }
344 368
345 void SkDebugCanvas::deleteDrawCommandAt(int index) { 369 void SkDebugCanvas::deleteDrawCommandAt(int index) {
346 SkASSERT(index < fCommandVector.count()); 370 SkASSERT(index < fCommandVector.count());
347 delete fCommandVector[index]; 371 delete fCommandVector[index];
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 605
582 void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) { 606 void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) {
583 this->addDrawCommand(new SkSetMatrixCommand(matrix)); 607 this->addDrawCommand(new SkSetMatrixCommand(matrix));
584 this->INHERITED::didSetMatrix(matrix); 608 this->INHERITED::didSetMatrix(matrix);
585 } 609 }
586 610
587 void SkDebugCanvas::toggleCommand(int index, bool toggle) { 611 void SkDebugCanvas::toggleCommand(int index, bool toggle) {
588 SkASSERT(index < fCommandVector.count()); 612 SkASSERT(index < fCommandVector.count());
589 fCommandVector[index]->setVisible(toggle); 613 fCommandVector[index]->setVisible(toggle);
590 } 614 }
615
616 static const char* gFillTypeStrs[] = {
617 "kWinding_FillType",
618 "kEvenOdd_FillType",
619 "kInverseWinding_FillType",
620 "kInverseEvenOdd_FillType"
621 };
622
623 static const char* gOpStrs[] = {
624 "kDifference_PathOp",
625 "kIntersect_PathOp",
626 "kUnion_PathOp",
627 "kXor_PathOp",
628 "kReverseDifference_PathOp",
629 };
630
631 void SkDebugCanvas::output_scalar(SkScalar num) {
632 if (num == (int) num) {
633 fClipStackData.appendf("%d", (int) num);
634 } else {
635 SkString str;
636 str.printf("%1.9g", num);
637 int width = (int) str.size();
638 const char* cStr = str.c_str();
639 while (cStr[width - 1] == '0') {
640 --width;
641 }
642 str.resize(width);
643 fClipStackData.appendf("%sf", str.c_str());
644 }
645 }
646
647 void SkDebugCanvas::output_points(const SkPoint* pts, int count) {
648 for (int index = 0; index < count; ++index) {
649 output_scalar(pts[index].fX);
650 fClipStackData.appendf(", ");
651 output_scalar(pts[index].fY);
652 if (index + 1 < count) {
653 fClipStackData.appendf(", ");
654 }
655 }
656 fClipStackData.appendf(");<br>");
657 }
658
659 void SkDebugCanvas::addPathData(const SkPath& path, const char* pathName) {
660 SkPath::RawIter iter(path);
661 SkPath::FillType fillType = path.getFillType();
662 fClipStackData.appendf(" SkPath %s;<br>", pathName);
663 fClipStackData.appendf(" %s.setFillType(SkPath::%s);<br>", pathName,
664 gFillTypeStrs[fillType]);
665 iter.setPath(path);
666 uint8_t verb;
667 SkPoint pts[4];
668 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
669 switch (verb) {
670 case SkPath::kMove_Verb:
671 fClipStackData.appendf(" %s.moveTo(", pathName);
672 output_points(&pts[0], 1);
673 continue;
674 case SkPath::kLine_Verb:
675 fClipStackData.appendf(" %s.lineTo(", pathName);
676 output_points(&pts[1], 1);
677 break;
678 case SkPath::kQuad_Verb:
679 fClipStackData.appendf(" %s.quadTo(", pathName);
680 output_points(&pts[1], 2);
681 break;
robertphillips 2014/05/16 12:21:24 I know it isn't live yet but do we want to handle
caryclark 2014/05/16 13:49:02 Done.
682 case SkPath::kCubic_Verb:
683 fClipStackData.appendf(" %s.cubicTo(", pathName);
684 output_points(&pts[1], 3);
685 break;
686 case SkPath::kClose_Verb:
687 fClipStackData.appendf(" %s.close();<br>", pathName);
688 break;
689 default:
690 SkDEBUGFAIL("bad verb");
691 return;
692 }
693 }
694 }
695
696 void SkDebugCanvas::addClipStackData(const SkPath& devPath, const SkPath& operan d,
697 SkRegion::Op elementOp) {
698 if (elementOp == SkRegion::kReplace_Op) {
699 if (!lastClipStackData(devPath)) {
700 fSaveDevPath = operand;
701 }
702 fCalledAddStackData = false;
703 } else {
704 fClipStackData.appendf("<br>static void test(skiatest::Reporter* reporte r,"
705 " const char* filename) {<br>");
706 addPathData(fCalledAddStackData ? devPath : fSaveDevPath, "path");
707 addPathData(operand, "pathB");
708 fClipStackData.appendf(" testPathOp(reporter, path, pathB, %s, filena me);<br>",
709 gOpStrs[elementOp]);
710 fClipStackData.appendf("}<br>");
711 fCalledAddStackData = true;
712 }
713 }
714
715 bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) {
716 if (fCalledAddStackData) {
717 fClipStackData.appendf("<br>");
718 addPathData(devPath, "pathOut");
719 return true;
720 }
721 return false;
722 }
OLDNEW
« src/utils/debugger/SkDebugCanvas.h ('K') | « src/utils/debugger/SkDebugCanvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698