chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #ifndef SKDEBUGGER_H_ |
| 11 | #define SKDEBUGGER_H_ |
| 12 | |
| 13 | #include "SkDebugCanvas.h" |
| 14 | #include "SkPicture.h" |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 15 | #include "SkTArray.h" |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 16 | |
borenet@google.com | 2d9dbd4 | 2013-03-12 13:07:40 +0000 | [diff] [blame] | 17 | class SkString; |
| 18 | |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 19 | class SkDebugger { |
| 20 | public: |
| 21 | SkDebugger(); |
| 22 | |
| 23 | ~SkDebugger(); |
| 24 | |
| 25 | void setIndex(int index) { |
| 26 | fIndex = index; |
| 27 | } |
| 28 | void draw(SkCanvas* canvas) { |
kkinnunen | 5a2315e | 2015-01-05 11:51:13 -0800 | [diff] [blame] | 29 | if (fIndex >= 0) { |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 30 | fDebugCanvas->drawTo(canvas, fIndex); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | void step(); |
| 35 | void stepBack(); |
| 36 | void play(); |
| 37 | void rewind(); |
| 38 | |
| 39 | bool isCommandVisible(int index) { |
| 40 | return fDebugCanvas->getDrawCommandVisibilityAt(index); |
| 41 | } |
| 42 | |
| 43 | void setCommandVisible(int index, bool isVisible) { |
| 44 | fDebugCanvas->toggleCommand(index, isVisible); |
| 45 | } |
| 46 | |
kkinnunen | 5037e9d | 2014-12-30 07:22:58 -0800 | [diff] [blame] | 47 | SkDrawCommand* getDrawCommandAt(int index) { |
| 48 | return fDebugCanvas->getDrawCommandAt(index); |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 49 | } |
| 50 | |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 51 | const SkTDArray<SkDrawCommand*>& getDrawCommands() const { |
| 52 | return fDebugCanvas->getDrawCommands(); |
| 53 | } |
| 54 | |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 55 | void highlightCurrentCommand(bool on) { |
| 56 | fDebugCanvas->toggleFilter(on); |
| 57 | } |
| 58 | |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 59 | void loadPicture(SkPicture* picture); |
| 60 | |
robertphillips | 587ea71 | 2016-03-25 07:04:35 -0700 | [diff] [blame] | 61 | sk_sp<SkPicture> copyPicture(); |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 62 | |
kkinnunen | 5037e9d | 2014-12-30 07:22:58 -0800 | [diff] [blame] | 63 | int getSize() const { |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 64 | return fDebugCanvas->getSize(); |
| 65 | } |
| 66 | |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 67 | void setUserMatrix(SkMatrix userMatrix) { |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 68 | // Should this live in debugger instead? |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 69 | fDebugCanvas->setUserMatrix(userMatrix); |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | int getCommandAtPoint(int x, int y, int index) { |
| 73 | return fDebugCanvas->getCommandAtPoint(x, y, index); |
| 74 | } |
| 75 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 76 | const SkTDArray<SkString*>* getCommandInfo(int index) const { |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 77 | return fDebugCanvas->getCommandInfo(index); |
| 78 | } |
| 79 | |
| 80 | const SkMatrix& getCurrentMatrix() { |
| 81 | return fDebugCanvas->getCurrentMatrix(); |
| 82 | } |
| 83 | |
| 84 | const SkIRect& getCurrentClip() { |
| 85 | return fDebugCanvas->getCurrentClip(); |
| 86 | } |
| 87 | |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 88 | SkRect pictureCull() const { |
Florin Malita | f530586 | 2016-11-15 10:03:32 -0500 | [diff] [blame] | 89 | return fPicture ? fPicture->cullRect() : SkRect::MakeEmpty(); |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | int index() { |
| 93 | return fIndex; |
| 94 | } |
| 95 | |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 96 | void setOverdrawViz(bool overDrawViz) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 97 | if (fDebugCanvas) { |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 98 | fDebugCanvas->setOverdrawViz(overDrawViz); |
| 99 | } |
| 100 | } |
| 101 | |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 102 | void setPathOps(bool pathOps) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 103 | if (fDebugCanvas) { |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 104 | fDebugCanvas->setAllowSimplifyClip(pathOps); |
| 105 | } |
| 106 | } |
| 107 | |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 108 | void setMegaViz(bool megaViz) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 109 | if (fDebugCanvas) { |
commit-bot@chromium.org | 768ac85 | 2014-03-03 16:32:17 +0000 | [diff] [blame] | 110 | fDebugCanvas->setMegaVizMode(megaViz); |
| 111 | } |
| 112 | } |
| 113 | |
reed | e7903c7 | 2015-03-16 10:26:13 -0700 | [diff] [blame] | 114 | void setTexFilterOverride(bool texFilterOverride, SkFilterQuality quality) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 115 | if (fDebugCanvas) { |
reed | e7903c7 | 2015-03-16 10:26:13 -0700 | [diff] [blame] | 116 | fDebugCanvas->overrideTexFiltering(texFilterOverride, quality); |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
skia.committer@gmail.com | 91274b9 | 2013-03-13 07:01:04 +0000 | [diff] [blame] | 120 | void getOverviewText(const SkTDArray<double>* typeTimes, double totTime, |
robertphillips@google.com | e428f9b | 2013-03-12 15:33:40 +0000 | [diff] [blame] | 121 | SkString* overview, int numRuns); |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 122 | |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 123 | void getClipStackText(SkString* clipStack); |
| 124 | |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 125 | private: |
Florin Malita | f530586 | 2016-11-15 10:03:32 -0500 | [diff] [blame] | 126 | std::unique_ptr<SkDebugCanvas> fDebugCanvas; |
| 127 | sk_sp<SkPicture> fPicture; |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 128 | |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 129 | int fIndex; |
| 130 | }; |
| 131 | |
| 132 | |
| 133 | #endif /* SKDEBUGGER_H_ */ |