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