blob: 5c41532cb91cae17b1bf5354c2f8c698644371c6 [file] [log] [blame]
Greg Daniela5cb7812017-06-16 09:45:32 -04001/*
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 */
22class GrBackendSemaphore {
23public:
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.
26 GrBackendSemaphore() : fBackend(kOpenGL_GrBackend), fGLSync(0), fIsInitialized(false) {}
27
28 void initGL(GrGLsync sync) {
29 fBackend = kOpenGL_GrBackend;
30 fGLSync = sync;
31 fIsInitialized = true;
32 }
33
34#ifdef SK_VULKAN
35 void initVulkan(VkSemaphore semaphore) {
36 fBackend = kVulkan_GrBackend;
37 fVkSemaphore = semaphore;
38 fIsInitialized = true;
39 }
40#endif
41
Greg Daniel8761e0c2017-07-20 16:36:01 -040042 bool isInitialized() const { return fIsInitialized; }
43
Greg Daniela5cb7812017-06-16 09:45:32 -040044 GrGLsync glSync() const {
45 if (!fIsInitialized || kOpenGL_GrBackend != fBackend) {
46 return 0;
47 }
48 return fGLSync;
49 }
50
51#ifdef SK_VULKAN
52 VkSemaphore vkSemaphore() const {
53 if (!fIsInitialized || kVulkan_GrBackend != fBackend) {
54 return VK_NULL_HANDLE;
55 }
56 return fVkSemaphore;
57 }
58#endif
59
60private:
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