blob: 342f9278d5d932844ea541e9df35e55ed38b9217 [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 Phillipsee683652017-04-26 11:53:10 -040036 GrRenderTargetOpList(sk_sp<GrRenderTargetProxy>, GrGpu*, 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
Brian Salomon1e41f4a2016-12-07 15:05:04 -050045 fLastFullClearOp = nullptr;
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
Robert Phillipsf5442bb2017-04-17 14:18:34 -040051 bool isEmpty() const { return fRecordedOps.empty(); }
52
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 */
Robert Phillipsf2361d22016-10-25 14:20:06 -040056 void reset() override;
57
58 void abandonGpuResources() override;
59 void freeGpuResources() override;
bsalomona73239a2015-04-28 13:35:17 -070060
61 /**
bsalomondc438982016-08-31 11:53:49 -070062 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
Brian Salomon1e41f4a2016-12-07 15:05:04 -050063 * of executeOps() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070064 */
Brian Salomon742e31d2016-12-07 17:06:19 -050065 void prepareOps(GrOpFlushState* flushState) override;
66 bool executeOps(GrOpFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070067
Robert Phillipsc0138922017-03-08 11:50:55 -050068 uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext) {
Brian Salomon54d212e2017-03-21 14:22:38 -040069 this->recordOp(std::move(op), renderTargetContext, nullptr, nullptr);
70 return this->uniqueID();
71 }
72 uint32_t addOp(std::unique_ptr<GrOp> op, GrRenderTargetContext* renderTargetContext,
73 GrAppliedClip&& clip, const DstTexture& dstTexture) {
74 this->recordOp(std::move(op), renderTargetContext, clip.doesClip() ? &clip : nullptr,
75 &dstTexture);
Robert Phillipsc0138922017-03-08 11:50:55 -050076 return this->uniqueID();
Brian Salomon69868af2016-12-22 15:42:51 -050077 }
robertphillips9199a9f2016-07-13 07:48:43 -070078
bsalomon9f129de2016-08-10 16:31:05 -070079 /** Clears the entire render target */
Brian Salomon69868af2016-12-22 15:42:51 -050080 void fullClear(GrRenderTargetContext*, GrColor color);
bsalomon9f129de2016-08-10 16:31:05 -070081
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000082 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +000083 * Copies a pixel rectangle from one surface to another. This call may finalize
84 * reserved vertex/index data (as though a draw call was made). The src pixels
85 * copied are specified by srcRect. They are copied to a rect of the same
86 * size in dst with top left at dstPoint. If the src rect is clipped by the
87 * src bounds then pixel values in the dst rect corresponding to area clipped
bsalomon6df86402015-06-01 10:41:49 -070088 * by the src rect are not overwritten. This method is not guaranteed to succeed
bsalomon@google.come4617bf2013-04-03 14:56:40 +000089 * depending on the type of surface, configs, etc, and the backend-specific
bsalomon6df86402015-06-01 10:41:49 -070090 * limitations.
bsalomon@google.come4617bf2013-04-03 14:56:40 +000091 */
Robert Phillipsbf25d432017-04-07 10:08:53 -040092 bool copySurface(GrResourceProvider* resourceProvider,
Robert Phillips178ce3e2017-04-13 09:15:47 -040093 GrRenderTargetContext* dst,
Robert Phillipsbf25d432017-04-07 10:08:53 -040094 GrSurfaceProxy* src,
bsalomonf90a02b2014-11-26 12:28:00 -080095 const SkIRect& srcRect,
96 const SkIPoint& dstPoint);
robertphillips@google.comff175842012-05-14 19:31:39 +000097
csmartdaltone0d36292016-07-29 08:14:20 -070098 gr_instanced::InstancedRendering* instancedRendering() const {
99 SkASSERT(fInstancedRendering);
Ben Wagner145dbcd2016-11-03 14:40:50 -0400100 return fInstancedRendering.get();
csmartdaltone0d36292016-07-29 08:14:20 -0700101 }
csmartdaltona7f29642016-07-07 08:49:11 -0700102
Brian Osman45580d32016-11-23 09:37:01 -0500103 GrRenderTargetOpList* asRenderTargetOpList() override { return this; }
104
Robert Phillipsf2361d22016-10-25 14:20:06 -0400105 SkDEBUGCODE(void dump() const override;)
106
Robert Phillipsc589b0b2017-04-17 07:53:07 -0400107 SkDEBUGCODE(void validateTargetsSingleRenderTarget() const override;)
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400108
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000109private:
Robert Phillipsb9a02a12017-04-06 11:08:40 -0400110 friend class GrRenderTargetContextPriv; // for stencil clip state. TODO: this is invasive
robertphillips6a186652015-10-20 07:37:58 -0700111
Brian Salomon54d212e2017-03-21 14:22:38 -0400112 struct RecordedOp {
Robert Phillips1119dc32017-04-11 12:54:57 -0400113 RecordedOp(std::unique_ptr<GrOp> op,
114 GrRenderTarget* rt,
115 const GrAppliedClip* appliedClip,
Brian Salomon54d212e2017-03-21 14:22:38 -0400116 const DstTexture* dstTexture)
Robert Phillips1119dc32017-04-11 12:54:57 -0400117 : fOp(std::move(op))
118 , fRenderTarget(rt)
119 , fAppliedClip(appliedClip) {
Brian Salomon54d212e2017-03-21 14:22:38 -0400120 if (dstTexture) {
121 fDstTexture = *dstTexture;
122 }
123 }
124 std::unique_ptr<GrOp> fOp;
125 // TODO: These ops will all to target the same render target and this won't be needed.
126 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
127 DstTexture fDstTexture;
128 const GrAppliedClip* fAppliedClip;
129 };
130
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500131 // If the input op is combined with an earlier op, this returns the combined op. Otherwise, it
132 // returns the input op.
Brian Salomon54d212e2017-03-21 14:22:38 -0400133 GrOp* recordOp(std::unique_ptr<GrOp>, GrRenderTargetContext*, GrAppliedClip* = nullptr,
134 const DstTexture* = nullptr);
Brian Salomon2790c522016-12-09 16:32:23 -0500135
Robert Phillipsee683652017-04-26 11:53:10 -0400136 void forwardCombine(const GrCaps&);
bsalomonad792c12015-09-10 11:10:50 -0700137
Brian Salomon54d212e2017-03-21 14:22:38 -0400138 // If this returns true then b has been merged into a's op.
139 bool combineIfPossible(const RecordedOp& a, GrOp* b, const GrAppliedClip* bClip,
Robert Phillipsee683652017-04-26 11:53:10 -0400140 const DstTexture* bDstTexture, const GrCaps&);
Brian Salomon69868af2016-12-22 15:42:51 -0500141
142 GrClearOp* fLastFullClearOp = nullptr;
Robert Phillipsf7a72612017-03-31 10:03:45 -0400143 GrGpuResource::UniqueID fLastFullClearResourceID = GrGpuResource::UniqueID::InvalidID();
144 GrSurfaceProxy::UniqueID fLastFullClearProxyID = GrSurfaceProxy::UniqueID::InvalidID();
Brian Salomon69868af2016-12-22 15:42:51 -0500145
Ben Wagner145dbcd2016-11-03 14:40:50 -0400146 std::unique_ptr<gr_instanced::InstancedRendering> fInstancedRendering;
bsalomon6dea83f2015-12-03 12:58:06 -0800147
Brian Salomon7dae46a2016-12-14 16:21:37 -0500148 int32_t fLastClipStackGenID;
Brian Salomon9a767722017-03-13 17:57:28 -0400149 SkIRect fLastDevClipBounds;
csmartdalton7cdda992016-11-01 07:03:03 -0700150
Brian Salomon54d212e2017-03-21 14:22:38 -0400151 SkSTArray<256, RecordedOp, true> fRecordedOps;
152
Robert Phillipsf6d7eb12017-04-26 14:55:34 -0400153 // MDB TODO: 4096 for the first allocation of the clip space will be huge overkill.
154 // Gather statistics to determine the correct size.
155 SkArenaAlloc fClipAllocator{4096};
Brian Salomon54d212e2017-03-21 14:22:38 -0400156
Robert Phillipsf2361d22016-10-25 14:20:06 -0400157 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700158};
159
reed@google.comac10a2d2010-12-22 21:39:39 +0000160#endif