blob: e329bc5736aac56349588cbf6a30642572d38350 [file] [log] [blame]
tomhudson@google.com93813632011-10-27 20:21:16 +00001/*
egdaniel8dd688b2015-01-22 10:16:09 -08002 * Copyright 2015 Google Inc.
tomhudson@google.com93813632011-10-27 20:21:16 +00003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
egdaniel8dd688b2015-01-22 10:16:09 -08008#ifndef GrPipelineBuilder_DEFINED
9#define GrPipelineBuilder_DEFINED
tomhudson@google.com93813632011-10-27 20:21:16 +000010
commit-bot@chromium.org24ab3b02013-08-14 21:56:37 +000011#include "GrBlend.h"
bsalomoneb1cb5c2015-05-22 08:01:09 -070012#include "GrCaps.h"
joshualitt44701df2015-02-23 14:44:57 -080013#include "GrClip.h"
bsalomonf96ba022014-09-17 08:05:40 -070014#include "GrGpuResourceRef.h"
egdanielb6cbc382014-11-13 11:00:34 -080015#include "GrProcOptInfo.h"
egdaniel89af44a2014-09-26 06:15:04 -070016#include "GrRenderTarget.h"
17#include "GrStencil.h"
egdaniel95131432014-12-09 11:15:43 -080018#include "GrXferProcessor.h"
egdaniel89af44a2014-09-26 06:15:04 -070019#include "SkMatrix.h"
egdaniel87509242014-12-17 13:37:13 -080020#include "effects/GrCoverageSetOpXP.h"
egdaniel080e6732014-12-22 07:35:52 -080021#include "effects/GrDisableColorXP.h"
egdaniel95131432014-12-09 11:15:43 -080022#include "effects/GrPorterDuffXferProcessor.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000023#include "effects/GrSimpleTextureEffect.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000024
bsalomonabd30f52015-08-13 13:34:48 -070025class GrDrawBatch;
bsalomon4b91f762015-05-19 09:29:46 -070026class GrCaps;
egdaniel89af44a2014-09-26 06:15:04 -070027class GrPaint;
28class GrTexture;
egdaniel170f90b2014-09-16 12:54:40 -070029
bsalomonac856c92015-08-27 06:30:17 -070030class GrPipelineBuilder : public SkNoncopyable {
bsalomon@google.com2e3d1442012-03-26 20:33:54 +000031public:
egdaniel8dd688b2015-01-22 10:16:09 -080032 GrPipelineBuilder();
33
bsalomon@google.com52a5dcb2012-01-17 16:01:37 +000034 /**
joshualitt7b670db2015-07-09 13:25:02 -070035 * Initializes the GrPipelineBuilder based on a GrPaint, render target, and clip. Note
egdaniel8dd688b2015-01-22 10:16:09 -080036 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have
37 * no GrPaint equivalents are set to default values with the exception of vertex attribute state
38 * which is unmodified by this function and clipping which will be enabled.
bsalomon@google.comaf84e742012-10-05 13:23:24 +000039 */
joshualitt7b670db2015-07-09 13:25:02 -070040 GrPipelineBuilder(const GrPaint&, GrRenderTarget*, const GrClip&);
41
42 virtual ~GrPipelineBuilder();
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000043
bsalomon@google.com2401ae82012-01-17 21:03:05 +000044 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -080045 /// @name Fragment Processors
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000046 ///
bsalomon6be6f7c2015-02-26 13:05:21 -080047 /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage.
48 /// There are two chains of FPs, one for color and one for coverage. The first FP in each
49 /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output
50 /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs
51 /// feed their output to the GrXferProcessor which controls blending.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000052 ////
53
bsalomonac856c92015-08-27 06:30:17 -070054 int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); }
55 int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); }
56 int numFragmentProcessors() const { return this->numColorFragmentProcessors() +
57 this->numCoverageFragmentProcessors(); }
egdaniel378092f2014-12-03 10:40:13 -080058
bsalomonac856c92015-08-27 06:30:17 -070059 const GrFragmentProcessor* getColorFragmentProcessor(int idx) const {
60 return fColorFragmentProcessors[idx];
61 }
62 const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const {
63 return fCoverageFragmentProcessors[idx];
jvanverth@google.com65eb4d52013-03-19 18:51:02 +000064 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +000065
bsalomonac856c92015-08-27 06:30:17 -070066 const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcessor* processor) {
67 SkASSERT(processor);
68 fColorFragmentProcessors.push_back(SkRef(processor));
69 return processor;
70 }
71
72 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* processor) {
73 SkASSERT(processor);
74 fCoverageFragmentProcessors.push_back(SkRef(processor));
75 return processor;
bsalomon@google.comadc65362013-01-28 14:26:09 +000076 }
77
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000078 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +000079 * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
tomhudson@google.com1e8f0162012-07-20 16:25:18 +000080 */
joshualittb0a8a372014-09-23 09:50:21 -070081 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bsalomon4a339522015-10-06 08:40:50 -070082 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +000083 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000084
joshualittb0a8a372014-09-23 09:50:21 -070085 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bsalomon4a339522015-10-06 08:40:50 -070086 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000087 }
88
joshualittb0a8a372014-09-23 09:50:21 -070089 void addColorTextureProcessor(GrTexture* texture,
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000090 const SkMatrix& matrix,
91 const GrTextureParams& params) {
bsalomon4a339522015-10-06 08:40:50 -070092 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix,
bsalomonac856c92015-08-27 06:30:17 -070093 params))->unref();
joshualittb0a8a372014-09-23 09:50:21 -070094 }
95
96 void addCoverageTextureProcessor(GrTexture* texture,
97 const SkMatrix& matrix,
98 const GrTextureParams& params) {
bsalomon4a339522015-10-06 08:40:50 -070099 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix,
100 params))->unref();
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000101 }
tomhudson@google.com676e6602012-07-10 17:21:48 +0000102
robertphillips@google.com972265d2012-06-13 18:49:30 +0000103 /**
bsalomon6be6f7c2015-02-26 13:05:21 -0800104 * When this object is destroyed it will remove any color/coverage FPs from the pipeline builder
bsalomon4a339522015-10-06 08:40:50 -0700105 * that were added after its constructor.
joshualitt5e6ba212015-07-13 07:35:05 -0700106 * This class can transiently modify its "const" GrPipelineBuilder object but will restore it
107 * when done - so it is notionally "const" correct.
robertphillips@google.com972265d2012-06-13 18:49:30 +0000108 */
joshualitt4421a4c2015-07-13 09:36:41 -0700109 class AutoRestoreFragmentProcessorState : public ::SkNoncopyable {
robertphillips@google.com972265d2012-06-13 18:49:30 +0000110 public:
joshualitt4421a4c2015-07-13 09:36:41 -0700111 AutoRestoreFragmentProcessorState()
halcanary96fcdcc2015-08-27 07:41:13 -0700112 : fPipelineBuilder(nullptr)
bsalomon9b536522014-09-05 09:18:51 -0700113 , fColorEffectCnt(0)
joshualittaf2533a2015-09-09 10:00:12 -0700114 , fCoverageEffectCnt(0) {}
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000115
joshualitt4421a4c2015-07-13 09:36:41 -0700116 AutoRestoreFragmentProcessorState(const GrPipelineBuilder& ds)
halcanary96fcdcc2015-08-27 07:41:13 -0700117 : fPipelineBuilder(nullptr)
bsalomon9b536522014-09-05 09:18:51 -0700118 , fColorEffectCnt(0)
joshualittaf2533a2015-09-09 10:00:12 -0700119 , fCoverageEffectCnt(0) {
joshualitt4421a4c2015-07-13 09:36:41 -0700120 this->set(&ds);
robertphillips@google.comf09b87d2013-06-13 20:06:44 +0000121 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000122
halcanary96fcdcc2015-08-27 07:41:13 -0700123 ~AutoRestoreFragmentProcessorState() { this->set(nullptr); }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000124
joshualitt5e6ba212015-07-13 07:35:05 -0700125 void set(const GrPipelineBuilder* ds);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000126
egdaniel8dd688b2015-01-22 10:16:09 -0800127 bool isSet() const { return SkToBool(fPipelineBuilder); }
bsalomon8af05232014-06-03 06:34:58 -0700128
bsalomon4a339522015-10-06 08:40:50 -0700129 const GrFragmentProcessor* addCoverageFragmentProcessor(
130 const GrFragmentProcessor* processor) {
joshualitt5e6ba212015-07-13 07:35:05 -0700131 SkASSERT(this->isSet());
bsalomonac856c92015-08-27 06:30:17 -0700132 return fPipelineBuilder->addCoverageFragmentProcessor(processor);
joshualitt5e6ba212015-07-13 07:35:05 -0700133 }
134
robertphillips@google.com972265d2012-06-13 18:49:30 +0000135 private:
joshualitt5e6ba212015-07-13 07:35:05 -0700136 // notionally const (as marginalia)
egdaniel8dd688b2015-01-22 10:16:09 -0800137 GrPipelineBuilder* fPipelineBuilder;
joshualitt5e6ba212015-07-13 07:35:05 -0700138 int fColorEffectCnt;
139 int fCoverageEffectCnt;
robertphillips@google.com972265d2012-06-13 18:49:30 +0000140 };
141
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000142 /// @}
143
144 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000145 /// @name Blending
146 ////
147
egdaniel89af44a2014-09-26 06:15:04 -0700148 /**
bsalomon6be6f7c2015-02-26 13:05:21 -0800149 * Installs a GrXPFactory. This object controls how src color, fractional pixel coverage,
150 * and the dst color are blended.
151 */
152 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
153 fXPFactory.reset(SkRef(xpFactory));
154 return xpFactory;
155 }
156
157 /**
158 * Sets a GrXPFactory that will ignore src color and perform a set operation between the draws
159 * output coverage and the destination. This is useful to render coverage masks as CSG.
160 */
161 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) {
162 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
163 }
164
165 /**
166 * Sets a GrXPFactory that disables color writes to the destination. This is useful when
167 * rendering to the stencil buffer.
168 */
169 void setDisableColorXPFactory() {
170 fXPFactory.reset(GrDisableColorXPFactory::Create());
171 }
172
173 const GrXPFactory* getXPFactory() const {
174 if (!fXPFactory) {
175 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
176 }
177 return fXPFactory.get();
178 }
179
180 /**
bsalomon6a44c6a2015-05-26 09:49:05 -0700181 * Checks whether the xp will need destination in a texture to correctly blend.
bsalomon6be6f7c2015-02-26 13:05:21 -0800182 */
bsalomon6a44c6a2015-05-26 09:49:05 -0700183 bool willXPNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI,
184 const GrProcOptInfo& coveragePOI) const;
joshualittd27f73e2014-12-29 07:43:36 -0800185
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000186 /// @}
187
bsalomon6be6f7c2015-02-26 13:05:21 -0800188
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000189 ///////////////////////////////////////////////////////////////////////////
190 /// @name Render Target
191 ////
192
193 /**
egdaniel89af44a2014-09-26 06:15:04 -0700194 * Retrieves the currently set render-target.
195 *
196 * @return The currently set render target.
197 */
bsalomon37dd3312014-11-03 08:47:23 -0800198 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700199
200 /**
bsalomon@google.comca432082013-01-23 19:53:46 +0000201 * Sets the render-target used at the next drawing call
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000202 *
203 * @param target The render target to set.
204 */
bsalomonae59b772014-11-19 08:23:49 -0800205 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000206
cdalton86ae0a92015-06-08 15:11:04 -0700207 /**
208 * Returns whether the rasterizer and stencil test (if any) will run at a higher sample rate
209 * than the color buffer. In is scenario, the higher sample rate is resolved during blending.
210 */
211 bool hasMixedSamples() const {
vbuzinovdded6962015-06-12 08:59:45 -0700212 return this->isHWAntialias() && !fRenderTarget->isUnifiedMultisampled();
cdalton86ae0a92015-06-08 15:11:04 -0700213 }
214
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000215 /// @}
216
217 ///////////////////////////////////////////////////////////////////////////
218 /// @name Stencil
219 ////
220
egdaniel89af44a2014-09-26 06:15:04 -0700221 const GrStencilSettings& getStencil() const { return fStencilSettings; }
222
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000223 /**
224 * Sets the stencil settings to use for the next draw.
225 * Changing the clip has the side-effect of possibly zeroing
226 * out the client settable stencil bits. So multipass algorithms
227 * using stencil should not change the clip between passes.
228 * @param settings the stencil settings to use.
229 */
bsalomon04ddf892014-11-19 12:36:22 -0800230 void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000231
232 /**
233 * Shortcut to disable stencil testing and ops.
234 */
bsalomon04ddf892014-11-19 12:36:22 -0800235 void disableStencil() { fStencilSettings.setDisabled(); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000236
bsalomon2ed5ef82014-07-07 08:44:05 -0700237 GrStencilSettings* stencil() { return &fStencilSettings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000238
bsalomon6be6f7c2015-02-26 13:05:21 -0800239 /**
240 * AutoRestoreStencil
241 *
242 * This simple struct saves and restores the stencil settings
joshualitt5e6ba212015-07-13 07:35:05 -0700243 * This class can transiently modify its "const" GrPipelineBuilder object but will restore it
244 * when done - so it is notionally "const" correct.
bsalomon6be6f7c2015-02-26 13:05:21 -0800245 */
246 class AutoRestoreStencil : public ::SkNoncopyable {
247 public:
halcanary96fcdcc2015-08-27 07:41:13 -0700248 AutoRestoreStencil() : fPipelineBuilder(nullptr) {}
bsalomon6be6f7c2015-02-26 13:05:21 -0800249
halcanary96fcdcc2015-08-27 07:41:13 -0700250 AutoRestoreStencil(const GrPipelineBuilder& ds) : fPipelineBuilder(nullptr) { this->set(&ds); }
bsalomon6be6f7c2015-02-26 13:05:21 -0800251
halcanary96fcdcc2015-08-27 07:41:13 -0700252 ~AutoRestoreStencil() { this->set(nullptr); }
bsalomon6be6f7c2015-02-26 13:05:21 -0800253
joshualitt5e6ba212015-07-13 07:35:05 -0700254 void set(const GrPipelineBuilder* ds) {
bsalomon6be6f7c2015-02-26 13:05:21 -0800255 if (fPipelineBuilder) {
256 fPipelineBuilder->setStencil(fStencilSettings);
257 }
joshualitt5e6ba212015-07-13 07:35:05 -0700258 fPipelineBuilder = const_cast<GrPipelineBuilder*>(ds);
bsalomon6be6f7c2015-02-26 13:05:21 -0800259 if (ds) {
260 fStencilSettings = ds->getStencil();
261 }
262 }
263
264 bool isSet() const { return SkToBool(fPipelineBuilder); }
265
joshualitt5e6ba212015-07-13 07:35:05 -0700266 void setStencil(const GrStencilSettings& settings) {
267 SkASSERT(this->isSet());
268 fPipelineBuilder->setStencil(settings);
269 }
270
bsalomon6be6f7c2015-02-26 13:05:21 -0800271 private:
joshualitt5e6ba212015-07-13 07:35:05 -0700272 // notionally const (as marginalia)
bsalomon6be6f7c2015-02-26 13:05:21 -0800273 GrPipelineBuilder* fPipelineBuilder;
274 GrStencilSettings fStencilSettings;
275 };
276
277
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000278 /// @}
279
280 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000281 /// @name State Flags
282 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000283
egdaniel89af44a2014-09-26 06:15:04 -0700284 /**
285 * Flags that affect rendering. Controlled using enable/disableState(). All
286 * default to disabled.
287 */
bsalomond79c5492015-04-27 10:07:04 -0700288 enum Flags {
egdaniel89af44a2014-09-26 06:15:04 -0700289 /**
egdaniel89af44a2014-09-26 06:15:04 -0700290 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
291 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
292 * the 3D API.
293 */
bsalomonaca31fe2015-09-22 11:38:46 -0700294 kHWAntialias_Flag = 0x01,
egdaniel89af44a2014-09-26 06:15:04 -0700295
bsalomond79c5492015-04-27 10:07:04 -0700296 /**
297 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
298 */
bsalomonaca31fe2015-09-22 11:38:46 -0700299 kSnapVerticesToPixelCenters_Flag = 0x02,
bsalomond79c5492015-04-27 10:07:04 -0700300
301 kLast_Flag = kSnapVerticesToPixelCenters_Flag,
egdaniel89af44a2014-09-26 06:15:04 -0700302 };
303
bsalomond79c5492015-04-27 10:07:04 -0700304 bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); }
305 bool snapVerticesToPixelCenters() const {
306 return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000307
308 /**
309 * Enable render state settings.
310 *
bsalomond79c5492015-04-27 10:07:04 -0700311 * @param flags bitfield of Flags specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000312 */
bsalomond79c5492015-04-27 10:07:04 -0700313 void enableState(uint32_t flags) { fFlags |= flags; }
314
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000315 /**
316 * Disable render state settings.
317 *
bsalomond79c5492015-04-27 10:07:04 -0700318 * @param flags bitfield of Flags specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000319 */
bsalomond79c5492015-04-27 10:07:04 -0700320 void disableState(uint32_t flags) { fFlags &= ~(flags); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000321
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000322 /**
bsalomond79c5492015-04-27 10:07:04 -0700323 * Enable or disable flags based on a boolean.
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000324 *
bsalomond79c5492015-04-27 10:07:04 -0700325 * @param flags bitfield of Flags to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000326 * @param enable if true enable stateBits, otherwise disable
327 */
bsalomond79c5492015-04-27 10:07:04 -0700328 void setState(uint32_t flags, bool enable) {
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000329 if (enable) {
bsalomond79c5492015-04-27 10:07:04 -0700330 this->enableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000331 } else {
bsalomond79c5492015-04-27 10:07:04 -0700332 this->disableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000333 }
334 }
335
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000336 /// @}
337
338 ///////////////////////////////////////////////////////////////////////////
339 /// @name Face Culling
340 ////
341
egdaniel89af44a2014-09-26 06:15:04 -0700342 enum DrawFace {
343 kInvalid_DrawFace = -1,
344
345 kBoth_DrawFace,
346 kCCW_DrawFace,
347 kCW_DrawFace,
348 };
349
350 /**
351 * Gets whether the target is drawing clockwise, counterclockwise,
352 * or both faces.
353 * @return the current draw face(s).
354 */
355 DrawFace getDrawFace() const { return fDrawFace; }
356
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000357 /**
358 * Controls whether clockwise, counterclockwise, or both faces are drawn.
359 * @param face the face(s) to draw.
360 */
361 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000362 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700363 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000364 }
365
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000366 /// @}
367
368 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000369
bsalomonabd30f52015-08-13 13:34:48 -0700370 const GrProcOptInfo& colorProcInfo(const GrDrawBatch* batch) const {
joshualitt4d8da812015-01-28 12:53:54 -0800371 this->calcColorInvariantOutput(batch);
372 return fColorProcInfo;
373 }
374
bsalomonabd30f52015-08-13 13:34:48 -0700375 const GrProcOptInfo& coverageProcInfo(const GrDrawBatch* batch) const {
joshualitt4d8da812015-01-28 12:53:54 -0800376 this->calcCoverageInvariantOutput(batch);
377 return fCoverageProcInfo;
378 }
joshualitt44701df2015-02-23 14:44:57 -0800379
380 void setClip(const GrClip& clip) { fClip = clip; }
381 const GrClip& clip() const { return fClip; }
382
egdaniele36914c2015-02-13 09:00:33 -0800383private:
384 // Calculating invariant color / coverage information is expensive, so we partially cache the
385 // results.
386 //
387 // canUseFracCoveragePrimProc() - Called in regular skia draw, caches results but only for a
388 // specific color and coverage. May be called multiple times
egdaniele36914c2015-02-13 09:00:33 -0800389 // GrOptDrawState constructor - never caches results
joshualittd15e4e42015-01-26 13:30:10 -0800390
391 /**
joshualitt4d8da812015-01-28 12:53:54 -0800392 * GrBatch provides the initial seed for these loops based off of its initial geometry data
393 */
bsalomonabd30f52015-08-13 13:34:48 -0700394 void calcColorInvariantOutput(const GrDrawBatch*) const;
395 void calcCoverageInvariantOutput(const GrDrawBatch*) const;
joshualitt4d8da812015-01-28 12:53:54 -0800396
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000397 // Some of the auto restore objects assume that no effects are removed during their lifetime.
398 // This is used to assert that this condition holds.
joshualitt5e6ba212015-07-13 07:35:05 -0700399 SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000400
bsalomonac856c92015-08-27 06:30:17 -0700401 typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArray;
egdaniel89af44a2014-09-26 06:15:04 -0700402
bsalomonae59b772014-11-19 08:23:49 -0800403 SkAutoTUnref<GrRenderTarget> fRenderTarget;
bsalomond79c5492015-04-27 10:07:04 -0700404 uint32_t fFlags;
bsalomonae59b772014-11-19 08:23:49 -0800405 GrStencilSettings fStencilSettings;
bsalomonae59b772014-11-19 08:23:49 -0800406 DrawFace fDrawFace;
joshualitt2fdeda02015-01-22 07:11:44 -0800407 mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
bsalomonac856c92015-08-27 06:30:17 -0700408 FragmentProcessorArray fColorFragmentProcessors;
409 FragmentProcessorArray fCoverageFragmentProcessors;
joshualitt44701df2015-02-23 14:44:57 -0800410 GrClip fClip;
egdaniel89af44a2014-09-26 06:15:04 -0700411
egdanielb6cbc382014-11-13 11:00:34 -0800412 mutable GrProcOptInfo fColorProcInfo;
413 mutable GrProcOptInfo fCoverageProcInfo;
egdanielb6cbc382014-11-13 11:00:34 -0800414
egdaniel8dd688b2015-01-22 10:16:09 -0800415 friend class GrPipeline;
tomhudson@google.com93813632011-10-27 20:21:16 +0000416};
417
418#endif