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" 14 15 #ifdef SK_VULKAN 16 #include "vk/GrVkTypes.h" 17 #endif 18 19 /** 20 * Wrapper class for passing into and receiving data from Ganesh about a backend semaphore object. 21 */ 22 class GrBackendSemaphore { 23 public: 24 // For convenience we just set the backend here to OpenGL. The GrBackendSemaphore cannot be used 25 // until either initGL or initVulkan are called which will set the appropriate GrBackend. GrBackendSemaphore()26 GrBackendSemaphore() : fBackend(kOpenGL_GrBackend), fGLSync(0), fIsInitialized(false) {} 27 initGL(GrGLsync sync)28 void initGL(GrGLsync sync) { 29 fBackend = kOpenGL_GrBackend; 30 fGLSync = sync; 31 fIsInitialized = true; 32 } 33 34 #ifdef SK_VULKAN initVulkan(VkSemaphore semaphore)35 void initVulkan(VkSemaphore semaphore) { 36 fBackend = kVulkan_GrBackend; 37 fVkSemaphore = semaphore; 38 fIsInitialized = true; 39 } 40 #endif 41 isInitialized()42 bool isInitialized() const { return fIsInitialized; } 43 glSync()44 GrGLsync glSync() const { 45 if (!fIsInitialized || kOpenGL_GrBackend != fBackend) { 46 return 0; 47 } 48 return fGLSync; 49 } 50 51 #ifdef SK_VULKAN vkSemaphore()52 VkSemaphore vkSemaphore() const { 53 if (!fIsInitialized || kVulkan_GrBackend != fBackend) { 54 return VK_NULL_HANDLE; 55 } 56 return fVkSemaphore; 57 } 58 #endif 59 60 private: 61 GrBackend fBackend; 62 union { 63 GrGLsync fGLSync; 64 #ifdef SK_VULKAN 65 VkSemaphore fVkSemaphore; 66 #endif 67 }; 68 bool fIsInitialized; 69 }; 70 71 #endif 72