blob: 00c4e2d47e4ca169b5308afd57d60748c36377f2 [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>
Romain Guye3b0a012013-06-26 15:45:41 -070030
Chris Craik0776a602013-02-14 15:36:01 -080031#include <cutils/compiler.h>
32
Romain Guye3b0a012013-06-26 15:45:41 -070033#include <androidfw/ResourceTypes.h>
34
Chris Craik0776a602013-02-14 15:36:01 -080035#include "Debug.h"
Tom Hudson2dc236b2014-10-15 15:46:42 -040036#include "CanvasProperty.h"
Chris Craikf57776b2013-10-25 18:30:17 -070037#include "DeferredDisplayList.h"
Tom Hudson2dc236b2014-10-15 15:46:42 -040038#include "Matrix.h"
John Reckacb6f072014-03-12 16:11:23 -070039#include "RenderProperties.h"
Chris Craik0776a602013-02-14 15:36:01 -080040
John Reck272a6852015-07-29 16:48:58 -070041#include <vector>
42
Chris Craik0776a602013-02-14 15:36:01 -080043class SkBitmap;
44class SkPaint;
45class SkPath;
46class SkRegion;
47
48namespace android {
49namespace uirenderer {
50
Chris Craikc3566d02013-02-04 16:16:33 -080051class DeferredDisplayList;
Chris Craik0776a602013-02-14 15:36:01 -080052class DisplayListOp;
Chris Craikdb663fe2015-04-20 13:34:45 -070053class DisplayListCanvas;
Chris Craik0776a602013-02-14 15:36:01 -080054class OpenGLRenderer;
55class Rect;
56class Layer;
Chris Craik0776a602013-02-14 15:36:01 -080057
Chris Craikb565df12015-10-05 13:00:52 -070058#if HWUI_NEW_OPS
59struct RecordedOp;
60struct RenderNodeOp;
Chris Craik10ed6922015-10-15 10:55:15 -070061
62typedef RecordedOp BaseOpType;
63typedef RenderNodeOp NodeOpType;
Chris Craikb565df12015-10-05 13:00:52 -070064#else
Chris Craika7090e02014-06-20 16:01:00 -070065class DrawRenderNodeOp;
Chris Craik10ed6922015-10-15 10:55:15 -070066
67typedef DisplayListOp BaseOpType;
68typedef DrawRenderNodeOp NodeOpType;
Chris Craikb565df12015-10-05 13:00:52 -070069#endif
Chris Craikff785832013-03-08 13:12:16 -080070
Chris Craikf57776b2013-10-25 18:30:17 -070071/**
72 * Holds data used in the playback a tree of DisplayLists.
73 */
Chris Craik07adacf2014-12-19 10:08:40 -080074struct PlaybackStateStruct {
Chris Craikf57776b2013-10-25 18:30:17 -070075protected:
76 PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator)
Chris Craik74669862014-08-07 17:27:30 -070077 : mRenderer(renderer)
78 , mReplayFlags(replayFlags)
79 , mAllocator(allocator) {}
Chris Craikf57776b2013-10-25 18:30:17 -070080
81public:
Chris Craikff785832013-03-08 13:12:16 -080082 OpenGLRenderer& mRenderer;
83 const int mReplayFlags;
Chris Craikf57776b2013-10-25 18:30:17 -070084
Chris Craik4ac36f82014-12-09 16:54:03 -080085 // Allocator with the lifetime of a single frame. replay uses an Allocator owned by the struct,
86 // while defer shares the DeferredDisplayList's Allocator
87 // TODO: move this allocator to be owned by object with clear frame lifecycle
Chris Craikf57776b2013-10-25 18:30:17 -070088 LinearAllocator * const mAllocator;
Chris Craik74669862014-08-07 17:27:30 -070089
90 SkPath* allocPathForFrame() {
Chris Craik4ac36f82014-12-09 16:54:03 -080091 return mRenderer.allocPathForFrame();
Chris Craik74669862014-08-07 17:27:30 -070092 }
Chris Craikff785832013-03-08 13:12:16 -080093};
94
Andreas Gampeedaecc12014-11-10 20:54:07 -080095struct DeferStateStruct : public PlaybackStateStruct {
Chris Craikf57776b2013-10-25 18:30:17 -070096 DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags)
Chris Craik9f68c092014-01-10 10:30:57 -080097 : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)),
98 mDeferredList(deferredList) {}
Chris Craikf57776b2013-10-25 18:30:17 -070099
100 DeferredDisplayList& mDeferredList;
101};
102
Chris Craik07adacf2014-12-19 10:08:40 -0800103struct ReplayStateStruct : public PlaybackStateStruct {
Chris Craikff785832013-03-08 13:12:16 -0800104 ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags)
Chris Craikf57776b2013-10-25 18:30:17 -0700105 : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator),
Tom Hudson107843d2014-09-08 11:26:26 -0400106 mDirty(dirty) {}
Chris Craikf57776b2013-10-25 18:30:17 -0700107
Chris Craikff785832013-03-08 13:12:16 -0800108 Rect& mDirty;
Chris Craikf57776b2013-10-25 18:30:17 -0700109 LinearAllocator mReplayAllocator;
Chris Craikff785832013-03-08 13:12:16 -0800110};
111
Chris Craik0776a602013-02-14 15:36:01 -0800112/**
John Reck44fd8d22014-02-26 11:00:11 -0800113 * Data structure that holds the list of commands used in display list stream
Chris Craik0776a602013-02-14 15:36:01 -0800114 */
Chris Craik003cc3d2015-10-16 10:24:55 -0700115class DisplayList {
Chris Craikdb663fe2015-04-20 13:34:45 -0700116 friend class DisplayListCanvas;
Chris Craikb565df12015-10-05 13:00:52 -0700117 friend class RecordingCanvas;
Chris Craik0776a602013-02-14 15:36:01 -0800118public:
Chris Craik8afd0f22014-08-21 17:41:57 -0700119 struct Chunk {
Chris Craik003cc3d2015-10-16 10:24:55 -0700120 // range of included ops in DisplayList::ops()
Chris Craik8afd0f22014-08-21 17:41:57 -0700121 size_t beginOpIndex;
122 size_t endOpIndex;
123
Chris Craik003cc3d2015-10-16 10:24:55 -0700124 // range of included children in DisplayList::children()
Chris Craik8afd0f22014-08-21 17:41:57 -0700125 size_t beginChildIndex;
126 size_t endChildIndex;
127
128 // whether children with non-zero Z in the chunk should be reordered
129 bool reorderChildren;
130 };
131
Chris Craik003cc3d2015-10-16 10:24:55 -0700132 DisplayList();
133 ~DisplayList();
John Reck44fd8d22014-02-26 11:00:11 -0800134
Chris Craikf533e942014-01-14 22:35:37 -0800135 // index of DisplayListOp restore, after which projected descendents should be drawn
Chris Craik1df26442014-02-05 16:50:41 -0800136 int projectionReceiveIndex;
John Reck44fd8d22014-02-26 11:00:11 -0800137
Chris Craikb36af872015-10-16 14:23:12 -0700138 const LsaVector<Chunk>& getChunks() const { return chunks; }
139 const LsaVector<BaseOpType*>& getOps() const { return ops; }
John Reck44fd8d22014-02-26 11:00:11 -0800140
Chris Craikb36af872015-10-16 14:23:12 -0700141 const LsaVector<NodeOpType*>& getChildren() const { return children; }
John Reck44fd8d22014-02-26 11:00:11 -0800142
Chris Craikb36af872015-10-16 14:23:12 -0700143 const LsaVector<const SkBitmap*>& getBitmapResources() const { return bitmapResources; }
144 const LsaVector<Functor*>& getFunctors() const { return functors; }
John Reck44fd8d22014-02-26 11:00:11 -0800145
Chris Craik10ed6922015-10-15 10:55:15 -0700146 size_t addChild(NodeOpType* childOp);
Chris Craikb36af872015-10-16 14:23:12 -0700147
John Reck087bc0c2014-04-04 16:20:08 -0700148
John Reck0e89e2b2014-10-31 14:49:06 -0700149 void ref(VirtualLightRefBase* prop) {
Chris Craikb36af872015-10-16 14:23:12 -0700150 referenceHolders.push_back(prop);
John Reck52244ff2014-05-01 21:27:37 -0700151 }
152
Chris Craik8afd0f22014-08-21 17:41:57 -0700153 size_t getUsedSize() {
154 return allocator.usedSize();
155 }
156 bool isEmpty() {
Chris Craik0b7e8242015-10-28 16:50:44 -0700157#if HWUI_NEW_OPS
158 return ops.empty();
159#else
Chris Craik8afd0f22014-08-21 17:41:57 -0700160 return !hasDrawOps;
Chris Craik0b7e8242015-10-28 16:50:44 -0700161#endif
Chris Craik8afd0f22014-08-21 17:41:57 -0700162 }
163
John Reck44fd8d22014-02-26 11:00:11 -0800164private:
Chris Craikb36af872015-10-16 14:23:12 -0700165 // allocator into which all ops and LsaVector arrays allocated
Chris Craik8afd0f22014-08-21 17:41:57 -0700166 LinearAllocator allocator;
Chris Craikb36af872015-10-16 14:23:12 -0700167 LinearStdAllocator<void*> stdAllocator;
168
169 LsaVector<Chunk> chunks;
170 LsaVector<BaseOpType*> ops;
171
172 // list of Ops referring to RenderNode children for quick, non-drawing traversal
173 LsaVector<NodeOpType*> children;
174
175 // Resources - Skia objects + 9 patches referred to by this DisplayList
176 LsaVector<const SkBitmap*> bitmapResources;
177 LsaVector<const SkPath*> pathResources;
178 LsaVector<const Res_png_9patch*> patchResources;
179 LsaVector<std::unique_ptr<const SkPaint>> paints;
180 LsaVector<std::unique_ptr<const SkRegion>> regions;
181 LsaVector< sp<VirtualLightRefBase> > referenceHolders;
182
183 // List of functors
184 LsaVector<Functor*> functors;
185
Chris Craik0b7e8242015-10-28 16:50:44 -0700186 bool hasDrawOps; // only used if !HWUI_NEW_OPS
Chris Craik8afd0f22014-08-21 17:41:57 -0700187
John Reck44fd8d22014-02-26 11:00:11 -0800188 void cleanupResources();
Chris Craik0776a602013-02-14 15:36:01 -0800189};
190
Chris Craik0776a602013-02-14 15:36:01 -0800191}; // namespace uirenderer
192}; // namespace android
193
194#endif // ANDROID_HWUI_OPENGL_RENDERER_H