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: |
| 32 | DumpOpsCanvas(std::ostream& output, int level, SkiaDisplayList& displayList) |
| 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 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 55 | void onDrawPaint(const SkPaint&) override { mOutput << mIdent << "drawPaint" << std::endl; } |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 56 | |
| 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 | |
| 85 | void onDrawText(const void*, size_t, SkScalar, SkScalar, const SkPaint&) override { |
| 86 | mOutput << mIdent << "drawText" << std::endl; |
| 87 | } |
| 88 | |
| 89 | void onDrawPosText(const void*, size_t, const SkPoint[], const SkPaint&) override { |
| 90 | mOutput << mIdent << "drawPosText" << std::endl; |
| 91 | } |
| 92 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 93 | void onDrawPosTextH(const void*, size_t, const SkScalar[], SkScalar, const SkPaint&) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 94 | mOutput << mIdent << "drawPosTextH" << std::endl; |
| 95 | } |
| 96 | |
| 97 | void onDrawTextOnPath(const void*, size_t, const SkPath&, const SkMatrix*, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 98 | const SkPaint&) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 99 | mOutput << mIdent << "drawTextOnPath" << std::endl; |
| 100 | } |
| 101 | |
| 102 | void onDrawTextRSXform(const void*, size_t, const SkRSXform[], const SkRect*, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 103 | const SkPaint&) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 104 | mOutput << mIdent << "drawTextRSXform" << std::endl; |
| 105 | } |
| 106 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 107 | void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint&) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 108 | mOutput << mIdent << "drawTextBlob" << std::endl; |
| 109 | } |
| 110 | |
| 111 | void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*) override { |
| 112 | mOutput << mIdent << "drawImage" << std::endl; |
| 113 | } |
| 114 | |
| 115 | void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 116 | const SkPaint*) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 117 | mOutput << mIdent << "drawImageNine" << std::endl; |
| 118 | } |
| 119 | |
| 120 | void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 121 | SrcRectConstraint) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 122 | mOutput << mIdent << "drawImageRect" << std::endl; |
| 123 | } |
| 124 | |
| 125 | void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 126 | const SkPaint*) override { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 127 | mOutput << mIdent << "drawImageLattice" << std::endl; |
| 128 | } |
| 129 | |
| 130 | void onDrawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint&) override { |
| 131 | mOutput << mIdent << "drawPoints" << std::endl; |
| 132 | } |
| 133 | |
| 134 | void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override { |
| 135 | mOutput << mIdent << "drawPicture" << std::endl; |
| 136 | } |
| 137 | |
| 138 | void onDrawDrawable(SkDrawable* drawable, const SkMatrix*) override { |
| 139 | mOutput << mIdent; |
| 140 | auto renderNodeDrawable = getRenderNodeDrawable(drawable); |
| 141 | if (nullptr != renderNodeDrawable) { |
| 142 | mOutput << std::string(mLevel * 2, ' ') << "drawRenderNode"; |
| 143 | renderNodeDrawable->getRenderNode()->output(mOutput, mLevel + 1); |
| 144 | return; |
| 145 | } |
| 146 | auto glFunctorDrawable = getGLFunctorDrawable(drawable); |
| 147 | if (nullptr != glFunctorDrawable) { |
| 148 | mOutput << std::string(mLevel * 2, ' ') << "drawGLFunctorDrawable" << std::endl; |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | mOutput << std::string(mLevel * 2, ' ') << "drawDrawable" << std::endl; |
| 153 | } |
| 154 | |
| 155 | private: |
| 156 | RenderNodeDrawable* getRenderNodeDrawable(SkDrawable* drawable) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 157 | for (auto& child : mDisplayList.mChildNodes) { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 158 | if (drawable == &child) { |
| 159 | return &child; |
| 160 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 161 | } |
| 162 | return nullptr; |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | GLFunctorDrawable* getGLFunctorDrawable(SkDrawable* drawable) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 166 | for (auto& child : mDisplayList.mChildFunctors) { |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 167 | if (drawable == &child) { |
| 168 | return &child; |
| 169 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 170 | } |
| 171 | return nullptr; |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | std::ostream& mOutput; |
| 175 | int mLevel; |
| 176 | SkiaDisplayList& mDisplayList; |
| 177 | std::string mIdent; |
| 178 | }; |
| 179 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 180 | }; // namespace skiapipeline |
| 181 | }; // namespace uirenderer |
| 182 | }; // namespace android |