2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_HWUI_DISPLAY_LIST_H
18 #define ANDROID_HWUI_DISPLAY_LIST_H
23 #include <private/hwui/DrawGlInfo.h>
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>
31 #include <cutils/compiler.h>
33 #include <androidfw/ResourceTypes.h>
36 #include "CanvasProperty.h"
37 #include "DeferredDisplayList.h"
38 #include "GlFunctorLifecycleListener.h"
40 #include "RenderProperties.h"
50 namespace uirenderer {
52 class DeferredDisplayList;
54 class DisplayListCanvas;
63 typedef RecordedOp BaseOpType;
64 typedef RenderNodeOp NodeOpType;
66 class DrawRenderNodeOp;
68 typedef DisplayListOp BaseOpType;
69 typedef DrawRenderNodeOp NodeOpType;
72 namespace VectorDrawable {
75 typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot;
78 * Holds data used in the playback a tree of DisplayLists.
80 struct PlaybackStateStruct {
82 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator)
84 , mReplayFlags(replayFlags)
85 , mAllocator(allocator) {}
88 OpenGLRenderer& mRenderer;
89 const int mReplayFlags;
91 // Allocator with the lifetime of a single frame. replay uses an Allocator owned by the struct,
92 // while defer shares the DeferredDisplayList's Allocator
93 // TODO: move this allocator to be owned by object with clear frame lifecycle
94 LinearAllocator * const mAllocator;
96 SkPath* allocPathForFrame() {
97 return mRenderer.allocPathForFrame();
101 struct DeferStateStruct : public PlaybackStateStruct {
102 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags)
103 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)),
104 mDeferredList(deferredList) {}
106 DeferredDisplayList& mDeferredList;
109 struct ReplayStateStruct : public PlaybackStateStruct {
110 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags)
111 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator),
115 LinearAllocator mReplayAllocator;
118 struct FunctorContainer {
120 GlFunctorLifecycleListener* listener;
124 * Data structure that holds the list of commands used in display list stream
127 friend class DisplayListCanvas;
128 friend class RecordingCanvas;
131 // range of included ops in DisplayList::ops()
135 // range of included children in DisplayList::children()
136 size_t beginChildIndex;
137 size_t endChildIndex;
139 // whether children with non-zero Z in the chunk should be reordered
140 bool reorderChildren;
142 const ClipBase* reorderClip;
149 // index of DisplayListOp restore, after which projected descendants should be drawn
150 int projectionReceiveIndex;
152 const LsaVector<Chunk>& getChunks() const { return chunks; }
153 const LsaVector<BaseOpType*>& getOps() const { return ops; }
155 const LsaVector<NodeOpType*>& getChildren() const { return children; }
157 const LsaVector<const SkBitmap*>& getBitmapResources() const { return bitmapResources; }
158 const LsaVector<FunctorContainer>& getFunctors() const { return functors; }
159 const LsaVector<VectorDrawableRoot*>& getVectorDrawables() { return vectorDrawables; }
161 size_t addChild(NodeOpType* childOp);
164 void ref(VirtualLightRefBase* prop) {
165 referenceHolders.push_back(prop);
168 size_t getUsedSize() {
169 return allocator.usedSize();
180 // allocator into which all ops and LsaVector arrays allocated
181 LinearAllocator allocator;
182 LinearStdAllocator<void*> stdAllocator;
184 LsaVector<Chunk> chunks;
185 LsaVector<BaseOpType*> ops;
187 // list of Ops referring to RenderNode children for quick, non-drawing traversal
188 LsaVector<NodeOpType*> children;
190 // Resources - Skia objects + 9 patches referred to by this DisplayList
191 LsaVector<const SkBitmap*> bitmapResources;
192 LsaVector<const SkPath*> pathResources;
193 LsaVector<const Res_png_9patch*> patchResources;
194 LsaVector<std::unique_ptr<const SkPaint>> paints;
195 LsaVector<std::unique_ptr<const SkRegion>> regions;
196 LsaVector< sp<VirtualLightRefBase> > referenceHolders;
199 LsaVector<FunctorContainer> functors;
201 // List of VectorDrawables that need to be notified of pushStaging. Note that this list gets nothing
202 // but a callback during sync DisplayList, unlike the list of functors defined above, which
203 // gets special treatment exclusive for webview.
204 LsaVector<VectorDrawableRoot*> vectorDrawables;
206 bool hasDrawOps; // only used if !HWUI_NEW_OPS
208 void cleanupResources();
211 }; // namespace uirenderer
212 }; // namespace android
214 #endif // ANDROID_HWUI_OPENGL_RENDERER_H