blob: 080ff69ce4a403acbbd32d61eec8fa8a4973f007 [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;
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)
46 , fDrawBatchBounds(false)
47 , fMaxBatchLookback(-1)
48 , fMaxBatchLookahead(-1) {}
bsalomon69cfe952015-11-30 13:27:47 -080049 bool fClipBatchToBounds;
bsalomon6dea83f2015-12-03 12:58:06 -080050 bool fDrawBatchBounds;
bsalomon489147c2015-12-14 12:13:09 -080051 int fMaxBatchLookback;
bsalomonaecc0182016-03-07 11:50:44 -080052 int fMaxBatchLookahead;
bsalomon69cfe952015-11-30 13:27:47 -080053 };
54
Robert Phillipsf2361d22016-10-25 14:20:06 -040055 GrRenderTargetOpList(GrRenderTarget*, GrGpu*, GrResourceProvider*,
56 GrAuditTrail*, const Options&);
bsalomona73239a2015-04-28 13:35:17 -070057
Robert Phillipsf2361d22016-10-25 14:20:06 -040058 ~GrRenderTargetOpList() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000059
Robert Phillipsf2361d22016-10-25 14:20:06 -040060 void makeClosed() override {
61 INHERITED::makeClosed();
62
bsalomonfd8d0132016-08-11 11:25:33 -070063 fLastFullClearBatch = nullptr;
bsalomonaecc0182016-03-07 11:50:44 -080064 this->forwardCombine();
robertphillipsa106c622015-10-16 09:07:06 -070065 }
bsalomonaecc0182016-03-07 11:50:44 -080066
reed@google.comac10a2d2010-12-22 21:39:39 +000067 /**
bsalomona73239a2015-04-28 13:35:17 -070068 * Empties the draw buffer of any queued up draws.
69 */
Robert Phillipsf2361d22016-10-25 14:20:06 -040070 void reset() override;
71
72 void abandonGpuResources() override;
73 void freeGpuResources() override;
bsalomona73239a2015-04-28 13:35:17 -070074
75 /**
bsalomondc438982016-08-31 11:53:49 -070076 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
77 * of drawBatches() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070078 */
Robert Phillipsf2361d22016-10-25 14:20:06 -040079 void prepareBatches(GrBatchFlushState* flushState) override;
80 bool drawBatches(GrBatchFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070081
82 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000083 * Gets the capabilities of the draw target.
84 */
bsalomonb3b9aec2015-09-10 11:16:35 -070085 const GrCaps* caps() const { return fGpu->caps(); }
bsalomon@google.com18c9c192011-09-22 21:01:31 +000086
robertphillips976f5f02016-06-03 10:59:20 -070087 void drawBatch(const GrPipelineBuilder&, GrDrawContext*, const GrClip&, GrDrawBatch*);
joshualitt4d8da812015-01-28 12:53:54 -080088
robertphillips9199a9f2016-07-13 07:48:43 -070089 void addBatch(sk_sp<GrBatch>);
90
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000091 /**
csmartdalton5c6fc4f2016-08-12 15:11:51 -070092 * Draws the path into user stencil bits. Upon return, all user stencil values
93 * inside the path will be nonzero. The path's fill must be either even/odd or
94 * winding (notnverse or hairline).It will respect the HW antialias boolean (if
95 * possible in the 3D API). Note, we will never have an inverse fill with
96 * stencil path.
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000097 */
robertphillips59cf61a2016-07-13 09:18:21 -070098 void stencilPath(GrDrawContext*,
99 const GrClip&,
robertphillips59cf61a2016-07-13 09:18:21 -0700100 bool useHWAA,
101 const SkMatrix& viewMatrix,
102 const GrPath*);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000103
bsalomon9f129de2016-08-10 16:31:05 -0700104 /** Clears the entire render target */
105 void fullClear(GrRenderTarget*, GrColor color);
106
bsalomon53469832015-08-18 09:20:09 -0700107 /** Discards the contents render target. */
108 void discard(GrRenderTarget*);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000109
110 /**
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000111 * Copies a pixel rectangle from one surface to another. This call may finalize
112 * reserved vertex/index data (as though a draw call was made). The src pixels
113 * copied are specified by srcRect. They are copied to a rect of the same
114 * size in dst with top left at dstPoint. If the src rect is clipped by the
115 * src bounds then pixel values in the dst rect corresponding to area clipped
bsalomon6df86402015-06-01 10:41:49 -0700116 * by the src rect are not overwritten. This method is not guaranteed to succeed
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000117 * depending on the type of surface, configs, etc, and the backend-specific
bsalomon6df86402015-06-01 10:41:49 -0700118 * limitations.
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000119 */
bsalomonb8fea972016-02-16 07:34:17 -0800120 bool copySurface(GrSurface* dst,
bsalomonf90a02b2014-11-26 12:28:00 -0800121 GrSurface* src,
122 const SkIRect& srcRect,
123 const SkIPoint& dstPoint);
robertphillips@google.comff175842012-05-14 19:31:39 +0000124
csmartdaltone0d36292016-07-29 08:14:20 -0700125 gr_instanced::InstancedRendering* instancedRendering() const {
126 SkASSERT(fInstancedRendering);
127 return fInstancedRendering;
128 }
csmartdaltona7f29642016-07-07 08:49:11 -0700129
Robert Phillipsf2361d22016-10-25 14:20:06 -0400130 SkDEBUGCODE(void dump() const override;)
131
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000132private:
robertphillips976f5f02016-06-03 10:59:20 -0700133 friend class GrDrawContextPriv; // for clearStencilClip
robertphillips6a186652015-10-20 07:37:58 -0700134
bsalomonfd8d0132016-08-11 11:25:33 -0700135 // Returns the batch that the input batch was combined with or the input batch if it wasn't
136 // combined.
137 GrBatch* recordBatch(GrBatch*, const SkRect& clippedBounds);
bsalomonaecc0182016-03-07 11:50:44 -0800138 void forwardCombine();
bsalomonad792c12015-09-10 11:10:50 -0700139
140 // Makes a copy of the dst if it is necessary for the draw. Returns false if a copy is required
141 // but couldn't be made. Otherwise, returns true. This method needs to be protected because it
142 // needs to be accessed by GLPrograms to setup a correct drawstate
143 bool setupDstReadIfNecessary(const GrPipelineBuilder&,
robertphillips55fdccc2016-06-06 06:16:20 -0700144 GrRenderTarget*,
145 const GrClip&,
146 const GrPipelineOptimizations& optimizations,
147 GrXferProcessor::DstTexture*,
148 const SkRect& batchBounds);
bsalomonad792c12015-09-10 11:10:50 -0700149
robertphillips55fdccc2016-06-06 06:16:20 -0700150 // Used only by drawContextPriv.
csmartdalton29df7602016-08-31 11:55:52 -0700151 void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTarget*);
joshualitt6db519c2014-10-29 08:48:18 -0700152
bsalomon6cc90062016-07-08 11:31:22 -0700153 struct RecordedBatch {
154 sk_sp<GrBatch> fBatch;
155 SkRect fClippedBounds;
156 };
157 SkSTArray<256, RecordedBatch, true> fRecordedBatches;
bsalomonfd8d0132016-08-11 11:25:33 -0700158 GrClearBatch* fLastFullClearBatch;
csmartdaltonc6f411e2016-08-05 22:32:12 -0700159 // The context is only in service of the GrClip, remove once it doesn't need this.
csmartdaltona7f29642016-07-07 08:49:11 -0700160 GrContext* fContext;
161 GrGpu* fGpu;
162 GrResourceProvider* fResourceProvider;
163 GrAuditTrail* fAuditTrail;
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
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