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