blob: 9bb2c49c1717f6834d6cc907df1019981f669f40 [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 Salomon189098e72017-01-19 09:55:19 -050012#include "GrPipeline.h"
Brian Salomon92ce5942017-01-18 11:01:10 -050013#include "GrProcessorSet.h"
egdaniel89af44a2014-09-26 06:15:04 -070014#include "GrRenderTarget.h"
cdalton93a379b2016-05-11 13:58:08 -070015#include "GrUserStencilSettings.h"
egdaniel95131432014-12-09 11:15:43 -080016#include "GrXferProcessor.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000017
bsalomon4b91f762015-05-19 09:29:46 -070018class GrCaps;
Brian Salomon92ce5942017-01-18 11:01:10 -050019class GrDrawOp;
egdaniel89af44a2014-09-26 06:15:04 -070020class GrPaint;
21class 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 Salomond2743ea2017-02-21 16:54:27 -050031 GrPipelineBuilder(GrPaint&& paint, GrAAType aaType)
Brian Salomon611572c2017-04-28 08:57:12 -040032 : fFlags(GrPipeline::SRGBFlagsFromPaint(paint))
Brian Salomond2743ea2017-02-21 16:54:27 -050033 , fUserStencilSettings(&GrUserStencilSettings::kUnused)
34 , fProcessors(std::move(paint)) {
35 if (GrAATypeIsHW(aaType)) {
36 fFlags |= GrPipeline::kHWAntialias_Flag;
37 }
38 }
joshualitt7b670db2015-07-09 13:25:02 -070039
bsalomon@google.com2401ae82012-01-17 21:03:05 +000040 ///////////////////////////////////////////////////////////////////////////
bsalomon6be6f7c2015-02-26 13:05:21 -080041 /// @name Fragment Processors
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000042 ///
bsalomon6be6f7c2015-02-26 13:05:21 -080043 /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage.
44 /// There are two chains of FPs, one for color and one for coverage. The first FP in each
45 /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output
46 /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs
47 /// feed their output to the GrXferProcessor which controls blending.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000048 ////
49
Brian Salomon92ce5942017-01-18 11:01:10 -050050 int numColorFragmentProcessors() const { return fProcessors.numColorFragmentProcessors(); }
51 int numCoverageFragmentProcessors() const {
52 return fProcessors.numCoverageFragmentProcessors();
53 }
54 int numFragmentProcessors() const { return fProcessors.numFragmentProcessors(); }
egdaniel378092f2014-12-03 10:40:13 -080055
bsalomonac856c92015-08-27 06:30:17 -070056 const GrFragmentProcessor* getColorFragmentProcessor(int idx) const {
Brian Salomon92ce5942017-01-18 11:01:10 -050057 return fProcessors.colorFragmentProcessor(idx);
bsalomonac856c92015-08-27 06:30:17 -070058 }
59 const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const {
Brian Salomon92ce5942017-01-18 11:01:10 -050060 return fProcessors.coverageFragmentProcessor(idx);
61 }
62
Brian Salomon5298dc82017-02-22 11:52:03 -050063 const GrProcessorSet& processors() const { return fProcessors; }
skia.committer@gmail.com01c34ee2013-03-20 07:01:02 +000064
Brian Salomon48d1b4c2017-04-08 07:38:53 -040065 GrProcessorSet::Analysis finalizeProcessors(const GrProcessorAnalysisColor& colorInput,
66 const GrProcessorAnalysisCoverage coverageInput,
67 const GrAppliedClip* clip, bool isMixedSamples,
68 const GrCaps& caps, GrColor* overrideColor) {
69 return fProcessors.finalize(colorInput, coverageInput, clip, isMixedSamples, caps,
70 overrideColor);
Brian Salomone14bd802017-04-04 15:13:25 -040071 }
72
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(); }
egdaniel89af44a2014-09-26 06:15:04 -070081
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000082 /**
cdalton93a379b2016-05-11 13:58:08 -070083 * Sets the user stencil settings for the next draw.
84 * This class only stores pointers to stencil settings objects.
85 * The caller guarantees the pointer will remain valid until it
86 * changes or goes out of scope.
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000087 * @param settings the stencil settings to use.
88 */
cdalton93a379b2016-05-11 13:58:08 -070089 void setUserStencil(const GrUserStencilSettings* settings) { fUserStencilSettings = settings; }
bsalomon6be6f7c2015-02-26 13:05:21 -080090
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000091 /// @}
92
93 ///////////////////////////////////////////////////////////////////////////
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000094 /// @name State Flags
95 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +000096
Brian Salomon189098e72017-01-19 09:55:19 -050097 bool isHWAntialias() const { return SkToBool(fFlags & GrPipeline::kHWAntialias_Flag); }
egdaniel89af44a2014-09-26 06:15:04 -070098
Brian Salomon189098e72017-01-19 09:55:19 -050099 void setSnapVerticesToPixelCenters(bool enable) {
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000100 if (enable) {
Brian Salomon189098e72017-01-19 09:55:19 -0500101 fFlags |= GrPipeline::kSnapVerticesToPixelCenters_Flag;
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000102 } else {
Brian Salomon189098e72017-01-19 09:55:19 -0500103 fFlags &= ~GrPipeline::kSnapVerticesToPixelCenters_Flag;
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +0000104 }
105 }
106
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000107 /// @}
108
Brian Salomonb5cb6832017-02-24 11:01:15 -0500109 void getPipelineInitArgs(GrPipeline::InitArgs* args) const {
Brian Salomon189098e72017-01-19 09:55:19 -0500110 args->fFlags = fFlags;
111 args->fUserStencil = fUserStencilSettings;
Brian Salomon189098e72017-01-19 09:55:19 -0500112 args->fProcessors = &fProcessors;
113 }
joshualitt44701df2015-02-23 14:44:57 -0800114
egdaniele36914c2015-02-13 09:00:33 -0800115private:
Brian Salomon92ce5942017-01-18 11:01:10 -0500116 uint32_t fFlags;
Brian Salomon189098e72017-01-19 09:55:19 -0500117 const GrUserStencilSettings* fUserStencilSettings;
Brian Salomon92ce5942017-01-18 11:01:10 -0500118 GrProcessorSet fProcessors;
tomhudson@google.com93813632011-10-27 20:21:16 +0000119};
120
121#endif