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