blob: c799d48f782130ea24cfa3a3cb1473c968e36be8 [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
Chris Craik5ea17242016-01-11 14:07:59 -080023#include <unordered_map>
John Reck1bcacfd2017-11-03 10:12:19 -070024#include <vector>
Chris Craik5ea17242016-01-11 14:07:59 -080025
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 {
John Reck1bcacfd2017-11-03 10:12:19 -070045enum {
46 Bitmap,
47 MergedPatch,
48 AlphaVertices,
49 Vertices,
50 AlphaMaskTexture,
51 Text,
52 ColorText,
53 Shadow,
54 TextureLayer,
55 Functor,
56 CopyToLayer,
57 CopyFromLayer,
Chris Craik5ea17242016-01-11 14:07:59 -080058
John Reck1bcacfd2017-11-03 10:12:19 -070059 Count // must be last
60};
Chris Craik5ea17242016-01-11 14:07:59 -080061}
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 {
John Reck1bcacfd2017-11-03 10:12:19 -070071 // Prevent copy/assign because users may stash pointer to offscreenBuffer and viewportClip
72 PREVENT_COPY_AND_ASSIGN(LayerBuilder);
73
Chris Craik5ea17242016-01-11 14:07:59 -080074public:
Chris Craikf158b492016-01-12 14:45:08 -080075 // Create LayerBuilder for Fbo0
76 LayerBuilder(uint32_t width, uint32_t height, const Rect& repaintRect)
John Reck1bcacfd2017-11-03 10:12:19 -070077 : LayerBuilder(width, height, repaintRect, nullptr, nullptr){};
Chris Craik5ea17242016-01-11 14:07:59 -080078
Chris Craikf158b492016-01-12 14:45:08 -080079 // Create LayerBuilder for an offscreen layer, where beginLayerOp is present for a
Chris Craik5ea17242016-01-11 14:07:59 -080080 // saveLayer, renderNode is present for a HW layer.
John Reck1bcacfd2017-11-03 10:12:19 -070081 LayerBuilder(uint32_t width, uint32_t height, const Rect& repaintRect,
82 const BeginLayerOp* beginLayerOp, RenderNode* renderNode);
Chris Craik5ea17242016-01-11 14:07:59 -080083
84 // iterate back toward target to see if anything drawn since should overlap the new op
85 // if no target, merging ops still iterate to find similar batch to insert after
John Reck1bcacfd2017-11-03 10:12:19 -070086 void locateInsertIndex(int batchId, const Rect& clippedBounds, BatchBase** targetBatch,
87 size_t* insertBatchIndex) const;
Chris Craik5ea17242016-01-11 14:07:59 -080088
89 void deferUnmergeableOp(LinearAllocator& allocator, BakedOpState* op, batchid_t batchId);
90
91 // insertion point of a new batch, will hopefully be immediately after similar batch
92 // (generally, should be similar shader)
John Reck1bcacfd2017-11-03 10:12:19 -070093 void deferMergeableOp(LinearAllocator& allocator, BakedOpState* op, batchid_t batchId,
94 mergeid_t mergeId);
Chris Craik5ea17242016-01-11 14:07:59 -080095
96 void replayBakedOpsImpl(void* arg, BakedOpReceiver* receivers, MergedOpReceiver*) const;
97
98 void deferLayerClear(const Rect& dstRect);
99
John Reck1bcacfd2017-11-03 10:12:19 -0700100 bool empty() const { return mBatches.empty(); }
Chris Craik5ea17242016-01-11 14:07:59 -0800101
Chris Craik80d2ade2016-03-28 12:54:07 -0700102 void clear();
Chris Craik5ea17242016-01-11 14:07:59 -0800103
104 void dump() const;
105
106 const uint32_t width;
107 const uint32_t height;
108 const Rect repaintRect;
Chris Craik4876de12016-02-25 16:54:08 -0800109 const ClipRect repaintClip;
Chris Craik5ea17242016-01-11 14:07:59 -0800110 OffscreenBuffer* offscreenBuffer;
111 const BeginLayerOp* beginLayerOp;
112 const RenderNode* renderNode;
Chris Craik5ea17242016-01-11 14:07:59 -0800113
114 // list of deferred CopyFromLayer ops, to be deferred upon encountering EndUnclippedLayerOps
115 std::vector<BakedOpState*> activeUnclippedSaveLayers;
John Reck1bcacfd2017-11-03 10:12:19 -0700116
Chris Craik5ea17242016-01-11 14:07:59 -0800117private:
Chris Craik80d2ade2016-03-28 12:54:07 -0700118 void onDeferOp(LinearAllocator& allocator, const BakedOpState* bakedState);
Chris Craik5ea17242016-01-11 14:07:59 -0800119 void flushLayerClears(LinearAllocator& allocator);
120
121 std::vector<BatchBase*> mBatches;
122
123 /**
124 * Maps the mergeid_t returned by an op's getMergeId() to the most recently seen
125 * MergingDrawBatch of that id. These ids are unique per draw type and guaranteed to not
126 * collide, which avoids the need to resolve mergeid collisions.
127 */
128 std::unordered_map<mergeid_t, MergingOpBatch*> mMergingBatchLookup[OpBatchType::Count];
129
130 // Maps batch ids to the most recent *non-merging* batch of that id
John Reck1bcacfd2017-11-03 10:12:19 -0700131 OpBatch* mBatchLookup[OpBatchType::Count] = {nullptr};
Chris Craik5ea17242016-01-11 14:07:59 -0800132
133 std::vector<Rect> mClearRects;
134};
135
John Reck1bcacfd2017-11-03 10:12:19 -0700136}; // namespace uirenderer
137}; // namespace android