blob: bf4935654c6810a578e1801a7619138fc6830739 [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.
Greg Danielbdf12ad2018-10-12 09:31:11 -040023 GrBackendSemaphore() : fBackend(GrBackendApi::kOpenGL), fGLSync(0), fIsInitialized(false) {}
Greg Daniela5cb7812017-06-16 09:45:32 -040024
25 void initGL(GrGLsync sync) {
Greg Danielbdf12ad2018-10-12 09:31:11 -040026 fBackend = GrBackendApi::kOpenGL;
Greg Daniela5cb7812017-06-16 09:45:32 -040027 fGLSync = sync;
28 fIsInitialized = true;
29 }
30
Greg Daniela5cb7812017-06-16 09:45:32 -040031 void initVulkan(VkSemaphore semaphore) {
Greg Danielbdf12ad2018-10-12 09:31:11 -040032 fBackend = GrBackendApi::kVulkan;
Greg Daniela5cb7812017-06-16 09:45:32 -040033 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 {
Greg Danielbdf12ad2018-10-12 09:31:11 -040044 if (!fIsInitialized || GrBackendApi::kOpenGL != fBackend) {
Greg Daniela5cb7812017-06-16 09:45:32 -040045 return 0;
46 }
47 return fGLSync;
48 }
49
Greg Daniela5cb7812017-06-16 09:45:32 -040050 VkSemaphore vkSemaphore() const {
Greg Danielbdf12ad2018-10-12 09:31:11 -040051 if (!fIsInitialized || GrBackendApi::kVulkan != fBackend) {
Greg Daniela5cb7812017-06-16 09:45:32 -040052 return VK_NULL_HANDLE;
53 }
54 return fVkSemaphore;
55 }
Greg Daniela5cb7812017-06-16 09:45:32 -040056
57private:
Greg Danielbdf12ad2018-10-12 09:31:11 -040058 GrBackendApi fBackend;
Greg Daniela5cb7812017-06-16 09:45:32 -040059 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