blob: 7e600d41d1cdb5529edd81381197ef268fb9c734 [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 Phillips646e4292017-06-13 12:44:56 -040030namespace gr_instanced {
31 class InstancedRendering;
32}
33
Robert Phillipsf2361d22016-10-25 14:20:06 -040034class GrRenderTargetOpList final : public GrOpList {
Brian Salomon54d212e2017-03-21 14:22:38 -040035private:
Robert Phillipsbb581ce2017-05-29 15:05:15 -040036 using DstProxy = GrXferProcessor::DstProxy;
Brian Salomon54d212e2017-03-21 14:22:38 -040037
bsalomon@google.comf6601872012-08-28 21:11:35 +000038public:
Robert Phillipsb6deea82017-05-11 14:14:30 -040039 GrRenderTargetOpList(GrRenderTargetProxy*, GrGpu*, GrAuditTrail*);
bsalomona73239a2015-04-28 13:35:17 -070040
Robert Phillipsf2361d22016-10-25 14:20:06 -040041 ~GrRenderTargetOpList() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000042
Robert Phillipsee683652017-04-26 11:53:10 -040043 void makeClosed(const GrCaps& caps) override {
Robert Phillipsf5442bb2017-04-17 14:18:34 -040044 if (this->isClosed()) {
45 return;
46 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040047
Robert Phillipsee683652017-04-26 11:53:10 -040048 this->forwardCombine(caps);
Robert Phillipsf5442bb2017-04-17 14:18:34 -040049
Robert Phillipsee683652017-04-26 11:53:10 -040050 INHERITED::makeClosed(caps);
robertphillipsa106c622015-10-16 09:07:06 -070051 }
bsalomonaecc0182016-03-07 11:50:44 -080052
Robert Phillipsf5442bb2017-04-17 14:18:34 -040053 bool isEmpty() const { return fRecordedOps.empty(); }
54
reed@google.comac10a2d2010-12-22 21:39:39 +000055 /**
bsalomona73239a2015-04-28 13:35:17 -070056 * Empties the draw buffer of any queued up draws.
57 */
Chris Daltona84cacf2017-10-04 10:30:29 -060058 void endFlush() override;
Robert Phillipsf2361d22016-10-25 14:20:06 -040059
60 void abandonGpuResources() override;
61 void freeGpuResources() override;
bsalomona73239a2015-04-28 13:35:17 -070062
63 /**
bsalomondc438982016-08-31 11:53:49 -070064 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
Brian Salomon1e41f4a2016-12-07 15:05:04 -050065 * of executeOps() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070066 */
Brian Osman407b3422017-08-22 15:01:32 -040067 void onPrepare(GrOpFlushState* flushState) override;
68 bool onExecute(GrOpFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070069
Robert Phillips5efd5ea2017-05-30 13:47:32 -040070 uint32_t addOp(std::unique_ptr<GrOp> op, const GrCaps& caps) {
Robert Phillipsb493eeb2017-09-13 13:10:52 -040071 auto addDependency = [ &caps, this ] (GrSurfaceProxy* p) {
72 this->addDependency(p, caps);
73 };
74
75 op->visitProxies(addDependency);
76
Robert Phillips9d6c64f2017-09-14 10:56:45 -040077 this->recordOp(std::move(op), caps);
Robert Phillipsb493eeb2017-09-13 13:10:52 -040078
Brian Salomon54d212e2017-03-21 14:22:38 -040079 return this->uniqueID();
80 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -040081
Robert Phillips5efd5ea2017-05-30 13:47:32 -040082 uint32_t addOp(std::unique_ptr<GrOp> op, const GrCaps& caps,
Robert Phillipsbb581ce2017-05-29 15:05:15 -040083 GrAppliedClip&& clip, const DstProxy& dstProxy) {
Robert Phillipsb493eeb2017-09-13 13:10:52 -040084 auto addDependency = [ &caps, this ] (GrSurfaceProxy* p) {
85 this->addDependency(p, caps);
86 };
87
88 op->visitProxies(addDependency);
89 clip.visitProxies(addDependency);
90
Robert Phillips5efd5ea2017-05-30 13:47:32 -040091 this->recordOp(std::move(op), caps, clip.doesClip() ? &clip : nullptr, &dstProxy);
Robert Phillipsb493eeb2017-09-13 13:10:52 -040092
Robert Phillipsc0138922017-03-08 11:50:55 -050093 return this->uniqueID();
Brian Salomon69868af2016-12-22 15:42:51 -050094 }
robertphillips9199a9f2016-07-13 07:48:43 -070095
Robert Phillips380b90c2017-08-30 07:41:07 -040096 void discard();
97
bsalomon9f129de2016-08-10 16:31:05 -070098 /** Clears the entire render target */
Robert Phillips5efd5ea2017-05-30 13:47:32 -040099 void fullClear(const GrCaps& caps, GrColor color);
bsalomon9f129de2016-08-10 16:31:05 -0700100
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000101 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000102 * Copies a pixel rectangle from one surface to another. This call may finalize
103 * reserved vertex/index data (as though a draw call was made). The src pixels
104 * copied are specified by srcRect. They are copied to a rect of the same
105 * size in dst with top left at dstPoint. If the src rect is clipped by the
106 * src bounds then pixel values in the dst rect corresponding to area clipped
bsalomon6df86402015-06-01 10:41:49 -0700107 * by the src rect are not overwritten. This method is not guaranteed to succeed
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000108 * depending on the type of surface, configs, etc, and the backend-specific
bsalomon6df86402015-06-01 10:41:49 -0700109 * limitations.
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000110 */
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400111 bool copySurface(const GrCaps& caps,
112 GrSurfaceProxy* dst,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400113 GrSurfaceProxy* src,
bsalomonf90a02b2014-11-26 12:28:00 -0800114 const SkIRect& srcRect,
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400115 const SkIPoint& dstPoint) override;
robertphillips@google.comff175842012-05-14 19:31:39 +0000116
csmartdaltone0d36292016-07-29 08:14:20 -0700117 gr_instanced::InstancedRendering* instancedRendering() const {
118 SkASSERT(fInstancedRendering);
Ben Wagner145dbcd2016-11-03 14:40:50 -0400119 return fInstancedRendering.get();
csmartdaltone0d36292016-07-29 08:14:20 -0700120 }
csmartdaltona7f29642016-07-07 08:49:11 -0700121
Brian Osman45580d32016-11-23 09:37:01 -0500122 GrRenderTargetOpList* asRenderTargetOpList() override { return this; }
123
Robert Phillipsf2361d22016-10-25 14:20:06 -0400124 SkDEBUGCODE(void dump() const override;)
125
Robert Phillipsc84c0302017-05-08 15:35:11 -0400126 SkDEBUGCODE(int numOps() const override { return fRecordedOps.count(); })
127 SkDEBUGCODE(int numClips() const override { return fNumClips; })
128
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000129private:
Robert Phillipsb9a02a12017-04-06 11:08:40 -0400130 friend class GrRenderTargetContextPriv; // for stencil clip state. TODO: this is invasive
robertphillips6a186652015-10-20 07:37:58 -0700131
Brian Salomon54d212e2017-03-21 14:22:38 -0400132 struct RecordedOp {
Brian Salomonbfd18cd2017-08-09 16:27:09 -0400133 RecordedOp(std::unique_ptr<GrOp> op, GrAppliedClip* appliedClip, const DstProxy* dstProxy)
134 : fOp(std::move(op)), fAppliedClip(appliedClip) {
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400135 if (dstProxy) {
136 fDstProxy = *dstProxy;
Brian Salomon54d212e2017-03-21 14:22:38 -0400137 }
138 }
Chris Dalton8816b932017-11-29 16:48:25 -0700139
140 void visitProxies(const GrOp::VisitProxyFunc& func) const {
141 if (fOp) {
142 fOp->visitProxies(func);
143 }
144 if (fDstProxy.proxy()) {
145 func(fDstProxy.proxy());
146 }
147 if (fAppliedClip) {
148 fAppliedClip->visitProxies(func);
149 }
150 }
151
Brian Salomon54d212e2017-03-21 14:22:38 -0400152 std::unique_ptr<GrOp> fOp;
Brian Salomonbfd18cd2017-08-09 16:27:09 -0400153 DstProxy fDstProxy;
154 GrAppliedClip* fAppliedClip;
Brian Salomon54d212e2017-03-21 14:22:38 -0400155 };
156
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400157 void gatherProxyIntervals(GrResourceAllocator*) const override;
158
Robert Phillips380b90c2017-08-30 07:41:07 -0400159 void recordOp(std::unique_ptr<GrOp>, const GrCaps& caps,
160 GrAppliedClip* = nullptr, const DstProxy* = nullptr);
Brian Salomon2790c522016-12-09 16:32:23 -0500161
Robert Phillipsee683652017-04-26 11:53:10 -0400162 void forwardCombine(const GrCaps&);
bsalomonad792c12015-09-10 11:10:50 -0700163
Brian Salomon54d212e2017-03-21 14:22:38 -0400164 // If this returns true then b has been merged into a's op.
165 bool combineIfPossible(const RecordedOp& a, GrOp* b, const GrAppliedClip* bClip,
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400166 const DstProxy* bDstTexture, const GrCaps&);
Brian Salomon69868af2016-12-22 15:42:51 -0500167
Ben Wagner145dbcd2016-11-03 14:40:50 -0400168 std::unique_ptr<gr_instanced::InstancedRendering> fInstancedRendering;
bsalomon6dea83f2015-12-03 12:58:06 -0800169
Robert Phillips806be2d2017-06-28 15:23:59 -0400170 uint32_t fLastClipStackGenID;
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400171 SkIRect fLastDevClipBounds;
Chris Dalton584a79a2017-11-15 13:14:01 -0700172 int fLastClipNumAnalyticFPs;
csmartdalton7cdda992016-11-01 07:03:03 -0700173
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400174 // For ops/opList we have mean: 5 stdDev: 28
175 SkSTArray<5, RecordedOp, true> fRecordedOps;
Brian Salomon54d212e2017-03-21 14:22:38 -0400176
Robert Phillipsf6d7eb12017-04-26 14:55:34 -0400177 // MDB TODO: 4096 for the first allocation of the clip space will be huge overkill.
178 // Gather statistics to determine the correct size.
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400179 SkArenaAlloc fClipAllocator{4096};
180 SkDEBUGCODE(int fNumClips;)
Brian Salomon54d212e2017-03-21 14:22:38 -0400181
Robert Phillipsf2361d22016-10-25 14:20:06 -0400182 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700183};
184
reed@google.comac10a2d2010-12-22 21:39:39 +0000185#endif