• 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 "include/gpu/GrTypes.h"
12 
13 #include "include/gpu/gl/GrGLTypes.h"
14 #include "include/gpu/vk/GrVkTypes.h"
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.
GrBackendSemaphore()23     GrBackendSemaphore() : fBackend(GrBackendApi::kOpenGL), fGLSync(0), fIsInitialized(false) {}
24 
initGL(GrGLsync sync)25     void initGL(GrGLsync sync) {
26         fBackend = GrBackendApi::kOpenGL;
27         fGLSync = sync;
28         fIsInitialized = true;
29     }
30 
initVulkan(VkSemaphore semaphore)31     void initVulkan(VkSemaphore semaphore) {
32         fBackend = GrBackendApi::kVulkan;
33         fVkSemaphore = semaphore;
34 #ifdef SK_VULKAN
35         fIsInitialized = true;
36 #else
37         fIsInitialized = false;
38 #endif
39     }
40 
isInitialized()41     bool isInitialized() const { return fIsInitialized; }
42 
glSync()43     GrGLsync glSync() const {
44         if (!fIsInitialized || GrBackendApi::kOpenGL != fBackend) {
45             return 0;
46         }
47         return fGLSync;
48     }
49 
vkSemaphore()50     VkSemaphore vkSemaphore() const {
51         if (!fIsInitialized || GrBackendApi::kVulkan != fBackend) {
52             return VK_NULL_HANDLE;
53         }
54         return fVkSemaphore;
55     }
56 
57 private:
58     GrBackendApi fBackend;
59     union {
60         GrGLsync    fGLSync;
61         VkSemaphore fVkSemaphore;
62     };
63     bool fIsInitialized;
64 };
65 
66 #endif
67