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