tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 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 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 8 | #ifndef GrProcessor_DEFINED |
| 9 | #define GrProcessor_DEFINED |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 10 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 11 | #include "../private/SkAtomics.h" |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 12 | #include "GrBuffer.h" |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 13 | #include "GrColor.h" |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 14 | #include "GrGpuResourceRef.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 15 | #include "GrProcessorUnitTest.h" |
bsalomon | 9574098 | 2014-09-04 13:12:37 -0700 | [diff] [blame] | 16 | #include "GrProgramElement.h" |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 17 | #include "GrSamplerState.h" |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 18 | #include "GrShaderVar.h" |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 19 | #include "GrSurfaceProxyPriv.h" |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 20 | #include "GrTextureProxy.h" |
egdaniel | 9e4d6d1 | 2014-10-15 13:49:02 -0700 | [diff] [blame] | 21 | #include "SkMath.h" |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 22 | #include "SkString.h" |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 23 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 24 | class GrContext; |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 25 | class GrCoordTransform; |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 26 | class GrInvariantOutput; |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 27 | class GrResourceProvider; |
bsalomon | 9574098 | 2014-09-04 13:12:37 -0700 | [diff] [blame] | 28 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Used by processors to build their keys. It incorporates each per-processor key into a larger |
| 31 | * shader key. |
| 32 | */ |
| 33 | class GrProcessorKeyBuilder { |
| 34 | public: |
| 35 | GrProcessorKeyBuilder(SkTArray<unsigned char, true>* data) : fData(data), fCount(0) { |
| 36 | SkASSERT(0 == fData->count() % sizeof(uint32_t)); |
| 37 | } |
| 38 | |
| 39 | void add32(uint32_t v) { |
| 40 | ++fCount; |
| 41 | fData->push_back_n(4, reinterpret_cast<uint8_t*>(&v)); |
| 42 | } |
| 43 | |
| 44 | /** Inserts count uint32_ts into the key. The returned pointer is only valid until the next |
| 45 | add*() call. */ |
| 46 | uint32_t* SK_WARN_UNUSED_RESULT add32n(int count) { |
| 47 | SkASSERT(count > 0); |
| 48 | fCount += count; |
| 49 | return reinterpret_cast<uint32_t*>(fData->push_back_n(4 * count)); |
| 50 | } |
| 51 | |
| 52 | size_t size() const { return sizeof(uint32_t) * fCount; } |
| 53 | |
| 54 | private: |
| 55 | SkTArray<uint8_t, true>* fData; // unowned ptr to the larger key. |
| 56 | int fCount; // number of uint32_ts added to fData by the processor. |
| 57 | }; |
| 58 | |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 59 | /** Provides custom shader code to the Ganesh shading pipeline. GrProcessor objects *must* be |
| 60 | immutable: after being constructed, their fields may not change. |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 61 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 62 | Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an |
mdempsky | 38f1f6f | 2015-08-27 12:57:01 -0700 | [diff] [blame] | 63 | processor must reach 0 before the thread terminates and the pool is destroyed. |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 64 | */ |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 65 | class GrProcessor { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 66 | public: |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 67 | enum ClassID { |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 68 | kBigKeyProcessor_ClassID, |
| 69 | kBlockInputFragmentProcessor_ClassID, |
| 70 | kCircleGeometryProcessor_ClassID, |
| 71 | kCircleInside2PtConicalEffect_ClassID, |
| 72 | kCircleOutside2PtConicalEffect_ClassID, |
| 73 | kCircularRRectEffect_ClassID, |
| 74 | kColorMatrixEffect_ClassID, |
| 75 | kColorTableEffect_ClassID, |
| 76 | kComposeOneFragmentProcessor_ClassID, |
| 77 | kComposeTwoFragmentProcessor_ClassID, |
| 78 | kCoverageSetOpXP_ClassID, |
| 79 | kCustomXP_ClassID, |
| 80 | kDashingCircleEffect_ClassID, |
| 81 | kDashingLineEffect_ClassID, |
| 82 | kDefaultGeoProc_ClassID, |
| 83 | kDIEllipseGeometryProcessor_ClassID, |
| 84 | kDisableColorXP_ClassID, |
| 85 | kEdge2PtConicalEffect_ClassID, |
| 86 | kEllipseGeometryProcessor_ClassID, |
| 87 | kEllipticalRRectEffect_ClassID, |
| 88 | kFocalInside2PtConicalEffect_ClassID, |
| 89 | kFocalOutside2PtConicalEffect_ClassID, |
| 90 | kGP_ClassID, |
Ethan Nicholas | 8dca18a | 2017-11-15 15:33:33 -0500 | [diff] [blame] | 91 | kGrAARectEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 92 | kGrAlphaThresholdFragmentProcessor_ClassID, |
Ethan Nicholas | c9472af | 2017-10-10 16:30:21 -0400 | [diff] [blame] | 93 | kGrArithmeticFP_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 94 | kGrBicubicEffect_ClassID, |
| 95 | kGrBitmapTextGeoProc_ClassID, |
| 96 | kGrBlurredEdgeFragmentProcessor_ClassID, |
| 97 | kGrCCPRCoverageProcessor_ClassID, |
| 98 | kGrCCPRPathProcessor_ClassID, |
| 99 | kGrCircleBlurFragmentProcessor_ClassID, |
| 100 | kGrCircleEffect_ClassID, |
Brian Osman | c4f93ca | 2017-10-17 17:15:52 -0400 | [diff] [blame] | 101 | kGrColorSpaceXformEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 102 | kGrConfigConversionEffect_ClassID, |
| 103 | kGrConicEffect_ClassID, |
| 104 | kGrConstColorProcessor_ClassID, |
| 105 | kGrConvexPolyEffect_ClassID, |
| 106 | kGrCubicEffect_ClassID, |
| 107 | kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID, |
| 108 | kGrDiffuseLightingEffect_ClassID, |
| 109 | kGrDisplacementMapEffect_ClassID, |
| 110 | kGrDistanceFieldA8TextGeoProc_ClassID, |
| 111 | kGrDistanceFieldLCDTextGeoProc_ClassID, |
| 112 | kGrDistanceFieldPathGeoProc_ClassID, |
| 113 | kGrDitherEffect_ClassID, |
| 114 | kGrEllipseEffect_ClassID, |
| 115 | kGrGaussianConvolutionFragmentProcessor_ClassID, |
| 116 | kGrImprovedPerlinNoiseEffect_ClassID, |
| 117 | kGrLightingEffect_ClassID, |
| 118 | kGrLinearGradient_ClassID, |
Ethan Nicholas | 14efcbf | 2017-11-07 09:23:38 -0500 | [diff] [blame] | 119 | kGrLumaColorFilterEffect_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 120 | kGrMagnifierEffect_ClassID, |
| 121 | kGrMatrixConvolutionEffect_ClassID, |
| 122 | kGrMeshTestProcessor_ClassID, |
| 123 | kGrMorphologyEffect_ClassID, |
| 124 | kGrNonlinearColorSpaceXformEffect_ClassID, |
Ethan Nicholas | d608c09 | 2017-10-26 09:30:08 -0400 | [diff] [blame] | 125 | kGrOverdrawFragmentProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 126 | kGrPathProcessor_ClassID, |
| 127 | kGrPerlinNoise2Effect_ClassID, |
| 128 | kGrPipelineDynamicStateTestProcessor_ClassID, |
Ethan Nicholas | be0a042 | 2017-11-17 13:44:05 -0500 | [diff] [blame^] | 129 | kGrPremulInputFragmentProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 130 | kGrQuadEffect_ClassID, |
| 131 | kGrRadialGradient_ClassID, |
| 132 | kGrRectBlurEffect_ClassID, |
| 133 | kGrRRectBlurEffect_ClassID, |
| 134 | kGrRRectShadowGeoProc_ClassID, |
| 135 | kGrSimpleTextureEffect_ClassID, |
| 136 | kGrSpecularLightingEffect_ClassID, |
| 137 | kGrSRGBEffect_ClassID, |
| 138 | kGrSweepGradient_ClassID, |
| 139 | kGrTextureDomainEffect_ClassID, |
Ethan Nicholas | be0a042 | 2017-11-17 13:44:05 -0500 | [diff] [blame^] | 140 | kGrUnpremulInputFragmentProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 141 | kHighContrastFilterEffect_ClassID, |
| 142 | kInstanceProcessor_ClassID, |
| 143 | kLumaColorFilterEffect_ClassID, |
| 144 | kMSAAQuadProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 145 | kPDLCDXferProcessor_ClassID, |
| 146 | kPorterDuffXferProcessor_ClassID, |
| 147 | kPremulFragmentProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 148 | kQuadEdgeEffect_ClassID, |
| 149 | kReplaceInputFragmentProcessor_ClassID, |
| 150 | kRRectsGaussianEdgeFP_ClassID, |
| 151 | kSeriesFragmentProcessor_ClassID, |
| 152 | kShaderPDXferProcessor_ClassID, |
| 153 | kSwizzleFragmentProcessor_ClassID, |
| 154 | kTestFP_ClassID, |
| 155 | kTextureGeometryProcessor_ClassID, |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 156 | kYUVtoRGBEffect_ClassID |
| 157 | }; |
| 158 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 159 | virtual ~GrProcessor() = default; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 160 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 161 | /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader |
| 162 | code. */ |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 163 | virtual const char* name() const = 0; |
bsalomon@google.com | 289efe0 | 2012-05-21 20:57:59 +0000 | [diff] [blame] | 164 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 165 | /** Human-readable dump of all information */ |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 166 | virtual SkString dumpInfo() const { |
| 167 | SkString str; |
| 168 | str.appendf("Missing data"); |
| 169 | return str; |
| 170 | } |
| 171 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 172 | /** |
| 173 | * Platform specific built-in features that a processor can request for the fragment shader. |
| 174 | */ |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 175 | enum RequiredFeatures { |
| 176 | kNone_RequiredFeatures = 0, |
Ethan Nicholas | 3865711 | 2017-02-09 17:01:22 -0500 | [diff] [blame] | 177 | kSampleLocations_RequiredFeature = 1 << 0 |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | GR_DECL_BITFIELD_OPS_FRIENDS(RequiredFeatures); |
| 181 | |
| 182 | RequiredFeatures requiredFeatures() const { return fRequiredFeatures; } |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 183 | |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 184 | void* operator new(size_t size); |
| 185 | void operator delete(void* target); |
| 186 | |
bsalomon@google.com | d42aca3 | 2013-04-23 15:37:27 +0000 | [diff] [blame] | 187 | void* operator new(size_t size, void* placement) { |
| 188 | return ::operator new(size, placement); |
| 189 | } |
| 190 | void operator delete(void* target, void* placement) { |
| 191 | ::operator delete(target, placement); |
| 192 | } |
| 193 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 194 | /** Helper for down-casting to a GrProcessor subclass */ |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 195 | template <typename T> const T& cast() const { return *static_cast<const T*>(this); } |
| 196 | |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 197 | ClassID classID() const { return fClassID; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 198 | |
bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 199 | protected: |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 200 | GrProcessor(ClassID classID) |
| 201 | : fClassID(classID) |
| 202 | , fRequiredFeatures(kNone_RequiredFeatures) {} |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame] | 203 | |
bsalomon@google.com | 50db75c | 2013-01-11 13:54:30 +0000 | [diff] [blame] | 204 | /** |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 205 | * If the prcoessor will generate code that uses platform specific built-in features, then it |
| 206 | * must call these methods from its constructor. Otherwise, requests to use these features will |
| 207 | * be denied. |
commit-bot@chromium.org | 8d47ddc | 2013-05-09 14:55:46 +0000 | [diff] [blame] | 208 | */ |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 209 | void setWillUseSampleLocations() { fRequiredFeatures |= kSampleLocations_RequiredFeature; } |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 210 | |
| 211 | void combineRequiredFeatures(const GrProcessor& other) { |
| 212 | fRequiredFeatures |= other.fRequiredFeatures; |
| 213 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 214 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 215 | private: |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 216 | GrProcessor(const GrProcessor&) = delete; |
| 217 | GrProcessor& operator=(const GrProcessor&) = delete; |
| 218 | |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 219 | ClassID fClassID; |
| 220 | RequiredFeatures fRequiredFeatures; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
cdalton | 8733210 | 2016-02-26 12:22:02 -0800 | [diff] [blame] | 223 | GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures); |
| 224 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 225 | /** A GrProcessor with the ability to access textures, buffers, and image storages. */ |
| 226 | class GrResourceIOProcessor : public GrProcessor { |
| 227 | public: |
| 228 | class TextureSampler; |
| 229 | class BufferAccess; |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 230 | |
| 231 | int numTextureSamplers() const { return fTextureSamplers.count(); } |
| 232 | |
| 233 | /** Returns the access pattern for the texture at index. index must be valid according to |
| 234 | numTextureSamplers(). */ |
| 235 | const TextureSampler& textureSampler(int index) const { return *fTextureSamplers[index]; } |
| 236 | |
| 237 | int numBuffers() const { return fBufferAccesses.count(); } |
| 238 | |
| 239 | /** Returns the access pattern for the buffer at index. index must be valid according to |
| 240 | numBuffers(). */ |
| 241 | const BufferAccess& bufferAccess(int index) const { return *fBufferAccesses[index]; } |
| 242 | |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 243 | bool instantiate(GrResourceProvider* resourceProvider) const; |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 244 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 245 | protected: |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 246 | GrResourceIOProcessor(ClassID classID) |
| 247 | : INHERITED(classID) {} |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 248 | |
| 249 | /** |
Brian Salomon | 559f556 | 2017-11-15 14:28:33 -0500 | [diff] [blame] | 250 | * Subclasses call these from their constructor to register sampler sources. The processor |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 251 | * subclass manages the lifetime of the objects (these functions only store pointers). The |
| 252 | * TextureSampler and/or BufferAccess instances are typically member fields of the GrProcessor |
| 253 | * subclass. These must only be called from the constructor because GrProcessors are immutable. |
| 254 | */ |
| 255 | void addTextureSampler(const TextureSampler*); |
| 256 | void addBufferAccess(const BufferAccess*); |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 257 | |
| 258 | bool hasSameSamplersAndAccesses(const GrResourceIOProcessor&) const; |
| 259 | |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 260 | // These methods can be used by derived classes that also derive from GrProgramElement. |
| 261 | void addPendingIOs() const; |
| 262 | void removeRefs() const; |
| 263 | void pendingIOComplete() const; |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 264 | |
Brian Salomon | d61c9d9 | 2017-04-10 10:54:25 -0400 | [diff] [blame] | 265 | private: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 266 | SkSTArray<4, const TextureSampler*, true> fTextureSamplers; |
| 267 | SkSTArray<1, const BufferAccess*, true> fBufferAccesses; |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 268 | |
| 269 | typedef GrProcessor INHERITED; |
| 270 | }; |
| 271 | |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 272 | /** |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 273 | * Used to represent a texture that is required by a GrResourceIOProcessor. It holds a GrTexture |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 274 | * along with an associated GrSamplerState. TextureSamplers don't perform any coord manipulation to |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 275 | * account for texture origin. |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 276 | */ |
Brian Salomon | ffc2ec4 | 2017-07-25 14:59:03 -0400 | [diff] [blame] | 277 | class GrResourceIOProcessor::TextureSampler { |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 278 | public: |
| 279 | /** |
| 280 | * Must be initialized before adding to a GrProcessor's texture access list. |
| 281 | */ |
| 282 | TextureSampler(); |
Brian Salomon | ffc2ec4 | 2017-07-25 14:59:03 -0400 | [diff] [blame] | 283 | /** |
| 284 | * This copy constructor is used by GrFragmentProcessor::clone() implementations. The copy |
| 285 | * always takes a new ref on the texture proxy as the new fragment processor will not yet be |
| 286 | * in pending execution state. |
| 287 | */ |
| 288 | explicit TextureSampler(const TextureSampler& that) |
| 289 | : fProxyRef(sk_ref_sp(that.fProxyRef.get()), that.fProxyRef.ioType()) |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 290 | , fSamplerState(that.fSamplerState) |
Brian Salomon | ffc2ec4 | 2017-07-25 14:59:03 -0400 | [diff] [blame] | 291 | , fVisibility(that.fVisibility) {} |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 292 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 293 | TextureSampler(sk_sp<GrTextureProxy>, const GrSamplerState&); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 294 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 295 | explicit TextureSampler(sk_sp<GrTextureProxy>, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 296 | GrSamplerState::Filter = GrSamplerState::Filter::kNearest, |
| 297 | GrSamplerState::WrapMode wrapXAndY = GrSamplerState::WrapMode::kClamp, |
Robert Phillips | bc7a4fb | 2017-01-23 15:30:35 -0500 | [diff] [blame] | 298 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 299 | |
| 300 | TextureSampler& operator=(const TextureSampler&) = delete; |
| 301 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 302 | void reset(sk_sp<GrTextureProxy>, const GrSamplerState&, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 303 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 304 | void reset(sk_sp<GrTextureProxy>, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 305 | GrSamplerState::Filter = GrSamplerState::Filter::kNearest, |
| 306 | GrSamplerState::WrapMode wrapXAndY = GrSamplerState::WrapMode::kClamp, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 307 | GrShaderFlags visibility = kFragment_GrShaderFlag); |
| 308 | |
| 309 | bool operator==(const TextureSampler& that) const { |
Robert Phillips | 159e3c6 | 2017-06-19 12:02:00 -0400 | [diff] [blame] | 310 | return this->proxy()->underlyingUniqueID() == that.proxy()->underlyingUniqueID() && |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 311 | fSamplerState == that.fSamplerState && fVisibility == that.fVisibility; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | bool operator!=(const TextureSampler& other) const { return !(*this == other); } |
| 315 | |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 316 | // 'instantiate' should only ever be called at flush time. |
| 317 | bool instantiate(GrResourceProvider* resourceProvider) const { |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 318 | return SkToBool(fProxyRef.get()->instantiate(resourceProvider)); |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | // 'peekTexture' should only ever be called after a successful 'instantiate' call |
| 322 | GrTexture* peekTexture() const { |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 323 | SkASSERT(fProxyRef.get()->priv().peekTexture()); |
| 324 | return fProxyRef.get()->priv().peekTexture(); |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 325 | } |
| 326 | |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 327 | GrTextureProxy* proxy() const { return fProxyRef.get()->asTextureProxy(); } |
Brian Salomon | db4183d | 2016-11-17 12:48:40 -0500 | [diff] [blame] | 328 | GrShaderFlags visibility() const { return fVisibility; } |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 329 | const GrSamplerState& samplerState() const { return fSamplerState; } |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 330 | |
Brian Salomon | 06e547c | 2017-06-09 16:11:32 -0400 | [diff] [blame] | 331 | bool isInitialized() const { return SkToBool(fProxyRef.get()); } |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 332 | /** |
| 333 | * For internal use by GrProcessor. |
| 334 | */ |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 335 | const GrSurfaceProxyRef* programProxy() const { return &fProxyRef; } |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 336 | |
| 337 | private: |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 338 | GrSurfaceProxyRef fProxyRef; |
| 339 | GrSamplerState fSamplerState; |
| 340 | GrShaderFlags fVisibility; |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 341 | }; |
| 342 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 343 | /** |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 344 | * Used to represent a texel buffer that will be read in a GrResourceIOProcessor. It holds a |
| 345 | * GrBuffer along with an associated offset and texel config. |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 346 | */ |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 347 | class GrResourceIOProcessor::BufferAccess { |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 348 | public: |
Brian Salomon | bc6b99d | 2017-01-11 10:32:34 -0500 | [diff] [blame] | 349 | BufferAccess() = default; |
| 350 | BufferAccess(GrPixelConfig texelConfig, GrBuffer* buffer, |
| 351 | GrShaderFlags visibility = kFragment_GrShaderFlag) { |
| 352 | this->reset(texelConfig, buffer, visibility); |
| 353 | } |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 354 | /** |
Brian Salomon | b17e639 | 2017-07-28 13:41:51 -0400 | [diff] [blame] | 355 | * This copy constructor is used by GrFragmentProcessor::clone() implementations. The copy |
| 356 | * always takes a new ref on the buffer proxy as the new fragment processor will not yet be |
| 357 | * in pending execution state. |
| 358 | */ |
| 359 | explicit BufferAccess(const BufferAccess& that) { |
| 360 | this->reset(that.fTexelConfig, that.fBuffer.get(), that.fVisibility); |
| 361 | } |
| 362 | |
| 363 | BufferAccess& operator=(const BufferAccess&) = delete; |
| 364 | |
| 365 | /** |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 366 | * Must be initialized before adding to a GrProcessor's buffer access list. |
| 367 | */ |
| 368 | void reset(GrPixelConfig texelConfig, GrBuffer* buffer, |
| 369 | GrShaderFlags visibility = kFragment_GrShaderFlag) { |
| 370 | fTexelConfig = texelConfig; |
| 371 | fBuffer.set(SkRef(buffer), kRead_GrIOType); |
| 372 | fVisibility = visibility; |
| 373 | } |
| 374 | |
| 375 | bool operator==(const BufferAccess& that) const { |
| 376 | return fTexelConfig == that.fTexelConfig && |
| 377 | this->buffer() == that.buffer() && |
| 378 | fVisibility == that.fVisibility; |
| 379 | } |
| 380 | |
| 381 | bool operator!=(const BufferAccess& that) const { return !(*this == that); } |
| 382 | |
| 383 | GrPixelConfig texelConfig() const { return fTexelConfig; } |
| 384 | GrBuffer* buffer() const { return fBuffer.get(); } |
| 385 | GrShaderFlags visibility() const { return fVisibility; } |
| 386 | |
| 387 | /** |
| 388 | * For internal use by GrProcessor. |
| 389 | */ |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 390 | const GrGpuResourceRef* programBuffer() const { return &fBuffer;} |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 391 | |
| 392 | private: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 393 | GrPixelConfig fTexelConfig; |
| 394 | GrTGpuResourceRef<GrBuffer> fBuffer; |
| 395 | GrShaderFlags fVisibility; |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 396 | |
| 397 | typedef SkNoncopyable INHERITED; |
| 398 | }; |
| 399 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 400 | #endif |