Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 1 | /* |
| 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 Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 17 | #pragma once |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 18 | |
| 19 | #include <SkCamera.h> |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 20 | #include <SkDrawable.h> |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 21 | #include <SkMatrix.h> |
| 22 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 23 | #include <private/hwui/DrawGlInfo.h> |
| 24 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 25 | #include <utils/KeyedVector.h> |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 26 | #include <utils/LinearAllocator.h> |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 27 | #include <utils/RefBase.h> |
| 28 | #include <utils/SortedVector.h> |
| 29 | #include <utils/String8.h> |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 30 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 31 | #include <cutils/compiler.h> |
| 32 | |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 33 | #include <androidfw/ResourceTypes.h> |
| 34 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 35 | #include "CanvasProperty.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 36 | #include "Debug.h" |
John Reck | cd1c3eb | 2016-04-14 10:38:54 -0700 | [diff] [blame] | 37 | #include "GlFunctorLifecycleListener.h" |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 38 | #include "Matrix.h" |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 39 | #include "RenderProperties.h" |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 40 | #include "TreeInfo.h" |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 41 | #include "hwui/Bitmap.h" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 42 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 43 | #include <vector> |
| 44 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 45 | class SkBitmap; |
| 46 | class SkPaint; |
| 47 | class SkPath; |
| 48 | class SkRegion; |
| 49 | |
| 50 | namespace android { |
| 51 | namespace uirenderer { |
| 52 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 53 | class Rect; |
| 54 | class Layer; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 55 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 56 | struct RecordedOp; |
| 57 | struct RenderNodeOp; |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 58 | |
| 59 | typedef RecordedOp BaseOpType; |
| 60 | typedef RenderNodeOp NodeOpType; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 61 | |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 62 | namespace VectorDrawable { |
| 63 | class Tree; |
| 64 | }; |
| 65 | typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot; |
| 66 | |
John Reck | cd1c3eb | 2016-04-14 10:38:54 -0700 | [diff] [blame] | 67 | struct FunctorContainer { |
| 68 | Functor* functor; |
| 69 | GlFunctorLifecycleListener* listener; |
| 70 | }; |
| 71 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 72 | /** |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 73 | * Data structure that holds the list of commands used in display list stream |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 74 | */ |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 75 | class DisplayList { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 76 | friend class RecordingCanvas; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 77 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 78 | public: |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 79 | struct Chunk { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 80 | // range of included ops in DisplayList::ops() |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 81 | size_t beginOpIndex; |
| 82 | size_t endOpIndex; |
| 83 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 84 | // range of included children in DisplayList::children() |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 85 | 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 Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 90 | |
| 91 | // clip at the beginning of a reorder section, applied to reordered children |
Chris Craik | d645640 | 2016-04-11 12:24:23 -0700 | [diff] [blame] | 92 | const ClipBase* reorderClip; |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 95 | DisplayList(); |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 96 | virtual ~DisplayList(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 97 | |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 98 | // index of DisplayListOp restore, after which projected descendants should be drawn |
Chris Craik | 1df2644 | 2014-02-05 16:50:41 -0800 | [diff] [blame] | 99 | int projectionReceiveIndex; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 100 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 101 | const LsaVector<Chunk>& getChunks() const { return chunks; } |
| 102 | const LsaVector<BaseOpType*>& getOps() const { return ops; } |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 103 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 104 | const LsaVector<NodeOpType*>& getChildren() const { return children; } |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 105 | |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 106 | const LsaVector<sk_sp<Bitmap>>& getBitmapResources() const { return bitmapResources; } |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 107 | |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 108 | size_t addChild(NodeOpType* childOp); |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 109 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 110 | void ref(VirtualLightRefBase* prop) { referenceHolders.push_back(prop); } |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 111 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 112 | size_t getUsedSize() { return allocator.usedSize(); } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 113 | |
| 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 Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 122 | virtual void syncContents(); |
| 123 | virtual void updateChildren(std::function<void(RenderNode*)> updateFn); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 124 | virtual bool prepareListAndChildren( |
| 125 | TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer, |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 126 | std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn); |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 127 | |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 128 | virtual void output(std::ostream& output, uint32_t level); |
| 129 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 130 | protected: |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 131 | // allocator into which all ops and LsaVector arrays allocated |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 132 | LinearAllocator allocator; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 133 | LinearStdAllocator<void*> stdAllocator; |
| 134 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 135 | private: |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 136 | 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 |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 143 | LsaVector<sk_sp<Bitmap>> bitmapResources; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 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; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 148 | LsaVector<sp<VirtualLightRefBase>> referenceHolders; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 149 | |
| 150 | // List of functors |
John Reck | cd1c3eb | 2016-04-14 10:38:54 -0700 | [diff] [blame] | 151 | LsaVector<FunctorContainer> functors; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 152 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 153 | // List of VectorDrawables that need to be notified of pushStaging. Note that this list gets |
| 154 | // nothing |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 155 | // but a callback during sync DisplayList, unlike the list of functors defined above, which |
| 156 | // gets special treatment exclusive for webview. |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 157 | LsaVector<VectorDrawableRoot*> vectorDrawables; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 158 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 159 | void cleanupResources(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 160 | }; |
| 161 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 162 | }; // namespace uirenderer |
| 163 | }; // namespace android |