1 /* 2 * Copyright (C) 2013 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 <SkCamera.h> 20 #include <SkDrawable.h> 21 #include <SkMatrix.h> 22 23 #include <private/hwui/DrawGlInfo.h> 24 25 #include <utils/KeyedVector.h> 26 #include <utils/LinearAllocator.h> 27 #include <utils/RefBase.h> 28 #include <utils/SortedVector.h> 29 #include <utils/String8.h> 30 31 #include <cutils/compiler.h> 32 33 #include <androidfw/ResourceTypes.h> 34 35 #include "CanvasProperty.h" 36 #include "Debug.h" 37 #include "GlFunctorLifecycleListener.h" 38 #include "Matrix.h" 39 #include "RenderProperties.h" 40 #include "TreeInfo.h" 41 #include "hwui/Bitmap.h" 42 43 #include <vector> 44 45 class SkBitmap; 46 class SkPaint; 47 class SkPath; 48 class SkRegion; 49 50 namespace android { 51 namespace uirenderer { 52 53 class Rect; 54 class Layer; 55 56 struct RecordedOp; 57 struct RenderNodeOp; 58 59 typedef RecordedOp BaseOpType; 60 typedef RenderNodeOp NodeOpType; 61 62 namespace VectorDrawable { 63 class Tree; 64 }; 65 typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot; 66 67 struct FunctorContainer { 68 Functor* functor; 69 GlFunctorLifecycleListener* listener; 70 }; 71 72 /** 73 * Data structure that holds the list of commands used in display list stream 74 */ 75 class DisplayList { 76 friend class RecordingCanvas; 77 78 public: 79 struct Chunk { 80 // range of included ops in DisplayList::ops() 81 size_t beginOpIndex; 82 size_t endOpIndex; 83 84 // range of included children in DisplayList::children() 85 size_t beginChildIndex; 86 size_t endChildIndex; 87 88 // whether children with non-zero Z in the chunk should be reordered 89 bool reorderChildren; 90 91 // clip at the beginning of a reorder section, applied to reordered children 92 const ClipBase* reorderClip; 93 }; 94 95 DisplayList(); 96 virtual ~DisplayList(); 97 98 // index of DisplayListOp restore, after which projected descendants should be drawn 99 int projectionReceiveIndex; 100 getChunks()101 const LsaVector<Chunk>& getChunks() const { return chunks; } getOps()102 const LsaVector<BaseOpType*>& getOps() const { return ops; } 103 getChildren()104 const LsaVector<NodeOpType*>& getChildren() const { return children; } 105 getBitmapResources()106 const LsaVector<sk_sp<Bitmap>>& getBitmapResources() const { return bitmapResources; } 107 108 size_t addChild(NodeOpType* childOp); 109 ref(VirtualLightRefBase * prop)110 void ref(VirtualLightRefBase* prop) { referenceHolders.push_back(prop); } 111 getUsedSize()112 size_t getUsedSize() { return allocator.usedSize(); } 113 isEmpty()114 virtual bool isEmpty() const { return ops.empty(); } hasFunctor()115 virtual bool hasFunctor() const { return !functors.empty(); } hasVectorDrawables()116 virtual bool hasVectorDrawables() const { return !vectorDrawables.empty(); } isSkiaDL()117 virtual bool isSkiaDL() const { return false; } reuseDisplayList(RenderNode * node,renderthread::CanvasContext * context)118 virtual bool reuseDisplayList(RenderNode* node, renderthread::CanvasContext* context) { 119 return false; 120 } 121 122 virtual void syncContents(); 123 virtual void updateChildren(std::function<void(RenderNode*)> updateFn); 124 virtual bool prepareListAndChildren( 125 TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer, 126 std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn); 127 128 virtual void output(std::ostream& output, uint32_t level); 129 130 protected: 131 // allocator into which all ops and LsaVector arrays allocated 132 LinearAllocator allocator; 133 LinearStdAllocator<void*> stdAllocator; 134 135 private: 136 LsaVector<Chunk> chunks; 137 LsaVector<BaseOpType*> ops; 138 139 // list of Ops referring to RenderNode children for quick, non-drawing traversal 140 LsaVector<NodeOpType*> children; 141 142 // Resources - Skia objects + 9 patches referred to by this DisplayList 143 LsaVector<sk_sp<Bitmap>> bitmapResources; 144 LsaVector<const SkPath*> pathResources; 145 LsaVector<const Res_png_9patch*> patchResources; 146 LsaVector<std::unique_ptr<const SkPaint>> paints; 147 LsaVector<std::unique_ptr<const SkRegion>> regions; 148 LsaVector<sp<VirtualLightRefBase>> referenceHolders; 149 150 // List of functors 151 LsaVector<FunctorContainer> functors; 152 153 // List of VectorDrawables that need to be notified of pushStaging. Note that this list gets 154 // nothing 155 // but a callback during sync DisplayList, unlike the list of functors defined above, which 156 // gets special treatment exclusive for webview. 157 LsaVector<VectorDrawableRoot*> vectorDrawables; 158 159 void cleanupResources(); 160 }; 161 162 }; // namespace uirenderer 163 }; // namespace android 164