blob: 727c5797d776891f44031750296089b7f4a5cb7c [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed2b2810b2016-07-04 14:28:31 -07007
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#ifndef SkDumpCanvas_DEFINED
9#define SkDumpCanvas_DEFINED
10
11#include "SkCanvas.h"
Brian Salomon199fb872017-02-06 09:41:10 -050012#include "SkVertices.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013
14/** This class overrides all the draw methods on SkCanvas, and formats them
15 as text, and then sends that to a Dumper helper object.
vandebo@chromium.org74b46192012-01-28 01:45:11 +000016
reed@android.com8a1c16f2008-12-17 15:59:43 +000017 Typical use might be to dump a display list to a log file to see what is
18 being drawn.
19 */
20class SkDumpCanvas : public SkCanvas {
21public:
22 class Dumper;
23
24 explicit SkDumpCanvas(Dumper* = 0);
Brian Salomond3b65972017-03-22 12:05:03 -040025 ~SkDumpCanvas() override;
vandebo@chromium.org74b46192012-01-28 01:45:11 +000026
reed@android.com8a1c16f2008-12-17 15:59:43 +000027 enum Verb {
28 kNULL_Verb,
29
30 kSave_Verb,
31 kRestore_Verb,
vandebo@chromium.org74b46192012-01-28 01:45:11 +000032
reed@android.com8a1c16f2008-12-17 15:59:43 +000033 kMatrix_Verb,
vandebo@chromium.org74b46192012-01-28 01:45:11 +000034
reed@android.com8a1c16f2008-12-17 15:59:43 +000035 kClip_Verb,
vandebo@chromium.org74b46192012-01-28 01:45:11 +000036
reed@android.com8a1c16f2008-12-17 15:59:43 +000037 kDrawPaint_Verb,
38 kDrawPoints_Verb,
reed@google.com4ed0fb72012-12-12 20:48:18 +000039 kDrawOval_Verb,
bsalomonac3aa242016-08-19 11:25:19 -070040 kDrawArc_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,
dandov963137b2014-08-07 07:49:53 -070049 kDrawPatch_Verb,
reedc4fda922015-01-02 06:39:51 -080050 kDrawData_Verb, // obsolete
reedf70b5312016-03-04 16:36:20 -080051 kDrawAnnotation_Verb,
robertphillips@google.com0a4805e2013-05-29 13:24:23 +000052
commit-bot@chromium.org210ae2a2014-02-27 17:40:13 +000053 kCull_Verb
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 };
vandebo@chromium.org74b46192012-01-28 01:45:11 +000055
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 /** Subclasses of this are installed on the DumpCanvas, and then called for
57 each drawing command.
58 */
59 class Dumper : public SkRefCnt {
60 public:
mtklein2766c002015-06-26 11:45:03 -070061
reed@google.com563a3b42012-06-26 19:24:50 +000062
reed@android.com8a1c16f2008-12-17 15:59:43 +000063 virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
64 const SkPaint*) = 0;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000065
reed@google.com563a3b42012-06-26 19:24:50 +000066 private:
67 typedef SkRefCnt INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 };
vandebo@chromium.org74b46192012-01-28 01:45:11 +000069
reed@android.com8a1c16f2008-12-17 15:59:43 +000070 Dumper* getDumper() const { return fDumper; }
71 void setDumper(Dumper*);
vandebo@chromium.org74b46192012-01-28 01:45:11 +000072
reed@android.com9b46e772009-06-05 12:24:41 +000073 int getNestLevel() const { return fNestLevel; }
vandebo@chromium.org74b46192012-01-28 01:45:11 +000074
commit-bot@chromium.orgab582732014-02-21 12:20:45 +000075protected:
mtklein36352bf2015-03-25 18:17:31 -070076 void willSave() override;
reed4960eee2015-12-18 07:09:18 -080077 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
mtklein36352bf2015-03-25 18:17:31 -070078 void willRestore() override;
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000079
mtklein36352bf2015-03-25 18:17:31 -070080 void didConcat(const SkMatrix&) override;
81 void didSetMatrix(const SkMatrix&) override;
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000082
mtklein36352bf2015-03-25 18:17:31 -070083 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
reed@google.come0d9ce82014-04-23 04:00:17 +000084 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
mtklein36352bf2015-03-25 18:17:31 -070085 const SkPaint&) override;
reed@google.come0d9ce82014-04-23 04:00:17 +000086 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
mtklein36352bf2015-03-25 18:17:31 -070087 const SkPaint&) override;
reed@google.come0d9ce82014-04-23 04:00:17 +000088 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
mtklein36352bf2015-03-25 18:17:31 -070089 SkScalar constY, const SkPaint&) override;
reed@google.come0d9ce82014-04-23 04:00:17 +000090 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
mtklein36352bf2015-03-25 18:17:31 -070091 const SkMatrix* matrix, const SkPaint&) override;
reed45561a02016-07-07 12:47:17 -070092 void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
93 const SkRect* cull, const SkPaint& paint) override;
fmalitab7425172014-08-26 07:56:44 -070094 virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
mtklein36352bf2015-03-25 18:17:31 -070095 const SkPaint& paint) override;
dandovb3c9d1c2014-08-12 08:34:29 -070096 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -040097 const SkPoint texCoords[4], SkBlendMode,
mtklein36352bf2015-03-25 18:17:31 -070098 const SkPaint& paint) override;
commit-bot@chromium.orgab582732014-02-21 12:20:45 +000099
mtklein36352bf2015-03-25 18:17:31 -0700100 void onDrawPaint(const SkPaint&) override;
101 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
102 void onDrawRect(const SkRect&, const SkPaint&) override;
103 void onDrawOval(const SkRect&, const SkPaint&) override;
bsalomonac3aa242016-08-19 11:25:19 -0700104 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
mtklein36352bf2015-03-25 18:17:31 -0700105 void onDrawRRect(const SkRRect&, const SkPaint&) override;
106 void onDrawPath(const SkPath&, const SkPaint&) override;
107 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
reed41af9662015-01-05 07:49:08 -0800108 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
reed562fe472015-07-28 07:35:14 -0700109 SrcRectConstraint) override;
mtklein36352bf2015-03-25 18:17:31 -0700110 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
reed41af9662015-01-05 07:49:08 -0800111 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700112 const SkPaint*, SrcRectConstraint) override;
reed41af9662015-01-05 07:49:08 -0800113 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
mtklein36352bf2015-03-25 18:17:31 -0700114 const SkPaint*) override;
Mike Reedfed9cfd2017-03-17 12:09:04 -0400115 void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
reed41af9662015-01-05 07:49:08 -0800116
Mike Reedc1f77742016-12-09 09:00:50 -0500117 void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override;
118 void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override;
119 void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override;
120 void onClipRegion(const SkRegion&, SkClipOp) override;
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000121
mtklein36352bf2015-03-25 18:17:31 -0700122 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
reedf70b5312016-03-04 16:36:20 -0800123 void onDrawAnnotation(const SkRect&, const char key[], SkData* value) override;
robertphillips9b14f262014-06-04 05:40:44 -0700124
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000125 static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle);
126
reed@android.com8a1c16f2008-12-17 15:59:43 +0000127private:
128 Dumper* fDumper;
reed@android.com9b46e772009-06-05 12:24:41 +0000129 int fNestLevel; // for nesting recursive elements like pictures
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000130
reed@android.com8a1c16f2008-12-17 15:59:43 +0000131 void dump(Verb, const SkPaint*, const char format[], ...);
132
133 typedef SkCanvas INHERITED;
134};
135
136/** Formats the draw commands, and send them to a function-pointer provided
137 by the caller.
138 */
139class SkFormatDumper : public SkDumpCanvas::Dumper {
140public:
141 SkFormatDumper(void (*)(const char text[], void* refcon), void* refcon);
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000142
reed@android.com8a1c16f2008-12-17 15:59:43 +0000143 // override from baseclass that does the formatting, and in turn calls
144 // the function pointer that was passed to the constructor
145 virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
mtklein36352bf2015-03-25 18:17:31 -0700146 const SkPaint*) override;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000147
reed@android.com8a1c16f2008-12-17 15:59:43 +0000148private:
149 void (*fProc)(const char*, void*);
150 void* fRefcon;
vandebo@chromium.org74b46192012-01-28 01:45:11 +0000151
reed@android.com8a1c16f2008-12-17 15:59:43 +0000152 typedef SkDumpCanvas::Dumper INHERITED;
153};
154
155/** Subclass of Dumper that dumps the drawing command to SkDebugf
156 */
157class SkDebugfDumper : public SkFormatDumper {
158public:
159 SkDebugfDumper();
160
161private:
162 typedef SkFormatDumper INHERITED;
163};
164
165#endif