blob: ce29e6ca6894a2fd57ee77c7e39ea5df29699693 [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:
egdaniel69bb90c2014-11-11 07:32:45 -080033 GrDrawState() {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +000034 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000035 this->reset();
36 }
tomhudson@google.com93813632011-10-27 20:21:16 +000037
bsalomon@google.com137f1342013-05-29 21:27:53 +000038 /**
39 * Copies another draw state.
40 **/
joshualitt9853cce2014-11-17 14:22:48 -080041 GrDrawState(const GrDrawState& state) {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +000042 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
bsalomon@google.com46f7afb2012-01-18 19:51:55 +000043 *this = state;
44 }
45
egdaniel170f90b2014-09-16 12:54:40 -070046 virtual ~GrDrawState();
bsalomon@google.com137f1342013-05-29 21:27:53 +000047
bsalomon@google.com52a5dcb2012-01-17 16:01:37 +000048 /**
joshualittb0a8a372014-09-23 09:50:21 -070049 * Resets to the default state. GrProcessors will be removed from all stages.
rmistry@google.comd6176b02012-08-23 18:14:13 +000050 */
joshualitt8059eb92014-12-29 15:10:07 -080051 void reset() { this->onReset(); }
bsalomon@google.comaf84e742012-10-05 13:23:24 +000052
53 /**
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +000054 * Initializes the GrDrawState based on a GrPaint, view matrix and render target. Note that
55 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that have no GrPaint
bsalomon9c0822a2014-08-11 11:07:48 -070056 * equivalents are set to default values with the exception of vertex attribute state which
57 * is unmodified by this function and clipping which will be enabled.
bsalomon@google.comaf84e742012-10-05 13:23:24 +000058 */
joshualitt8059eb92014-12-29 15:10:07 -080059 void setFromPaint(const GrPaint&, GrRenderTarget*);
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000060
jvanverth@google.com9b855c72013-03-01 18:21:22 +000061 /// @}
62
jvanverth@google.com9b855c72013-03-01 18:21:22 +000063 /**
bsalomon62c447d2014-08-08 08:08:50 -070064 * Depending on features available in the underlying 3D API and the color blend mode requested
65 * it may or may not be possible to correctly blend with fractional pixel coverage generated by
66 * the fragment shader.
67 *
68 * This function considers the current draw state and the draw target's capabilities to
69 * determine whether coverage can be handled correctly. This function assumes that the caller
joshualitt2e3b3e32014-12-09 13:31:14 -080070 * intends to specify fractional pixel coverage via a primitive processor but may not have
71 * specified it yet.
bsalomon62c447d2014-08-08 08:08:50 -070072 */
joshualitt2e3b3e32014-12-09 13:31:14 -080073 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps) const;
bsalomon62c447d2014-08-08 08:08:50 -070074
egdaniel89af44a2014-09-26 06:15:04 -070075 /**
egdanielcd8b6302014-11-11 14:46:05 -080076 * This function returns true if the render target destination pixel values will be read for
77 * blending during draw.
78 */
joshualitt56995b52014-12-11 15:44:02 -080079 bool willBlendWithDst(const GrPrimitiveProcessor*) const;
joshualittbd769d02014-09-04 08:56:46 -070080
bsalomon@google.com2401ae82012-01-17 21:03:05 +000081 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.comadc65362013-01-28 14:26:09 +000082 /// @name Effect Stages
joshualittb0a8a372014-09-23 09:50:21 -070083 /// Each stage hosts a GrProcessor. The effect produces an output color or coverage in the
84 /// fragment shader. Its inputs are the output from the previous stage as well as some variables
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000085 /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color,
86 /// the fragment position, local coordinates).
87 ///
88 /// The stages are divided into two sets, color-computing and coverage-computing. The final
89 /// color stage produces the final pixel color. The coverage-computing stages function exactly
90 /// as the color-computing but the output of the final coverage stage is treated as a fractional
91 /// pixel coverage rather than as input to the src/dst color blend step.
92 ///
93 /// The input color to the first color-stage is either the constant color or interpolated
94 /// per-vertex colors. The input to the first coverage stage is either a constant coverage
95 /// (usually full-coverage) or interpolated per-vertex coverage.
96 ///
97 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the
98 /// the color / coverage distinction.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000099 ////
100
egdaniel89af44a2014-09-26 06:15:04 -0700101 int numColorStages() const { return fColorStages.count(); }
102 int numCoverageStages() const { return fCoverageStages.count(); }
joshualitt4dd99882014-11-11 08:51:30 -0800103 int numFragmentStages() const { return this->numColorStages() + this->numCoverageStages(); }
egdaniel378092f2014-12-03 10:40:13 -0800104
105 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); }
106
egdaniel89af44a2014-09-26 06:15:04 -0700107 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[idx]; }
108 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; }
109
110 /**
111 * Checks whether any of the effects will read the dst pixel color.
joshualitt2e3b3e32014-12-09 13:31:14 -0800112 * TODO remove when we have an XP
egdaniel89af44a2014-09-26 06:15:04 -0700113 */
joshualitt56995b52014-12-11 15:44:02 -0800114 bool willEffectReadDstColor(const GrPrimitiveProcessor*) const;
egdaniel89af44a2014-09-26 06:15:04 -0700115
egdaniel95131432014-12-09 11:15:43 -0800116 /**
117 * The xfer processor factory.
118 */
119 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
120 fXPFactory.reset(SkRef(xpFactory));
121 return xpFactory;
122 }
123
124 void setPorterDuffXPFactory(SkXfermode::Mode mode) {
125 fXPFactory.reset(GrPorterDuffXPFactory::Create(mode));
126 }
127
128 void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) {
129 fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst));
130 }
131
egdaniel87509242014-12-17 13:37:13 -0800132 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) {
133 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
134 }
135
egdaniel080e6732014-12-22 07:35:52 -0800136 void setDisableColorXPFactory() {
137 fXPFactory.reset(GrDisableColorXPFactory::Create());
138 }
139
joshualittb0a8a372014-09-23 09:50:21 -0700140 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700141 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700142 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect));
egdanielb6cbc382014-11-13 11:00:34 -0800143 fColorProcInfoValid = false;
jvanverth@google.com65eb4d52013-03-19 18:51:02 +0000144 return effect;
145 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +0000146
joshualittb0a8a372014-09-23 09:50:21 -0700147 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700148 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700149 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect));
egdanielb6cbc382014-11-13 11:00:34 -0800150 fCoverageProcInfoValid = false;
bsalomon@google.comadc65362013-01-28 14:26:09 +0000151 return effect;
152 }
153
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000154 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000155 * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
tomhudson@google.com1e8f0162012-07-20 16:25:18 +0000156 */
joshualittb0a8a372014-09-23 09:50:21 -0700157 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
158 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +0000159 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000160
joshualittb0a8a372014-09-23 09:50:21 -0700161 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
162 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000163 }
164
joshualittb0a8a372014-09-23 09:50:21 -0700165 void addColorTextureProcessor(GrTexture* texture,
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000166 const SkMatrix& matrix,
167 const GrTextureParams& params) {
joshualittb0a8a372014-09-23 09:50:21 -0700168 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
169 }
170
171 void addCoverageTextureProcessor(GrTexture* texture,
172 const SkMatrix& matrix,
173 const GrTextureParams& params) {
174 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000175 }
tomhudson@google.com676e6602012-07-10 17:21:48 +0000176
robertphillips@google.com972265d2012-06-13 18:49:30 +0000177 /**
bsalomon9b536522014-09-05 09:18:51 -0700178 * When this object is destroyed it will remove any color/coverage effects from the draw state
179 * that were added after its constructor.
180 *
181 * This class has strange behavior around geometry processor. If there is a GP on the draw state
182 * it will assert that the GP is not modified until after the destructor of the ARE. If the
183 * draw state has a NULL GP when the ARE is constructed then it will reset it to null in the
184 * destructor.
185 *
186 * TODO: We'd prefer for the ARE to just save and restore the GP. However, this would add
187 * significant complexity to the multi-ref architecture for deferred drawing. Once GrDrawState
188 * and GrOptDrawState are fully separated then GrDrawState will never be in the deferred
189 * execution state and GrOptDrawState always will be (and will be immutable and therefore
190 * unable to have an ARE). At this point we can restore sanity and have the ARE save and restore
191 * the GP.
robertphillips@google.com972265d2012-06-13 18:49:30 +0000192 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000193 class AutoRestoreEffects : public ::SkNoncopyable {
robertphillips@google.com972265d2012-06-13 18:49:30 +0000194 public:
bsalomon9b536522014-09-05 09:18:51 -0700195 AutoRestoreEffects()
196 : fDrawState(NULL)
bsalomon9b536522014-09-05 09:18:51 -0700197 , fColorEffectCnt(0)
198 , fCoverageEffectCnt(0) {}
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000199
bsalomon9b536522014-09-05 09:18:51 -0700200 AutoRestoreEffects(GrDrawState* ds)
201 : fDrawState(NULL)
bsalomon9b536522014-09-05 09:18:51 -0700202 , fColorEffectCnt(0)
203 , fCoverageEffectCnt(0) {
skia.committer@gmail.com5c493d52013-06-14 07:00:49 +0000204 this->set(ds);
robertphillips@google.comf09b87d2013-06-13 20:06:44 +0000205 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000206
207 ~AutoRestoreEffects() { this->set(NULL); }
208
bsalomon8f727332014-08-05 07:50:06 -0700209 void set(GrDrawState* ds);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000210
bsalomon49f085d2014-09-05 13:34:00 -0700211 bool isSet() const { return SkToBool(fDrawState); }
bsalomon8af05232014-06-03 06:34:58 -0700212
robertphillips@google.com972265d2012-06-13 18:49:30 +0000213 private:
bsalomon9b536522014-09-05 09:18:51 -0700214 GrDrawState* fDrawState;
bsalomon9b536522014-09-05 09:18:51 -0700215 int fColorEffectCnt;
216 int fCoverageEffectCnt;
robertphillips@google.com972265d2012-06-13 18:49:30 +0000217 };
218
joshualitta58fe352014-10-27 08:39:00 -0700219 /**
220 * AutoRestoreStencil
221 *
222 * This simple struct saves and restores the stencil settings
223 */
224 class AutoRestoreStencil : public ::SkNoncopyable {
225 public:
226 AutoRestoreStencil() : fDrawState(NULL) {}
227
228 AutoRestoreStencil(GrDrawState* ds) : fDrawState(NULL) { this->set(ds); }
229
230 ~AutoRestoreStencil() { this->set(NULL); }
231
232 void set(GrDrawState* ds) {
233 if (fDrawState) {
234 fDrawState->setStencil(fStencilSettings);
235 }
236 fDrawState = ds;
237 if (ds) {
238 fStencilSettings = ds->getStencil();
239 }
240 }
241
242 bool isSet() const { return SkToBool(fDrawState); }
243
244 private:
245 GrDrawState* fDrawState;
246 GrStencilSettings fStencilSettings;
247 };
248
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000249 /// @}
250
251 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000252 /// @name Blending
253 ////
254
egdaniel89af44a2014-09-26 06:15:04 -0700255 /**
256 * Determines whether multiplying the computed per-pixel color by the pixel's fractional
257 * coverage before the blend will give the correct final destination color. In general it
258 * will not as coverage is applied after blending.
259 */
260 bool canTweakAlphaForCoverage() const;
261
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000262 /// @}
263
joshualittd27f73e2014-12-29 07:43:36 -0800264
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000265 /// @}
266
267 ///////////////////////////////////////////////////////////////////////////
268 /// @name Render Target
269 ////
270
271 /**
egdaniel89af44a2014-09-26 06:15:04 -0700272 * Retrieves the currently set render-target.
273 *
274 * @return The currently set render target.
275 */
bsalomon37dd3312014-11-03 08:47:23 -0800276 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700277
278 /**
bsalomon@google.comca432082013-01-23 19:53:46 +0000279 * Sets the render-target used at the next drawing call
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000280 *
281 * @param target The render target to set.
282 */
bsalomonae59b772014-11-19 08:23:49 -0800283 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000284
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000285 /// @}
286
287 ///////////////////////////////////////////////////////////////////////////
288 /// @name Stencil
289 ////
290
egdaniel89af44a2014-09-26 06:15:04 -0700291 const GrStencilSettings& getStencil() const { return fStencilSettings; }
292
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000293 /**
294 * Sets the stencil settings to use for the next draw.
295 * Changing the clip has the side-effect of possibly zeroing
296 * out the client settable stencil bits. So multipass algorithms
297 * using stencil should not change the clip between passes.
298 * @param settings the stencil settings to use.
299 */
bsalomon04ddf892014-11-19 12:36:22 -0800300 void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000301
302 /**
303 * Shortcut to disable stencil testing and ops.
304 */
bsalomon04ddf892014-11-19 12:36:22 -0800305 void disableStencil() { fStencilSettings.setDisabled(); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000306
bsalomon2ed5ef82014-07-07 08:44:05 -0700307 GrStencilSettings* stencil() { return &fStencilSettings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000308
309 /// @}
310
311 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000312 /// @name State Flags
313 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000314
egdaniel89af44a2014-09-26 06:15:04 -0700315 /**
316 * Flags that affect rendering. Controlled using enable/disableState(). All
317 * default to disabled.
318 */
319 enum StateBits {
320 /**
321 * Perform dithering. TODO: Re-evaluate whether we need this bit
322 */
323 kDither_StateBit = 0x01,
324 /**
325 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
326 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
327 * the 3D API.
328 */
329 kHWAntialias_StateBit = 0x02,
330 /**
331 * Draws will respect the clip, otherwise the clip is ignored.
332 */
333 kClip_StateBit = 0x04,
egdaniel89af44a2014-09-26 06:15:04 -0700334
egdaniel080e6732014-12-22 07:35:52 -0800335 kLast_StateBit = kClip_StateBit,
egdaniel89af44a2014-09-26 06:15:04 -0700336 };
337
egdaniel89af44a2014-09-26 06:15:04 -0700338 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); }
bsalomon04ddf892014-11-19 12:36:22 -0800339 bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); }
340 bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000341
342 /**
343 * Enable render state settings.
344 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000345 * @param stateBits bitfield of StateBits specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000346 */
bsalomon04ddf892014-11-19 12:36:22 -0800347 void enableState(uint32_t stateBits) { fFlagBits |= stateBits; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000348
349 /**
350 * Disable render state settings.
351 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000352 * @param stateBits bitfield of StateBits specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000353 */
bsalomon04ddf892014-11-19 12:36:22 -0800354 void disableState(uint32_t stateBits) { fFlagBits &= ~(stateBits); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000355
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000356 /**
357 * Enable or disable stateBits based on a boolean.
358 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000359 * @param stateBits bitfield of StateBits to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000360 * @param enable if true enable stateBits, otherwise disable
361 */
362 void setState(uint32_t stateBits, bool enable) {
363 if (enable) {
364 this->enableState(stateBits);
365 } else {
366 this->disableState(stateBits);
367 }
368 }
369
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000370 /// @}
371
372 ///////////////////////////////////////////////////////////////////////////
373 /// @name Face Culling
374 ////
375
egdaniel89af44a2014-09-26 06:15:04 -0700376 enum DrawFace {
377 kInvalid_DrawFace = -1,
378
379 kBoth_DrawFace,
380 kCCW_DrawFace,
381 kCW_DrawFace,
382 };
383
384 /**
385 * Gets whether the target is drawing clockwise, counterclockwise,
386 * or both faces.
387 * @return the current draw face(s).
388 */
389 DrawFace getDrawFace() const { return fDrawFace; }
390
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000391 /**
392 * Controls whether clockwise, counterclockwise, or both faces are drawn.
393 * @param face the face(s) to draw.
394 */
395 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000396 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700397 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000398 }
399
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000400 /// @}
401
402 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000403
bsalomon8f727332014-08-05 07:50:06 -0700404 GrDrawState& operator= (const GrDrawState& that);
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000405
406private:
joshualitt56995b52014-12-11 15:44:02 -0800407 bool isEqual(const GrDrawState& that, bool explicitLocalCoords) const;
egdaniel89af44a2014-09-26 06:15:04 -0700408
joshualitt56995b52014-12-11 15:44:02 -0800409 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const {
410 this->calcColorInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800411 return fColorProcInfo;
412 }
413
joshualitt56995b52014-12-11 15:44:02 -0800414 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const {
415 this->calcCoverageInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800416 return fCoverageProcInfo;
417 }
418
egdaniel89af44a2014-09-26 06:15:04 -0700419 /**
joshualitt56995b52014-12-11 15:44:02 -0800420 * If fColorProcInfoValid is false, function calculates the invariant output for the color
421 * stages and results are stored in fColorProcInfo.
egdaniel89af44a2014-09-26 06:15:04 -0700422 */
joshualitt56995b52014-12-11 15:44:02 -0800423 void calcColorInvariantOutput(const GrPrimitiveProcessor*) const;
424
425 /**
426 * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage
427 * stages and results are stored in fCoverageProcInfo.
428 */
429 void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const;
egdaniel89af44a2014-09-26 06:15:04 -0700430
egdanielb6cbc382014-11-13 11:00:34 -0800431 /**
432 * If fColorProcInfoValid is false, function calculates the invariant output for the color
433 * stages and results are stored in fColorProcInfo.
434 */
joshualitt2e3b3e32014-12-09 13:31:14 -0800435 void calcColorInvariantOutput(GrColor) const;
egdanielb6cbc382014-11-13 11:00:34 -0800436
437 /**
438 * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage
439 * stages and results are stored in fCoverageProcInfo.
440 */
joshualitt2e3b3e32014-12-09 13:31:14 -0800441 void calcCoverageInvariantOutput(GrColor) const;
egdanielb6cbc382014-11-13 11:00:34 -0800442
joshualitt8059eb92014-12-29 15:10:07 -0800443 void onReset();
bsalomon@google.com137f1342013-05-29 21:27:53 +0000444
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000445 // Some of the auto restore objects assume that no effects are removed during their lifetime.
446 // This is used to assert that this condition holds.
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000447 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000448
joshualitta5305a12014-10-10 17:47:00 -0700449 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray;
egdaniel89af44a2014-09-26 06:15:04 -0700450
bsalomonae59b772014-11-19 08:23:49 -0800451 SkAutoTUnref<GrRenderTarget> fRenderTarget;
bsalomonae59b772014-11-19 08:23:49 -0800452 uint32_t fFlagBits;
bsalomonae59b772014-11-19 08:23:49 -0800453 GrStencilSettings fStencilSettings;
bsalomonae59b772014-11-19 08:23:49 -0800454 DrawFace fDrawFace;
egdaniel378092f2014-12-03 10:40:13 -0800455 SkAutoTUnref<const GrXPFactory> fXPFactory;
bsalomonae59b772014-11-19 08:23:49 -0800456 FragmentStageArray fColorStages;
457 FragmentStageArray fCoverageStages;
egdaniel89af44a2014-09-26 06:15:04 -0700458
egdanielb6cbc382014-11-13 11:00:34 -0800459 mutable GrProcOptInfo fColorProcInfo;
460 mutable GrProcOptInfo fCoverageProcInfo;
461 mutable bool fColorProcInfoValid;
462 mutable bool fCoverageProcInfoValid;
joshualitt2e3b3e32014-12-09 13:31:14 -0800463 mutable GrColor fColorCache;
464 mutable GrColor fCoverageCache;
joshualitt56995b52014-12-11 15:44:02 -0800465 mutable const GrPrimitiveProcessor* fColorPrimProc;
466 mutable const GrPrimitiveProcessor* fCoveragePrimProc;
egdanielb6cbc382014-11-13 11:00:34 -0800467
egdanielb109ac22014-10-07 06:45:44 -0700468 friend class GrOptDrawState;
tomhudson@google.com93813632011-10-27 20:21:16 +0000469};
470
471#endif