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" |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 41 | #include "Matrix.h" |
| 42 | #include "DeferredDisplayList.h" |
John Reck | acb6f07 | 2014-03-12 16:11:23 -0700 | [diff] [blame] | 43 | #include "RenderProperties.h" |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 44 | |
| 45 | class SkBitmap; |
| 46 | class SkPaint; |
| 47 | class SkPath; |
| 48 | class SkRegion; |
| 49 | |
| 50 | namespace android { |
| 51 | namespace uirenderer { |
| 52 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 53 | class DeferredDisplayList; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 54 | class DisplayListOp; |
| 55 | class DisplayListRenderer; |
| 56 | class OpenGLRenderer; |
| 57 | class Rect; |
| 58 | class Layer; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 59 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 60 | class ClipRectOp; |
| 61 | class SaveLayerOp; |
| 62 | class SaveOp; |
| 63 | class RestoreToCountOp; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 64 | class DrawDisplayListOp; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 65 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 66 | /** |
| 67 | * Holds data used in the playback a tree of DisplayLists. |
| 68 | */ |
| 69 | class PlaybackStateStruct { |
| 70 | protected: |
| 71 | PlaybackStateStruct(OpenGLRenderer& renderer, int replayFlags, LinearAllocator* allocator) |
Chris Craik | 3783e70 | 2014-01-27 14:26:14 -0800 | [diff] [blame] | 72 | : mRenderer(renderer), mReplayFlags(replayFlags), mAllocator(allocator){} |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 73 | |
| 74 | public: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 75 | OpenGLRenderer& mRenderer; |
| 76 | const int mReplayFlags; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 77 | |
| 78 | // Allocator with the lifetime of a single frame. |
| 79 | // replay uses an Allocator owned by the struct, while defer shares the DeferredDisplayList's Allocator |
| 80 | LinearAllocator * const mAllocator; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 83 | class DeferStateStruct : public PlaybackStateStruct { |
| 84 | public: |
| 85 | DeferStateStruct(DeferredDisplayList& deferredList, OpenGLRenderer& renderer, int replayFlags) |
Chris Craik | 9f68c09 | 2014-01-10 10:30:57 -0800 | [diff] [blame] | 86 | : PlaybackStateStruct(renderer, replayFlags, &(deferredList.mAllocator)), |
| 87 | mDeferredList(deferredList) {} |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 88 | |
| 89 | DeferredDisplayList& mDeferredList; |
| 90 | }; |
| 91 | |
| 92 | class ReplayStateStruct : public PlaybackStateStruct { |
| 93 | public: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 94 | ReplayStateStruct(OpenGLRenderer& renderer, Rect& dirty, int replayFlags) |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 95 | : PlaybackStateStruct(renderer, replayFlags, &mReplayAllocator), |
| 96 | mDirty(dirty), mDrawGlStatus(DrawGlInfo::kStatusDone) {} |
| 97 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 98 | Rect& mDirty; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 99 | status_t mDrawGlStatus; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 100 | LinearAllocator mReplayAllocator; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 103 | /** |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 104 | * 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] | 105 | */ |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 106 | class DisplayListData { |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 107 | public: |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 108 | DisplayListData(); |
| 109 | ~DisplayListData(); |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 110 | |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 111 | // allocator into which all ops were allocated |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 112 | LinearAllocator allocator; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 113 | |
| 114 | // pointers to all ops within display list, pointing into allocator data |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 115 | Vector<DisplayListOp*> displayListOps; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 116 | |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 117 | // index of DisplayListOp restore, after which projected descendents should be drawn |
Chris Craik | 1df2644 | 2014-02-05 16:50:41 -0800 | [diff] [blame] | 118 | int projectionReceiveIndex; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 119 | |
| 120 | Vector<const SkBitmap*> bitmapResources; |
| 121 | Vector<const SkBitmap*> ownedBitmapResources; |
| 122 | Vector<const Res_png_9patch*> patchResources; |
| 123 | |
| 124 | Vector<const SkPaint*> paints; |
| 125 | Vector<const SkPath*> paths; |
| 126 | SortedVector<const SkPath*> sourcePaths; |
| 127 | Vector<const SkRegion*> regions; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 128 | Vector<Layer*> layers; |
| 129 | uint32_t functorCount; |
| 130 | bool hasDrawOps; |
| 131 | |
| 132 | bool isEmpty() { |
| 133 | return !displayListOps.size(); |
| 134 | } |
| 135 | |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 136 | void addChild(DrawDisplayListOp* childOp); |
| 137 | const Vector<DrawDisplayListOp*>& children() { return mChildren; } |
| 138 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 139 | void refProperty(CanvasPropertyPrimitive* prop) { |
| 140 | mReferenceHolders.push(prop); |
| 141 | } |
| 142 | |
| 143 | void refProperty(CanvasPropertyPaint* prop) { |
| 144 | mReferenceHolders.push(prop); |
| 145 | } |
| 146 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 147 | private: |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 148 | Vector< sp<VirtualLightRefBase> > mReferenceHolders; |
| 149 | |
| 150 | // list of children display lists for quick, non-drawing traversal |
| 151 | Vector<DrawDisplayListOp*> mChildren; |
| 152 | |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 153 | void cleanupResources(); |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 154 | }; |
| 155 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 156 | }; // namespace uirenderer |
| 157 | }; // namespace android |
| 158 | |
| 159 | #endif // ANDROID_HWUI_OPENGL_RENDERER_H |