| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +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 SKDEBUGCANVAS_H_ |
| 11 | #define SKDEBUGCANVAS_H_ |
| 12 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 13 | #include "SkCanvas.h" |
| 14 | #include "SkDrawCommand.h" |
| 15 | #include "SkPicture.h" |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 16 | #include "SkTArray.h" |
| chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 17 | #include "SkString.h" |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 18 | |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 19 | class SkTexOverrideFilter; |
| 20 | |
| fmalita@google.com | 86681b3 | 2013-06-13 20:59:14 +0000 | [diff] [blame] | 21 | class SK_API SkDebugCanvas : public SkCanvas { |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 22 | public: |
| chudy@google.com | 80a4a60 | 2012-07-30 18:54:07 +0000 | [diff] [blame] | 23 | SkDebugCanvas(int width, int height); |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 24 | virtual ~SkDebugCanvas(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 25 | |
| 26 | void toggleFilter(bool toggle); |
| 27 | |
| 28 | /** |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 29 | * Enable or disable overdraw visualization |
| 30 | */ |
| 31 | void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; } |
| 32 | |
| 33 | /** |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 34 | * Enable or disable texure filtering override |
| 35 | */ |
| skia.committer@gmail.com | f84ad8f | 2013-10-18 07:01:59 +0000 | [diff] [blame] | 36 | void overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level); |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 37 | |
| 38 | /** |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 39 | Executes all draw calls to the canvas. |
| 40 | @param canvas The canvas being drawn to |
| 41 | */ |
| 42 | void draw(SkCanvas* canvas); |
| 43 | |
| 44 | /** |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 45 | Executes the draw calls up to the specified index. |
| 46 | @param canvas The canvas being drawn to |
| 47 | @param index The index of the final command being executed |
| 48 | */ |
| chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 49 | void drawTo(SkCanvas* canvas, int index); |
| 50 | |
| 51 | /** |
| chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 52 | Returns the most recently calculated transformation matrix |
| 53 | */ |
| 54 | const SkMatrix& getCurrentMatrix() { |
| 55 | return fMatrix; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | Returns the most recently calculated clip |
| 60 | */ |
| 61 | const SkIRect& getCurrentClip() { |
| 62 | return fClip; |
| 63 | } |
| 64 | |
| 65 | /** |
| chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 66 | Returns the index of the last draw command to write to the pixel at (x,y) |
| 67 | */ |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 68 | int getCommandAtPoint(int x, int y, int index); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 69 | |
| 70 | /** |
| robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 71 | Removes the command at the specified index |
| 72 | @param index The index of the command to delete |
| 73 | */ |
| 74 | void deleteDrawCommandAt(int index); |
| 75 | |
| 76 | /** |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 77 | Returns the draw command at the given index. |
| 78 | @param index The index of the command |
| 79 | */ |
| 80 | SkDrawCommand* getDrawCommandAt(int index); |
| 81 | |
| 82 | /** |
| robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 83 | Sets the draw command for a given index. |
| 84 | @param index The index to overwrite |
| 85 | @param command The new command |
| 86 | */ |
| 87 | void setDrawCommandAt(int index, SkDrawCommand* command); |
| 88 | |
| 89 | /** |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 90 | Returns information about the command at the given index. |
| 91 | @param index The index of the command |
| 92 | */ |
| chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 93 | SkTDArray<SkString*>* getCommandInfo(int index); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 94 | |
| 95 | /** |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 96 | Returns the visibility of the command at the given index. |
| 97 | @param index The index of the command |
| 98 | */ |
| 99 | bool getDrawCommandVisibilityAt(int index); |
| 100 | |
| 101 | /** |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 102 | Returns the vector of draw commands |
| 103 | */ |
| reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 104 | SK_ATTR_DEPRECATED("please use getDrawCommandAt and getSize instead") |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 105 | const SkTDArray<SkDrawCommand*>& getDrawCommands() const; |
| skia.committer@gmail.com | 2e71f16 | 2013-03-12 07:12:32 +0000 | [diff] [blame] | 106 | |
| robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 107 | /** |
| 108 | Returns the vector of draw commands. Do not use this entry |
| 109 | point - it is going away! |
| 110 | */ |
| 111 | SkTDArray<SkDrawCommand*>& getDrawCommands(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * Returns the string vector of draw commands |
| 115 | */ |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 116 | SkTArray<SkString>* getDrawCommandsAsStrings() const; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 117 | |
| 118 | /** |
| chudy@google.com | f141432 | 2012-07-03 20:28:14 +0000 | [diff] [blame] | 119 | Returns length of draw command vector. |
| 120 | */ |
| commit-bot@chromium.org | 0d4fe14 | 2013-07-15 22:47:14 +0000 | [diff] [blame] | 121 | int getSize() const { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 122 | return fCommandVector.count(); |
| chudy@google.com | f141432 | 2012-07-03 20:28:14 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 125 | /** |
| 126 | Toggles the visibility / execution of the draw command at index i with |
| 127 | the value of toggle. |
| 128 | */ |
| 129 | void toggleCommand(int index, bool toggle); |
| 130 | |
| chudy@google.com | b9ddd4e | 2012-07-10 14:14:50 +0000 | [diff] [blame] | 131 | void setBounds(int width, int height) { |
| 132 | fWidth = width; |
| 133 | fHeight = height; |
| 134 | } |
| 135 | |
| bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 136 | void setUserMatrix(SkMatrix matrix) { |
| 137 | fUserMatrix = matrix; |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 140 | //////////////////////////////////////////////////////////////////////////////// |
| 141 | // Inherited from SkCanvas |
| 142 | //////////////////////////////////////////////////////////////////////////////// |
| 143 | |
| 144 | virtual void clear(SkColor) SK_OVERRIDE; |
| 145 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 146 | virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; |
| 147 | |
| 148 | virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
| 149 | const SkPaint*) SK_OVERRIDE; |
| 150 | |
| reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 151 | virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, |
| commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 152 | const SkRect& dst, const SkPaint* paint, |
| 153 | DrawBitmapRectFlags flags) SK_OVERRIDE; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 154 | |
| 155 | virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
| 156 | const SkPaint*) SK_OVERRIDE; |
| 157 | |
| 158 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 159 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
| 160 | |
| 161 | virtual void drawData(const void*, size_t) SK_OVERRIDE; |
| 162 | |
| robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 163 | virtual void beginCommentGroup(const char* description) SK_OVERRIDE; |
| 164 | |
| 165 | virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; |
| 166 | |
| 167 | virtual void endCommentGroup() SK_OVERRIDE; |
| 168 | |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 169 | virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE; |
| 170 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 171 | virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
| 172 | |
| bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 173 | virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
| 174 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 175 | virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; |
| 176 | |
| 177 | virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], |
| 178 | const SkPaint&) SK_OVERRIDE; |
| 179 | |
| 180 | virtual void drawPosText(const void* text, size_t byteLength, |
| 181 | const SkPoint pos[], const SkPaint&) SK_OVERRIDE; |
| 182 | |
| 183 | virtual void drawPosTextH(const void* text, size_t byteLength, |
| skia.committer@gmail.com | 422188f | 2013-01-03 02:01:32 +0000 | [diff] [blame] | 184 | const SkScalar xpos[], SkScalar constY, |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 185 | const SkPaint&) SK_OVERRIDE; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 186 | |
| bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 187 | virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; |
| 188 | |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 189 | virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE; |
| 190 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 191 | virtual void drawSprite(const SkBitmap&, int left, int top, |
| 192 | const SkPaint*) SK_OVERRIDE; |
| 193 | |
| 194 | virtual void drawText(const void* text, size_t byteLength, SkScalar x, |
| 195 | SkScalar y, const SkPaint&) SK_OVERRIDE; |
| 196 | |
| 197 | virtual void drawTextOnPath(const void* text, size_t byteLength, |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 198 | const SkPath& path, const SkMatrix* matrix, |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 199 | const SkPaint&) SK_OVERRIDE; |
| 200 | |
| 201 | virtual void drawVertices(VertexMode, int vertexCount, |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 202 | const SkPoint vertices[], const SkPoint texs[], |
| 203 | const SkColor colors[], SkXfermode*, |
| 204 | const uint16_t indices[], int indexCount, |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 205 | const SkPaint&) SK_OVERRIDE; |
| 206 | |
| 207 | virtual void restore() SK_OVERRIDE; |
| 208 | |
| 209 | virtual bool rotate(SkScalar degrees) SK_OVERRIDE; |
| 210 | |
| 211 | virtual int save(SaveFlags) SK_OVERRIDE; |
| 212 | |
| 213 | virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE; |
| 214 | |
| 215 | virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 216 | |
| 217 | virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; |
| 218 | |
| 219 | virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 220 | |
| 221 | virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; |
| 222 | |
| robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 223 | static const int kVizImageHeight = 256; |
| 224 | static const int kVizImageWidth = 256; |
| 225 | |
| robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 226 | virtual bool isClipEmpty() const SK_OVERRIDE { return false; } |
| skia.committer@gmail.com | 370a899 | 2014-03-01 03:02:09 +0000 | [diff] [blame^] | 227 | virtual ClipType getClipType() const SK_OVERRIDE { |
| 228 | return kRect_ClipType; |
| robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 229 | } |
| 230 | virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE { |
| 231 | if (NULL != bounds) { |
| skia.committer@gmail.com | 370a899 | 2014-03-01 03:02:09 +0000 | [diff] [blame^] | 232 | bounds->setXYWH(0, 0, |
| 233 | SkIntToScalar(this->imageInfo().fWidth), |
| robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 234 | SkIntToScalar(this->imageInfo().fHeight)); |
| 235 | } |
| 236 | return true; |
| 237 | } |
| 238 | virtual bool getClipDeviceBounds(SkIRect* bounds) const SK_OVERRIDE { |
| 239 | if (NULL != bounds) { |
| 240 | bounds->setLargest(); |
| 241 | } |
| 242 | return true; |
| 243 | } |
| 244 | |
| commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 245 | protected: |
| 246 | virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; |
| commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 247 | virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE; |
| 248 | virtual void onPopCull() SK_OVERRIDE; |
| commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 249 | |
| robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 250 | virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 251 | virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 252 | virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 253 | virtual void onClipRegion(const SkRegion& region, SkRegion::Op) SK_OVERRIDE; |
| 254 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 255 | private: |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 256 | SkTDArray<SkDrawCommand*> fCommandVector; |
| chudy@google.com | b9ddd4e | 2012-07-10 14:14:50 +0000 | [diff] [blame] | 257 | int fWidth; |
| commit-bot@chromium.org | 1735d66 | 2013-12-04 13:42:46 +0000 | [diff] [blame] | 258 | int fHeight; |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 259 | bool fFilter; |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 260 | int fIndex; |
| bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 261 | SkMatrix fUserMatrix; |
| chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 262 | SkMatrix fMatrix; |
| 263 | SkIRect fClip; |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 264 | |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 265 | bool fOverdrawViz; |
| 266 | SkDrawFilter* fOverdrawFilter; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 267 | |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 268 | bool fOverrideTexFiltering; |
| 269 | SkTexOverrideFilter* fTexOverrideFilter; |
| 270 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 271 | /** |
| tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 272 | Number of unmatched save() calls at any point during a draw. |
| 273 | If there are any saveLayer() calls outstanding, we need to resolve |
| 274 | all of them, which in practice means resolving all save() calls, |
| 275 | to avoid corruption of our canvas. |
| 276 | */ |
| 277 | int fOutstandingSaveCount; |
| 278 | |
| 279 | /** |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 280 | Adds the command to the classes vector of commands. |
| 281 | @param command The draw command for execution |
| 282 | */ |
| 283 | void addDrawCommand(SkDrawCommand* command); |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 284 | |
| 285 | /** |
| 286 | Applies any panning and zooming the user has specified before |
| 287 | drawing anything else into the canvas. |
| 288 | */ |
| 289 | void applyUserTransform(SkCanvas* canvas); |
| robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 290 | |
| 291 | typedef SkCanvas INHERITED; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 292 | }; |
| 293 | |
| 294 | #endif |