blob: 6fc679bfeb4e01327004238ebf1090c39da07f9d [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 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 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#ifndef SkDumpCanvas_DEFINED
9#define SkDumpCanvas_DEFINED
10
11#include "SkCanvas.h"
12
robertphillips@google.com76f9e932013-01-15 20:17:47 +000013#ifdef SK_DEVELOPER
14
reed@android.com8a1c16f2008-12-17 15:59:43 +000015/** This class overrides all the draw methods on SkCanvas, and formats them
16 as text, and then sends that to a Dumper helper object.
vandebo@chromium.org74b46192012-01-28 01:45:11 +000017
reed@android.com8a1c16f2008-12-17 15:59:43 +000018 Typical use might be to dump a display list to a log file to see what is
19 being drawn.
20 */
21class SkDumpCanvas : public SkCanvas {
22public:
23 class Dumper;
24
25 explicit SkDumpCanvas(Dumper* = 0);
26 virtual ~SkDumpCanvas();
vandebo@chromium.org74b46192012-01-28 01:45:11 +000027
reed@android.com8a1c16f2008-12-17 15:59:43 +000028 enum Verb {
29 kNULL_Verb,
30
31 kSave_Verb,
32 kRestore_Verb,
vandebo@chromium.org74b46192012-01-28 01:45:11 +000033
reed@android.com8a1c16f2008-12-17 15:59:43 +000034 kMatrix_Verb,
vandebo@chromium.org74b46192012-01-28 01:45:11 +000035
reed@android.com8a1c16f2008-12-17 15:59:43 +000036 kClip_Verb,
vandebo@chromium.org74b46192012-01-28 01:45:11 +000037
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 kDrawPaint_Verb,
39 kDrawPoints_Verb,
reed@google.com4ed0fb72012-12-12 20:48:18 +000040 kDrawOval_Verb,
reed@android.com8a1c16f2008-12-17 15:59:43 +000041 kDrawRect_Verb,
reed@google.com4ed0fb72012-12-12 20:48:18 +000042 kDrawRRect_Verb,
commit-bot@chromium.orgab582732014-02-21 12:20:45 +000043 kDrawDRRect_Verb,
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 kDrawPath_Verb,
45 kDrawBitmap_Verb,
46 kDrawText_Verb,
47 kDrawPicture_Verb,
reed@android.comcb608442009-12-04 21:32:27 +000048 kDrawVertices_Verb,
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000049 kDrawData_Verb,
50
51 kBeginCommentGroup_Verb,
52 kAddComment_Verb,
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +000053 kEndCommentGroup_Verb,
54
55 kCull_Verb
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 };
vandebo@chromium.org74b46192012-01-28 01:45:11 +000057
reed@android.com8a1c16f2008-12-17 15:59:43 +000058 /** Subclasses of this are installed on the DumpCanvas, and then called for
59 each drawing command.
60 */
61 class Dumper : public SkRefCnt {
62 public:
reed@google.com563a3b42012-06-26 19:24:50 +000063 SK_DECLARE_INST_COUNT(Dumper)
64
reed@android.com8a1c16f2008-12-17 15:59:43 +000065 virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
66 const SkPaint*) = 0;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000067
reed@google.com563a3b42012-06-26 19:24:50 +000068 private:
69 typedef SkRefCnt INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000070 };
vandebo@chromium.org74b46192012-01-28 01:45:11 +000071
reed@android.com8a1c16f2008-12-17 15:59:43 +000072 Dumper* getDumper() const { return fDumper; }
73 void setDumper(Dumper*);
vandebo@chromium.org74b46192012-01-28 01:45:11 +000074
reed@android.com9b46e772009-06-05 12:24:41 +000075 int getNestLevel() const { return fNestLevel; }
vandebo@chromium.org74b46192012-01-28 01:45:11 +000076
reed@google.com2d4297c2011-10-06 13:14:12 +000077 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000078 virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
reed@google.com2d4297c2011-10-06 13:14:12 +000079 const SkPaint& paint) SK_OVERRIDE;
reed@google.com4ed0fb72012-12-12 20:48:18 +000080 virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
bsalomon@google.com7ce564c2013-10-22 16:54:15 +000081 virtual void drawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
reed@google.com4ed0fb72012-12-12 20:48:18 +000082 virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE;
bsalomon@google.com7ce564c2013-10-22 16:54:15 +000083 virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000084 virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
reed@google.com43d74842011-12-07 14:46:39 +000085 const SkPaint* paint) SK_OVERRIDE;
reed@google.com71121732012-09-18 15:14:33 +000086 virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +000087 const SkRect& dst, const SkPaint* paint,
88 DrawBitmapRectFlags flags) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000089 virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
reed@google.com43d74842011-12-07 14:46:39 +000090 const SkPaint* paint) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000091 virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
reed@google.com43d74842011-12-07 14:46:39 +000092 const SkPaint* paint) SK_OVERRIDE;
reed@google.com2d4297c2011-10-06 13:14:12 +000093 virtual void drawPicture(SkPicture&) SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000094 virtual void drawVertices(VertexMode vmode, int vertexCount,
95 const SkPoint vertices[], const SkPoint texs[],
96 const SkColor colors[], SkXfermode* xmode,
97 const uint16_t indices[], int indexCount,
reed@google.com2d4297c2011-10-06 13:14:12 +000098 const SkPaint& paint) SK_OVERRIDE;
99 virtual void drawData(const void*, size_t) SK_OVERRIDE;
robertphillips@google.com0a4805e2013-05-29 13:24:23 +0000100 virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
101 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
102 virtual void endCommentGroup() SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000103
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000104protected:
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000105 virtual void willSave(SaveFlags) SK_OVERRIDE;
106 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
107 virtual void willRestore() SK_OVERRIDE;
108
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000109 virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
110 virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
111
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000112 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
reed@google.come0d9ce82014-04-23 04:00:17 +0000113 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
114 const SkPaint&) SK_OVERRIDE;
115 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
116 const SkPaint&) SK_OVERRIDE;
117 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
118 SkScalar constY, const SkPaint&) SK_OVERRIDE;
119 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
120 const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +0000121 virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
122 virtual void onPopCull() SK_OVERRIDE;
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000123
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000124 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
125 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
126 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
127 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
128
129 static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle);
130
reed@android.com8a1c16f2008-12-17 15:59:43 +0000131private:
132 Dumper* fDumper;
reed@android.com9b46e772009-06-05 12:24:41 +0000133 int fNestLevel; // for nesting recursive elements like pictures
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000134
reed@android.com8a1c16f2008-12-17 15:59:43 +0000135 void dump(Verb, const SkPaint*, const char format[], ...);
136
137 typedef SkCanvas INHERITED;
138};
139
140/** Formats the draw commands, and send them to a function-pointer provided
141 by the caller.
142 */
143class SkFormatDumper : public SkDumpCanvas::Dumper {
144public:
145 SkFormatDumper(void (*)(const char text[], void* refcon), void* refcon);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000146
reed@android.com8a1c16f2008-12-17 15:59:43 +0000147 // override from baseclass that does the formatting, and in turn calls
148 // the function pointer that was passed to the constructor
149 virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
reed@google.com2d4297c2011-10-06 13:14:12 +0000150 const SkPaint*) SK_OVERRIDE;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000151
reed@android.com8a1c16f2008-12-17 15:59:43 +0000152private:
153 void (*fProc)(const char*, void*);
154 void* fRefcon;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000155
reed@android.com8a1c16f2008-12-17 15:59:43 +0000156 typedef SkDumpCanvas::Dumper INHERITED;
157};
158
159/** Subclass of Dumper that dumps the drawing command to SkDebugf
160 */
161class SkDebugfDumper : public SkFormatDumper {
162public:
163 SkDebugfDumper();
164
165private:
166 typedef SkFormatDumper INHERITED;
167};
168
169#endif
robertphillips@google.com76f9e932013-01-15 20:17:47 +0000170
171#endif