Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Greg Daniel | 54bfb18 | 2018-11-20 17:12:36 -0500 | [diff] [blame] | 8 | |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 9 | #include "include/gpu/GrDirectContext.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrContextThreadSafeProxy.h" |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 12 | #include "src/core/SkTaskGroup.h" |
| 13 | #include "src/gpu/GrClientMappedBufferManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrContextPriv.h" |
| 15 | #include "src/gpu/GrContextThreadSafeProxyPriv.h" |
| 16 | #include "src/gpu/GrGpu.h" |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrResourceProvider.h" |
| 18 | #include "src/gpu/GrShaderUtils.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 19 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/effects/GrSkSLFP.h" |
| 21 | #include "src/gpu/gl/GrGLGpu.h" |
| 22 | #include "src/gpu/mock/GrMockGpu.h" |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 23 | #include "src/gpu/ops/GrSmallPathAtlasMgr.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 24 | #include "src/gpu/text/GrAtlasManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/text/GrStrikeCache.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 26 | #ifdef SK_METAL |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/gpu/mtl/GrMtlTrampoline.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 28 | #endif |
| 29 | #ifdef SK_VULKAN |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 30 | #include "src/gpu/vk/GrVkGpu.h" |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 31 | #endif |
Jim Van Verth | d2d4c5e | 2020-02-19 14:57:58 -0500 | [diff] [blame] | 32 | #ifdef SK_DIRECT3D |
| 33 | #include "src/gpu/d3d/GrD3DGpu.h" |
| 34 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 35 | #ifdef SK_DAWN |
Mike Klein | 52337de | 2019-07-25 09:00:52 -0500 | [diff] [blame] | 36 | #include "src/gpu/dawn/GrDawnGpu.h" |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 37 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 38 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 39 | #if GR_TEST_UTILS |
| 40 | # include "include/utils/SkRandom.h" |
| 41 | # if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 42 | # include <sanitizer/lsan_interface.h> |
| 43 | # endif |
| 44 | #endif |
| 45 | |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 46 | #ifdef SK_DISABLE_REDUCE_OPLIST_SPLITTING |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 47 | static const bool kDefaultReduceOpsTaskSplitting = false; |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 48 | #else |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 49 | static const bool kDefaultReduceOpsTaskSplitting = false; |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 50 | #endif |
| 51 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 52 | #define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner()) |
| 53 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 54 | GrDirectContext::GrDirectContext(GrBackendApi backend, const GrContextOptions& options) |
Robert Phillips | 3262bc8 | 2020-08-10 12:11:58 -0400 | [diff] [blame] | 55 | : INHERITED(GrContextThreadSafeProxyPriv::Make(backend, options)) { |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 56 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 57 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 58 | GrDirectContext::~GrDirectContext() { |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 59 | ASSERT_SINGLE_OWNER |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 60 | // this if-test protects against the case where the context is being destroyed |
| 61 | // before having been fully created |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 62 | if (fGpu) { |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 63 | this->flushAndSubmit(); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 64 | } |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 65 | |
| 66 | this->destroyDrawingManager(); |
| 67 | fMappedBufferManager.reset(); |
| 68 | |
| 69 | // Ideally we could just let the ptr drop, but resource cache queries this ptr in releaseAll. |
| 70 | if (fResourceCache) { |
| 71 | fResourceCache->releaseAll(); |
| 72 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 73 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 74 | |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame^] | 75 | void GrDirectContext::resetGLTextureBindings() { |
| 76 | if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) { |
| 77 | return; |
| 78 | } |
| 79 | fGpu->resetTextureBindings(); |
| 80 | } |
| 81 | |
| 82 | void GrDirectContext::resetContext(uint32_t state) { |
| 83 | ASSERT_SINGLE_OWNER |
| 84 | fGpu->markContextDirty(state); |
| 85 | } |
| 86 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 87 | void GrDirectContext::abandonContext() { |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame^] | 88 | if (INHERITED::abandoned()) { |
| 89 | return; |
| 90 | } |
| 91 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 92 | INHERITED::abandonContext(); |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame^] | 93 | |
| 94 | fStrikeCache->freeAll(); |
| 95 | |
| 96 | fMappedBufferManager->abandon(); |
| 97 | |
| 98 | fResourceProvider->abandon(); |
| 99 | |
| 100 | // abandon first to so destructors |
| 101 | // don't try to free the resources in the API. |
| 102 | fResourceCache->abandonAll(); |
| 103 | |
| 104 | fGpu->disconnect(GrGpu::DisconnectType::kAbandon); |
| 105 | |
| 106 | fMappedBufferManager.reset(); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 107 | if (fSmallPathAtlasMgr) { |
| 108 | fSmallPathAtlasMgr->reset(); |
| 109 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 110 | fAtlasManager->freeAll(); |
| 111 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 112 | |
Adlai Holler | a7a4044 | 2020-10-09 09:49:42 -0400 | [diff] [blame^] | 113 | bool GrDirectContext::abandoned() { |
| 114 | if (INHERITED::abandoned()) { |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | if (fGpu && fGpu->isDeviceLost()) { |
| 119 | this->abandonContext(); |
| 120 | return true; |
| 121 | } |
| 122 | return false; |
| 123 | } |
| 124 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 125 | void GrDirectContext::releaseResourcesAndAbandonContext() { |
| 126 | INHERITED::releaseResourcesAndAbandonContext(); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 127 | if (fSmallPathAtlasMgr) { |
| 128 | fSmallPathAtlasMgr->reset(); |
| 129 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 130 | fAtlasManager->freeAll(); |
| 131 | } |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 132 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 133 | void GrDirectContext::freeGpuResources() { |
| 134 | this->flushAndSubmit(); |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 135 | if (fSmallPathAtlasMgr) { |
| 136 | fSmallPathAtlasMgr->reset(); |
| 137 | } |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 138 | fAtlasManager->freeAll(); |
Robert Phillips | 56181ba | 2019-03-08 12:00:45 -0500 | [diff] [blame] | 139 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 140 | INHERITED::freeGpuResources(); |
| 141 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 142 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 143 | bool GrDirectContext::init() { |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 144 | ASSERT_SINGLE_OWNER |
| 145 | if (!fGpu) { |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 146 | return false; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 147 | } |
| 148 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 149 | fThreadSafeProxy->priv().init(fGpu->refCaps()); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 150 | if (!INHERITED::init()) { |
| 151 | return false; |
| 152 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 153 | |
Adlai Holler | 9555f29 | 2020-10-09 09:41:14 -0400 | [diff] [blame] | 154 | SkASSERT(this->getTextBlobCache()); |
| 155 | SkASSERT(this->threadSafeCache()); |
| 156 | |
| 157 | fStrikeCache = std::make_unique<GrStrikeCache>(); |
| 158 | fResourceCache = std::make_unique<GrResourceCache>(this->caps(), this->singleOwner(), |
| 159 | this->contextID()); |
| 160 | fResourceCache->setProxyProvider(this->proxyProvider()); |
| 161 | fResourceCache->setThreadSafeCache(this->threadSafeCache()); |
| 162 | fResourceProvider = std::make_unique<GrResourceProvider>(fGpu.get(), fResourceCache.get(), |
| 163 | this->singleOwner()); |
| 164 | fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID()); |
| 165 | |
| 166 | fDidTestPMConversions = false; |
| 167 | |
| 168 | // DDL TODO: we need to think through how the task group & persistent cache |
| 169 | // get passed on to/shared between all the DDLRecorders created with this context. |
| 170 | if (this->options().fExecutor) { |
| 171 | fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor); |
| 172 | } |
| 173 | |
| 174 | fPersistentCache = this->options().fPersistentCache; |
| 175 | fShaderErrorHandler = this->options().fShaderErrorHandler; |
| 176 | if (!fShaderErrorHandler) { |
| 177 | fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler(); |
| 178 | } |
| 179 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 180 | bool reduceOpsTaskSplitting = kDefaultReduceOpsTaskSplitting; |
| 181 | if (GrContextOptions::Enable::kNo == this->options().fReduceOpsTaskSplitting) { |
| 182 | reduceOpsTaskSplitting = false; |
| 183 | } else if (GrContextOptions::Enable::kYes == this->options().fReduceOpsTaskSplitting) { |
| 184 | reduceOpsTaskSplitting = true; |
| 185 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 186 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 187 | this->setupDrawingManager(true, reduceOpsTaskSplitting); |
| 188 | |
| 189 | GrDrawOpAtlas::AllowMultitexturing allowMultitexturing; |
| 190 | if (GrContextOptions::Enable::kNo == this->options().fAllowMultipleGlyphCacheTextures || |
| 191 | // multitexturing supported only if range can represent the index + texcoords fully |
| 192 | !(this->caps()->shaderCaps()->floatIs32Bits() || |
| 193 | this->caps()->shaderCaps()->integerSupport())) { |
| 194 | allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo; |
| 195 | } else { |
| 196 | allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes; |
| 197 | } |
| 198 | |
| 199 | GrProxyProvider* proxyProvider = this->priv().proxyProvider(); |
| 200 | |
Robert Phillips | 3262bc8 | 2020-08-10 12:11:58 -0400 | [diff] [blame] | 201 | fAtlasManager = std::make_unique<GrAtlasManager>(proxyProvider, |
| 202 | this->options().fGlyphCacheTextureMaximumBytes, |
| 203 | allowMultitexturing); |
| 204 | this->priv().addOnFlushCallbackObject(fAtlasManager.get()); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 205 | |
| 206 | return true; |
| 207 | } |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 208 | |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 209 | GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() { |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 210 | if (!fSmallPathAtlasMgr) { |
| 211 | fSmallPathAtlasMgr = std::make_unique<GrSmallPathAtlasMgr>(); |
| 212 | |
| 213 | this->priv().addOnFlushCallbackObject(fSmallPathAtlasMgr.get()); |
| 214 | } |
| 215 | |
| 216 | if (!fSmallPathAtlasMgr->initAtlas(this->proxyProvider(), this->caps())) { |
| 217 | return nullptr; |
| 218 | } |
| 219 | |
| 220 | return fSmallPathAtlasMgr.get(); |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame] | 221 | } |
| 222 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 223 | #ifdef SK_GL |
Robert Phillips | c7228c6 | 2020-07-14 12:57:39 -0400 | [diff] [blame] | 224 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 225 | /*************************************************************************************************/ |
| 226 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 227 | GrContextOptions defaultOptions; |
Jim Van Verth | 03b8ab2 | 2020-02-24 11:36:15 -0500 | [diff] [blame] | 228 | return MakeGL(std::move(glInterface), defaultOptions); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 229 | } |
| 230 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 231 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(const GrContextOptions& options) { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 232 | return MakeGL(nullptr, options); |
| 233 | } |
| 234 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 235 | sk_sp<GrDirectContext> GrDirectContext::MakeGL() { |
Brian Salomon | c1b9c10 | 2018-04-06 09:18:00 -0400 | [diff] [blame] | 236 | GrContextOptions defaultOptions; |
| 237 | return MakeGL(nullptr, defaultOptions); |
| 238 | } |
| 239 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 240 | #if GR_TEST_UTILS |
| 241 | GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGetErrorFn> original) { |
| 242 | // A SkRandom and a GrGLFunction<GrGLGetErrorFn> are too big to be captured by a |
| 243 | // GrGLFunction<GrGLGetError> (surprise, surprise). So we make a context object and |
| 244 | // capture that by pointer. However, GrGLFunction doesn't support calling a destructor |
| 245 | // on the thing it captures. So we leak the context. |
| 246 | struct GetErrorContext { |
| 247 | SkRandom fRandom; |
| 248 | GrGLFunction<GrGLGetErrorFn> fGetError; |
| 249 | }; |
| 250 | |
| 251 | auto errorContext = new GetErrorContext; |
| 252 | |
| 253 | #if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 254 | __lsan_ignore_object(errorContext); |
| 255 | #endif |
| 256 | |
| 257 | errorContext->fGetError = original; |
| 258 | |
| 259 | return GrGLFunction<GrGLGetErrorFn>([errorContext]() { |
| 260 | GrGLenum error = errorContext->fGetError(); |
| 261 | if (error == GR_GL_NO_ERROR && (errorContext->fRandom.nextU() % 300) == 0) { |
| 262 | error = GR_GL_OUT_OF_MEMORY; |
| 263 | } |
| 264 | return error; |
| 265 | }); |
| 266 | } |
| 267 | #endif |
| 268 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 269 | sk_sp<GrDirectContext> GrDirectContext::MakeGL(sk_sp<const GrGLInterface> glInterface, |
| 270 | const GrContextOptions& options) { |
| 271 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kOpenGL, options)); |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 272 | #if GR_TEST_UTILS |
| 273 | if (options.fRandomGLOOM) { |
| 274 | auto copy = sk_make_sp<GrGLInterface>(*glInterface); |
| 275 | copy->fFunctions.fGetError = |
| 276 | make_get_error_with_random_oom(glInterface->fFunctions.fGetError); |
| 277 | #if GR_GL_CHECK_ERROR |
| 278 | // Suppress logging GL errors since we'll be synthetically generating them. |
| 279 | copy->suppressErrorLogging(); |
| 280 | #endif |
| 281 | glInterface = std::move(copy); |
| 282 | } |
| 283 | #endif |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 284 | direct->fGpu = GrGLGpu::Make(std::move(glInterface), options, direct.get()); |
| 285 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 286 | return nullptr; |
| 287 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 288 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 289 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 290 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 291 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 292 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 293 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions) { |
| 294 | GrContextOptions defaultOptions; |
| 295 | return MakeMock(mockOptions, defaultOptions); |
| 296 | } |
| 297 | |
| 298 | sk_sp<GrDirectContext> GrDirectContext::MakeMock(const GrMockOptions* mockOptions, |
| 299 | const GrContextOptions& options) { |
| 300 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMock, options)); |
| 301 | |
| 302 | direct->fGpu = GrMockGpu::Make(mockOptions, options, direct.get()); |
| 303 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 304 | return nullptr; |
| 305 | } |
Chris Dalton | a378b45 | 2019-12-11 13:24:11 -0500 | [diff] [blame] | 306 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 307 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 308 | } |
| 309 | |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 310 | #ifdef SK_VULKAN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 311 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 312 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext) { |
| 313 | GrContextOptions defaultOptions; |
| 314 | return MakeVulkan(backendContext, defaultOptions); |
| 315 | } |
| 316 | |
| 317 | sk_sp<GrDirectContext> GrDirectContext::MakeVulkan(const GrVkBackendContext& backendContext, |
| 318 | const GrContextOptions& options) { |
| 319 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kVulkan, options)); |
| 320 | |
| 321 | direct->fGpu = GrVkGpu::Make(backendContext, options, direct.get()); |
| 322 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 323 | return nullptr; |
| 324 | } |
| 325 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 326 | return direct; |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame] | 327 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 328 | #endif |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 329 | |
| 330 | #ifdef SK_METAL |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 331 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 332 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 333 | GrContextOptions defaultOptions; |
| 334 | return MakeMetal(device, queue, defaultOptions); |
| 335 | } |
| 336 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 337 | sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue, |
| 338 | const GrContextOptions& options) { |
| 339 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options)); |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 340 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 341 | direct->fGpu = GrMtlTrampoline::MakeGpu(direct.get(), options, device, queue); |
| 342 | if (!direct->init()) { |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 343 | return nullptr; |
| 344 | } |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 345 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 346 | return direct; |
Robert Phillips | a3457b8 | 2018-03-08 11:30:12 -0500 | [diff] [blame] | 347 | } |
| 348 | #endif |
| 349 | |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 350 | #ifdef SK_DIRECT3D |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 351 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 352 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext) { |
| 353 | GrContextOptions defaultOptions; |
| 354 | return MakeDirect3D(backendContext, defaultOptions); |
| 355 | } |
| 356 | |
| 357 | sk_sp<GrDirectContext> GrDirectContext::MakeDirect3D(const GrD3DBackendContext& backendContext, |
| 358 | const GrContextOptions& options) { |
| 359 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDirect3D, options)); |
| 360 | |
| 361 | direct->fGpu = GrD3DGpu::Make(backendContext, options, direct.get()); |
| 362 | if (!direct->init()) { |
Jim Van Verth | d2d4c5e | 2020-02-19 14:57:58 -0500 | [diff] [blame] | 363 | return nullptr; |
| 364 | } |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 365 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 366 | return direct; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 367 | } |
| 368 | #endif |
| 369 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 370 | #ifdef SK_DAWN |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 371 | /*************************************************************************************************/ |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 372 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 373 | GrContextOptions defaultOptions; |
| 374 | return MakeDawn(device, defaultOptions); |
| 375 | } |
| 376 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 377 | sk_sp<GrDirectContext> GrDirectContext::MakeDawn(const wgpu::Device& device, |
| 378 | const GrContextOptions& options) { |
| 379 | sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kDawn, options)); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 380 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 381 | direct->fGpu = GrDawnGpu::Make(device, options, direct.get()); |
| 382 | if (!direct->init()) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 383 | return nullptr; |
| 384 | } |
| 385 | |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 386 | return direct; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 387 | } |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 388 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 389 | #endif |