blob: 5029b4bdafeea725e27b62ab8c1e4be4c03230e8 [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 Salomon1e41f4a2016-12-07 15:05:04 -050077 void prepareOps(GrBatchFlushState* flushState) override;
78 bool executeOps(GrBatchFlushState* 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 Salomon1e41f4a2016-12-07 15:05:04 -050085 void addDrawOp(const GrPipelineBuilder&, GrRenderTargetContext*, const GrClip&, GrDrawOp*);
joshualitt4d8da812015-01-28 12:53:54 -080086
Brian Salomon1e41f4a2016-12-07 15:05:04 -050087 void addOp(sk_sp<GrOp>);
robertphillips9199a9f2016-07-13 07:48:43 -070088
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000089 /**
csmartdalton5c6fc4f2016-08-12 15:11:51 -070090 * Draws the path into user stencil bits. Upon return, all user stencil values
91 * inside the path will be nonzero. The path's fill must be either even/odd or
92 * winding (notnverse or hairline).It will respect the HW antialias boolean (if
93 * possible in the 3D API). Note, we will never have an inverse fill with
94 * stencil path.
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000095 */
Brian Osman11052242016-10-27 14:47:55 -040096 void stencilPath(GrRenderTargetContext*,
robertphillips59cf61a2016-07-13 09:18:21 -070097 const GrClip&,
robertphillips59cf61a2016-07-13 09:18:21 -070098 bool useHWAA,
99 const SkMatrix& viewMatrix,
100 const GrPath*);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000101
bsalomon9f129de2016-08-10 16:31:05 -0700102 /** Clears the entire render target */
103 void fullClear(GrRenderTarget*, GrColor color);
104
bsalomon53469832015-08-18 09:20:09 -0700105 /** Discards the contents render target. */
106 void discard(GrRenderTarget*);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000107
108 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000109 * Copies a pixel rectangle from one surface to another. This call may finalize
110 * reserved vertex/index data (as though a draw call was made). The src pixels
111 * copied are specified by srcRect. They are copied to a rect of the same
112 * size in dst with top left at dstPoint. If the src rect is clipped by the
113 * src bounds then pixel values in the dst rect corresponding to area clipped
bsalomon6df86402015-06-01 10:41:49 -0700114 * by the src rect are not overwritten. This method is not guaranteed to succeed
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000115 * depending on the type of surface, configs, etc, and the backend-specific
bsalomon6df86402015-06-01 10:41:49 -0700116 * limitations.
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000117 */
bsalomonb8fea972016-02-16 07:34:17 -0800118 bool copySurface(GrSurface* dst,
bsalomonf90a02b2014-11-26 12:28:00 -0800119 GrSurface* src,
120 const SkIRect& srcRect,
121 const SkIPoint& dstPoint);
robertphillips@google.comff175842012-05-14 19:31:39 +0000122
csmartdaltone0d36292016-07-29 08:14:20 -0700123 gr_instanced::InstancedRendering* instancedRendering() const {
124 SkASSERT(fInstancedRendering);
Ben Wagner145dbcd2016-11-03 14:40:50 -0400125 return fInstancedRendering.get();
csmartdaltone0d36292016-07-29 08:14:20 -0700126 }
csmartdaltona7f29642016-07-07 08:49:11 -0700127
Brian Osman45580d32016-11-23 09:37:01 -0500128 GrRenderTargetOpList* asRenderTargetOpList() override { return this; }
129
Robert Phillipsf2361d22016-10-25 14:20:06 -0400130 SkDEBUGCODE(void dump() const override;)
131
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000132private:
csmartdalton7cdda992016-11-01 07:03:03 -0700133 friend class GrRenderTargetContextPriv; // for clearStencilClip and stencil clip state.
robertphillips6a186652015-10-20 07:37:58 -0700134
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.
137 GrOp* recordOp(GrOp*, const SkRect& clippedBounds);
bsalomonaecc0182016-03-07 11:50:44 -0800138 void forwardCombine();
bsalomonad792c12015-09-10 11:10:50 -0700139
Brian Salomon5b7b49f2016-12-07 14:31:00 -0500140 // Makes a copy of the dst if it is necessary for the draw and returns the texture that should
141 // be used by GrXferProcessor to access the destination color. If the texture is nullptr then
142 // a texture copy could not be made.
143 void setupDstTexture(GrRenderTarget*,
144 const GrClip&,
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500145 const SkRect& drawOpBounds,
Brian Salomon5b7b49f2016-12-07 14:31:00 -0500146 GrXferProcessor::DstTexture*);
bsalomonad792c12015-09-10 11:10:50 -0700147
Brian Osman693a5402016-10-27 15:13:22 -0400148 // Used only via GrRenderTargetContextPriv.
csmartdalton29df7602016-08-31 11:55:52 -0700149 void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTarget*);
joshualitt6db519c2014-10-29 08:48:18 -0700150
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500151 struct RecordedOp {
152 sk_sp<GrOp> fOp;
153 SkRect fClippedBounds;
bsalomon6cc90062016-07-08 11:31:22 -0700154 };
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500155 SkSTArray<256, RecordedOp, true> fRecordedOps;
156 GrClearBatch* fLastFullClearOp;
csmartdaltonc6f411e2016-08-05 22:32:12 -0700157 // The context is only in service of the GrClip, remove once it doesn't need this.
csmartdaltona7f29642016-07-07 08:49:11 -0700158 GrContext* fContext;
159 GrGpu* fGpu;
160 GrResourceProvider* fResourceProvider;
joshualitt3bdd7dc2014-10-31 08:27:39 -0700161
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500162 bool fClipOpToBounds;
163 int fMaxOpLookback;
164 int fMaxOpLookahead;
csmartdaltona7f29642016-07-07 08:49:11 -0700165
Ben Wagner145dbcd2016-11-03 14:40:50 -0400166 std::unique_ptr<gr_instanced::InstancedRendering> fInstancedRendering;
bsalomon6dea83f2015-12-03 12:58:06 -0800167
csmartdalton7cdda992016-11-01 07:03:03 -0700168 int32_t fLastClipStackGenID;
169 SkIRect fLastClipStackRect;
170 SkIPoint fLastClipOrigin;
171
Robert Phillipsf2361d22016-10-25 14:20:06 -0400172 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700173};
174
reed@google.comac10a2d2010-12-22 21:39:39 +0000175#endif