blob: 828cdcb17a5dfac743497205dfc1814d92b9be4e [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"
Greg Daniela5cb7812017-06-16 09:45:32 -040014#include "vk/GrVkTypes.h"
Greg Daniela5cb7812017-06-16 09:45:32 -040015
16/**
17 * Wrapper class for passing into and receiving data from Ganesh about a backend semaphore object.
18 */
19class GrBackendSemaphore {
20public:
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.
23 GrBackendSemaphore() : fBackend(kOpenGL_GrBackend), fGLSync(0), fIsInitialized(false) {}
24
25 void initGL(GrGLsync sync) {
26 fBackend = kOpenGL_GrBackend;
27 fGLSync = sync;
28 fIsInitialized = true;
29 }
30
Greg Daniela5cb7812017-06-16 09:45:32 -040031 void initVulkan(VkSemaphore semaphore) {
32 fBackend = kVulkan_GrBackend;
33 fVkSemaphore = semaphore;
Greg Danielb4d89562018-10-03 18:44:49 +000034#ifdef SK_VULKAN
Greg Daniela5cb7812017-06-16 09:45:32 -040035 fIsInitialized = true;
Greg Danielb4d89562018-10-03 18:44:49 +000036#else
37 fIsInitialized = false;
Mike Kleina55e2142018-10-03 16:34:11 +000038#endif
Greg Danielb4d89562018-10-03 18:44:49 +000039 }
Greg Daniela5cb7812017-06-16 09:45:32 -040040
Greg Daniel8761e0c2017-07-20 16:36:01 -040041 bool isInitialized() const { return fIsInitialized; }
42
Greg Daniela5cb7812017-06-16 09:45:32 -040043 GrGLsync glSync() const {
44 if (!fIsInitialized || kOpenGL_GrBackend != fBackend) {
45 return 0;
46 }
47 return fGLSync;
48 }
49
Greg Daniela5cb7812017-06-16 09:45:32 -040050 VkSemaphore vkSemaphore() const {
51 if (!fIsInitialized || kVulkan_GrBackend != fBackend) {
52 return VK_NULL_HANDLE;
53 }
54 return fVkSemaphore;
55 }
Greg Daniela5cb7812017-06-16 09:45:32 -040056
57private:
58 GrBackend fBackend;
59 union {
60 GrGLsync fGLSync;
Greg Daniela5cb7812017-06-16 09:45:32 -040061 VkSemaphore fVkSemaphore;
Greg Daniela5cb7812017-06-16 09:45:32 -040062 };
63 bool fIsInitialized;
64};
65
66#endif