blob: e2a7bc7e5fb10c79ff2b8ea23dfdeb1d59013f07 [file] [log] [blame]
tomhudson@google.com93813632011-10-27 20:21:16 +00001/*
egdaniel8dd688b2015-01-22 10:16:09 -08002 * Copyright 2015 Google Inc.
tomhudson@google.com93813632011-10-27 20:21:16 +00003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
egdaniel8dd688b2015-01-22 10:16:09 -08008#ifndef GrPipelineBuilder_DEFINED
9#define GrPipelineBuilder_DEFINED
tomhudson@google.com93813632011-10-27 20:21:16 +000010
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000011#include "GrBlend.h"
bsalomoneb1cb5c2015-05-22 08:01:09 -070012#include "GrCaps.h"
joshualitt44701df2015-02-23 14:44:57 -080013#include "GrClip.h"
bsalomonf96ba022014-09-17 08:05:40 -070014#include "GrGpuResourceRef.h"
egdanielb6cbc382014-11-13 11:00:34 -080015#include "GrProcOptInfo.h"
joshualitt2cdec312015-07-09 07:31:31 -070016#include "GrProcessorDataManager.h"
egdaniel89af44a2014-09-26 06:15:04 -070017#include "GrRenderTarget.h"
18#include "GrStencil.h"
egdaniel95131432014-12-09 11:15:43 -080019#include "GrXferProcessor.h"
egdaniel89af44a2014-09-26 06:15:04 -070020#include "SkMatrix.h"
egdaniel87509242014-12-17 13:37:13 -080021#include "effects/GrCoverageSetOpXP.h"
egdaniel080e6732014-12-22 07:35:52 -080022#include "effects/GrDisableColorXP.h"
egdaniel95131432014-12-09 11:15:43 -080023#include "effects/GrPorterDuffXferProcessor.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000024#include "effects/GrSimpleTextureEffect.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000025
bsalomonabd30f52015-08-13 13:34:48 -070026class GrDrawBatch;
bsalomon4b91f762015-05-19 09:29:46 -070027class GrCaps;
egdaniel89af44a2014-09-26 06:15:04 -070028class GrPaint;
29class GrTexture;
egdaniel170f90b2014-09-16 12:54:40 -070030
bsalomonac856c92015-08-27 06:30:17 -070031class GrPipelineBuilder : public SkNoncopyable {
bsalomon@google.com2e3d1442012-03-26 20:33:54 +000032public:
egdaniel8dd688b2015-01-22 10:16:09 -080033 GrPipelineBuilder();
34
bsalomon@google.com52a5dcb2012-01-17 16:01:37 +000035 /**
joshualitt7b670db2015-07-09 13:25:02 -070036 * Initializes the GrPipelineBuilder based on a GrPaint, render target, and clip. Note
egdaniel8dd688b2015-01-22 10:16:09 -080037 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have
38 * no GrPaint equivalents are set to default values with the exception of vertex attribute state
39 * which is unmodified by this function and clipping which will be enabled.
bsalomon@google.comaf84e742012-10-05 13:23:24 +000040 */
joshualitt7b670db2015-07-09 13:25:02 -070041 GrPipelineBuilder(const GrPaint&, GrRenderTarget*, const GrClip&);
42
43 virtual ~GrPipelineBuilder();
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000044
bsalomon@google.com2401ae82012-01-17 21:03:05 +000045 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -080046 /// @name Fragment Processors
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000047 ///
bsalomon6be6f7c2015-02-26 13:05:21 -080048 /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage.
49 /// There are two chains of FPs, one for color and one for coverage. The first FP in each
50 /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output
51 /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs
52 /// feed their output to the GrXferProcessor which controls blending.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000053 ////
54
bsalomonac856c92015-08-27 06:30:17 -070055 int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); }
56 int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); }
57 int numFragmentProcessors() const { return this->numColorFragmentProcessors() +
58 this->numCoverageFragmentProcessors(); }
egdaniel378092f2014-12-03 10:40:13 -080059
bsalomonac856c92015-08-27 06:30:17 -070060 const GrFragmentProcessor* getColorFragmentProcessor(int idx) const {
61 return fColorFragmentProcessors[idx];
62 }
63 const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const {
64 return fCoverageFragmentProcessors[idx];
jvanverth@google.com65eb4d52013-03-19 18:51:02 +000065 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +000066
bsalomonac856c92015-08-27 06:30:17 -070067 const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcessor* processor) {
68 SkASSERT(processor);
69 fColorFragmentProcessors.push_back(SkRef(processor));
70 return processor;
71 }
72
73 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* processor) {
74 SkASSERT(processor);
75 fCoverageFragmentProcessors.push_back(SkRef(processor));
76 return processor;
bsalomon@google.comadc65362013-01-28 14:26:09 +000077 }
78
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000079 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +000080 * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
tomhudson@google.com1e8f0162012-07-20 16:25:18 +000081 */
joshualittb0a8a372014-09-23 09:50:21 -070082 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
joshualittaf2533a2015-09-09 10:00:12 -070083 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(&fProcDataManager, texture,
bsalomonac856c92015-08-27 06:30:17 -070084 matrix))->unref();
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +000085 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000086
joshualittb0a8a372014-09-23 09:50:21 -070087 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
joshualittaf2533a2015-09-09 10:00:12 -070088 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(&fProcDataManager, texture,
bsalomonac856c92015-08-27 06:30:17 -070089 matrix))->unref();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000090 }
91
joshualittb0a8a372014-09-23 09:50:21 -070092 void addColorTextureProcessor(GrTexture* texture,
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000093 const SkMatrix& matrix,
94 const GrTextureParams& params) {
joshualittaf2533a2015-09-09 10:00:12 -070095 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(&fProcDataManager, texture,
bsalomonac856c92015-08-27 06:30:17 -070096 matrix,
97 params))->unref();
joshualittb0a8a372014-09-23 09:50:21 -070098 }
99
100 void addCoverageTextureProcessor(GrTexture* texture,
101 const SkMatrix& matrix,
102 const GrTextureParams& params) {
joshualittaf2533a2015-09-09 10:00:12 -0700103 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(&fProcDataManager, texture,
bsalomonac856c92015-08-27 06:30:17 -0700104 matrix, params))->unref();
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000105 }
tomhudson@google.com676e6602012-07-10 17:21:48 +0000106
robertphillips@google.com972265d2012-06-13 18:49:30 +0000107 /**
bsalomon6be6f7c2015-02-26 13:05:21 -0800108 * When this object is destroyed it will remove any color/coverage FPs from the pipeline builder
joshualitt4421a4c2015-07-13 09:36:41 -0700109 * and also remove any additions to the GrProcessorDataManager that were added after its
110 * constructor.
joshualitt5e6ba212015-07-13 07:35:05 -0700111 * This class can transiently modify its "const" GrPipelineBuilder object but will restore it
112 * when done - so it is notionally "const" correct.
robertphillips@google.com972265d2012-06-13 18:49:30 +0000113 */
joshualitt4421a4c2015-07-13 09:36:41 -0700114 class AutoRestoreFragmentProcessorState : public ::SkNoncopyable {
robertphillips@google.com972265d2012-06-13 18:49:30 +0000115 public:
joshualitt4421a4c2015-07-13 09:36:41 -0700116 AutoRestoreFragmentProcessorState()
halcanary96fcdcc2015-08-27 07:41:13 -0700117 : fPipelineBuilder(nullptr)
bsalomon9b536522014-09-05 09:18:51 -0700118 , fColorEffectCnt(0)
joshualittaf2533a2015-09-09 10:00:12 -0700119 , fCoverageEffectCnt(0) {}
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000120
joshualitt4421a4c2015-07-13 09:36:41 -0700121 AutoRestoreFragmentProcessorState(const GrPipelineBuilder& ds)
halcanary96fcdcc2015-08-27 07:41:13 -0700122 : fPipelineBuilder(nullptr)
bsalomon9b536522014-09-05 09:18:51 -0700123 , fColorEffectCnt(0)
joshualittaf2533a2015-09-09 10:00:12 -0700124 , fCoverageEffectCnt(0) {
joshualitt4421a4c2015-07-13 09:36:41 -0700125 this->set(&ds);
robertphillips@google.comf09b87d2013-06-13 20:06:44 +0000126 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000127
halcanary96fcdcc2015-08-27 07:41:13 -0700128 ~AutoRestoreFragmentProcessorState() { this->set(nullptr); }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000129
joshualitt5e6ba212015-07-13 07:35:05 -0700130 void set(const GrPipelineBuilder* ds);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000131
egdaniel8dd688b2015-01-22 10:16:09 -0800132 bool isSet() const { return SkToBool(fPipelineBuilder); }
bsalomon8af05232014-06-03 06:34:58 -0700133
joshualitt4421a4c2015-07-13 09:36:41 -0700134 GrProcessorDataManager* getProcessorDataManager() {
135 SkASSERT(this->isSet());
136 return fPipelineBuilder->getProcessorDataManager();
137 }
138
bsalomonac856c92015-08-27 06:30:17 -0700139 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* processor) {
joshualitt5e6ba212015-07-13 07:35:05 -0700140 SkASSERT(this->isSet());
bsalomonac856c92015-08-27 06:30:17 -0700141 return fPipelineBuilder->addCoverageFragmentProcessor(processor);
joshualitt5e6ba212015-07-13 07:35:05 -0700142 }
143
robertphillips@google.com972265d2012-06-13 18:49:30 +0000144 private:
joshualitt5e6ba212015-07-13 07:35:05 -0700145 // notionally const (as marginalia)
egdaniel8dd688b2015-01-22 10:16:09 -0800146 GrPipelineBuilder* fPipelineBuilder;
joshualitt5e6ba212015-07-13 07:35:05 -0700147 int fColorEffectCnt;
148 int fCoverageEffectCnt;
robertphillips@google.com972265d2012-06-13 18:49:30 +0000149 };
150
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000151 /// @}
152
153 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000154 /// @name Blending
155 ////
156
egdaniel89af44a2014-09-26 06:15:04 -0700157 /**
bsalomon6be6f7c2015-02-26 13:05:21 -0800158 * Installs a GrXPFactory. This object controls how src color, fractional pixel coverage,
159 * and the dst color are blended.
160 */
161 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
162 fXPFactory.reset(SkRef(xpFactory));
163 return xpFactory;
164 }
165
166 /**
167 * Sets a GrXPFactory that will ignore src color and perform a set operation between the draws
168 * output coverage and the destination. This is useful to render coverage masks as CSG.
169 */
170 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) {
171 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
172 }
173
174 /**
175 * Sets a GrXPFactory that disables color writes to the destination. This is useful when
176 * rendering to the stencil buffer.
177 */
178 void setDisableColorXPFactory() {
179 fXPFactory.reset(GrDisableColorXPFactory::Create());
180 }
181
182 const GrXPFactory* getXPFactory() const {
183 if (!fXPFactory) {
184 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
185 }
186 return fXPFactory.get();
187 }
188
189 /**
bsalomon6a44c6a2015-05-26 09:49:05 -0700190 * Checks whether the xp will need destination in a texture to correctly blend.
bsalomon6be6f7c2015-02-26 13:05:21 -0800191 */
bsalomon6a44c6a2015-05-26 09:49:05 -0700192 bool willXPNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI,
193 const GrProcOptInfo& coveragePOI) const;
joshualittd27f73e2014-12-29 07:43:36 -0800194
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000195 /// @}
196
bsalomon6be6f7c2015-02-26 13:05:21 -0800197
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000198 ///////////////////////////////////////////////////////////////////////////
199 /// @name Render Target
200 ////
201
202 /**
egdaniel89af44a2014-09-26 06:15:04 -0700203 * Retrieves the currently set render-target.
204 *
205 * @return The currently set render target.
206 */
bsalomon37dd3312014-11-03 08:47:23 -0800207 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700208
209 /**
bsalomon@google.comca432082013-01-23 19:53:46 +0000210 * Sets the render-target used at the next drawing call
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000211 *
212 * @param target The render target to set.
213 */
bsalomonae59b772014-11-19 08:23:49 -0800214 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000215
cdalton86ae0a92015-06-08 15:11:04 -0700216 /**
217 * Returns whether the rasterizer and stencil test (if any) will run at a higher sample rate
218 * than the color buffer. In is scenario, the higher sample rate is resolved during blending.
219 */
220 bool hasMixedSamples() const {
vbuzinovdded6962015-06-12 08:59:45 -0700221 return this->isHWAntialias() && !fRenderTarget->isUnifiedMultisampled();
cdalton86ae0a92015-06-08 15:11:04 -0700222 }
223
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000224 /// @}
225
226 ///////////////////////////////////////////////////////////////////////////
227 /// @name Stencil
228 ////
229
egdaniel89af44a2014-09-26 06:15:04 -0700230 const GrStencilSettings& getStencil() const { return fStencilSettings; }
231
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000232 /**
233 * Sets the stencil settings to use for the next draw.
234 * Changing the clip has the side-effect of possibly zeroing
235 * out the client settable stencil bits. So multipass algorithms
236 * using stencil should not change the clip between passes.
237 * @param settings the stencil settings to use.
238 */
bsalomon04ddf892014-11-19 12:36:22 -0800239 void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000240
241 /**
242 * Shortcut to disable stencil testing and ops.
243 */
bsalomon04ddf892014-11-19 12:36:22 -0800244 void disableStencil() { fStencilSettings.setDisabled(); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000245
bsalomon2ed5ef82014-07-07 08:44:05 -0700246 GrStencilSettings* stencil() { return &fStencilSettings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000247
bsalomon6be6f7c2015-02-26 13:05:21 -0800248 /**
249 * AutoRestoreStencil
250 *
251 * This simple struct saves and restores the stencil settings
joshualitt5e6ba212015-07-13 07:35:05 -0700252 * This class can transiently modify its "const" GrPipelineBuilder object but will restore it
253 * when done - so it is notionally "const" correct.
bsalomon6be6f7c2015-02-26 13:05:21 -0800254 */
255 class AutoRestoreStencil : public ::SkNoncopyable {
256 public:
halcanary96fcdcc2015-08-27 07:41:13 -0700257 AutoRestoreStencil() : fPipelineBuilder(nullptr) {}
bsalomon6be6f7c2015-02-26 13:05:21 -0800258
halcanary96fcdcc2015-08-27 07:41:13 -0700259 AutoRestoreStencil(const GrPipelineBuilder& ds) : fPipelineBuilder(nullptr) { this->set(&ds); }
bsalomon6be6f7c2015-02-26 13:05:21 -0800260
halcanary96fcdcc2015-08-27 07:41:13 -0700261 ~AutoRestoreStencil() { this->set(nullptr); }
bsalomon6be6f7c2015-02-26 13:05:21 -0800262
joshualitt5e6ba212015-07-13 07:35:05 -0700263 void set(const GrPipelineBuilder* ds) {
bsalomon6be6f7c2015-02-26 13:05:21 -0800264 if (fPipelineBuilder) {
265 fPipelineBuilder->setStencil(fStencilSettings);
266 }
joshualitt5e6ba212015-07-13 07:35:05 -0700267 fPipelineBuilder = const_cast<GrPipelineBuilder*>(ds);
bsalomon6be6f7c2015-02-26 13:05:21 -0800268 if (ds) {
269 fStencilSettings = ds->getStencil();
270 }
271 }
272
273 bool isSet() const { return SkToBool(fPipelineBuilder); }
274
joshualitt5e6ba212015-07-13 07:35:05 -0700275 void setStencil(const GrStencilSettings& settings) {
276 SkASSERT(this->isSet());
277 fPipelineBuilder->setStencil(settings);
278 }
279
bsalomon6be6f7c2015-02-26 13:05:21 -0800280 private:
joshualitt5e6ba212015-07-13 07:35:05 -0700281 // notionally const (as marginalia)
bsalomon6be6f7c2015-02-26 13:05:21 -0800282 GrPipelineBuilder* fPipelineBuilder;
283 GrStencilSettings fStencilSettings;
284 };
285
286
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000287 /// @}
288
289 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000290 /// @name State Flags
291 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000292
egdaniel89af44a2014-09-26 06:15:04 -0700293 /**
294 * Flags that affect rendering. Controlled using enable/disableState(). All
295 * default to disabled.
296 */
bsalomond79c5492015-04-27 10:07:04 -0700297 enum Flags {
egdaniel89af44a2014-09-26 06:15:04 -0700298 /**
egdaniel89af44a2014-09-26 06:15:04 -0700299 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
300 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
301 * the 3D API.
302 */
bsalomonaca31fe2015-09-22 11:38:46 -0700303 kHWAntialias_Flag = 0x01,
egdaniel89af44a2014-09-26 06:15:04 -0700304
bsalomond79c5492015-04-27 10:07:04 -0700305 /**
306 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
307 */
bsalomonaca31fe2015-09-22 11:38:46 -0700308 kSnapVerticesToPixelCenters_Flag = 0x02,
bsalomond79c5492015-04-27 10:07:04 -0700309
310 kLast_Flag = kSnapVerticesToPixelCenters_Flag,
egdaniel89af44a2014-09-26 06:15:04 -0700311 };
312
bsalomond79c5492015-04-27 10:07:04 -0700313 bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); }
314 bool snapVerticesToPixelCenters() const {
315 return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000316
317 /**
318 * Enable render state settings.
319 *
bsalomond79c5492015-04-27 10:07:04 -0700320 * @param flags bitfield of Flags specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000321 */
bsalomond79c5492015-04-27 10:07:04 -0700322 void enableState(uint32_t flags) { fFlags |= flags; }
323
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000324 /**
325 * Disable render state settings.
326 *
bsalomond79c5492015-04-27 10:07:04 -0700327 * @param flags bitfield of Flags specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000328 */
bsalomond79c5492015-04-27 10:07:04 -0700329 void disableState(uint32_t flags) { fFlags &= ~(flags); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000330
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000331 /**
bsalomond79c5492015-04-27 10:07:04 -0700332 * Enable or disable flags based on a boolean.
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000333 *
bsalomond79c5492015-04-27 10:07:04 -0700334 * @param flags bitfield of Flags to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000335 * @param enable if true enable stateBits, otherwise disable
336 */
bsalomond79c5492015-04-27 10:07:04 -0700337 void setState(uint32_t flags, bool enable) {
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000338 if (enable) {
bsalomond79c5492015-04-27 10:07:04 -0700339 this->enableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000340 } else {
bsalomond79c5492015-04-27 10:07:04 -0700341 this->disableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000342 }
343 }
344
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000345 /// @}
346
347 ///////////////////////////////////////////////////////////////////////////
348 /// @name Face Culling
349 ////
350
egdaniel89af44a2014-09-26 06:15:04 -0700351 enum DrawFace {
352 kInvalid_DrawFace = -1,
353
354 kBoth_DrawFace,
355 kCCW_DrawFace,
356 kCW_DrawFace,
357 };
358
359 /**
360 * Gets whether the target is drawing clockwise, counterclockwise,
361 * or both faces.
362 * @return the current draw face(s).
363 */
364 DrawFace getDrawFace() const { return fDrawFace; }
365
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000366 /**
367 * Controls whether clockwise, counterclockwise, or both faces are drawn.
368 * @param face the face(s) to draw.
369 */
370 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000371 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700372 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000373 }
374
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000375 /// @}
376
377 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000378
bsalomonabd30f52015-08-13 13:34:48 -0700379 const GrProcOptInfo& colorProcInfo(const GrDrawBatch* batch) const {
joshualitt4d8da812015-01-28 12:53:54 -0800380 this->calcColorInvariantOutput(batch);
381 return fColorProcInfo;
382 }
383
bsalomonabd30f52015-08-13 13:34:48 -0700384 const GrProcOptInfo& coverageProcInfo(const GrDrawBatch* batch) const {
joshualitt4d8da812015-01-28 12:53:54 -0800385 this->calcCoverageInvariantOutput(batch);
386 return fCoverageProcInfo;
387 }
joshualitt44701df2015-02-23 14:44:57 -0800388
389 void setClip(const GrClip& clip) { fClip = clip; }
390 const GrClip& clip() const { return fClip; }
391
joshualittaf2533a2015-09-09 10:00:12 -0700392 GrProcessorDataManager* getProcessorDataManager() { return &fProcDataManager; }
393 const GrProcessorDataManager* processorDataManager() const { return &fProcDataManager; }
joshualitt2cdec312015-07-09 07:31:31 -0700394
egdaniele36914c2015-02-13 09:00:33 -0800395private:
396 // Calculating invariant color / coverage information is expensive, so we partially cache the
397 // results.
398 //
399 // canUseFracCoveragePrimProc() - Called in regular skia draw, caches results but only for a
400 // specific color and coverage. May be called multiple times
egdaniele36914c2015-02-13 09:00:33 -0800401 // GrOptDrawState constructor - never caches results
joshualittd15e4e42015-01-26 13:30:10 -0800402
403 /**
joshualitt4d8da812015-01-28 12:53:54 -0800404 * GrBatch provides the initial seed for these loops based off of its initial geometry data
405 */
bsalomonabd30f52015-08-13 13:34:48 -0700406 void calcColorInvariantOutput(const GrDrawBatch*) const;
407 void calcCoverageInvariantOutput(const GrDrawBatch*) const;
joshualitt4d8da812015-01-28 12:53:54 -0800408
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000409 // Some of the auto restore objects assume that no effects are removed during their lifetime.
410 // This is used to assert that this condition holds.
joshualitt5e6ba212015-07-13 07:35:05 -0700411 SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000412
bsalomonac856c92015-08-27 06:30:17 -0700413 typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArray;
egdaniel89af44a2014-09-26 06:15:04 -0700414
joshualittaf2533a2015-09-09 10:00:12 -0700415 GrProcessorDataManager fProcDataManager;
bsalomonae59b772014-11-19 08:23:49 -0800416 SkAutoTUnref<GrRenderTarget> fRenderTarget;
bsalomond79c5492015-04-27 10:07:04 -0700417 uint32_t fFlags;
bsalomonae59b772014-11-19 08:23:49 -0800418 GrStencilSettings fStencilSettings;
bsalomonae59b772014-11-19 08:23:49 -0800419 DrawFace fDrawFace;
joshualitt2fdeda02015-01-22 07:11:44 -0800420 mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
bsalomonac856c92015-08-27 06:30:17 -0700421 FragmentProcessorArray fColorFragmentProcessors;
422 FragmentProcessorArray fCoverageFragmentProcessors;
joshualitt44701df2015-02-23 14:44:57 -0800423 GrClip fClip;
egdaniel89af44a2014-09-26 06:15:04 -0700424
egdanielb6cbc382014-11-13 11:00:34 -0800425 mutable GrProcOptInfo fColorProcInfo;
426 mutable GrProcOptInfo fCoverageProcInfo;
egdanielb6cbc382014-11-13 11:00:34 -0800427
egdaniel8dd688b2015-01-22 10:16:09 -0800428 friend class GrPipeline;
tomhudson@google.com93813632011-10-27 20:21:16 +0000429};
430
431#endif