blob: e9611325b263413fcce096245c3433000780d720 [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 Salomon9afd3712016-12-01 10:59:09 -050019#include "batches/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;
bsalomonfd8d0132016-08-11 11:25:33 -070031class GrClearBatch;
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;
bsalomon1fcc01c2015-09-09 09:48:06 -070035class GrDrawPathBatchBase;
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 {
bsalomonaecc0182016-03-07 11:50:44 -080044 Options ()
45 : fClipBatchToBounds(false)
bsalomonaecc0182016-03-07 11:50:44 -080046 , fMaxBatchLookback(-1)
47 , fMaxBatchLookahead(-1) {}
bsalomon69cfe952015-11-30 13:27:47 -080048 bool fClipBatchToBounds;
bsalomon489147c2015-12-14 12:13:09 -080049 int fMaxBatchLookback;
bsalomonaecc0182016-03-07 11:50:44 -080050 int fMaxBatchLookahead;
bsalomon69cfe952015-11-30 13:27:47 -080051 };
52
Robert Phillipsc7635fa2016-10-28 13:25:24 -040053 GrRenderTargetOpList(GrRenderTargetProxy*, GrGpu*, GrResourceProvider*,
Robert Phillipsf2361d22016-10-25 14:20:06 -040054 GrAuditTrail*, const Options&);
bsalomona73239a2015-04-28 13:35:17 -070055
Robert Phillipsf2361d22016-10-25 14:20:06 -040056 ~GrRenderTargetOpList() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000057
Robert Phillipsf2361d22016-10-25 14:20:06 -040058 void makeClosed() override {
59 INHERITED::makeClosed();
60
Brian Salomon1e41f4a2016-12-07 15:05:04 -050061 fLastFullClearOp = nullptr;
bsalomonaecc0182016-03-07 11:50:44 -080062 this->forwardCombine();
robertphillipsa106c622015-10-16 09:07:06 -070063 }
bsalomonaecc0182016-03-07 11:50:44 -080064
reed@google.comac10a2d2010-12-22 21:39:39 +000065 /**
bsalomona73239a2015-04-28 13:35:17 -070066 * Empties the draw buffer of any queued up draws.
67 */
Robert Phillipsf2361d22016-10-25 14:20:06 -040068 void reset() override;
69
70 void abandonGpuResources() override;
71 void freeGpuResources() override;
bsalomona73239a2015-04-28 13:35:17 -070072
73 /**
bsalomondc438982016-08-31 11:53:49 -070074 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
Brian Salomon1e41f4a2016-12-07 15:05:04 -050075 * of executeOps() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070076 */
Brian Salomon742e31d2016-12-07 17:06:19 -050077 void prepareOps(GrOpFlushState* flushState) override;
78 bool executeOps(GrOpFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070079
80 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000081 * Gets the capabilities of the draw target.
82 */
bsalomonb3b9aec2015-09-10 11:16:35 -070083 const GrCaps* caps() const { return fGpu->caps(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000084
Brian Salomon21aa35f2016-12-09 16:01:53 -050085 void addDrawOp(const GrPipelineBuilder&, GrRenderTargetContext*, const GrClip&,
86 sk_sp<GrDrawOp>);
joshualitt4d8da812015-01-28 12:53:54 -080087
Brian Salomon2790c522016-12-09 16:32:23 -050088 void addOp(sk_sp<GrOp> op) { this->recordOp(std::move(op)); }
robertphillips9199a9f2016-07-13 07:48:43 -070089
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000090 /**
csmartdalton5c6fc4f2016-08-12 15:11:51 -070091 * Draws the path into user stencil bits. Upon return, all user stencil values
92 * inside the path will be nonzero. The path's fill must be either even/odd or
93 * winding (notnverse or hairline).It will respect the HW antialias boolean (if
94 * possible in the 3D API). Note, we will never have an inverse fill with
95 * stencil path.
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000096 */
Brian Osman11052242016-10-27 14:47:55 -040097 void stencilPath(GrRenderTargetContext*,
robertphillips59cf61a2016-07-13 09:18:21 -070098 const GrClip&,
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050099 GrAAType aa,
robertphillips59cf61a2016-07-13 09:18:21 -0700100 const SkMatrix& viewMatrix,
101 const GrPath*);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000102
bsalomon9f129de2016-08-10 16:31:05 -0700103 /** Clears the entire render target */
104 void fullClear(GrRenderTarget*, GrColor color);
105
bsalomon53469832015-08-18 09:20:09 -0700106 /** Discards the contents render target. */
107 void discard(GrRenderTarget*);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000108
109 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000110 * Copies a pixel rectangle from one surface to another. This call may finalize
111 * reserved vertex/index data (as though a draw call was made). The src pixels
112 * copied are specified by srcRect. They are copied to a rect of the same
113 * size in dst with top left at dstPoint. If the src rect is clipped by the
114 * src bounds then pixel values in the dst rect corresponding to area clipped
bsalomon6df86402015-06-01 10:41:49 -0700115 * by the src rect are not overwritten. This method is not guaranteed to succeed
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000116 * depending on the type of surface, configs, etc, and the backend-specific
bsalomon6df86402015-06-01 10:41:49 -0700117 * limitations.
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000118 */
bsalomonb8fea972016-02-16 07:34:17 -0800119 bool copySurface(GrSurface* dst,
bsalomonf90a02b2014-11-26 12:28:00 -0800120 GrSurface* src,
121 const SkIRect& srcRect,
122 const SkIPoint& dstPoint);
robertphillips@google.comff175842012-05-14 19:31:39 +0000123
csmartdaltone0d36292016-07-29 08:14:20 -0700124 gr_instanced::InstancedRendering* instancedRendering() const {
125 SkASSERT(fInstancedRendering);
Ben Wagner145dbcd2016-11-03 14:40:50 -0400126 return fInstancedRendering.get();
csmartdaltone0d36292016-07-29 08:14:20 -0700127 }
csmartdaltona7f29642016-07-07 08:49:11 -0700128
Brian Osman45580d32016-11-23 09:37:01 -0500129 GrRenderTargetOpList* asRenderTargetOpList() override { return this; }
130
Robert Phillipsf2361d22016-10-25 14:20:06 -0400131 SkDEBUGCODE(void dump() const override;)
132
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000133private:
csmartdalton7cdda992016-11-01 07:03:03 -0700134 friend class GrRenderTargetContextPriv; // for clearStencilClip and stencil clip state.
robertphillips6a186652015-10-20 07:37:58 -0700135
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500136 // If the input op is combined with an earlier op, this returns the combined op. Otherwise, it
137 // returns the input op.
Brian Salomon2790c522016-12-09 16:32:23 -0500138 GrOp* recordOp(sk_sp<GrOp> op) {
139 SkRect bounds = op->bounds();
140 return this->recordOp(std::move(op), bounds);
141 }
142
143 // Variant that allows an explicit bounds (computed from the Op's bounds and a clip).
144 GrOp* recordOp(sk_sp<GrOp>, const SkRect& clippedBounds);
145
bsalomonaecc0182016-03-07 11:50:44 -0800146 void forwardCombine();
bsalomonad792c12015-09-10 11:10:50 -0700147
Brian Salomon5b7b49f2016-12-07 14:31:00 -0500148 // Makes a copy of the dst if it is necessary for the draw and returns the texture that should
149 // be used by GrXferProcessor to access the destination color. If the texture is nullptr then
150 // a texture copy could not be made.
151 void setupDstTexture(GrRenderTarget*,
152 const GrClip&,
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500153 const SkRect& drawOpBounds,
Brian Salomon5b7b49f2016-12-07 14:31:00 -0500154 GrXferProcessor::DstTexture*);
bsalomonad792c12015-09-10 11:10:50 -0700155
Brian Osman693a5402016-10-27 15:13:22 -0400156 // Used only via GrRenderTargetContextPriv.
csmartdalton29df7602016-08-31 11:55:52 -0700157 void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTarget*);
joshualitt6db519c2014-10-29 08:48:18 -0700158
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500159 struct RecordedOp {
160 sk_sp<GrOp> fOp;
161 SkRect fClippedBounds;
bsalomon6cc90062016-07-08 11:31:22 -0700162 };
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500163 SkSTArray<256, RecordedOp, true> fRecordedOps;
164 GrClearBatch* fLastFullClearOp;
csmartdaltonc6f411e2016-08-05 22:32:12 -0700165 // The context is only in service of the GrClip, remove once it doesn't need this.
csmartdaltona7f29642016-07-07 08:49:11 -0700166 GrContext* fContext;
167 GrGpu* fGpu;
168 GrResourceProvider* fResourceProvider;
joshualitt3bdd7dc2014-10-31 08:27:39 -0700169
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500170 bool fClipOpToBounds;
171 int fMaxOpLookback;
172 int fMaxOpLookahead;
csmartdaltona7f29642016-07-07 08:49:11 -0700173
Ben Wagner145dbcd2016-11-03 14:40:50 -0400174 std::unique_ptr<gr_instanced::InstancedRendering> fInstancedRendering;
bsalomon6dea83f2015-12-03 12:58:06 -0800175
csmartdalton7cdda992016-11-01 07:03:03 -0700176 int32_t fLastClipStackGenID;
177 SkIRect fLastClipStackRect;
178 SkIPoint fLastClipOrigin;
179
Robert Phillipsf2361d22016-10-25 14:20:06 -0400180 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700181};
182
reed@google.comac10a2d2010-12-22 21:39:39 +0000183#endif