blob: 06b08919732f78397154594e1c6fd7e9b34b93b9 [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
Chris Craik5e00c7c2016-07-06 16:10:09 -070017#pragma once
Chris Craik0776a602013-02-14 15:36:01 -080018
19#include <SkCamera.h>
Derek Sollenberger0df62092016-09-27 16:04:42 -040020#include <SkDrawable.h>
Chris Craik0776a602013-02-14 15:36:01 -080021#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"
John Reckcd1c3eb2016-04-14 10:38:54 -070037#include "GlFunctorLifecycleListener.h"
Tom Hudson2dc236b2014-10-15 15:46:42 -040038#include "Matrix.h"
John Reckacb6f072014-03-12 16:11:23 -070039#include "RenderProperties.h"
Derek Sollenberger0df62092016-09-27 16:04:42 -040040#include "TreeInfo.h"
Chris Craik0776a602013-02-14 15:36:01 -080041
John Reck272a6852015-07-29 16:48:58 -070042#include <vector>
43
Chris Craik0776a602013-02-14 15:36:01 -080044class SkBitmap;
45class SkPaint;
46class SkPath;
47class SkRegion;
48
49namespace android {
50namespace uirenderer {
51
Chris Craik0776a602013-02-14 15:36:01 -080052class Rect;
53class Layer;
Chris Craik0776a602013-02-14 15:36:01 -080054
Chris Craikb565df12015-10-05 13:00:52 -070055struct RecordedOp;
56struct RenderNodeOp;
Chris Craik10ed6922015-10-15 10:55:15 -070057
58typedef RecordedOp BaseOpType;
59typedef RenderNodeOp NodeOpType;
Chris Craikff785832013-03-08 13:12:16 -080060
Doris Liu67ce99b2016-05-17 16:50:31 -070061namespace VectorDrawable {
62class Tree;
63};
64typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot;
65
John Reckcd1c3eb2016-04-14 10:38:54 -070066struct FunctorContainer {
67 Functor* functor;
68 GlFunctorLifecycleListener* listener;
69};
70
Doris Liu1d8e1942016-03-02 15:16:28 -080071/**
John Reck44fd8d22014-02-26 11:00:11 -080072 * Data structure that holds the list of commands used in display list stream
Chris Craik0776a602013-02-14 15:36:01 -080073 */
Chris Craik003cc3d2015-10-16 10:24:55 -070074class DisplayList {
Chris Craikb565df12015-10-05 13:00:52 -070075 friend class RecordingCanvas;
Chris Craik0776a602013-02-14 15:36:01 -080076public:
Chris Craik8afd0f22014-08-21 17:41:57 -070077 struct Chunk {
Chris Craik003cc3d2015-10-16 10:24:55 -070078 // range of included ops in DisplayList::ops()
Chris Craik8afd0f22014-08-21 17:41:57 -070079 size_t beginOpIndex;
80 size_t endOpIndex;
81
Chris Craik003cc3d2015-10-16 10:24:55 -070082 // range of included children in DisplayList::children()
Chris Craik8afd0f22014-08-21 17:41:57 -070083 size_t beginChildIndex;
84 size_t endChildIndex;
85
86 // whether children with non-zero Z in the chunk should be reordered
87 bool reorderChildren;
Chris Craik5e00c7c2016-07-06 16:10:09 -070088
89 // clip at the beginning of a reorder section, applied to reordered children
Chris Craikd6456402016-04-11 12:24:23 -070090 const ClipBase* reorderClip;
Chris Craik8afd0f22014-08-21 17:41:57 -070091 };
92
Chris Craik003cc3d2015-10-16 10:24:55 -070093 DisplayList();
Derek Sollenberger0df62092016-09-27 16:04:42 -040094 virtual ~DisplayList();
John Reck44fd8d22014-02-26 11:00:11 -080095
Chris Craik8d1f2122015-11-24 16:40:09 -080096 // index of DisplayListOp restore, after which projected descendants should be drawn
Chris Craik1df26442014-02-05 16:50:41 -080097 int projectionReceiveIndex;
John Reck44fd8d22014-02-26 11:00:11 -080098
Chris Craikb36af872015-10-16 14:23:12 -070099 const LsaVector<Chunk>& getChunks() const { return chunks; }
100 const LsaVector<BaseOpType*>& getOps() const { return ops; }
John Reck44fd8d22014-02-26 11:00:11 -0800101
Chris Craikb36af872015-10-16 14:23:12 -0700102 const LsaVector<NodeOpType*>& getChildren() const { return children; }
John Reck44fd8d22014-02-26 11:00:11 -0800103
Chris Craikb36af872015-10-16 14:23:12 -0700104 const LsaVector<const SkBitmap*>& getBitmapResources() const { return bitmapResources; }
John Reck44fd8d22014-02-26 11:00:11 -0800105
Chris Craik10ed6922015-10-15 10:55:15 -0700106 size_t addChild(NodeOpType* childOp);
Chris Craikb36af872015-10-16 14:23:12 -0700107
John Reck087bc0c2014-04-04 16:20:08 -0700108
John Reck0e89e2b2014-10-31 14:49:06 -0700109 void ref(VirtualLightRefBase* prop) {
Chris Craikb36af872015-10-16 14:23:12 -0700110 referenceHolders.push_back(prop);
John Reck52244ff2014-05-01 21:27:37 -0700111 }
112
Chris Craik8afd0f22014-08-21 17:41:57 -0700113 size_t getUsedSize() {
114 return allocator.usedSize();
115 }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400116
117 virtual bool isEmpty() const { return ops.empty(); }
118 virtual bool hasFunctor() const { return !functors.empty(); }
119 virtual bool hasVectorDrawables() const { return !vectorDrawables.empty(); }
120 virtual bool isSkiaDL() const { return false; }
121 virtual bool reuseDisplayList(RenderNode* node, renderthread::CanvasContext* context) {
122 return false;
Chris Craik8afd0f22014-08-21 17:41:57 -0700123 }
124
Derek Sollenberger0df62092016-09-27 16:04:42 -0400125 virtual void syncContents();
126 virtual void updateChildren(std::function<void(RenderNode*)> updateFn);
127 virtual bool prepareListAndChildren(TreeInfo& info, bool functorsNeedLayer,
128 std::function<void(RenderNode*, TreeInfo&, bool)> childFn);
129
130protected:
Chris Craikb36af872015-10-16 14:23:12 -0700131 // allocator into which all ops and LsaVector arrays allocated
Chris Craik8afd0f22014-08-21 17:41:57 -0700132 LinearAllocator allocator;
Chris Craikb36af872015-10-16 14:23:12 -0700133 LinearStdAllocator<void*> stdAllocator;
134
Derek Sollenberger0df62092016-09-27 16:04:42 -0400135private:
Chris Craikb36af872015-10-16 14:23:12 -0700136 LsaVector<Chunk> chunks;
137 LsaVector<BaseOpType*> ops;
138
139 // list of Ops referring to RenderNode children for quick, non-drawing traversal
140 LsaVector<NodeOpType*> children;
141
142 // Resources - Skia objects + 9 patches referred to by this DisplayList
143 LsaVector<const SkBitmap*> bitmapResources;
144 LsaVector<const SkPath*> pathResources;
145 LsaVector<const Res_png_9patch*> patchResources;
146 LsaVector<std::unique_ptr<const SkPaint>> paints;
147 LsaVector<std::unique_ptr<const SkRegion>> regions;
148 LsaVector< sp<VirtualLightRefBase> > referenceHolders;
149
150 // List of functors
John Reckcd1c3eb2016-04-14 10:38:54 -0700151 LsaVector<FunctorContainer> functors;
Chris Craikb36af872015-10-16 14:23:12 -0700152
Doris Liu67ce99b2016-05-17 16:50:31 -0700153 // List of VectorDrawables that need to be notified of pushStaging. Note that this list gets nothing
Doris Liu1d8e1942016-03-02 15:16:28 -0800154 // but a callback during sync DisplayList, unlike the list of functors defined above, which
155 // gets special treatment exclusive for webview.
Doris Liu67ce99b2016-05-17 16:50:31 -0700156 LsaVector<VectorDrawableRoot*> vectorDrawables;
Doris Liu1d8e1942016-03-02 15:16:28 -0800157
John Reck44fd8d22014-02-26 11:00:11 -0800158 void cleanupResources();
Chris Craik0776a602013-02-14 15:36:01 -0800159};
160
Chris Craik0776a602013-02-14 15:36:01 -0800161}; // namespace uirenderer
162}; // namespace android