epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
reed | 2b2810b | 2016-07-04 14:28:31 -0700 | [diff] [blame] | 7 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #ifndef SkDumpCanvas_DEFINED |
| 9 | #define SkDumpCanvas_DEFINED |
| 10 | |
| 11 | #include "SkCanvas.h" |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 12 | #include "SkVertices.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | |
| 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.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 16 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 17 | Typical use might be to dump a display list to a log file to see what is |
| 18 | being drawn. |
| 19 | */ |
| 20 | class SkDumpCanvas : public SkCanvas { |
| 21 | public: |
| 22 | class Dumper; |
| 23 | |
| 24 | explicit SkDumpCanvas(Dumper* = 0); |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 25 | ~SkDumpCanvas() override; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 26 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | enum Verb { |
| 28 | kNULL_Verb, |
| 29 | |
| 30 | kSave_Verb, |
| 31 | kRestore_Verb, |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 32 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | kMatrix_Verb, |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 34 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | kClip_Verb, |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 36 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | kDrawPaint_Verb, |
| 38 | kDrawPoints_Verb, |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 39 | kDrawOval_Verb, |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 40 | kDrawArc_Verb, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | kDrawRect_Verb, |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 42 | kDrawRRect_Verb, |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 43 | kDrawDRRect_Verb, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | kDrawPath_Verb, |
| 45 | kDrawBitmap_Verb, |
| 46 | kDrawText_Verb, |
| 47 | kDrawPicture_Verb, |
reed@android.com | cb60844 | 2009-12-04 21:32:27 +0000 | [diff] [blame] | 48 | kDrawVertices_Verb, |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 49 | kDrawPatch_Verb, |
reed | c4fda92 | 2015-01-02 06:39:51 -0800 | [diff] [blame] | 50 | kDrawData_Verb, // obsolete |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 51 | kDrawAnnotation_Verb, |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 52 | |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 53 | kCull_Verb |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | }; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 55 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | /** Subclasses of this are installed on the DumpCanvas, and then called for |
| 57 | each drawing command. |
| 58 | */ |
| 59 | class Dumper : public SkRefCnt { |
| 60 | public: |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 61 | |
reed@google.com | 563a3b4 | 2012-06-26 19:24:50 +0000 | [diff] [blame] | 62 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[], |
| 64 | const SkPaint*) = 0; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 65 | |
reed@google.com | 563a3b4 | 2012-06-26 19:24:50 +0000 | [diff] [blame] | 66 | private: |
| 67 | typedef SkRefCnt INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | }; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 69 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | Dumper* getDumper() const { return fDumper; } |
| 71 | void setDumper(Dumper*); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 72 | |
reed@android.com | 9b46e77 | 2009-06-05 12:24:41 +0000 | [diff] [blame] | 73 | int getNestLevel() const { return fNestLevel; } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 74 | |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 75 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 76 | void willSave() override; |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 77 | SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 78 | void willRestore() override; |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 79 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 80 | void didConcat(const SkMatrix&) override; |
| 81 | void didSetMatrix(const SkMatrix&) override; |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 82 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 83 | void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 84 | virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 85 | const SkPaint&) override; |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 86 | virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 87 | const SkPaint&) override; |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 88 | virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 89 | SkScalar constY, const SkPaint&) override; |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 90 | virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 91 | const SkMatrix* matrix, const SkPaint&) override; |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 92 | void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 93 | const SkRect* cull, const SkPaint& paint) override; |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 94 | virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 95 | const SkPaint& paint) override; |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 96 | virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 97 | const SkPoint texCoords[4], SkBlendMode, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 98 | const SkPaint& paint) override; |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 99 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 100 | 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; |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 104 | void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 105 | 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; |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 108 | void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 109 | SrcRectConstraint) override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 110 | void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override; |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 111 | void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 112 | const SkPaint*, SrcRectConstraint) override; |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 113 | void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 114 | const SkPaint*) override; |
Mike Reed | fed9cfd | 2017-03-17 12:09:04 -0400 | [diff] [blame] | 115 | void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 116 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 117 | 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.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 121 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 122 | void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 123 | void onDrawAnnotation(const SkRect&, const char key[], SkData* value) override; |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 124 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 125 | static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle); |
| 126 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 127 | private: |
| 128 | Dumper* fDumper; |
reed@android.com | 9b46e77 | 2009-06-05 12:24:41 +0000 | [diff] [blame] | 129 | int fNestLevel; // for nesting recursive elements like pictures |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 130 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 131 | 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 | */ |
| 139 | class SkFormatDumper : public SkDumpCanvas::Dumper { |
| 140 | public: |
| 141 | SkFormatDumper(void (*)(const char text[], void* refcon), void* refcon); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 142 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | // 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[], |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 146 | const SkPaint*) override; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 147 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 148 | private: |
| 149 | void (*fProc)(const char*, void*); |
| 150 | void* fRefcon; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 151 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 152 | typedef SkDumpCanvas::Dumper INHERITED; |
| 153 | }; |
| 154 | |
| 155 | /** Subclass of Dumper that dumps the drawing command to SkDebugf |
| 156 | */ |
| 157 | class SkDebugfDumper : public SkFormatDumper { |
| 158 | public: |
| 159 | SkDebugfDumper(); |
| 160 | |
| 161 | private: |
| 162 | typedef SkFormatDumper INHERITED; |
| 163 | }; |
| 164 | |
| 165 | #endif |