michael@0: michael@0: /* michael@0: * Copyright 2011 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: #ifndef SkDumpCanvas_DEFINED michael@0: #define SkDumpCanvas_DEFINED michael@0: michael@0: #include "SkCanvas.h" michael@0: michael@0: #ifdef SK_DEVELOPER michael@0: michael@0: /** This class overrides all the draw methods on SkCanvas, and formats them michael@0: as text, and then sends that to a Dumper helper object. michael@0: michael@0: Typical use might be to dump a display list to a log file to see what is michael@0: being drawn. michael@0: */ michael@0: class SkDumpCanvas : public SkCanvas { michael@0: public: michael@0: class Dumper; michael@0: michael@0: explicit SkDumpCanvas(Dumper* = 0); michael@0: virtual ~SkDumpCanvas(); michael@0: michael@0: enum Verb { michael@0: kNULL_Verb, michael@0: michael@0: kSave_Verb, michael@0: kRestore_Verb, michael@0: michael@0: kMatrix_Verb, michael@0: michael@0: kClip_Verb, michael@0: michael@0: kDrawPaint_Verb, michael@0: kDrawPoints_Verb, michael@0: kDrawOval_Verb, michael@0: kDrawRect_Verb, michael@0: kDrawRRect_Verb, michael@0: kDrawDRRect_Verb, michael@0: kDrawPath_Verb, michael@0: kDrawBitmap_Verb, michael@0: kDrawText_Verb, michael@0: kDrawPicture_Verb, michael@0: kDrawVertices_Verb, michael@0: kDrawData_Verb, michael@0: michael@0: kBeginCommentGroup_Verb, michael@0: kAddComment_Verb, michael@0: kEndCommentGroup_Verb, michael@0: michael@0: kCull_Verb michael@0: }; michael@0: michael@0: /** Subclasses of this are installed on the DumpCanvas, and then called for michael@0: each drawing command. michael@0: */ michael@0: class Dumper : public SkRefCnt { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(Dumper) michael@0: michael@0: virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[], michael@0: const SkPaint*) = 0; michael@0: michael@0: private: michael@0: typedef SkRefCnt INHERITED; michael@0: }; michael@0: michael@0: Dumper* getDumper() const { return fDumper; } michael@0: void setDumper(Dumper*); michael@0: michael@0: int getNestLevel() const { return fNestLevel; } michael@0: michael@0: virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[], michael@0: const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, michael@0: const SkPaint* paint) SK_OVERRIDE; michael@0: virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, michael@0: const SkRect& dst, const SkPaint* paint, michael@0: DrawBitmapRectFlags flags) SK_OVERRIDE; michael@0: virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, michael@0: const SkPaint* paint) SK_OVERRIDE; michael@0: virtual void drawSprite(const SkBitmap& bitmap, int left, int top, michael@0: const SkPaint* paint) SK_OVERRIDE; michael@0: virtual void drawText(const void* text, size_t byteLength, SkScalar x, michael@0: SkScalar y, const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawPosText(const void* text, size_t byteLength, michael@0: const SkPoint pos[], const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawPosTextH(const void* text, size_t byteLength, michael@0: const SkScalar xpos[], SkScalar constY, michael@0: const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawTextOnPath(const void* text, size_t byteLength, michael@0: const SkPath& path, const SkMatrix* matrix, michael@0: const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawPicture(SkPicture&) SK_OVERRIDE; michael@0: virtual void drawVertices(VertexMode vmode, int vertexCount, michael@0: const SkPoint vertices[], const SkPoint texs[], michael@0: const SkColor colors[], SkXfermode* xmode, michael@0: const uint16_t indices[], int indexCount, michael@0: const SkPaint& paint) SK_OVERRIDE; michael@0: virtual void drawData(const void*, size_t) SK_OVERRIDE; michael@0: virtual void beginCommentGroup(const char* description) SK_OVERRIDE; michael@0: virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; michael@0: virtual void endCommentGroup() SK_OVERRIDE; 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&, SkRegion::Op) SK_OVERRIDE; michael@0: michael@0: static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle); michael@0: michael@0: private: michael@0: Dumper* fDumper; michael@0: int fNestLevel; // for nesting recursive elements like pictures michael@0: michael@0: void dump(Verb, const SkPaint*, const char format[], ...); michael@0: michael@0: typedef SkCanvas INHERITED; michael@0: }; michael@0: michael@0: /** Formats the draw commands, and send them to a function-pointer provided michael@0: by the caller. michael@0: */ michael@0: class SkFormatDumper : public SkDumpCanvas::Dumper { michael@0: public: michael@0: SkFormatDumper(void (*)(const char text[], void* refcon), void* refcon); michael@0: michael@0: // override from baseclass that does the formatting, and in turn calls michael@0: // the function pointer that was passed to the constructor michael@0: virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[], michael@0: const SkPaint*) SK_OVERRIDE; michael@0: michael@0: private: michael@0: void (*fProc)(const char*, void*); michael@0: void* fRefcon; michael@0: michael@0: typedef SkDumpCanvas::Dumper INHERITED; michael@0: }; michael@0: michael@0: /** Subclass of Dumper that dumps the drawing command to SkDebugf michael@0: */ michael@0: class SkDebugfDumper : public SkFormatDumper { michael@0: public: michael@0: SkDebugfDumper(); michael@0: michael@0: private: michael@0: typedef SkFormatDumper INHERITED; michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: #endif