blob: 0cfc3b701affc0e63da6d62539ee197a8b3427d5 [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
Tom Hudson2dc236b2014-10-15 15:46:42 -040035#include "CanvasProperty.h"
John Reck1bcacfd2017-11-03 10:12:19 -070036#include "Debug.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"
sergeyvec4a4b12016-10-20 18:39:04 -070041#include "hwui/Bitmap.h"
Chris Craik0776a602013-02-14 15:36:01 -080042
John Reck272a6852015-07-29 16:48:58 -070043#include <vector>
44
Chris Craik0776a602013-02-14 15:36:01 -080045class SkBitmap;
46class SkPaint;
47class SkPath;
48class SkRegion;
49
50namespace android {
51namespace uirenderer {
52
Chris Craik0776a602013-02-14 15:36:01 -080053class Rect;
54class Layer;
Chris Craik0776a602013-02-14 15:36:01 -080055
Chris Craikb565df12015-10-05 13:00:52 -070056struct RecordedOp;
57struct RenderNodeOp;
Chris Craik10ed6922015-10-15 10:55:15 -070058
59typedef RecordedOp BaseOpType;
60typedef RenderNodeOp NodeOpType;
Chris Craikff785832013-03-08 13:12:16 -080061
Doris Liu67ce99b2016-05-17 16:50:31 -070062namespace VectorDrawable {
63class Tree;
64};
65typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot;
66
John Reckcd1c3eb2016-04-14 10:38:54 -070067struct FunctorContainer {
68 Functor* functor;
69 GlFunctorLifecycleListener* listener;
70};
71
Doris Liu1d8e1942016-03-02 15:16:28 -080072/**
John Reck44fd8d22014-02-26 11:00:11 -080073 * Data structure that holds the list of commands used in display list stream
Chris Craik0776a602013-02-14 15:36:01 -080074 */
Chris Craik003cc3d2015-10-16 10:24:55 -070075class DisplayList {
Chris Craikb565df12015-10-05 13:00:52 -070076 friend class RecordingCanvas;
John Reck1bcacfd2017-11-03 10:12:19 -070077
Chris Craik0776a602013-02-14 15:36:01 -080078public:
Chris Craik8afd0f22014-08-21 17:41:57 -070079 struct Chunk {
Chris Craik003cc3d2015-10-16 10:24:55 -070080 // range of included ops in DisplayList::ops()
Chris Craik8afd0f22014-08-21 17:41:57 -070081 size_t beginOpIndex;
82 size_t endOpIndex;
83
Chris Craik003cc3d2015-10-16 10:24:55 -070084 // range of included children in DisplayList::children()
Chris Craik8afd0f22014-08-21 17:41:57 -070085 size_t beginChildIndex;
86 size_t endChildIndex;
87
88 // whether children with non-zero Z in the chunk should be reordered
89 bool reorderChildren;
Chris Craik5e00c7c2016-07-06 16:10:09 -070090
91 // clip at the beginning of a reorder section, applied to reordered children
Chris Craikd6456402016-04-11 12:24:23 -070092 const ClipBase* reorderClip;
Chris Craik8afd0f22014-08-21 17:41:57 -070093 };
94
Chris Craik003cc3d2015-10-16 10:24:55 -070095 DisplayList();
Derek Sollenberger0df62092016-09-27 16:04:42 -040096 virtual ~DisplayList();
John Reck44fd8d22014-02-26 11:00:11 -080097
Chris Craik8d1f2122015-11-24 16:40:09 -080098 // index of DisplayListOp restore, after which projected descendants should be drawn
Chris Craik1df26442014-02-05 16:50:41 -080099 int projectionReceiveIndex;
John Reck44fd8d22014-02-26 11:00:11 -0800100
Chris Craikb36af872015-10-16 14:23:12 -0700101 const LsaVector<Chunk>& getChunks() const { return chunks; }
102 const LsaVector<BaseOpType*>& getOps() const { return ops; }
John Reck44fd8d22014-02-26 11:00:11 -0800103
Chris Craikb36af872015-10-16 14:23:12 -0700104 const LsaVector<NodeOpType*>& getChildren() const { return children; }
John Reck44fd8d22014-02-26 11:00:11 -0800105
sergeyvec4a4b12016-10-20 18:39:04 -0700106 const LsaVector<sk_sp<Bitmap>>& getBitmapResources() const { return bitmapResources; }
John Reck44fd8d22014-02-26 11:00:11 -0800107
Chris Craik10ed6922015-10-15 10:55:15 -0700108 size_t addChild(NodeOpType* childOp);
Chris Craikb36af872015-10-16 14:23:12 -0700109
John Reck1bcacfd2017-11-03 10:12:19 -0700110 void ref(VirtualLightRefBase* prop) { referenceHolders.push_back(prop); }
John Reck087bc0c2014-04-04 16:20:08 -0700111
John Reck1bcacfd2017-11-03 10:12:19 -0700112 size_t getUsedSize() { return allocator.usedSize(); }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400113
114 virtual bool isEmpty() const { return ops.empty(); }
115 virtual bool hasFunctor() const { return !functors.empty(); }
116 virtual bool hasVectorDrawables() const { return !vectorDrawables.empty(); }
117 virtual bool isSkiaDL() const { return false; }
118 virtual bool reuseDisplayList(RenderNode* node, renderthread::CanvasContext* context) {
119 return false;
Chris Craik8afd0f22014-08-21 17:41:57 -0700120 }
121
Derek Sollenberger0df62092016-09-27 16:04:42 -0400122 virtual void syncContents();
123 virtual void updateChildren(std::function<void(RenderNode*)> updateFn);
John Reck1bcacfd2017-11-03 10:12:19 -0700124 virtual bool prepareListAndChildren(
125 TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer,
John Reck2de950d2017-01-25 10:58:30 -0800126 std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn);
Derek Sollenberger0df62092016-09-27 16:04:42 -0400127
Stan Ilievd2172372017-02-09 16:59:27 -0500128 virtual void output(std::ostream& output, uint32_t level);
129
Derek Sollenberger0df62092016-09-27 16:04:42 -0400130protected:
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
sergeyvec4a4b12016-10-20 18:39:04 -0700143 LsaVector<sk_sp<Bitmap>> bitmapResources;
Chris Craikb36af872015-10-16 14:23:12 -0700144 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;
John Reck1bcacfd2017-11-03 10:12:19 -0700148 LsaVector<sp<VirtualLightRefBase>> referenceHolders;
Chris Craikb36af872015-10-16 14:23:12 -0700149
150 // List of functors
John Reckcd1c3eb2016-04-14 10:38:54 -0700151 LsaVector<FunctorContainer> functors;
Chris Craikb36af872015-10-16 14:23:12 -0700152
John Reck1bcacfd2017-11-03 10:12:19 -0700153 // List of VectorDrawables that need to be notified of pushStaging. Note that this list gets
154 // nothing
Doris Liu1d8e1942016-03-02 15:16:28 -0800155 // but a callback during sync DisplayList, unlike the list of functors defined above, which
156 // gets special treatment exclusive for webview.
Doris Liu67ce99b2016-05-17 16:50:31 -0700157 LsaVector<VectorDrawableRoot*> vectorDrawables;
Doris Liu1d8e1942016-03-02 15:16:28 -0800158
John Reck44fd8d22014-02-26 11:00:11 -0800159 void cleanupResources();
Chris Craik0776a602013-02-14 15:36:01 -0800160};
161
John Reck1bcacfd2017-11-03 10:12:19 -0700162}; // namespace uirenderer
163}; // namespace android