michael@0: michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SKDEBUGCANVAS_H_ michael@0: #define SKDEBUGCANVAS_H_ michael@0: michael@0: #include "SkCanvas.h" michael@0: #include "SkDrawCommand.h" michael@0: #include "SkPicture.h" michael@0: #include "SkTArray.h" michael@0: #include "SkString.h" michael@0: michael@0: class SkTexOverrideFilter; michael@0: michael@0: class SK_API SkDebugCanvas : public SkCanvas { michael@0: public: michael@0: SkDebugCanvas(int width, int height); michael@0: virtual ~SkDebugCanvas(); michael@0: michael@0: void toggleFilter(bool toggle) { fFilter = toggle; } michael@0: michael@0: void setMegaVizMode(bool megaVizMode) { fMegaVizMode = megaVizMode; } michael@0: michael@0: /** michael@0: * Enable or disable overdraw visualization michael@0: */ michael@0: void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; } michael@0: michael@0: /** michael@0: * Enable or disable texure filtering override michael@0: */ michael@0: void overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level); michael@0: michael@0: /** michael@0: Executes all draw calls to the canvas. michael@0: @param canvas The canvas being drawn to michael@0: */ michael@0: void draw(SkCanvas* canvas); michael@0: michael@0: /** michael@0: Executes the draw calls up to the specified index. michael@0: @param canvas The canvas being drawn to michael@0: @param index The index of the final command being executed michael@0: */ michael@0: void drawTo(SkCanvas* canvas, int index); michael@0: michael@0: /** michael@0: Returns the most recently calculated transformation matrix michael@0: */ michael@0: const SkMatrix& getCurrentMatrix() { michael@0: return fMatrix; michael@0: } michael@0: michael@0: /** michael@0: Returns the most recently calculated clip michael@0: */ michael@0: const SkIRect& getCurrentClip() { michael@0: return fClip; michael@0: } michael@0: michael@0: /** michael@0: Returns the index of the last draw command to write to the pixel at (x,y) michael@0: */ michael@0: int getCommandAtPoint(int x, int y, int index); michael@0: michael@0: /** michael@0: Removes the command at the specified index michael@0: @param index The index of the command to delete michael@0: */ michael@0: void deleteDrawCommandAt(int index); michael@0: michael@0: /** michael@0: Returns the draw command at the given index. michael@0: @param index The index of the command michael@0: */ michael@0: SkDrawCommand* getDrawCommandAt(int index); michael@0: michael@0: /** michael@0: Sets the draw command for a given index. michael@0: @param index The index to overwrite michael@0: @param command The new command michael@0: */ michael@0: void setDrawCommandAt(int index, SkDrawCommand* command); michael@0: michael@0: /** michael@0: Returns information about the command at the given index. michael@0: @param index The index of the command michael@0: */ michael@0: SkTDArray* getCommandInfo(int index); michael@0: michael@0: /** michael@0: Returns the visibility of the command at the given index. michael@0: @param index The index of the command michael@0: */ michael@0: bool getDrawCommandVisibilityAt(int index); michael@0: michael@0: /** michael@0: Returns the vector of draw commands michael@0: */ michael@0: SK_ATTR_DEPRECATED("please use getDrawCommandAt and getSize instead") michael@0: const SkTDArray& getDrawCommands() const; michael@0: michael@0: /** michael@0: Returns the vector of draw commands. Do not use this entry michael@0: point - it is going away! michael@0: */ michael@0: SkTDArray& getDrawCommands(); michael@0: michael@0: /** michael@0: * Returns the string vector of draw commands michael@0: */ michael@0: SkTArray* getDrawCommandsAsStrings() const; michael@0: michael@0: /** michael@0: Returns length of draw command vector. michael@0: */ michael@0: int getSize() const { michael@0: return fCommandVector.count(); michael@0: } michael@0: michael@0: /** michael@0: Toggles the visibility / execution of the draw command at index i with michael@0: the value of toggle. michael@0: */ michael@0: void toggleCommand(int index, bool toggle); michael@0: michael@0: void setBounds(int width, int height) { michael@0: fWidth = width; michael@0: fHeight = height; michael@0: } michael@0: michael@0: void setUserMatrix(SkMatrix matrix) { michael@0: fUserMatrix = matrix; michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Inherited from SkCanvas michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: virtual void clear(SkColor) SK_OVERRIDE; michael@0: michael@0: virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, michael@0: const SkPaint*) SK_OVERRIDE; michael@0: michael@0: virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, michael@0: const SkRect& dst, const SkPaint* paint, michael@0: DrawBitmapRectFlags flags) SK_OVERRIDE; michael@0: michael@0: virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, michael@0: const SkPaint*) SK_OVERRIDE; michael@0: michael@0: virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, michael@0: const SkRect& dst, const SkPaint*) SK_OVERRIDE; michael@0: michael@0: virtual void drawData(const void*, size_t) SK_OVERRIDE; michael@0: michael@0: virtual void beginCommentGroup(const char* description) SK_OVERRIDE; michael@0: michael@0: virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; michael@0: michael@0: virtual void endCommentGroup() SK_OVERRIDE; michael@0: michael@0: virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE; michael@0: michael@0: virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; michael@0: michael@0: virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; michael@0: michael@0: virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; michael@0: michael@0: virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], michael@0: const SkPaint&) SK_OVERRIDE; michael@0: michael@0: virtual void drawPosText(const void* text, size_t byteLength, michael@0: const SkPoint pos[], const SkPaint&) SK_OVERRIDE; michael@0: michael@0: virtual void drawPosTextH(const void* text, size_t byteLength, michael@0: const SkScalar xpos[], SkScalar constY, michael@0: const SkPaint&) SK_OVERRIDE; michael@0: michael@0: virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; michael@0: michael@0: virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE; michael@0: michael@0: virtual void drawSprite(const SkBitmap&, int left, int top, michael@0: const SkPaint*) SK_OVERRIDE; michael@0: michael@0: virtual void drawText(const void* text, size_t byteLength, SkScalar x, michael@0: SkScalar y, const SkPaint&) SK_OVERRIDE; michael@0: michael@0: virtual void drawTextOnPath(const void* text, size_t byteLength, michael@0: const SkPath& path, const SkMatrix* matrix, michael@0: const SkPaint&) SK_OVERRIDE; michael@0: michael@0: virtual void drawVertices(VertexMode, int vertexCount, michael@0: const SkPoint vertices[], const SkPoint texs[], michael@0: const SkColor colors[], SkXfermode*, michael@0: const uint16_t indices[], int indexCount, michael@0: const SkPaint&) SK_OVERRIDE; michael@0: michael@0: static const int kVizImageHeight = 256; michael@0: static const int kVizImageWidth = 256; michael@0: michael@0: virtual bool isClipEmpty() const SK_OVERRIDE { return false; } michael@0: virtual bool isClipRect() const SK_OVERRIDE { return true; } michael@0: #ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE michael@0: virtual ClipType getClipType() const SK_OVERRIDE { michael@0: return kRect_ClipType; michael@0: } michael@0: #endif michael@0: virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE { michael@0: if (NULL != bounds) { michael@0: bounds->setXYWH(0, 0, michael@0: SkIntToScalar(this->imageInfo().fWidth), michael@0: SkIntToScalar(this->imageInfo().fHeight)); michael@0: } michael@0: return true; michael@0: } michael@0: virtual bool getClipDeviceBounds(SkIRect* bounds) const SK_OVERRIDE { michael@0: if (NULL != bounds) { michael@0: bounds->setLargest(); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: protected: michael@0: virtual void willSave(SaveFlags) SK_OVERRIDE; michael@0: virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; michael@0: virtual void willRestore() SK_OVERRIDE; michael@0: michael@0: virtual void didTranslate(SkScalar, SkScalar) SK_OVERRIDE; michael@0: virtual void didScale(SkScalar, SkScalar) SK_OVERRIDE; michael@0: virtual void didRotate(SkScalar) SK_OVERRIDE; michael@0: virtual void didSkew(SkScalar, SkScalar) SK_OVERRIDE; michael@0: virtual void didConcat(const SkMatrix&) SK_OVERRIDE; michael@0: virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE; michael@0: michael@0: virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; michael@0: virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE; michael@0: virtual void onPopCull() SK_OVERRIDE; michael@0: michael@0: virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; michael@0: virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; michael@0: virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; michael@0: virtual void onClipRegion(const SkRegion& region, SkRegion::Op) SK_OVERRIDE; michael@0: michael@0: void markActiveCommands(int index); michael@0: michael@0: private: michael@0: SkTDArray fCommandVector; michael@0: int fWidth; michael@0: int fHeight; michael@0: bool fFilter; michael@0: bool fMegaVizMode; michael@0: int fIndex; michael@0: SkMatrix fUserMatrix; michael@0: SkMatrix fMatrix; michael@0: SkIRect fClip; michael@0: michael@0: bool fOverdrawViz; michael@0: SkDrawFilter* fOverdrawFilter; michael@0: michael@0: bool fOverrideTexFiltering; michael@0: SkTexOverrideFilter* fTexOverrideFilter; michael@0: michael@0: /** michael@0: Number of unmatched save() calls at any point during a draw. michael@0: If there are any saveLayer() calls outstanding, we need to resolve michael@0: all of them, which in practice means resolving all save() calls, michael@0: to avoid corruption of our canvas. michael@0: */ michael@0: int fOutstandingSaveCount; michael@0: michael@0: /** michael@0: The active saveLayer commands at a given point in the renderering. michael@0: Only used when "mega" visualization is enabled. michael@0: */ michael@0: SkTDArray fActiveLayers; michael@0: michael@0: /** michael@0: The active cull commands at a given point in the rendering. michael@0: Only used when "mega" visualization is enabled. michael@0: */ michael@0: SkTDArray fActiveCulls; michael@0: michael@0: /** michael@0: Adds the command to the classes vector of commands. michael@0: @param command The draw command for execution michael@0: */ michael@0: void addDrawCommand(SkDrawCommand* command); michael@0: michael@0: /** michael@0: Applies any panning and zooming the user has specified before michael@0: drawing anything else into the canvas. michael@0: */ michael@0: void applyUserTransform(SkCanvas* canvas); michael@0: michael@0: typedef SkCanvas INHERITED; michael@0: }; michael@0: michael@0: #endif