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