blob: 7e444672700e1828324383f6161e753979ac02b0 [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"
Chris Dalton945ee652019-01-23 09:10:36 -070016#include "ops/GrDrawOp.h"
Brian Salomon54d212e2017-03-21 14:22:38 -040017#include "SkArenaAlloc.h"
bsalomon@google.com8d67c072012-12-13 20:38:14 +000018#include "SkClipStack.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000019#include "SkMatrix.h"
reed1b55a962015-09-17 20:16:13 -070020#include "SkStringUtils.h"
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +000021#include "SkStrokeRec.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000022#include "SkTArray.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000023#include "SkTLazy.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000024#include "SkTypes.h"
Scroggo97c88c22011-05-11 14:05:25 +000025
joshualitt086cee12016-01-12 06:45:24 -080026class GrAuditTrail;
Brian Salomon7dae46a2016-12-14 16:21:37 -050027class GrClearOp;
bsalomon4b91f762015-05-19 09:29:46 -070028class GrCaps;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040029class GrRenderTargetProxy;
sugoi@google.com12b4e272012-12-06 20:13:11 +000030
Robert Phillipsf2361d22016-10-25 14:20:06 -040031class GrRenderTargetOpList final : public GrOpList {
Brian Salomon54d212e2017-03-21 14:22:38 -040032private:
Robert Phillipsbb581ce2017-05-29 15:05:15 -040033 using DstProxy = GrXferProcessor::DstProxy;
Brian Salomon54d212e2017-03-21 14:22:38 -040034
bsalomon@google.comf6601872012-08-28 21:11:35 +000035public:
Robert Phillipsc994a932018-06-19 13:09:54 -040036 GrRenderTargetOpList(GrResourceProvider*, sk_sp<GrOpMemoryPool>,
37 GrRenderTargetProxy*, GrAuditTrail*);
bsalomona73239a2015-04-28 13:35:17 -070038
Robert Phillipsf2361d22016-10-25 14:20:06 -040039 ~GrRenderTargetOpList() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000040
Robert Phillipsee683652017-04-26 11:53:10 -040041 void makeClosed(const GrCaps& caps) override {
Robert Phillipsf5442bb2017-04-17 14:18:34 -040042 if (this->isClosed()) {
43 return;
44 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040045
Robert Phillipsee683652017-04-26 11:53:10 -040046 this->forwardCombine(caps);
Robert Phillipsf5442bb2017-04-17 14:18:34 -040047
Robert Phillipsee683652017-04-26 11:53:10 -040048 INHERITED::makeClosed(caps);
robertphillipsa106c622015-10-16 09:07:06 -070049 }
bsalomonaecc0182016-03-07 11:50:44 -080050
Brian Salomon588cec72018-11-14 13:56:37 -050051 bool isEmpty() const { return fOpChains.empty(); }
Robert Phillipsf5442bb2017-04-17 14:18:34 -040052
reed@google.comac10a2d2010-12-22 21:39:39 +000053 /**
bsalomona73239a2015-04-28 13:35:17 -070054 * Empties the draw buffer of any queued up draws.
55 */
Chris Daltona84cacf2017-10-04 10:30:29 -060056 void endFlush() override;
Robert Phillipsf2361d22016-10-25 14:20:06 -040057
bsalomona73239a2015-04-28 13:35:17 -070058 /**
bsalomondc438982016-08-31 11:53:49 -070059 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
Brian Salomon1e41f4a2016-12-07 15:05:04 -050060 * of executeOps() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070061 */
Brian Osman407b3422017-08-22 15:01:32 -040062 void onPrepare(GrOpFlushState* flushState) override;
63 bool onExecute(GrOpFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070064
Brian Salomon348a0372018-10-31 10:42:18 -040065 void addOp(std::unique_ptr<GrOp> op, const GrCaps& caps) {
Robert Phillipsb493eeb2017-09-13 13:10:52 -040066 auto addDependency = [ &caps, this ] (GrSurfaceProxy* p) {
67 this->addDependency(p, caps);
68 };
69
70 op->visitProxies(addDependency);
71
Chris Dalton945ee652019-01-23 09:10:36 -070072 this->recordOp(std::move(op), GrProcessorSet::EmptySetAnalysis(), nullptr, nullptr, caps);
Brian Salomon54d212e2017-03-21 14:22:38 -040073 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -040074
Chris Dalton945ee652019-01-23 09:10:36 -070075 void addDrawOp(std::unique_ptr<GrDrawOp> op, const GrProcessorSet::Analysis& processorAnalysis,
76 GrAppliedClip&& clip, const DstProxy& dstProxy, const GrCaps& caps) {
Robert Phillipsb493eeb2017-09-13 13:10:52 -040077 auto addDependency = [ &caps, this ] (GrSurfaceProxy* p) {
78 this->addDependency(p, caps);
79 };
80
81 op->visitProxies(addDependency);
82 clip.visitProxies(addDependency);
Robert Phillips2739ab02018-07-27 07:35:55 -040083 if (dstProxy.proxy()) {
84 addDependency(dstProxy.proxy());
85 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -040086
Chris Dalton945ee652019-01-23 09:10:36 -070087 this->recordOp(std::move(op), processorAnalysis, clip.doesClip() ? &clip : nullptr,
88 &dstProxy, caps);
Brian Salomon69868af2016-12-22 15:42:51 -050089 }
robertphillips9199a9f2016-07-13 07:48:43 -070090
Robert Phillips380b90c2017-08-30 07:41:07 -040091 void discard();
92
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000093 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +000094 * Copies a pixel rectangle from one surface to another. This call may finalize
95 * reserved vertex/index data (as though a draw call was made). The src pixels
96 * copied are specified by srcRect. They are copied to a rect of the same
97 * size in dst with top left at dstPoint. If the src rect is clipped by the
98 * src bounds then pixel values in the dst rect corresponding to area clipped
bsalomon6df86402015-06-01 10:41:49 -070099 * by the src rect are not overwritten. This method is not guaranteed to succeed
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000100 * depending on the type of surface, configs, etc, and the backend-specific
bsalomon6df86402015-06-01 10:41:49 -0700101 * limitations.
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000102 */
Robert Phillips7c525e62018-06-12 10:11:12 -0400103 bool copySurface(GrContext*,
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400104 GrSurfaceProxy* dst,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400105 GrSurfaceProxy* src,
bsalomonf90a02b2014-11-26 12:28:00 -0800106 const SkIRect& srcRect,
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400107 const SkIPoint& dstPoint) override;
robertphillips@google.comff175842012-05-14 19:31:39 +0000108
Brian Osman45580d32016-11-23 09:37:01 -0500109 GrRenderTargetOpList* asRenderTargetOpList() override { return this; }
110
Robert Phillips27483912018-04-20 12:43:18 -0400111 SkDEBUGCODE(void dump(bool printDependencies) const override;)
Robert Phillipsc84c0302017-05-08 15:35:11 -0400112 SkDEBUGCODE(int numClips() const override { return fNumClips; })
Chris Dalton706a6ff2017-11-29 22:01:06 -0700113 SkDEBUGCODE(void visitProxies_debugOnly(const GrOp::VisitProxyFunc&) const;)
Robert Phillipsc84c0302017-05-08 15:35:11 -0400114
Brian Salomon13540482018-07-09 10:31:47 -0400115private:
Brian Salomonc3833b42018-07-09 18:23:58 +0000116 friend class GrRenderTargetContextPriv; // for stencil clip state. TODO: this is invasive
117
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500118 // The RTC and RTOpList have to work together to handle buffer clears. In most cases, buffer
119 // clearing can be done natively, in which case the op list's load ops are sufficient. In other
120 // cases, draw ops must be used, which makes the RTC the best place for those decisions. This,
121 // however, requires that the RTC be able to coordinate with the op list to achieve similar ends
122 friend class GrRenderTargetContext;
123
124 // Must only be called if native stencil buffer clearing is enabled
125 void setStencilLoadOp(GrLoadOp op);
126 // Must only be called if native color buffer clearing is enabled.
127 void setColorLoadOp(GrLoadOp op, const SkPMColor4f& color);
128 // Sets the clear color to transparent black
129 void setColorLoadOp(GrLoadOp op) {
130 static const SkPMColor4f kDefaultClearColor = {0.f, 0.f, 0.f, 0.f};
131 this->setColorLoadOp(op, kDefaultClearColor);
132 }
133
134 // Perform book-keeping for a fullscreen clear, regardless of how the clear is implemented later
135 // (i.e. setColorLoadOp(), adding a ClearOp, or adding a GrFillRectOp that covers the device).
136 // Returns true if the clear can be converted into a load op (barring device caps).
137 bool resetForFullscreenClear();
138
Robert Phillipsc994a932018-06-19 13:09:54 -0400139 void deleteOps();
140
Brian Salomon588cec72018-11-14 13:56:37 -0500141 class OpChain {
142 public:
143 OpChain(const OpChain&) = delete;
144 OpChain& operator=(const OpChain&) = delete;
Chris Dalton945ee652019-01-23 09:10:36 -0700145 OpChain(std::unique_ptr<GrOp>, GrProcessorSet::Analysis, GrAppliedClip*, const DstProxy*);
Brian Salomon588cec72018-11-14 13:56:37 -0500146
147 ~OpChain() {
148 // The ops are stored in a GrMemoryPool and must be explicitly deleted via the pool.
149 SkASSERT(fList.empty());
Brian Salomon54d212e2017-03-21 14:22:38 -0400150 }
Chris Dalton8816b932017-11-29 16:48:25 -0700151
Brian Salomon588cec72018-11-14 13:56:37 -0500152 void visitProxies(const GrOp::VisitProxyFunc&, GrOp::VisitorType) const;
Robert Phillipsc994a932018-06-19 13:09:54 -0400153
Brian Salomon588cec72018-11-14 13:56:37 -0500154 GrOp* head() const { return fList.head(); }
Robert Phillips7c525e62018-06-12 10:11:12 -0400155
Brian Salomon588cec72018-11-14 13:56:37 -0500156 GrAppliedClip* appliedClip() const { return fAppliedClip; }
157 const DstProxy& dstProxy() const { return fDstProxy; }
158 const SkRect& bounds() const { return fBounds; }
Chris Dalton8816b932017-11-29 16:48:25 -0700159
Brian Salomon588cec72018-11-14 13:56:37 -0500160 // Deletes all the ops in the chain via the pool.
161 void deleteOps(GrOpMemoryPool* pool);
162
163 // Attempts to move the ops from the passed chain to this chain at the head. Also attempts
164 // to merge ops between the chains. Upon success the passed chain is empty.
165 // Fails when the chains aren't of the same op type, have different clips or dst proxies.
166 bool prependChain(OpChain*, const GrCaps&, GrOpMemoryPool*, GrAuditTrail*);
167
168 // Attempts to add 'op' to this chain either by merging or adding to the tail. Returns
169 // 'op' to the caller upon failure, otherwise null. Fails when the op and chain aren't of
170 // the same op type, have different clips or dst proxies.
Chris Dalton945ee652019-01-23 09:10:36 -0700171 std::unique_ptr<GrOp> appendOp(std::unique_ptr<GrOp> op, GrProcessorSet::Analysis,
172 const DstProxy*, const GrAppliedClip*, const GrCaps&,
173 GrOpMemoryPool*, GrAuditTrail*);
Brian Salomon588cec72018-11-14 13:56:37 -0500174
175 private:
176 class List {
177 public:
178 List() = default;
179 List(std::unique_ptr<GrOp>);
180 List(List&&);
181 List& operator=(List&& that);
182
183 bool empty() const { return !SkToBool(fHead); }
184 GrOp* head() const { return fHead.get(); }
185 GrOp* tail() const { return fTail; }
186
187 std::unique_ptr<GrOp> popHead();
188 std::unique_ptr<GrOp> removeOp(GrOp* op);
189 void pushHead(std::unique_ptr<GrOp> op);
190 void pushTail(std::unique_ptr<GrOp>);
191
192 void validate() const;
193
194 private:
195 std::unique_ptr<GrOp> fHead;
196 GrOp* fTail = nullptr;
197 };
198
199 void validate() const;
200
Chris Dalton945ee652019-01-23 09:10:36 -0700201 bool tryConcat(List*, GrProcessorSet::Analysis, const DstProxy&, const GrAppliedClip*,
202 const SkRect& bounds, const GrCaps&, GrOpMemoryPool*, GrAuditTrail*);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700203 static List DoConcat(List, List, const GrCaps&, GrOpMemoryPool*, GrAuditTrail*);
Brian Salomon588cec72018-11-14 13:56:37 -0500204
205 List fList;
Chris Dalton945ee652019-01-23 09:10:36 -0700206 GrProcessorSet::Analysis fProcessorAnalysis;
Brian Salomon588cec72018-11-14 13:56:37 -0500207 DstProxy fDstProxy;
208 GrAppliedClip* fAppliedClip;
209 SkRect fBounds;
Brian Salomon54d212e2017-03-21 14:22:38 -0400210 };
211
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500212 void purgeOpsWithUninstantiatedProxies() override;
213
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400214 void gatherProxyIntervals(GrResourceAllocator*) const override;
215
Chris Dalton945ee652019-01-23 09:10:36 -0700216 void recordOp(std::unique_ptr<GrOp>, GrProcessorSet::Analysis, GrAppliedClip*, const DstProxy*,
217 const GrCaps& caps);
Brian Salomon2790c522016-12-09 16:32:23 -0500218
Robert Phillipsee683652017-04-26 11:53:10 -0400219 void forwardCombine(const GrCaps&);
bsalomonad792c12015-09-10 11:10:50 -0700220
Brian Salomonc3833b42018-07-09 18:23:58 +0000221 uint32_t fLastClipStackGenID;
222 SkIRect fLastDevClipBounds;
223 int fLastClipNumAnalyticFPs;
csmartdalton7cdda992016-11-01 07:03:03 -0700224
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400225 // For ops/opList we have mean: 5 stdDev: 28
Brian Salomon588cec72018-11-14 13:56:37 -0500226 SkSTArray<25, OpChain, true> fOpChains;
Brian Salomon54d212e2017-03-21 14:22:38 -0400227
Robert Phillipsf6d7eb12017-04-26 14:55:34 -0400228 // MDB TODO: 4096 for the first allocation of the clip space will be huge overkill.
229 // Gather statistics to determine the correct size.
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400230 SkArenaAlloc fClipAllocator{4096};
231 SkDEBUGCODE(int fNumClips;)
Brian Salomon54d212e2017-03-21 14:22:38 -0400232
Robert Phillipsf2361d22016-10-25 14:20:06 -0400233 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700234};
235
reed@google.comac10a2d2010-12-22 21:39:39 +0000236#endif