• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
glSync()42     GrGLsync glSync() const {
43         if (!fIsInitialized || kOpenGL_GrBackend != fBackend) {
44             return 0;
45         }
46         return fGLSync;
47     }
48 
49 #ifdef SK_VULKAN
vkSemaphore()50     VkSemaphore vkSemaphore() const {
51         if (!fIsInitialized || kVulkan_GrBackend != fBackend) {
52             return VK_NULL_HANDLE;
53         }
54         return fVkSemaphore;
55     }
56 #endif
57 
58 private:
59     GrBackend fBackend;
60     union {
61         GrGLsync    fGLSync;
62 #ifdef SK_VULKAN
63         VkSemaphore fVkSemaphore;
64 #endif
65     };
66     bool fIsInitialized;
67 };
68 
69 #endif
70