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