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