blob: 2987e0cc79e9db0a06ac9c135b23ebe7852c679f [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001/*
2 * Copyright 2012 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 */
7
8
9#ifndef SKDEBUGCANVAS_H_
10#define SKDEBUGCANVAS_H_
11
chudy@google.com902ebe52012-06-29 14:21:22 +000012#include "SkCanvas.h"
Brian Osman78a76482018-05-18 16:59:13 -040013#include "SkCanvasVirtualEnforcer.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000014#include "SkDrawCommand.h"
bungemand3ebb482015-08-05 13:57:49 -070015#include "SkPath.h"
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +000016#include "SkPathOps.h"
reedfb8c1fc2015-08-04 18:44:56 -070017#include "SkString.h"
bungemand3ebb482015-08-05 13:57:49 -070018#include "SkTArray.h"
Brian Salomon199fb872017-02-06 09:41:10 -050019#include "SkVertices.h"
ethannicholas402cd912016-02-10 12:57:30 -080020#include "UrlDataManager.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000021
joshualittae47aee2016-03-10 13:29:36 -080022class GrAuditTrail;
fmalita65cdb572015-03-26 07:24:48 -070023class SkNWayCanvas;
Brian Osman255735e2018-04-06 14:51:42 -040024class SkPicture;
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000025
Brian Osman78a76482018-05-18 16:59:13 -040026// TODO: Continue filling in missing functionality so this can be switched on
27#if 0
28class SkDebugCanvas : public SkCanvasVirtualEnforcer<SkCanvas> {
29#else
Mike Klein0f61faa2016-10-11 16:26:57 -040030class SkDebugCanvas : public SkCanvas {
Brian Osman78a76482018-05-18 16:59:13 -040031#endif
chudy@google.com902ebe52012-06-29 14:21:22 +000032public:
chudy@google.com80a4a602012-07-30 18:54:07 +000033 SkDebugCanvas(int width, int height);
vjiaoblack95302da2016-07-21 10:25:54 -070034
Brian Salomond3b65972017-03-22 12:05:03 -040035 ~SkDebugCanvas() override;
chudy@google.com902ebe52012-06-29 14:21:22 +000036
chudy@google.com902ebe52012-06-29 14:21:22 +000037 /**
robertphillips@google.comf4741c12013-02-06 20:13:54 +000038 * Enable or disable overdraw visualization
39 */
fmalita65cdb572015-03-26 07:24:48 -070040 void setOverdrawViz(bool overdrawViz);
vjiaoblack95302da2016-07-21 10:25:54 -070041
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000042 bool getOverdrawViz() const { return fOverdrawViz; }
43
ethannicholas0a0520a2016-02-12 12:06:53 -080044 /**
45 * Set the color of the clip visualization. An alpha of zero renders the clip invisible.
46 */
47 void setClipVizColor(SkColor clipVizColor) { this->fClipVizColor = clipVizColor; }
vjiaoblack95302da2016-07-21 10:25:54 -070048
Brian Salomon144a5c52016-12-20 16:48:59 -050049 void setDrawGpuOpBounds(bool drawGpuOpBounds) { fDrawGpuOpBounds = drawGpuOpBounds; }
joshualitt10d8fc22016-02-29 11:15:06 -080050
Brian Salomon144a5c52016-12-20 16:48:59 -050051 bool getDrawGpuOpBounds() const { return fDrawGpuOpBounds; }
joshualitt5d5207a2016-02-29 12:46:04 -080052
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000053 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000054 Executes all draw calls to the canvas.
55 @param canvas The canvas being drawn to
56 */
vjiaoblack95302da2016-07-21 10:25:54 -070057 void draw(SkCanvas *canvas);
chudy@google.com902ebe52012-06-29 14:21:22 +000058
59 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000060 Executes the draw calls up to the specified index.
61 @param canvas The canvas being drawn to
62 @param index The index of the final command being executed
Brian Salomon144a5c52016-12-20 16:48:59 -050063 @param m an optional Mth gpu op to highlight, or -1
chudy@google.com902ebe52012-06-29 14:21:22 +000064 */
vjiaoblack95302da2016-07-21 10:25:54 -070065 void drawTo(SkCanvas *canvas, int index, int m = -1);
chudy@google.com0b5bbb02012-07-31 19:55:32 +000066
67 /**
chudy@google.coma9e937c2012-08-03 17:32:05 +000068 Returns the most recently calculated transformation matrix
69 */
vjiaoblack95302da2016-07-21 10:25:54 -070070 const SkMatrix &getCurrentMatrix() {
chudy@google.coma9e937c2012-08-03 17:32:05 +000071 return fMatrix;
72 }
73
74 /**
75 Returns the most recently calculated clip
76 */
vjiaoblack95302da2016-07-21 10:25:54 -070077 const SkIRect &getCurrentClip() {
chudy@google.coma9e937c2012-08-03 17:32:05 +000078 return fClip;
79 }
80
81 /**
robertphillips@google.com50c84da2013-04-01 18:18:49 +000082 Removes the command at the specified index
83 @param index The index of the command to delete
84 */
85 void deleteDrawCommandAt(int index);
86
87 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000088 Returns the draw command at the given index.
89 @param index The index of the command
90 */
vjiaoblack95302da2016-07-21 10:25:54 -070091 SkDrawCommand *getDrawCommandAt(int index);
chudy@google.com902ebe52012-06-29 14:21:22 +000092
93 /**
chudy@google.comf1414322012-07-03 20:28:14 +000094 Returns length of draw command vector.
95 */
commit-bot@chromium.org0d4fe142013-07-15 22:47:14 +000096 int getSize() const {
robertphillips@google.com67baba42013-01-02 20:20:31 +000097 return fCommandVector.count();
chudy@google.comf1414322012-07-03 20:28:14 +000098 }
99
chudy@google.com902ebe52012-06-29 14:21:22 +0000100 /**
101 Toggles the visibility / execution of the draw command at index i with
102 the value of toggle.
103 */
104 void toggleCommand(int index, bool toggle);
105
ethannicholas402cd912016-02-10 12:57:30 -0800106 /**
ethannicholas0a0520a2016-02-12 12:06:53 -0800107 Returns a JSON object representing up to the Nth draw, where N is less than
halcanary9d524f22016-03-29 09:03:52 -0700108 SkDebugCanvas::getSize(). The encoder may use the UrlDataManager to store binary data such
ethannicholas0a0520a2016-02-12 12:06:53 -0800109 as images, referring to them via URLs embedded in the JSON.
ethannicholas402cd912016-02-10 12:57:30 -0800110 */
vjiaoblack95302da2016-07-21 10:25:54 -0700111 Json::Value toJSON(UrlDataManager &urlDataManager, int n, SkCanvas *);
ethannicholas402cd912016-02-10 12:57:30 -0800112
Brian Salomon144a5c52016-12-20 16:48:59 -0500113 Json::Value toJSONOpList(int n, SkCanvas*);
joshualittae47aee2016-03-10 13:29:36 -0800114
Robert Phillipsdeaf5682017-09-06 13:07:21 -0400115 void detachCommands(SkTDArray<SkDrawCommand*>* dst) {
116 fCommandVector.swap(*dst);
117 }
118
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000119protected:
mtklein36352bf2015-03-25 18:17:31 -0700120 void willSave() override;
vjiaoblack95302da2016-07-21 10:25:54 -0700121
122 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec &) override;
123
mtklein36352bf2015-03-25 18:17:31 -0700124 void willRestore() override;
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000125
vjiaoblack95302da2016-07-21 10:25:54 -0700126 void didConcat(const SkMatrix &) override;
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000127
vjiaoblack95302da2016-07-21 10:25:54 -0700128 void didSetMatrix(const SkMatrix &) override;
129
reed97660cc2016-06-28 18:54:19 -0700130 void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
mtklein36352bf2015-03-25 18:17:31 -0700131 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800132 void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
mtklein36352bf2015-03-25 18:17:31 -0700133 const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800134 void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
mtklein36352bf2015-03-25 18:17:31 -0700135 const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800136 void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
mtklein36352bf2015-03-25 18:17:31 -0700137 SkScalar constY, const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800138 void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
mtklein36352bf2015-03-25 18:17:31 -0700139 const SkMatrix* matrix, const SkPaint&) override;
reed45561a02016-07-07 12:47:17 -0700140 void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[], const SkRect*,
141 const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800142 void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
mtklein36352bf2015-03-25 18:17:31 -0700143 const SkPaint& paint) override;
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000144
robertphillips9bafc302015-02-13 11:13:00 -0800145 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -0400146 const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint) override;
mtklein36352bf2015-03-25 18:17:31 -0700147 void onDrawPaint(const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800148
mtklein36352bf2015-03-25 18:17:31 -0700149 void onDrawRect(const SkRect&, const SkPaint&) override;
150 void onDrawOval(const SkRect&, const SkPaint&) override;
bsalomonac3aa242016-08-19 11:25:19 -0700151 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
mtklein36352bf2015-03-25 18:17:31 -0700152 void onDrawRRect(const SkRRect&, const SkPaint&) override;
153 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
Mike Reedfed9cfd2017-03-17 12:09:04 -0400154 void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
mtklein36352bf2015-03-25 18:17:31 -0700155 void onDrawPath(const SkPath&, const SkPaint&) override;
Brian Osmanc25e2692018-03-12 10:57:28 -0400156 void onDrawRegion(const SkRegion&, const SkPaint&) override;
mtklein36352bf2015-03-25 18:17:31 -0700157 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
Brian Osman78a76482018-05-18 16:59:13 -0400158 void onDrawBitmapLattice(const SkBitmap&, const Lattice&, const SkRect&,
159 const SkPaint*) override;
reed41af9662015-01-05 07:49:08 -0800160 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
reed562fe472015-07-28 07:35:14 -0700161 SrcRectConstraint) override;
mtklein36352bf2015-03-25 18:17:31 -0700162 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
Stan Ilievac42aeb2017-01-12 16:20:50 -0500163 void onDrawImageLattice(const SkImage* image, const Lattice& lattice,
164 const SkRect& dst, const SkPaint* paint) override;
reed41af9662015-01-05 07:49:08 -0800165 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700166 const SkPaint*, SrcRectConstraint) override;
reed41af9662015-01-05 07:49:08 -0800167 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
mtklein36352bf2015-03-25 18:17:31 -0700168 const SkPaint*) override;
Brian Osmanc25e2692018-03-12 10:57:28 -0400169 void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
170 const SkPaint*) override;
Mike Reedc1f77742016-12-09 09:00:50 -0500171 void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override;
172 void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override;
173 void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override;
174 void onClipRegion(const SkRegion& region, SkClipOp) override;
Derek Sollenberger6aab2ab2018-04-12 12:45:58 -0400175 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000176
mtklein36352bf2015-03-25 18:17:31 -0700177 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
robertphillips9b14f262014-06-04 05:40:44 -0700178
chudy@google.com902ebe52012-06-29 14:21:22 +0000179private:
robertphillips@google.com67baba42013-01-02 20:20:31 +0000180 SkTDArray<SkDrawCommand*> fCommandVector;
chudy@google.coma9e937c2012-08-03 17:32:05 +0000181 SkMatrix fMatrix;
182 SkIRect fClip;
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000183
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000184 bool fOverdrawViz;
ethannicholas0a0520a2016-02-12 12:06:53 -0800185 SkColor fClipVizColor;
Brian Salomon144a5c52016-12-20 16:48:59 -0500186 bool fDrawGpuOpBounds;
chudy@google.com902ebe52012-06-29 14:21:22 +0000187
188 /**
Robert Phillipsdeaf5682017-09-06 13:07:21 -0400189 Adds the command to the class' vector of commands.
chudy@google.com902ebe52012-06-29 14:21:22 +0000190 @param command The draw command for execution
191 */
192 void addDrawCommand(SkDrawCommand* command);
chudy@google.com830b8792012-08-01 15:57:52 +0000193
joshualittae47aee2016-03-10 13:29:36 -0800194 GrAuditTrail* getAuditTrail(SkCanvas*);
195
Brian Salomon144a5c52016-12-20 16:48:59 -0500196 void drawAndCollectOps(int n, SkCanvas*);
joshualittae47aee2016-03-10 13:29:36 -0800197 void cleanupAuditTrail(SkCanvas*);
fmalita65cdb572015-03-26 07:24:48 -0700198
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000199 typedef SkCanvas INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000200};
201
202#endif