blob: d7615484c9753b2f91299e5a930ba133c48b3382 [file] [log] [blame]
Chris Craik0776a602013-02-14 15:36:01 -08001/*
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
Chris Craikff785832013-03-08 13:12:16 -080023#include <private/hwui/DrawGlInfo.h>
24
Chris Craikf57776b2013-10-25 18:30:17 -070025#include <utils/KeyedVector.h>
Chris Craikc1c5f082013-09-11 16:23:37 -070026#include <utils/LinearAllocator.h>
Chris Craik0776a602013-02-14 15:36:01 -080027#include <utils/RefBase.h>
28#include <utils/SortedVector.h>
29#include <utils/String8.h>
30#include <utils/Vector.h>
Romain Guye3b0a012013-06-26 15:45:41 -070031
Chris Craik0776a602013-02-14 15:36:01 -080032#include <cutils/compiler.h>
33
Romain Guye3b0a012013-06-26 15:45:41 -070034#include <androidfw/ResourceTypes.h>
35
Chris Craik0776a602013-02-14 15:36:01 -080036#include "Debug.h"
Tom Hudson2dc236b2014-10-15 15:46:42 -040037#include "CanvasProperty.h"
Chris Craikf57776b2013-10-25 18:30:17 -070038#include "DeferredDisplayList.h"
Tom Hudson2dc236b2014-10-15 15:46:42 -040039#include "Matrix.h"
John Reckacb6f072014-03-12 16:11:23 -070040#include "RenderProperties.h"
Chris Craik0776a602013-02-14 15:36:01 -080041
42class SkBitmap;
43class SkPaint;
44class SkPath;
45class SkRegion;
46
47namespace android {
48namespace uirenderer {
49
Chris Craikc3566d02013-02-04 16:16:33 -080050class DeferredDisplayList;
Chris Craik0776a602013-02-14 15:36:01 -080051class DisplayListOp;
Chris Craikdb663fe2015-04-20 13:34:45 -070052class DisplayListCanvas;
Chris Craik0776a602013-02-14 15:36:01 -080053class OpenGLRenderer;
54class Rect;
55class Layer;
Chris Craik0776a602013-02-14 15:36:01 -080056
Chris Craikff785832013-03-08 13:12:16 -080057class ClipRectOp;
58class SaveLayerOp;
59class SaveOp;
60class RestoreToCountOp;
Chris Craika7090e02014-06-20 16:01:00 -070061class DrawRenderNodeOp;
Chris Craikff785832013-03-08 13:12:16 -080062
Chris Craikf57776b2013-10-25 18:30:17 -070063/**
64 * Holds data used in the playback a tree of DisplayLists.
65 */
Chris Craik07adacf2014-12-19 10:08:40 -080066struct PlaybackStateStruct {
Chris Craikf57776b2013-10-25 18:30:17 -070067protected:
68 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator)
Chris Craik74669862014-08-07 17:27:30 -070069 : mRenderer(renderer)
70 , mReplayFlags(replayFlags)
71 , mAllocator(allocator) {}
Chris Craikf57776b2013-10-25 18:30:17 -070072
73public:
Chris Craikff785832013-03-08 13:12:16 -080074 OpenGLRenderer& mRenderer;
75 const int mReplayFlags;
Chris Craikf57776b2013-10-25 18:30:17 -070076
Chris Craik4ac36f82014-12-09 16:54:03 -080077 // Allocator with the lifetime of a single frame. replay uses an Allocator owned by the struct,
78 // while defer shares the DeferredDisplayList's Allocator
79 // TODO: move this allocator to be owned by object with clear frame lifecycle
Chris Craikf57776b2013-10-25 18:30:17 -070080 LinearAllocator * const mAllocator;
Chris Craik74669862014-08-07 17:27:30 -070081
82 SkPath* allocPathForFrame() {
Chris Craik4ac36f82014-12-09 16:54:03 -080083 return mRenderer.allocPathForFrame();
Chris Craik74669862014-08-07 17:27:30 -070084 }
Chris Craikff785832013-03-08 13:12:16 -080085};
86
Andreas Gampeedaecc12014-11-10 20:54:07 -080087struct DeferStateStruct : public PlaybackStateStruct {
Chris Craikf57776b2013-10-25 18:30:17 -070088 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags)
Chris Craik9f68c092014-01-10 10:30:57 -080089 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)),
90 mDeferredList(deferredList) {}
Chris Craikf57776b2013-10-25 18:30:17 -070091
92 DeferredDisplayList& mDeferredList;
93};
94
Chris Craik07adacf2014-12-19 10:08:40 -080095struct ReplayStateStruct : public PlaybackStateStruct {
Chris Craikff785832013-03-08 13:12:16 -080096 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags)
Chris Craikf57776b2013-10-25 18:30:17 -070097 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator),
Tom Hudson107843d2014-09-08 11:26:26 -040098 mDirty(dirty) {}
Chris Craikf57776b2013-10-25 18:30:17 -070099
Chris Craikff785832013-03-08 13:12:16 -0800100 Rect& mDirty;
Chris Craikf57776b2013-10-25 18:30:17 -0700101 LinearAllocator mReplayAllocator;
Chris Craikff785832013-03-08 13:12:16 -0800102};
103
Chris Craik0776a602013-02-14 15:36:01 -0800104/**
John Reck44fd8d22014-02-26 11:00:11 -0800105 * Data structure that holds the list of commands used in display list stream
Chris Craik0776a602013-02-14 15:36:01 -0800106 */
John Reck44fd8d22014-02-26 11:00:11 -0800107class DisplayListData {
Chris Craikdb663fe2015-04-20 13:34:45 -0700108 friend class DisplayListCanvas;
Chris Craik0776a602013-02-14 15:36:01 -0800109public:
Chris Craik8afd0f22014-08-21 17:41:57 -0700110 struct Chunk {
111 // range of included ops in DLD::displayListOps
112 size_t beginOpIndex;
113 size_t endOpIndex;
114
115 // range of included children in DLD::mChildren
116 size_t beginChildIndex;
117 size_t endChildIndex;
118
119 // whether children with non-zero Z in the chunk should be reordered
120 bool reorderChildren;
121 };
122
John Reck087bc0c2014-04-04 16:20:08 -0700123 DisplayListData();
124 ~DisplayListData();
John Reck44fd8d22014-02-26 11:00:11 -0800125
Chris Craikf57776b2013-10-25 18:30:17 -0700126 // pointers to all ops within display list, pointing into allocator data
Chris Craik0776a602013-02-14 15:36:01 -0800127 Vector<DisplayListOp*> displayListOps;
Chris Craikf57776b2013-10-25 18:30:17 -0700128
Chris Craikf533e942014-01-14 22:35:37 -0800129 // index of DisplayListOp restore, after which projected descendents should be drawn
Chris Craik1df26442014-02-05 16:50:41 -0800130 int projectionReceiveIndex;
John Reck44fd8d22014-02-26 11:00:11 -0800131
132 Vector<const SkBitmap*> bitmapResources;
Derek Sollenbergeree248592015-02-12 14:10:21 -0500133 Vector<const SkPath*> pathResources;
John Reck44fd8d22014-02-26 11:00:11 -0800134 Vector<const Res_png_9patch*> patchResources;
135
Chris Craik51d6a3d2014-12-22 17:16:56 -0800136 std::vector<std::unique_ptr<const SkPaint>> paints;
137 std::vector<std::unique_ptr<const SkRegion>> regions;
John Reck09d5cdd2014-07-24 10:36:08 -0700138 Vector<Functor*> functors;
John Reck44fd8d22014-02-26 11:00:11 -0800139
Chris Craik8afd0f22014-08-21 17:41:57 -0700140 const Vector<Chunk>& getChunks() const {
141 return chunks;
John Reck44fd8d22014-02-26 11:00:11 -0800142 }
143
Chris Craik8afd0f22014-08-21 17:41:57 -0700144 size_t addChild(DrawRenderNodeOp* childOp);
Chris Craika7090e02014-06-20 16:01:00 -0700145 const Vector<DrawRenderNodeOp*>& children() { return mChildren; }
John Reck087bc0c2014-04-04 16:20:08 -0700146
John Reck0e89e2b2014-10-31 14:49:06 -0700147 void ref(VirtualLightRefBase* prop) {
John Reck52244ff2014-05-01 21:27:37 -0700148 mReferenceHolders.push(prop);
149 }
150
Chris Craik8afd0f22014-08-21 17:41:57 -0700151 size_t getUsedSize() {
152 return allocator.usedSize();
153 }
154 bool isEmpty() {
155 return !hasDrawOps;
156 }
157
John Reck44fd8d22014-02-26 11:00:11 -0800158private:
John Reck087bc0c2014-04-04 16:20:08 -0700159 Vector< sp<VirtualLightRefBase> > mReferenceHolders;
160
161 // list of children display lists for quick, non-drawing traversal
Chris Craika7090e02014-06-20 16:01:00 -0700162 Vector<DrawRenderNodeOp*> mChildren;
John Reck087bc0c2014-04-04 16:20:08 -0700163
Chris Craik8afd0f22014-08-21 17:41:57 -0700164 Vector<Chunk> chunks;
165
166 // allocator into which all ops were allocated
167 LinearAllocator allocator;
168 bool hasDrawOps;
169
John Reck44fd8d22014-02-26 11:00:11 -0800170 void cleanupResources();
Chris Craik0776a602013-02-14 15:36:01 -0800171};
172
Chris Craik0776a602013-02-14 15:36:01 -0800173}; // namespace uirenderer
174}; // namespace android
175
176#endif // ANDROID_HWUI_OPENGL_RENDERER_H