blob: 96807d5a751c288332777805dea2da8be37c0fb5 [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
joshualitt4d8da812015-01-28 12:53:54 -080011#include "GrBatch.h"
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000012#include "GrBlend.h"
joshualitt44701df2015-02-23 14:44:57 -080013#include "GrClip.h"
egdanielc0648242014-09-22 13:17:02 -070014#include "GrDrawTargetCaps.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
egdaniel8dd688b2015-01-22 10:16:09 -080031class GrPipelineBuilder {
bsalomon@google.com2e3d1442012-03-26 20:33:54 +000032public:
egdaniel8dd688b2015-01-22 10:16:09 -080033 GrPipelineBuilder();
34
35 GrPipelineBuilder(const GrPipelineBuilder& pipelineBuilder) {
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +000036 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
egdaniel8dd688b2015-01-22 10:16:09 -080037 *this = pipelineBuilder;
bsalomon@google.com46f7afb2012-01-18 19:51:55 +000038 }
39
egdaniel8dd688b2015-01-22 10:16:09 -080040 virtual ~GrPipelineBuilder();
bsalomon@google.com137f1342013-05-29 21:27:53 +000041
bsalomon@google.com52a5dcb2012-01-17 16:01:37 +000042 /**
egdaniel8dd688b2015-01-22 10:16:09 -080043 * Initializes the GrPipelineBuilder based on a GrPaint, view matrix and render target. Note
44 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have
45 * no GrPaint equivalents are set to default values with the exception of vertex attribute state
46 * which is unmodified by this function and clipping which will be enabled.
bsalomon@google.comaf84e742012-10-05 13:23:24 +000047 */
joshualitt570d2f82015-02-25 13:19:48 -080048 void setFromPaint(const GrPaint&, GrRenderTarget*, const GrClip&);
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000049
jvanverth@google.com9b855c72013-03-01 18:21:22 +000050 /// @}
51
jvanverth@google.com9b855c72013-03-01 18:21:22 +000052 /**
egdanielcd8b6302014-11-11 14:46:05 -080053 * This function returns true if the render target destination pixel values will be read for
54 * blending during draw.
55 */
joshualitt56995b52014-12-11 15:44:02 -080056 bool willBlendWithDst(const GrPrimitiveProcessor*) const;
joshualittbd769d02014-09-04 08:56:46 -070057
bsalomon@google.com2401ae82012-01-17 21:03:05 +000058 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.comadc65362013-01-28 14:26:09 +000059 /// @name Effect Stages
joshualittb0a8a372014-09-23 09:50:21 -070060 /// Each stage hosts a GrProcessor. The effect produces an output color or coverage in the
61 /// fragment shader. Its inputs are the output from the previous stage as well as some variables
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000062 /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color,
63 /// the fragment position, local coordinates).
64 ///
65 /// The stages are divided into two sets, color-computing and coverage-computing. The final
66 /// color stage produces the final pixel color. The coverage-computing stages function exactly
67 /// as the color-computing but the output of the final coverage stage is treated as a fractional
68 /// pixel coverage rather than as input to the src/dst color blend step.
69 ///
70 /// The input color to the first color-stage is either the constant color or interpolated
71 /// per-vertex colors. The input to the first coverage stage is either a constant coverage
72 /// (usually full-coverage) or interpolated per-vertex coverage.
73 ///
74 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the
75 /// the color / coverage distinction.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000076 ////
77
egdaniel89af44a2014-09-26 06:15:04 -070078 int numColorStages() const { return fColorStages.count(); }
79 int numCoverageStages() const { return fCoverageStages.count(); }
joshualitt4dd99882014-11-11 08:51:30 -080080 int numFragmentStages() const { return this->numColorStages() + this->numCoverageStages(); }
egdaniel378092f2014-12-03 10:40:13 -080081
joshualitt2fdeda02015-01-22 07:11:44 -080082 const GrXPFactory* getXPFactory() const {
83 if (!fXPFactory) {
84 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
85 }
86 return fXPFactory.get();
87 }
egdaniel378092f2014-12-03 10:40:13 -080088
egdaniel89af44a2014-09-26 06:15:04 -070089 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[idx]; }
90 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; }
91
92 /**
bsalomon50785a32015-02-06 07:02:37 -080093 * Checks whether the xp will need a copy of the destination to correctly blend.
egdaniel89af44a2014-09-26 06:15:04 -070094 */
egdaniele36914c2015-02-13 09:00:33 -080095 bool willXPNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& colorPOI,
96 const GrProcOptInfo& coveragePOI) const;
egdaniel89af44a2014-09-26 06:15:04 -070097
egdaniel95131432014-12-09 11:15:43 -080098 /**
99 * The xfer processor factory.
100 */
101 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
102 fXPFactory.reset(SkRef(xpFactory));
103 return xpFactory;
104 }
105
egdaniel87509242014-12-17 13:37:13 -0800106 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) {
107 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
108 }
109
egdaniel080e6732014-12-22 07:35:52 -0800110 void setDisableColorXPFactory() {
111 fXPFactory.reset(GrDisableColorXPFactory::Create());
112 }
113
joshualittb0a8a372014-09-23 09:50:21 -0700114 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700115 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700116 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect));
egdanielb6cbc382014-11-13 11:00:34 -0800117 fColorProcInfoValid = false;
jvanverth@google.com65eb4d52013-03-19 18:51:02 +0000118 return effect;
119 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +0000120
joshualittb0a8a372014-09-23 09:50:21 -0700121 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700122 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700123 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect));
egdanielb6cbc382014-11-13 11:00:34 -0800124 fCoverageProcInfoValid = false;
bsalomon@google.comadc65362013-01-28 14:26:09 +0000125 return effect;
126 }
127
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000128 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000129 * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
tomhudson@google.com1e8f0162012-07-20 16:25:18 +0000130 */
joshualittb0a8a372014-09-23 09:50:21 -0700131 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
132 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +0000133 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000134
joshualittb0a8a372014-09-23 09:50:21 -0700135 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
136 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000137 }
138
joshualittb0a8a372014-09-23 09:50:21 -0700139 void addColorTextureProcessor(GrTexture* texture,
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000140 const SkMatrix& matrix,
141 const GrTextureParams& params) {
joshualittb0a8a372014-09-23 09:50:21 -0700142 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
143 }
144
145 void addCoverageTextureProcessor(GrTexture* texture,
146 const SkMatrix& matrix,
147 const GrTextureParams& params) {
148 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000149 }
tomhudson@google.com676e6602012-07-10 17:21:48 +0000150
robertphillips@google.com972265d2012-06-13 18:49:30 +0000151 /**
egdaniel8dd688b2015-01-22 10:16:09 -0800152 * When this object is destroyed it will remove any color/coverage effects from the pipeline
153 * builder that were added after its constructor.
bsalomon9b536522014-09-05 09:18:51 -0700154 *
egdaniel8dd688b2015-01-22 10:16:09 -0800155 * This class has strange behavior around geometry processor. If there is a GP on the
156 * GrPipelineBuilder it will assert that the GP is not modified until after the destructor of
157 * the ARE. If the GrPipelineBuilder has a NULL GP when the ARE is constructed then it will reset
158 * it to null in the destructor.
robertphillips@google.com972265d2012-06-13 18:49:30 +0000159 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000160 class AutoRestoreEffects : public ::SkNoncopyable {
robertphillips@google.com972265d2012-06-13 18:49:30 +0000161 public:
bsalomon9b536522014-09-05 09:18:51 -0700162 AutoRestoreEffects()
egdaniel8dd688b2015-01-22 10:16:09 -0800163 : fPipelineBuilder(NULL)
bsalomon9b536522014-09-05 09:18:51 -0700164 , fColorEffectCnt(0)
165 , fCoverageEffectCnt(0) {}
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000166
egdaniel8dd688b2015-01-22 10:16:09 -0800167 AutoRestoreEffects(GrPipelineBuilder* ds)
168 : fPipelineBuilder(NULL)
bsalomon9b536522014-09-05 09:18:51 -0700169 , fColorEffectCnt(0)
170 , fCoverageEffectCnt(0) {
skia.committer@gmail.com5c493d52013-06-14 07:00:49 +0000171 this->set(ds);
robertphillips@google.comf09b87d2013-06-13 20:06:44 +0000172 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000173
174 ~AutoRestoreEffects() { this->set(NULL); }
175
egdaniel8dd688b2015-01-22 10:16:09 -0800176 void set(GrPipelineBuilder* ds);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000177
egdaniel8dd688b2015-01-22 10:16:09 -0800178 bool isSet() const { return SkToBool(fPipelineBuilder); }
bsalomon8af05232014-06-03 06:34:58 -0700179
robertphillips@google.com972265d2012-06-13 18:49:30 +0000180 private:
egdaniel8dd688b2015-01-22 10:16:09 -0800181 GrPipelineBuilder* fPipelineBuilder;
bsalomon9b536522014-09-05 09:18:51 -0700182 int fColorEffectCnt;
183 int fCoverageEffectCnt;
robertphillips@google.com972265d2012-06-13 18:49:30 +0000184 };
185
joshualitta58fe352014-10-27 08:39:00 -0700186 /**
187 * AutoRestoreStencil
188 *
189 * This simple struct saves and restores the stencil settings
190 */
191 class AutoRestoreStencil : public ::SkNoncopyable {
192 public:
egdaniel8dd688b2015-01-22 10:16:09 -0800193 AutoRestoreStencil() : fPipelineBuilder(NULL) {}
joshualitta58fe352014-10-27 08:39:00 -0700194
egdaniel8dd688b2015-01-22 10:16:09 -0800195 AutoRestoreStencil(GrPipelineBuilder* ds) : fPipelineBuilder(NULL) { this->set(ds); }
joshualitta58fe352014-10-27 08:39:00 -0700196
197 ~AutoRestoreStencil() { this->set(NULL); }
198
egdaniel8dd688b2015-01-22 10:16:09 -0800199 void set(GrPipelineBuilder* ds) {
200 if (fPipelineBuilder) {
201 fPipelineBuilder->setStencil(fStencilSettings);
joshualitta58fe352014-10-27 08:39:00 -0700202 }
egdaniel8dd688b2015-01-22 10:16:09 -0800203 fPipelineBuilder = ds;
joshualitta58fe352014-10-27 08:39:00 -0700204 if (ds) {
205 fStencilSettings = ds->getStencil();
206 }
207 }
208
egdaniel8dd688b2015-01-22 10:16:09 -0800209 bool isSet() const { return SkToBool(fPipelineBuilder); }
joshualitta58fe352014-10-27 08:39:00 -0700210
211 private:
egdaniel8dd688b2015-01-22 10:16:09 -0800212 GrPipelineBuilder* fPipelineBuilder;
213 GrStencilSettings fStencilSettings;
joshualitta58fe352014-10-27 08:39:00 -0700214 };
215
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000216 /// @}
217
218 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000219 /// @name Blending
220 ////
221
egdaniel89af44a2014-09-26 06:15:04 -0700222 /**
223 * Determines whether multiplying the computed per-pixel color by the pixel's fractional
224 * coverage before the blend will give the correct final destination color. In general it
225 * will not as coverage is applied after blending.
226 */
227 bool canTweakAlphaForCoverage() const;
228
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000229 /// @}
230
joshualittd27f73e2014-12-29 07:43:36 -0800231
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000232 /// @}
233
234 ///////////////////////////////////////////////////////////////////////////
235 /// @name Render Target
236 ////
237
238 /**
egdaniel89af44a2014-09-26 06:15:04 -0700239 * Retrieves the currently set render-target.
240 *
241 * @return The currently set render target.
242 */
bsalomon37dd3312014-11-03 08:47:23 -0800243 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700244
245 /**
bsalomon@google.comca432082013-01-23 19:53:46 +0000246 * Sets the render-target used at the next drawing call
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000247 *
248 * @param target The render target to set.
249 */
bsalomonae59b772014-11-19 08:23:49 -0800250 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000251
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000252 /// @}
253
254 ///////////////////////////////////////////////////////////////////////////
255 /// @name Stencil
256 ////
257
egdaniel89af44a2014-09-26 06:15:04 -0700258 const GrStencilSettings& getStencil() const { return fStencilSettings; }
259
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000260 /**
261 * Sets the stencil settings to use for the next draw.
262 * Changing the clip has the side-effect of possibly zeroing
263 * out the client settable stencil bits. So multipass algorithms
264 * using stencil should not change the clip between passes.
265 * @param settings the stencil settings to use.
266 */
bsalomon04ddf892014-11-19 12:36:22 -0800267 void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000268
269 /**
270 * Shortcut to disable stencil testing and ops.
271 */
bsalomon04ddf892014-11-19 12:36:22 -0800272 void disableStencil() { fStencilSettings.setDisabled(); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000273
bsalomon2ed5ef82014-07-07 08:44:05 -0700274 GrStencilSettings* stencil() { return &fStencilSettings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000275
276 /// @}
277
278 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000279 /// @name State Flags
280 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000281
egdaniel89af44a2014-09-26 06:15:04 -0700282 /**
283 * Flags that affect rendering. Controlled using enable/disableState(). All
284 * default to disabled.
285 */
286 enum StateBits {
287 /**
288 * Perform dithering. TODO: Re-evaluate whether we need this bit
289 */
290 kDither_StateBit = 0x01,
291 /**
292 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
293 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
294 * the 3D API.
295 */
296 kHWAntialias_StateBit = 0x02,
egdaniel89af44a2014-09-26 06:15:04 -0700297
joshualitt44701df2015-02-23 14:44:57 -0800298 kLast_StateBit = kHWAntialias_StateBit,
egdaniel89af44a2014-09-26 06:15:04 -0700299 };
300
bsalomon04ddf892014-11-19 12:36:22 -0800301 bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); }
302 bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000303
304 /**
305 * Enable render state settings.
306 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000307 * @param stateBits bitfield of StateBits specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000308 */
bsalomon04ddf892014-11-19 12:36:22 -0800309 void enableState(uint32_t stateBits) { fFlagBits |= stateBits; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000310
311 /**
312 * Disable render state settings.
313 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000314 * @param stateBits bitfield of StateBits specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000315 */
bsalomon04ddf892014-11-19 12:36:22 -0800316 void disableState(uint32_t stateBits) { fFlagBits &= ~(stateBits); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000317
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000318 /**
319 * Enable or disable stateBits based on a boolean.
320 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000321 * @param stateBits bitfield of StateBits to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000322 * @param enable if true enable stateBits, otherwise disable
323 */
324 void setState(uint32_t stateBits, bool enable) {
325 if (enable) {
326 this->enableState(stateBits);
327 } else {
328 this->disableState(stateBits);
329 }
330 }
331
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000332 /// @}
333
334 ///////////////////////////////////////////////////////////////////////////
335 /// @name Face Culling
336 ////
337
egdaniel89af44a2014-09-26 06:15:04 -0700338 enum DrawFace {
339 kInvalid_DrawFace = -1,
340
341 kBoth_DrawFace,
342 kCCW_DrawFace,
343 kCW_DrawFace,
344 };
345
346 /**
347 * Gets whether the target is drawing clockwise, counterclockwise,
348 * or both faces.
349 * @return the current draw face(s).
350 */
351 DrawFace getDrawFace() const { return fDrawFace; }
352
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000353 /**
354 * Controls whether clockwise, counterclockwise, or both faces are drawn.
355 * @param face the face(s) to draw.
356 */
357 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000358 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700359 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000360 }
361
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000362 /// @}
363
364 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000365
egdaniel8dd688b2015-01-22 10:16:09 -0800366 GrPipelineBuilder& operator= (const GrPipelineBuilder& that);
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000367
joshualitt4d8da812015-01-28 12:53:54 -0800368 // TODO delete when we have Batch
joshualitt56995b52014-12-11 15:44:02 -0800369 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const {
370 this->calcColorInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800371 return fColorProcInfo;
372 }
373
joshualitt56995b52014-12-11 15:44:02 -0800374 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const {
375 this->calcCoverageInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800376 return fCoverageProcInfo;
377 }
378
joshualitt4d8da812015-01-28 12:53:54 -0800379 const GrProcOptInfo& colorProcInfo(const GrBatch* batch) const {
380 this->calcColorInvariantOutput(batch);
381 return fColorProcInfo;
382 }
383
384 const GrProcOptInfo& coverageProcInfo(const GrBatch* batch) const {
385 this->calcCoverageInvariantOutput(batch);
386 return fCoverageProcInfo;
387 }
joshualitt44701df2015-02-23 14:44:57 -0800388
389 void setClip(const GrClip& clip) { fClip = clip; }
390 const GrClip& clip() const { return fClip; }
391
egdaniele36914c2015-02-13 09:00:33 -0800392private:
393 // Calculating invariant color / coverage information is expensive, so we partially cache the
394 // results.
395 //
396 // canUseFracCoveragePrimProc() - Called in regular skia draw, caches results but only for a
397 // specific color and coverage. May be called multiple times
398 // willBlendWithDst() - only called by Nvpr, does not cache results
399 // GrOptDrawState constructor - never caches results
joshualittd15e4e42015-01-26 13:30:10 -0800400
401 /**
joshualitt4d8da812015-01-28 12:53:54 -0800402 * Primproc variants of the calc functions
403 * TODO remove these when batch is everywhere
joshualittd5a7db42015-01-27 15:39:06 -0800404 */
joshualitt4d8da812015-01-28 12:53:54 -0800405 void calcColorInvariantOutput(const GrPrimitiveProcessor*) const;
joshualittc2893c52015-01-28 06:54:30 -0800406 void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const;
joshualittd5a7db42015-01-27 15:39:06 -0800407
408 /**
joshualitt4d8da812015-01-28 12:53:54 -0800409 * GrBatch provides the initial seed for these loops based off of its initial geometry data
410 */
411 void calcColorInvariantOutput(const GrBatch*) const;
412 void calcCoverageInvariantOutput(const GrBatch*) const;
413
414 /**
egdanielb6cbc382014-11-13 11:00:34 -0800415 * If fColorProcInfoValid is false, function calculates the invariant output for the color
416 * stages and results are stored in fColorProcInfo.
417 */
joshualitt2e3b3e32014-12-09 13:31:14 -0800418 void calcColorInvariantOutput(GrColor) const;
egdanielb6cbc382014-11-13 11:00:34 -0800419
420 /**
421 * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage
422 * stages and results are stored in fCoverageProcInfo.
423 */
joshualitt2e3b3e32014-12-09 13:31:14 -0800424 void calcCoverageInvariantOutput(GrColor) const;
egdanielb6cbc382014-11-13 11:00:34 -0800425
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000426 // Some of the auto restore objects assume that no effects are removed during their lifetime.
427 // This is used to assert that this condition holds.
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000428 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000429
joshualitta5305a12014-10-10 17:47:00 -0700430 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray;
egdaniel89af44a2014-09-26 06:15:04 -0700431
bsalomonae59b772014-11-19 08:23:49 -0800432 SkAutoTUnref<GrRenderTarget> fRenderTarget;
bsalomonae59b772014-11-19 08:23:49 -0800433 uint32_t fFlagBits;
bsalomonae59b772014-11-19 08:23:49 -0800434 GrStencilSettings fStencilSettings;
bsalomonae59b772014-11-19 08:23:49 -0800435 DrawFace fDrawFace;
joshualitt2fdeda02015-01-22 07:11:44 -0800436 mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
bsalomonae59b772014-11-19 08:23:49 -0800437 FragmentStageArray fColorStages;
438 FragmentStageArray fCoverageStages;
joshualitt44701df2015-02-23 14:44:57 -0800439 GrClip fClip;
egdaniel89af44a2014-09-26 06:15:04 -0700440
egdanielb6cbc382014-11-13 11:00:34 -0800441 mutable GrProcOptInfo fColorProcInfo;
442 mutable GrProcOptInfo fCoverageProcInfo;
443 mutable bool fColorProcInfoValid;
444 mutable bool fCoverageProcInfoValid;
joshualitt2e3b3e32014-12-09 13:31:14 -0800445 mutable GrColor fColorCache;
446 mutable GrColor fCoverageCache;
egdanielb6cbc382014-11-13 11:00:34 -0800447
egdaniel8dd688b2015-01-22 10:16:09 -0800448 friend class GrPipeline;
tomhudson@google.com93813632011-10-27 20:21:16 +0000449};
450
451#endif