blob: b95614931bcab7b8d79c05d935fdfab9acdc5e7e [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 -040026class SkDebugCanvas : public SkCanvasVirtualEnforcer<SkCanvas> {
chudy@google.com902ebe52012-06-29 14:21:22 +000027public:
chudy@google.com80a4a602012-07-30 18:54:07 +000028 SkDebugCanvas(int width, int height);
vjiaoblack95302da2016-07-21 10:25:54 -070029
Brian Salomond3b65972017-03-22 12:05:03 -040030 ~SkDebugCanvas() override;
chudy@google.com902ebe52012-06-29 14:21:22 +000031
chudy@google.com902ebe52012-06-29 14:21:22 +000032 /**
robertphillips@google.comf4741c12013-02-06 20:13:54 +000033 * Enable or disable overdraw visualization
34 */
fmalita65cdb572015-03-26 07:24:48 -070035 void setOverdrawViz(bool overdrawViz);
vjiaoblack95302da2016-07-21 10:25:54 -070036
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +000037 bool getOverdrawViz() const { return fOverdrawViz; }
38
ethannicholas0a0520a2016-02-12 12:06:53 -080039 /**
40 * Set the color of the clip visualization. An alpha of zero renders the clip invisible.
41 */
42 void setClipVizColor(SkColor clipVizColor) { this->fClipVizColor = clipVizColor; }
vjiaoblack95302da2016-07-21 10:25:54 -070043
Brian Salomon144a5c52016-12-20 16:48:59 -050044 void setDrawGpuOpBounds(bool drawGpuOpBounds) { fDrawGpuOpBounds = drawGpuOpBounds; }
joshualitt10d8fc22016-02-29 11:15:06 -080045
Brian Salomon144a5c52016-12-20 16:48:59 -050046 bool getDrawGpuOpBounds() const { return fDrawGpuOpBounds; }
joshualitt5d5207a2016-02-29 12:46:04 -080047
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000048 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000049 Executes all draw calls to the canvas.
50 @param canvas The canvas being drawn to
51 */
vjiaoblack95302da2016-07-21 10:25:54 -070052 void draw(SkCanvas *canvas);
chudy@google.com902ebe52012-06-29 14:21:22 +000053
54 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000055 Executes the draw calls up to the specified index.
56 @param canvas The canvas being drawn to
57 @param index The index of the final command being executed
Brian Salomon144a5c52016-12-20 16:48:59 -050058 @param m an optional Mth gpu op to highlight, or -1
chudy@google.com902ebe52012-06-29 14:21:22 +000059 */
vjiaoblack95302da2016-07-21 10:25:54 -070060 void drawTo(SkCanvas *canvas, int index, int m = -1);
chudy@google.com0b5bbb02012-07-31 19:55:32 +000061
62 /**
chudy@google.coma9e937c2012-08-03 17:32:05 +000063 Returns the most recently calculated transformation matrix
64 */
vjiaoblack95302da2016-07-21 10:25:54 -070065 const SkMatrix &getCurrentMatrix() {
chudy@google.coma9e937c2012-08-03 17:32:05 +000066 return fMatrix;
67 }
68
69 /**
70 Returns the most recently calculated clip
71 */
vjiaoblack95302da2016-07-21 10:25:54 -070072 const SkIRect &getCurrentClip() {
chudy@google.coma9e937c2012-08-03 17:32:05 +000073 return fClip;
74 }
75
76 /**
robertphillips@google.com50c84da2013-04-01 18:18:49 +000077 Removes the command at the specified index
78 @param index The index of the command to delete
79 */
80 void deleteDrawCommandAt(int index);
81
82 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000083 Returns the draw command at the given index.
84 @param index The index of the command
85 */
vjiaoblack95302da2016-07-21 10:25:54 -070086 SkDrawCommand *getDrawCommandAt(int index);
chudy@google.com902ebe52012-06-29 14:21:22 +000087
88 /**
chudy@google.comf1414322012-07-03 20:28:14 +000089 Returns length of draw command vector.
90 */
commit-bot@chromium.org0d4fe142013-07-15 22:47:14 +000091 int getSize() const {
robertphillips@google.com67baba42013-01-02 20:20:31 +000092 return fCommandVector.count();
chudy@google.comf1414322012-07-03 20:28:14 +000093 }
94
chudy@google.com902ebe52012-06-29 14:21:22 +000095 /**
96 Toggles the visibility / execution of the draw command at index i with
97 the value of toggle.
98 */
99 void toggleCommand(int index, bool toggle);
100
ethannicholas402cd912016-02-10 12:57:30 -0800101 /**
ethannicholas0a0520a2016-02-12 12:06:53 -0800102 Returns a JSON object representing up to the Nth draw, where N is less than
halcanary9d524f22016-03-29 09:03:52 -0700103 SkDebugCanvas::getSize(). The encoder may use the UrlDataManager to store binary data such
ethannicholas0a0520a2016-02-12 12:06:53 -0800104 as images, referring to them via URLs embedded in the JSON.
ethannicholas402cd912016-02-10 12:57:30 -0800105 */
vjiaoblack95302da2016-07-21 10:25:54 -0700106 Json::Value toJSON(UrlDataManager &urlDataManager, int n, SkCanvas *);
ethannicholas402cd912016-02-10 12:57:30 -0800107
Brian Salomon144a5c52016-12-20 16:48:59 -0500108 Json::Value toJSONOpList(int n, SkCanvas*);
joshualittae47aee2016-03-10 13:29:36 -0800109
Robert Phillipsdeaf5682017-09-06 13:07:21 -0400110 void detachCommands(SkTDArray<SkDrawCommand*>* dst) {
111 fCommandVector.swap(*dst);
112 }
113
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000114protected:
mtklein36352bf2015-03-25 18:17:31 -0700115 void willSave() override;
vjiaoblack95302da2016-07-21 10:25:54 -0700116
117 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec &) override;
118
mtklein36352bf2015-03-25 18:17:31 -0700119 void willRestore() override;
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000120
vjiaoblack95302da2016-07-21 10:25:54 -0700121 void didConcat(const SkMatrix &) override;
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000122
vjiaoblack95302da2016-07-21 10:25:54 -0700123 void didSetMatrix(const SkMatrix &) override;
124
reed97660cc2016-06-28 18:54:19 -0700125 void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
mtklein36352bf2015-03-25 18:17:31 -0700126 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800127 void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
mtklein36352bf2015-03-25 18:17:31 -0700128 const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800129 void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
mtklein36352bf2015-03-25 18:17:31 -0700130 const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800131 void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
mtklein36352bf2015-03-25 18:17:31 -0700132 SkScalar constY, const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800133 void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
mtklein36352bf2015-03-25 18:17:31 -0700134 const SkMatrix* matrix, const SkPaint&) override;
reed45561a02016-07-07 12:47:17 -0700135 void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[], const SkRect*,
136 const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800137 void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
mtklein36352bf2015-03-25 18:17:31 -0700138 const SkPaint& paint) override;
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000139
robertphillips9bafc302015-02-13 11:13:00 -0800140 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -0400141 const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint) override;
mtklein36352bf2015-03-25 18:17:31 -0700142 void onDrawPaint(const SkPaint&) override;
robertphillips9bafc302015-02-13 11:13:00 -0800143
mtklein36352bf2015-03-25 18:17:31 -0700144 void onDrawRect(const SkRect&, const SkPaint&) override;
145 void onDrawOval(const SkRect&, const SkPaint&) override;
bsalomonac3aa242016-08-19 11:25:19 -0700146 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
mtklein36352bf2015-03-25 18:17:31 -0700147 void onDrawRRect(const SkRRect&, const SkPaint&) override;
148 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
Ruiqi Maof5101492018-06-29 14:32:21 -0400149 void onDrawVerticesObject(const SkVertices*, const SkMatrix* bones, int boneCount, SkBlendMode,
150 const SkPaint&) override;
mtklein36352bf2015-03-25 18:17:31 -0700151 void onDrawPath(const SkPath&, const SkPaint&) override;
Brian Osmanc25e2692018-03-12 10:57:28 -0400152 void onDrawRegion(const SkRegion&, const SkPaint&) override;
mtklein36352bf2015-03-25 18:17:31 -0700153 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
Brian Osman78a76482018-05-18 16:59:13 -0400154 void onDrawBitmapLattice(const SkBitmap&, const Lattice&, const SkRect&,
155 const SkPaint*) override;
reed41af9662015-01-05 07:49:08 -0800156 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
reed562fe472015-07-28 07:35:14 -0700157 SrcRectConstraint) override;
mtklein36352bf2015-03-25 18:17:31 -0700158 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
Stan Ilievac42aeb2017-01-12 16:20:50 -0500159 void onDrawImageLattice(const SkImage* image, const Lattice& lattice,
160 const SkRect& dst, const SkPaint* paint) override;
reed41af9662015-01-05 07:49:08 -0800161 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700162 const SkPaint*, SrcRectConstraint) override;
reed41af9662015-01-05 07:49:08 -0800163 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
mtklein36352bf2015-03-25 18:17:31 -0700164 const SkPaint*) override;
Brian Osmanc25e2692018-03-12 10:57:28 -0400165 void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
166 const SkPaint*) override;
Brian Osman616f1cb2018-05-29 11:23:35 -0400167 void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
168 int, SkBlendMode, const SkRect*, const SkPaint*) override;
Mike Reedc1f77742016-12-09 09:00:50 -0500169 void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override;
170 void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override;
171 void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override;
172 void onClipRegion(const SkRegion& region, SkClipOp) override;
Derek Sollenberger6aab2ab2018-04-12 12:45:58 -0400173 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000174
Brian Osmanc7611082018-05-29 14:55:50 -0400175 void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
mtklein36352bf2015-03-25 18:17:31 -0700176 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
robertphillips9b14f262014-06-04 05:40:44 -0700177
chudy@google.com902ebe52012-06-29 14:21:22 +0000178private:
robertphillips@google.com67baba42013-01-02 20:20:31 +0000179 SkTDArray<SkDrawCommand*> fCommandVector;
chudy@google.coma9e937c2012-08-03 17:32:05 +0000180 SkMatrix fMatrix;
181 SkIRect fClip;
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000182
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000183 bool fOverdrawViz;
ethannicholas0a0520a2016-02-12 12:06:53 -0800184 SkColor fClipVizColor;
Brian Salomon144a5c52016-12-20 16:48:59 -0500185 bool fDrawGpuOpBounds;
chudy@google.com902ebe52012-06-29 14:21:22 +0000186
187 /**
Robert Phillipsdeaf5682017-09-06 13:07:21 -0400188 Adds the command to the class' vector of commands.
chudy@google.com902ebe52012-06-29 14:21:22 +0000189 @param command The draw command for execution
190 */
191 void addDrawCommand(SkDrawCommand* command);
chudy@google.com830b8792012-08-01 15:57:52 +0000192
joshualittae47aee2016-03-10 13:29:36 -0800193 GrAuditTrail* getAuditTrail(SkCanvas*);
194
Brian Salomon144a5c52016-12-20 16:48:59 -0500195 void drawAndCollectOps(int n, SkCanvas*);
joshualittae47aee2016-03-10 13:29:36 -0800196 void cleanupAuditTrail(SkCanvas*);
fmalita65cdb572015-03-26 07:24:48 -0700197
Brian Osmanc7611082018-05-29 14:55:50 -0400198 typedef SkCanvasVirtualEnforcer<SkCanvas> INHERITED;
chudy@google.com902ebe52012-06-29 14:21:22 +0000199};
200
201#endif