blob: 2b5d58051c2c5142bedf823eed6fd1bf0e29a7e3 [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
22namespace android {
23namespace uirenderer {
24namespace skiapipeline {
25
26/**
27 * DumpOpsCanvas prints drawing ops from a SkiaDisplayList into a std::ostream. Children render
28 * nodes are walked recursively and their drawing ops are printed as well.
29 */
30class DumpOpsCanvas : public SkCanvas {
31public:
32 DumpOpsCanvas(std::ostream& output, int level, SkiaDisplayList& displayList)
33 : mOutput(output)
34 , mLevel(level)
35 , mDisplayList(displayList)
John Reck1bcacfd2017-11-03 10:12:19 -070036 , mIdent((level + 1) * 2, ' ') {}
Stan Ilievd2172372017-02-09 16:59:27 -050037
38protected:
39 void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle) override {
40 mOutput << mIdent << "clipRect" << std::endl;
41 }
42
43 void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) override {
44 mOutput << mIdent << "clipRRect" << std::endl;
45 }
46
47 void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle) override {
48 mOutput << mIdent << "clipPath" << std::endl;
49 }
50
51 void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override {
52 mOutput << mIdent << "clipRegion" << std::endl;
53 }
54
John Reck1bcacfd2017-11-03 10:12:19 -070055 void onDrawPaint(const SkPaint&) override { mOutput << mIdent << "drawPaint" << std::endl; }
Stan Ilievd2172372017-02-09 16:59:27 -050056
57 void onDrawPath(const SkPath&, const SkPaint&) override {
58 mOutput << mIdent << "drawPath" << std::endl;
59 }
60
61 void onDrawRect(const SkRect&, const SkPaint&) override {
62 mOutput << mIdent << "drawRect" << std::endl;
63 }
64
65 void onDrawRegion(const SkRegion&, const SkPaint&) override {
66 mOutput << mIdent << "drawRegion" << std::endl;
67 }
68
69 void onDrawOval(const SkRect&, const SkPaint&) override {
70 mOutput << mIdent << "drawOval" << std::endl;
71 }
72
73 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override {
74 mOutput << mIdent << "drawArc" << std::endl;
75 }
76
77 void onDrawRRect(const SkRRect&, const SkPaint&) override {
78 mOutput << mIdent << "drawRRect" << std::endl;
79 }
80
81 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override {
82 mOutput << mIdent << "drawDRRect" << std::endl;
83 }
84
Stan Ilievd2172372017-02-09 16:59:27 -050085 void onDrawTextRSXform(const void*, size_t, const SkRSXform[], const SkRect*,
John Reck1bcacfd2017-11-03 10:12:19 -070086 const SkPaint&) override {
Stan Ilievd2172372017-02-09 16:59:27 -050087 mOutput << mIdent << "drawTextRSXform" << std::endl;
88 }
89
John Reck1bcacfd2017-11-03 10:12:19 -070090 void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint&) override {
Stan Ilievd2172372017-02-09 16:59:27 -050091 mOutput << mIdent << "drawTextBlob" << std::endl;
92 }
93
94 void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*) override {
95 mOutput << mIdent << "drawImage" << std::endl;
96 }
97
98 void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
John Reck1bcacfd2017-11-03 10:12:19 -070099 const SkPaint*) override {
Stan Ilievd2172372017-02-09 16:59:27 -0500100 mOutput << mIdent << "drawImageNine" << std::endl;
101 }
102
103 void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
John Reck1bcacfd2017-11-03 10:12:19 -0700104 SrcRectConstraint) override {
Stan Ilievd2172372017-02-09 16:59:27 -0500105 mOutput << mIdent << "drawImageRect" << std::endl;
106 }
107
108 void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst,
John Reck1bcacfd2017-11-03 10:12:19 -0700109 const SkPaint*) override {
Stan Ilievd2172372017-02-09 16:59:27 -0500110 mOutput << mIdent << "drawImageLattice" << std::endl;
111 }
112
113 void onDrawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint&) override {
114 mOutput << mIdent << "drawPoints" << std::endl;
115 }
116
117 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override {
118 mOutput << mIdent << "drawPicture" << std::endl;
119 }
120
121 void onDrawDrawable(SkDrawable* drawable, const SkMatrix*) override {
122 mOutput << mIdent;
123 auto renderNodeDrawable = getRenderNodeDrawable(drawable);
124 if (nullptr != renderNodeDrawable) {
125 mOutput << std::string(mLevel * 2, ' ') << "drawRenderNode";
126 renderNodeDrawable->getRenderNode()->output(mOutput, mLevel + 1);
127 return;
128 }
Stan Iliev11606ff2018-09-17 14:01:16 -0400129 auto glFunctorDrawable = getFunctorDrawable(drawable);
Stan Ilievd2172372017-02-09 16:59:27 -0500130 if (nullptr != glFunctorDrawable) {
131 mOutput << std::string(mLevel * 2, ' ') << "drawGLFunctorDrawable" << std::endl;
132 return;
133 }
134
135 mOutput << std::string(mLevel * 2, ' ') << "drawDrawable" << std::endl;
136 }
137
138private:
139 RenderNodeDrawable* getRenderNodeDrawable(SkDrawable* drawable) {
John Reck1bcacfd2017-11-03 10:12:19 -0700140 for (auto& child : mDisplayList.mChildNodes) {
Stan Ilievd2172372017-02-09 16:59:27 -0500141 if (drawable == &child) {
142 return &child;
143 }
John Reck1bcacfd2017-11-03 10:12:19 -0700144 }
145 return nullptr;
Stan Ilievd2172372017-02-09 16:59:27 -0500146 }
147
Stan Iliev11606ff2018-09-17 14:01:16 -0400148 FunctorDrawable* getFunctorDrawable(SkDrawable* drawable) {
John Reck1bcacfd2017-11-03 10:12:19 -0700149 for (auto& child : mDisplayList.mChildFunctors) {
Stan Iliev11606ff2018-09-17 14:01:16 -0400150 if (drawable == child) {
151 return child;
Stan Ilievd2172372017-02-09 16:59:27 -0500152 }
John Reck1bcacfd2017-11-03 10:12:19 -0700153 }
154 return nullptr;
Stan Ilievd2172372017-02-09 16:59:27 -0500155 }
156
157 std::ostream& mOutput;
158 int mLevel;
159 SkiaDisplayList& mDisplayList;
160 std::string mIdent;
161};
162
Chris Blume7b8a8082018-11-30 15:51:58 -0800163} // namespace skiapipeline
164} // namespace uirenderer
165} // namespace android