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 | /** |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 113 | * 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] | 114 | */ |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 115 | class DisplayList { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 116 | friend class DisplayListCanvas; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 117 | friend class RecordingCanvas; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 118 | public: |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 119 | struct Chunk { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 120 | // range of included ops in DisplayList::ops() |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 121 | size_t beginOpIndex; |
| 122 | size_t endOpIndex; |
| 123 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 124 | // range of included children in DisplayList::children() |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 125 | size_t beginChildIndex; |
| 126 | size_t endChildIndex; |
| 127 | |
| 128 | // whether children with non-zero Z in the chunk should be reordered |
| 129 | bool reorderChildren; |
| 130 | }; |
| 131 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 132 | DisplayList(); |
| 133 | ~DisplayList(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 134 | |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 135 | // index of DisplayListOp restore, after which projected descendents should be drawn |
Chris Craik | 1df2644 | 2014-02-05 16:50:41 -0800 | [diff] [blame] | 136 | int projectionReceiveIndex; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 137 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 138 | const LsaVector<Chunk>& getChunks() const { return chunks; } |
| 139 | const LsaVector<BaseOpType*>& getOps() const { return ops; } |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 140 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 141 | const LsaVector<NodeOpType*>& getChildren() const { return children; } |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 142 | |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 143 | const LsaVector<const SkBitmap*>& getBitmapResources() const { return bitmapResources; } |
| 144 | const LsaVector<Functor*>& getFunctors() const { return functors; } |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 145 | |
Chris Craik | 10ed692 | 2015-10-15 10:55:15 -0700 | [diff] [blame] | 146 | size_t addChild(NodeOpType* childOp); |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 147 | |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 148 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 149 | void ref(VirtualLightRefBase* prop) { |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 150 | referenceHolders.push_back(prop); |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 153 | size_t getUsedSize() { |
| 154 | return allocator.usedSize(); |
| 155 | } |
| 156 | bool isEmpty() { |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 157 | #if HWUI_NEW_OPS |
| 158 | return ops.empty(); |
| 159 | #else |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 160 | return !hasDrawOps; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 161 | #endif |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 162 | } |
| 163 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 164 | private: |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 165 | // allocator into which all ops and LsaVector arrays allocated |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 166 | LinearAllocator allocator; |
Chris Craik | b36af87 | 2015-10-16 14:23:12 -0700 | [diff] [blame] | 167 | LinearStdAllocator<void*> stdAllocator; |
| 168 | |
| 169 | LsaVector<Chunk> chunks; |
| 170 | LsaVector<BaseOpType*> ops; |
| 171 | |
| 172 | // list of Ops referring to RenderNode children for quick, non-drawing traversal |
| 173 | LsaVector<NodeOpType*> children; |
| 174 | |
| 175 | // Resources - Skia objects + 9 patches referred to by this DisplayList |
| 176 | LsaVector<const SkBitmap*> bitmapResources; |
| 177 | LsaVector<const SkPath*> pathResources; |
| 178 | LsaVector<const Res_png_9patch*> patchResources; |
| 179 | LsaVector<std::unique_ptr<const SkPaint>> paints; |
| 180 | LsaVector<std::unique_ptr<const SkRegion>> regions; |
| 181 | LsaVector< sp<VirtualLightRefBase> > referenceHolders; |
| 182 | |
| 183 | // List of functors |
| 184 | LsaVector<Functor*> functors; |
| 185 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 186 | bool hasDrawOps; // only used if !HWUI_NEW_OPS |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 187 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 188 | void cleanupResources(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 189 | }; |
| 190 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 191 | }; // namespace uirenderer |
| 192 | }; // namespace android |
| 193 | |
| 194 | #endif // ANDROID_HWUI_OPENGL_RENDERER_H |