blob: 0ac64850951a60977a1255bf1f65c45ca10cc631 [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"
joshualitt2cdec312015-07-09 07:31:31 -070016#include "GrProcessorDataManager.h"
egdaniel89af44a2014-09-26 06:15:04 -070017#include "GrRenderTarget.h"
18#include "GrStencil.h"
egdaniel95131432014-12-09 11:15:43 -080019#include "GrXferProcessor.h"
egdaniel89af44a2014-09-26 06:15:04 -070020#include "SkMatrix.h"
egdaniel87509242014-12-17 13:37:13 -080021#include "effects/GrCoverageSetOpXP.h"
egdaniel080e6732014-12-22 07:35:52 -080022#include "effects/GrDisableColorXP.h"
egdaniel95131432014-12-09 11:15:43 -080023#include "effects/GrPorterDuffXferProcessor.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000024#include "effects/GrSimpleTextureEffect.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000025
bsalomonabd30f52015-08-13 13:34:48 -070026class GrDrawBatch;
bsalomon4b91f762015-05-19 09:29:46 -070027class GrCaps;
egdaniel89af44a2014-09-26 06:15:04 -070028class GrPaint;
29class GrTexture;
egdaniel170f90b2014-09-16 12:54:40 -070030
bsalomonac856c92015-08-27 06:30:17 -070031class GrPipelineBuilder : public SkNoncopyable {
bsalomon@google.com2e3d1442012-03-26 20:33:54 +000032public:
egdaniel8dd688b2015-01-22 10:16:09 -080033 GrPipelineBuilder();
34
bsalomon@google.com52a5dcb2012-01-17 16:01:37 +000035 /**
joshualitt7b670db2015-07-09 13:25:02 -070036 * Initializes the GrPipelineBuilder based on a GrPaint, render target, and clip. Note
egdaniel8dd688b2015-01-22 10:16:09 -080037 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have
38 * no GrPaint equivalents are set to default values with the exception of vertex attribute state
39 * which is unmodified by this function and clipping which will be enabled.
bsalomon@google.comaf84e742012-10-05 13:23:24 +000040 */
joshualitt7b670db2015-07-09 13:25:02 -070041 GrPipelineBuilder(const GrPaint&, GrRenderTarget*, const GrClip&);
42
43 virtual ~GrPipelineBuilder();
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000044
bsalomon@google.com2401ae82012-01-17 21:03:05 +000045 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -080046 /// @name Fragment Processors
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000047 ///
bsalomon6be6f7c2015-02-26 13:05:21 -080048 /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage.
49 /// There are two chains of FPs, one for color and one for coverage. The first FP in each
50 /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output
51 /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs
52 /// feed their output to the GrXferProcessor which controls blending.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000053 ////
54
bsalomonac856c92015-08-27 06:30:17 -070055 int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); }
56 int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); }
57 int numFragmentProcessors() const { return this->numColorFragmentProcessors() +
58 this->numCoverageFragmentProcessors(); }
egdaniel378092f2014-12-03 10:40:13 -080059
bsalomonac856c92015-08-27 06:30:17 -070060 const GrFragmentProcessor* getColorFragmentProcessor(int idx) const {
61 return fColorFragmentProcessors[idx];
62 }
63 const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const {
64 return fCoverageFragmentProcessors[idx];
jvanverth@google.com65eb4d52013-03-19 18:51:02 +000065 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +000066
bsalomonac856c92015-08-27 06:30:17 -070067 const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcessor* processor) {
68 SkASSERT(processor);
69 fColorFragmentProcessors.push_back(SkRef(processor));
70 return processor;
71 }
72
73 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* processor) {
74 SkASSERT(processor);
75 fCoverageFragmentProcessors.push_back(SkRef(processor));
76 return processor;
bsalomon@google.comadc65362013-01-28 14:26:09 +000077 }
78
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000079 /**
bsalomon@google.comc7818882013-03-20 19:19:53 +000080 * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
tomhudson@google.com1e8f0162012-07-20 16:25:18 +000081 */
joshualittb0a8a372014-09-23 09:50:21 -070082 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bsalomonac856c92015-08-27 06:30:17 -070083 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
84 matrix))->unref();
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +000085 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000086
joshualittb0a8a372014-09-23 09:50:21 -070087 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
bsalomonac856c92015-08-27 06:30:17 -070088 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
89 matrix))->unref();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000090 }
91
joshualittb0a8a372014-09-23 09:50:21 -070092 void addColorTextureProcessor(GrTexture* texture,
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000093 const SkMatrix& matrix,
94 const GrTextureParams& params) {
bsalomonac856c92015-08-27 06:30:17 -070095 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
96 matrix,
97 params))->unref();
joshualittb0a8a372014-09-23 09:50:21 -070098 }
99
100 void addCoverageTextureProcessor(GrTexture* texture,
101 const SkMatrix& matrix,
102 const GrTextureParams& params) {
bsalomonac856c92015-08-27 06:30:17 -0700103 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture,
104 matrix, params))->unref();
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000105 }
tomhudson@google.com676e6602012-07-10 17:21:48 +0000106
robertphillips@google.com972265d2012-06-13 18:49:30 +0000107 /**
bsalomon6be6f7c2015-02-26 13:05:21 -0800108 * When this object is destroyed it will remove any color/coverage FPs from the pipeline builder
joshualitt4421a4c2015-07-13 09:36:41 -0700109 * and also remove any additions to the GrProcessorDataManager that were added after its
110 * constructor.
joshualitt5e6ba212015-07-13 07:35:05 -0700111 * This class can transiently modify its "const" GrPipelineBuilder object but will restore it
112 * when done - so it is notionally "const" correct.
robertphillips@google.com972265d2012-06-13 18:49:30 +0000113 */
joshualitt4421a4c2015-07-13 09:36:41 -0700114 class AutoRestoreFragmentProcessorState : public ::SkNoncopyable {
robertphillips@google.com972265d2012-06-13 18:49:30 +0000115 public:
joshualitt4421a4c2015-07-13 09:36:41 -0700116 AutoRestoreFragmentProcessorState()
halcanary96fcdcc2015-08-27 07:41:13 -0700117 : fPipelineBuilder(nullptr)
bsalomon9b536522014-09-05 09:18:51 -0700118 , fColorEffectCnt(0)
joshualitt4421a4c2015-07-13 09:36:41 -0700119 , fCoverageEffectCnt(0)
120 , fSaveMarker(0) {}
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000121
joshualitt4421a4c2015-07-13 09:36:41 -0700122 AutoRestoreFragmentProcessorState(const GrPipelineBuilder& ds)
halcanary96fcdcc2015-08-27 07:41:13 -0700123 : fPipelineBuilder(nullptr)
bsalomon9b536522014-09-05 09:18:51 -0700124 , fColorEffectCnt(0)
joshualitt4421a4c2015-07-13 09:36:41 -0700125 , fCoverageEffectCnt(0)
126 , fSaveMarker(0) {
127 this->set(&ds);
robertphillips@google.comf09b87d2013-06-13 20:06:44 +0000128 }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000129
halcanary96fcdcc2015-08-27 07:41:13 -0700130 ~AutoRestoreFragmentProcessorState() { this->set(nullptr); }
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000131
joshualitt5e6ba212015-07-13 07:35:05 -0700132 void set(const GrPipelineBuilder* ds);
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000133
egdaniel8dd688b2015-01-22 10:16:09 -0800134 bool isSet() const { return SkToBool(fPipelineBuilder); }
bsalomon8af05232014-06-03 06:34:58 -0700135
joshualitt4421a4c2015-07-13 09:36:41 -0700136 GrProcessorDataManager* getProcessorDataManager() {
137 SkASSERT(this->isSet());
138 return fPipelineBuilder->getProcessorDataManager();
139 }
140
bsalomonac856c92015-08-27 06:30:17 -0700141 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* processor) {
joshualitt5e6ba212015-07-13 07:35:05 -0700142 SkASSERT(this->isSet());
bsalomonac856c92015-08-27 06:30:17 -0700143 return fPipelineBuilder->addCoverageFragmentProcessor(processor);
joshualitt5e6ba212015-07-13 07:35:05 -0700144 }
145
robertphillips@google.com972265d2012-06-13 18:49:30 +0000146 private:
joshualitt5e6ba212015-07-13 07:35:05 -0700147 // notionally const (as marginalia)
egdaniel8dd688b2015-01-22 10:16:09 -0800148 GrPipelineBuilder* fPipelineBuilder;
joshualitt5e6ba212015-07-13 07:35:05 -0700149 int fColorEffectCnt;
150 int fCoverageEffectCnt;
joshualitt4421a4c2015-07-13 09:36:41 -0700151 uint32_t fSaveMarker;
robertphillips@google.com972265d2012-06-13 18:49:30 +0000152 };
153
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000154 /// @}
155
156 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000157 /// @name Blending
158 ////
159
egdaniel89af44a2014-09-26 06:15:04 -0700160 /**
bsalomon6be6f7c2015-02-26 13:05:21 -0800161 * Installs a GrXPFactory. This object controls how src color, fractional pixel coverage,
162 * and the dst color are blended.
163 */
164 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
165 fXPFactory.reset(SkRef(xpFactory));
166 return xpFactory;
167 }
168
169 /**
170 * Sets a GrXPFactory that will ignore src color and perform a set operation between the draws
171 * output coverage and the destination. This is useful to render coverage masks as CSG.
172 */
173 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) {
174 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage));
175 }
176
177 /**
178 * Sets a GrXPFactory that disables color writes to the destination. This is useful when
179 * rendering to the stencil buffer.
180 */
181 void setDisableColorXPFactory() {
182 fXPFactory.reset(GrDisableColorXPFactory::Create());
183 }
184
185 const GrXPFactory* getXPFactory() const {
186 if (!fXPFactory) {
187 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
188 }
189 return fXPFactory.get();
190 }
191
192 /**
bsalomon6a44c6a2015-05-26 09:49:05 -0700193 * Checks whether the xp will need destination in a texture to correctly blend.
bsalomon6be6f7c2015-02-26 13:05:21 -0800194 */
bsalomon6a44c6a2015-05-26 09:49:05 -0700195 bool willXPNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI,
196 const GrProcOptInfo& coveragePOI) const;
joshualittd27f73e2014-12-29 07:43:36 -0800197
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000198 /// @}
199
bsalomon6be6f7c2015-02-26 13:05:21 -0800200
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000201 ///////////////////////////////////////////////////////////////////////////
202 /// @name Render Target
203 ////
204
205 /**
egdaniel89af44a2014-09-26 06:15:04 -0700206 * Retrieves the currently set render-target.
207 *
208 * @return The currently set render target.
209 */
bsalomon37dd3312014-11-03 08:47:23 -0800210 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700211
212 /**
bsalomon@google.comca432082013-01-23 19:53:46 +0000213 * Sets the render-target used at the next drawing call
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000214 *
215 * @param target The render target to set.
216 */
bsalomonae59b772014-11-19 08:23:49 -0800217 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000218
cdalton86ae0a92015-06-08 15:11:04 -0700219 /**
220 * Returns whether the rasterizer and stencil test (if any) will run at a higher sample rate
221 * than the color buffer. In is scenario, the higher sample rate is resolved during blending.
222 */
223 bool hasMixedSamples() const {
vbuzinovdded6962015-06-12 08:59:45 -0700224 return this->isHWAntialias() && !fRenderTarget->isUnifiedMultisampled();
cdalton86ae0a92015-06-08 15:11:04 -0700225 }
226
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000227 /// @}
228
229 ///////////////////////////////////////////////////////////////////////////
230 /// @name Stencil
231 ////
232
egdaniel89af44a2014-09-26 06:15:04 -0700233 const GrStencilSettings& getStencil() const { return fStencilSettings; }
234
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000235 /**
236 * Sets the stencil settings to use for the next draw.
237 * Changing the clip has the side-effect of possibly zeroing
238 * out the client settable stencil bits. So multipass algorithms
239 * using stencil should not change the clip between passes.
240 * @param settings the stencil settings to use.
241 */
bsalomon04ddf892014-11-19 12:36:22 -0800242 void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000243
244 /**
245 * Shortcut to disable stencil testing and ops.
246 */
bsalomon04ddf892014-11-19 12:36:22 -0800247 void disableStencil() { fStencilSettings.setDisabled(); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000248
bsalomon2ed5ef82014-07-07 08:44:05 -0700249 GrStencilSettings* stencil() { return &fStencilSettings; }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000250
bsalomon6be6f7c2015-02-26 13:05:21 -0800251 /**
252 * AutoRestoreStencil
253 *
254 * This simple struct saves and restores the stencil settings
joshualitt5e6ba212015-07-13 07:35:05 -0700255 * This class can transiently modify its "const" GrPipelineBuilder object but will restore it
256 * when done - so it is notionally "const" correct.
bsalomon6be6f7c2015-02-26 13:05:21 -0800257 */
258 class AutoRestoreStencil : public ::SkNoncopyable {
259 public:
halcanary96fcdcc2015-08-27 07:41:13 -0700260 AutoRestoreStencil() : fPipelineBuilder(nullptr) {}
bsalomon6be6f7c2015-02-26 13:05:21 -0800261
halcanary96fcdcc2015-08-27 07:41:13 -0700262 AutoRestoreStencil(const GrPipelineBuilder& ds) : fPipelineBuilder(nullptr) { this->set(&ds); }
bsalomon6be6f7c2015-02-26 13:05:21 -0800263
halcanary96fcdcc2015-08-27 07:41:13 -0700264 ~AutoRestoreStencil() { this->set(nullptr); }
bsalomon6be6f7c2015-02-26 13:05:21 -0800265
joshualitt5e6ba212015-07-13 07:35:05 -0700266 void set(const GrPipelineBuilder* ds) {
bsalomon6be6f7c2015-02-26 13:05:21 -0800267 if (fPipelineBuilder) {
268 fPipelineBuilder->setStencil(fStencilSettings);
269 }
joshualitt5e6ba212015-07-13 07:35:05 -0700270 fPipelineBuilder = const_cast<GrPipelineBuilder*>(ds);
bsalomon6be6f7c2015-02-26 13:05:21 -0800271 if (ds) {
272 fStencilSettings = ds->getStencil();
273 }
274 }
275
276 bool isSet() const { return SkToBool(fPipelineBuilder); }
277
joshualitt5e6ba212015-07-13 07:35:05 -0700278 void setStencil(const GrStencilSettings& settings) {
279 SkASSERT(this->isSet());
280 fPipelineBuilder->setStencil(settings);
281 }
282
bsalomon6be6f7c2015-02-26 13:05:21 -0800283 private:
joshualitt5e6ba212015-07-13 07:35:05 -0700284 // notionally const (as marginalia)
bsalomon6be6f7c2015-02-26 13:05:21 -0800285 GrPipelineBuilder* fPipelineBuilder;
286 GrStencilSettings fStencilSettings;
287 };
288
289
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000290 /// @}
291
292 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000293 /// @name State Flags
294 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000295
egdaniel89af44a2014-09-26 06:15:04 -0700296 /**
297 * Flags that affect rendering. Controlled using enable/disableState(). All
298 * default to disabled.
299 */
bsalomond79c5492015-04-27 10:07:04 -0700300 enum Flags {
egdaniel89af44a2014-09-26 06:15:04 -0700301 /**
302 * Perform dithering. TODO: Re-evaluate whether we need this bit
303 */
bsalomond79c5492015-04-27 10:07:04 -0700304 kDither_Flag = 0x01,
egdaniel89af44a2014-09-26 06:15:04 -0700305 /**
306 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
307 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
308 * the 3D API.
309 */
bsalomond79c5492015-04-27 10:07:04 -0700310 kHWAntialias_Flag = 0x02,
egdaniel89af44a2014-09-26 06:15:04 -0700311
bsalomond79c5492015-04-27 10:07:04 -0700312 /**
313 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
314 */
315 kSnapVerticesToPixelCenters_Flag = 0x04,
316
317 kLast_Flag = kSnapVerticesToPixelCenters_Flag,
egdaniel89af44a2014-09-26 06:15:04 -0700318 };
319
bsalomond79c5492015-04-27 10:07:04 -0700320 bool isDither() const { return SkToBool(fFlags & kDither_Flag); }
321 bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); }
322 bool snapVerticesToPixelCenters() const {
323 return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000324
325 /**
326 * Enable render state settings.
327 *
bsalomond79c5492015-04-27 10:07:04 -0700328 * @param flags bitfield of Flags specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000329 */
bsalomond79c5492015-04-27 10:07:04 -0700330 void enableState(uint32_t flags) { fFlags |= flags; }
331
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000332 /**
333 * Disable render state settings.
334 *
bsalomond79c5492015-04-27 10:07:04 -0700335 * @param flags bitfield of Flags specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000336 */
bsalomond79c5492015-04-27 10:07:04 -0700337 void disableState(uint32_t flags) { fFlags &= ~(flags); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000338
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000339 /**
bsalomond79c5492015-04-27 10:07:04 -0700340 * Enable or disable flags based on a boolean.
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000341 *
bsalomond79c5492015-04-27 10:07:04 -0700342 * @param flags bitfield of Flags to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000343 * @param enable if true enable stateBits, otherwise disable
344 */
bsalomond79c5492015-04-27 10:07:04 -0700345 void setState(uint32_t flags, bool enable) {
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000346 if (enable) {
bsalomond79c5492015-04-27 10:07:04 -0700347 this->enableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000348 } else {
bsalomond79c5492015-04-27 10:07:04 -0700349 this->disableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000350 }
351 }
352
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000353 /// @}
354
355 ///////////////////////////////////////////////////////////////////////////
356 /// @name Face Culling
357 ////
358
egdaniel89af44a2014-09-26 06:15:04 -0700359 enum DrawFace {
360 kInvalid_DrawFace = -1,
361
362 kBoth_DrawFace,
363 kCCW_DrawFace,
364 kCW_DrawFace,
365 };
366
367 /**
368 * Gets whether the target is drawing clockwise, counterclockwise,
369 * or both faces.
370 * @return the current draw face(s).
371 */
372 DrawFace getDrawFace() const { return fDrawFace; }
373
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000374 /**
375 * Controls whether clockwise, counterclockwise, or both faces are drawn.
376 * @param face the face(s) to draw.
377 */
378 void setDrawFace(DrawFace face) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000379 SkASSERT(kInvalid_DrawFace != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700380 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000381 }
382
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000383 /// @}
384
385 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000386
joshualitt4d8da812015-01-28 12:53:54 -0800387 // TODO delete when we have Batch
joshualitt56995b52014-12-11 15:44:02 -0800388 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const {
389 this->calcColorInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800390 return fColorProcInfo;
391 }
392
joshualitt56995b52014-12-11 15:44:02 -0800393 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const {
394 this->calcCoverageInvariantOutput(pp);
egdaniel912b3d22014-11-17 07:45:53 -0800395 return fCoverageProcInfo;
396 }
397
bsalomonabd30f52015-08-13 13:34:48 -0700398 const GrProcOptInfo& colorProcInfo(const GrDrawBatch* batch) const {
joshualitt4d8da812015-01-28 12:53:54 -0800399 this->calcColorInvariantOutput(batch);
400 return fColorProcInfo;
401 }
402
bsalomonabd30f52015-08-13 13:34:48 -0700403 const GrProcOptInfo& coverageProcInfo(const GrDrawBatch* batch) const {
joshualitt4d8da812015-01-28 12:53:54 -0800404 this->calcCoverageInvariantOutput(batch);
405 return fCoverageProcInfo;
406 }
joshualitt44701df2015-02-23 14:44:57 -0800407
408 void setClip(const GrClip& clip) { fClip = clip; }
409 const GrClip& clip() const { return fClip; }
410
joshualitt5b4f05f2015-07-10 07:26:21 -0700411 GrProcessorDataManager* getProcessorDataManager() { return fProcDataManager.get(); }
412 const GrProcessorDataManager* processorDataManager() const { return fProcDataManager.get(); }
joshualitt2cdec312015-07-09 07:31:31 -0700413
egdaniele36914c2015-02-13 09:00:33 -0800414private:
415 // Calculating invariant color / coverage information is expensive, so we partially cache the
416 // results.
417 //
418 // canUseFracCoveragePrimProc() - Called in regular skia draw, caches results but only for a
419 // specific color and coverage. May be called multiple times
egdaniele36914c2015-02-13 09:00:33 -0800420 // GrOptDrawState constructor - never caches results
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 */
bsalomonabd30f52015-08-13 13:34:48 -0700432 void calcColorInvariantOutput(const GrDrawBatch*) const;
433 void calcCoverageInvariantOutput(const GrDrawBatch*) const;
joshualitt4d8da812015-01-28 12:53:54 -0800434
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000435 // Some of the auto restore objects assume that no effects are removed during their lifetime.
436 // This is used to assert that this condition holds.
joshualitt5e6ba212015-07-13 07:35:05 -0700437 SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;)
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000438
bsalomonac856c92015-08-27 06:30:17 -0700439 typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArray;
egdaniel89af44a2014-09-26 06:15:04 -0700440
joshualitt5b4f05f2015-07-10 07:26:21 -0700441 SkAutoTUnref<GrProcessorDataManager> fProcDataManager;
bsalomonae59b772014-11-19 08:23:49 -0800442 SkAutoTUnref<GrRenderTarget> fRenderTarget;
bsalomond79c5492015-04-27 10:07:04 -0700443 uint32_t fFlags;
bsalomonae59b772014-11-19 08:23:49 -0800444 GrStencilSettings fStencilSettings;
bsalomonae59b772014-11-19 08:23:49 -0800445 DrawFace fDrawFace;
joshualitt2fdeda02015-01-22 07:11:44 -0800446 mutable SkAutoTUnref<const GrXPFactory> fXPFactory;
bsalomonac856c92015-08-27 06:30:17 -0700447 FragmentProcessorArray fColorFragmentProcessors;
448 FragmentProcessorArray fCoverageFragmentProcessors;
joshualitt44701df2015-02-23 14:44:57 -0800449 GrClip fClip;
egdaniel89af44a2014-09-26 06:15:04 -0700450
egdanielb6cbc382014-11-13 11:00:34 -0800451 mutable GrProcOptInfo fColorProcInfo;
452 mutable GrProcOptInfo fCoverageProcInfo;
egdanielb6cbc382014-11-13 11:00:34 -0800453
egdaniel8dd688b2015-01-22 10:16:09 -0800454 friend class GrPipeline;
tomhudson@google.com93813632011-10-27 20:21:16 +0000455};
456
457#endif