chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | #ifndef SKDEBUGCANVAS_H_ |
| 10 | #define SKDEBUGCANVAS_H_ |
| 11 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 12 | #include "SkCanvas.h" |
Brian Osman | 78a7648 | 2018-05-18 16:59:13 -0400 | [diff] [blame] | 13 | #include "SkCanvasVirtualEnforcer.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 14 | #include "SkDrawCommand.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 15 | #include "SkPath.h" |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 16 | #include "SkPathOps.h" |
reed | fb8c1fc | 2015-08-04 18:44:56 -0700 | [diff] [blame] | 17 | #include "SkString.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 18 | #include "SkTArray.h" |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 19 | #include "SkVertices.h" |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 20 | #include "UrlDataManager.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 21 | |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 22 | class GrAuditTrail; |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 23 | class SkNWayCanvas; |
Brian Osman | 255735e | 2018-04-06 14:51:42 -0400 | [diff] [blame] | 24 | class SkPicture; |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 25 | |
Brian Osman | 78a7648 | 2018-05-18 16:59:13 -0400 | [diff] [blame] | 26 | class SkDebugCanvas : public SkCanvasVirtualEnforcer<SkCanvas> { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 27 | public: |
chudy@google.com | 80a4a60 | 2012-07-30 18:54:07 +0000 | [diff] [blame] | 28 | SkDebugCanvas(int width, int height); |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 29 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 30 | ~SkDebugCanvas() override; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 31 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 32 | /** |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 33 | * Enable or disable overdraw visualization |
| 34 | */ |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 35 | void setOverdrawViz(bool overdrawViz); |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 36 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 37 | bool getOverdrawViz() const { return fOverdrawViz; } |
| 38 | |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 39 | /** |
| 40 | * Set the color of the clip visualization. An alpha of zero renders the clip invisible. |
| 41 | */ |
| 42 | void setClipVizColor(SkColor clipVizColor) { this->fClipVizColor = clipVizColor; } |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 43 | |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 44 | void setDrawGpuOpBounds(bool drawGpuOpBounds) { fDrawGpuOpBounds = drawGpuOpBounds; } |
joshualitt | 10d8fc2 | 2016-02-29 11:15:06 -0800 | [diff] [blame] | 45 | |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 46 | bool getDrawGpuOpBounds() const { return fDrawGpuOpBounds; } |
joshualitt | 5d5207a | 2016-02-29 12:46:04 -0800 | [diff] [blame] | 47 | |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 48 | /** |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 49 | Executes all draw calls to the canvas. |
| 50 | @param canvas The canvas being drawn to |
| 51 | */ |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 52 | void draw(SkCanvas *canvas); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 55 | Executes the draw calls up to the specified index. |
| 56 | @param canvas The canvas being drawn to |
| 57 | @param index The index of the final command being executed |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 58 | @param m an optional Mth gpu op to highlight, or -1 |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 59 | */ |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 60 | void drawTo(SkCanvas *canvas, int index, int m = -1); |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 61 | |
| 62 | /** |
chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 63 | Returns the most recently calculated transformation matrix |
| 64 | */ |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 65 | const SkMatrix &getCurrentMatrix() { |
chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 66 | return fMatrix; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | Returns the most recently calculated clip |
| 71 | */ |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 72 | const SkIRect &getCurrentClip() { |
chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 73 | return fClip; |
| 74 | } |
| 75 | |
| 76 | /** |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 77 | Removes the command at the specified index |
| 78 | @param index The index of the command to delete |
| 79 | */ |
| 80 | void deleteDrawCommandAt(int index); |
| 81 | |
| 82 | /** |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 83 | Returns the draw command at the given index. |
| 84 | @param index The index of the command |
| 85 | */ |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 86 | SkDrawCommand *getDrawCommandAt(int index); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 87 | |
| 88 | /** |
chudy@google.com | f141432 | 2012-07-03 20:28:14 +0000 | [diff] [blame] | 89 | Returns length of draw command vector. |
| 90 | */ |
commit-bot@chromium.org | 0d4fe14 | 2013-07-15 22:47:14 +0000 | [diff] [blame] | 91 | int getSize() const { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 92 | return fCommandVector.count(); |
chudy@google.com | f141432 | 2012-07-03 20:28:14 +0000 | [diff] [blame] | 93 | } |
| 94 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 95 | /** |
| 96 | Toggles the visibility / execution of the draw command at index i with |
| 97 | the value of toggle. |
| 98 | */ |
| 99 | void toggleCommand(int index, bool toggle); |
| 100 | |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 101 | /** |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 102 | Returns a JSON object representing up to the Nth draw, where N is less than |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 103 | SkDebugCanvas::getSize(). The encoder may use the UrlDataManager to store binary data such |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 104 | as images, referring to them via URLs embedded in the JSON. |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 105 | */ |
Brian Osman | d8a90f9 | 2019-01-28 13:41:19 -0500 | [diff] [blame] | 106 | void toJSON(SkJSONWriter& writer, UrlDataManager &urlDataManager, int n, SkCanvas *); |
ethannicholas | 402cd91 | 2016-02-10 12:57:30 -0800 | [diff] [blame] | 107 | |
Brian Osman | d8a90f9 | 2019-01-28 13:41:19 -0500 | [diff] [blame] | 108 | void toJSONOpList(SkJSONWriter& writer, int n, SkCanvas*); |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 109 | |
Robert Phillips | deaf568 | 2017-09-06 13:07:21 -0400 | [diff] [blame] | 110 | void detachCommands(SkTDArray<SkDrawCommand*>* dst) { |
| 111 | fCommandVector.swap(*dst); |
| 112 | } |
| 113 | |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 114 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 115 | void willSave() override; |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 116 | SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec &) override; |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 117 | bool onDoSaveBehind(const SkRect*) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 118 | void willRestore() override; |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 119 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 120 | void didConcat(const SkMatrix &) override; |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 121 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 122 | void didSetMatrix(const SkMatrix &) override; |
| 123 | |
reed | 97660cc | 2016-06-28 18:54:19 -0700 | [diff] [blame] | 124 | void onDrawAnnotation(const SkRect&, const char[], SkData*) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 125 | void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 126 | void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 127 | const SkPaint& paint) override; |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 128 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 129 | void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 130 | const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 131 | void onDrawPaint(const SkPaint&) override; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 132 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 133 | void onDrawRect(const SkRect&, const SkPaint&) override; |
Michael Ludwig | 7545190 | 2019-01-23 11:14:29 -0500 | [diff] [blame] | 134 | void onDrawEdgeAARect(const SkRect&, SkCanvas::QuadAAFlags, SkColor, SkBlendMode) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 135 | void onDrawOval(const SkRect&, const SkPaint&) override; |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 136 | void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 137 | void onDrawRRect(const SkRRect&, const SkPaint&) override; |
| 138 | void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override; |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 139 | void onDrawVerticesObject(const SkVertices*, const SkVertices::Bone bones[], int boneCount, |
| 140 | SkBlendMode, const SkPaint&) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 141 | void onDrawPath(const SkPath&, const SkPaint&) override; |
Brian Osman | c25e269 | 2018-03-12 10:57:28 -0400 | [diff] [blame] | 142 | void onDrawRegion(const SkRegion&, const SkPaint&) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 143 | void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override; |
Brian Osman | 78a7648 | 2018-05-18 16:59:13 -0400 | [diff] [blame] | 144 | void onDrawBitmapLattice(const SkBitmap&, const Lattice&, const SkRect&, |
| 145 | const SkPaint*) override; |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 146 | void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 147 | SrcRectConstraint) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 148 | void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override; |
Stan Iliev | ac42aeb | 2017-01-12 16:20:50 -0500 | [diff] [blame] | 149 | void onDrawImageLattice(const SkImage* image, const Lattice& lattice, |
| 150 | const SkRect& dst, const SkPaint* paint) override; |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 151 | void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 152 | const SkPaint*, SrcRectConstraint) override; |
Brian Salomon | d003d22 | 2018-11-26 13:25:05 -0500 | [diff] [blame] | 153 | void onDrawImageSet(const ImageSetEntry[], int count, SkFilterQuality, SkBlendMode) override; |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 154 | void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 155 | const SkPaint*) override; |
Brian Osman | c25e269 | 2018-03-12 10:57:28 -0400 | [diff] [blame] | 156 | void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst, |
| 157 | const SkPaint*) override; |
Brian Osman | 616f1cb | 2018-05-29 11:23:35 -0400 | [diff] [blame] | 158 | void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], |
| 159 | int, SkBlendMode, const SkRect*, const SkPaint*) override; |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 160 | void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override; |
| 161 | void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override; |
| 162 | void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override; |
| 163 | void onClipRegion(const SkRegion& region, SkClipOp) override; |
Derek Sollenberger | 6aab2ab | 2018-04-12 12:45:58 -0400 | [diff] [blame] | 164 | void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override; |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 165 | |
Brian Osman | c761108 | 2018-05-29 14:55:50 -0400 | [diff] [blame] | 166 | void onDrawDrawable(SkDrawable*, const SkMatrix*) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 167 | void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 168 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 169 | private: |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 170 | SkTDArray<SkDrawCommand*> fCommandVector; |
chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 171 | SkMatrix fMatrix; |
| 172 | SkIRect fClip; |
robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 173 | |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 174 | bool fOverdrawViz; |
ethannicholas | 0a0520a | 2016-02-12 12:06:53 -0800 | [diff] [blame] | 175 | SkColor fClipVizColor; |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 176 | bool fDrawGpuOpBounds; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 177 | |
| 178 | /** |
Robert Phillips | deaf568 | 2017-09-06 13:07:21 -0400 | [diff] [blame] | 179 | Adds the command to the class' vector of commands. |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 180 | @param command The draw command for execution |
| 181 | */ |
| 182 | void addDrawCommand(SkDrawCommand* command); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 183 | |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 184 | GrAuditTrail* getAuditTrail(SkCanvas*); |
| 185 | |
Brian Salomon | 144a5c5 | 2016-12-20 16:48:59 -0500 | [diff] [blame] | 186 | void drawAndCollectOps(int n, SkCanvas*); |
joshualitt | ae47aee | 2016-03-10 13:29:36 -0800 | [diff] [blame] | 187 | void cleanupAuditTrail(SkCanvas*); |
fmalita | 65cdb57 | 2015-03-26 07:24:48 -0700 | [diff] [blame] | 188 | |
Brian Osman | c761108 | 2018-05-29 14:55:50 -0400 | [diff] [blame] | 189 | typedef SkCanvasVirtualEnforcer<SkCanvas> INHERITED; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | #endif |