gfx/skia/trunk/src/utils/debugger/SkDebugCanvas.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/utils/debugger/SkDebugCanvas.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,307 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2012 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SKDEBUGCANVAS_H_
    1.14 +#define SKDEBUGCANVAS_H_
    1.15 +
    1.16 +#include "SkCanvas.h"
    1.17 +#include "SkDrawCommand.h"
    1.18 +#include "SkPicture.h"
    1.19 +#include "SkTArray.h"
    1.20 +#include "SkString.h"
    1.21 +
    1.22 +class SkTexOverrideFilter;
    1.23 +
    1.24 +class SK_API SkDebugCanvas : public SkCanvas {
    1.25 +public:
    1.26 +    SkDebugCanvas(int width, int height);
    1.27 +    virtual ~SkDebugCanvas();
    1.28 +
    1.29 +    void toggleFilter(bool toggle) { fFilter = toggle; }
    1.30 +
    1.31 +    void setMegaVizMode(bool megaVizMode) { fMegaVizMode = megaVizMode; }
    1.32 +
    1.33 +    /**
    1.34 +     * Enable or disable overdraw visualization
    1.35 +     */
    1.36 +    void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; }
    1.37 +
    1.38 +    /**
    1.39 +     * Enable or disable texure filtering override
    1.40 +     */
    1.41 +    void overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level);
    1.42 +
    1.43 +    /**
    1.44 +        Executes all draw calls to the canvas.
    1.45 +        @param canvas  The canvas being drawn to
    1.46 +     */
    1.47 +    void draw(SkCanvas* canvas);
    1.48 +
    1.49 +    /**
    1.50 +        Executes the draw calls up to the specified index.
    1.51 +        @param canvas  The canvas being drawn to
    1.52 +        @param index  The index of the final command being executed
    1.53 +     */
    1.54 +    void drawTo(SkCanvas* canvas, int index);
    1.55 +
    1.56 +    /**
    1.57 +        Returns the most recently calculated transformation matrix
    1.58 +     */
    1.59 +    const SkMatrix& getCurrentMatrix() {
    1.60 +        return fMatrix;
    1.61 +    }
    1.62 +
    1.63 +    /**
    1.64 +        Returns the most recently calculated clip
    1.65 +     */
    1.66 +    const SkIRect& getCurrentClip() {
    1.67 +        return fClip;
    1.68 +    }
    1.69 +
    1.70 +    /**
    1.71 +        Returns the index of the last draw command to write to the pixel at (x,y)
    1.72 +     */
    1.73 +    int getCommandAtPoint(int x, int y, int index);
    1.74 +
    1.75 +    /**
    1.76 +        Removes the command at the specified index
    1.77 +        @param index  The index of the command to delete
    1.78 +     */
    1.79 +    void deleteDrawCommandAt(int index);
    1.80 +
    1.81 +    /**
    1.82 +        Returns the draw command at the given index.
    1.83 +        @param index  The index of the command
    1.84 +     */
    1.85 +    SkDrawCommand* getDrawCommandAt(int index);
    1.86 +
    1.87 +    /**
    1.88 +        Sets the draw command for a given index.
    1.89 +        @param index  The index to overwrite
    1.90 +        @param command The new command
    1.91 +     */
    1.92 +    void setDrawCommandAt(int index, SkDrawCommand* command);
    1.93 +
    1.94 +    /**
    1.95 +        Returns information about the command at the given index.
    1.96 +        @param index  The index of the command
    1.97 +     */
    1.98 +    SkTDArray<SkString*>* getCommandInfo(int index);
    1.99 +
   1.100 +    /**
   1.101 +        Returns the visibility of the command at the given index.
   1.102 +        @param index  The index of the command
   1.103 +     */
   1.104 +    bool getDrawCommandVisibilityAt(int index);
   1.105 +
   1.106 +    /**
   1.107 +        Returns the vector of draw commands
   1.108 +     */
   1.109 +    SK_ATTR_DEPRECATED("please use getDrawCommandAt and getSize instead")
   1.110 +    const SkTDArray<SkDrawCommand*>& getDrawCommands() const;
   1.111 +
   1.112 +    /**
   1.113 +        Returns the vector of draw commands. Do not use this entry
   1.114 +        point - it is going away!
   1.115 +     */
   1.116 +    SkTDArray<SkDrawCommand*>& getDrawCommands();
   1.117 +
   1.118 +    /**
   1.119 +     * Returns the string vector of draw commands
   1.120 +     */
   1.121 +    SkTArray<SkString>* getDrawCommandsAsStrings() const;
   1.122 +
   1.123 +    /**
   1.124 +        Returns length of draw command vector.
   1.125 +     */
   1.126 +    int getSize() const {
   1.127 +        return fCommandVector.count();
   1.128 +    }
   1.129 +
   1.130 +    /**
   1.131 +        Toggles the visibility / execution of the draw command at index i with
   1.132 +        the value of toggle.
   1.133 +     */
   1.134 +    void toggleCommand(int index, bool toggle);
   1.135 +
   1.136 +    void setBounds(int width, int height) {
   1.137 +        fWidth = width;
   1.138 +        fHeight = height;
   1.139 +    }
   1.140 +
   1.141 +    void setUserMatrix(SkMatrix matrix) {
   1.142 +        fUserMatrix = matrix;
   1.143 +    }
   1.144 +
   1.145 +////////////////////////////////////////////////////////////////////////////////
   1.146 +// Inherited from SkCanvas
   1.147 +////////////////////////////////////////////////////////////////////////////////
   1.148 +
   1.149 +    virtual void clear(SkColor) SK_OVERRIDE;
   1.150 +
   1.151 +    virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
   1.152 +                            const SkPaint*) SK_OVERRIDE;
   1.153 +
   1.154 +    virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src,
   1.155 +                                      const SkRect& dst, const SkPaint* paint,
   1.156 +                                      DrawBitmapRectFlags flags) SK_OVERRIDE;
   1.157 +
   1.158 +    virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
   1.159 +                                  const SkPaint*) SK_OVERRIDE;
   1.160 +
   1.161 +    virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
   1.162 +                                const SkRect& dst, const SkPaint*) SK_OVERRIDE;
   1.163 +
   1.164 +    virtual void drawData(const void*, size_t) SK_OVERRIDE;
   1.165 +
   1.166 +    virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
   1.167 +
   1.168 +    virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
   1.169 +
   1.170 +    virtual void endCommentGroup() SK_OVERRIDE;
   1.171 +
   1.172 +    virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
   1.173 +
   1.174 +    virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
   1.175 +
   1.176 +    virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
   1.177 +
   1.178 +    virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
   1.179 +
   1.180 +    virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
   1.181 +                            const SkPaint&) SK_OVERRIDE;
   1.182 +
   1.183 +    virtual void drawPosText(const void* text, size_t byteLength,
   1.184 +                             const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
   1.185 +
   1.186 +    virtual void drawPosTextH(const void* text, size_t byteLength,
   1.187 +                              const SkScalar xpos[], SkScalar constY,
   1.188 +                              const SkPaint&) SK_OVERRIDE;
   1.189 +
   1.190 +    virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
   1.191 +
   1.192 +    virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
   1.193 +
   1.194 +    virtual void drawSprite(const SkBitmap&, int left, int top,
   1.195 +                            const SkPaint*) SK_OVERRIDE;
   1.196 +
   1.197 +    virtual void drawText(const void* text, size_t byteLength, SkScalar x,
   1.198 +                          SkScalar y, const SkPaint&) SK_OVERRIDE;
   1.199 +
   1.200 +    virtual void drawTextOnPath(const void* text, size_t byteLength,
   1.201 +                                const SkPath& path, const SkMatrix* matrix,
   1.202 +                                const SkPaint&) SK_OVERRIDE;
   1.203 +
   1.204 +    virtual void drawVertices(VertexMode, int vertexCount,
   1.205 +                              const SkPoint vertices[], const SkPoint texs[],
   1.206 +                              const SkColor colors[], SkXfermode*,
   1.207 +                              const uint16_t indices[], int indexCount,
   1.208 +                              const SkPaint&) SK_OVERRIDE;
   1.209 +
   1.210 +    static const int kVizImageHeight = 256;
   1.211 +    static const int kVizImageWidth = 256;
   1.212 +
   1.213 +    virtual bool isClipEmpty() const SK_OVERRIDE { return false; }
   1.214 +    virtual bool isClipRect() const SK_OVERRIDE { return true; }
   1.215 +#ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
   1.216 +    virtual ClipType getClipType() const SK_OVERRIDE {
   1.217 +        return kRect_ClipType;
   1.218 +    }
   1.219 +#endif
   1.220 +    virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE {
   1.221 +        if (NULL != bounds) {
   1.222 +            bounds->setXYWH(0, 0,
   1.223 +                            SkIntToScalar(this->imageInfo().fWidth),
   1.224 +                            SkIntToScalar(this->imageInfo().fHeight));
   1.225 +        }
   1.226 +        return true;
   1.227 +    }
   1.228 +    virtual bool getClipDeviceBounds(SkIRect* bounds) const SK_OVERRIDE {
   1.229 +        if (NULL != bounds) {
   1.230 +            bounds->setLargest();
   1.231 +        }
   1.232 +        return true;
   1.233 +    }
   1.234 +
   1.235 +protected:
   1.236 +    virtual void willSave(SaveFlags) SK_OVERRIDE;
   1.237 +    virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
   1.238 +    virtual void willRestore() SK_OVERRIDE;
   1.239 +
   1.240 +    virtual void didTranslate(SkScalar, SkScalar) SK_OVERRIDE;
   1.241 +    virtual void didScale(SkScalar, SkScalar) SK_OVERRIDE;
   1.242 +    virtual void didRotate(SkScalar) SK_OVERRIDE;
   1.243 +    virtual void didSkew(SkScalar, SkScalar) SK_OVERRIDE;
   1.244 +    virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
   1.245 +    virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
   1.246 +
   1.247 +    virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
   1.248 +    virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
   1.249 +    virtual void onPopCull() SK_OVERRIDE;
   1.250 +
   1.251 +    virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
   1.252 +    virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
   1.253 +    virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
   1.254 +    virtual void onClipRegion(const SkRegion& region, SkRegion::Op) SK_OVERRIDE;
   1.255 +
   1.256 +    void markActiveCommands(int index);
   1.257 +
   1.258 +private:
   1.259 +    SkTDArray<SkDrawCommand*> fCommandVector;
   1.260 +    int fWidth;
   1.261 +    int fHeight;
   1.262 +    bool fFilter;
   1.263 +    bool fMegaVizMode;
   1.264 +    int fIndex;
   1.265 +    SkMatrix fUserMatrix;
   1.266 +    SkMatrix fMatrix;
   1.267 +    SkIRect fClip;
   1.268 +
   1.269 +    bool fOverdrawViz;
   1.270 +    SkDrawFilter* fOverdrawFilter;
   1.271 +
   1.272 +    bool fOverrideTexFiltering;
   1.273 +    SkTexOverrideFilter* fTexOverrideFilter;
   1.274 +
   1.275 +    /**
   1.276 +        Number of unmatched save() calls at any point during a draw.
   1.277 +        If there are any saveLayer() calls outstanding, we need to resolve
   1.278 +        all of them, which in practice means resolving all save() calls,
   1.279 +        to avoid corruption of our canvas.
   1.280 +    */
   1.281 +    int fOutstandingSaveCount;
   1.282 +
   1.283 +    /**
   1.284 +        The active saveLayer commands at a given point in the renderering.
   1.285 +        Only used when "mega" visualization is enabled.
   1.286 +    */
   1.287 +    SkTDArray<SkDrawCommand*> fActiveLayers;
   1.288 +
   1.289 +    /**
   1.290 +        The active cull commands at a given point in the rendering.
   1.291 +        Only used when "mega" visualization is enabled.
   1.292 +    */
   1.293 +    SkTDArray<SkDrawCommand*> fActiveCulls;
   1.294 +
   1.295 +    /**
   1.296 +        Adds the command to the classes vector of commands.
   1.297 +        @param command  The draw command for execution
   1.298 +     */
   1.299 +    void addDrawCommand(SkDrawCommand* command);
   1.300 +
   1.301 +    /**
   1.302 +        Applies any panning and zooming the user has specified before
   1.303 +        drawing anything else into the canvas.
   1.304 +     */
   1.305 +    void applyUserTransform(SkCanvas* canvas);
   1.306 +
   1.307 +    typedef SkCanvas INHERITED;
   1.308 +};
   1.309 +
   1.310 +#endif

mercurial