blob: e0c4d3d46ea71efea3e54b8fa57d37be882e09f1 [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
bsalomonf96ba022014-09-17 08:05:40 -070011#include "GrGpuResourceRef.h"
Brian Salomon92ce5942017-01-18 11:01:10 -050012#include "GrProcessorSet.h"
egdaniel89af44a2014-09-26 06:15:04 -070013#include "GrRenderTarget.h"
cdalton93a379b2016-05-11 13:58:08 -070014#include "GrUserStencilSettings.h"
egdaniel95131432014-12-09 11:15:43 -080015#include "GrXferProcessor.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000016
bsalomon4b91f762015-05-19 09:29:46 -070017class GrCaps;
Brian Salomon92ce5942017-01-18 11:01:10 -050018class GrDrawOp;
egdaniel89af44a2014-09-26 06:15:04 -070019class GrPaint;
Brian Salomon92ce5942017-01-18 11:01:10 -050020struct GrPipelineAnalysis;
egdaniel89af44a2014-09-26 06:15:04 -070021class GrTexture;
egdaniel170f90b2014-09-16 12:54:40 -070022
Brian Salomon92ce5942017-01-18 11:01:10 -050023class GrPipelineBuilder : private SkNoncopyable {
bsalomon@google.com2e3d1442012-03-26 20:33:54 +000024public:
bsalomon@google.com52a5dcb2012-01-17 16:01:37 +000025 /**
robertphillips55fdccc2016-06-06 06:16:20 -070026 * Initializes the GrPipelineBuilder based on a GrPaint and MSAA availability. Note
egdaniel8dd688b2015-01-22 10:16:09 -080027 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have
28 * no GrPaint equivalents are set to default values with the exception of vertex attribute state
29 * which is unmodified by this function and clipping which will be enabled.
bsalomon@google.comaf84e742012-10-05 13:23:24 +000030 */
Brian Salomon82f44312017-01-11 13:42:54 -050031 GrPipelineBuilder(GrPaint&&, GrAAType);
joshualitt7b670db2015-07-09 13:25:02 -070032
bsalomon@google.com2401ae82012-01-17 21:03:05 +000033 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -080034 /// @name Fragment Processors
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000035 ///
bsalomon6be6f7c2015-02-26 13:05:21 -080036 /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage.
37 /// There are two chains of FPs, one for color and one for coverage. The first FP in each
38 /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output
39 /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs
40 /// feed their output to the GrXferProcessor which controls blending.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000041 ////
42
Brian Salomon92ce5942017-01-18 11:01:10 -050043 int numColorFragmentProcessors() const { return fProcessors.numColorFragmentProcessors(); }
44 int numCoverageFragmentProcessors() const {
45 return fProcessors.numCoverageFragmentProcessors();
46 }
47 int numFragmentProcessors() const { return fProcessors.numFragmentProcessors(); }
egdaniel378092f2014-12-03 10:40:13 -080048
bsalomonac856c92015-08-27 06:30:17 -070049 const GrFragmentProcessor* getColorFragmentProcessor(int idx) const {
Brian Salomon92ce5942017-01-18 11:01:10 -050050 return fProcessors.colorFragmentProcessor(idx);
bsalomonac856c92015-08-27 06:30:17 -070051 }
52 const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const {
Brian Salomon92ce5942017-01-18 11:01:10 -050053 return fProcessors.coverageFragmentProcessor(idx);
54 }
55
56 void analyzeFragmentProcessors(GrPipelineAnalysis* analysis) const {
57 fProcessors.analyzeFragmentProcessors(analysis);
jvanverth@google.com65eb4d52013-03-19 18:51:02 +000058 }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +000059
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000060 /// @}
61
62 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000063 /// @name Blending
64 ////
65
Brian Salomon92ce5942017-01-18 11:01:10 -050066 const GrXPFactory* getXPFactory() const { return fProcessors.xpFactory(); }
bsalomon6be6f7c2015-02-26 13:05:21 -080067
68 /**
bsalomon6a44c6a2015-05-26 09:49:05 -070069 * Checks whether the xp will need destination in a texture to correctly blend.
bsalomon6be6f7c2015-02-26 13:05:21 -080070 */
Brian Salomon92aee3d2016-12-21 09:20:25 -050071 bool willXPNeedDstTexture(const GrCaps& caps, const GrPipelineAnalysis&) const;
joshualittd27f73e2014-12-29 07:43:36 -080072
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000073 /// @}
74
bsalomon6be6f7c2015-02-26 13:05:21 -080075
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000076 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000077 /// @name Stencil
78 ////
79
robertphillips976f5f02016-06-03 10:59:20 -070080 bool hasUserStencilSettings() const { return !fUserStencilSettings->isUnused(); }
cdalton93a379b2016-05-11 13:58:08 -070081 const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; }
egdaniel89af44a2014-09-26 06:15:04 -070082
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000083 /**
cdalton93a379b2016-05-11 13:58:08 -070084 * Sets the user stencil settings for the next draw.
85 * This class only stores pointers to stencil settings objects.
86 * The caller guarantees the pointer will remain valid until it
87 * changes or goes out of scope.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000088 * @param settings the stencil settings to use.
89 */
cdalton93a379b2016-05-11 13:58:08 -070090 void setUserStencil(const GrUserStencilSettings* settings) { fUserStencilSettings = settings; }
91 void disableUserStencil() { fUserStencilSettings = &GrUserStencilSettings::kUnused; }
bsalomon6be6f7c2015-02-26 13:05:21 -080092
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000093 /// @}
94
95 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000096 /// @name State Flags
97 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +000098
egdaniel89af44a2014-09-26 06:15:04 -070099 /**
100 * Flags that affect rendering. Controlled using enable/disableState(). All
101 * default to disabled.
102 */
bsalomond79c5492015-04-27 10:07:04 -0700103 enum Flags {
egdaniel89af44a2014-09-26 06:15:04 -0700104 /**
egdaniel89af44a2014-09-26 06:15:04 -0700105 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
106 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
107 * the 3D API.
108 */
bsalomonaca31fe2015-09-22 11:38:46 -0700109 kHWAntialias_Flag = 0x01,
egdaniel89af44a2014-09-26 06:15:04 -0700110
bsalomond79c5492015-04-27 10:07:04 -0700111 /**
112 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
113 */
bsalomonaca31fe2015-09-22 11:38:46 -0700114 kSnapVerticesToPixelCenters_Flag = 0x02,
bsalomond79c5492015-04-27 10:07:04 -0700115
brianosman64d094d2016-03-25 06:01:59 -0700116 /**
117 * Suppress linear -> sRGB conversion when rendering to sRGB render targets.
118 */
119 kDisableOutputConversionToSRGB_Flag = 0x04,
120
brianosman898235c2016-04-06 07:38:23 -0700121 /**
122 * Allow sRGB -> linear conversion when reading from sRGB inputs.
123 */
124 kAllowSRGBInputs_Flag = 0x08,
125
dvonbeck9b03e7b2016-08-01 11:01:56 -0700126 /**
127 * Signals that one or more FPs need access to the distance vector field to the nearest
128 * edge
129 */
130 kUsesDistanceVectorField_Flag = 0x10,
131
132 kLast_Flag = kUsesDistanceVectorField_Flag,
egdaniel89af44a2014-09-26 06:15:04 -0700133 };
134
bsalomond79c5492015-04-27 10:07:04 -0700135 bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); }
136 bool snapVerticesToPixelCenters() const {
137 return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); }
brianosman64d094d2016-03-25 06:01:59 -0700138 bool getDisableOutputConversionToSRGB() const {
139 return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag); }
brianosman898235c2016-04-06 07:38:23 -0700140 bool getAllowSRGBInputs() const {
141 return SkToBool(fFlags & kAllowSRGBInputs_Flag); }
dvonbeck9b03e7b2016-08-01 11:01:56 -0700142 bool getUsesDistanceVectorField() const {
143 return SkToBool(fFlags & kUsesDistanceVectorField_Flag); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000144
145 /**
146 * Enable render state settings.
147 *
bsalomond79c5492015-04-27 10:07:04 -0700148 * @param flags bitfield of Flags specifying the states to enable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000149 */
bsalomond79c5492015-04-27 10:07:04 -0700150 void enableState(uint32_t flags) { fFlags |= flags; }
halcanary9d524f22016-03-29 09:03:52 -0700151
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000152 /**
153 * Disable render state settings.
154 *
bsalomond79c5492015-04-27 10:07:04 -0700155 * @param flags bitfield of Flags specifying the states to disable
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000156 */
bsalomond79c5492015-04-27 10:07:04 -0700157 void disableState(uint32_t flags) { fFlags &= ~(flags); }
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000158
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000159 /**
bsalomond79c5492015-04-27 10:07:04 -0700160 * Enable or disable flags based on a boolean.
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000161 *
bsalomond79c5492015-04-27 10:07:04 -0700162 * @param flags bitfield of Flags to enable or disable
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000163 * @param enable if true enable stateBits, otherwise disable
164 */
bsalomond79c5492015-04-27 10:07:04 -0700165 void setState(uint32_t flags, bool enable) {
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000166 if (enable) {
bsalomond79c5492015-04-27 10:07:04 -0700167 this->enableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000168 } else {
bsalomond79c5492015-04-27 10:07:04 -0700169 this->disableState(flags);
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000170 }
171 }
172
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000173 /// @}
174
175 ///////////////////////////////////////////////////////////////////////////
176 /// @name Face Culling
177 ////
178
egdaniel89af44a2014-09-26 06:15:04 -0700179 /**
180 * Gets whether the target is drawing clockwise, counterclockwise,
181 * or both faces.
182 * @return the current draw face(s).
183 */
robertphillips5fa7f302016-07-21 09:21:04 -0700184 GrDrawFace getDrawFace() const { return fDrawFace; }
egdaniel89af44a2014-09-26 06:15:04 -0700185
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000186 /**
187 * Controls whether clockwise, counterclockwise, or both faces are drawn.
188 * @param face the face(s) to draw.
189 */
robertphillips5fa7f302016-07-21 09:21:04 -0700190 void setDrawFace(GrDrawFace face) {
191 SkASSERT(GrDrawFace::kInvalid != face);
bsalomon2ed5ef82014-07-07 08:44:05 -0700192 fDrawFace = face;
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000193 }
194
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000195 /// @}
196
197 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000198
Brian Salomon09d994e2016-12-21 11:14:46 -0500199 bool usePLSDstRead(const GrDrawOp*) const;
joshualitt44701df2015-02-23 14:44:57 -0800200
egdaniele36914c2015-02-13 09:00:33 -0800201private:
Brian Salomon92ce5942017-01-18 11:01:10 -0500202 uint32_t fFlags;
203 const GrUserStencilSettings* fUserStencilSettings;
204 GrDrawFace fDrawFace;
205 GrProcessorSet fProcessors;
tomhudson@google.com93813632011-10-27 20:21:16 +0000206};
207
208#endif