Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #pragma once |
| 18 | |
| 19 | #include "ClipArea.h" |
| 20 | #include "Rect.h" |
Chris Craik | 84ad614 | 2016-01-12 12:09:19 -0800 | [diff] [blame] | 21 | #include "utils/Macros.h" |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 22 | |
| 23 | #include <vector> |
| 24 | #include <unordered_map> |
| 25 | |
| 26 | struct SkRect; |
| 27 | |
| 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | |
| 31 | class BakedOpState; |
| 32 | struct BeginLayerOp; |
| 33 | class BatchBase; |
| 34 | class LinearAllocator; |
| 35 | struct MergedBakedOpList; |
| 36 | class MergingOpBatch; |
| 37 | class OffscreenBuffer; |
| 38 | class OpBatch; |
| 39 | class RenderNode; |
| 40 | |
| 41 | typedef int batchid_t; |
| 42 | typedef const void* mergeid_t; |
| 43 | |
| 44 | namespace OpBatchType { |
| 45 | enum { |
| 46 | Bitmap, |
| 47 | MergedPatch, |
| 48 | AlphaVertices, |
| 49 | Vertices, |
| 50 | AlphaMaskTexture, |
| 51 | Text, |
| 52 | ColorText, |
| 53 | Shadow, |
| 54 | TextureLayer, |
| 55 | Functor, |
| 56 | CopyToLayer, |
| 57 | CopyFromLayer, |
| 58 | |
| 59 | Count // must be last |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | typedef void (*BakedOpReceiver)(void*, const BakedOpState&); |
| 64 | typedef void (*MergedOpReceiver)(void*, const MergedBakedOpList& opList); |
| 65 | |
| 66 | /** |
| 67 | * Stores the deferred render operations and state used to compute ordering |
| 68 | * for a single FBO/layer. |
| 69 | */ |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 70 | class LayerBuilder { |
Chris Craik | 84ad614 | 2016-01-12 12:09:19 -0800 | [diff] [blame] | 71 | // Prevent copy/assign because users may stash pointer to offscreenBuffer and viewportClip |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 72 | PREVENT_COPY_AND_ASSIGN(LayerBuilder); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 73 | public: |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 74 | // Create LayerBuilder for Fbo0 |
| 75 | LayerBuilder(uint32_t width, uint32_t height, const Rect& repaintRect) |
| 76 | : LayerBuilder(width, height, repaintRect, nullptr, nullptr) {}; |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 77 | |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 78 | // Create LayerBuilder for an offscreen layer, where beginLayerOp is present for a |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 79 | // saveLayer, renderNode is present for a HW layer. |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 80 | LayerBuilder(uint32_t width, uint32_t height, |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 81 | const Rect& repaintRect, const BeginLayerOp* beginLayerOp, RenderNode* renderNode); |
| 82 | |
| 83 | // iterate back toward target to see if anything drawn since should overlap the new op |
| 84 | // if no target, merging ops still iterate to find similar batch to insert after |
| 85 | void locateInsertIndex(int batchId, const Rect& clippedBounds, |
| 86 | BatchBase** targetBatch, size_t* insertBatchIndex) const; |
| 87 | |
| 88 | void deferUnmergeableOp(LinearAllocator& allocator, BakedOpState* op, batchid_t batchId); |
| 89 | |
| 90 | // insertion point of a new batch, will hopefully be immediately after similar batch |
| 91 | // (generally, should be similar shader) |
| 92 | void deferMergeableOp(LinearAllocator& allocator, |
| 93 | BakedOpState* op, batchid_t batchId, mergeid_t mergeId); |
| 94 | |
| 95 | void replayBakedOpsImpl(void* arg, BakedOpReceiver* receivers, MergedOpReceiver*) const; |
| 96 | |
| 97 | void deferLayerClear(const Rect& dstRect); |
| 98 | |
| 99 | bool empty() const { |
| 100 | return mBatches.empty(); |
| 101 | } |
| 102 | |
| 103 | void clear() { |
| 104 | mBatches.clear(); |
| 105 | } |
| 106 | |
| 107 | void dump() const; |
| 108 | |
| 109 | const uint32_t width; |
| 110 | const uint32_t height; |
| 111 | const Rect repaintRect; |
| 112 | OffscreenBuffer* offscreenBuffer; |
| 113 | const BeginLayerOp* beginLayerOp; |
| 114 | const RenderNode* renderNode; |
| 115 | const ClipRect viewportClip; |
| 116 | |
| 117 | // list of deferred CopyFromLayer ops, to be deferred upon encountering EndUnclippedLayerOps |
| 118 | std::vector<BakedOpState*> activeUnclippedSaveLayers; |
| 119 | private: |
| 120 | void flushLayerClears(LinearAllocator& allocator); |
| 121 | |
| 122 | std::vector<BatchBase*> mBatches; |
| 123 | |
| 124 | /** |
| 125 | * Maps the mergeid_t returned by an op's getMergeId() to the most recently seen |
| 126 | * MergingDrawBatch of that id. These ids are unique per draw type and guaranteed to not |
| 127 | * collide, which avoids the need to resolve mergeid collisions. |
| 128 | */ |
| 129 | std::unordered_map<mergeid_t, MergingOpBatch*> mMergingBatchLookup[OpBatchType::Count]; |
| 130 | |
| 131 | // Maps batch ids to the most recent *non-merging* batch of that id |
| 132 | OpBatch* mBatchLookup[OpBatchType::Count] = { nullptr }; |
| 133 | |
| 134 | std::vector<Rect> mClearRects; |
| 135 | }; |
| 136 | |
| 137 | }; // namespace uirenderer |
| 138 | }; // namespace android |