blob: 2bafd9aeabf2cee84cbdbff5191ac88da23bb273 [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"
egdaniel89af44a2014-09-26 06:15:04 -070016#include "GrRenderTarget.h"
17#include "GrStencil.h"
egdaniel95131432014-12-09 11:15:43 -080018#include "GrXferProcessor.h"
egdaniel89af44a2014-09-26 06:15:04 -070019#include "SkMatrix.h"
egdaniel87509242014-12-17 13:37:13 -080020#include "effects/GrCoverageSetOpXP.h"
egdaniel080e6732014-12-22 07:35:52 -080021#include "effects/GrDisableColorXP.h"
egdaniel95131432014-12-09 11:15:43 -080022#include "effects/GrPorterDuffXferProcessor.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000023#include "effects/GrSimpleTextureEffect.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000024
bsalomonabd30f52015-08-13 13:34:48 -070025class GrDrawBatch;
bsalomon4b91f762015-05-19 09:29:46 -070026class GrCaps;
egdaniel89af44a2014-09-26 06:15:04 -070027class GrPaint;
28class GrTexture;
egdaniel170f90b2014-09-16 12:54:40 -070029
bsalomonac856c92015-08-27 06:30:17 -070030class GrPipelineBuilder : public SkNoncopyable {
bsalomon@google.com2e3d1442012-03-26 20:33:54 +000031public:
egdaniel8dd688b2015-01-22 10:16:09 -080032 GrPipelineBuilder();
33
bsalomon@google.com52a5dcb2012-01-17 16:01:37 +000034 /**
joshualitt7b670db2015-07-09 13:25:02 -070035 * Initializes the GrPipelineBuilder based on a GrPaint, render target, and clip. Note
egdaniel8dd688b2015-01-22 10:16:09 -080036 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have
37 * no GrPaint equivalents are set to default values with the exception of vertex attribute state
38 * which is unmodified by this function and clipping which will be enabled.
bsalomon@google.comaf84e742012-10-05 13:23:24 +000039 */
joshualitt7b670db2015-07-09 13:25:02 -070040 GrPipelineBuilder(const GrPaint&, GrRenderTarget*, const GrClip&);
41
42 virtual ~GrPipelineBuilder();
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000043
bsalomon@google.com2401ae82012-01-17 21:03:05 +000044 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -080045 /// @name Fragment Processors
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000046 ///
bsalomon6be6f7c2015-02-26 13:05:21 -080047 /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage.
48 /// There are two chains of FPs, one for color and one for coverage. The first FP in each
49 /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output
50 /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs
51 /// feed their output to the GrXferProcessor which controls blending.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000052 ////
53
bsalomonac856c92015-08-27 06:30:17 -070054 int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); }
55 int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); }
56 int numFragmentProcessors() const { return this->numColorFragmentProcessors() +
57 this->numCoverageFragmentProcessors(); }
egdaniel378092f2014-12-03 10:40:13 -080058
bsalomonac856c92015-08-27 06:30:17 -070059 const GrFragmentProcessor* getColorFragmentProcessor(int idx) const {
60 return fColorFragmentProcessors[idx];
61 }
62 const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const {
63 return fCoverageFragmentProcessors[idx];
jvanverth@google.com65eb4d52013-03-19 18:51:02 +000064 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +000065
bsalomonac856c92015-08-27 06:30:17 -070066 const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcessor* processor) {
67 SkASSERT(processor);
68 fColorFragmentProcessors.push_back(SkRef(processor));
69 return processor;
70 }
71
72 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* processor) {
73 SkASSERT(processor);
74 fCoverageFragmentProcessors.push_back(SkRef(processor));
75 return processor;
bsalomon@google.comadc65362013-01-28 14:26:09 +000076 }
77
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000078 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +000079 * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
tomhudson@google.com1e8f0162012-07-20 16:25:18 +000080 */
joshualittb0a8a372014-09-23 09:50:21 -070081 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bsalomon4a339522015-10-06 08:40:50 -070082 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +000083 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000084
joshualittb0a8a372014-09-23 09:50:21 -070085 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bsalomon4a339522015-10-06 08:40:50 -070086 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000087 }
88
joshualittb0a8a372014-09-23 09:50:21 -070089 void addColorTextureProcessor(GrTexture* texture,
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000090 const SkMatrix& matrix,
91 const GrTextureParams& params) {
bsalomon4a339522015-10-06 08:40:50 -070092 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix,
bsalomonac856c92015-08-27 06:30:17 -070093 params))->unref();
joshualittb0a8a372014-09-23 09:50:21 -070094 }
95
96 void addCoverageTextureProcessor(GrTexture* texture,
97 const SkMatrix& matrix,
98 const GrTextureParams& params) {
bsalomon4a339522015-10-06 08:40:50 -070099 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix,
100 params))->unref();
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000101 }
tomhudson@google.com676e6602012-07-10 17:21:48 +0000102
robertphillips@google.com972265d2012-06-13 18:49:30 +0000103 /**
bsalomon6be6f7c2015-02-26 13:05:21 -0800104 * When this object is destroyed it will remove any color/coverage FPs from the pipeline builder
bsalomon4a339522015-10-06 08:40:50 -0700105 * that were added after its constructor.
joshualitt5e6ba212015-07-13 07:35:05 -0700106 * This class can transiently modify its "const" GrPipelineBuilder object but will restore it
107 * when done - so it is notionally "const" correct.
robertphillips@google.com972265d2012-06-13 18:49:30 +0000108 */
joshualitt4421a4c2015-07-13 09:36:41 -0700109 class AutoRestoreFragmentProcessorState : public ::SkNoncopyable {
robertphillips@google.com972265d2012-06-13 18:49:30 +0000110 public:
joshualitt4421a4c2015-07-13 09:36:41 -0700111 AutoRestoreFragmentProcessorState()
halcanary96fcdcc2015-08-27 07:41:13 -0700112 : fPipelineBuilder(nullptr)
bsalomon9b536522014-09-05 09:18:51 -0700113 , fColorEffectCnt(0)
joshualittaf2533a2015-09-09 10:00:12 -0700114 , fCoverageEffectCnt(0) {}
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000115
joshualitt4421a4c2015-07-13 09:36:41 -0700116 AutoRestoreFragmentProcessorState(const GrPipelineBuilder& ds)
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) {
joshualitt4421a4c2015-07-13 09:36:41 -0700120 this->set(&ds);
robertphillips@google.comf09b87d2013-06-13 20:06:44 +0000121 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000122
halcanary96fcdcc2015-08-27 07:41:13 -0700123 ~AutoRestoreFragmentProcessorState() { this->set(nullptr); }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000124
joshualitt5e6ba212015-07-13 07:35:05 -0700125 void set(const GrPipelineBuilder* ds);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000126
egdaniel8dd688b2015-01-22 10:16:09 -0800127 bool isSet() const { return SkToBool(fPipelineBuilder); }
bsalomon8af05232014-06-03 06:34:58 -0700128
bsalomon4a339522015-10-06 08:40:50 -0700129 const GrFragmentProcessor* addCoverageFragmentProcessor(
130 const GrFragmentProcessor* processor) {
joshualitt5e6ba212015-07-13 07:35:05 -0700131 SkASSERT(this->isSet());
bsalomonac856c92015-08-27 06:30:17 -0700132 return fPipelineBuilder->addCoverageFragmentProcessor(processor);
joshualitt5e6ba212015-07-13 07:35:05 -0700133 }
134
robertphillips@google.com972265d2012-06-13 18:49:30 +0000135 private:
joshualitt5e6ba212015-07-13 07:35:05 -0700136 // notionally const (as marginalia)
egdaniel8dd688b2015-01-22 10:16:09 -0800137 GrPipelineBuilder* fPipelineBuilder;
joshualitt5e6ba212015-07-13 07:35:05 -0700138 int fColorEffectCnt;
139 int fCoverageEffectCnt;
robertphillips@google.com972265d2012-06-13 18:49:30 +0000140 };
141
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000142 /// @}
143
144 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000145 /// @name Blending
146 ////
147
egdaniel89af44a2014-09-26 06:15:04 -0700148 /**
bsalomon6be6f7c2015-02-26 13:05:21 -0800149 * Installs a GrXPFactory. This object controls how src color, fractional pixel coverage,
150 * and the dst color are blended.
151 */
152 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
153 fXPFactory.reset(SkRef(xpFactory));
154 return xpFactory;
155 }
156
157 /**
158 * Sets a GrXPFactory that will ignore src color and perform a set operation between the draws
159 * output coverage and the destination. This is useful to render coverage masks as CSG.
160 */
161 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) {
162 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
163 }
164
165 /**
166 * Sets a GrXPFactory that disables color writes to the destination. This is useful when
167 * rendering to the stencil buffer.
168 */
169 void setDisableColorXPFactory() {
170 fXPFactory.reset(GrDisableColorXPFactory::Create());
171 }
172
173 const GrXPFactory* getXPFactory() const {
174 if (!fXPFactory) {
175 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
176 }
177 return fXPFactory.get();
178 }
179
180 /**
bsalomon6a44c6a2015-05-26 09:49:05 -0700181 * Checks whether the xp will need destination in a texture to correctly blend.
bsalomon6be6f7c2015-02-26 13:05:21 -0800182 */
bsalomon6a44c6a2015-05-26 09:49:05 -0700183 bool willXPNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI,
184 const GrProcOptInfo& coveragePOI) const;
joshualittd27f73e2014-12-29 07:43:36 -0800185
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000186 /// @}
187
bsalomon6be6f7c2015-02-26 13:05:21 -0800188
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000189 ///////////////////////////////////////////////////////////////////////////
190 /// @name Render Target
191 ////
192
193 /**
egdaniel89af44a2014-09-26 06:15:04 -0700194 * Retrieves the currently set render-target.
195 *
196 * @return The currently set render target.
197 */
bsalomon37dd3312014-11-03 08:47:23 -0800198 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700199
200 /**
bsalomon@google.comca432082013-01-23 19:53:46 +0000201 * Sets the render-target used at the next drawing call
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000202 *
203 * @param target The render target to set.
204 */
bsalomonae59b772014-11-19 08:23:49 -0800205 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000206
cdalton86ae0a92015-06-08 15:11:04 -0700207 /**
208 * Returns whether the rasterizer and stencil test (if any) will run at a higher sample rate
209 * than the color buffer. In is scenario, the higher sample rate is resolved during blending.
210 */
211 bool hasMixedSamples() const {
vbuzinovdded6962015-06-12 08:59:45 -0700212 return this->isHWAntialias() && !fRenderTarget->isUnifiedMultisampled();
cdalton86ae0a92015-06-08 15:11:04 -0700213 }
214
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000215 /// @}
216
217 ///////////////////////////////////////////////////////////////////////////
218 /// @name Stencil
219 ////
220
egdaniel89af44a2014-09-26 06:15:04 -0700221 const GrStencilSettings& getStencil() const { return fStencilSettings; }
222
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000223 /**
224 * Sets the stencil settings to use for the next draw.
225 * Changing the clip has the side-effect of possibly zeroing
226 * out the client settable stencil bits. So multipass algorithms
227 * using stencil should not change the clip between passes.
228 * @param settings the stencil settings to use.
229 */
bsalomon04ddf892014-11-19 12:36:22 -0800230 void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000231
bsalomon2ed5ef82014-07-07 08:44:05 -0700232 GrStencilSettings* stencil() { return &fStencilSettings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000233
bsalomon6be6f7c2015-02-26 13:05:21 -0800234 /**
235 * AutoRestoreStencil
236 *
237 * This simple struct saves and restores the stencil settings
joshualitt5e6ba212015-07-13 07:35:05 -0700238 * This class can transiently modify its "const" GrPipelineBuilder object but will restore it
239 * when done - so it is notionally "const" correct.
bsalomon6be6f7c2015-02-26 13:05:21 -0800240 */
241 class AutoRestoreStencil : public ::SkNoncopyable {
242 public:
halcanary96fcdcc2015-08-27 07:41:13 -0700243 AutoRestoreStencil() : fPipelineBuilder(nullptr) {}
bsalomon6be6f7c2015-02-26 13:05:21 -0800244
halcanary96fcdcc2015-08-27 07:41:13 -0700245 AutoRestoreStencil(const GrPipelineBuilder& ds) : fPipelineBuilder(nullptr) { this->set(&ds); }
bsalomon6be6f7c2015-02-26 13:05:21 -0800246
halcanary96fcdcc2015-08-27 07:41:13 -0700247 ~AutoRestoreStencil() { this->set(nullptr); }
bsalomon6be6f7c2015-02-26 13:05:21 -0800248
joshualitt5e6ba212015-07-13 07:35:05 -0700249 void set(const GrPipelineBuilder* ds) {
bsalomon6be6f7c2015-02-26 13:05:21 -0800250 if (fPipelineBuilder) {
251 fPipelineBuilder->setStencil(fStencilSettings);
252 }
joshualitt5e6ba212015-07-13 07:35:05 -0700253 fPipelineBuilder = const_cast<GrPipelineBuilder*>(ds);
bsalomon6be6f7c2015-02-26 13:05:21 -0800254 if (ds) {
255 fStencilSettings = ds->getStencil();
256 }
257 }
258
259 bool isSet() const { return SkToBool(fPipelineBuilder); }
260
joshualitt5e6ba212015-07-13 07:35:05 -0700261 void setStencil(const GrStencilSettings& settings) {
262 SkASSERT(this->isSet());
263 fPipelineBuilder->setStencil(settings);
264 }
265
bsalomon6be6f7c2015-02-26 13:05:21 -0800266 private:
joshualitt5e6ba212015-07-13 07:35:05 -0700267 // notionally const (as marginalia)
bsalomon6be6f7c2015-02-26 13:05:21 -0800268 GrPipelineBuilder* fPipelineBuilder;
269 GrStencilSettings fStencilSettings;
270 };
271
272
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000273 /// @}
274
275 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000276 /// @name State Flags
277 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000278
egdaniel89af44a2014-09-26 06:15:04 -0700279 /**
280 * Flags that affect rendering. Controlled using enable/disableState(). All
281 * default to disabled.
282 */
bsalomond79c5492015-04-27 10:07:04 -0700283 enum Flags {
egdaniel89af44a2014-09-26 06:15:04 -0700284 /**
egdaniel89af44a2014-09-26 06:15:04 -0700285 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
286 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
287 * the 3D API.
288 */
bsalomonaca31fe2015-09-22 11:38:46 -0700289 kHWAntialias_Flag = 0x01,
egdaniel89af44a2014-09-26 06:15:04 -0700290
bsalomond79c5492015-04-27 10:07:04 -0700291 /**
292 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
293 */
bsalomonaca31fe2015-09-22 11:38:46 -0700294 kSnapVerticesToPixelCenters_Flag = 0x02,
bsalomond79c5492015-04-27 10:07:04 -0700295
296 kLast_Flag = kSnapVerticesToPixelCenters_Flag,
egdaniel89af44a2014-09-26 06:15:04 -0700297 };
298
bsalomond79c5492015-04-27 10:07:04 -0700299 bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); }
300 bool snapVerticesToPixelCenters() const {
301 return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000302
303 /**
304 * Enable render state settings.
305 *
bsalomond79c5492015-04-27 10:07:04 -0700306 * @param flags bitfield of Flags specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000307 */
bsalomond79c5492015-04-27 10:07:04 -0700308 void enableState(uint32_t flags) { fFlags |= flags; }
309
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000310 /**
311 * Disable render state settings.
312 *
bsalomond79c5492015-04-27 10:07:04 -0700313 * @param flags bitfield of Flags specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000314 */
bsalomond79c5492015-04-27 10:07:04 -0700315 void disableState(uint32_t flags) { fFlags &= ~(flags); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000316
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000317 /**
bsalomond79c5492015-04-27 10:07:04 -0700318 * Enable or disable flags based on a boolean.
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000319 *
bsalomond79c5492015-04-27 10:07:04 -0700320 * @param flags bitfield of Flags to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000321 * @param enable if true enable stateBits, otherwise disable
322 */
bsalomond79c5492015-04-27 10:07:04 -0700323 void setState(uint32_t flags, bool enable) {
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000324 if (enable) {
bsalomond79c5492015-04-27 10:07:04 -0700325 this->enableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000326 } else {
bsalomond79c5492015-04-27 10:07:04 -0700327 this->disableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000328 }
329 }
330
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000331 /// @}
332
333 ///////////////////////////////////////////////////////////////////////////
334 /// @name Face Culling
335 ////
336
egdaniel89af44a2014-09-26 06:15:04 -0700337 enum DrawFace {
338 kInvalid_DrawFace = -1,
339
340 kBoth_DrawFace,
341 kCCW_DrawFace,
342 kCW_DrawFace,
343 };
344
345 /**
346 * Gets whether the target is drawing clockwise, counterclockwise,
347 * or both faces.
348 * @return the current draw face(s).
349 */
350 DrawFace getDrawFace() const { return fDrawFace; }
351
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000352 /**
353 * Controls whether clockwise, counterclockwise, or both faces are drawn.
354 * @param face the face(s) to draw.
355 */
356 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000357 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700358 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000359 }
360
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000361 /// @}
362
363 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000364
bsalomonabd30f52015-08-13 13:34:48 -0700365 const GrProcOptInfo& colorProcInfo(const GrDrawBatch* batch) const {
joshualitt4d8da812015-01-28 12:53:54 -0800366 this->calcColorInvariantOutput(batch);
367 return fColorProcInfo;
368 }
369
bsalomonabd30f52015-08-13 13:34:48 -0700370 const GrProcOptInfo& coverageProcInfo(const GrDrawBatch* batch) const {
joshualitt4d8da812015-01-28 12:53:54 -0800371 this->calcCoverageInvariantOutput(batch);
372 return fCoverageProcInfo;
373 }
joshualitt44701df2015-02-23 14:44:57 -0800374
375 void setClip(const GrClip& clip) { fClip = clip; }
376 const GrClip& clip() const { return fClip; }
377
egdaniele36914c2015-02-13 09:00:33 -0800378private:
379 // Calculating invariant color / coverage information is expensive, so we partially cache the
380 // results.
381 //
382 // canUseFracCoveragePrimProc() - Called in regular skia draw, caches results but only for a
383 // specific color and coverage. May be called multiple times
egdaniele36914c2015-02-13 09:00:33 -0800384 // GrOptDrawState constructor - never caches results
joshualittd15e4e42015-01-26 13:30:10 -0800385
386 /**
joshualitt4d8da812015-01-28 12:53:54 -0800387 * GrBatch provides the initial seed for these loops based off of its initial geometry data
388 */
bsalomonabd30f52015-08-13 13:34:48 -0700389 void calcColorInvariantOutput(const GrDrawBatch*) const;
390 void calcCoverageInvariantOutput(const GrDrawBatch*) const;
joshualitt4d8da812015-01-28 12:53:54 -0800391
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000392 // Some of the auto restore objects assume that no effects are removed during their lifetime.
393 // This is used to assert that this condition holds.
joshualitt5e6ba212015-07-13 07:35:05 -0700394 SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000395
bsalomonac856c92015-08-27 06:30:17 -0700396 typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArray;
egdaniel89af44a2014-09-26 06:15:04 -0700397
bsalomonae59b772014-11-19 08:23:49 -0800398 SkAutoTUnref<GrRenderTarget> fRenderTarget;
bsalomond79c5492015-04-27 10:07:04 -0700399 uint32_t fFlags;
bsalomonae59b772014-11-19 08:23:49 -0800400 GrStencilSettings fStencilSettings;
bsalomonae59b772014-11-19 08:23:49 -0800401 DrawFace fDrawFace;
joshualitt2fdeda02015-01-22 07:11:44 -0800402 mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
bsalomonac856c92015-08-27 06:30:17 -0700403 FragmentProcessorArray fColorFragmentProcessors;
404 FragmentProcessorArray fCoverageFragmentProcessors;
joshualitt44701df2015-02-23 14:44:57 -0800405 GrClip fClip;
egdaniel89af44a2014-09-26 06:15:04 -0700406
egdanielb6cbc382014-11-13 11:00:34 -0800407 mutable GrProcOptInfo fColorProcInfo;
408 mutable GrProcOptInfo fCoverageProcInfo;
egdanielb6cbc382014-11-13 11:00:34 -0800409
egdaniel8dd688b2015-01-22 10:16:09 -0800410 friend class GrPipeline;
tomhudson@google.com93813632011-10-27 20:21:16 +0000411};
412
413#endif