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. |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame^] | 23 | GrBackendSemaphore() : fBackend(GrBackendApi::kOpenGL), fGLSync(0), fIsInitialized(false) {} |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 24 | |
| 25 | void initGL(GrGLsync sync) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame^] | 26 | fBackend = GrBackendApi::kOpenGL; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 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) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame^] | 32 | fBackend = GrBackendApi::kVulkan; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 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 { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame^] | 44 | if (!fIsInitialized || GrBackendApi::kOpenGL != fBackend) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 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 { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame^] | 51 | if (!fIsInitialized || GrBackendApi::kVulkan != fBackend) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 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: |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame^] | 58 | GrBackendApi fBackend; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 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 |