blob: 45fc574bde78c8b5a511d8223f5133f16efe9b6d [file] [log] [blame]
tomhudson@google.com93813632011-10-27 20:21:16 +00001/*
2 * Copyright 2011 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.
6 */
7
8#ifndef GrDrawState_DEFINED
9#define GrDrawState_DEFINED
10
egdaniel89af44a2014-09-26 06:15:04 -070011
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000012#include "GrBlend.h"
egdanielc0648242014-09-22 13:17:02 -070013#include "GrDrawTargetCaps.h"
bsalomon6251d172014-10-15 10:50:36 -070014#include "GrGeometryProcessor.h"
bsalomonf96ba022014-09-17 08:05:40 -070015#include "GrGpuResourceRef.h"
bsalomonae59b772014-11-19 08:23:49 -080016#include "GrFragmentStage.h"
egdanielb6cbc382014-11-13 11:00:34 -080017#include "GrProcOptInfo.h"
egdaniel89af44a2014-09-26 06:15:04 -070018#include "GrRenderTarget.h"
19#include "GrStencil.h"
egdaniel95131432014-12-09 11:15:43 -080020#include "GrXferProcessor.h"
egdaniel89af44a2014-09-26 06:15:04 -070021#include "SkMatrix.h"
egdaniel87509242014-12-17 13:37:13 -080022#include "effects/GrCoverageSetOpXP.h"
egdaniel080e6732014-12-22 07:35:52 -080023#include "effects/GrDisableColorXP.h"
egdaniel95131432014-12-09 11:15:43 -080024#include "effects/GrPorterDuffXferProcessor.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000025#include "effects/GrSimpleTextureEffect.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000026
egdaniel89af44a2014-09-26 06:15:04 -070027class GrDrawTargetCaps;
egdaniel89af44a2014-09-26 06:15:04 -070028class GrPaint;
29class GrTexture;
egdaniel170f90b2014-09-16 12:54:40 -070030
joshualitt9853cce2014-11-17 14:22:48 -080031class GrDrawState {
bsalomon@google.com2e3d1442012-03-26 20:33:54 +000032public:
joshualitt2fdeda02015-01-22 07:11:44 -080033 GrDrawState();
bsalomon@google.com137f1342013-05-29 21:27:53 +000034 /**
35 * Copies another draw state.
36 **/
joshualitt9853cce2014-11-17 14:22:48 -080037 GrDrawState(const GrDrawState& state) {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +000038 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
bsalomon@google.com46f7afb2012-01-18 19:51:55 +000039 *this = state;
40 }
41
egdaniel170f90b2014-09-16 12:54:40 -070042 virtual ~GrDrawState();
bsalomon@google.com137f1342013-05-29 21:27:53 +000043
bsalomon@google.com52a5dcb2012-01-17 16:01:37 +000044 /**
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +000045 * Initializes the GrDrawState based on a GrPaint, view matrix and render target. Note that
46 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that have no GrPaint
bsalomon9c0822a2014-08-11 11:07:48 -070047 * equivalents are set to default values with the exception of vertex attribute state which
48 * is unmodified by this function and clipping which will be enabled.
bsalomon@google.comaf84e742012-10-05 13:23:24 +000049 */
joshualitt8059eb92014-12-29 15:10:07 -080050 void setFromPaint(const GrPaint&, GrRenderTarget*);
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000051
jvanverth@google.com9b855c72013-03-01 18:21:22 +000052 /// @}
53
jvanverth@google.com9b855c72013-03-01 18:21:22 +000054 /**
bsalomon62c447d2014-08-08 08:08:50 -070055 * Depending on features available in the underlying 3D API and the color blend mode requested
56 * it may or may not be possible to correctly blend with fractional pixel coverage generated by
57 * the fragment shader.
58 *
59 * This function considers the current draw state and the draw target's capabilities to
60 * determine whether coverage can be handled correctly. This function assumes that the caller
joshualitt2e3b3e32014-12-09 13:31:14 -080061 * intends to specify fractional pixel coverage via a primitive processor but may not have
62 * specified it yet.
bsalomon62c447d2014-08-08 08:08:50 -070063 */
joshualitt2e3b3e32014-12-09 13:31:14 -080064 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps) const;
bsalomon62c447d2014-08-08 08:08:50 -070065
egdaniel89af44a2014-09-26 06:15:04 -070066 /**
egdanielcd8b6302014-11-11 14:46:05 -080067 * This function returns true if the render target destination pixel values will be read for
68 * blending during draw.
69 */
joshualitt56995b52014-12-11 15:44:02 -080070 bool willBlendWithDst(const GrPrimitiveProcessor*) const;
joshualittbd769d02014-09-04 08:56:46 -070071
bsalomon@google.com2401ae82012-01-17 21:03:05 +000072 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.comadc65362013-01-28 14:26:09 +000073 /// @name Effect Stages
joshualittb0a8a372014-09-23 09:50:21 -070074 /// Each stage hosts a GrProcessor. The effect produces an output color or coverage in the
75 /// fragment shader. Its inputs are the output from the previous stage as well as some variables
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000076 /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color,
77 /// the fragment position, local coordinates).
78 ///
79 /// The stages are divided into two sets, color-computing and coverage-computing. The final
80 /// color stage produces the final pixel color. The coverage-computing stages function exactly
81 /// as the color-computing but the output of the final coverage stage is treated as a fractional
82 /// pixel coverage rather than as input to the src/dst color blend step.
83 ///
84 /// The input color to the first color-stage is either the constant color or interpolated
85 /// per-vertex colors. The input to the first coverage stage is either a constant coverage
86 /// (usually full-coverage) or interpolated per-vertex coverage.
87 ///
88 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the
89 /// the color / coverage distinction.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000090 ////
91
egdaniel89af44a2014-09-26 06:15:04 -070092 int numColorStages() const { return fColorStages.count(); }
93 int numCoverageStages() const { return fCoverageStages.count(); }
joshualitt4dd99882014-11-11 08:51:30 -080094 int numFragmentStages() const { return this->numColorStages() + this->numCoverageStages(); }
egdaniel378092f2014-12-03 10:40:13 -080095
joshualitt2fdeda02015-01-22 07:11:44 -080096 const GrXPFactory* getXPFactory() const {
97 if (!fXPFactory) {
98 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
99 }
100 return fXPFactory.get();
101 }
egdaniel378092f2014-12-03 10:40:13 -0800102
egdaniel89af44a2014-09-26 06:15:04 -0700103 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[idx]; }
104 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; }
105
106 /**
egdaniel71e236c2015-01-20 06:34:51 -0800107 * Checks whether the xp will read the dst pixel color.
108 * TODO: remove when we have dstCpy contained inside of GrXP
egdaniel89af44a2014-09-26 06:15:04 -0700109 */
egdaniel71e236c2015-01-20 06:34:51 -0800110 bool willEffectReadDstColor() const;
egdaniel89af44a2014-09-26 06:15:04 -0700111
egdaniel95131432014-12-09 11:15:43 -0800112 /**
113 * The xfer processor factory.
114 */
115 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
116 fXPFactory.reset(SkRef(xpFactory));
117 return xpFactory;
118 }
119
120 void setPorterDuffXPFactory(SkXfermode::Mode mode) {
121 fXPFactory.reset(GrPorterDuffXPFactory::Create(mode));
122 }
123
124 void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) {
125 fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst));
126 }
127
egdaniel87509242014-12-17 13:37:13 -0800128 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) {
129 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
130 }
131
egdaniel080e6732014-12-22 07:35:52 -0800132 void setDisableColorXPFactory() {
133 fXPFactory.reset(GrDisableColorXPFactory::Create());
134 }
135
joshualittb0a8a372014-09-23 09:50:21 -0700136 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700137 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700138 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect));
egdanielb6cbc382014-11-13 11:00:34 -0800139 fColorProcInfoValid = false;
jvanverth@google.com65eb4d52013-03-19 18:51:02 +0000140 return effect;
141 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +0000142
joshualittb0a8a372014-09-23 09:50:21 -0700143 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700144 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700145 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect));
egdanielb6cbc382014-11-13 11:00:34 -0800146 fCoverageProcInfoValid = false;
bsalomon@google.comadc65362013-01-28 14:26:09 +0000147 return effect;
148 }
149
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000150 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000151 * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
tomhudson@google.com1e8f0162012-07-20 16:25:18 +0000152 */
joshualittb0a8a372014-09-23 09:50:21 -0700153 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
154 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +0000155 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000156
joshualittb0a8a372014-09-23 09:50:21 -0700157 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
158 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000159 }
160
joshualittb0a8a372014-09-23 09:50:21 -0700161 void addColorTextureProcessor(GrTexture* texture,
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000162 const SkMatrix& matrix,
163 const GrTextureParams& params) {
joshualittb0a8a372014-09-23 09:50:21 -0700164 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
165 }
166
167 void addCoverageTextureProcessor(GrTexture* texture,
168 const SkMatrix& matrix,
169 const GrTextureParams& params) {
170 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000171 }
tomhudson@google.com676e6602012-07-10 17:21:48 +0000172
robertphillips@google.com972265d2012-06-13 18:49:30 +0000173 /**
bsalomon9b536522014-09-05 09:18:51 -0700174 * When this object is destroyed it will remove any color/coverage effects from the draw state
175 * that were added after its constructor.
176 *
177 * This class has strange behavior around geometry processor. If there is a GP on the draw state
178 * it will assert that the GP is not modified until after the destructor of the ARE. If the
179 * draw state has a NULL GP when the ARE is constructed then it will reset it to null in the
180 * destructor.
181 *
182 * TODO: We'd prefer for the ARE to just save and restore the GP. However, this would add
183 * significant complexity to the multi-ref architecture for deferred drawing. Once GrDrawState
184 * and GrOptDrawState are fully separated then GrDrawState will never be in the deferred
185 * execution state and GrOptDrawState always will be (and will be immutable and therefore
186 * unable to have an ARE). At this point we can restore sanity and have the ARE save and restore
187 * the GP.
robertphillips@google.com972265d2012-06-13 18:49:30 +0000188 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000189 class AutoRestoreEffects : public ::SkNoncopyable {
robertphillips@google.com972265d2012-06-13 18:49:30 +0000190 public:
bsalomon9b536522014-09-05 09:18:51 -0700191 AutoRestoreEffects()
192 : fDrawState(NULL)
bsalomon9b536522014-09-05 09:18:51 -0700193 , fColorEffectCnt(0)
194 , fCoverageEffectCnt(0) {}
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000195
bsalomon9b536522014-09-05 09:18:51 -0700196 AutoRestoreEffects(GrDrawState* ds)
197 : fDrawState(NULL)
bsalomon9b536522014-09-05 09:18:51 -0700198 , fColorEffectCnt(0)
199 , fCoverageEffectCnt(0) {
skia.committer@gmail.com5c493d52013-06-14 07:00:49 +0000200 this->set(ds);
robertphillips@google.comf09b87d2013-06-13 20:06:44 +0000201 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000202
203 ~AutoRestoreEffects() { this->set(NULL); }
204
bsalomon8f727332014-08-05 07:50:06 -0700205 void set(GrDrawState* ds);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000206
bsalomon49f085d2014-09-05 13:34:00 -0700207 bool isSet() const { return SkToBool(fDrawState); }
bsalomon8af05232014-06-03 06:34:58 -0700208
robertphillips@google.com972265d2012-06-13 18:49:30 +0000209 private:
bsalomon9b536522014-09-05 09:18:51 -0700210 GrDrawState* fDrawState;
bsalomon9b536522014-09-05 09:18:51 -0700211 int fColorEffectCnt;
212 int fCoverageEffectCnt;
robertphillips@google.com972265d2012-06-13 18:49:30 +0000213 };
214
joshualitta58fe352014-10-27 08:39:00 -0700215 /**
216 * AutoRestoreStencil
217 *
218 * This simple struct saves and restores the stencil settings
219 */
220 class AutoRestoreStencil : public ::SkNoncopyable {
221 public:
222 AutoRestoreStencil() : fDrawState(NULL) {}
223
224 AutoRestoreStencil(GrDrawState* ds) : fDrawState(NULL) { this->set(ds); }
225
226 ~AutoRestoreStencil() { this->set(NULL); }
227
228 void set(GrDrawState* ds) {
229 if (fDrawState) {
230 fDrawState->setStencil(fStencilSettings);
231 }
232 fDrawState = ds;
233 if (ds) {
234 fStencilSettings = ds->getStencil();
235 }
236 }
237
238 bool isSet() const { return SkToBool(fDrawState); }
239
240 private:
241 GrDrawState* fDrawState;
242 GrStencilSettings fStencilSettings;
243 };
244
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000245 /// @}
246
247 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000248 /// @name Blending
249 ////
250
egdaniel89af44a2014-09-26 06:15:04 -0700251 /**
252 * Determines whether multiplying the computed per-pixel color by the pixel's fractional
253 * coverage before the blend will give the correct final destination color. In general it
254 * will not as coverage is applied after blending.
255 */
256 bool canTweakAlphaForCoverage() const;
257
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000258 /// @}
259
joshualittd27f73e2014-12-29 07:43:36 -0800260
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000261 /// @}
262
263 ///////////////////////////////////////////////////////////////////////////
264 /// @name Render Target
265 ////
266
267 /**
egdaniel89af44a2014-09-26 06:15:04 -0700268 * Retrieves the currently set render-target.
269 *
270 * @return The currently set render target.
271 */
bsalomon37dd3312014-11-03 08:47:23 -0800272 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700273
274 /**
bsalomon@google.comca432082013-01-23 19:53:46 +0000275 * Sets the render-target used at the next drawing call
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000276 *
277 * @param target The render target to set.
278 */
bsalomonae59b772014-11-19 08:23:49 -0800279 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000280
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000281 /// @}
282
283 ///////////////////////////////////////////////////////////////////////////
284 /// @name Stencil
285 ////
286
egdaniel89af44a2014-09-26 06:15:04 -0700287 const GrStencilSettings& getStencil() const { return fStencilSettings; }
288
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000289 /**
290 * Sets the stencil settings to use for the next draw.
291 * Changing the clip has the side-effect of possibly zeroing
292 * out the client settable stencil bits. So multipass algorithms
293 * using stencil should not change the clip between passes.
294 * @param settings the stencil settings to use.
295 */
bsalomon04ddf892014-11-19 12:36:22 -0800296 void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000297
298 /**
299 * Shortcut to disable stencil testing and ops.
300 */
bsalomon04ddf892014-11-19 12:36:22 -0800301 void disableStencil() { fStencilSettings.setDisabled(); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000302
bsalomon2ed5ef82014-07-07 08:44:05 -0700303 GrStencilSettings* stencil() { return &fStencilSettings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000304
305 /// @}
306
307 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000308 /// @name State Flags
309 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000310
egdaniel89af44a2014-09-26 06:15:04 -0700311 /**
312 * Flags that affect rendering. Controlled using enable/disableState(). All
313 * default to disabled.
314 */
315 enum StateBits {
316 /**
317 * Perform dithering. TODO: Re-evaluate whether we need this bit
318 */
319 kDither_StateBit = 0x01,
320 /**
321 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
322 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
323 * the 3D API.
324 */
325 kHWAntialias_StateBit = 0x02,
326 /**
327 * Draws will respect the clip, otherwise the clip is ignored.
328 */
329 kClip_StateBit = 0x04,
egdaniel89af44a2014-09-26 06:15:04 -0700330
egdaniel080e6732014-12-22 07:35:52 -0800331 kLast_StateBit = kClip_StateBit,
egdaniel89af44a2014-09-26 06:15:04 -0700332 };
333
egdaniel89af44a2014-09-26 06:15:04 -0700334 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); }
bsalomon04ddf892014-11-19 12:36:22 -0800335 bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); }
336 bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000337
338 /**
339 * Enable render state settings.
340 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000341 * @param stateBits bitfield of StateBits specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000342 */
bsalomon04ddf892014-11-19 12:36:22 -0800343 void enableState(uint32_t stateBits) { fFlagBits |= stateBits; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000344
345 /**
346 * Disable render state settings.
347 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000348 * @param stateBits bitfield of StateBits specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000349 */
bsalomon04ddf892014-11-19 12:36:22 -0800350 void disableState(uint32_t stateBits) { fFlagBits &= ~(stateBits); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000351
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000352 /**
353 * Enable or disable stateBits based on a boolean.
354 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000355 * @param stateBits bitfield of StateBits to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000356 * @param enable if true enable stateBits, otherwise disable
357 */
358 void setState(uint32_t stateBits, bool enable) {
359 if (enable) {
360 this->enableState(stateBits);
361 } else {
362 this->disableState(stateBits);
363 }
364 }
365
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000366 /// @}
367
368 ///////////////////////////////////////////////////////////////////////////
369 /// @name Face Culling
370 ////
371
egdaniel89af44a2014-09-26 06:15:04 -0700372 enum DrawFace {
373 kInvalid_DrawFace = -1,
374
375 kBoth_DrawFace,
376 kCCW_DrawFace,
377 kCW_DrawFace,
378 };
379
380 /**
381 * Gets whether the target is drawing clockwise, counterclockwise,
382 * or both faces.
383 * @return the current draw face(s).
384 */
385 DrawFace getDrawFace() const { return fDrawFace; }
386
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000387 /**
388 * Controls whether clockwise, counterclockwise, or both faces are drawn.
389 * @param face the face(s) to draw.
390 */
391 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000392 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700393 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000394 }
395
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000396 /// @}
397
398 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000399
bsalomon8f727332014-08-05 07:50:06 -0700400 GrDrawState& operator= (const GrDrawState& that);
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000401
402private:
joshualitt56995b52014-12-11 15:44:02 -0800403 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const {
404 this->calcColorInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800405 return fColorProcInfo;
406 }
407
joshualitt56995b52014-12-11 15:44:02 -0800408 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const {
409 this->calcCoverageInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800410 return fCoverageProcInfo;
411 }
412
egdaniel89af44a2014-09-26 06:15:04 -0700413 /**
joshualitt56995b52014-12-11 15:44:02 -0800414 * If fColorProcInfoValid is false, function calculates the invariant output for the color
415 * stages and results are stored in fColorProcInfo.
egdaniel89af44a2014-09-26 06:15:04 -0700416 */
joshualitt56995b52014-12-11 15:44:02 -0800417 void calcColorInvariantOutput(const GrPrimitiveProcessor*) const;
418
419 /**
420 * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage
421 * stages and results are stored in fCoverageProcInfo.
422 */
423 void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const;
egdaniel89af44a2014-09-26 06:15:04 -0700424
egdanielb6cbc382014-11-13 11:00:34 -0800425 /**
426 * If fColorProcInfoValid is false, function calculates the invariant output for the color
427 * stages and results are stored in fColorProcInfo.
428 */
joshualitt2e3b3e32014-12-09 13:31:14 -0800429 void calcColorInvariantOutput(GrColor) const;
egdanielb6cbc382014-11-13 11:00:34 -0800430
431 /**
432 * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage
433 * stages and results are stored in fCoverageProcInfo.
434 */
joshualitt2e3b3e32014-12-09 13:31:14 -0800435 void calcCoverageInvariantOutput(GrColor) const;
egdanielb6cbc382014-11-13 11:00:34 -0800436
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000437 // Some of the auto restore objects assume that no effects are removed during their lifetime.
438 // This is used to assert that this condition holds.
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000439 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000440
joshualitta5305a12014-10-10 17:47:00 -0700441 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray;
egdaniel89af44a2014-09-26 06:15:04 -0700442
bsalomonae59b772014-11-19 08:23:49 -0800443 SkAutoTUnref<GrRenderTarget> fRenderTarget;
bsalomonae59b772014-11-19 08:23:49 -0800444 uint32_t fFlagBits;
bsalomonae59b772014-11-19 08:23:49 -0800445 GrStencilSettings fStencilSettings;
bsalomonae59b772014-11-19 08:23:49 -0800446 DrawFace fDrawFace;
joshualitt2fdeda02015-01-22 07:11:44 -0800447 mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
bsalomonae59b772014-11-19 08:23:49 -0800448 FragmentStageArray fColorStages;
449 FragmentStageArray fCoverageStages;
egdaniel89af44a2014-09-26 06:15:04 -0700450
egdanielb6cbc382014-11-13 11:00:34 -0800451 mutable GrProcOptInfo fColorProcInfo;
452 mutable GrProcOptInfo fCoverageProcInfo;
453 mutable bool fColorProcInfoValid;
454 mutable bool fCoverageProcInfoValid;
joshualitt2e3b3e32014-12-09 13:31:14 -0800455 mutable GrColor fColorCache;
456 mutable GrColor fCoverageCache;
joshualitt56995b52014-12-11 15:44:02 -0800457 mutable const GrPrimitiveProcessor* fColorPrimProc;
458 mutable const GrPrimitiveProcessor* fCoveragePrimProc;
egdanielb6cbc382014-11-13 11:00:34 -0800459
egdanielb109ac22014-10-07 06:45:44 -0700460 friend class GrOptDrawState;
tomhudson@google.com93813632011-10-27 20:21:16 +0000461};
462
463#endif