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 | |
| 19 | class SkDebugCanvas : public SkCanvas { |
| 20 | public: |
chudy@google.com | 80a4a60 | 2012-07-30 18:54:07 +0000 | [diff] [blame] | 21 | SkDebugCanvas(int width, int height); |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame^] | 22 | virtual ~SkDebugCanvas(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 23 | |
| 24 | void toggleFilter(bool toggle); |
| 25 | |
| 26 | /** |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame^] | 27 | * Enable or disable overdraw visualization |
| 28 | */ |
| 29 | void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; } |
| 30 | |
| 31 | /** |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 32 | Executes all draw calls to the canvas. |
| 33 | @param canvas The canvas being drawn to |
| 34 | */ |
| 35 | void draw(SkCanvas* canvas); |
| 36 | |
| 37 | /** |
| 38 | Executes the draw calls in the specified range. |
| 39 | @param canvas The canvas being drawn to |
| 40 | @param i The beginning of the range |
| 41 | @param j The end of the range |
| 42 | TODO(chudy): Implement |
| 43 | */ |
| 44 | void drawRange(SkCanvas* canvas, int i, int j); |
| 45 | |
| 46 | /** |
| 47 | Executes the draw calls up to the specified index. |
| 48 | @param canvas The canvas being drawn to |
| 49 | @param index The index of the final command being executed |
| 50 | */ |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 51 | void drawTo(SkCanvas* canvas, int index); |
| 52 | |
| 53 | /** |
chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 54 | Returns the most recently calculated transformation matrix |
| 55 | */ |
| 56 | const SkMatrix& getCurrentMatrix() { |
| 57 | return fMatrix; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | Returns the most recently calculated clip |
| 62 | */ |
| 63 | const SkIRect& getCurrentClip() { |
| 64 | return fClip; |
| 65 | } |
| 66 | |
| 67 | /** |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 68 | Returns the index of the last draw command to write to the pixel at (x,y) |
| 69 | */ |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 70 | int getCommandAtPoint(int x, int y, int index); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | Returns the draw command at the given index. |
| 74 | @param index The index of the command |
| 75 | */ |
| 76 | SkDrawCommand* getDrawCommandAt(int index); |
| 77 | |
| 78 | /** |
| 79 | Returns information about the command at the given index. |
| 80 | @param index The index of the command |
| 81 | */ |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 82 | SkTDArray<SkString*>* getCommandInfo(int index); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 83 | |
| 84 | /** |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 85 | Returns the visibility of the command at the given index. |
| 86 | @param index The index of the command |
| 87 | */ |
| 88 | bool getDrawCommandVisibilityAt(int index); |
| 89 | |
| 90 | /** |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 91 | Returns the vector of draw commands |
| 92 | */ |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 93 | const SkTDArray<SkDrawCommand*>& getDrawCommands() const; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * Returns the string vector of draw commands |
| 97 | */ |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 98 | SkTArray<SkString>* getDrawCommandsAsStrings() const; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 99 | |
| 100 | /** |
chudy@google.com | f141432 | 2012-07-03 20:28:14 +0000 | [diff] [blame] | 101 | Returns length of draw command vector. |
| 102 | */ |
| 103 | int getSize() { |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 104 | return fCommandVector.count(); |
chudy@google.com | f141432 | 2012-07-03 20:28:14 +0000 | [diff] [blame] | 105 | } |
| 106 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 107 | /** |
| 108 | Toggles the visibility / execution of the draw command at index i with |
| 109 | the value of toggle. |
| 110 | */ |
| 111 | void toggleCommand(int index, bool toggle); |
| 112 | |
chudy@google.com | b9ddd4e | 2012-07-10 14:14:50 +0000 | [diff] [blame] | 113 | void setBounds(int width, int height) { |
| 114 | fWidth = width; |
| 115 | fHeight = height; |
| 116 | } |
| 117 | |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 118 | void setUserMatrix(SkMatrix matrix) { |
| 119 | fUserMatrix = matrix; |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 120 | } |
| 121 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 122 | //////////////////////////////////////////////////////////////////////////////// |
| 123 | // Inherited from SkCanvas |
| 124 | //////////////////////////////////////////////////////////////////////////////// |
| 125 | |
| 126 | virtual void clear(SkColor) SK_OVERRIDE; |
| 127 | |
| 128 | virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE; |
| 129 | |
| 130 | virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE; |
| 131 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 132 | virtual bool clipRRect(const SkRRect& rrect, |
| 133 | SkRegion::Op op = SkRegion::kIntersect_Op, |
| 134 | bool doAntiAlias = false) SK_OVERRIDE; |
| 135 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 136 | virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE; |
| 137 | |
| 138 | virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; |
| 139 | |
| 140 | virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
| 141 | const SkPaint*) SK_OVERRIDE; |
| 142 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 143 | virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, |
| 144 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 145 | |
| 146 | virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
| 147 | const SkPaint*) SK_OVERRIDE; |
| 148 | |
| 149 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 150 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
| 151 | |
| 152 | virtual void drawData(const void*, size_t) SK_OVERRIDE; |
| 153 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 154 | virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE; |
| 155 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 156 | virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
| 157 | |
| 158 | virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
| 159 | |
| 160 | virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; |
| 161 | |
| 162 | virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], |
| 163 | const SkPaint&) SK_OVERRIDE; |
| 164 | |
| 165 | virtual void drawPosText(const void* text, size_t byteLength, |
| 166 | const SkPoint pos[], const SkPaint&) SK_OVERRIDE; |
| 167 | |
| 168 | virtual void drawPosTextH(const void* text, size_t byteLength, |
skia.committer@gmail.com | 422188f | 2013-01-03 02:01:32 +0000 | [diff] [blame] | 169 | const SkScalar xpos[], SkScalar constY, |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 170 | const SkPaint&) SK_OVERRIDE; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 171 | |
| 172 | virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; |
| 173 | |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 174 | virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE; |
| 175 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 176 | virtual void drawSprite(const SkBitmap&, int left, int top, |
| 177 | const SkPaint*) SK_OVERRIDE; |
| 178 | |
| 179 | virtual void drawText(const void* text, size_t byteLength, SkScalar x, |
| 180 | SkScalar y, const SkPaint&) SK_OVERRIDE; |
| 181 | |
| 182 | virtual void drawTextOnPath(const void* text, size_t byteLength, |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 183 | const SkPath& path, const SkMatrix* matrix, |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 184 | const SkPaint&) SK_OVERRIDE; |
| 185 | |
| 186 | virtual void drawVertices(VertexMode, int vertexCount, |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 187 | const SkPoint vertices[], const SkPoint texs[], |
| 188 | const SkColor colors[], SkXfermode*, |
| 189 | const uint16_t indices[], int indexCount, |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 190 | const SkPaint&) SK_OVERRIDE; |
| 191 | |
| 192 | virtual void restore() SK_OVERRIDE; |
| 193 | |
| 194 | virtual bool rotate(SkScalar degrees) SK_OVERRIDE; |
| 195 | |
| 196 | virtual int save(SaveFlags) SK_OVERRIDE; |
| 197 | |
| 198 | virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE; |
| 199 | |
| 200 | virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 201 | |
| 202 | virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; |
| 203 | |
| 204 | virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 205 | |
| 206 | virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; |
| 207 | |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 208 | static const int kVizImageHeight = 256; |
| 209 | static const int kVizImageWidth = 256; |
| 210 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 211 | private: |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 212 | SkTDArray<SkDrawCommand*> fCommandVector; |
chudy@google.com | b9ddd4e | 2012-07-10 14:14:50 +0000 | [diff] [blame] | 213 | int fHeight; |
| 214 | int fWidth; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 215 | SkBitmap fBm; |
chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 216 | bool fFilter; |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 217 | int fIndex; |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 218 | SkMatrix fUserMatrix; |
chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 219 | SkMatrix fMatrix; |
| 220 | SkIRect fClip; |
robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame^] | 221 | bool fOverdrawViz; |
| 222 | SkDrawFilter* fOverdrawFilter; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 223 | |
| 224 | /** |
tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 225 | Number of unmatched save() calls at any point during a draw. |
| 226 | If there are any saveLayer() calls outstanding, we need to resolve |
| 227 | all of them, which in practice means resolving all save() calls, |
| 228 | to avoid corruption of our canvas. |
| 229 | */ |
| 230 | int fOutstandingSaveCount; |
| 231 | |
| 232 | /** |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 233 | Adds the command to the classes vector of commands. |
| 234 | @param command The draw command for execution |
| 235 | */ |
| 236 | void addDrawCommand(SkDrawCommand* command); |
chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 237 | |
| 238 | /** |
| 239 | Applies any panning and zooming the user has specified before |
| 240 | drawing anything else into the canvas. |
| 241 | */ |
| 242 | void applyUserTransform(SkCanvas* canvas); |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 243 | |
| 244 | typedef SkCanvas INHERITED; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | #endif |