blob: dd265ed5019b2fbfa5233ffefe6dbfc1cd991107 [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"
15#include "SkArenaAlloc.h"
bsalomon@google.com8d67c072012-12-13 20:38:14 +000016#include "SkClipStack.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000017#include "SkMatrix.h"
reed1b55a962015-09-17 20:16:13 -070018#include "SkStringUtils.h"
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +000019#include "SkStrokeRec.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000020#include "SkTArray.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000021#include "SkTLazy.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000022#include "SkTypes.h"
Scroggo97c88c22011-05-11 14:05:25 +000023
joshualitt086cee12016-01-12 06:45:24 -080024class GrAuditTrail;
Brian Salomon7dae46a2016-12-14 16:21:37 -050025class GrClearOp;
bsalomon4b91f762015-05-19 09:29:46 -070026class GrCaps;
Brian Salomon25a88092016-12-01 09:36:50 -050027class GrOp;
robertphillips28a838e2016-06-23 14:07:00 -070028class GrPipelineBuilder;
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:
33 using DstTexture = GrXferProcessor::DstTexture;
34
bsalomon@google.comf6601872012-08-28 21:11:35 +000035public:
Robert Phillipsf2361d22016-10-25 14:20:06 -040036 /** Options for GrRenderTargetOpList behavior. */
bsalomon69cfe952015-11-30 13:27:47 -080037 struct Options {
Brian Salomon09d994e2016-12-21 11:14:46 -050038 int fMaxOpCombineLookback = -1;
39 int fMaxOpCombineLookahead = -1;
bsalomon69cfe952015-11-30 13:27:47 -080040 };
41
Robert Phillipsdc83b892017-04-13 12:23:54 -040042 GrRenderTargetOpList(sk_sp<GrRenderTargetProxy>, GrGpu*, GrResourceProvider*,
Robert Phillipsf2361d22016-10-25 14:20:06 -040043 GrAuditTrail*, const Options&);
bsalomona73239a2015-04-28 13:35:17 -070044
Robert Phillipsf2361d22016-10-25 14:20:06 -040045 ~GrRenderTargetOpList() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000046
Robert Phillipsf2361d22016-10-25 14:20:06 -040047 void makeClosed() override {
Robert Phillipsf5442bb2017-04-17 14:18:34 -040048 if (this->isClosed()) {
49 return;
50 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040051
Brian Salomon1e41f4a2016-12-07 15:05:04 -050052 fLastFullClearOp = nullptr;
bsalomonaecc0182016-03-07 11:50:44 -080053 this->forwardCombine();
Robert Phillipsf5442bb2017-04-17 14:18:34 -040054
55 INHERITED::makeClosed();
robertphillipsa106c622015-10-16 09:07:06 -070056 }
bsalomonaecc0182016-03-07 11:50:44 -080057
Robert Phillipsf5442bb2017-04-17 14:18:34 -040058 bool isEmpty() const { return fRecordedOps.empty(); }
59
reed@google.comac10a2d2010-12-22 21:39:39 +000060 /**
bsalomona73239a2015-04-28 13:35:17 -070061 * Empties the draw buffer of any queued up draws.
62 */
Robert Phillipsf2361d22016-10-25 14:20:06 -040063 void reset() override;
64
65 void abandonGpuResources() override;
66 void freeGpuResources() override;
bsalomona73239a2015-04-28 13:35:17 -070067
68 /**
bsalomondc438982016-08-31 11:53:49 -070069 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
Brian Salomon1e41f4a2016-12-07 15:05:04 -050070 * of executeOps() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070071 */
Brian Salomon742e31d2016-12-07 17:06:19 -050072 void prepareOps(GrOpFlushState* flushState) override;
73 bool executeOps(GrOpFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070074
75 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000076 * Gets the capabilities of the draw target.
77 */
bsalomonb3b9aec2015-09-10 11:16:35 -070078 const GrCaps* caps() const { return fGpu->caps(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000079
Robert Phillipsc0138922017-03-08 11:50:55 -050080 uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext) {
Brian Salomon54d212e2017-03-21 14:22:38 -040081 this->recordOp(std::move(op), renderTargetContext, nullptr, nullptr);
82 return this->uniqueID();
83 }
84 uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext,
85 GrAppliedClip&& clip, const DstTexture& dstTexture) {
86 this->recordOp(std::move(op), renderTargetContext, clip.doesClip() ? &clip : nullptr,
87 &dstTexture);
Robert Phillipsc0138922017-03-08 11:50:55 -050088 return this->uniqueID();
Brian Salomon69868af2016-12-22 15:42:51 -050089 }
robertphillips9199a9f2016-07-13 07:48:43 -070090
bsalomon9f129de2016-08-10 16:31:05 -070091 /** Clears the entire render target */
Brian Salomon69868af2016-12-22 15:42:51 -050092 void fullClear(GrRenderTargetContext*, GrColor 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 Phillipsbf25d432017-04-07 10:08:53 -0400104 bool copySurface(GrResourceProvider* resourceProvider,
Robert Phillips178ce3e2017-04-13 09:15:47 -0400105 GrRenderTargetContext* dst,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400106 GrSurfaceProxy* src,
bsalomonf90a02b2014-11-26 12:28:00 -0800107 const SkIRect& srcRect,
108 const SkIPoint& dstPoint);
robertphillips@google.comff175842012-05-14 19:31:39 +0000109
csmartdaltone0d36292016-07-29 08:14:20 -0700110 gr_instanced::InstancedRendering* instancedRendering() const {
111 SkASSERT(fInstancedRendering);
Ben Wagner145dbcd2016-11-03 14:40:50 -0400112 return fInstancedRendering.get();
csmartdaltone0d36292016-07-29 08:14:20 -0700113 }
csmartdaltona7f29642016-07-07 08:49:11 -0700114
Brian Osman45580d32016-11-23 09:37:01 -0500115 GrRenderTargetOpList* asRenderTargetOpList() override { return this; }
116
Robert Phillipsf2361d22016-10-25 14:20:06 -0400117 SkDEBUGCODE(void dump() const override;)
118
Robert Phillipsc589b0b2017-04-17 07:53:07 -0400119 SkDEBUGCODE(void validateTargetsSingleRenderTarget() const override;)
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400120
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000121private:
Robert Phillipsb9a02a12017-04-06 11:08:40 -0400122 friend class GrRenderTargetContextPriv; // for stencil clip state. TODO: this is invasive
robertphillips6a186652015-10-20 07:37:58 -0700123
Brian Salomon54d212e2017-03-21 14:22:38 -0400124 struct RecordedOp {
Robert Phillips1119dc32017-04-11 12:54:57 -0400125 RecordedOp(std::unique_ptr<GrOp> op,
126 GrRenderTarget* rt,
127 const GrAppliedClip* appliedClip,
Brian Salomon54d212e2017-03-21 14:22:38 -0400128 const DstTexture* dstTexture)
Robert Phillips1119dc32017-04-11 12:54:57 -0400129 : fOp(std::move(op))
130 , fRenderTarget(rt)
131 , fAppliedClip(appliedClip) {
Brian Salomon54d212e2017-03-21 14:22:38 -0400132 if (dstTexture) {
133 fDstTexture = *dstTexture;
134 }
135 }
136 std::unique_ptr<GrOp> fOp;
137 // TODO: These ops will all to target the same render target and this won't be needed.
138 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
139 DstTexture fDstTexture;
140 const GrAppliedClip* fAppliedClip;
141 };
142
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500143 // If the input op is combined with an earlier op, this returns the combined op. Otherwise, it
144 // returns the input op.
Brian Salomon54d212e2017-03-21 14:22:38 -0400145 GrOp* recordOp(std::unique_ptr<GrOp>, GrRenderTargetContext*, GrAppliedClip* = nullptr,
146 const DstTexture* = nullptr);
Brian Salomon2790c522016-12-09 16:32:23 -0500147
bsalomonaecc0182016-03-07 11:50:44 -0800148 void forwardCombine();
bsalomonad792c12015-09-10 11:10:50 -0700149
Brian Salomon54d212e2017-03-21 14:22:38 -0400150 // If this returns true then b has been merged into a's op.
151 bool combineIfPossible(const RecordedOp& a, GrOp* b, const GrAppliedClip* bClip,
152 const DstTexture* bDstTexture);
Brian Salomon69868af2016-12-22 15:42:51 -0500153
154 GrClearOp* fLastFullClearOp = nullptr;
Robert Phillipsf7a72612017-03-31 10:03:45 -0400155 GrGpuResource::UniqueID fLastFullClearResourceID = GrGpuResource::UniqueID::InvalidID();
156 GrSurfaceProxy::UniqueID fLastFullClearProxyID = GrSurfaceProxy::UniqueID::InvalidID();
Brian Salomon69868af2016-12-22 15:42:51 -0500157
Brian Salomon7dae46a2016-12-14 16:21:37 -0500158 GrGpu* fGpu;
159 GrResourceProvider* fResourceProvider;
joshualitt3bdd7dc2014-10-31 08:27:39 -0700160
Brian Salomon7dae46a2016-12-14 16:21:37 -0500161 int fMaxOpLookback;
162 int fMaxOpLookahead;
csmartdaltona7f29642016-07-07 08:49:11 -0700163
Ben Wagner145dbcd2016-11-03 14:40:50 -0400164 std::unique_ptr<gr_instanced::InstancedRendering> fInstancedRendering;
bsalomon6dea83f2015-12-03 12:58:06 -0800165
Brian Salomon7dae46a2016-12-14 16:21:37 -0500166 int32_t fLastClipStackGenID;
Brian Salomon9a767722017-03-13 17:57:28 -0400167 SkIRect fLastDevClipBounds;
csmartdalton7cdda992016-11-01 07:03:03 -0700168
Brian Salomon54d212e2017-03-21 14:22:38 -0400169 SkSTArray<256, RecordedOp, true> fRecordedOps;
170
171 char fClipAllocatorStorage[4096];
172 SkArenaAlloc fClipAllocator;
173
Robert Phillipsf2361d22016-10-25 14:20:06 -0400174 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700175};
176
reed@google.comac10a2d2010-12-22 21:39:39 +0000177#endif