1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/utils/SkDumpCanvas.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,177 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 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 +#ifndef SkDumpCanvas_DEFINED 1.12 +#define SkDumpCanvas_DEFINED 1.13 + 1.14 +#include "SkCanvas.h" 1.15 + 1.16 +#ifdef SK_DEVELOPER 1.17 + 1.18 +/** This class overrides all the draw methods on SkCanvas, and formats them 1.19 + as text, and then sends that to a Dumper helper object. 1.20 + 1.21 + Typical use might be to dump a display list to a log file to see what is 1.22 + being drawn. 1.23 + */ 1.24 +class SkDumpCanvas : public SkCanvas { 1.25 +public: 1.26 + class Dumper; 1.27 + 1.28 + explicit SkDumpCanvas(Dumper* = 0); 1.29 + virtual ~SkDumpCanvas(); 1.30 + 1.31 + enum Verb { 1.32 + kNULL_Verb, 1.33 + 1.34 + kSave_Verb, 1.35 + kRestore_Verb, 1.36 + 1.37 + kMatrix_Verb, 1.38 + 1.39 + kClip_Verb, 1.40 + 1.41 + kDrawPaint_Verb, 1.42 + kDrawPoints_Verb, 1.43 + kDrawOval_Verb, 1.44 + kDrawRect_Verb, 1.45 + kDrawRRect_Verb, 1.46 + kDrawDRRect_Verb, 1.47 + kDrawPath_Verb, 1.48 + kDrawBitmap_Verb, 1.49 + kDrawText_Verb, 1.50 + kDrawPicture_Verb, 1.51 + kDrawVertices_Verb, 1.52 + kDrawData_Verb, 1.53 + 1.54 + kBeginCommentGroup_Verb, 1.55 + kAddComment_Verb, 1.56 + kEndCommentGroup_Verb, 1.57 + 1.58 + kCull_Verb 1.59 + }; 1.60 + 1.61 + /** Subclasses of this are installed on the DumpCanvas, and then called for 1.62 + each drawing command. 1.63 + */ 1.64 + class Dumper : public SkRefCnt { 1.65 + public: 1.66 + SK_DECLARE_INST_COUNT(Dumper) 1.67 + 1.68 + virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[], 1.69 + const SkPaint*) = 0; 1.70 + 1.71 + private: 1.72 + typedef SkRefCnt INHERITED; 1.73 + }; 1.74 + 1.75 + Dumper* getDumper() const { return fDumper; } 1.76 + void setDumper(Dumper*); 1.77 + 1.78 + int getNestLevel() const { return fNestLevel; } 1.79 + 1.80 + virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; 1.81 + virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[], 1.82 + const SkPaint& paint) SK_OVERRIDE; 1.83 + virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE; 1.84 + virtual void drawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE; 1.85 + virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE; 1.86 + virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE; 1.87 + virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 1.88 + const SkPaint* paint) SK_OVERRIDE; 1.89 + virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 1.90 + const SkRect& dst, const SkPaint* paint, 1.91 + DrawBitmapRectFlags flags) SK_OVERRIDE; 1.92 + virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, 1.93 + const SkPaint* paint) SK_OVERRIDE; 1.94 + virtual void drawSprite(const SkBitmap& bitmap, int left, int top, 1.95 + const SkPaint* paint) SK_OVERRIDE; 1.96 + virtual void drawText(const void* text, size_t byteLength, SkScalar x, 1.97 + SkScalar y, const SkPaint& paint) SK_OVERRIDE; 1.98 + virtual void drawPosText(const void* text, size_t byteLength, 1.99 + const SkPoint pos[], const SkPaint& paint) SK_OVERRIDE; 1.100 + virtual void drawPosTextH(const void* text, size_t byteLength, 1.101 + const SkScalar xpos[], SkScalar constY, 1.102 + const SkPaint& paint) SK_OVERRIDE; 1.103 + virtual void drawTextOnPath(const void* text, size_t byteLength, 1.104 + const SkPath& path, const SkMatrix* matrix, 1.105 + const SkPaint& paint) SK_OVERRIDE; 1.106 + virtual void drawPicture(SkPicture&) SK_OVERRIDE; 1.107 + virtual void drawVertices(VertexMode vmode, int vertexCount, 1.108 + const SkPoint vertices[], const SkPoint texs[], 1.109 + const SkColor colors[], SkXfermode* xmode, 1.110 + const uint16_t indices[], int indexCount, 1.111 + const SkPaint& paint) SK_OVERRIDE; 1.112 + virtual void drawData(const void*, size_t) SK_OVERRIDE; 1.113 + virtual void beginCommentGroup(const char* description) SK_OVERRIDE; 1.114 + virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; 1.115 + virtual void endCommentGroup() SK_OVERRIDE; 1.116 + 1.117 +protected: 1.118 + virtual void willSave(SaveFlags) SK_OVERRIDE; 1.119 + virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; 1.120 + virtual void willRestore() SK_OVERRIDE; 1.121 + 1.122 + virtual void didTranslate(SkScalar, SkScalar) SK_OVERRIDE; 1.123 + virtual void didScale(SkScalar, SkScalar) SK_OVERRIDE; 1.124 + virtual void didRotate(SkScalar) SK_OVERRIDE; 1.125 + virtual void didSkew(SkScalar, SkScalar) SK_OVERRIDE; 1.126 + virtual void didConcat(const SkMatrix&) SK_OVERRIDE; 1.127 + virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE; 1.128 + 1.129 + virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; 1.130 + virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE; 1.131 + virtual void onPopCull() SK_OVERRIDE; 1.132 + 1.133 + virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; 1.134 + virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; 1.135 + virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; 1.136 + virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; 1.137 + 1.138 + static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle); 1.139 + 1.140 +private: 1.141 + Dumper* fDumper; 1.142 + int fNestLevel; // for nesting recursive elements like pictures 1.143 + 1.144 + void dump(Verb, const SkPaint*, const char format[], ...); 1.145 + 1.146 + typedef SkCanvas INHERITED; 1.147 +}; 1.148 + 1.149 +/** Formats the draw commands, and send them to a function-pointer provided 1.150 + by the caller. 1.151 + */ 1.152 +class SkFormatDumper : public SkDumpCanvas::Dumper { 1.153 +public: 1.154 + SkFormatDumper(void (*)(const char text[], void* refcon), void* refcon); 1.155 + 1.156 + // override from baseclass that does the formatting, and in turn calls 1.157 + // the function pointer that was passed to the constructor 1.158 + virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[], 1.159 + const SkPaint*) SK_OVERRIDE; 1.160 + 1.161 +private: 1.162 + void (*fProc)(const char*, void*); 1.163 + void* fRefcon; 1.164 + 1.165 + typedef SkDumpCanvas::Dumper INHERITED; 1.166 +}; 1.167 + 1.168 +/** Subclass of Dumper that dumps the drawing command to SkDebugf 1.169 + */ 1.170 +class SkDebugfDumper : public SkFormatDumper { 1.171 +public: 1.172 + SkDebugfDumper(); 1.173 + 1.174 +private: 1.175 + typedef SkFormatDumper INHERITED; 1.176 +}; 1.177 + 1.178 +#endif 1.179 + 1.180 +#endif