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 | 5baedd6 | 2015-03-09 12:15:53 -0700 | [diff] [blame] | 118 | int32_t GrProcessor::gCurrProcessorClassID = GrProcessor::kIllegalProcessorClassID; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 119 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 120 | /////////////////////////////////////////////////////////////////////////////// |
| 121 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 122 | 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] | 123 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 124 | void GrProcessor::operator delete(void* target) { |
| 125 | return MemoryPoolAccessor().pool()->release(target); |
| 126 | } |
| 127 | |
| 128 | /////////////////////////////////////////////////////////////////////////////// |
| 129 | |
| 130 | void GrResourceIOProcessor::addTextureSampler(const TextureSampler* access) { |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 131 | fTextureSamplers.push_back(access); |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 134 | void GrResourceIOProcessor::addBufferAccess(const BufferAccess* access) { |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 135 | fBufferAccesses.push_back(access); |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 136 | } |
| 137 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 138 | void GrResourceIOProcessor::addImageStorageAccess(const ImageStorageAccess* access) { |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 139 | fImageStorageAccesses.push_back(access); |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 140 | } |
| 141 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 142 | void GrResourceIOProcessor::addPendingIOs() const { |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 143 | for (const auto& sampler : fTextureSamplers) { |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 144 | sampler->programProxy()->markPendingIO(); |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 145 | } |
| 146 | for (const auto& buffer : fBufferAccesses) { |
| 147 | buffer->programBuffer()->markPendingIO(); |
| 148 | } |
| 149 | for (const auto& imageStorage : fImageStorageAccesses) { |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 150 | imageStorage->programProxy()->markPendingIO(); |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 154 | void GrResourceIOProcessor::removeRefs() const { |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 155 | for (const auto& sampler : fTextureSamplers) { |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 156 | sampler->programProxy()->removeRef(); |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 157 | } |
| 158 | for (const auto& buffer : fBufferAccesses) { |
| 159 | buffer->programBuffer()->removeRef(); |
| 160 | } |
| 161 | for (const auto& imageStorage : fImageStorageAccesses) { |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 162 | imageStorage->programProxy()->removeRef(); |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 166 | void GrResourceIOProcessor::pendingIOComplete() const { |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 167 | for (const auto& sampler : fTextureSamplers) { |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 168 | sampler->programProxy()->pendingIOComplete(); |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 169 | } |
| 170 | for (const auto& buffer : fBufferAccesses) { |
| 171 | buffer->programBuffer()->pendingIOComplete(); |
| 172 | } |
| 173 | for (const auto& imageStorage : fImageStorageAccesses) { |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 174 | imageStorage->programProxy()->pendingIOComplete(); |
Brian Salomon | e57194f | 2017-01-09 15:30:02 -0500 | [diff] [blame] | 175 | } |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 178 | bool GrResourceIOProcessor::instantiate(GrResourceProvider* resourceProvider) const { |
| 179 | for (const auto& sampler : fTextureSamplers) { |
| 180 | if (!sampler->instantiate(resourceProvider)) { |
| 181 | return false; |
| 182 | } |
| 183 | } |
| 184 | |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 185 | // MDB TODO: instantiate 'fBufferAccesses' here as well |
| 186 | |
Robert Phillips | 9bee2e5 | 2017-05-29 12:37:20 -0400 | [diff] [blame] | 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 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 224 | GrResourceIOProcessor::TextureSampler::TextureSampler(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 225 | const GrSamplerState& samplerState) { |
| 226 | this->reset(std::move(proxy), samplerState); |
Robert Phillips | 901f29a | 2017-01-24 16:24:41 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 229 | GrResourceIOProcessor::TextureSampler::TextureSampler(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 230 | GrSamplerState::Filter filterMode, |
| 231 | GrSamplerState::WrapMode wrapXAndY, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 232 | GrShaderFlags visibility) { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 233 | this->reset(std::move(proxy), filterMode, wrapXAndY, visibility); |
Robert Phillips | bc7a4fb | 2017-01-23 15:30:35 -0500 | [diff] [blame] | 234 | } |
| 235 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 236 | void GrResourceIOProcessor::TextureSampler::reset(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 237 | const GrSamplerState& samplerState, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 238 | GrShaderFlags visibility) { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 239 | fSamplerState = samplerState; |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 240 | fProxyRef.setProxy(std::move(proxy), kRead_GrIOType); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 241 | fSamplerState.setFilterMode(SkTMin(samplerState.filter(), this->proxy()->highestFilterMode())); |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 242 | fVisibility = visibility; |
| 243 | } |
| 244 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 245 | void GrResourceIOProcessor::TextureSampler::reset(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 246 | GrSamplerState::Filter filterMode, |
| 247 | GrSamplerState::WrapMode wrapXAndY, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 248 | GrShaderFlags visibility) { |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 249 | fProxyRef.setProxy(std::move(proxy), kRead_GrIOType); |
| 250 | filterMode = SkTMin(filterMode, this->proxy()->highestFilterMode()); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 251 | fSamplerState = GrSamplerState(wrapXAndY, filterMode); |
Robert Phillips | 30f9bc6 | 2017-02-22 15:28:38 -0500 | [diff] [blame] | 252 | fVisibility = visibility; |
| 253 | } |
| 254 | |
Brian Salomon | 0bbecb2 | 2016-11-17 11:38:22 -0500 | [diff] [blame] | 255 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 256 | |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 257 | GrResourceIOProcessor::ImageStorageAccess::ImageStorageAccess(sk_sp<GrTextureProxy> proxy, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 258 | GrIOType ioType, |
| 259 | GrSLMemoryModel memoryModel, |
| 260 | GrSLRestrict restrict, |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 261 | GrShaderFlags visibility) |
| 262 | : fProxyRef(std::move(proxy), ioType) { |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 263 | SkASSERT(fProxyRef.get()); |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 264 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 265 | fMemoryModel = memoryModel; |
| 266 | fRestrict = restrict; |
| 267 | fVisibility = visibility; |
| 268 | // We currently infer this from the config. However, we could allow the client to specify |
| 269 | // a format that is different but compatible with the config. |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 270 | switch (fProxyRef.get()->config()) { |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 271 | case kRGBA_8888_GrPixelConfig: |
| 272 | fFormat = GrImageStorageFormat::kRGBA8; |
| 273 | break; |
| 274 | case kRGBA_8888_sint_GrPixelConfig: |
| 275 | fFormat = GrImageStorageFormat::kRGBA8i; |
| 276 | break; |
| 277 | case kRGBA_half_GrPixelConfig: |
| 278 | fFormat = GrImageStorageFormat::kRGBA16f; |
| 279 | break; |
| 280 | case kRGBA_float_GrPixelConfig: |
| 281 | fFormat = GrImageStorageFormat::kRGBA32f; |
| 282 | break; |
| 283 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 284 | SK_ABORT("Config is not (yet) supported as image storage."); |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 285 | break; |
| 286 | } |
| 287 | } |