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