GrBackendSemaphore.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef GrBackendSemaphore_DEFINED
  8. #define GrBackendSemaphore_DEFINED
  9. #include "include/gpu/GrTypes.h"
  10. #include "include/gpu/gl/GrGLTypes.h"
  11. #include "include/gpu/vk/GrVkTypes.h"
  12. /**
  13. * Wrapper class for passing into and receiving data from Ganesh about a backend semaphore object.
  14. */
  15. class GrBackendSemaphore {
  16. public:
  17. // For convenience we just set the backend here to OpenGL. The GrBackendSemaphore cannot be used
  18. // until either initGL or initVulkan are called which will set the appropriate GrBackend.
  19. GrBackendSemaphore() : fBackend(GrBackendApi::kOpenGL), fGLSync(0), fIsInitialized(false) {}
  20. void initGL(GrGLsync sync) {
  21. fBackend = GrBackendApi::kOpenGL;
  22. fGLSync = sync;
  23. fIsInitialized = true;
  24. }
  25. void initVulkan(VkSemaphore semaphore) {
  26. fBackend = GrBackendApi::kVulkan;
  27. fVkSemaphore = semaphore;
  28. #ifdef SK_VULKAN
  29. fIsInitialized = true;
  30. #else
  31. fIsInitialized = false;
  32. #endif
  33. }
  34. bool isInitialized() const { return fIsInitialized; }
  35. GrGLsync glSync() const {
  36. if (!fIsInitialized || GrBackendApi::kOpenGL != fBackend) {
  37. return 0;
  38. }
  39. return fGLSync;
  40. }
  41. VkSemaphore vkSemaphore() const {
  42. if (!fIsInitialized || GrBackendApi::kVulkan != fBackend) {
  43. return VK_NULL_HANDLE;
  44. }
  45. return fVkSemaphore;
  46. }
  47. private:
  48. GrBackendApi fBackend;
  49. union {
  50. GrGLsync fGLSync;
  51. VkSemaphore fVkSemaphore;
  52. };
  53. bool fIsInitialized;
  54. };
  55. #endif