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 | #include "GrProcessor.h" |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 9 | #include "GrContext.h" |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 10 | #include "GrGeometryProcessor.h" |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 11 | #include "GrMemoryPool.h" |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 12 | #include "GrSamplerParams.h" |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 13 | #include "GrTexturePriv.h" |
Robert Phillips | bc7a4fb | 2017-01-23 15:30:35 -0500 | [diff] [blame] | 14 | #include "GrTextureProxy.h" |
egdaniel | 915187b | 2014-12-05 12:58:28 -0800 | [diff] [blame] | 15 | #include "GrXferProcessor.h" |
joshualitt | 23ac62c | 2015-03-30 09:53:47 -0700 | [diff] [blame] | 16 | #include "SkSpinlock.h" |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 17 | |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 18 | #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 19 | #if GR_TEST_UTILS |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 20 | class GrFragmentProcessor; |
| 21 | class GrGeometryProcessor; |
| 22 | |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 23 | /* |
| 24 | * Originally these were both in the processor unit test header, but then it seemed to cause linker |
| 25 | * problems on android. |
| 26 | */ |
| 27 | template<> |
| 28 | SkTArray<GrProcessorTestFactory<GrFragmentProcessor>*, true>* |
| 29 | GrProcessorTestFactory<GrFragmentProcessor>::GetFactories() { |
| 30 | static SkTArray<GrProcessorTestFactory<GrFragmentProcessor>*, true> gFactories; |
| 31 | return &gFactories; |
| 32 | } |
| 33 | |
| 34 | template<> |
Brian Salomon | 003312a | 2017-01-09 16:00:33 +0000 | [diff] [blame] | 35 | SkTArray<GrProcessorTestFactory<GrGeometryProcessor>*, true>* |
| 36 | GrProcessorTestFactory<GrGeometryProcessor>::GetFactories() { |
| 37 | static SkTArray<GrProcessorTestFactory<GrGeometryProcessor>*, true> gFactories; |
Brian Salomon | a8f80de | 2017-01-07 09:37:13 -0500 | [diff] [blame] | 38 | return &gFactories; |
| 39 | } |
| 40 | |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 41 | SkTArray<GrXPFactoryTestFactory*, true>* GrXPFactoryTestFactory::GetFactories() { |
| 42 | static SkTArray<GrXPFactoryTestFactory*, true> gFactories; |
| 43 | return &gFactories; |
| 44 | } |
| 45 | |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 46 | /* |
| 47 | * To ensure we always have successful static initialization, before creating from the factories |
| 48 | * we verify the count is as expected. If a new factory is added, then these numbers must be |
| 49 | * manually adjusted. |
| 50 | */ |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 51 | static const int kFPFactoryCount = 40; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 52 | static const int kGPFactoryCount = 14; |
Brian Salomon | 1c4717b | 2017-01-06 12:54:58 -0500 | [diff] [blame] | 53 | static const int kXPFactoryCount = 4; |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 54 | |
| 55 | template<> |
| 56 | void GrProcessorTestFactory<GrFragmentProcessor>::VerifyFactoryCount() { |
| 57 | if (kFPFactoryCount != GetFactories()->count()) { |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 58 | SkDebugf("\nExpected %d fragment processor factories, found %d.\n", |
| 59 | kFPFactoryCount, GetFactories()->count()); |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 60 | SkFAIL("Wrong number of fragment processor factories!"); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | template<> |
| 65 | void GrProcessorTestFactory<GrGeometryProcessor>::VerifyFactoryCount() { |
| 66 | if (kGPFactoryCount != GetFactories()->count()) { |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 67 | SkDebugf("\nExpected %d geometry processor factories, found %d.\n", |
| 68 | kGPFactoryCount, GetFactories()->count()); |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 69 | SkFAIL("Wrong number of geometry processor factories!"); |
| 70 | } |
| 71 | } |
| 72 | |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 73 | void GrXPFactoryTestFactory::VerifyFactoryCount() { |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 74 | if (kXPFactoryCount != GetFactories()->count()) { |
Ben Wagner | c03e1c5 | 2016-10-17 15:20:02 -0400 | [diff] [blame] | 75 | SkDebugf("\nExpected %d xp factory factories, found %d.\n", |
| 76 | kXPFactoryCount, GetFactories()->count()); |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 77 | SkFAIL("Wrong number of xp factory factories!"); |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 81 | #endif |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 82 | #endif |
joshualitt | 9e87fa7 | 2014-10-09 13:12:35 -0700 | [diff] [blame] | 83 | |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 84 | |
joshualitt | 23ac62c | 2015-03-30 09:53:47 -0700 | [diff] [blame] | 85 | // We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on |
| 86 | // different threads. The GrContext is not used concurrently on different threads and there is a |
| 87 | // memory barrier between accesses of a context on different threads. Also, there may be multiple |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 88 | // GrContexts and those contexts may be in use concurrently on different threads. |
| 89 | namespace { |
mtklein | 15923c9 | 2016-02-29 10:14:38 -0800 | [diff] [blame] | 90 | static SkSpinlock gProcessorSpinlock; |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 91 | class MemoryPoolAccessor { |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 92 | public: |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 93 | |
msarett | 68440f8 | 2016-08-29 14:52:24 -0700 | [diff] [blame] | 94 | // We know in the Android framework there is only one GrContext. |
| 95 | #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
| 96 | MemoryPoolAccessor() {} |
| 97 | ~MemoryPoolAccessor() {} |
| 98 | #else |
| 99 | MemoryPoolAccessor() { gProcessorSpinlock.acquire(); } |
joshualitt | 23ac62c | 2015-03-30 09:53:47 -0700 | [diff] [blame] | 100 | ~MemoryPoolAccessor() { gProcessorSpinlock.release(); } |
msarett | 68440f8 | 2016-08-29 14:52:24 -0700 | [diff] [blame] | 101 | #endif |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 102 | |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 103 | GrMemoryPool* pool() const { |
| 104 | static GrMemoryPool gPool(4096, 4096); |
| 105 | return &gPool; |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 106 | } |
| 107 | }; |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 108 | } |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 109 | |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 110 | int32_t GrProcessor::gCurrProcessorClassID = GrProcessor::kIllegalProcessorClassID; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 111 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 112 | /////////////////////////////////////////////////////////////////////////////// |
| 113 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 114 | GrProcessor::~GrProcessor() {} |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 115 | |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 116 | void GrProcessor::addTextureSampler(const TextureSampler* access) { |
| 117 | fTextureSamplers.push_back(access); |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Brian Salomon | b014cca | 2016-11-18 11:39:15 -0500 | [diff] [blame] | 120 | void GrProcessor::addBufferAccess(const BufferAccess* access) { |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 121 | fBufferAccesses.push_back(access); |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void GrProcessor::addImageStorageAccess(const ImageStorageAccess* access) { |
| 125 | fImageStorageAccesses.push_back(access); |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void GrProcessor::addPendingIOs() const { |
| 129 | for (const auto& sampler : fTextureSamplers) { |
| 130 | sampler->programTexture()->markPendingIO(); |
| 131 | } |
| 132 | for (const auto& buffer : fBufferAccesses) { |
| 133 | buffer->programBuffer()->markPendingIO(); |
| 134 | } |
| 135 | for (const auto& imageStorage : fImageStorageAccesses) { |
| 136 | imageStorage->programTexture()->markPendingIO(); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | void GrProcessor::removeRefs() const { |
| 141 | for (const auto& sampler : fTextureSamplers) { |
| 142 | sampler->programTexture()->removeRef(); |
| 143 | } |
| 144 | for (const auto& buffer : fBufferAccesses) { |
| 145 | buffer->programBuffer()->removeRef(); |
| 146 | } |
| 147 | for (const auto& imageStorage : fImageStorageAccesses) { |
| 148 | imageStorage->programTexture()->removeRef(); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void GrProcessor::pendingIOComplete() const { |
| 153 | for (const auto& sampler : fTextureSamplers) { |
| 154 | sampler->programTexture()->pendingIOComplete(); |
| 155 | } |
| 156 | for (const auto& buffer : fBufferAccesses) { |
| 157 | buffer->programBuffer()->pendingIOComplete(); |
| 158 | } |
| 159 | for (const auto& imageStorage : fImageStorageAccesses) { |
| 160 | imageStorage->programTexture()->pendingIOComplete(); |
| 161 | } |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 162 | } |
| 163 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 164 | void* GrProcessor::operator new(size_t size) { |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 165 | return MemoryPoolAccessor().pool()->allocate(size); |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 166 | } |
| 167 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 168 | void GrProcessor::operator delete(void* target) { |
bsalomon | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 169 | return MemoryPoolAccessor().pool()->release(target); |
tomhudson@google.com | dcba4c2 | 2012-07-24 21:36:16 +0000 | [diff] [blame] | 170 | } |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 171 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 172 | bool GrProcessor::hasSameSamplersAndAccesses(const GrProcessor &that) const { |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 173 | if (this->numTextureSamplers() != that.numTextureSamplers() || |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 174 | this->numBuffers() != that.numBuffers() || |
| 175 | this->numImageStorages() != that.numImageStorages()) { |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame] | 176 | return false; |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 177 | } |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 178 | for (int i = 0; i < this->numTextureSamplers(); ++i) { |
| 179 | if (this->textureSampler(i) != that.textureSampler(i)) { |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame] | 180 | return false; |
| 181 | } |
| 182 | } |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 183 | for (int i = 0; i < this->numBuffers(); ++i) { |
| 184 | if (this->bufferAccess(i) != that.bufferAccess(i)) { |
| 185 | return false; |
| 186 | } |
| 187 | } |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 188 | for (int i = 0; i < this->numImageStorages(); ++i) { |
| 189 | if (this->imageStorageAccess(i) != that.imageStorageAccess(i)) { |
| 190 | return false; |
| 191 | } |
| 192 | } |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame] | 193 | return true; |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 194 | } |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 195 | |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 196 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 197 | |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 198 | GrProcessor::TextureSampler::TextureSampler() {} |
| 199 | |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 200 | GrProcessor::TextureSampler::TextureSampler(GrTexture* texture, const GrSamplerParams& params) { |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 201 | this->reset(texture, params); |
| 202 | } |
| 203 | |
| 204 | GrProcessor::TextureSampler::TextureSampler(GrTexture* texture, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 205 | GrSamplerParams::FilterMode filterMode, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 206 | SkShader::TileMode tileXAndY, |
| 207 | GrShaderFlags visibility) { |
| 208 | this->reset(texture, filterMode, tileXAndY, visibility); |
| 209 | } |
| 210 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 211 | GrProcessor::TextureSampler::TextureSampler(GrResourceProvider* resourceProvider, |
Robert Phillips | bc7a4fb | 2017-01-23 15:30:35 -0500 | [diff] [blame] | 212 | sk_sp<GrTextureProxy> proxy, |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 213 | const GrSamplerParams& params) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 214 | this->reset(resourceProvider, std::move(proxy), params); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 215 | } |
| 216 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 217 | GrProcessor::TextureSampler::TextureSampler(GrResourceProvider* resourceProvider, |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 218 | sk_sp<GrTextureProxy> proxy, |
Robert Phillips | bc7a4fb | 2017-01-23 15:30:35 -0500 | [diff] [blame] | 219 | GrSamplerParams::FilterMode filterMode, |
| 220 | SkShader::TileMode tileXAndY, |
| 221 | GrShaderFlags visibility) { |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 222 | this->reset(resourceProvider, std::move(proxy), filterMode, tileXAndY, visibility); |
Robert Phillips | bc7a4fb | 2017-01-23 15:30:35 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 225 | void GrProcessor::TextureSampler::reset(GrTexture* texture, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 226 | const GrSamplerParams& params, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 227 | GrShaderFlags visibility) { |
| 228 | SkASSERT(texture); |
| 229 | fTexture.set(SkRef(texture), kRead_GrIOType); |
| 230 | fParams = params; |
| 231 | fParams.setFilterMode(SkTMin(params.filterMode(), texture->texturePriv().highestFilterMode())); |
| 232 | fVisibility = visibility; |
| 233 | } |
| 234 | |
| 235 | void GrProcessor::TextureSampler::reset(GrTexture* texture, |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 236 | GrSamplerParams::FilterMode filterMode, |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 237 | SkShader::TileMode tileXAndY, |
| 238 | GrShaderFlags visibility) { |
| 239 | SkASSERT(texture); |
| 240 | fTexture.set(SkRef(texture), kRead_GrIOType); |
| 241 | filterMode = SkTMin(filterMode, texture->texturePriv().highestFilterMode()); |
| 242 | fParams.reset(tileXAndY, filterMode); |
| 243 | fVisibility = visibility; |
| 244 | } |
| 245 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 246 | void GrProcessor::TextureSampler::reset(GrResourceProvider* resourceProvider, |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 247 | sk_sp<GrTextureProxy> proxy, |
| 248 | const GrSamplerParams& params, |
| 249 | GrShaderFlags visibility) { |
| 250 | // For now, end the deferral at this time. Once all the TextureSamplers are swapped over |
| 251 | // to taking a GrSurfaceProxy just use the IORefs on the proxy |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 252 | GrTexture* texture = proxy->instantiate(resourceProvider); |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 253 | SkASSERT(texture); |
| 254 | fTexture.set(SkRef(texture), kRead_GrIOType); |
| 255 | fParams = params; |
| 256 | fParams.setFilterMode(SkTMin(params.filterMode(), texture->texturePriv().highestFilterMode())); |
| 257 | fVisibility = visibility; |
| 258 | } |
| 259 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 260 | void GrProcessor::TextureSampler::reset(GrResourceProvider* resourceProvider, |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 261 | sk_sp<GrTextureProxy> proxy, |
| 262 | GrSamplerParams::FilterMode filterMode, |
| 263 | SkShader::TileMode tileXAndY, |
| 264 | GrShaderFlags visibility) { |
| 265 | // For now, end the deferral at this time. Once all the TextureSamplers are swapped over |
| 266 | // to taking a GrSurfaceProxy just use the IORefs on the proxy |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 267 | GrTexture* texture = proxy->instantiate(resourceProvider); |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 268 | SkASSERT(texture); |
| 269 | fTexture.set(SkRef(texture), kRead_GrIOType); |
| 270 | filterMode = SkTMin(filterMode, texture->texturePriv().highestFilterMode()); |
| 271 | fParams.reset(tileXAndY, filterMode); |
| 272 | fVisibility = visibility; |
| 273 | } |
| 274 | |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 275 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 276 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 277 | GrProcessor::ImageStorageAccess::ImageStorageAccess(sk_sp<GrTexture> texture, GrIOType ioType, |
| 278 | GrSLMemoryModel memoryModel, |
| 279 | GrSLRestrict restrict, |
| 280 | GrShaderFlags visibility) { |
| 281 | SkASSERT(texture); |
| 282 | fTexture.set(texture.release(), ioType); |
| 283 | fMemoryModel = memoryModel; |
| 284 | fRestrict = restrict; |
| 285 | fVisibility = visibility; |
| 286 | // We currently infer this from the config. However, we could allow the client to specify |
| 287 | // a format that is different but compatible with the config. |
| 288 | switch (fTexture.get()->config()) { |
| 289 | case kRGBA_8888_GrPixelConfig: |
| 290 | fFormat = GrImageStorageFormat::kRGBA8; |
| 291 | break; |
| 292 | case kRGBA_8888_sint_GrPixelConfig: |
| 293 | fFormat = GrImageStorageFormat::kRGBA8i; |
| 294 | break; |
| 295 | case kRGBA_half_GrPixelConfig: |
| 296 | fFormat = GrImageStorageFormat::kRGBA16f; |
| 297 | break; |
| 298 | case kRGBA_float_GrPixelConfig: |
| 299 | fFormat = GrImageStorageFormat::kRGBA32f; |
| 300 | break; |
| 301 | default: |
| 302 | SkFAIL("Config is not (yet) supported as image storage."); |
| 303 | break; |
| 304 | } |
| 305 | } |