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