blob: 6a052dbb7cea2e0e3d3cf3adb058a5e0786faab8 [file] [log] [blame]
Stan Ilievd2172372017-02-09 16:59:27 -05001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
John Reck1bcacfd2017-11-03 10:12:19 -070019#include "RenderNode.h"
Stan Ilievd2172372017-02-09 16:59:27 -050020#include "SkiaDisplayList.h"
21
Kevin Lubick856848e2022-02-24 16:24:09 +000022class SkRRect;
23
Stan Ilievd2172372017-02-09 16:59:27 -050024namespace android {
25namespace uirenderer {
26namespace skiapipeline {
27
28/**
29 * DumpOpsCanvas prints drawing ops from a SkiaDisplayList into a std::ostream. Children render
30 * nodes are walked recursively and their drawing ops are printed as well.
31 */
32class DumpOpsCanvas : public SkCanvas {
33public:
John Reckbe671952021-01-13 22:39:32 -050034 DumpOpsCanvas(std::ostream& output, int level, const SkiaDisplayList& displayList)
Stan Ilievd2172372017-02-09 16:59:27 -050035 : mOutput(output)
36 , mLevel(level)
37 , mDisplayList(displayList)
John Reck1bcacfd2017-11-03 10:12:19 -070038 , mIdent((level + 1) * 2, ' ') {}
Stan Ilievd2172372017-02-09 16:59:27 -050039
40protected:
41 void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle) override {
42 mOutput << mIdent << "clipRect" << std::endl;
43 }
44
45 void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) override {
46 mOutput << mIdent << "clipRRect" << std::endl;
47 }
48
49 void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle) override {
50 mOutput << mIdent << "clipPath" << std::endl;
51 }
52
53 void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override {
54 mOutput << mIdent << "clipRegion" << std::endl;
55 }
56
Michael Ludwig70cf50c22021-07-21 17:02:39 +000057 void onResetClip() override { mOutput << mIdent << "resetClip" << std::endl; }
58
John Reck1bcacfd2017-11-03 10:12:19 -070059 void onDrawPaint(const SkPaint&) override { mOutput << mIdent << "drawPaint" << std::endl; }
Stan Ilievd2172372017-02-09 16:59:27 -050060
61 void onDrawPath(const SkPath&, const SkPaint&) override {
62 mOutput << mIdent << "drawPath" << std::endl;
63 }
64
65 void onDrawRect(const SkRect&, const SkPaint&) override {
66 mOutput << mIdent << "drawRect" << std::endl;
67 }
68
69 void onDrawRegion(const SkRegion&, const SkPaint&) override {
70 mOutput << mIdent << "drawRegion" << std::endl;
71 }
72
73 void onDrawOval(const SkRect&, const SkPaint&) override {
74 mOutput << mIdent << "drawOval" << std::endl;
75 }
76
77 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override {
78 mOutput << mIdent << "drawArc" << std::endl;
79 }
80
81 void onDrawRRect(const SkRRect&, const SkPaint&) override {
82 mOutput << mIdent << "drawRRect" << std::endl;
83 }
84
85 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override {
86 mOutput << mIdent << "drawDRRect" << std::endl;
87 }
88
John Reck1bcacfd2017-11-03 10:12:19 -070089 void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint&) override {
Stan Ilievd2172372017-02-09 16:59:27 -050090 mOutput << mIdent << "drawTextBlob" << std::endl;
91 }
92
Mike Reed2d1279f2020-12-30 09:57:25 -050093 void onDrawImage2(const SkImage*, SkScalar dx, SkScalar dy, const SkSamplingOptions&,
94 const SkPaint*) override {
Stan Ilievd2172372017-02-09 16:59:27 -050095 mOutput << mIdent << "drawImage" << std::endl;
96 }
97
Mike Reed2d1279f2020-12-30 09:57:25 -050098 void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&,
99 const SkPaint*, SrcRectConstraint) override {
Stan Ilievd2172372017-02-09 16:59:27 -0500100 mOutput << mIdent << "drawImageRect" << std::endl;
101 }
102
Mike Reed2d1279f2020-12-30 09:57:25 -0500103 void onDrawImageLattice2(const SkImage*, const Lattice& lattice, const SkRect& dst,
104 SkFilterMode, const SkPaint*) override {
Stan Ilievd2172372017-02-09 16:59:27 -0500105 mOutput << mIdent << "drawImageLattice" << std::endl;
106 }
107
108 void onDrawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint&) override {
109 mOutput << mIdent << "drawPoints" << std::endl;
110 }
111
112 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override {
113 mOutput << mIdent << "drawPicture" << std::endl;
114 }
115
116 void onDrawDrawable(SkDrawable* drawable, const SkMatrix*) override {
117 mOutput << mIdent;
118 auto renderNodeDrawable = getRenderNodeDrawable(drawable);
119 if (nullptr != renderNodeDrawable) {
120 mOutput << std::string(mLevel * 2, ' ') << "drawRenderNode";
121 renderNodeDrawable->getRenderNode()->output(mOutput, mLevel + 1);
122 return;
123 }
Stan Iliev11606ff2018-09-17 14:01:16 -0400124 auto glFunctorDrawable = getFunctorDrawable(drawable);
Stan Ilievd2172372017-02-09 16:59:27 -0500125 if (nullptr != glFunctorDrawable) {
126 mOutput << std::string(mLevel * 2, ' ') << "drawGLFunctorDrawable" << std::endl;
127 return;
128 }
129
130 mOutput << std::string(mLevel * 2, ' ') << "drawDrawable" << std::endl;
131 }
132
133private:
John Reckbe671952021-01-13 22:39:32 -0500134 const RenderNodeDrawable* getRenderNodeDrawable(SkDrawable* drawable) {
John Reck1bcacfd2017-11-03 10:12:19 -0700135 for (auto& child : mDisplayList.mChildNodes) {
Stan Ilievd2172372017-02-09 16:59:27 -0500136 if (drawable == &child) {
137 return &child;
138 }
John Reck1bcacfd2017-11-03 10:12:19 -0700139 }
140 return nullptr;
Stan Ilievd2172372017-02-09 16:59:27 -0500141 }
142
Stan Iliev11606ff2018-09-17 14:01:16 -0400143 FunctorDrawable* getFunctorDrawable(SkDrawable* drawable) {
John Reck1bcacfd2017-11-03 10:12:19 -0700144 for (auto& child : mDisplayList.mChildFunctors) {
Stan Iliev11606ff2018-09-17 14:01:16 -0400145 if (drawable == child) {
146 return child;
Stan Ilievd2172372017-02-09 16:59:27 -0500147 }
John Reck1bcacfd2017-11-03 10:12:19 -0700148 }
149 return nullptr;
Stan Ilievd2172372017-02-09 16:59:27 -0500150 }
151
152 std::ostream& mOutput;
153 int mLevel;
John Reckbe671952021-01-13 22:39:32 -0500154 const SkiaDisplayList& mDisplayList;
Stan Ilievd2172372017-02-09 16:59:27 -0500155 std::string mIdent;
156};
157
Chris Blume7b8a8082018-11-30 15:51:58 -0800158} // namespace skiapipeline
159} // namespace uirenderer
160} // namespace android