| 1 |
/* |
| 2 |
* Copyright 2023 Google LLC |
| 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 skgpu_graphite_BackendSemaphore_DEFINED |
| 9 |
#define skgpu_graphite_BackendSemaphore_DEFINED |
| 10 |
|
| 11 |
#include "include/private/base/SkAPI.h" |
| 12 |
#include "include/private/base/SkAnySubclass.h" |
| 13 |
|
| 14 |
#include <cstddef> |
| 15 |
|
| 16 |
namespace skgpu { enum class BackendApi : unsigned int; } |
| 17 |
|
| 18 |
namespace skgpu::graphite { |
| 19 |
|
| 20 |
class BackendSemaphoreData; |
| 21 |
|
| 22 |
class SK_API BackendSemaphore { |
| 23 |
public: |
| 24 |
BackendSemaphore(); |
| 25 |
|
| 26 |
BackendSemaphore(const BackendSemaphore&); |
| 27 |
|
| 28 |
~BackendSemaphore(); |
| 29 |
|
| 30 |
BackendSemaphore& operator=(const BackendSemaphore&); |
| 31 |
|
| 32 |
bool isValid() const { return fIsValid; } |
| 33 |
BackendApi backend() const { return fBackend; } |
| 34 |
|
| 35 |
private: |
| 36 |
friend class BackendSemaphoreData; |
| 37 |
friend class BackendSemaphorePriv; |
| 38 |
|
| 39 |
// Size determined by looking at the BackendSemaphoreData subclasses, then |
| 40 |
// guessing-and-checking. Compiler will complain if this is too small - in that case, just |
| 41 |
// increase the number. |
| 42 |
inline constexpr static size_t kMaxSubclassSize = 24; |
| 43 |
using AnyBackendSemaphoreData = SkAnySubclass<BackendSemaphoreData, kMaxSubclassSize>; |
| 44 |
|
| 45 |
template <typename SomeBackendSemaphoreData> |
| 46 |
BackendSemaphore(BackendApi backend, const SomeBackendSemaphoreData& data) |
| 47 |
: fBackend(backend), fIsValid(true) { |
| 48 |
fSemaphoreData.emplace<SomeBackendSemaphoreData>(data); |
| 49 |
} |
| 50 |
|
| 51 |
BackendApi fBackend; |
| 52 |
AnyBackendSemaphoreData fSemaphoreData; |
| 53 |
|
| 54 |
bool fIsValid = false; |
| 55 |
}; |
| 56 |
|
| 57 |
} // namespace skgpu::graphite |
| 58 |
|
| 59 |
#endif // skgpu_graphite_BackendSemaphore_DEFINED |
| 60 |
|