blob: 5743c39dc59c2c3609d435b24f517d4a06b00fa7 [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"
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
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 */
joshualitt8059eb92014-12-29 15:10:07 -080048 void setFromPaint(const GrPaint&, GrRenderTarget*);
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 /**
bsalomon62c447d2014-08-08 08:08:50 -070053 * Depending on features available in the underlying 3D API and the color blend mode requested
54 * it may or may not be possible to correctly blend with fractional pixel coverage generated by
55 * the fragment shader.
56 *
egdaniel8dd688b2015-01-22 10:16:09 -080057 * This function considers the current GrPipelineBuilder and the draw target's capabilities to
bsalomon62c447d2014-08-08 08:08:50 -070058 * determine whether coverage can be handled correctly. This function assumes that the caller
joshualitt2e3b3e32014-12-09 13:31:14 -080059 * intends to specify fractional pixel coverage via a primitive processor but may not have
60 * specified it yet.
bsalomon62c447d2014-08-08 08:08:50 -070061 */
joshualitt2e3b3e32014-12-09 13:31:14 -080062 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps) const;
bsalomon62c447d2014-08-08 08:08:50 -070063
egdaniel89af44a2014-09-26 06:15:04 -070064 /**
egdanielcd8b6302014-11-11 14:46:05 -080065 * This function returns true if the render target destination pixel values will be read for
66 * blending during draw.
67 */
joshualitt56995b52014-12-11 15:44:02 -080068 bool willBlendWithDst(const GrPrimitiveProcessor*) const;
joshualittbd769d02014-09-04 08:56:46 -070069
bsalomon@google.com2401ae82012-01-17 21:03:05 +000070 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.comadc65362013-01-28 14:26:09 +000071 /// @name Effect Stages
joshualittb0a8a372014-09-23 09:50:21 -070072 /// Each stage hosts a GrProcessor. The effect produces an output color or coverage in the
73 /// fragment shader. Its inputs are the output from the previous stage as well as some variables
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000074 /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color,
75 /// the fragment position, local coordinates).
76 ///
77 /// The stages are divided into two sets, color-computing and coverage-computing. The final
78 /// color stage produces the final pixel color. The coverage-computing stages function exactly
79 /// as the color-computing but the output of the final coverage stage is treated as a fractional
80 /// pixel coverage rather than as input to the src/dst color blend step.
81 ///
82 /// The input color to the first color-stage is either the constant color or interpolated
83 /// per-vertex colors. The input to the first coverage stage is either a constant coverage
84 /// (usually full-coverage) or interpolated per-vertex coverage.
85 ///
86 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the
87 /// the color / coverage distinction.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000088 ////
89
egdaniel89af44a2014-09-26 06:15:04 -070090 int numColorStages() const { return fColorStages.count(); }
91 int numCoverageStages() const { return fCoverageStages.count(); }
joshualitt4dd99882014-11-11 08:51:30 -080092 int numFragmentStages() const { return this->numColorStages() + this->numCoverageStages(); }
egdaniel378092f2014-12-03 10:40:13 -080093
joshualitt2fdeda02015-01-22 07:11:44 -080094 const GrXPFactory* getXPFactory() const {
95 if (!fXPFactory) {
96 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
97 }
98 return fXPFactory.get();
99 }
egdaniel378092f2014-12-03 10:40:13 -0800100
egdaniel89af44a2014-09-26 06:15:04 -0700101 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[idx]; }
102 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; }
103
104 /**
bsalomon50785a32015-02-06 07:02:37 -0800105 * Checks whether the xp will need a copy of the destination to correctly blend.
egdaniel89af44a2014-09-26 06:15:04 -0700106 */
bsalomon50785a32015-02-06 07:02:37 -0800107 bool willXPNeedDstCopy(const GrDrawTargetCaps& caps) const;
egdaniel89af44a2014-09-26 06:15:04 -0700108
egdaniel95131432014-12-09 11:15:43 -0800109 /**
110 * The xfer processor factory.
111 */
112 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
113 fXPFactory.reset(SkRef(xpFactory));
114 return xpFactory;
115 }
116
117 void setPorterDuffXPFactory(SkXfermode::Mode mode) {
118 fXPFactory.reset(GrPorterDuffXPFactory::Create(mode));
119 }
120
121 void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) {
122 fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst));
123 }
124
egdaniel87509242014-12-17 13:37:13 -0800125 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) {
126 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
127 }
128
egdaniel080e6732014-12-22 07:35:52 -0800129 void setDisableColorXPFactory() {
130 fXPFactory.reset(GrDisableColorXPFactory::Create());
131 }
132
joshualittb0a8a372014-09-23 09:50:21 -0700133 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700134 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700135 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect));
egdanielb6cbc382014-11-13 11:00:34 -0800136 fColorProcInfoValid = false;
jvanverth@google.com65eb4d52013-03-19 18:51:02 +0000137 return effect;
138 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +0000139
joshualittb0a8a372014-09-23 09:50:21 -0700140 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) {
bsalomon49f085d2014-09-05 13:34:00 -0700141 SkASSERT(effect);
joshualittb0a8a372014-09-23 09:50:21 -0700142 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect));
egdanielb6cbc382014-11-13 11:00:34 -0800143 fCoverageProcInfoValid = false;
bsalomon@google.comadc65362013-01-28 14:26:09 +0000144 return effect;
145 }
146
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000147 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +0000148 * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
tomhudson@google.com1e8f0162012-07-20 16:25:18 +0000149 */
joshualittb0a8a372014-09-23 09:50:21 -0700150 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
151 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +0000152 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000153
joshualittb0a8a372014-09-23 09:50:21 -0700154 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
155 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000156 }
157
joshualittb0a8a372014-09-23 09:50:21 -0700158 void addColorTextureProcessor(GrTexture* texture,
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000159 const SkMatrix& matrix,
160 const GrTextureParams& params) {
joshualittb0a8a372014-09-23 09:50:21 -0700161 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
162 }
163
164 void addCoverageTextureProcessor(GrTexture* texture,
165 const SkMatrix& matrix,
166 const GrTextureParams& params) {
167 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000168 }
tomhudson@google.com676e6602012-07-10 17:21:48 +0000169
robertphillips@google.com972265d2012-06-13 18:49:30 +0000170 /**
egdaniel8dd688b2015-01-22 10:16:09 -0800171 * When this object is destroyed it will remove any color/coverage effects from the pipeline
172 * builder that were added after its constructor.
bsalomon9b536522014-09-05 09:18:51 -0700173 *
egdaniel8dd688b2015-01-22 10:16:09 -0800174 * This class has strange behavior around geometry processor. If there is a GP on the
175 * GrPipelineBuilder it will assert that the GP is not modified until after the destructor of
176 * the ARE. If the GrPipelineBuilder has a NULL GP when the ARE is constructed then it will reset
177 * it to null in the destructor.
robertphillips@google.com972265d2012-06-13 18:49:30 +0000178 */
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000179 class AutoRestoreEffects : public ::SkNoncopyable {
robertphillips@google.com972265d2012-06-13 18:49:30 +0000180 public:
bsalomon9b536522014-09-05 09:18:51 -0700181 AutoRestoreEffects()
egdaniel8dd688b2015-01-22 10:16:09 -0800182 : fPipelineBuilder(NULL)
bsalomon9b536522014-09-05 09:18:51 -0700183 , fColorEffectCnt(0)
184 , fCoverageEffectCnt(0) {}
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000185
egdaniel8dd688b2015-01-22 10:16:09 -0800186 AutoRestoreEffects(GrPipelineBuilder* ds)
187 : fPipelineBuilder(NULL)
bsalomon9b536522014-09-05 09:18:51 -0700188 , fColorEffectCnt(0)
189 , fCoverageEffectCnt(0) {
skia.committer@gmail.com5c493d52013-06-14 07:00:49 +0000190 this->set(ds);
robertphillips@google.comf09b87d2013-06-13 20:06:44 +0000191 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000192
193 ~AutoRestoreEffects() { this->set(NULL); }
194
egdaniel8dd688b2015-01-22 10:16:09 -0800195 void set(GrPipelineBuilder* ds);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000196
egdaniel8dd688b2015-01-22 10:16:09 -0800197 bool isSet() const { return SkToBool(fPipelineBuilder); }
bsalomon8af05232014-06-03 06:34:58 -0700198
robertphillips@google.com972265d2012-06-13 18:49:30 +0000199 private:
egdaniel8dd688b2015-01-22 10:16:09 -0800200 GrPipelineBuilder* fPipelineBuilder;
bsalomon9b536522014-09-05 09:18:51 -0700201 int fColorEffectCnt;
202 int fCoverageEffectCnt;
robertphillips@google.com972265d2012-06-13 18:49:30 +0000203 };
204
joshualitta58fe352014-10-27 08:39:00 -0700205 /**
206 * AutoRestoreStencil
207 *
208 * This simple struct saves and restores the stencil settings
209 */
210 class AutoRestoreStencil : public ::SkNoncopyable {
211 public:
egdaniel8dd688b2015-01-22 10:16:09 -0800212 AutoRestoreStencil() : fPipelineBuilder(NULL) {}
joshualitta58fe352014-10-27 08:39:00 -0700213
egdaniel8dd688b2015-01-22 10:16:09 -0800214 AutoRestoreStencil(GrPipelineBuilder* ds) : fPipelineBuilder(NULL) { this->set(ds); }
joshualitta58fe352014-10-27 08:39:00 -0700215
216 ~AutoRestoreStencil() { this->set(NULL); }
217
egdaniel8dd688b2015-01-22 10:16:09 -0800218 void set(GrPipelineBuilder* ds) {
219 if (fPipelineBuilder) {
220 fPipelineBuilder->setStencil(fStencilSettings);
joshualitta58fe352014-10-27 08:39:00 -0700221 }
egdaniel8dd688b2015-01-22 10:16:09 -0800222 fPipelineBuilder = ds;
joshualitta58fe352014-10-27 08:39:00 -0700223 if (ds) {
224 fStencilSettings = ds->getStencil();
225 }
226 }
227
egdaniel8dd688b2015-01-22 10:16:09 -0800228 bool isSet() const { return SkToBool(fPipelineBuilder); }
joshualitta58fe352014-10-27 08:39:00 -0700229
230 private:
egdaniel8dd688b2015-01-22 10:16:09 -0800231 GrPipelineBuilder* fPipelineBuilder;
232 GrStencilSettings fStencilSettings;
joshualitta58fe352014-10-27 08:39:00 -0700233 };
234
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000235 /// @}
236
237 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000238 /// @name Blending
239 ////
240
egdaniel89af44a2014-09-26 06:15:04 -0700241 /**
242 * Determines whether multiplying the computed per-pixel color by the pixel's fractional
243 * coverage before the blend will give the correct final destination color. In general it
244 * will not as coverage is applied after blending.
245 */
246 bool canTweakAlphaForCoverage() const;
247
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000248 /// @}
249
joshualittd27f73e2014-12-29 07:43:36 -0800250
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000251 /// @}
252
253 ///////////////////////////////////////////////////////////////////////////
254 /// @name Render Target
255 ////
256
257 /**
egdaniel89af44a2014-09-26 06:15:04 -0700258 * Retrieves the currently set render-target.
259 *
260 * @return The currently set render target.
261 */
bsalomon37dd3312014-11-03 08:47:23 -0800262 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700263
264 /**
bsalomon@google.comca432082013-01-23 19:53:46 +0000265 * Sets the render-target used at the next drawing call
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000266 *
267 * @param target The render target to set.
268 */
bsalomonae59b772014-11-19 08:23:49 -0800269 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000270
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000271 /// @}
272
273 ///////////////////////////////////////////////////////////////////////////
274 /// @name Stencil
275 ////
276
egdaniel89af44a2014-09-26 06:15:04 -0700277 const GrStencilSettings& getStencil() const { return fStencilSettings; }
278
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000279 /**
280 * Sets the stencil settings to use for the next draw.
281 * Changing the clip has the side-effect of possibly zeroing
282 * out the client settable stencil bits. So multipass algorithms
283 * using stencil should not change the clip between passes.
284 * @param settings the stencil settings to use.
285 */
bsalomon04ddf892014-11-19 12:36:22 -0800286 void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000287
288 /**
289 * Shortcut to disable stencil testing and ops.
290 */
bsalomon04ddf892014-11-19 12:36:22 -0800291 void disableStencil() { fStencilSettings.setDisabled(); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000292
bsalomon2ed5ef82014-07-07 08:44:05 -0700293 GrStencilSettings* stencil() { return &fStencilSettings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000294
295 /// @}
296
297 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000298 /// @name State Flags
299 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000300
egdaniel89af44a2014-09-26 06:15:04 -0700301 /**
302 * Flags that affect rendering. Controlled using enable/disableState(). All
303 * default to disabled.
304 */
305 enum StateBits {
306 /**
307 * Perform dithering. TODO: Re-evaluate whether we need this bit
308 */
309 kDither_StateBit = 0x01,
310 /**
311 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
312 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
313 * the 3D API.
314 */
315 kHWAntialias_StateBit = 0x02,
316 /**
317 * Draws will respect the clip, otherwise the clip is ignored.
318 */
319 kClip_StateBit = 0x04,
egdaniel89af44a2014-09-26 06:15:04 -0700320
egdaniel080e6732014-12-22 07:35:52 -0800321 kLast_StateBit = kClip_StateBit,
egdaniel89af44a2014-09-26 06:15:04 -0700322 };
323
egdaniel89af44a2014-09-26 06:15:04 -0700324 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); }
bsalomon04ddf892014-11-19 12:36:22 -0800325 bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); }
326 bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000327
328 /**
329 * Enable render state settings.
330 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000331 * @param stateBits bitfield of StateBits specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000332 */
bsalomon04ddf892014-11-19 12:36:22 -0800333 void enableState(uint32_t stateBits) { fFlagBits |= stateBits; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000334
335 /**
336 * Disable render state settings.
337 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000338 * @param stateBits bitfield of StateBits specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000339 */
bsalomon04ddf892014-11-19 12:36:22 -0800340 void disableState(uint32_t stateBits) { fFlagBits &= ~(stateBits); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000341
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000342 /**
343 * Enable or disable stateBits based on a boolean.
344 *
bsalomon@google.com1e269b52012-10-15 14:25:31 +0000345 * @param stateBits bitfield of StateBits to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000346 * @param enable if true enable stateBits, otherwise disable
347 */
348 void setState(uint32_t stateBits, bool enable) {
349 if (enable) {
350 this->enableState(stateBits);
351 } else {
352 this->disableState(stateBits);
353 }
354 }
355
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000356 /// @}
357
358 ///////////////////////////////////////////////////////////////////////////
359 /// @name Face Culling
360 ////
361
egdaniel89af44a2014-09-26 06:15:04 -0700362 enum DrawFace {
363 kInvalid_DrawFace = -1,
364
365 kBoth_DrawFace,
366 kCCW_DrawFace,
367 kCW_DrawFace,
368 };
369
370 /**
371 * Gets whether the target is drawing clockwise, counterclockwise,
372 * or both faces.
373 * @return the current draw face(s).
374 */
375 DrawFace getDrawFace() const { return fDrawFace; }
376
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000377 /**
378 * Controls whether clockwise, counterclockwise, or both faces are drawn.
379 * @param face the face(s) to draw.
380 */
381 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000382 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700383 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000384 }
385
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000386 /// @}
387
388 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000389
egdaniel8dd688b2015-01-22 10:16:09 -0800390 GrPipelineBuilder& operator= (const GrPipelineBuilder& that);
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000391
392private:
joshualitt4d8da812015-01-28 12:53:54 -0800393 // 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
400
401 // TODO delete when we have Batch
joshualitt56995b52014-12-11 15:44:02 -0800402 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const {
403 this->calcColorInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800404 return fColorProcInfo;
405 }
406
joshualitt56995b52014-12-11 15:44:02 -0800407 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const {
408 this->calcCoverageInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800409 return fCoverageProcInfo;
410 }
411
joshualitt4d8da812015-01-28 12:53:54 -0800412 const GrProcOptInfo& colorProcInfo(const GrBatch* batch) const {
413 this->calcColorInvariantOutput(batch);
414 return fColorProcInfo;
415 }
416
417 const GrProcOptInfo& coverageProcInfo(const GrBatch* batch) const {
418 this->calcCoverageInvariantOutput(batch);
419 return fCoverageProcInfo;
420 }
joshualittd15e4e42015-01-26 13:30:10 -0800421
422 /**
joshualitt4d8da812015-01-28 12:53:54 -0800423 * Primproc variants of the calc functions
424 * TODO remove these when batch is everywhere
joshualittd5a7db42015-01-27 15:39:06 -0800425 */
joshualitt4d8da812015-01-28 12:53:54 -0800426 void calcColorInvariantOutput(const GrPrimitiveProcessor*) const;
joshualittc2893c52015-01-28 06:54:30 -0800427 void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const;
joshualittd5a7db42015-01-27 15:39:06 -0800428
429 /**
joshualitt4d8da812015-01-28 12:53:54 -0800430 * GrBatch provides the initial seed for these loops based off of its initial geometry data
431 */
432 void calcColorInvariantOutput(const GrBatch*) const;
433 void calcCoverageInvariantOutput(const GrBatch*) const;
434
435 /**
egdanielb6cbc382014-11-13 11:00:34 -0800436 * If fColorProcInfoValid is false, function calculates the invariant output for the color
437 * stages and results are stored in fColorProcInfo.
438 */
joshualitt2e3b3e32014-12-09 13:31:14 -0800439 void calcColorInvariantOutput(GrColor) const;
egdanielb6cbc382014-11-13 11:00:34 -0800440
441 /**
442 * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage
443 * stages and results are stored in fCoverageProcInfo.
444 */
joshualitt2e3b3e32014-12-09 13:31:14 -0800445 void calcCoverageInvariantOutput(GrColor) const;
egdanielb6cbc382014-11-13 11:00:34 -0800446
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000447 // Some of the auto restore objects assume that no effects are removed during their lifetime.
448 // This is used to assert that this condition holds.
commit-bot@chromium.org1acc3d72013-09-06 23:13:05 +0000449 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000450
joshualitta5305a12014-10-10 17:47:00 -0700451 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray;
egdaniel89af44a2014-09-26 06:15:04 -0700452
bsalomonae59b772014-11-19 08:23:49 -0800453 SkAutoTUnref<GrRenderTarget> fRenderTarget;
bsalomonae59b772014-11-19 08:23:49 -0800454 uint32_t fFlagBits;
bsalomonae59b772014-11-19 08:23:49 -0800455 GrStencilSettings fStencilSettings;
bsalomonae59b772014-11-19 08:23:49 -0800456 DrawFace fDrawFace;
joshualitt2fdeda02015-01-22 07:11:44 -0800457 mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
bsalomonae59b772014-11-19 08:23:49 -0800458 FragmentStageArray fColorStages;
459 FragmentStageArray fCoverageStages;
egdaniel89af44a2014-09-26 06:15:04 -0700460
egdanielb6cbc382014-11-13 11:00:34 -0800461 mutable GrProcOptInfo fColorProcInfo;
462 mutable GrProcOptInfo fCoverageProcInfo;
463 mutable bool fColorProcInfoValid;
464 mutable bool fCoverageProcInfoValid;
joshualitt2e3b3e32014-12-09 13:31:14 -0800465 mutable GrColor fColorCache;
466 mutable GrColor fCoverageCache;
egdanielb6cbc382014-11-13 11:00:34 -0800467
egdaniel8dd688b2015-01-22 10:16:09 -0800468 friend class GrPipeline;
tomhudson@google.com93813632011-10-27 20:21:16 +0000469};
470
471#endif