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> |
| 30 | #include <utils/Vector.h> |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 31 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 32 | #include <cutils/compiler.h> |
| 33 | |
Romain Guy | e3b0a01 | 2013-06-26 15:45:41 -0700 | [diff] [blame] | 34 | #include <androidfw/ResourceTypes.h> |
| 35 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 36 | #include "Debug.h" |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 37 | #include "CanvasProperty.h" |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 38 | #include "DeferredDisplayList.h" |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 39 | #include "Matrix.h" |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 40 | #include "RenderProperties.h" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 41 | |
| 42 | class SkBitmap; |
| 43 | class SkPaint; |
| 44 | class SkPath; |
| 45 | class SkRegion; |
| 46 | |
| 47 | namespace android { |
| 48 | namespace uirenderer { |
| 49 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 50 | class DeferredDisplayList; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 51 | class DisplayListOp; |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 52 | class DisplayListCanvas; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 53 | class OpenGLRenderer; |
| 54 | class Rect; |
| 55 | class Layer; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 56 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 57 | class ClipRectOp; |
| 58 | class SaveLayerOp; |
| 59 | class SaveOp; |
| 60 | class RestoreToCountOp; |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 61 | class DrawRenderNodeOp; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 62 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 63 | /** |
| 64 | * Holds data used in the playback a tree of DisplayLists. |
| 65 | */ |
Chris Craik | 07adacf | 2014-12-19 10:08:40 -0800 | [diff] [blame] | 66 | struct PlaybackStateStruct { |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 67 | protected: |
| 68 | PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator) |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 69 | : mRenderer(renderer) |
| 70 | , mReplayFlags(replayFlags) |
| 71 | , mAllocator(allocator) {} |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 72 | |
| 73 | public: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 74 | OpenGLRenderer& mRenderer; |
| 75 | const int mReplayFlags; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 76 | |
Chris Craik | 4ac36f8 | 2014-12-09 16:54:03 -0800 | [diff] [blame] | 77 | // Allocator with the lifetime of a single frame. replay uses an Allocator owned by the struct, |
| 78 | // while defer shares the DeferredDisplayList's Allocator |
| 79 | // 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] | 80 | LinearAllocator * const mAllocator; |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 81 | |
| 82 | SkPath* allocPathForFrame() { |
Chris Craik | 4ac36f8 | 2014-12-09 16:54:03 -0800 | [diff] [blame] | 83 | return mRenderer.allocPathForFrame(); |
Chris Craik | 7466986 | 2014-08-07 17:27:30 -0700 | [diff] [blame] | 84 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
Andreas Gampe | edaecc1 | 2014-11-10 20:54:07 -0800 | [diff] [blame] | 87 | struct DeferStateStruct : public PlaybackStateStruct { |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 88 | DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags) |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 89 | : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)), |
| 90 | mDeferredList(deferredList) {} |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 91 | |
| 92 | DeferredDisplayList& mDeferredList; |
| 93 | }; |
| 94 | |
Chris Craik | 07adacf | 2014-12-19 10:08:40 -0800 | [diff] [blame] | 95 | struct ReplayStateStruct : public PlaybackStateStruct { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 96 | ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags) |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 97 | : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator), |
Tom Hudson | 107843d | 2014-09-08 11:26:26 -0400 | [diff] [blame] | 98 | mDirty(dirty) {} |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 99 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 100 | Rect& mDirty; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 101 | LinearAllocator mReplayAllocator; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 104 | /** |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 105 | * 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] | 106 | */ |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 107 | class DisplayListData { |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 108 | friend class DisplayListCanvas; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 109 | public: |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 110 | struct Chunk { |
| 111 | // range of included ops in DLD::displayListOps |
| 112 | size_t beginOpIndex; |
| 113 | size_t endOpIndex; |
| 114 | |
| 115 | // range of included children in DLD::mChildren |
| 116 | size_t beginChildIndex; |
| 117 | size_t endChildIndex; |
| 118 | |
| 119 | // whether children with non-zero Z in the chunk should be reordered |
| 120 | bool reorderChildren; |
| 121 | }; |
| 122 | |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 123 | DisplayListData(); |
| 124 | ~DisplayListData(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 125 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 126 | // pointers to all ops within display list, pointing into allocator data |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 127 | Vector<DisplayListOp*> displayListOps; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 128 | |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 129 | // index of DisplayListOp restore, after which projected descendents should be drawn |
Chris Craik | 1df2644 | 2014-02-05 16:50:41 -0800 | [diff] [blame] | 130 | int projectionReceiveIndex; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 131 | |
| 132 | Vector<const SkBitmap*> bitmapResources; |
Derek Sollenberger | ee24859 | 2015-02-12 14:10:21 -0500 | [diff] [blame] | 133 | Vector<const SkPath*> pathResources; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 134 | Vector<const Res_png_9patch*> patchResources; |
| 135 | |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 136 | std::vector<std::unique_ptr<const SkPaint>> paints; |
| 137 | std::vector<std::unique_ptr<const SkRegion>> regions; |
John Reck | 09d5cdd | 2014-07-24 10:36:08 -0700 | [diff] [blame] | 138 | Vector<Functor*> functors; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 139 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 140 | const Vector<Chunk>& getChunks() const { |
| 141 | return chunks; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 144 | size_t addChild(DrawRenderNodeOp* childOp); |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 145 | const Vector<DrawRenderNodeOp*>& children() { return mChildren; } |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 146 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 147 | void ref(VirtualLightRefBase* prop) { |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 148 | mReferenceHolders.push(prop); |
| 149 | } |
| 150 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 151 | size_t getUsedSize() { |
| 152 | return allocator.usedSize(); |
| 153 | } |
| 154 | bool isEmpty() { |
| 155 | return !hasDrawOps; |
| 156 | } |
| 157 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 158 | private: |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 159 | Vector< sp<VirtualLightRefBase> > mReferenceHolders; |
| 160 | |
| 161 | // list of children display lists for quick, non-drawing traversal |
Chris Craik | a7090e0 | 2014-06-20 16:01:00 -0700 | [diff] [blame] | 162 | Vector<DrawRenderNodeOp*> mChildren; |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 163 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 164 | Vector<Chunk> chunks; |
| 165 | |
| 166 | // allocator into which all ops were allocated |
| 167 | LinearAllocator allocator; |
| 168 | bool hasDrawOps; |
| 169 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 170 | void cleanupResources(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 171 | }; |
| 172 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 173 | }; // namespace uirenderer |
| 174 | }; // namespace android |
| 175 | |
| 176 | #endif // ANDROID_HWUI_OPENGL_RENDERER_H |