blob: 7c861b2c1eb1222c7b29c49d67fc45c3c6031336 [file] [log] [blame]
egdaniel3658f382014-09-15 07:01:59 -07001/*
egdaniel8dd688b2015-01-22 10:16:09 -08002 * Copyright 2015 Google Inc.
egdaniel3658f382014-09-15 07:01:59 -07003 *
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 GrPipeline_DEFINED
9#define GrPipeline_DEFINED
egdaniel3658f382014-09-15 07:01:59 -070010
egdanielb109ac22014-10-07 06:45:44 -070011#include "GrColor.h"
bsalomonac856c92015-08-27 06:30:17 -070012#include "GrFragmentProcessor.h"
joshualittdbe1e6f2015-07-16 08:12:45 -070013#include "GrNonAtomicRef.h"
bsalomonac856c92015-08-27 06:30:17 -070014#include "GrPendingProgramElement.h"
Brian Salomon5298dc82017-02-22 11:52:03 -050015#include "GrProcessorSet.h"
joshualitt79f8fae2014-10-28 17:59:26 -070016#include "GrProgramDesc.h"
csmartdaltonbf4a8f92016-09-06 10:01:06 -070017#include "GrScissorState.h"
csmartdaltonc633abb2016-11-01 08:55:55 -070018#include "GrUserStencilSettings.h"
csmartdaltonbf4a8f92016-09-06 10:01:06 -070019#include "GrWindowRectsState.h"
egdanielb109ac22014-10-07 06:45:44 -070020#include "SkMatrix.h"
21#include "SkRefCnt.h"
robertphillips5fa7f302016-07-21 09:21:04 -070022#include "effects/GrCoverageSetOpXP.h"
23#include "effects/GrDisableColorXP.h"
24#include "effects/GrPorterDuffXferProcessor.h"
25#include "effects/GrSimpleTextureEffect.h"
26
Brian Salomon652ecb52017-01-17 12:39:53 -050027class GrAppliedClip;
joshualitt79f8fae2014-10-28 17:59:26 -070028class GrDeviceCoordTexture;
Brian Salomon25a88092016-12-01 09:36:50 -050029class GrOp;
egdaniel8dd688b2015-01-22 10:16:09 -080030class GrPipelineBuilder;
Brian Salomon25a88092016-12-01 09:36:50 -050031class GrRenderTargetContext;
egdaniel3658f382014-09-15 07:01:59 -070032
Brian Salomon92aee3d2016-12-21 09:20:25 -050033/**
egdaniel8dd688b2015-01-22 10:16:09 -080034 * Class that holds an optimized version of a GrPipelineBuilder. It is meant to be an immutable
35 * class, and contains all data needed to set the state for a gpu draw.
egdaniel3658f382014-09-15 07:01:59 -070036 */
cdalton4833f392016-02-02 22:46:16 -080037class GrPipeline : public GrNonAtomicRef<GrPipeline> {
egdaniel3658f382014-09-15 07:01:59 -070038public:
bsalomoncb02b382015-08-12 11:14:50 -070039 ///////////////////////////////////////////////////////////////////////////
40 /// @name Creation
41
Brian Salomon189098e72017-01-19 09:55:19 -050042 enum Flags {
43 /**
44 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
45 * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by
46 * the 3D API.
47 */
48 kHWAntialias_Flag = 0x1,
49
50 /**
51 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
52 */
53 kSnapVerticesToPixelCenters_Flag = 0x2,
Brian Salomon189098e72017-01-19 09:55:19 -050054 };
55
Brian Salomonb5cb6832017-02-24 11:01:15 -050056 struct InitArgs {
Brian Salomon189098e72017-01-19 09:55:19 -050057 uint32_t fFlags = 0;
58 GrDrawFace fDrawFace = GrDrawFace::kBoth;
59 const GrProcessorSet* fProcessors = nullptr;
Brian Salomon5298dc82017-02-22 11:52:03 -050060 const GrProcessorSet::FragmentProcessorAnalysis* fAnalysis;
Brian Salomon189098e72017-01-19 09:55:19 -050061 const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused;
Brian Salomonb5cb6832017-02-24 11:01:15 -050062 const GrAppliedClip* fAppliedClip = nullptr;
Brian Salomonb16e8ac2017-02-22 11:52:36 -050063 GrRenderTarget* fRenderTarget = nullptr;
Brian Salomon189098e72017-01-19 09:55:19 -050064 const GrCaps* fCaps = nullptr;
bsalomona387a112015-08-11 14:47:42 -070065 GrXferProcessor::DstTexture fDstTexture;
66 };
67
Brian Salomonb5cb6832017-02-24 11:01:15 -050068 /**
69 * A Default constructed pipeline is unusable until init() is called.
70 **/
71 GrPipeline() = default;
egdanielb109ac22014-10-07 06:45:44 -070072
csmartdalton119fb2b2017-02-08 14:41:05 -050073 /**
74 * Creates a simple pipeline with default settings and no processors. The provided blend mode
Brian Salomonb5cb6832017-02-24 11:01:15 -050075 * must be "Porter Duff" (<= kLastCoeffMode). This pipeline is initialized without requiring
76 * a call to init().
csmartdalton119fb2b2017-02-08 14:41:05 -050077 **/
78 GrPipeline(GrRenderTarget*, SkBlendMode);
79
Brian Salomonb5cb6832017-02-24 11:01:15 -050080 /** (Re)initializes a pipeline. After initialization the pipeline can be used. */
Brian Salomone7d30482017-03-29 12:09:15 -040081 void init(const InitArgs&);
Brian Salomonb5cb6832017-02-24 11:01:15 -050082
83 /** True if the pipeline has been initialized. */
84 bool isInitialized() const { return SkToBool(fRenderTarget.get()); }
85
bsalomoncb02b382015-08-12 11:14:50 -070086 /// @}
87
88 ///////////////////////////////////////////////////////////////////////////
89 /// @name Comparisons
90
91 /**
joshualitt2fe79232015-08-05 12:02:27 -070092 * Returns true if these pipelines are equivalent. Coord transforms may be applied either on
93 * the GPU or the CPU. When we apply them on the CPU then the matrices need not agree in order
94 * to combine draws. Therefore we take a param that indicates whether coord transforms should be
95 * compared."
joshualitt9b989322014-12-15 14:16:27 -080096 */
bsalomon7312ff82016-09-12 08:55:38 -070097 static bool AreEqual(const GrPipeline& a, const GrPipeline& b);
bsalomoncb02b382015-08-12 11:14:50 -070098
99 /**
Brian Salomon09d994e2016-12-21 11:14:46 -0500100 * Allows a GrOp subclass to determine whether two GrOp instances can combine. This is a
101 * stricter test than isEqual because it also considers blend barriers when the two ops'
102 * bounds overlap
bsalomoncb02b382015-08-12 11:14:50 -0700103 */
104 static bool CanCombine(const GrPipeline& a, const SkRect& aBounds,
105 const GrPipeline& b, const SkRect& bBounds,
bsalomon7312ff82016-09-12 08:55:38 -0700106 const GrCaps& caps) {
107 if (!AreEqual(a, b)) {
bsalomoncb02b382015-08-12 11:14:50 -0700108 return false;
109 }
110 if (a.xferBarrierType(caps)) {
111 return aBounds.fRight <= bBounds.fLeft ||
112 aBounds.fBottom <= bBounds.fTop ||
113 bBounds.fRight <= aBounds.fLeft ||
114 bBounds.fBottom <= aBounds.fTop;
115 }
116 return true;
117 }
egdaniel89af44a2014-09-26 06:15:04 -0700118
119 /// @}
120
121 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -0800122 /// @name GrFragmentProcessors
egdaniel89af44a2014-09-26 06:15:04 -0700123
Robert Phillipsf2361d22016-10-25 14:20:06 -0400124 // Make the renderTarget's GrOpList (if it exists) be dependent on any
125 // GrOpLists in this pipeline
robertphillips498d7ac2015-10-30 10:11:30 -0700126 void addDependenciesTo(GrRenderTarget* rt) const;
bsalomon6be6f7c2015-02-26 13:05:21 -0800127
bsalomonac856c92015-08-27 06:30:17 -0700128 int numColorFragmentProcessors() const { return fNumColorProcessors; }
129 int numCoverageFragmentProcessors() const {
130 return fFragmentProcessors.count() - fNumColorProcessors;
131 }
132 int numFragmentProcessors() const { return fFragmentProcessors.count(); }
egdaniel89af44a2014-09-26 06:15:04 -0700133
bsalomon2047b782015-12-21 13:12:54 -0800134 const GrXferProcessor& getXferProcessor() const {
135 if (fXferProcessor.get()) {
136 return *fXferProcessor.get();
137 } else {
138 // A null xp member means the common src-over case. GrXferProcessor's ref'ing
139 // mechanism is not thread safe so we do not hold a ref on this global.
140 return GrPorterDuffXPFactory::SimpleSrcOverXP();
141 }
142 }
egdaniel378092f2014-12-03 10:40:13 -0800143
bsalomonac856c92015-08-27 06:30:17 -0700144 const GrFragmentProcessor& getColorFragmentProcessor(int idx) const {
145 SkASSERT(idx < this->numColorFragmentProcessors());
146 return *fFragmentProcessors[idx].get();
egdanield9aa2182014-10-09 13:47:05 -0700147 }
bsalomonac856c92015-08-27 06:30:17 -0700148
149 const GrFragmentProcessor& getCoverageFragmentProcessor(int idx) const {
150 SkASSERT(idx < this->numCoverageFragmentProcessors());
151 return *fFragmentProcessors[fNumColorProcessors + idx].get();
egdanield9aa2182014-10-09 13:47:05 -0700152 }
bsalomonac856c92015-08-27 06:30:17 -0700153
154 const GrFragmentProcessor& getFragmentProcessor(int idx) const {
155 return *fFragmentProcessors[idx].get();
bsalomonae59b772014-11-19 08:23:49 -0800156 }
egdaniel89af44a2014-09-26 06:15:04 -0700157
158 /// @}
159
egdaniel89af44a2014-09-26 06:15:04 -0700160 /**
161 * Retrieves the currently set render-target.
162 *
163 * @return The currently set render target.
164 */
bsalomon37dd3312014-11-03 08:47:23 -0800165 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
egdaniel89af44a2014-09-26 06:15:04 -0700166
csmartdaltonc633abb2016-11-01 08:55:55 -0700167 const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; }
egdaniel89af44a2014-09-26 06:15:04 -0700168
bsalomon3e791242014-12-17 13:43:13 -0800169 const GrScissorState& getScissorState() const { return fScissorState; }
joshualitt54e0c122014-11-19 09:38:51 -0800170
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700171 const GrWindowRectsState& getWindowRectsState() const { return fWindowRectsState; }
csmartdalton28341fa2016-08-17 10:00:21 -0700172
Brian Salomon189098e72017-01-19 09:55:19 -0500173 bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAntialias_Flag); }
174 bool snapVerticesToPixelCenters() const {
175 return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag);
176 }
brianosman64d094d2016-03-25 06:01:59 -0700177 bool getDisableOutputConversionToSRGB() const {
178 return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag);
179 }
brianosman898235c2016-04-06 07:38:23 -0700180 bool getAllowSRGBInputs() const {
181 return SkToBool(fFlags & kAllowSRGBInputs_Flag);
182 }
dvonbeck9b03e7b2016-08-01 11:01:56 -0700183 bool usesDistanceVectorField() const {
184 return SkToBool(fFlags & kUsesDistanceVectorField_Flag);
185 }
cdalton193d9cf2016-05-12 11:52:02 -0700186 bool hasStencilClip() const {
187 return SkToBool(fFlags & kHasStencilClip_Flag);
188 }
csmartdaltonc633abb2016-11-01 08:55:55 -0700189 bool isStencilEnabled() const {
190 return SkToBool(fFlags & kStencilEnabled_Flag);
191 }
bsalomonae59b772014-11-19 08:23:49 -0800192
bsalomoncb02b382015-08-12 11:14:50 -0700193 GrXferBarrierType xferBarrierType(const GrCaps& caps) const {
bsalomon2047b782015-12-21 13:12:54 -0800194 return this->getXferProcessor().xferBarrierType(fRenderTarget.get(), caps);
bsalomoncb02b382015-08-12 11:14:50 -0700195 }
196
egdaniel89af44a2014-09-26 06:15:04 -0700197 /**
bsalomonae59b772014-11-19 08:23:49 -0800198 * Gets whether the target is drawing clockwise, counterclockwise,
199 * or both faces.
200 * @return the current draw face(s).
egdaniel89af44a2014-09-26 06:15:04 -0700201 */
Brian Salomon189098e72017-01-19 09:55:19 -0500202 GrDrawFace getDrawFace() const { return static_cast<GrDrawFace>(fDrawFace); }
bsalomonae59b772014-11-19 08:23:49 -0800203
bsalomonae59b772014-11-19 08:23:49 -0800204private:
Brian Salomonf87e2b92017-01-19 11:31:50 -0500205 /** This is a continuation of the public "Flags" enum. */
Brian Salomon189098e72017-01-19 09:55:19 -0500206 enum PrivateFlags {
Brian Salomonf87e2b92017-01-19 11:31:50 -0500207 kDisableOutputConversionToSRGB_Flag = 0x4,
208 kAllowSRGBInputs_Flag = 0x8,
Brian Salomon189098e72017-01-19 09:55:19 -0500209 kUsesDistanceVectorField_Flag = 0x10,
210 kHasStencilClip_Flag = 0x20,
211 kStencilEnabled_Flag = 0x40,
bsalomon04ddf892014-11-19 12:36:22 -0800212 };
213
bsalomonae59b772014-11-19 08:23:49 -0800214 typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget;
bsalomonac856c92015-08-27 06:30:17 -0700215 typedef GrPendingProgramElement<const GrFragmentProcessor> PendingFragmentProcessor;
216 typedef SkAutoSTArray<8, PendingFragmentProcessor> FragmentProcessorArray;
egdaniel378092f2014-12-03 10:40:13 -0800217 typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor;
bsalomonae59b772014-11-19 08:23:49 -0800218 RenderTarget fRenderTarget;
bsalomon3e791242014-12-17 13:43:13 -0800219 GrScissorState fScissorState;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700220 GrWindowRectsState fWindowRectsState;
csmartdaltonc633abb2016-11-01 08:55:55 -0700221 const GrUserStencilSettings* fUserStencilSettings;
Brian Salomon189098e72017-01-19 09:55:19 -0500222 uint16_t fDrawFace;
223 uint16_t fFlags;
egdaniel378092f2014-12-03 10:40:13 -0800224 ProgramXferProcessor fXferProcessor;
bsalomonac856c92015-08-27 06:30:17 -0700225 FragmentProcessorArray fFragmentProcessors;
egdanield9aa2182014-10-09 13:47:05 -0700226
bsalomonac856c92015-08-27 06:30:17 -0700227 // This value is also the index in fFragmentProcessors where coverage processors begin.
228 int fNumColorProcessors;
egdaniel89af44a2014-09-26 06:15:04 -0700229
egdaniel89af44a2014-09-26 06:15:04 -0700230 typedef SkRefCnt INHERITED;
egdaniel3658f382014-09-15 07:01:59 -0700231};
232
233#endif