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