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
21 #define LOG_TAG "OpenGLRenderer"
27 #include <private/hwui/DrawGlInfo.h>
29 #include <utils/KeyedVector.h>
30 #include <utils/LinearAllocator.h>
31 #include <utils/RefBase.h>
32 #include <utils/SortedVector.h>
33 #include <utils/String8.h>
34 #include <utils/Vector.h>
36 #include <cutils/compiler.h>
38 #include <androidfw/ResourceTypes.h>
41 #include "CanvasProperty.h"
42 #include "DeferredDisplayList.h"
44 #include "RenderProperties.h"
52 namespace uirenderer {
54 class DeferredDisplayList;
56 class DisplayListRenderer;
64 class RestoreToCountOp;
65 class DrawRenderNodeOp;
68 * Holds data used in the playback a tree of DisplayLists.
70 struct PlaybackStateStruct {
72 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator)
74 , mReplayFlags(replayFlags)
75 , mAllocator(allocator) {}
78 OpenGLRenderer& mRenderer;
79 const int mReplayFlags;
81 // Allocator with the lifetime of a single frame. replay uses an Allocator owned by the struct,
82 // while defer shares the DeferredDisplayList's Allocator
83 // TODO: move this allocator to be owned by object with clear frame lifecycle
84 LinearAllocator * const mAllocator;
86 SkPath* allocPathForFrame() {
87 return mRenderer.allocPathForFrame();
91 struct DeferStateStruct : public PlaybackStateStruct {
92 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags)
93 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)),
94 mDeferredList(deferredList) {}
96 DeferredDisplayList& mDeferredList;
99 struct ReplayStateStruct : public PlaybackStateStruct {
100 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags)
101 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator),
105 LinearAllocator mReplayAllocator;
109 * Data structure that holds the list of commands used in display list stream
111 class DisplayListData {
112 friend class DisplayListRenderer;
115 // range of included ops in DLD::displayListOps
119 // range of included children in DLD::mChildren
120 size_t beginChildIndex;
121 size_t endChildIndex;
123 // whether children with non-zero Z in the chunk should be reordered
124 bool reorderChildren;
130 // pointers to all ops within display list, pointing into allocator data
131 Vector<DisplayListOp*> displayListOps;
133 // index of DisplayListOp restore, after which projected descendents should be drawn
134 int projectionReceiveIndex;
136 Vector<const SkBitmap*> bitmapResources;
137 Vector<const SkPath*> pathResources;
138 Vector<const Res_png_9patch*> patchResources;
140 std::vector<std::unique_ptr<const SkPaint>> paints;
141 std::vector<std::unique_ptr<const SkRegion>> regions;
142 Vector<Functor*> functors;
144 const Vector<Chunk>& getChunks() const {
148 size_t addChild(DrawRenderNodeOp* childOp);
149 const Vector<DrawRenderNodeOp*>& children() { return mChildren; }
151 void ref(VirtualLightRefBase* prop) {
152 mReferenceHolders.push(prop);
155 size_t getUsedSize() {
156 return allocator.usedSize();
163 Vector< sp<VirtualLightRefBase> > mReferenceHolders;
165 // list of children display lists for quick, non-drawing traversal
166 Vector<DrawRenderNodeOp*> mChildren;
168 Vector<Chunk> chunks;
170 // allocator into which all ops were allocated
171 LinearAllocator allocator;
174 void cleanupResources();
177 }; // namespace uirenderer
178 }; // namespace android
180 #endif // ANDROID_HWUI_OPENGL_RENDERER_H