blob: f41f6eeae2275e4b0aec9e8dddb6591203c44b46 [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 /**
299 * Perform dithering. TODO: Re-evaluate whether we need this bit
300 */
bsalomond79c5492015-04-27 10:07:04 -0700301 kDither_Flag = 0x01,
egdaniel89af44a2014-09-26 06:15:04 -0700302 /**
303 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
304 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
305 * the 3D API.
306 */
bsalomond79c5492015-04-27 10:07:04 -0700307 kHWAntialias_Flag = 0x02,
egdaniel89af44a2014-09-26 06:15:04 -0700308
bsalomond79c5492015-04-27 10:07:04 -0700309 /**
310 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
311 */
312 kSnapVerticesToPixelCenters_Flag = 0x04,
313
314 kLast_Flag = kSnapVerticesToPixelCenters_Flag,
egdaniel89af44a2014-09-26 06:15:04 -0700315 };
316
bsalomond79c5492015-04-27 10:07:04 -0700317 bool isDither() const { return SkToBool(fFlags & kDither_Flag); }
318 bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); }
319 bool snapVerticesToPixelCenters() const {
320 return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000321
322 /**
323 * Enable render state settings.
324 *
bsalomond79c5492015-04-27 10:07:04 -0700325 * @param flags bitfield of Flags specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000326 */
bsalomond79c5492015-04-27 10:07:04 -0700327 void enableState(uint32_t flags) { fFlags |= flags; }
328
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000329 /**
330 * Disable render state settings.
331 *
bsalomond79c5492015-04-27 10:07:04 -0700332 * @param flags bitfield of Flags specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000333 */
bsalomond79c5492015-04-27 10:07:04 -0700334 void disableState(uint32_t flags) { fFlags &= ~(flags); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000335
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000336 /**
bsalomond79c5492015-04-27 10:07:04 -0700337 * Enable or disable flags based on a boolean.
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000338 *
bsalomond79c5492015-04-27 10:07:04 -0700339 * @param flags bitfield of Flags to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000340 * @param enable if true enable stateBits, otherwise disable
341 */
bsalomond79c5492015-04-27 10:07:04 -0700342 void setState(uint32_t flags, bool enable) {
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000343 if (enable) {
bsalomond79c5492015-04-27 10:07:04 -0700344 this->enableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000345 } else {
bsalomond79c5492015-04-27 10:07:04 -0700346 this->disableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000347 }
348 }
349
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000350 /// @}
351
352 ///////////////////////////////////////////////////////////////////////////
353 /// @name Face Culling
354 ////
355
egdaniel89af44a2014-09-26 06:15:04 -0700356 enum DrawFace {
357 kInvalid_DrawFace = -1,
358
359 kBoth_DrawFace,
360 kCCW_DrawFace,
361 kCW_DrawFace,
362 };
363
364 /**
365 * Gets whether the target is drawing clockwise, counterclockwise,
366 * or both faces.
367 * @return the current draw face(s).
368 */
369 DrawFace getDrawFace() const { return fDrawFace; }
370
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000371 /**
372 * Controls whether clockwise, counterclockwise, or both faces are drawn.
373 * @param face the face(s) to draw.
374 */
375 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000376 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700377 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000378 }
379
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000380 /// @}
381
382 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000383
joshualitt4d8da812015-01-28 12:53:54 -0800384 // TODO delete when we have Batch
joshualitt56995b52014-12-11 15:44:02 -0800385 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const {
386 this->calcColorInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800387 return fColorProcInfo;
388 }
389
joshualitt56995b52014-12-11 15:44:02 -0800390 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const {
391 this->calcCoverageInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800392 return fCoverageProcInfo;
393 }
394
bsalomonabd30f52015-08-13 13:34:48 -0700395 const GrProcOptInfo& colorProcInfo(const GrDrawBatch* batch) const {
joshualitt4d8da812015-01-28 12:53:54 -0800396 this->calcColorInvariantOutput(batch);
397 return fColorProcInfo;
398 }
399
bsalomonabd30f52015-08-13 13:34:48 -0700400 const GrProcOptInfo& coverageProcInfo(const GrDrawBatch* batch) const {
joshualitt4d8da812015-01-28 12:53:54 -0800401 this->calcCoverageInvariantOutput(batch);
402 return fCoverageProcInfo;
403 }
joshualitt44701df2015-02-23 14:44:57 -0800404
405 void setClip(const GrClip& clip) { fClip = clip; }
406 const GrClip& clip() const { return fClip; }
407
joshualittaf2533a2015-09-09 10:00:12 -0700408 GrProcessorDataManager* getProcessorDataManager() { return &fProcDataManager; }
409 const GrProcessorDataManager* processorDataManager() const { return &fProcDataManager; }
joshualitt2cdec312015-07-09 07:31:31 -0700410
egdaniele36914c2015-02-13 09:00:33 -0800411private:
412 // Calculating invariant color / coverage information is expensive, so we partially cache the
413 // results.
414 //
415 // canUseFracCoveragePrimProc() - Called in regular skia draw, caches results but only for a
416 // specific color and coverage. May be called multiple times
egdaniele36914c2015-02-13 09:00:33 -0800417 // GrOptDrawState constructor - never caches results
joshualittd15e4e42015-01-26 13:30:10 -0800418
419 /**
joshualitt4d8da812015-01-28 12:53:54 -0800420 * Primproc variants of the calc functions
421 * TODO remove these when batch is everywhere
joshualittd5a7db42015-01-27 15:39:06 -0800422 */
joshualitt4d8da812015-01-28 12:53:54 -0800423 void calcColorInvariantOutput(const GrPrimitiveProcessor*) const;
joshualittc2893c52015-01-28 06:54:30 -0800424 void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const;
joshualittd5a7db42015-01-27 15:39:06 -0800425
426 /**
joshualitt4d8da812015-01-28 12:53:54 -0800427 * GrBatch provides the initial seed for these loops based off of its initial geometry data
428 */
bsalomonabd30f52015-08-13 13:34:48 -0700429 void calcColorInvariantOutput(const GrDrawBatch*) const;
430 void calcCoverageInvariantOutput(const GrDrawBatch*) const;
joshualitt4d8da812015-01-28 12:53:54 -0800431
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000432 // Some of the auto restore objects assume that no effects are removed during their lifetime.
433 // This is used to assert that this condition holds.
joshualitt5e6ba212015-07-13 07:35:05 -0700434 SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000435
bsalomonac856c92015-08-27 06:30:17 -0700436 typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArray;
egdaniel89af44a2014-09-26 06:15:04 -0700437
joshualittaf2533a2015-09-09 10:00:12 -0700438 GrProcessorDataManager fProcDataManager;
bsalomonae59b772014-11-19 08:23:49 -0800439 SkAutoTUnref<GrRenderTarget> fRenderTarget;
bsalomond79c5492015-04-27 10:07:04 -0700440 uint32_t fFlags;
bsalomonae59b772014-11-19 08:23:49 -0800441 GrStencilSettings fStencilSettings;
bsalomonae59b772014-11-19 08:23:49 -0800442 DrawFace fDrawFace;
joshualitt2fdeda02015-01-22 07:11:44 -0800443 mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
bsalomonac856c92015-08-27 06:30:17 -0700444 FragmentProcessorArray fColorFragmentProcessors;
445 FragmentProcessorArray fCoverageFragmentProcessors;
joshualitt44701df2015-02-23 14:44:57 -0800446 GrClip fClip;
egdaniel89af44a2014-09-26 06:15:04 -0700447
egdanielb6cbc382014-11-13 11:00:34 -0800448 mutable GrProcOptInfo fColorProcInfo;
449 mutable GrProcOptInfo fCoverageProcInfo;
egdanielb6cbc382014-11-13 11:00:34 -0800450
egdaniel8dd688b2015-01-22 10:16:09 -0800451 friend class GrPipeline;
tomhudson@google.com93813632011-10-27 20:21:16 +0000452};
453
454#endif