blob: d22a764c0ea58b92b6473554340f7e060711dd68 [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"
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;
Chris Craik0776a602013-02-14 15:36:01 -080077public:
Chris Craik8afd0f22014-08-21 17:41:57 -070078 struct Chunk {
Chris Craik003cc3d2015-10-16 10:24:55 -070079 // range of included ops in DisplayList::ops()
Chris Craik8afd0f22014-08-21 17:41:57 -070080 size_t beginOpIndex;
81 size_t endOpIndex;
82
Chris Craik003cc3d2015-10-16 10:24:55 -070083 // range of included children in DisplayList::children()
Chris Craik8afd0f22014-08-21 17:41:57 -070084 size_t beginChildIndex;
85 size_t endChildIndex;
86
87 // whether children with non-zero Z in the chunk should be reordered
88 bool reorderChildren;
Chris Craik5e00c7c2016-07-06 16:10:09 -070089
90 // clip at the beginning of a reorder section, applied to reordered children
Chris Craikd6456402016-04-11 12:24:23 -070091 const ClipBase* reorderClip;
Chris Craik8afd0f22014-08-21 17:41:57 -070092 };
93
Chris Craik003cc3d2015-10-16 10:24:55 -070094 DisplayList();
Derek Sollenberger0df62092016-09-27 16:04:42 -040095 virtual ~DisplayList();
John Reck44fd8d22014-02-26 11:00:11 -080096
Chris Craik8d1f2122015-11-24 16:40:09 -080097 // index of DisplayListOp restore, after which projected descendants should be drawn
Chris Craik1df26442014-02-05 16:50:41 -080098 int projectionReceiveIndex;
John Reck44fd8d22014-02-26 11:00:11 -080099
Chris Craikb36af872015-10-16 14:23:12 -0700100 const LsaVector<Chunk>& getChunks() const { return chunks; }
101 const LsaVector<BaseOpType*>& getOps() const { return ops; }
John Reck44fd8d22014-02-26 11:00:11 -0800102
Chris Craikb36af872015-10-16 14:23:12 -0700103 const LsaVector<NodeOpType*>& getChildren() const { return children; }
John Reck44fd8d22014-02-26 11:00:11 -0800104
sergeyvec4a4b12016-10-20 18:39:04 -0700105 const LsaVector<sk_sp<Bitmap>>& getBitmapResources() const { return bitmapResources; }
John Reck44fd8d22014-02-26 11:00:11 -0800106
Chris Craik10ed6922015-10-15 10:55:15 -0700107 size_t addChild(NodeOpType* childOp);
Chris Craikb36af872015-10-16 14:23:12 -0700108
John Reck087bc0c2014-04-04 16:20:08 -0700109
John Reck0e89e2b2014-10-31 14:49:06 -0700110 void ref(VirtualLightRefBase* prop) {
Chris Craikb36af872015-10-16 14:23:12 -0700111 referenceHolders.push_back(prop);
John Reck52244ff2014-05-01 21:27:37 -0700112 }
113
Chris Craik8afd0f22014-08-21 17:41:57 -0700114 size_t getUsedSize() {
115 return allocator.usedSize();
116 }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400117
118 virtual bool isEmpty() const { return ops.empty(); }
119 virtual bool hasFunctor() const { return !functors.empty(); }
120 virtual bool hasVectorDrawables() const { return !vectorDrawables.empty(); }
121 virtual bool isSkiaDL() const { return false; }
122 virtual bool reuseDisplayList(RenderNode* node, renderthread::CanvasContext* context) {
123 return false;
Chris Craik8afd0f22014-08-21 17:41:57 -0700124 }
125
Derek Sollenberger0df62092016-09-27 16:04:42 -0400126 virtual void syncContents();
127 virtual void updateChildren(std::function<void(RenderNode*)> updateFn);
John Reck2de950d2017-01-25 10:58:30 -0800128 virtual bool prepareListAndChildren(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer,
129 std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn);
Derek Sollenberger0df62092016-09-27 16:04:42 -0400130
Stan Ilievd2172372017-02-09 16:59:27 -0500131 virtual void output(std::ostream& output, uint32_t level);
132
Derek Sollenberger0df62092016-09-27 16:04:42 -0400133protected:
Chris Craikb36af872015-10-16 14:23:12 -0700134 // allocator into which all ops and LsaVector arrays allocated
Chris Craik8afd0f22014-08-21 17:41:57 -0700135 LinearAllocator allocator;
Chris Craikb36af872015-10-16 14:23:12 -0700136 LinearStdAllocator<void*> stdAllocator;
137
Derek Sollenberger0df62092016-09-27 16:04:42 -0400138private:
Chris Craikb36af872015-10-16 14:23:12 -0700139 LsaVector<Chunk> chunks;
140 LsaVector<BaseOpType*> ops;
141
142 // list of Ops referring to RenderNode children for quick, non-drawing traversal
143 LsaVector<NodeOpType*> children;
144
145 // Resources - Skia objects + 9 patches referred to by this DisplayList
sergeyvec4a4b12016-10-20 18:39:04 -0700146 LsaVector<sk_sp<Bitmap>> bitmapResources;
Chris Craikb36af872015-10-16 14:23:12 -0700147 LsaVector<const SkPath*> pathResources;
148 LsaVector<const Res_png_9patch*> patchResources;
149 LsaVector<std::unique_ptr<const SkPaint>> paints;
150 LsaVector<std::unique_ptr<const SkRegion>> regions;
151 LsaVector< sp<VirtualLightRefBase> > referenceHolders;
152
153 // List of functors
John Reckcd1c3eb2016-04-14 10:38:54 -0700154 LsaVector<FunctorContainer> functors;
Chris Craikb36af872015-10-16 14:23:12 -0700155
Doris Liu67ce99b2016-05-17 16:50:31 -0700156 // List of VectorDrawables that need to be notified of pushStaging. Note that this list gets nothing
Doris Liu1d8e1942016-03-02 15:16:28 -0800157 // but a callback during sync DisplayList, unlike the list of functors defined above, which
158 // gets special treatment exclusive for webview.
Doris Liu67ce99b2016-05-17 16:50:31 -0700159 LsaVector<VectorDrawableRoot*> vectorDrawables;
Doris Liu1d8e1942016-03-02 15:16:28 -0800160
John Reck44fd8d22014-02-26 11:00:11 -0800161 void cleanupResources();
Chris Craik0776a602013-02-14 15:36:01 -0800162};
163
Chris Craik0776a602013-02-14 15:36:01 -0800164}; // namespace uirenderer
165}; // namespace android