Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | |
| 8 | #ifndef GrDirectContext_DEFINED |
| 9 | #define GrDirectContext_DEFINED |
| 10 | |
| 11 | #include "include/gpu/GrContext.h" |
| 12 | |
| 13 | class GrAtlasManager; |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame^] | 14 | class GrSmallPathAtlasMgr; |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 15 | |
Robert Phillips | c7228c6 | 2020-07-14 12:57:39 -0400 | [diff] [blame] | 16 | class SK_API GrDirectContext : public GrContext { |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 17 | public: |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 18 | #ifdef SK_GL |
| 19 | /** |
| 20 | * Creates a GrDirectContext for a backend context. If no GrGLInterface is provided then the |
| 21 | * result of GrGLMakeNativeInterface() is used if it succeeds. |
| 22 | */ |
| 23 | static sk_sp<GrDirectContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&); |
| 24 | static sk_sp<GrDirectContext> MakeGL(sk_sp<const GrGLInterface>); |
| 25 | static sk_sp<GrDirectContext> MakeGL(const GrContextOptions&); |
| 26 | static sk_sp<GrDirectContext> MakeGL(); |
| 27 | #endif |
| 28 | |
| 29 | #ifdef SK_VULKAN |
| 30 | /** |
| 31 | * The Vulkan context (VkQueue, VkDevice, VkInstance) must be kept alive until the returned |
| 32 | * GrDirectContext is destroyed. This also means that any objects created with this |
| 33 | * GrDirectContext (e.g. SkSurfaces, SkImages, etc.) must also be released as they may hold |
| 34 | * refs on the GrDirectContext. Once all these objects and the GrDirectContext are released, |
| 35 | * then it is safe to delete the vulkan objects. |
| 36 | */ |
| 37 | static sk_sp<GrDirectContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&); |
| 38 | static sk_sp<GrDirectContext> MakeVulkan(const GrVkBackendContext&); |
| 39 | #endif |
| 40 | |
| 41 | #ifdef SK_METAL |
| 42 | /** |
| 43 | * Makes a GrDirectContext which uses Metal as the backend. The device parameter is an |
| 44 | * MTLDevice and queue is an MTLCommandQueue which should be used by the backend. These objects |
| 45 | * must have a ref on them which can be transferred to Ganesh which will release the ref |
| 46 | * when the GrDirectContext is destroyed. |
| 47 | */ |
| 48 | static sk_sp<GrDirectContext> MakeMetal(void* device, void* queue, const GrContextOptions&); |
| 49 | static sk_sp<GrDirectContext> MakeMetal(void* device, void* queue); |
| 50 | #endif |
| 51 | |
| 52 | #ifdef SK_DIRECT3D |
| 53 | /** |
| 54 | * Makes a GrDirectContext which uses Direct3D as the backend. The Direct3D context |
| 55 | * must be kept alive until the returned GrDirectContext is first destroyed or abandoned. |
| 56 | */ |
| 57 | static sk_sp<GrDirectContext> MakeDirect3D(const GrD3DBackendContext&, const GrContextOptions&); |
| 58 | static sk_sp<GrDirectContext> MakeDirect3D(const GrD3DBackendContext&); |
| 59 | #endif |
| 60 | |
| 61 | #ifdef SK_DAWN |
| 62 | static sk_sp<GrDirectContext> MakeDawn(const wgpu::Device&, |
| 63 | const GrContextOptions&); |
| 64 | static sk_sp<GrDirectContext> MakeDawn(const wgpu::Device&); |
| 65 | #endif |
| 66 | |
| 67 | static sk_sp<GrDirectContext> MakeMock(const GrMockOptions*, const GrContextOptions&); |
| 68 | static sk_sp<GrDirectContext> MakeMock(const GrMockOptions*); |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 69 | |
| 70 | ~GrDirectContext() override; |
| 71 | |
| 72 | void abandonContext() override; |
| 73 | |
| 74 | void releaseResourcesAndAbandonContext() override; |
| 75 | |
| 76 | void freeGpuResources() override; |
| 77 | |
| 78 | protected: |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 79 | GrDirectContext(GrBackendApi backend, const GrContextOptions& options); |
| 80 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 81 | bool init() override; |
| 82 | |
Robert Phillips | 3262bc8 | 2020-08-10 12:11:58 -0400 | [diff] [blame] | 83 | GrAtlasManager* onGetAtlasManager() override { return fAtlasManager.get(); } |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame^] | 84 | GrSmallPathAtlasMgr* onGetSmallPathAtlasMgr() override; |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 85 | |
Robert Phillips | 44333c5 | 2020-06-30 13:28:00 -0400 | [diff] [blame] | 86 | GrDirectContext* asDirectContext() override { return this; } |
| 87 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 88 | private: |
Robert Phillips | 3262bc8 | 2020-08-10 12:11:58 -0400 | [diff] [blame] | 89 | std::unique_ptr<GrAtlasManager> fAtlasManager; |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 90 | |
Robert Phillips | 5edf510 | 2020-08-10 16:30:36 -0400 | [diff] [blame^] | 91 | // The small path renderer atlas will be stored here |
| 92 | |
Robert Phillips | ad24845 | 2020-06-30 09:27:52 -0400 | [diff] [blame] | 93 | typedef GrContext INHERITED; |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | #endif |