blob: a66686040b27708d331fc9a184e5d1fd53a4bda8 [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
joshualitt44701df2015-02-23 14:44:57 -080011#include "GrClip.h"
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000012#include "GrContext.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040013#include "GrOpList.h"
joshualitt8072caa2015-02-12 14:20:52 -080014#include "GrPathProcessor.h"
15#include "GrPrimitiveProcessor.h"
kkinnunenccdaa042014-08-20 01:36:23 -070016#include "GrPathRendering.h"
bsalomon6a44c6a2015-05-26 09:49:05 -070017#include "GrXferProcessor.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000018
Brian Salomon89527432016-12-16 09:52:16 -050019#include "ops/GrDrawOp.h"
bsalomon473addf2015-10-02 07:49:05 -070020
bsalomon@google.com8d67c072012-12-13 20:38:14 +000021#include "SkClipStack.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000022#include "SkMatrix.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000023#include "SkPath.h"
reed1b55a962015-09-17 20:16:13 -070024#include "SkStringUtils.h"
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +000025#include "SkStrokeRec.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000026#include "SkTArray.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000027#include "SkTLazy.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000028#include "SkTypes.h"
Scroggo97c88c22011-05-11 14:05:25 +000029
joshualitt086cee12016-01-12 06:45:24 -080030class GrAuditTrail;
Brian Salomon7dae46a2016-12-14 16:21:37 -050031class GrClearOp;
joshualitt44701df2015-02-23 14:44:57 -080032class GrClip;
bsalomon4b91f762015-05-19 09:29:46 -070033class GrCaps;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000034class GrPath;
Brian Salomon82c263f2016-12-15 09:54:06 -050035class GrDrawPathOpBase;
Brian Salomon25a88092016-12-01 09:36:50 -050036class GrOp;
robertphillips28a838e2016-06-23 14:07:00 -070037class GrPipelineBuilder;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040038class GrRenderTargetProxy;
sugoi@google.com12b4e272012-12-06 20:13:11 +000039
Robert Phillipsf2361d22016-10-25 14:20:06 -040040class GrRenderTargetOpList final : public GrOpList {
bsalomon@google.comf6601872012-08-28 21:11:35 +000041public:
Robert Phillipsf2361d22016-10-25 14:20:06 -040042 /** Options for GrRenderTargetOpList behavior. */
bsalomon69cfe952015-11-30 13:27:47 -080043 struct Options {
Brian Salomon09d994e2016-12-21 11:14:46 -050044 bool fClipDrawOpsToBounds = false;
45 int fMaxOpCombineLookback = -1;
46 int fMaxOpCombineLookahead = -1;
bsalomon69cfe952015-11-30 13:27:47 -080047 };
48
Robert Phillipsc7635fa2016-10-28 13:25:24 -040049 GrRenderTargetOpList(GrRenderTargetProxy*, GrGpu*, GrResourceProvider*,
Robert Phillipsf2361d22016-10-25 14:20:06 -040050 GrAuditTrail*, const Options&);
bsalomona73239a2015-04-28 13:35:17 -070051
Robert Phillipsf2361d22016-10-25 14:20:06 -040052 ~GrRenderTargetOpList() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000053
Robert Phillipsf2361d22016-10-25 14:20:06 -040054 void makeClosed() override {
55 INHERITED::makeClosed();
56
Brian Salomon1e41f4a2016-12-07 15:05:04 -050057 fLastFullClearOp = nullptr;
bsalomonaecc0182016-03-07 11:50:44 -080058 this->forwardCombine();
robertphillipsa106c622015-10-16 09:07:06 -070059 }
bsalomonaecc0182016-03-07 11:50:44 -080060
reed@google.comac10a2d2010-12-22 21:39:39 +000061 /**
bsalomona73239a2015-04-28 13:35:17 -070062 * Empties the draw buffer of any queued up draws.
63 */
Robert Phillipsf2361d22016-10-25 14:20:06 -040064 void reset() override;
65
66 void abandonGpuResources() override;
67 void freeGpuResources() override;
bsalomona73239a2015-04-28 13:35:17 -070068
69 /**
bsalomondc438982016-08-31 11:53:49 -070070 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
Brian Salomon1e41f4a2016-12-07 15:05:04 -050071 * of executeOps() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070072 */
Brian Salomon742e31d2016-12-07 17:06:19 -050073 void prepareOps(GrOpFlushState* flushState) override;
74 bool executeOps(GrOpFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070075
76 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000077 * Gets the capabilities of the draw target.
78 */
bsalomonb3b9aec2015-09-10 11:16:35 -070079 const GrCaps* caps() const { return fGpu->caps(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000080
Brian Salomon21aa35f2016-12-09 16:01:53 -050081 void addDrawOp(const GrPipelineBuilder&, GrRenderTargetContext*, const GrClip&,
82 sk_sp<GrDrawOp>);
joshualitt4d8da812015-01-28 12:53:54 -080083
Brian Salomon69868af2016-12-22 15:42:51 -050084 void addOp(sk_sp<GrOp> op, GrRenderTargetContext* renderTargetContext) {
85 this->recordOp(std::move(op), renderTargetContext);
86 }
robertphillips9199a9f2016-07-13 07:48:43 -070087
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000088 /**
csmartdalton5c6fc4f2016-08-12 15:11:51 -070089 * Draws the path into user stencil bits. Upon return, all user stencil values
90 * inside the path will be nonzero. The path's fill must be either even/odd or
91 * winding (notnverse or hairline).It will respect the HW antialias boolean (if
92 * possible in the 3D API). Note, we will never have an inverse fill with
93 * stencil path.
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000094 */
Brian Osman11052242016-10-27 14:47:55 -040095 void stencilPath(GrRenderTargetContext*,
robertphillips59cf61a2016-07-13 09:18:21 -070096 const GrClip&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050097 GrAAType aa,
robertphillips59cf61a2016-07-13 09:18:21 -070098 const SkMatrix& viewMatrix,
99 const GrPath*);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000100
bsalomon9f129de2016-08-10 16:31:05 -0700101 /** Clears the entire render target */
Brian Salomon69868af2016-12-22 15:42:51 -0500102 void fullClear(GrRenderTargetContext*, GrColor color);
bsalomon9f129de2016-08-10 16:31:05 -0700103
bsalomon53469832015-08-18 09:20:09 -0700104 /** Discards the contents render target. */
Brian Salomon69868af2016-12-22 15:42:51 -0500105 void discard(GrRenderTargetContext*);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000106
107 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000108 * Copies a pixel rectangle from one surface to another. This call may finalize
109 * reserved vertex/index data (as though a draw call was made). The src pixels
110 * copied are specified by srcRect. They are copied to a rect of the same
111 * size in dst with top left at dstPoint. If the src rect is clipped by the
112 * src bounds then pixel values in the dst rect corresponding to area clipped
bsalomon6df86402015-06-01 10:41:49 -0700113 * by the src rect are not overwritten. This method is not guaranteed to succeed
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000114 * depending on the type of surface, configs, etc, and the backend-specific
bsalomon6df86402015-06-01 10:41:49 -0700115 * limitations.
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000116 */
bsalomonb8fea972016-02-16 07:34:17 -0800117 bool copySurface(GrSurface* dst,
bsalomonf90a02b2014-11-26 12:28:00 -0800118 GrSurface* src,
119 const SkIRect& srcRect,
120 const SkIPoint& dstPoint);
robertphillips@google.comff175842012-05-14 19:31:39 +0000121
csmartdaltone0d36292016-07-29 08:14:20 -0700122 gr_instanced::InstancedRendering* instancedRendering() const {
123 SkASSERT(fInstancedRendering);
Ben Wagner145dbcd2016-11-03 14:40:50 -0400124 return fInstancedRendering.get();
csmartdaltone0d36292016-07-29 08:14:20 -0700125 }
csmartdaltona7f29642016-07-07 08:49:11 -0700126
Brian Osman45580d32016-11-23 09:37:01 -0500127 GrRenderTargetOpList* asRenderTargetOpList() override { return this; }
128
Robert Phillipsf2361d22016-10-25 14:20:06 -0400129 SkDEBUGCODE(void dump() const override;)
130
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000131private:
csmartdalton7cdda992016-11-01 07:03:03 -0700132 friend class GrRenderTargetContextPriv; // for clearStencilClip and stencil clip state.
robertphillips6a186652015-10-20 07:37:58 -0700133
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500134 // If the input op is combined with an earlier op, this returns the combined op. Otherwise, it
135 // returns the input op.
Brian Salomon69868af2016-12-22 15:42:51 -0500136 GrOp* recordOp(sk_sp<GrOp> op, GrRenderTargetContext* renderTargetContext) {
Brian Salomon2790c522016-12-09 16:32:23 -0500137 SkRect bounds = op->bounds();
Brian Salomon69868af2016-12-22 15:42:51 -0500138 return this->recordOp(std::move(op), renderTargetContext, bounds);
Brian Salomon2790c522016-12-09 16:32:23 -0500139 }
140
141 // Variant that allows an explicit bounds (computed from the Op's bounds and a clip).
Brian Salomon69868af2016-12-22 15:42:51 -0500142 GrOp* recordOp(sk_sp<GrOp>, GrRenderTargetContext*, const SkRect& clippedBounds);
Brian Salomon2790c522016-12-09 16:32:23 -0500143
bsalomonaecc0182016-03-07 11:50:44 -0800144 void forwardCombine();
bsalomonad792c12015-09-10 11:10:50 -0700145
Brian Salomon5b7b49f2016-12-07 14:31:00 -0500146 // Makes a copy of the dst if it is necessary for the draw and returns the texture that should
147 // be used by GrXferProcessor to access the destination color. If the texture is nullptr then
148 // a texture copy could not be made.
149 void setupDstTexture(GrRenderTarget*,
150 const GrClip&,
Brian Salomon09d994e2016-12-21 11:14:46 -0500151 const SkRect& opBounds,
Brian Salomon5b7b49f2016-12-07 14:31:00 -0500152 GrXferProcessor::DstTexture*);
bsalomonad792c12015-09-10 11:10:50 -0700153
Brian Osman693a5402016-10-27 15:13:22 -0400154 // Used only via GrRenderTargetContextPriv.
Brian Salomon69868af2016-12-22 15:42:51 -0500155 void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTargetContext*);
joshualitt6db519c2014-10-29 08:48:18 -0700156
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500157 struct RecordedOp {
158 sk_sp<GrOp> fOp;
159 SkRect fClippedBounds;
Brian Salomon69868af2016-12-22 15:42:51 -0500160 // TODO: Use proxy ID instead of instantiated render target ID.
161 GrGpuResource::UniqueID fRenderTargetID;
bsalomon6cc90062016-07-08 11:31:22 -0700162 };
Brian Salomon7dae46a2016-12-14 16:21:37 -0500163 SkSTArray<256, RecordedOp, true> fRecordedOps;
Brian Salomon69868af2016-12-22 15:42:51 -0500164
165 GrClearOp* fLastFullClearOp = nullptr;
166 GrGpuResource::UniqueID fLastFullClearRenderTargetID = GrGpuResource::UniqueID::InvalidID();
167
csmartdaltonc6f411e2016-08-05 22:32:12 -0700168 // The context is only in service of the GrClip, remove once it doesn't need this.
Brian Salomon7dae46a2016-12-14 16:21:37 -0500169 GrContext* fContext;
170 GrGpu* fGpu;
171 GrResourceProvider* fResourceProvider;
joshualitt3bdd7dc2014-10-31 08:27:39 -0700172
Brian Salomon7dae46a2016-12-14 16:21:37 -0500173 bool fClipOpToBounds;
174 int fMaxOpLookback;
175 int fMaxOpLookahead;
csmartdaltona7f29642016-07-07 08:49:11 -0700176
Ben Wagner145dbcd2016-11-03 14:40:50 -0400177 std::unique_ptr<gr_instanced::InstancedRendering> fInstancedRendering;
bsalomon6dea83f2015-12-03 12:58:06 -0800178
Brian Salomon7dae46a2016-12-14 16:21:37 -0500179 int32_t fLastClipStackGenID;
180 SkIRect fLastClipStackRect;
181 SkIPoint fLastClipOrigin;
csmartdalton7cdda992016-11-01 07:03:03 -0700182
Robert Phillipsf2361d22016-10-25 14:20:06 -0400183 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700184};
185
reed@google.comac10a2d2010-12-22 21:39:39 +0000186#endif