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