blob: 69372b1ca7da489bdb39fdfe4177bbdbfbe8df4f [file] [log] [blame]
tomhudson@google.com168e6342012-04-18 17:49:20 +00001/*
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
joshualittb0a8a372014-09-23 09:50:21 -07008#ifndef GrProcessor_DEFINED
9#define GrProcessor_DEFINED
tomhudson@google.com168e6342012-04-18 17:49:20 +000010
Brian Salomon0c26a9d2017-07-06 10:09:38 -040011#include "../private/SkAtomics.h"
Brian Salomonb014cca2016-11-18 11:39:15 -050012#include "GrBuffer.h"
Brian Salomon0c26a9d2017-07-06 10:09:38 -040013#include "GrColor.h"
Brian Salomonb014cca2016-11-18 11:39:15 -050014#include "GrGpuResourceRef.h"
joshualittb0a8a372014-09-23 09:50:21 -070015#include "GrProcessorUnitTest.h"
bsalomon95740982014-09-04 13:12:37 -070016#include "GrProgramElement.h"
Brian Salomon2bbdcc42017-09-07 12:36:34 -040017#include "GrSamplerState.h"
Brian Salomonf9f45122016-11-29 11:59:17 -050018#include "GrShaderVar.h"
Robert Phillips8a02f652017-05-12 14:49:16 -040019#include "GrSurfaceProxyPriv.h"
Brian Salomon0c26a9d2017-07-06 10:09:38 -040020#include "GrTextureProxy.h"
egdaniel9e4d6d12014-10-15 13:49:02 -070021#include "SkMath.h"
robertphillipse004bfc2015-11-16 09:06:59 -080022#include "SkString.h"
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000023
tomhudson@google.com168e6342012-04-18 17:49:20 +000024class GrContext;
bsalomon@google.com77af6802013-10-02 13:04:56 +000025class GrCoordTransform;
egdaniel605dd0f2014-11-12 08:35:25 -080026class GrInvariantOutput;
Brian Osman32342f02017-03-04 08:12:46 -050027class GrResourceProvider;
bsalomon95740982014-09-04 13:12:37 -070028
joshualitteb2a6762014-12-04 11:35:33 -080029/**
30 * Used by processors to build their keys. It incorporates each per-processor key into a larger
31 * shader key.
32 */
33class GrProcessorKeyBuilder {
34public:
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
54private:
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
bsalomon98b33eb2014-10-15 11:05:26 -070059/** 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.com0ac6af42013-01-16 15:16:18 +000061
joshualittb0a8a372014-09-23 09:50:21 -070062 Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
mdempsky38f1f6f2015-08-27 12:57:01 -070063 processor must reach 0 before the thread terminates and the pool is destroyed.
bsalomon98b33eb2014-10-15 11:05:26 -070064 */
Brian Salomond61c9d92017-04-10 10:54:25 -040065class GrProcessor {
tomhudson@google.com168e6342012-04-18 17:49:20 +000066public:
Ethan Nicholasabff9562017-10-09 10:54:08 -040067 enum ClassID {
Ethan Nicholasabff9562017-10-09 10:54:08 -040068 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 Nicholas8dca18a2017-11-15 15:33:33 -050091 kGrAARectEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040092 kGrAlphaThresholdFragmentProcessor_ClassID,
Ethan Nicholasc9472af2017-10-10 16:30:21 -040093 kGrArithmeticFP_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -040094 kGrBicubicEffect_ClassID,
95 kGrBitmapTextGeoProc_ClassID,
96 kGrBlurredEdgeFragmentProcessor_ClassID,
97 kGrCCPRCoverageProcessor_ClassID,
98 kGrCCPRPathProcessor_ClassID,
99 kGrCircleBlurFragmentProcessor_ClassID,
100 kGrCircleEffect_ClassID,
Brian Osmanc4f93ca2017-10-17 17:15:52 -0400101 kGrColorSpaceXformEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400102 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 Nicholas14efcbf2017-11-07 09:23:38 -0500119 kGrLumaColorFilterEffect_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400120 kGrMagnifierEffect_ClassID,
121 kGrMatrixConvolutionEffect_ClassID,
122 kGrMeshTestProcessor_ClassID,
123 kGrMorphologyEffect_ClassID,
124 kGrNonlinearColorSpaceXformEffect_ClassID,
Ethan Nicholasd608c092017-10-26 09:30:08 -0400125 kGrOverdrawFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400126 kGrPathProcessor_ClassID,
127 kGrPerlinNoise2Effect_ClassID,
128 kGrPipelineDynamicStateTestProcessor_ClassID,
Ethan Nicholasbe0a0422017-11-17 13:44:05 -0500129 kGrPremulInputFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400130 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 Nicholasbe0a0422017-11-17 13:44:05 -0500140 kGrUnpremulInputFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400141 kHighContrastFilterEffect_ClassID,
142 kInstanceProcessor_ClassID,
143 kLumaColorFilterEffect_ClassID,
144 kMSAAQuadProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400145 kPDLCDXferProcessor_ClassID,
146 kPorterDuffXferProcessor_ClassID,
147 kPremulFragmentProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400148 kQuadEdgeEffect_ClassID,
149 kReplaceInputFragmentProcessor_ClassID,
150 kRRectsGaussianEdgeFP_ClassID,
151 kSeriesFragmentProcessor_ClassID,
152 kShaderPDXferProcessor_ClassID,
153 kSwizzleFragmentProcessor_ClassID,
154 kTestFP_ClassID,
155 kTextureGeometryProcessor_ClassID,
Ethan Nicholasabff9562017-10-09 10:54:08 -0400156 kYUVtoRGBEffect_ClassID
157 };
158
Brian Salomonab015ef2017-04-04 10:15:51 -0400159 virtual ~GrProcessor() = default;
tomhudson@google.com168e6342012-04-18 17:49:20 +0000160
Brian Salomonb014cca2016-11-18 11:39:15 -0500161 /** Human-meaningful string to identify this prcoessor; may be embedded in generated shader
162 code. */
joshualitteb2a6762014-12-04 11:35:33 -0800163 virtual const char* name() const = 0;
bsalomon@google.com289efe02012-05-21 20:57:59 +0000164
Brian Salomonb014cca2016-11-18 11:39:15 -0500165 /** Human-readable dump of all information */
robertphillipse004bfc2015-11-16 09:06:59 -0800166 virtual SkString dumpInfo() const {
167 SkString str;
168 str.appendf("Missing data");
169 return str;
170 }
171
Brian Salomonf9f45122016-11-29 11:59:17 -0500172 /**
173 * Platform specific built-in features that a processor can request for the fragment shader.
174 */
cdalton87332102016-02-26 12:22:02 -0800175 enum RequiredFeatures {
176 kNone_RequiredFeatures = 0,
Ethan Nicholas38657112017-02-09 17:01:22 -0500177 kSampleLocations_RequiredFeature = 1 << 0
cdalton87332102016-02-26 12:22:02 -0800178 };
179
180 GR_DECL_BITFIELD_OPS_FRIENDS(RequiredFeatures);
181
182 RequiredFeatures requiredFeatures() const { return fRequiredFeatures; }
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000183
tomhudson@google.comdcba4c22012-07-24 21:36:16 +0000184 void* operator new(size_t size);
185 void operator delete(void* target);
186
bsalomon@google.comd42aca32013-04-23 15:37:27 +0000187 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 Salomonb014cca2016-11-18 11:39:15 -0500194 /** Helper for down-casting to a GrProcessor subclass */
joshualitt49586be2014-09-16 08:21:41 -0700195 template <typename T> const T& cast() const { return *static_cast<const T*>(this); }
196
Ethan Nicholasabff9562017-10-09 10:54:08 -0400197 ClassID classID() const { return fClassID; }
joshualitteb2a6762014-12-04 11:35:33 -0800198
bsalomon@google.com50db75c2013-01-11 13:54:30 +0000199protected:
Ethan Nicholasabff9562017-10-09 10:54:08 -0400200 GrProcessor(ClassID classID)
201 : fClassID(classID)
202 , fRequiredFeatures(kNone_RequiredFeatures) {}
bsalomon420d7e92014-10-16 09:18:09 -0700203
bsalomon@google.com50db75c2013-01-11 13:54:30 +0000204 /**
cdalton28f45b92016-03-07 13:58:26 -0800205 * 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.org8d47ddc2013-05-09 14:55:46 +0000208 */
cdalton28f45b92016-03-07 13:58:26 -0800209 void setWillUseSampleLocations() { fRequiredFeatures |= kSampleLocations_RequiredFeature; }
cdalton87332102016-02-26 12:22:02 -0800210
211 void combineRequiredFeatures(const GrProcessor& other) {
212 fRequiredFeatures |= other.fRequiredFeatures;
213 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000214
bsalomon0e08fc12014-10-15 08:19:04 -0700215private:
Brian Salomond61c9d92017-04-10 10:54:25 -0400216 GrProcessor(const GrProcessor&) = delete;
217 GrProcessor& operator=(const GrProcessor&) = delete;
218
Ethan Nicholasabff9562017-10-09 10:54:08 -0400219 ClassID fClassID;
220 RequiredFeatures fRequiredFeatures;
tomhudson@google.com168e6342012-04-18 17:49:20 +0000221};
222
cdalton87332102016-02-26 12:22:02 -0800223GR_MAKE_BITFIELD_OPS(GrProcessor::RequiredFeatures);
224
Brian Salomonab015ef2017-04-04 10:15:51 -0400225/** A GrProcessor with the ability to access textures, buffers, and image storages. */
226class GrResourceIOProcessor : public GrProcessor {
227public:
228 class TextureSampler;
229 class BufferAccess;
Brian Salomonab015ef2017-04-04 10:15:51 -0400230
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 Phillips9bee2e52017-05-29 12:37:20 -0400243 bool instantiate(GrResourceProvider* resourceProvider) const;
Robert Phillipsa91e0b72017-05-01 13:12:20 -0400244
Brian Salomonab015ef2017-04-04 10:15:51 -0400245protected:
Ethan Nicholasabff9562017-10-09 10:54:08 -0400246 GrResourceIOProcessor(ClassID classID)
247 : INHERITED(classID) {}
Brian Salomonab015ef2017-04-04 10:15:51 -0400248
249 /**
Brian Salomon559f5562017-11-15 14:28:33 -0500250 * Subclasses call these from their constructor to register sampler sources. The processor
Brian Salomonab015ef2017-04-04 10:15:51 -0400251 * 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 Salomonab015ef2017-04-04 10:15:51 -0400257
258 bool hasSameSamplersAndAccesses(const GrResourceIOProcessor&) const;
259
Brian Salomond61c9d92017-04-10 10:54:25 -0400260 // 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 Salomonab015ef2017-04-04 10:15:51 -0400264
Brian Salomond61c9d92017-04-10 10:54:25 -0400265private:
Brian Salomonab015ef2017-04-04 10:15:51 -0400266 SkSTArray<4, const TextureSampler*, true> fTextureSamplers;
267 SkSTArray<1, const BufferAccess*, true> fBufferAccesses;
Brian Salomonab015ef2017-04-04 10:15:51 -0400268
269 typedef GrProcessor INHERITED;
270};
271
Brian Salomon0bbecb22016-11-17 11:38:22 -0500272/**
Brian Salomonab015ef2017-04-04 10:15:51 -0400273 * Used to represent a texture that is required by a GrResourceIOProcessor. It holds a GrTexture
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400274 * along with an associated GrSamplerState. TextureSamplers don't perform any coord manipulation to
Brian Salomonab015ef2017-04-04 10:15:51 -0400275 * account for texture origin.
Brian Salomon0bbecb22016-11-17 11:38:22 -0500276 */
Brian Salomonffc2ec42017-07-25 14:59:03 -0400277class GrResourceIOProcessor::TextureSampler {
Brian Salomon0bbecb22016-11-17 11:38:22 -0500278public:
279 /**
280 * Must be initialized before adding to a GrProcessor's texture access list.
281 */
282 TextureSampler();
Brian Salomonffc2ec42017-07-25 14:59:03 -0400283 /**
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 Salomon2bbdcc42017-09-07 12:36:34 -0400290 , fSamplerState(that.fSamplerState)
Brian Salomonffc2ec42017-07-25 14:59:03 -0400291 , fVisibility(that.fVisibility) {}
Brian Salomon0bbecb22016-11-17 11:38:22 -0500292
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400293 TextureSampler(sk_sp<GrTextureProxy>, const GrSamplerState&);
Brian Salomonb17e6392017-07-28 13:41:51 -0400294
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400295 explicit TextureSampler(sk_sp<GrTextureProxy>,
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400296 GrSamplerState::Filter = GrSamplerState::Filter::kNearest,
297 GrSamplerState::WrapMode wrapXAndY = GrSamplerState::WrapMode::kClamp,
Robert Phillipsbc7a4fb2017-01-23 15:30:35 -0500298 GrShaderFlags visibility = kFragment_GrShaderFlag);
Brian Salomonb17e6392017-07-28 13:41:51 -0400299
300 TextureSampler& operator=(const TextureSampler&) = delete;
301
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400302 void reset(sk_sp<GrTextureProxy>, const GrSamplerState&,
Brian Salomon0bbecb22016-11-17 11:38:22 -0500303 GrShaderFlags visibility = kFragment_GrShaderFlag);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -0400304 void reset(sk_sp<GrTextureProxy>,
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400305 GrSamplerState::Filter = GrSamplerState::Filter::kNearest,
306 GrSamplerState::WrapMode wrapXAndY = GrSamplerState::WrapMode::kClamp,
Brian Salomon0bbecb22016-11-17 11:38:22 -0500307 GrShaderFlags visibility = kFragment_GrShaderFlag);
308
309 bool operator==(const TextureSampler& that) const {
Robert Phillips159e3c62017-06-19 12:02:00 -0400310 return this->proxy()->underlyingUniqueID() == that.proxy()->underlyingUniqueID() &&
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400311 fSamplerState == that.fSamplerState && fVisibility == that.fVisibility;
Brian Salomon0bbecb22016-11-17 11:38:22 -0500312 }
313
314 bool operator!=(const TextureSampler& other) const { return !(*this == other); }
315
Robert Phillips9bee2e52017-05-29 12:37:20 -0400316 // 'instantiate' should only ever be called at flush time.
317 bool instantiate(GrResourceProvider* resourceProvider) const {
Robert Phillips18166ee2017-06-01 12:55:44 -0400318 return SkToBool(fProxyRef.get()->instantiate(resourceProvider));
Robert Phillips9bee2e52017-05-29 12:37:20 -0400319 }
320
321 // 'peekTexture' should only ever be called after a successful 'instantiate' call
322 GrTexture* peekTexture() const {
Robert Phillips18166ee2017-06-01 12:55:44 -0400323 SkASSERT(fProxyRef.get()->priv().peekTexture());
324 return fProxyRef.get()->priv().peekTexture();
Robert Phillips9bee2e52017-05-29 12:37:20 -0400325 }
326
Robert Phillips18166ee2017-06-01 12:55:44 -0400327 GrTextureProxy* proxy() const { return fProxyRef.get()->asTextureProxy(); }
Brian Salomondb4183d2016-11-17 12:48:40 -0500328 GrShaderFlags visibility() const { return fVisibility; }
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400329 const GrSamplerState& samplerState() const { return fSamplerState; }
Brian Salomon0bbecb22016-11-17 11:38:22 -0500330
Brian Salomon06e547c2017-06-09 16:11:32 -0400331 bool isInitialized() const { return SkToBool(fProxyRef.get()); }
Brian Salomon0bbecb22016-11-17 11:38:22 -0500332 /**
333 * For internal use by GrProcessor.
334 */
Robert Phillips18166ee2017-06-01 12:55:44 -0400335 const GrSurfaceProxyRef* programProxy() const { return &fProxyRef; }
Brian Salomon0bbecb22016-11-17 11:38:22 -0500336
337private:
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400338 GrSurfaceProxyRef fProxyRef;
339 GrSamplerState fSamplerState;
340 GrShaderFlags fVisibility;
Brian Salomon0bbecb22016-11-17 11:38:22 -0500341};
342
Brian Salomonb014cca2016-11-18 11:39:15 -0500343/**
Brian Salomonab015ef2017-04-04 10:15:51 -0400344 * 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 Salomonb014cca2016-11-18 11:39:15 -0500346 */
Brian Salomonb17e6392017-07-28 13:41:51 -0400347class GrResourceIOProcessor::BufferAccess {
Brian Salomonb014cca2016-11-18 11:39:15 -0500348public:
Brian Salomonbc6b99d2017-01-11 10:32:34 -0500349 BufferAccess() = default;
350 BufferAccess(GrPixelConfig texelConfig, GrBuffer* buffer,
351 GrShaderFlags visibility = kFragment_GrShaderFlag) {
352 this->reset(texelConfig, buffer, visibility);
353 }
Brian Salomonb014cca2016-11-18 11:39:15 -0500354 /**
Brian Salomonb17e6392017-07-28 13:41:51 -0400355 * 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 Salomonb014cca2016-11-18 11:39:15 -0500366 * 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 Salomonf9f45122016-11-29 11:59:17 -0500390 const GrGpuResourceRef* programBuffer() const { return &fBuffer;}
Brian Salomonb014cca2016-11-18 11:39:15 -0500391
392private:
Brian Salomonab015ef2017-04-04 10:15:51 -0400393 GrPixelConfig fTexelConfig;
394 GrTGpuResourceRef<GrBuffer> fBuffer;
395 GrShaderFlags fVisibility;
Brian Salomonb014cca2016-11-18 11:39:15 -0500396
397 typedef SkNoncopyable INHERITED;
398};
399
tomhudson@google.com168e6342012-04-18 17:49:20 +0000400#endif