tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1 | /* |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2 | * Copyright 2015 Google Inc. |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 8 | #ifndef GrPipelineBuilder_DEFINED |
| 9 | #define GrPipelineBuilder_DEFINED |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 10 | |
bsalomon | f96ba02 | 2014-09-17 08:05:40 -0700 | [diff] [blame] | 11 | #include "GrGpuResourceRef.h" |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 12 | #include "GrPipeline.h" |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 13 | #include "GrProcessorSet.h" |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 14 | #include "GrRenderTarget.h" |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 15 | #include "GrUserStencilSettings.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 16 | #include "GrXferProcessor.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 17 | |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 18 | class GrCaps; |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 19 | class GrDrawOp; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 20 | class GrPaint; |
| 21 | class GrTexture; |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 22 | |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 23 | class GrPipelineBuilder : private SkNoncopyable { |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 24 | public: |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 25 | /** |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 26 | * Initializes the GrPipelineBuilder based on a GrPaint and MSAA availability. Note |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 27 | * 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.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 30 | */ |
Brian Salomon | d2743ea | 2017-02-21 16:54:27 -0500 | [diff] [blame] | 31 | GrPipelineBuilder(GrPaint&& paint, GrAAType aaType) |
Brian Salomon | 611572c | 2017-04-28 08:57:12 -0400 | [diff] [blame] | 32 | : fFlags(GrPipeline::SRGBFlagsFromPaint(paint)) |
Brian Salomon | d2743ea | 2017-02-21 16:54:27 -0500 | [diff] [blame] | 33 | , fUserStencilSettings(&GrUserStencilSettings::kUnused) |
| 34 | , fProcessors(std::move(paint)) { |
| 35 | if (GrAATypeIsHW(aaType)) { |
| 36 | fFlags |= GrPipeline::kHWAntialias_Flag; |
| 37 | } |
| 38 | } |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 39 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 40 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 41 | /// @name Fragment Processors |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 42 | /// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 43 | /// 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.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 48 | //// |
| 49 | |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 50 | int numColorFragmentProcessors() const { return fProcessors.numColorFragmentProcessors(); } |
| 51 | int numCoverageFragmentProcessors() const { |
| 52 | return fProcessors.numCoverageFragmentProcessors(); |
| 53 | } |
| 54 | int numFragmentProcessors() const { return fProcessors.numFragmentProcessors(); } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 55 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 56 | const GrFragmentProcessor* getColorFragmentProcessor(int idx) const { |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 57 | return fProcessors.colorFragmentProcessor(idx); |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 58 | } |
| 59 | const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const { |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 60 | return fProcessors.coverageFragmentProcessor(idx); |
| 61 | } |
| 62 | |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 63 | const GrProcessorSet& processors() const { return fProcessors; } |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 64 | |
Brian Salomon | 48d1b4c | 2017-04-08 07:38:53 -0400 | [diff] [blame] | 65 | 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 Salomon | e14bd80 | 2017-04-04 15:13:25 -0400 | [diff] [blame] | 71 | } |
| 72 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 73 | /// @} |
| 74 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 75 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 76 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 77 | /// @name Stencil |
| 78 | //// |
| 79 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 80 | bool hasUserStencilSettings() const { return !fUserStencilSettings->isUnused(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 81 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 82 | /** |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 83 | * 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.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 87 | * @param settings the stencil settings to use. |
| 88 | */ |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 89 | void setUserStencil(const GrUserStencilSettings* settings) { fUserStencilSettings = settings; } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 90 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 91 | /// @} |
| 92 | |
| 93 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 94 | /// @name State Flags |
| 95 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 96 | |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 97 | bool isHWAntialias() const { return SkToBool(fFlags & GrPipeline::kHWAntialias_Flag); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 98 | |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 99 | void setSnapVerticesToPixelCenters(bool enable) { |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 100 | if (enable) { |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 101 | fFlags |= GrPipeline::kSnapVerticesToPixelCenters_Flag; |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 102 | } else { |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 103 | fFlags &= ~GrPipeline::kSnapVerticesToPixelCenters_Flag; |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 107 | /// @} |
| 108 | |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 109 | void getPipelineInitArgs(GrPipeline::InitArgs* args) const { |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 110 | args->fFlags = fFlags; |
| 111 | args->fUserStencil = fUserStencilSettings; |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 112 | args->fProcessors = &fProcessors; |
| 113 | } |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 114 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 115 | private: |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 116 | uint32_t fFlags; |
Brian Salomon | 189098e7 | 2017-01-19 09:55:19 -0500 | [diff] [blame] | 117 | const GrUserStencilSettings* fUserStencilSettings; |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 118 | GrProcessorSet fProcessors; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | #endif |