blob: e4b2bf64be43647419e8d9ab2ecdf9c8dc8cc6b1 [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
bsalomon473addf2015-10-02 07:49:05 -070019#include "batches/GrDrawBatch.h"
20
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"
bsalomon@google.com8d67c072012-12-13 20:38:14 +000029#include "SkXfermode.h"
Scroggo97c88c22011-05-11 14:05:25 +000030
joshualitt086cee12016-01-12 06:45:24 -080031class GrAuditTrail;
bsalomon53469832015-08-18 09:20:09 -070032class GrBatch;
bsalomonfd8d0132016-08-11 11:25:33 -070033class GrClearBatch;
joshualitt44701df2015-02-23 14:44:57 -080034class GrClip;
bsalomon4b91f762015-05-19 09:29:46 -070035class GrCaps;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000036class GrPath;
bsalomon1fcc01c2015-09-09 09:48:06 -070037class GrDrawPathBatchBase;
robertphillips28a838e2016-06-23 14:07:00 -070038class GrPipelineBuilder;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040039class GrRenderTargetProxy;
sugoi@google.com12b4e272012-12-06 20:13:11 +000040
Robert Phillipsf2361d22016-10-25 14:20:06 -040041class GrRenderTargetOpList final : public GrOpList {
bsalomon@google.comf6601872012-08-28 21:11:35 +000042public:
Robert Phillipsf2361d22016-10-25 14:20:06 -040043 /** Options for GrRenderTargetOpList behavior. */
bsalomon69cfe952015-11-30 13:27:47 -080044 struct Options {
bsalomonaecc0182016-03-07 11:50:44 -080045 Options ()
46 : fClipBatchToBounds(false)
47 , fDrawBatchBounds(false)
48 , fMaxBatchLookback(-1)
49 , fMaxBatchLookahead(-1) {}
bsalomon69cfe952015-11-30 13:27:47 -080050 bool fClipBatchToBounds;
bsalomon6dea83f2015-12-03 12:58:06 -080051 bool fDrawBatchBounds;
bsalomon489147c2015-12-14 12:13:09 -080052 int fMaxBatchLookback;
bsalomonaecc0182016-03-07 11:50:44 -080053 int fMaxBatchLookahead;
bsalomon69cfe952015-11-30 13:27:47 -080054 };
55
Robert Phillipsc7635fa2016-10-28 13:25:24 -040056 GrRenderTargetOpList(GrRenderTargetProxy*, GrGpu*, GrResourceProvider*,
Robert Phillipsf2361d22016-10-25 14:20:06 -040057 GrAuditTrail*, const Options&);
bsalomona73239a2015-04-28 13:35:17 -070058
Robert Phillipsf2361d22016-10-25 14:20:06 -040059 ~GrRenderTargetOpList() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000060
Robert Phillipsf2361d22016-10-25 14:20:06 -040061 void makeClosed() override {
62 INHERITED::makeClosed();
63
bsalomonfd8d0132016-08-11 11:25:33 -070064 fLastFullClearBatch = nullptr;
bsalomonaecc0182016-03-07 11:50:44 -080065 this->forwardCombine();
robertphillipsa106c622015-10-16 09:07:06 -070066 }
bsalomonaecc0182016-03-07 11:50:44 -080067
reed@google.comac10a2d2010-12-22 21:39:39 +000068 /**
bsalomona73239a2015-04-28 13:35:17 -070069 * Empties the draw buffer of any queued up draws.
70 */
Robert Phillipsf2361d22016-10-25 14:20:06 -040071 void reset() override;
72
73 void abandonGpuResources() override;
74 void freeGpuResources() override;
bsalomona73239a2015-04-28 13:35:17 -070075
76 /**
bsalomondc438982016-08-31 11:53:49 -070077 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
78 * of drawBatches() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070079 */
Robert Phillipsf2361d22016-10-25 14:20:06 -040080 void prepareBatches(GrBatchFlushState* flushState) override;
81 bool drawBatches(GrBatchFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070082
83 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000084 * Gets the capabilities of the draw target.
85 */
bsalomonb3b9aec2015-09-10 11:16:35 -070086 const GrCaps* caps() const { return fGpu->caps(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000087
Brian Osman11052242016-10-27 14:47:55 -040088 void drawBatch(const GrPipelineBuilder&, GrRenderTargetContext*, const GrClip&, GrDrawBatch*);
joshualitt4d8da812015-01-28 12:53:54 -080089
robertphillips9199a9f2016-07-13 07:48:43 -070090 void addBatch(sk_sp<GrBatch>);
91
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000092 /**
csmartdalton5c6fc4f2016-08-12 15:11:51 -070093 * Draws the path into user stencil bits. Upon return, all user stencil values
94 * inside the path will be nonzero. The path's fill must be either even/odd or
95 * winding (notnverse or hairline).It will respect the HW antialias boolean (if
96 * possible in the 3D API). Note, we will never have an inverse fill with
97 * stencil path.
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000098 */
Brian Osman11052242016-10-27 14:47:55 -040099 void stencilPath(GrRenderTargetContext*,
robertphillips59cf61a2016-07-13 09:18:21 -0700100 const GrClip&,
robertphillips59cf61a2016-07-13 09:18:21 -0700101 bool useHWAA,
102 const SkMatrix& viewMatrix,
103 const GrPath*);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000104
bsalomon9f129de2016-08-10 16:31:05 -0700105 /** Clears the entire render target */
106 void fullClear(GrRenderTarget*, GrColor color);
107
bsalomon53469832015-08-18 09:20:09 -0700108 /** Discards the contents render target. */
109 void discard(GrRenderTarget*);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000110
111 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000112 * Copies a pixel rectangle from one surface to another. This call may finalize
113 * reserved vertex/index data (as though a draw call was made). The src pixels
114 * copied are specified by srcRect. They are copied to a rect of the same
115 * size in dst with top left at dstPoint. If the src rect is clipped by the
116 * src bounds then pixel values in the dst rect corresponding to area clipped
bsalomon6df86402015-06-01 10:41:49 -0700117 * by the src rect are not overwritten. This method is not guaranteed to succeed
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000118 * depending on the type of surface, configs, etc, and the backend-specific
bsalomon6df86402015-06-01 10:41:49 -0700119 * limitations.
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000120 */
bsalomonb8fea972016-02-16 07:34:17 -0800121 bool copySurface(GrSurface* dst,
bsalomonf90a02b2014-11-26 12:28:00 -0800122 GrSurface* src,
123 const SkIRect& srcRect,
124 const SkIPoint& dstPoint);
robertphillips@google.comff175842012-05-14 19:31:39 +0000125
csmartdaltone0d36292016-07-29 08:14:20 -0700126 gr_instanced::InstancedRendering* instancedRendering() const {
127 SkASSERT(fInstancedRendering);
128 return fInstancedRendering;
129 }
csmartdaltona7f29642016-07-07 08:49:11 -0700130
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
bsalomonfd8d0132016-08-11 11:25:33 -0700136 // Returns the batch that the input batch was combined with or the input batch if it wasn't
137 // combined.
138 GrBatch* recordBatch(GrBatch*, const SkRect& clippedBounds);
bsalomonaecc0182016-03-07 11:50:44 -0800139 void forwardCombine();
bsalomonad792c12015-09-10 11:10:50 -0700140
141 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
142 // but couldn't be made. Otherwise, returns true. This method needs to be protected because it
143 // needs to be accessed by GLPrograms to setup a correct drawstate
144 bool setupDstReadIfNecessary(const GrPipelineBuilder&,
robertphillips55fdccc2016-06-06 06:16:20 -0700145 GrRenderTarget*,
146 const GrClip&,
147 const GrPipelineOptimizations& optimizations,
148 GrXferProcessor::DstTexture*,
149 const SkRect& batchBounds);
bsalomonad792c12015-09-10 11:10:50 -0700150
Brian Osman693a5402016-10-27 15:13:22 -0400151 // Used only via GrRenderTargetContextPriv.
csmartdalton29df7602016-08-31 11:55:52 -0700152 void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTarget*);
joshualitt6db519c2014-10-29 08:48:18 -0700153
bsalomon6cc90062016-07-08 11:31:22 -0700154 struct RecordedBatch {
155 sk_sp<GrBatch> fBatch;
156 SkRect fClippedBounds;
157 };
158 SkSTArray<256, RecordedBatch, true> fRecordedBatches;
bsalomonfd8d0132016-08-11 11:25:33 -0700159 GrClearBatch* fLastFullClearBatch;
csmartdaltonc6f411e2016-08-05 22:32:12 -0700160 // The context is only in service of the GrClip, remove once it doesn't need this.
csmartdaltona7f29642016-07-07 08:49:11 -0700161 GrContext* fContext;
162 GrGpu* fGpu;
163 GrResourceProvider* fResourceProvider;
joshualitt3bdd7dc2014-10-31 08:27:39 -0700164
csmartdaltona7f29642016-07-07 08:49:11 -0700165 bool fClipBatchToBounds;
166 bool fDrawBatchBounds;
167 int fMaxBatchLookback;
168 int fMaxBatchLookahead;
169
170 SkAutoTDelete<gr_instanced::InstancedRendering> fInstancedRendering;
bsalomon6dea83f2015-12-03 12:58:06 -0800171
csmartdalton7cdda992016-11-01 07:03:03 -0700172 int32_t fLastClipStackGenID;
173 SkIRect fLastClipStackRect;
174 SkIPoint fLastClipOrigin;
175
Robert Phillipsf2361d22016-10-25 14:20:06 -0400176 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700177};
178
reed@google.comac10a2d2010-12-22 21:39:39 +0000179#endif