| 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" |
| 16 | #include <vector> |
| 17 | |
| 18 | class SkDebugCanvas : public SkCanvas { |
| 19 | public: |
| chudy@google.com | 80a4a60 | 2012-07-30 18:54:07 +0000 | [diff] [blame] | 20 | SkDebugCanvas(int width, int height); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 21 | ~SkDebugCanvas(); |
| 22 | |
| 23 | void toggleFilter(bool toggle); |
| 24 | |
| 25 | /** |
| 26 | Executes all draw calls to the canvas. |
| 27 | @param canvas The canvas being drawn to |
| 28 | */ |
| 29 | void draw(SkCanvas* canvas); |
| 30 | |
| 31 | /** |
| 32 | Executes the draw calls in the specified range. |
| 33 | @param canvas The canvas being drawn to |
| 34 | @param i The beginning of the range |
| 35 | @param j The end of the range |
| 36 | TODO(chudy): Implement |
| 37 | */ |
| 38 | void drawRange(SkCanvas* canvas, int i, int j); |
| 39 | |
| 40 | /** |
| 41 | Executes the draw calls up to the specified index. |
| 42 | @param canvas The canvas being drawn to |
| 43 | @param index The index of the final command being executed |
| 44 | */ |
| chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame^] | 45 | void drawTo(SkCanvas* canvas, int index); |
| 46 | |
| 47 | /** |
| 48 | Returns the index of the last draw command to write to the pixel at (x,y) |
| 49 | */ |
| 50 | int getCommandAtPoint(int x, int y, int index, |
| 51 | SkIPoint transform, float scale); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | Returns the draw command at the given index. |
| 55 | @param index The index of the command |
| 56 | */ |
| 57 | SkDrawCommand* getDrawCommandAt(int index); |
| 58 | |
| 59 | /** |
| 60 | Returns information about the command at the given index. |
| 61 | @param index The index of the command |
| 62 | */ |
| 63 | std::vector<std::string>* getCommandInfoAt(int index); |
| 64 | |
| 65 | /** |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 66 | Returns the visibility of the command at the given index. |
| 67 | @param index The index of the command |
| 68 | */ |
| 69 | bool getDrawCommandVisibilityAt(int index); |
| 70 | |
| 71 | /** |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 72 | Returns the vector of draw commands |
| 73 | */ |
| 74 | std::vector<SkDrawCommand*> getDrawCommands(); |
| 75 | |
| 76 | /** |
| 77 | * Returns the string vector of draw commands |
| 78 | */ |
| 79 | std::vector<std::string>* getDrawCommandsAsStrings(); |
| 80 | |
| 81 | /** |
| chudy@google.com | f141432 | 2012-07-03 20:28:14 +0000 | [diff] [blame] | 82 | Returns length of draw command vector. |
| 83 | */ |
| 84 | int getSize() { |
| 85 | return commandVector.size(); |
| 86 | } |
| 87 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 88 | /** |
| 89 | Toggles the visibility / execution of the draw command at index i with |
| 90 | the value of toggle. |
| 91 | */ |
| 92 | void toggleCommand(int index, bool toggle); |
| 93 | |
| chudy@google.com | b9ddd4e | 2012-07-10 14:14:50 +0000 | [diff] [blame] | 94 | void setBounds(int width, int height) { |
| 95 | fWidth = width; |
| 96 | fHeight = height; |
| 97 | } |
| 98 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 99 | //////////////////////////////////////////////////////////////////////////////// |
| 100 | // Inherited from SkCanvas |
| 101 | //////////////////////////////////////////////////////////////////////////////// |
| 102 | |
| 103 | virtual void clear(SkColor) SK_OVERRIDE; |
| 104 | |
| 105 | virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE; |
| 106 | |
| 107 | virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE; |
| 108 | |
| 109 | virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE; |
| 110 | |
| 111 | virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; |
| 112 | |
| 113 | virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
| 114 | const SkPaint*) SK_OVERRIDE; |
| 115 | |
| 116 | virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src, |
| 117 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
| 118 | |
| 119 | virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
| 120 | const SkPaint*) SK_OVERRIDE; |
| 121 | |
| 122 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 123 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
| 124 | |
| 125 | virtual void drawData(const void*, size_t) SK_OVERRIDE; |
| 126 | |
| 127 | virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
| 128 | |
| 129 | virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
| 130 | |
| 131 | virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; |
| 132 | |
| 133 | virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], |
| 134 | const SkPaint&) SK_OVERRIDE; |
| 135 | |
| 136 | virtual void drawPosText(const void* text, size_t byteLength, |
| 137 | const SkPoint pos[], const SkPaint&) SK_OVERRIDE; |
| 138 | |
| 139 | virtual void drawPosTextH(const void* text, size_t byteLength, |
| 140 | const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE; |
| 141 | |
| 142 | virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; |
| 143 | |
| 144 | virtual void drawSprite(const SkBitmap&, int left, int top, |
| 145 | const SkPaint*) SK_OVERRIDE; |
| 146 | |
| 147 | virtual void drawText(const void* text, size_t byteLength, SkScalar x, |
| 148 | SkScalar y, const SkPaint&) SK_OVERRIDE; |
| 149 | |
| 150 | virtual void drawTextOnPath(const void* text, size_t byteLength, |
| 151 | const SkPath& path, const SkMatrix* matrix, |
| 152 | const SkPaint&) SK_OVERRIDE; |
| 153 | |
| 154 | virtual void drawVertices(VertexMode, int vertexCount, |
| 155 | const SkPoint vertices[], const SkPoint texs[], |
| 156 | const SkColor colors[], SkXfermode*, |
| 157 | const uint16_t indices[], int indexCount, |
| 158 | const SkPaint&) SK_OVERRIDE; |
| 159 | |
| 160 | virtual void restore() SK_OVERRIDE; |
| 161 | |
| 162 | virtual bool rotate(SkScalar degrees) SK_OVERRIDE; |
| 163 | |
| 164 | virtual int save(SaveFlags) SK_OVERRIDE; |
| 165 | |
| 166 | virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE; |
| 167 | |
| 168 | virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 169 | |
| 170 | virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; |
| 171 | |
| 172 | virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 173 | |
| 174 | virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; |
| 175 | |
| 176 | private: |
| 177 | typedef SkCanvas INHERITED; |
| 178 | std::vector<SkDrawCommand*> commandVector; |
| 179 | std::vector<SkDrawCommand*>::const_iterator it; |
| chudy@google.com | b9ddd4e | 2012-07-10 14:14:50 +0000 | [diff] [blame] | 180 | int fHeight; |
| 181 | int fWidth; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 182 | SkBitmap fBm; |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 183 | bool fFilter; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | Adds the command to the classes vector of commands. |
| 187 | @param command The draw command for execution |
| 188 | */ |
| 189 | void addDrawCommand(SkDrawCommand* command); |
| 190 | }; |
| 191 | |
| 192 | #endif |