Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 1 | /* |
| 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 Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 19 | #include "RenderNode.h" |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 20 | #include "SkiaDisplayList.h" |
| 21 | |
| 22 | namespace android { |
| 23 | namespace uirenderer { |
| 24 | namespace 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 | */ |
| 30 | class DumpOpsCanvas : public SkCanvas { |
| 31 | public: |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 32 | DumpOpsCanvas(std::ostream& output, int level, const SkiaDisplayList& displayList) |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 33 | : mOutput(output) |
| 34 | , mLevel(level) |
| 35 | , mDisplayList(displayList) |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 36 | , mIdent((level + 1) * 2, ' ') {} |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 37 | |
| 38 | protected: |
| 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 | |
Michael Ludwig | 70cf50c2 | 2021-07-21 17:02:39 +0000 | [diff] [blame^] | 55 | void onResetClip() override { mOutput << mIdent << "resetClip" << std::endl; } |
| 56 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 57 | void onDrawPaint(const SkPaint&) override { mOutput << mIdent << "drawPaint" << std::endl; } |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 58 | |
| 59 | void onDrawPath(const SkPath&, const SkPaint&) override { |
| 60 | mOutput << mIdent << "drawPath" << std::endl; |
| 61 | } |
| 62 | |
| 63 | void onDrawRect(const SkRect&, const SkPaint&) override { |
| 64 | mOutput << mIdent << "drawRect" << std::endl; |
| 65 | } |
| 66 | |
| 67 | void onDrawRegion(const SkRegion&, const SkPaint&) override { |
| 68 | mOutput << mIdent << "drawRegion" << std::endl; |
| 69 | } |
| 70 | |
| 71 | void onDrawOval(const SkRect&, const SkPaint&) override { |
| 72 | mOutput << mIdent << "drawOval" << std::endl; |
| 73 | } |
| 74 | |
| 75 | void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override { |
| 76 | mOutput << mIdent << "drawArc" << std::endl; |
| 77 | } |
| 78 | |
| 79 | void onDrawRRect(const SkRRect&, const SkPaint&) override { |
| 80 | mOutput << mIdent << "drawRRect" << std::endl; |
| 81 | } |
| 82 | |
| 83 | void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override { |
| 84 | mOutput << mIdent << "drawDRRect" << std::endl; |
| 85 | } |
| 86 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 87 | void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint&) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 88 | mOutput << mIdent << "drawTextBlob" << std::endl; |
| 89 | } |
| 90 | |
Mike Reed | 2d1279f | 2020-12-30 09:57:25 -0500 | [diff] [blame] | 91 | void onDrawImage2(const SkImage*, SkScalar dx, SkScalar dy, const SkSamplingOptions&, |
| 92 | const SkPaint*) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 93 | mOutput << mIdent << "drawImage" << std::endl; |
| 94 | } |
| 95 | |
Mike Reed | 2d1279f | 2020-12-30 09:57:25 -0500 | [diff] [blame] | 96 | void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&, |
| 97 | const SkPaint*, SrcRectConstraint) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 98 | mOutput << mIdent << "drawImageRect" << std::endl; |
| 99 | } |
| 100 | |
Mike Reed | 2d1279f | 2020-12-30 09:57:25 -0500 | [diff] [blame] | 101 | void onDrawImageLattice2(const SkImage*, const Lattice& lattice, const SkRect& dst, |
| 102 | SkFilterMode, const SkPaint*) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 103 | mOutput << mIdent << "drawImageLattice" << std::endl; |
| 104 | } |
| 105 | |
| 106 | void onDrawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint&) override { |
| 107 | mOutput << mIdent << "drawPoints" << std::endl; |
| 108 | } |
| 109 | |
| 110 | void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override { |
| 111 | mOutput << mIdent << "drawPicture" << std::endl; |
| 112 | } |
| 113 | |
| 114 | void onDrawDrawable(SkDrawable* drawable, const SkMatrix*) override { |
| 115 | mOutput << mIdent; |
| 116 | auto renderNodeDrawable = getRenderNodeDrawable(drawable); |
| 117 | if (nullptr != renderNodeDrawable) { |
| 118 | mOutput << std::string(mLevel * 2, ' ') << "drawRenderNode"; |
| 119 | renderNodeDrawable->getRenderNode()->output(mOutput, mLevel + 1); |
| 120 | return; |
| 121 | } |
Stan Iliev | 11606ff | 2018-09-17 14:01:16 -0400 | [diff] [blame] | 122 | auto glFunctorDrawable = getFunctorDrawable(drawable); |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 123 | if (nullptr != glFunctorDrawable) { |
| 124 | mOutput << std::string(mLevel * 2, ' ') << "drawGLFunctorDrawable" << std::endl; |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | mOutput << std::string(mLevel * 2, ' ') << "drawDrawable" << std::endl; |
| 129 | } |
| 130 | |
| 131 | private: |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 132 | const RenderNodeDrawable* getRenderNodeDrawable(SkDrawable* drawable) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 133 | for (auto& child : mDisplayList.mChildNodes) { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 134 | if (drawable == &child) { |
| 135 | return &child; |
| 136 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 137 | } |
| 138 | return nullptr; |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 139 | } |
| 140 | |
Stan Iliev | 11606ff | 2018-09-17 14:01:16 -0400 | [diff] [blame] | 141 | FunctorDrawable* getFunctorDrawable(SkDrawable* drawable) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 142 | for (auto& child : mDisplayList.mChildFunctors) { |
Stan Iliev | 11606ff | 2018-09-17 14:01:16 -0400 | [diff] [blame] | 143 | if (drawable == child) { |
| 144 | return child; |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 145 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 146 | } |
| 147 | return nullptr; |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | std::ostream& mOutput; |
| 151 | int mLevel; |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 152 | const SkiaDisplayList& mDisplayList; |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 153 | std::string mIdent; |
| 154 | }; |
| 155 | |
Chris Blume | 7b8a808 | 2018-11-30 15:51:58 -0800 | [diff] [blame] | 156 | } // namespace skiapipeline |
| 157 | } // namespace uirenderer |
| 158 | } // namespace android |