Chris Craik | c3566d0 | 2013-02-04 16:16:33 -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_DEFERRED_DISPLAY_LIST_H |
| 18 | #define ANDROID_HWUI_DEFERRED_DISPLAY_LIST_H |
| 19 | |
| 20 | #include <utils/Errors.h> |
| 21 | #include <utils/Vector.h> |
| 22 | |
| 23 | #include "Matrix.h" |
| 24 | #include "Rect.h" |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 25 | #include "utils/TinyHashMap.h" |
| 26 | |
| 27 | class SkBitmap; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 32 | class ClipOp; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 33 | class DrawOp; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 34 | class SaveOp; |
| 35 | class SaveLayerOp; |
| 36 | class StateOp; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 37 | class OpenGLRenderer; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 38 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 39 | class Batch; |
| 40 | class DrawBatch; |
| 41 | class MergingDrawBatch; |
| 42 | |
| 43 | typedef void* mergeid_t; |
| 44 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 45 | class DeferredDisplayList { |
| 46 | public: |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 47 | DeferredDisplayList(const Rect& bounds, bool avoidOverdraw = true) : |
| 48 | mBounds(bounds), mAvoidOverdraw(avoidOverdraw) { |
| 49 | clear(); |
| 50 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 51 | ~DeferredDisplayList() { clear(); } |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 52 | void reset(const Rect& bounds) { mBounds.set(bounds); } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 53 | |
| 54 | enum OpBatchId { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 55 | kOpBatch_None = 0, // Don't batch |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 56 | kOpBatch_Bitmap, |
| 57 | kOpBatch_Patch, |
| 58 | kOpBatch_AlphaVertices, |
| 59 | kOpBatch_Vertices, |
| 60 | kOpBatch_AlphaMaskTexture, |
| 61 | kOpBatch_Text, |
| 62 | kOpBatch_ColorText, |
| 63 | |
| 64 | kOpBatch_Count, // Add other batch ids before this |
| 65 | }; |
| 66 | |
| 67 | bool isEmpty() { return mBatches.isEmpty(); } |
| 68 | |
| 69 | /** |
| 70 | * Plays back all of the draw ops recorded into batches to the renderer. |
| 71 | * Adjusts the state of the renderer as necessary, and restores it when complete |
| 72 | */ |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 73 | status_t flush(OpenGLRenderer& renderer, Rect& dirty); |
| 74 | |
| 75 | void addClip(OpenGLRenderer& renderer, ClipOp* op); |
| 76 | void addSaveLayer(OpenGLRenderer& renderer, SaveLayerOp* op, int newSaveCount); |
| 77 | void addSave(OpenGLRenderer& renderer, SaveOp* op, int newSaveCount); |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 78 | void addRestoreToCount(OpenGLRenderer& renderer, StateOp* op, int newSaveCount); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Add a draw op into the DeferredDisplayList, reordering as needed (for performance) if |
| 82 | * disallowReorder is false, respecting draw order when overlaps occur |
| 83 | */ |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 84 | void addDrawOp(OpenGLRenderer& renderer, DrawOp* op); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 85 | |
| 86 | private: |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 87 | /** |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 88 | * Resets the batching back-pointers, creating a barrier in the operation stream so that no ops |
| 89 | * added in the future will be inserted into a batch that already exist. |
| 90 | */ |
| 91 | void resetBatchingState(); |
| 92 | |
Chris Craik | 1206b9b | 2013-04-04 14:46:24 -0700 | [diff] [blame] | 93 | void clear(); |
| 94 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 95 | void storeStateOpBarrier(OpenGLRenderer& renderer, StateOp* op); |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 96 | void storeRestoreToCountBarrier(OpenGLRenderer& renderer, StateOp* op, int newSaveCount); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 97 | |
| 98 | bool recordingComplexClip() const { return mComplexClipStackStart >= 0; } |
| 99 | |
| 100 | int getStateOpDeferFlags() const; |
| 101 | int getDrawOpDeferFlags() const; |
| 102 | |
Chris Craik | f70119c | 2013-06-13 11:21:22 -0700 | [diff] [blame] | 103 | void discardDrawingBatches(const unsigned int maxIndex); |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 104 | |
| 105 | // layer space bounds of rendering |
| 106 | Rect mBounds; |
| 107 | const bool mAvoidOverdraw; |
| 108 | |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 109 | /** |
| 110 | * At defer time, stores the *defer time* savecount of save/saveLayer ops that were deferred, so |
| 111 | * that when an associated restoreToCount is deferred, it can be recorded as a |
| 112 | * RestoreToCountBatch |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 113 | */ |
| 114 | Vector<int> mSaveStack; |
| 115 | int mComplexClipStackStart; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 116 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 117 | Vector<Batch*> mBatches; |
| 118 | |
| 119 | // Maps batch ids to the most recent *non-merging* batch of that id |
| 120 | Batch* mBatchLookup[kOpBatch_Count]; |
| 121 | |
| 122 | // Points to the index after the most recent barrier |
| 123 | int mEarliestBatchIndex; |
| 124 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 125 | // Points to the first index that may contain a pure drawing batch |
| 126 | int mEarliestUnclearedIndex; |
| 127 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 128 | /** |
| 129 | * Maps the mergeid_t returned by an op's getMergeId() to the most recently seen |
| 130 | * MergingDrawBatch of that id. These ids are unique per draw type and guaranteed to not |
| 131 | * collide, which avoids the need to resolve mergeid collisions. |
| 132 | */ |
| 133 | TinyHashMap<mergeid_t, DrawBatch*> mMergingBatches[kOpBatch_Count]; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 134 | }; |
| 135 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 136 | /** |
| 137 | * Struct containing information that instructs the defer |
| 138 | */ |
| 139 | struct DeferInfo { |
| 140 | public: |
| 141 | DeferInfo() : |
| 142 | batchId(DeferredDisplayList::kOpBatch_None), |
| 143 | mergeId((mergeid_t) -1), |
| 144 | mergeable(false), |
| 145 | opaqueOverBounds(false) { |
| 146 | }; |
| 147 | |
| 148 | int batchId; |
| 149 | mergeid_t mergeId; |
| 150 | bool mergeable; |
| 151 | bool opaqueOverBounds; // opaque over bounds in DeferredDisplayState - can skip ops below |
| 152 | }; |
| 153 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 154 | }; // namespace uirenderer |
| 155 | }; // namespace android |
| 156 | |
| 157 | #endif // ANDROID_HWUI_DEFERRED_DISPLAY_LIST_H |