• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "Debug.h"
36 #include "CanvasProperty.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 public:
78     struct Chunk {
79         // range of included ops in DisplayList::ops()
80         size_t beginOpIndex;
81         size_t endOpIndex;
82 
83         // range of included children in DisplayList::children()
84         size_t beginChildIndex;
85         size_t endChildIndex;
86 
87         // whether children with non-zero Z in the chunk should be reordered
88         bool reorderChildren;
89 
90         // clip at the beginning of a reorder section, applied to reordered children
91         const ClipBase* reorderClip;
92     };
93 
94     DisplayList();
95     virtual ~DisplayList();
96 
97     // index of DisplayListOp restore, after which projected descendants should be drawn
98     int projectionReceiveIndex;
99 
getChunks()100     const LsaVector<Chunk>& getChunks() const { return chunks; }
getOps()101     const LsaVector<BaseOpType*>& getOps() const { return ops; }
102 
getChildren()103     const LsaVector<NodeOpType*>& getChildren() const { return children; }
104 
getBitmapResources()105     const LsaVector<sk_sp<Bitmap>>& getBitmapResources() const { return bitmapResources; }
106 
107     size_t addChild(NodeOpType* childOp);
108 
109 
ref(VirtualLightRefBase * prop)110     void ref(VirtualLightRefBase* prop) {
111         referenceHolders.push_back(prop);
112     }
113 
getUsedSize()114     size_t getUsedSize() {
115         return allocator.usedSize();
116     }
117 
isEmpty()118     virtual bool isEmpty() const { return ops.empty(); }
hasFunctor()119     virtual bool hasFunctor() const { return !functors.empty(); }
hasVectorDrawables()120     virtual bool hasVectorDrawables() const { return !vectorDrawables.empty(); }
isSkiaDL()121     virtual bool isSkiaDL() const { return false; }
reuseDisplayList(RenderNode * node,renderthread::CanvasContext * context)122     virtual bool reuseDisplayList(RenderNode* node, renderthread::CanvasContext* context) {
123         return false;
124     }
125 
126     virtual void syncContents();
127     virtual void updateChildren(std::function<void(RenderNode*)> updateFn);
128     virtual bool prepareListAndChildren(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer,
129             std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn);
130 
131     virtual void output(std::ostream& output, uint32_t level);
132 
133 protected:
134     // allocator into which all ops and LsaVector arrays allocated
135     LinearAllocator allocator;
136     LinearStdAllocator<void*> stdAllocator;
137 
138 private:
139     LsaVector<Chunk> chunks;
140     LsaVector<BaseOpType*> ops;
141 
142     // list of Ops referring to RenderNode children for quick, non-drawing traversal
143     LsaVector<NodeOpType*> children;
144 
145     // Resources - Skia objects + 9 patches referred to by this DisplayList
146     LsaVector<sk_sp<Bitmap>> bitmapResources;
147     LsaVector<const SkPath*> pathResources;
148     LsaVector<const Res_png_9patch*> patchResources;
149     LsaVector<std::unique_ptr<const SkPaint>> paints;
150     LsaVector<std::unique_ptr<const SkRegion>> regions;
151     LsaVector< sp<VirtualLightRefBase> > referenceHolders;
152 
153     // List of functors
154     LsaVector<FunctorContainer> functors;
155 
156     // List of VectorDrawables that need to be notified of pushStaging. Note that this list gets nothing
157     // but a callback during sync DisplayList, unlike the list of functors defined above, which
158     // gets special treatment exclusive for webview.
159     LsaVector<VectorDrawableRoot*> vectorDrawables;
160 
161     void cleanupResources();
162 };
163 
164 }; // namespace uirenderer
165 }; // namespace android
166