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 19 #include "RenderNode.h" 20 #include "SkiaDisplayList.h" 21 22 class SkRRect; 23 24 namespace android { 25 namespace uirenderer { 26 namespace 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 */ 32 class DumpOpsCanvas : public SkCanvas { 33 public: DumpOpsCanvas(std::ostream & output,int level,const SkiaDisplayList & displayList)34 DumpOpsCanvas(std::ostream& output, int level, const SkiaDisplayList& displayList) 35 : mOutput(output) 36 , mLevel(level) 37 , mDisplayList(displayList) 38 , mIdent((level + 1) * 2, ' ') {} 39 40 protected: onClipRect(const SkRect & rect,SkClipOp,ClipEdgeStyle)41 void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle) override { 42 mOutput << mIdent << "clipRect" << std::endl; 43 } 44 onClipRRect(const SkRRect & rrect,SkClipOp,ClipEdgeStyle)45 void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) override { 46 mOutput << mIdent << "clipRRect" << std::endl; 47 } 48 onClipPath(const SkPath & path,SkClipOp,ClipEdgeStyle)49 void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle) override { 50 mOutput << mIdent << "clipPath" << std::endl; 51 } 52 onClipRegion(const SkRegion & deviceRgn,SkClipOp)53 void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override { 54 mOutput << mIdent << "clipRegion" << std::endl; 55 } 56 onResetClip()57 void onResetClip() override { mOutput << mIdent << "resetClip" << std::endl; } 58 onDrawPaint(const SkPaint &)59 void onDrawPaint(const SkPaint&) override { mOutput << mIdent << "drawPaint" << std::endl; } 60 onDrawPath(const SkPath &,const SkPaint &)61 void onDrawPath(const SkPath&, const SkPaint&) override { 62 mOutput << mIdent << "drawPath" << std::endl; 63 } 64 onDrawRect(const SkRect &,const SkPaint &)65 void onDrawRect(const SkRect&, const SkPaint&) override { 66 mOutput << mIdent << "drawRect" << std::endl; 67 } 68 onDrawRegion(const SkRegion &,const SkPaint &)69 void onDrawRegion(const SkRegion&, const SkPaint&) override { 70 mOutput << mIdent << "drawRegion" << std::endl; 71 } 72 onDrawOval(const SkRect &,const SkPaint &)73 void onDrawOval(const SkRect&, const SkPaint&) override { 74 mOutput << mIdent << "drawOval" << std::endl; 75 } 76 onDrawArc(const SkRect &,SkScalar,SkScalar,bool,const SkPaint &)77 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override { 78 mOutput << mIdent << "drawArc" << std::endl; 79 } 80 onDrawRRect(const SkRRect &,const SkPaint &)81 void onDrawRRect(const SkRRect&, const SkPaint&) override { 82 mOutput << mIdent << "drawRRect" << std::endl; 83 } 84 onDrawDRRect(const SkRRect &,const SkRRect &,const SkPaint &)85 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override { 86 mOutput << mIdent << "drawDRRect" << std::endl; 87 } 88 onDrawTextBlob(const SkTextBlob *,SkScalar,SkScalar,const SkPaint &)89 void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint&) override { 90 mOutput << mIdent << "drawTextBlob" << std::endl; 91 } 92 onDrawImageRect2(const SkImage *,const SkRect &,const SkRect &,const SkSamplingOptions &,const SkPaint *,SrcRectConstraint)93 void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&, 94 const SkPaint*, SrcRectConstraint) override { 95 mOutput << mIdent << "drawImageRect" << std::endl; 96 } 97 onDrawImageLattice2(const SkImage *,const Lattice & lattice,const SkRect & dst,SkFilterMode,const SkPaint *)98 void onDrawImageLattice2(const SkImage*, const Lattice& lattice, const SkRect& dst, 99 SkFilterMode, const SkPaint*) override { 100 mOutput << mIdent << "drawImageLattice" << std::endl; 101 } 102 onDrawPoints(SkCanvas::PointMode,size_t,const SkPoint[],const SkPaint &)103 void onDrawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint&) override { 104 mOutput << mIdent << "drawPoints" << std::endl; 105 } 106 onDrawPicture(const SkPicture *,const SkMatrix *,const SkPaint *)107 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override { 108 mOutput << mIdent << "drawPicture" << std::endl; 109 } 110 onDrawDrawable(SkDrawable * drawable,const SkMatrix *)111 void onDrawDrawable(SkDrawable* drawable, const SkMatrix*) override { 112 mOutput << mIdent; 113 auto renderNodeDrawable = getRenderNodeDrawable(drawable); 114 if (nullptr != renderNodeDrawable) { 115 mOutput << std::string(mLevel * 2, ' ') << "drawRenderNode"; 116 renderNodeDrawable->getRenderNode()->output(mOutput, mLevel + 1); 117 return; 118 } 119 auto glFunctorDrawable = getFunctorDrawable(drawable); 120 if (nullptr != glFunctorDrawable) { 121 mOutput << std::string(mLevel * 2, ' ') << "drawGLFunctorDrawable" << std::endl; 122 return; 123 } 124 125 mOutput << std::string(mLevel * 2, ' ') << "drawDrawable" << std::endl; 126 } 127 128 private: getRenderNodeDrawable(SkDrawable * drawable)129 const RenderNodeDrawable* getRenderNodeDrawable(SkDrawable* drawable) { 130 for (auto& child : mDisplayList.mChildNodes) { 131 if (drawable == &child) { 132 return &child; 133 } 134 } 135 return nullptr; 136 } 137 getFunctorDrawable(SkDrawable * drawable)138 FunctorDrawable* getFunctorDrawable(SkDrawable* drawable) { 139 for (auto& child : mDisplayList.mChildFunctors) { 140 if (drawable == child) { 141 return child; 142 } 143 } 144 return nullptr; 145 } 146 147 std::ostream& mOutput; 148 int mLevel; 149 const SkiaDisplayList& mDisplayList; 150 std::string mIdent; 151 }; 152 153 } // namespace skiapipeline 154 } // namespace uirenderer 155 } // namespace android 156