OSDN Git Service

Merge "Ensure Dequeue/Queue duration is always set" into nyc-mr1-dev
[android-x86/frameworks-base.git] / libs / hwui / DisplayList.h
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 #ifndef ANDROID_HWUI_DISPLAY_LIST_H
18 #define ANDROID_HWUI_DISPLAY_LIST_H
19
20 #include <SkCamera.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 "DeferredDisplayList.h"
38 #include "GlFunctorLifecycleListener.h"
39 #include "Matrix.h"
40 #include "RenderProperties.h"
41
42 #include <vector>
43
44 class SkBitmap;
45 class SkPaint;
46 class SkPath;
47 class SkRegion;
48
49 namespace android {
50 namespace uirenderer {
51
52 class DeferredDisplayList;
53 class DisplayListOp;
54 class DisplayListCanvas;
55 class OpenGLRenderer;
56 class Rect;
57 class Layer;
58
59 #if HWUI_NEW_OPS
60 struct RecordedOp;
61 struct RenderNodeOp;
62
63 typedef RecordedOp BaseOpType;
64 typedef RenderNodeOp NodeOpType;
65 #else
66 class DrawRenderNodeOp;
67
68 typedef DisplayListOp BaseOpType;
69 typedef DrawRenderNodeOp NodeOpType;
70 #endif
71
72 namespace VectorDrawable {
73 class Tree;
74 };
75 typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot;
76
77 /**
78  * Holds data used in the playback a tree of DisplayLists.
79  */
80 struct PlaybackStateStruct {
81 protected:
82     PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator)
83             : mRenderer(renderer)
84             , mReplayFlags(replayFlags)
85             , mAllocator(allocator) {}
86
87 public:
88     OpenGLRenderer& mRenderer;
89     const int mReplayFlags;
90
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;
95
96     SkPath* allocPathForFrame() {
97         return mRenderer.allocPathForFrame();
98     }
99 };
100
101 struct DeferStateStruct : public PlaybackStateStruct {
102     DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags)
103             : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)),
104             mDeferredList(deferredList) {}
105
106     DeferredDisplayList& mDeferredList;
107 };
108
109 struct ReplayStateStruct : public PlaybackStateStruct {
110     ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags)
111             : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator),
112             mDirty(dirty) {}
113
114     Rect& mDirty;
115     LinearAllocator mReplayAllocator;
116 };
117
118 struct FunctorContainer {
119     Functor* functor;
120     GlFunctorLifecycleListener* listener;
121 };
122
123 /**
124  * Data structure that holds the list of commands used in display list stream
125  */
126 class DisplayList {
127     friend class DisplayListCanvas;
128     friend class RecordingCanvas;
129 public:
130     struct Chunk {
131         // range of included ops in DisplayList::ops()
132         size_t beginOpIndex;
133         size_t endOpIndex;
134
135         // range of included children in DisplayList::children()
136         size_t beginChildIndex;
137         size_t endChildIndex;
138
139         // whether children with non-zero Z in the chunk should be reordered
140         bool reorderChildren;
141 #if HWUI_NEW_OPS
142         const ClipBase* reorderClip;
143 #endif
144     };
145
146     DisplayList();
147     ~DisplayList();
148
149     // index of DisplayListOp restore, after which projected descendants should be drawn
150     int projectionReceiveIndex;
151
152     const LsaVector<Chunk>& getChunks() const { return chunks; }
153     const LsaVector<BaseOpType*>& getOps() const { return ops; }
154
155     const LsaVector<NodeOpType*>& getChildren() const { return children; }
156
157     const LsaVector<const SkBitmap*>& getBitmapResources() const { return bitmapResources; }
158     const LsaVector<FunctorContainer>& getFunctors() const { return functors; }
159     const LsaVector<VectorDrawableRoot*>& getVectorDrawables() { return vectorDrawables; }
160
161     size_t addChild(NodeOpType* childOp);
162
163
164     void ref(VirtualLightRefBase* prop) {
165         referenceHolders.push_back(prop);
166     }
167
168     size_t getUsedSize() {
169         return allocator.usedSize();
170     }
171     bool isEmpty() {
172 #if HWUI_NEW_OPS
173         return ops.empty();
174 #else
175         return !hasDrawOps;
176 #endif
177     }
178
179 private:
180     // allocator into which all ops and LsaVector arrays allocated
181     LinearAllocator allocator;
182     LinearStdAllocator<void*> stdAllocator;
183
184     LsaVector<Chunk> chunks;
185     LsaVector<BaseOpType*> ops;
186
187     // list of Ops referring to RenderNode children for quick, non-drawing traversal
188     LsaVector<NodeOpType*> children;
189
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;
197
198     // List of functors
199     LsaVector<FunctorContainer> functors;
200
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;
205
206     bool hasDrawOps; // only used if !HWUI_NEW_OPS
207
208     void cleanupResources();
209 };
210
211 }; // namespace uirenderer
212 }; // namespace android
213
214 #endif // ANDROID_HWUI_OPENGL_RENDERER_H