blob: c44c3416e37989bb196c83540b2f1028aae11412 [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 Phillipsc7635fa2016-10-28 13:25:24 -040042 GrRenderTargetOpList(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 {
48 INHERITED::makeClosed();
49
Brian Salomon1e41f4a2016-12-07 15:05:04 -050050 fLastFullClearOp = nullptr;
bsalomonaecc0182016-03-07 11:50:44 -080051 this->forwardCombine();
robertphillipsa106c622015-10-16 09:07:06 -070052 }
bsalomonaecc0182016-03-07 11:50:44 -080053
reed@google.comac10a2d2010-12-22 21:39:39 +000054 /**
bsalomona73239a2015-04-28 13:35:17 -070055 * Empties the draw buffer of any queued up draws.
56 */
Robert Phillipsf2361d22016-10-25 14:20:06 -040057 void reset() override;
58
59 void abandonGpuResources() override;
60 void freeGpuResources() override;
bsalomona73239a2015-04-28 13:35:17 -070061
62 /**
bsalomondc438982016-08-31 11:53:49 -070063 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
Brian Salomon1e41f4a2016-12-07 15:05:04 -050064 * of executeOps() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070065 */
Brian Salomon742e31d2016-12-07 17:06:19 -050066 void prepareOps(GrOpFlushState* flushState) override;
67 bool executeOps(GrOpFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070068
69 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000070 * Gets the capabilities of the draw target.
71 */
bsalomonb3b9aec2015-09-10 11:16:35 -070072 const GrCaps* caps() const { return fGpu->caps(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000073
Robert Phillipsc0138922017-03-08 11:50:55 -050074 uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext) {
Brian Salomon54d212e2017-03-21 14:22:38 -040075 this->recordOp(std::move(op), renderTargetContext, nullptr, nullptr);
76 return this->uniqueID();
77 }
78 uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext,
79 GrAppliedClip&& clip, const DstTexture& dstTexture) {
80 this->recordOp(std::move(op), renderTargetContext, clip.doesClip() ? &clip : nullptr,
81 &dstTexture);
Robert Phillipsc0138922017-03-08 11:50:55 -050082 return this->uniqueID();
Brian Salomon69868af2016-12-22 15:42:51 -050083 }
robertphillips9199a9f2016-07-13 07:48:43 -070084
bsalomon9f129de2016-08-10 16:31:05 -070085 /** Clears the entire render target */
Brian Salomon69868af2016-12-22 15:42:51 -050086 void fullClear(GrRenderTargetContext*, GrColor color);
bsalomon9f129de2016-08-10 16:31:05 -070087
bsalomon53469832015-08-18 09:20:09 -070088 /** Discards the contents render target. */
Brian Salomon69868af2016-12-22 15:42:51 -050089 void discard(GrRenderTargetContext*);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000090
91 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +000092 * Copies a pixel rectangle from one surface to another. This call may finalize
93 * reserved vertex/index data (as though a draw call was made). The src pixels
94 * copied are specified by srcRect. They are copied to a rect of the same
95 * size in dst with top left at dstPoint. If the src rect is clipped by the
96 * src bounds then pixel values in the dst rect corresponding to area clipped
bsalomon6df86402015-06-01 10:41:49 -070097 * by the src rect are not overwritten. This method is not guaranteed to succeed
bsalomon@google.come4617bf2013-04-03 14:56:40 +000098 * depending on the type of surface, configs, etc, and the backend-specific
bsalomon6df86402015-06-01 10:41:49 -070099 * limitations.
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000100 */
bsalomonb8fea972016-02-16 07:34:17 -0800101 bool copySurface(GrSurface* dst,
bsalomonf90a02b2014-11-26 12:28:00 -0800102 GrSurface* src,
103 const SkIRect& srcRect,
104 const SkIPoint& dstPoint);
robertphillips@google.comff175842012-05-14 19:31:39 +0000105
csmartdaltone0d36292016-07-29 08:14:20 -0700106 gr_instanced::InstancedRendering* instancedRendering() const {
107 SkASSERT(fInstancedRendering);
Ben Wagner145dbcd2016-11-03 14:40:50 -0400108 return fInstancedRendering.get();
csmartdaltone0d36292016-07-29 08:14:20 -0700109 }
csmartdaltona7f29642016-07-07 08:49:11 -0700110
Brian Osman45580d32016-11-23 09:37:01 -0500111 GrRenderTargetOpList* asRenderTargetOpList() override { return this; }
112
Robert Phillipsf2361d22016-10-25 14:20:06 -0400113 SkDEBUGCODE(void dump() const override;)
114
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400115 SkDEBUGCODE(void validateTargetsSingleRenderTarget() const;)
116
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000117private:
csmartdalton7cdda992016-11-01 07:03:03 -0700118 friend class GrRenderTargetContextPriv; // for clearStencilClip and stencil clip state.
robertphillips6a186652015-10-20 07:37:58 -0700119
Brian Salomon54d212e2017-03-21 14:22:38 -0400120 struct RecordedOp {
121 RecordedOp(std::unique_ptr<GrOp> op, GrRenderTarget* rt, const GrAppliedClip* appliedClip,
122 const DstTexture* dstTexture)
123 : fOp(std::move(op)), fRenderTarget(rt), fAppliedClip(appliedClip) {
124 if (dstTexture) {
125 fDstTexture = *dstTexture;
126 }
127 }
128 std::unique_ptr<GrOp> fOp;
129 // TODO: These ops will all to target the same render target and this won't be needed.
130 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
131 DstTexture fDstTexture;
132 const GrAppliedClip* fAppliedClip;
133 };
134
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500135 // If the input op is combined with an earlier op, this returns the combined op. Otherwise, it
136 // returns the input op.
Brian Salomon54d212e2017-03-21 14:22:38 -0400137 GrOp* recordOp(std::unique_ptr<GrOp>, GrRenderTargetContext*, GrAppliedClip* = nullptr,
138 const DstTexture* = nullptr);
Brian Salomon2790c522016-12-09 16:32:23 -0500139
bsalomonaecc0182016-03-07 11:50:44 -0800140 void forwardCombine();
bsalomonad792c12015-09-10 11:10:50 -0700141
Brian Osman693a5402016-10-27 15:13:22 -0400142 // Used only via GrRenderTargetContextPriv.
Brian Salomon69868af2016-12-22 15:42:51 -0500143 void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTargetContext*);
joshualitt6db519c2014-10-29 08:48:18 -0700144
Brian Salomon54d212e2017-03-21 14:22:38 -0400145 // If this returns true then b has been merged into a's op.
146 bool combineIfPossible(const RecordedOp& a, GrOp* b, const GrAppliedClip* bClip,
147 const DstTexture* bDstTexture);
Brian Salomon69868af2016-12-22 15:42:51 -0500148
149 GrClearOp* fLastFullClearOp = nullptr;
150 GrGpuResource::UniqueID fLastFullClearRenderTargetID = GrGpuResource::UniqueID::InvalidID();
151
Brian Salomon7dae46a2016-12-14 16:21:37 -0500152 GrGpu* fGpu;
153 GrResourceProvider* fResourceProvider;
joshualitt3bdd7dc2014-10-31 08:27:39 -0700154
Brian Salomon7dae46a2016-12-14 16:21:37 -0500155 int fMaxOpLookback;
156 int fMaxOpLookahead;
csmartdaltona7f29642016-07-07 08:49:11 -0700157
Ben Wagner145dbcd2016-11-03 14:40:50 -0400158 std::unique_ptr<gr_instanced::InstancedRendering> fInstancedRendering;
bsalomon6dea83f2015-12-03 12:58:06 -0800159
Brian Salomon7dae46a2016-12-14 16:21:37 -0500160 int32_t fLastClipStackGenID;
Brian Salomon9a767722017-03-13 17:57:28 -0400161 SkIRect fLastDevClipBounds;
csmartdalton7cdda992016-11-01 07:03:03 -0700162
Brian Salomon54d212e2017-03-21 14:22:38 -0400163 SkSTArray<256, RecordedOp, true> fRecordedOps;
164
165 char fClipAllocatorStorage[4096];
166 SkArenaAlloc fClipAllocator;
167
Robert Phillipsf2361d22016-10-25 14:20:06 -0400168 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700169};
170
reed@google.comac10a2d2010-12-22 21:39:39 +0000171#endif