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 | |
| 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 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 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 35 | #include "Debug.h" |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 36 | #include "CanvasProperty.h" |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 37 | #include "DeferredDisplayList.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" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 40 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 41 | #include <vector> |
| 42 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 43 | class SkBitmap; |
| 44 | class SkPaint; |
| 45 | class SkPath; |
| 46 | class SkRegion; |
| 47 | |
| 48 | namespace android { |
| 49 | namespace uirenderer { |
| 50 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 51 | class DeferredDisplayList; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 52 | class DisplayListOp; |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 53 | class DisplayListCanvas; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 54 | class OpenGLRenderer; |
| 55 | class Rect; |
| 56 | class Layer; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 57 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 58 | #if HWUI_NEW_OPS |
| 59 | struct RecordedOp; |
| 60 | struct RenderNodeOp; |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 61 | |
| 62 | typedef RecordedOp BaseOpType; |
| 63 | typedef RenderNodeOp NodeOpType; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 64 | #else |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 65 | class DrawRenderNodeOp; |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 66 | |
| 67 | typedef DisplayListOp BaseOpType; |
| 68 | typedef DrawRenderNodeOp NodeOpType; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 69 | #endif |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 70 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 71 | /** |
| 72 | * Holds data used in the playback a tree of DisplayLists. |
| 73 | */ |
Chris Craik | 07adacf | 2014-12-19 10:08:40 -0800 | [diff] [blame] | 74 | struct PlaybackStateStruct { |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 75 | protected: |
| 76 | PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator) |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 77 | : mRenderer(renderer) |
| 78 | , mReplayFlags(replayFlags) |
| 79 | , mAllocator(allocator) {} |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 80 | |
| 81 | public: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 82 | OpenGLRenderer& mRenderer; |
| 83 | const int mReplayFlags; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 84 | |
Chris Craik | 4ac36f8 | 2014-12-09 16:54:03 -0800 | [diff] [blame] | 85 | // 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 Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 88 | LinearAllocator * const mAllocator; |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 89 | |
| 90 | SkPath* allocPathForFrame() { |
Chris Craik | 4ac36f8 | 2014-12-09 16:54:03 -0800 | [diff] [blame] | 91 | return mRenderer.allocPathForFrame(); |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 92 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
Andreas Gampe | edaecc1 | 2014-11-10 20:54:07 -0800 | [diff] [blame] | 95 | struct DeferStateStruct : public PlaybackStateStruct { |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 96 | DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags) |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 97 | : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)), |
| 98 | mDeferredList(deferredList) {} |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 99 | |
| 100 | DeferredDisplayList& mDeferredList; |
| 101 | }; |
| 102 | |
Chris Craik | 07adacf | 2014-12-19 10:08:40 -0800 | [diff] [blame] | 103 | struct ReplayStateStruct : public PlaybackStateStruct { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 104 | ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags) |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 105 | : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator), |
Tom Hudson | 107843d | 2014-09-08 11:26:26 -0400 | [diff] [blame] | 106 | mDirty(dirty) {} |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 107 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 108 | Rect& mDirty; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 109 | LinearAllocator mReplayAllocator; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 110 | }; |
| 111 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 112 | /** |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 113 | * Functor that can be used for objects with data in both UI thread and RT to keep the data |
| 114 | * in sync. This functor, when added to DisplayList, will be call during DisplayList sync. |
| 115 | */ |
| 116 | struct PushStagingFunctor { |
| 117 | PushStagingFunctor() {} |
| 118 | virtual ~PushStagingFunctor() {} |
| 119 | virtual void operator ()() {} |
| 120 | }; |
| 121 | |
| 122 | /** |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 123 | * 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] | 124 | */ |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 125 | class DisplayList { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 126 | friend class DisplayListCanvas; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 127 | friend class RecordingCanvas; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 128 | public: |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 129 | struct Chunk { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 130 | // range of included ops in DisplayList::ops() |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 131 | size_t beginOpIndex; |
| 132 | size_t endOpIndex; |
| 133 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 134 | // range of included children in DisplayList::children() |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 135 | size_t beginChildIndex; |
| 136 | size_t endChildIndex; |
| 137 | |
| 138 | // whether children with non-zero Z in the chunk should be reordered |
| 139 | bool reorderChildren; |
| 140 | }; |
| 141 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 142 | DisplayList(); |
| 143 | ~DisplayList(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 144 | |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 145 | // index of DisplayListOp restore, after which projected descendants should be drawn |
Chris Craik | 1df2644 | 2014-02-05 16:50:41 -0800 | [diff] [blame] | 146 | int projectionReceiveIndex; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 147 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 148 | const LsaVector<Chunk>& getChunks() const { return chunks; } |
| 149 | const LsaVector<BaseOpType*>& getOps() const { return ops; } |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 150 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 151 | const LsaVector<NodeOpType*>& getChildren() const { return children; } |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 152 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 153 | const LsaVector<const SkBitmap*>& getBitmapResources() const { return bitmapResources; } |
| 154 | const LsaVector<Functor*>& getFunctors() const { return functors; } |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 155 | const LsaVector<PushStagingFunctor*>& getPushStagingFunctors() { return pushStagingFunctors; } |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 156 | |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 157 | size_t addChild(NodeOpType* childOp); |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 158 | |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 159 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 160 | void ref(VirtualLightRefBase* prop) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 161 | referenceHolders.push_back(prop); |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 164 | size_t getUsedSize() { |
| 165 | return allocator.usedSize(); |
| 166 | } |
| 167 | bool isEmpty() { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 168 | #if HWUI_NEW_OPS |
| 169 | return ops.empty(); |
| 170 | #else |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 171 | return !hasDrawOps; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 172 | #endif |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 173 | } |
| 174 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 175 | private: |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 176 | // allocator into which all ops and LsaVector arrays allocated |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 177 | LinearAllocator allocator; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 178 | LinearStdAllocator<void*> stdAllocator; |
| 179 | |
| 180 | LsaVector<Chunk> chunks; |
| 181 | LsaVector<BaseOpType*> ops; |
| 182 | |
| 183 | // list of Ops referring to RenderNode children for quick, non-drawing traversal |
| 184 | LsaVector<NodeOpType*> children; |
| 185 | |
| 186 | // Resources - Skia objects + 9 patches referred to by this DisplayList |
| 187 | LsaVector<const SkBitmap*> bitmapResources; |
| 188 | LsaVector<const SkPath*> pathResources; |
| 189 | LsaVector<const Res_png_9patch*> patchResources; |
| 190 | LsaVector<std::unique_ptr<const SkPaint>> paints; |
| 191 | LsaVector<std::unique_ptr<const SkRegion>> regions; |
| 192 | LsaVector< sp<VirtualLightRefBase> > referenceHolders; |
| 193 | |
| 194 | // List of functors |
| 195 | LsaVector<Functor*> functors; |
| 196 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 197 | // List of functors that need to be notified of pushStaging. Note that this list gets nothing |
| 198 | // but a callback during sync DisplayList, unlike the list of functors defined above, which |
| 199 | // gets special treatment exclusive for webview. |
| 200 | LsaVector<PushStagingFunctor*> pushStagingFunctors; |
| 201 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 202 | bool hasDrawOps; // only used if !HWUI_NEW_OPS |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 203 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 204 | void cleanupResources(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 205 | }; |
| 206 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 207 | }; // namespace uirenderer |
| 208 | }; // namespace android |
| 209 | |
| 210 | #endif // ANDROID_HWUI_OPENGL_RENDERER_H |