blob: 99968e1750c8fbf5cb3139a3bd3848c0ecc3efc7 [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"
Chris Craik84ad6142016-01-12 12:09:19 -080021#include "utils/Macros.h"
Chris Craik5ea17242016-01-11 14:07:59 -080022
23#include <vector>
24#include <unordered_map>
25
26struct SkRect;
27
28namespace android {
29namespace uirenderer {
30
31class BakedOpState;
32struct BeginLayerOp;
33class BatchBase;
34class LinearAllocator;
35struct MergedBakedOpList;
36class MergingOpBatch;
37class OffscreenBuffer;
38class OpBatch;
39class RenderNode;
40
41typedef int batchid_t;
42typedef const void* mergeid_t;
43
44namespace 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
63typedef void (*BakedOpReceiver)(void*, const BakedOpState&);
64typedef 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 Craikf158b492016-01-12 14:45:08 -080070class LayerBuilder {
Chris Craik84ad6142016-01-12 12:09:19 -080071// Prevent copy/assign because users may stash pointer to offscreenBuffer and viewportClip
Chris Craikf158b492016-01-12 14:45:08 -080072PREVENT_COPY_AND_ASSIGN(LayerBuilder);
Chris Craik5ea17242016-01-11 14:07:59 -080073public:
Chris Craikf158b492016-01-12 14:45:08 -080074 // Create LayerBuilder for Fbo0
75 LayerBuilder(uint32_t width, uint32_t height, const Rect& repaintRect)
76 : LayerBuilder(width, height, repaintRect, nullptr, nullptr) {};
Chris Craik5ea17242016-01-11 14:07:59 -080077
Chris Craikf158b492016-01-12 14:45:08 -080078 // Create LayerBuilder for an offscreen layer, where beginLayerOp is present for a
Chris Craik5ea17242016-01-11 14:07:59 -080079 // saveLayer, renderNode is present for a HW layer.
Chris Craikf158b492016-01-12 14:45:08 -080080 LayerBuilder(uint32_t width, uint32_t height,
Chris Craik5ea17242016-01-11 14:07:59 -080081 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;
119private:
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