Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 GrBackendSemaphore_DEFINED |
| 9 | #define GrBackendSemaphore_DEFINED |
| 10 | |
| 11 | #include "GrTypes.h" |
| 12 | |
| 13 | #include "gl/GrGLTypes.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 14 | #include "vk/GrVkTypes.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 15 | |
| 16 | /** |
| 17 | * Wrapper class for passing into and receiving data from Ganesh about a backend semaphore object. |
| 18 | */ |
| 19 | class GrBackendSemaphore { |
| 20 | public: |
| 21 | // For convenience we just set the backend here to OpenGL. The GrBackendSemaphore cannot be used |
| 22 | // until either initGL or initVulkan are called which will set the appropriate GrBackend. |
| 23 | GrBackendSemaphore() : fBackend(kOpenGL_GrBackend), fGLSync(0), fIsInitialized(false) {} |
| 24 | |
| 25 | void initGL(GrGLsync sync) { |
| 26 | fBackend = kOpenGL_GrBackend; |
| 27 | fGLSync = sync; |
| 28 | fIsInitialized = true; |
| 29 | } |
| 30 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 31 | void initVulkan(VkSemaphore semaphore) { |
| 32 | fBackend = kVulkan_GrBackend; |
| 33 | fVkSemaphore = semaphore; |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame^] | 34 | #ifdef SK_VULKAN |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 35 | fIsInitialized = true; |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame^] | 36 | #else |
| 37 | fIsInitialized = false; |
Mike Klein | a55e214 | 2018-10-03 16:34:11 +0000 | [diff] [blame] | 38 | #endif |
Greg Daniel | b4d8956 | 2018-10-03 18:44:49 +0000 | [diff] [blame^] | 39 | } |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 40 | |
Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 41 | bool isInitialized() const { return fIsInitialized; } |
| 42 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 43 | GrGLsync glSync() const { |
| 44 | if (!fIsInitialized || kOpenGL_GrBackend != fBackend) { |
| 45 | return 0; |
| 46 | } |
| 47 | return fGLSync; |
| 48 | } |
| 49 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 50 | VkSemaphore vkSemaphore() const { |
| 51 | if (!fIsInitialized || kVulkan_GrBackend != fBackend) { |
| 52 | return VK_NULL_HANDLE; |
| 53 | } |
| 54 | return fVkSemaphore; |
| 55 | } |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 56 | |
| 57 | private: |
| 58 | GrBackend fBackend; |
| 59 | union { |
| 60 | GrGLsync fGLSync; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 61 | VkSemaphore fVkSemaphore; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 62 | }; |
| 63 | bool fIsInitialized; |
| 64 | }; |
| 65 | |
| 66 | #endif |