blob: 6eb19ec12721d36abb6c6516c34c8045e398a8db [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
Robert Phillipsf2361d22016-10-25 14:20:06 -04008#ifndef GrRenderTargetOpList_DEFINED
9#define GrRenderTargetOpList_DEFINED
reed@google.comac10a2d2010-12-22 21:39:39 +000010
Brian Salomon54d212e2017-03-21 14:22:38 -040011#include "GrAppliedClip.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040012#include "GrOpList.h"
Brian Salomonc48af932017-03-16 19:51:42 +000013#include "GrPathRendering.h"
Brian Salomon54d212e2017-03-21 14:22:38 -040014#include "GrPrimitiveProcessor.h"
Robert Phillips646e4292017-06-13 12:44:56 -040015#include "ops/GrOp.h"
Brian Salomon54d212e2017-03-21 14:22:38 -040016#include "SkArenaAlloc.h"
bsalomon@google.com8d67c072012-12-13 20:38:14 +000017#include "SkClipStack.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000018#include "SkMatrix.h"
reed1b55a962015-09-17 20:16:13 -070019#include "SkStringUtils.h"
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +000020#include "SkStrokeRec.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000021#include "SkTArray.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000022#include "SkTLazy.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000023#include "SkTypes.h"
Scroggo97c88c22011-05-11 14:05:25 +000024
joshualitt086cee12016-01-12 06:45:24 -080025class GrAuditTrail;
Brian Salomon7dae46a2016-12-14 16:21:37 -050026class GrClearOp;
bsalomon4b91f762015-05-19 09:29:46 -070027class GrCaps;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040028class GrRenderTargetProxy;
sugoi@google.com12b4e272012-12-06 20:13:11 +000029
Robert Phillipsf2361d22016-10-25 14:20:06 -040030class GrRenderTargetOpList final : public GrOpList {
Brian Salomon54d212e2017-03-21 14:22:38 -040031private:
Robert Phillipsbb581ce2017-05-29 15:05:15 -040032 using DstProxy = GrXferProcessor::DstProxy;
Brian Salomon54d212e2017-03-21 14:22:38 -040033
bsalomon@google.comf6601872012-08-28 21:11:35 +000034public:
Robert Phillipsc994a932018-06-19 13:09:54 -040035 GrRenderTargetOpList(GrResourceProvider*, sk_sp<GrOpMemoryPool>,
36 GrRenderTargetProxy*, GrAuditTrail*);
bsalomona73239a2015-04-28 13:35:17 -070037
Robert Phillipsf2361d22016-10-25 14:20:06 -040038 ~GrRenderTargetOpList() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000039
Robert Phillipsee683652017-04-26 11:53:10 -040040 void makeClosed(const GrCaps& caps) override {
Robert Phillipsf5442bb2017-04-17 14:18:34 -040041 if (this->isClosed()) {
42 return;
43 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040044
Robert Phillipsee683652017-04-26 11:53:10 -040045 this->forwardCombine(caps);
Robert Phillipsf5442bb2017-04-17 14:18:34 -040046
Robert Phillipsee683652017-04-26 11:53:10 -040047 INHERITED::makeClosed(caps);
robertphillipsa106c622015-10-16 09:07:06 -070048 }
bsalomonaecc0182016-03-07 11:50:44 -080049
Brian Salomon588cec72018-11-14 13:56:37 -050050 bool isEmpty() const { return fOpChains.empty(); }
Robert Phillipsf5442bb2017-04-17 14:18:34 -040051
reed@google.comac10a2d2010-12-22 21:39:39 +000052 /**
bsalomona73239a2015-04-28 13:35:17 -070053 * Empties the draw buffer of any queued up draws.
54 */
Chris Daltona84cacf2017-10-04 10:30:29 -060055 void endFlush() override;
Robert Phillipsf2361d22016-10-25 14:20:06 -040056
bsalomona73239a2015-04-28 13:35:17 -070057 /**
bsalomondc438982016-08-31 11:53:49 -070058 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
Brian Salomon1e41f4a2016-12-07 15:05:04 -050059 * of executeOps() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070060 */
Brian Osman407b3422017-08-22 15:01:32 -040061 void onPrepare(GrOpFlushState* flushState) override;
62 bool onExecute(GrOpFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070063
Brian Salomon348a0372018-10-31 10:42:18 -040064 void addOp(std::unique_ptr<GrOp> op, const GrCaps& caps) {
Robert Phillipsb493eeb2017-09-13 13:10:52 -040065 auto addDependency = [ &caps, this ] (GrSurfaceProxy* p) {
66 this->addDependency(p, caps);
67 };
68
69 op->visitProxies(addDependency);
70
Brian Salomon348a0372018-10-31 10:42:18 -040071 this->recordOp(std::move(op), caps);
Brian Salomon54d212e2017-03-21 14:22:38 -040072 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -040073
Brian Salomon348a0372018-10-31 10:42:18 -040074 void addOp(std::unique_ptr<GrOp> op, const GrCaps& caps, GrAppliedClip&& clip,
75 const DstProxy& dstProxy) {
Robert Phillipsb493eeb2017-09-13 13:10:52 -040076 auto addDependency = [ &caps, this ] (GrSurfaceProxy* p) {
77 this->addDependency(p, caps);
78 };
79
80 op->visitProxies(addDependency);
81 clip.visitProxies(addDependency);
Robert Phillips2739ab02018-07-27 07:35:55 -040082 if (dstProxy.proxy()) {
83 addDependency(dstProxy.proxy());
84 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -040085
Brian Salomon348a0372018-10-31 10:42:18 -040086 this->recordOp(std::move(op), caps, clip.doesClip() ? &clip : nullptr, &dstProxy);
Brian Salomon69868af2016-12-22 15:42:51 -050087 }
robertphillips9199a9f2016-07-13 07:48:43 -070088
Robert Phillips380b90c2017-08-30 07:41:07 -040089 void discard();
90
bsalomon9f129de2016-08-10 16:31:05 -070091 /** Clears the entire render target */
Brian Osman9a9baae2018-11-05 15:06:26 -050092 void fullClear(GrContext*, const SkPMColor4f& color);
bsalomon9f129de2016-08-10 16:31:05 -070093
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000094 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +000095 * Copies a pixel rectangle from one surface to another. This call may finalize
96 * reserved vertex/index data (as though a draw call was made). The src pixels
97 * copied are specified by srcRect. They are copied to a rect of the same
98 * size in dst with top left at dstPoint. If the src rect is clipped by the
99 * src bounds then pixel values in the dst rect corresponding to area clipped
bsalomon6df86402015-06-01 10:41:49 -0700100 * by the src rect are not overwritten. This method is not guaranteed to succeed
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000101 * depending on the type of surface, configs, etc, and the backend-specific
bsalomon6df86402015-06-01 10:41:49 -0700102 * limitations.
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000103 */
Robert Phillips7c525e62018-06-12 10:11:12 -0400104 bool copySurface(GrContext*,
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400105 GrSurfaceProxy* dst,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400106 GrSurfaceProxy* src,
bsalomonf90a02b2014-11-26 12:28:00 -0800107 const SkIRect& srcRect,
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400108 const SkIPoint& dstPoint) override;
robertphillips@google.comff175842012-05-14 19:31:39 +0000109
Brian Osman45580d32016-11-23 09:37:01 -0500110 GrRenderTargetOpList* asRenderTargetOpList() override { return this; }
111
Robert Phillips27483912018-04-20 12:43:18 -0400112 SkDEBUGCODE(void dump(bool printDependencies) const override;)
Robert Phillipsc84c0302017-05-08 15:35:11 -0400113 SkDEBUGCODE(int numClips() const override { return fNumClips; })
Chris Dalton706a6ff2017-11-29 22:01:06 -0700114 SkDEBUGCODE(void visitProxies_debugOnly(const GrOp::VisitProxyFunc&) const;)
Robert Phillipsc84c0302017-05-08 15:35:11 -0400115
Brian Salomon13540482018-07-09 10:31:47 -0400116private:
Brian Salomonc3833b42018-07-09 18:23:58 +0000117 friend class GrRenderTargetContextPriv; // for stencil clip state. TODO: this is invasive
118
Robert Phillipsc994a932018-06-19 13:09:54 -0400119 void deleteOps();
120
Brian Salomon588cec72018-11-14 13:56:37 -0500121 class OpChain {
122 public:
123 OpChain(const OpChain&) = delete;
124 OpChain& operator=(const OpChain&) = delete;
125 OpChain(std::unique_ptr<GrOp>, GrAppliedClip*, const DstProxy*);
126
127 ~OpChain() {
128 // The ops are stored in a GrMemoryPool and must be explicitly deleted via the pool.
129 SkASSERT(fList.empty());
Brian Salomon54d212e2017-03-21 14:22:38 -0400130 }
Chris Dalton8816b932017-11-29 16:48:25 -0700131
Brian Salomon588cec72018-11-14 13:56:37 -0500132 void visitProxies(const GrOp::VisitProxyFunc&, GrOp::VisitorType) const;
Robert Phillipsc994a932018-06-19 13:09:54 -0400133
Brian Salomon588cec72018-11-14 13:56:37 -0500134 GrOp* head() const { return fList.head(); }
Robert Phillips7c525e62018-06-12 10:11:12 -0400135
Brian Salomon588cec72018-11-14 13:56:37 -0500136 GrAppliedClip* appliedClip() const { return fAppliedClip; }
137 const DstProxy& dstProxy() const { return fDstProxy; }
138 const SkRect& bounds() const { return fBounds; }
Chris Dalton8816b932017-11-29 16:48:25 -0700139
Brian Salomon588cec72018-11-14 13:56:37 -0500140 // Deletes all the ops in the chain via the pool.
141 void deleteOps(GrOpMemoryPool* pool);
142
143 // Attempts to move the ops from the passed chain to this chain at the head. Also attempts
144 // to merge ops between the chains. Upon success the passed chain is empty.
145 // Fails when the chains aren't of the same op type, have different clips or dst proxies.
146 bool prependChain(OpChain*, const GrCaps&, GrOpMemoryPool*, GrAuditTrail*);
147
148 // Attempts to add 'op' to this chain either by merging or adding to the tail. Returns
149 // 'op' to the caller upon failure, otherwise null. Fails when the op and chain aren't of
150 // the same op type, have different clips or dst proxies.
151 std::unique_ptr<GrOp> appendOp(std::unique_ptr<GrOp> op, const DstProxy*,
152 const GrAppliedClip*, const GrCaps&, GrOpMemoryPool*,
153 GrAuditTrail*);
154
155 private:
156 class List {
157 public:
158 List() = default;
159 List(std::unique_ptr<GrOp>);
160 List(List&&);
161 List& operator=(List&& that);
162
163 bool empty() const { return !SkToBool(fHead); }
164 GrOp* head() const { return fHead.get(); }
165 GrOp* tail() const { return fTail; }
166
167 std::unique_ptr<GrOp> popHead();
168 std::unique_ptr<GrOp> removeOp(GrOp* op);
169 void pushHead(std::unique_ptr<GrOp> op);
170 void pushTail(std::unique_ptr<GrOp>);
171
172 void validate() const;
173
174 private:
175 std::unique_ptr<GrOp> fHead;
176 GrOp* fTail = nullptr;
177 };
178
179 void validate() const;
180
181 std::tuple<List, List> TryConcat(List chainA, const DstProxy& dstProxyA,
182 const GrAppliedClip* appliedClipA, List chainB,
183 const DstProxy& dstProxyB,
184 const GrAppliedClip* appliedClipB, const GrCaps&,
185 GrOpMemoryPool*, GrAuditTrail*);
186 List DoConcat(List, List, const GrCaps&, GrOpMemoryPool*, GrAuditTrail*);
187
188 List fList;
189 DstProxy fDstProxy;
190 GrAppliedClip* fAppliedClip;
191 SkRect fBounds;
Brian Salomon54d212e2017-03-21 14:22:38 -0400192 };
193
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500194 void purgeOpsWithUninstantiatedProxies() override;
195
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400196 void gatherProxyIntervals(GrResourceAllocator*) const override;
197
Brian Salomon348a0372018-10-31 10:42:18 -0400198 void recordOp(std::unique_ptr<GrOp>, const GrCaps& caps, GrAppliedClip* = nullptr,
199 const DstProxy* = nullptr);
Brian Salomon2790c522016-12-09 16:32:23 -0500200
Robert Phillipsee683652017-04-26 11:53:10 -0400201 void forwardCombine(const GrCaps&);
bsalomonad792c12015-09-10 11:10:50 -0700202
Brian Salomonc3833b42018-07-09 18:23:58 +0000203 uint32_t fLastClipStackGenID;
204 SkIRect fLastDevClipBounds;
205 int fLastClipNumAnalyticFPs;
csmartdalton7cdda992016-11-01 07:03:03 -0700206
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400207 // For ops/opList we have mean: 5 stdDev: 28
Brian Salomon588cec72018-11-14 13:56:37 -0500208 SkSTArray<25, OpChain, true> fOpChains;
Brian Salomon54d212e2017-03-21 14:22:38 -0400209
Robert Phillipsf6d7eb12017-04-26 14:55:34 -0400210 // MDB TODO: 4096 for the first allocation of the clip space will be huge overkill.
211 // Gather statistics to determine the correct size.
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400212 SkArenaAlloc fClipAllocator{4096};
213 SkDEBUGCODE(int fNumClips;)
Brian Salomon54d212e2017-03-21 14:22:38 -0400214
Robert Phillipsf2361d22016-10-25 14:20:06 -0400215 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700216};
217
reed@google.comac10a2d2010-12-22 21:39:39 +0000218#endif