xref: /aosp_15_r20/external/skia/include/gpu/ganesh/GrBackendSemaphore.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 
8 #ifndef GrBackendSemaphore_DEFINED
9 #define GrBackendSemaphore_DEFINED
10 
11 #include "include/gpu/ganesh/GrTypes.h"  // IWYU pragma: keep
12 #include "include/private/base/SkAPI.h"
13 #include "include/private/base/SkAnySubclass.h"
14 
15 #ifdef SK_DIRECT3D
16 #include "include/private/gpu/ganesh/GrD3DTypesMinimal.h"
17 #endif
18 
19 #include <cstddef>
20 
21 class GrBackendSemaphoreData;
22 
23 /**
24  * Wrapper class for passing into and receiving data from Ganesh about a backend semaphore object.
25  */
26 class SK_API GrBackendSemaphore {
27 public:
28     // The GrBackendSemaphore cannot be used until either init* is called, which will set the
29     // appropriate GrBackend.
30     GrBackendSemaphore();
31     ~GrBackendSemaphore();
32     GrBackendSemaphore(const GrBackendSemaphore&);
33     GrBackendSemaphore& operator=(const GrBackendSemaphore&);
34 
35 #ifdef SK_DIRECT3D
initDirect3D(const GrD3DFenceInfo & info)36     void initDirect3D(const GrD3DFenceInfo& info) {
37         fBackend = GrBackendApi::kDirect3D;
38         this->assignD3DFenceInfo(info);
39         fIsInitialized = true;
40     }
41 #endif
42 
isInitialized()43     bool isInitialized() const { return fIsInitialized; }
backend()44     GrBackendApi backend() const { return fBackend; }
45 
46 #ifdef SK_DIRECT3D
47     bool getD3DFenceInfo(GrD3DFenceInfo* outInfo) const;
48 #endif
49 
50 private:
51     friend class GrBackendSemaphorePriv;
52     friend class GrBackendSemaphoreData;
53     // Size determined by looking at the GrBackendSemaphoreData subclasses, then
54     // guessing-and-checking. Compiler will complain if this is too small - in that case,
55     // just increase the number.
56     inline constexpr static size_t kMaxSubclassSize = 24;
57     using AnySemaphoreData = SkAnySubclass<GrBackendSemaphoreData, kMaxSubclassSize>;
58 
59     template <typename SemaphoreData>
GrBackendSemaphore(GrBackendApi api,SemaphoreData data)60     GrBackendSemaphore(GrBackendApi api, SemaphoreData data) : fBackend(api), fIsInitialized(true) {
61         fSemaphoreData.emplace<SemaphoreData>(data);
62     }
63 
64 #ifdef SK_DIRECT3D
65     void assignD3DFenceInfo(const GrD3DFenceInfo& info);
66 #endif
67 
68     GrBackendApi fBackend;
69     AnySemaphoreData fSemaphoreData;
70 
71     union {
72         void* fPlaceholder;  // TODO(293490566)
73 #ifdef SK_DIRECT3D
74         GrD3DFenceInfo* fD3DFenceInfo;
75 #endif
76     };
77     bool fIsInitialized;
78 };
79 
80 #endif
81