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