| OLD | NEW |
| (Empty) |
| 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 | |
| 13 #include "SkCanvas.h" | |
| 14 #include "SkDrawCommand.h" | |
| 15 #include "SkPicture.h" | |
| 16 #include "SkTArray.h" | |
| 17 #include "SkString.h" | |
| 18 | |
| 19 class SkDebugCanvas : public SkCanvas { | |
| 20 public: | |
| 21 SkDebugCanvas(int width, int height); | |
| 22 virtual ~SkDebugCanvas(); | |
| 23 | |
| 24 void toggleFilter(bool toggle); | |
| 25 | |
| 26 /** | |
| 27 * Enable or disable overdraw visualization | |
| 28 */ | |
| 29 void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; } | |
| 30 | |
| 31 /** | |
| 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 */ | |
| 51 void drawTo(SkCanvas* canvas, int index); | |
| 52 | |
| 53 /** | |
| 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 /** | |
| 68 Returns the index of the last draw command to write to the pixel at (x,y
) | |
| 69 */ | |
| 70 int getCommandAtPoint(int x, int y, int index); | |
| 71 | |
| 72 /** | |
| 73 Removes the command at the specified index | |
| 74 @param index The index of the command to delete | |
| 75 */ | |
| 76 void deleteDrawCommandAt(int index); | |
| 77 | |
| 78 /** | |
| 79 Returns the draw command at the given index. | |
| 80 @param index The index of the command | |
| 81 */ | |
| 82 SkDrawCommand* getDrawCommandAt(int index); | |
| 83 | |
| 84 /** | |
| 85 Sets the draw command for a given index. | |
| 86 @param index The index to overwrite | |
| 87 @param command The new command | |
| 88 */ | |
| 89 void setDrawCommandAt(int index, SkDrawCommand* command); | |
| 90 | |
| 91 /** | |
| 92 Returns information about the command at the given index. | |
| 93 @param index The index of the command | |
| 94 */ | |
| 95 SkTDArray<SkString*>* getCommandInfo(int index); | |
| 96 | |
| 97 /** | |
| 98 Returns the visibility of the command at the given index. | |
| 99 @param index The index of the command | |
| 100 */ | |
| 101 bool getDrawCommandVisibilityAt(int index); | |
| 102 | |
| 103 /** | |
| 104 Returns the vector of draw commands | |
| 105 DEPRECATED: please use getDrawCommandAt and getSize instead | |
| 106 */ | |
| 107 const SkTDArray<SkDrawCommand*>& getDrawCommands() const; | |
| 108 | |
| 109 /** | |
| 110 Returns the vector of draw commands. Do not use this entry | |
| 111 point - it is going away! | |
| 112 */ | |
| 113 SkTDArray<SkDrawCommand*>& getDrawCommands(); | |
| 114 | |
| 115 /** | |
| 116 * Returns the string vector of draw commands | |
| 117 */ | |
| 118 SkTArray<SkString>* getDrawCommandsAsStrings() const; | |
| 119 | |
| 120 /** | |
| 121 Returns length of draw command vector. | |
| 122 */ | |
| 123 int getSize() { | |
| 124 return fCommandVector.count(); | |
| 125 } | |
| 126 | |
| 127 /** | |
| 128 Toggles the visibility / execution of the draw command at index i with | |
| 129 the value of toggle. | |
| 130 */ | |
| 131 void toggleCommand(int index, bool toggle); | |
| 132 | |
| 133 void setBounds(int width, int height) { | |
| 134 fWidth = width; | |
| 135 fHeight = height; | |
| 136 } | |
| 137 | |
| 138 void setUserMatrix(SkMatrix matrix) { | |
| 139 fUserMatrix = matrix; | |
| 140 } | |
| 141 | |
| 142 //////////////////////////////////////////////////////////////////////////////// | |
| 143 // Inherited from SkCanvas | |
| 144 //////////////////////////////////////////////////////////////////////////////// | |
| 145 | |
| 146 virtual void clear(SkColor) SK_OVERRIDE; | |
| 147 | |
| 148 virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE; | |
| 149 | |
| 150 virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE; | |
| 151 | |
| 152 virtual bool clipRRect(const SkRRect& rrect, | |
| 153 SkRegion::Op op = SkRegion::kIntersect_Op, | |
| 154 bool doAntiAlias = false) SK_OVERRIDE; | |
| 155 | |
| 156 virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE
; | |
| 157 | |
| 158 virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; | |
| 159 | |
| 160 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, | |
| 161 const SkPaint*) SK_OVERRIDE; | |
| 162 | |
| 163 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, | |
| 164 const SkRect& dst, const SkPaint*) SK_OVERRIDE
; | |
| 165 | |
| 166 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, | |
| 167 const SkPaint*) SK_OVERRIDE; | |
| 168 | |
| 169 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, | |
| 170 const SkRect& dst, const SkPaint*) SK_OVERRIDE; | |
| 171 | |
| 172 virtual void drawData(const void*, size_t) SK_OVERRIDE; | |
| 173 | |
| 174 virtual void beginCommentGroup(const char* description) SK_OVERRIDE; | |
| 175 | |
| 176 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; | |
| 177 | |
| 178 virtual void endCommentGroup() SK_OVERRIDE; | |
| 179 | |
| 180 virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE; | |
| 181 | |
| 182 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; | |
| 183 | |
| 184 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; | |
| 185 | |
| 186 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; | |
| 187 | |
| 188 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], | |
| 189 const SkPaint&) SK_OVERRIDE; | |
| 190 | |
| 191 virtual void drawPosText(const void* text, size_t byteLength, | |
| 192 const SkPoint pos[], const SkPaint&) SK_OVERRIDE; | |
| 193 | |
| 194 virtual void drawPosTextH(const void* text, size_t byteLength, | |
| 195 const SkScalar xpos[], SkScalar constY, | |
| 196 const SkPaint&) SK_OVERRIDE; | |
| 197 | |
| 198 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; | |
| 199 | |
| 200 virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRI
DE; | |
| 201 | |
| 202 virtual void drawSprite(const SkBitmap&, int left, int top, | |
| 203 const SkPaint*) SK_OVERRIDE; | |
| 204 | |
| 205 virtual void drawText(const void* text, size_t byteLength, SkScalar x, | |
| 206 SkScalar y, const SkPaint&) SK_OVERRIDE; | |
| 207 | |
| 208 virtual void drawTextOnPath(const void* text, size_t byteLength, | |
| 209 const SkPath& path, const SkMatrix* matrix, | |
| 210 const SkPaint&) SK_OVERRIDE; | |
| 211 | |
| 212 virtual void drawVertices(VertexMode, int vertexCount, | |
| 213 const SkPoint vertices[], const SkPoint texs[], | |
| 214 const SkColor colors[], SkXfermode*, | |
| 215 const uint16_t indices[], int indexCount, | |
| 216 const SkPaint&) SK_OVERRIDE; | |
| 217 | |
| 218 virtual void restore() SK_OVERRIDE; | |
| 219 | |
| 220 virtual bool rotate(SkScalar degrees) SK_OVERRIDE; | |
| 221 | |
| 222 virtual int save(SaveFlags) SK_OVERRIDE; | |
| 223 | |
| 224 virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OV
ERRIDE; | |
| 225 | |
| 226 virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; | |
| 227 | |
| 228 virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; | |
| 229 | |
| 230 virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE; | |
| 231 | |
| 232 virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; | |
| 233 | |
| 234 static const int kVizImageHeight = 256; | |
| 235 static const int kVizImageWidth = 256; | |
| 236 | |
| 237 private: | |
| 238 SkTDArray<SkDrawCommand*> fCommandVector; | |
| 239 int fHeight; | |
| 240 int fWidth; | |
| 241 SkBitmap fBm; | |
| 242 bool fFilter; | |
| 243 int fIndex; | |
| 244 SkMatrix fUserMatrix; | |
| 245 SkMatrix fMatrix; | |
| 246 SkIRect fClip; | |
| 247 bool fOverdrawViz; | |
| 248 SkDrawFilter* fOverdrawFilter; | |
| 249 | |
| 250 /** | |
| 251 Number of unmatched save() calls at any point during a draw. | |
| 252 If there are any saveLayer() calls outstanding, we need to resolve | |
| 253 all of them, which in practice means resolving all save() calls, | |
| 254 to avoid corruption of our canvas. | |
| 255 */ | |
| 256 int fOutstandingSaveCount; | |
| 257 | |
| 258 /** | |
| 259 Adds the command to the classes vector of commands. | |
| 260 @param command The draw command for execution | |
| 261 */ | |
| 262 void addDrawCommand(SkDrawCommand* command); | |
| 263 | |
| 264 /** | |
| 265 Applies any panning and zooming the user has specified before | |
| 266 drawing anything else into the canvas. | |
| 267 */ | |
| 268 void applyUserTransform(SkCanvas* canvas); | |
| 269 | |
| 270 typedef SkCanvas INHERITED; | |
| 271 }; | |
| 272 | |
| 273 #endif | |
| OLD | NEW |