xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/metal/SyncMtl.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright (c) 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // SyncMtl:
7 //    Defines the class interface for SyncMtl, implementing SyncImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_METAL_SYNCMTL_H_
11 #define LIBANGLE_RENDERER_METAL_SYNCMTL_H_
12 
13 #include <optional>
14 
15 #include "libANGLE/renderer/EGLSyncImpl.h"
16 #include "libANGLE/renderer/FenceNVImpl.h"
17 #include "libANGLE/renderer/SyncImpl.h"
18 #include "libANGLE/renderer/metal/mtl_common.h"
19 
20 namespace egl
21 {
22 class AttributeMap;
23 }
24 
25 namespace rx
26 {
27 
28 class ContextMtl;
29 
30 namespace mtl
31 {
32 class SyncImpl;
33 }  // namespace mtl
34 
35 class FenceNVMtl : public FenceNVImpl
36 {
37   public:
38     FenceNVMtl();
39     ~FenceNVMtl() override;
40     void onDestroy(const gl::Context *context) override;
41     angle::Result set(const gl::Context *context, GLenum condition) override;
42     angle::Result test(const gl::Context *context, GLboolean *outFinished) override;
43     angle::Result finish(const gl::Context *context) override;
44 
45   private:
46     std::unique_ptr<mtl::SyncImpl> mSync;
47 };
48 
49 class SyncMtl : public SyncImpl
50 {
51   public:
52     SyncMtl();
53     ~SyncMtl() override;
54 
55     void onDestroy(const gl::Context *context) override;
56 
57     angle::Result set(const gl::Context *context, GLenum condition, GLbitfield flags) override;
58     angle::Result clientWait(const gl::Context *context,
59                              GLbitfield flags,
60                              GLuint64 timeout,
61                              GLenum *outResult) override;
62     angle::Result serverWait(const gl::Context *context,
63                              GLbitfield flags,
64                              GLuint64 timeout) override;
65     angle::Result getStatus(const gl::Context *context, GLint *outResult) override;
66 
67   private:
68     std::unique_ptr<mtl::SyncImpl> mSync;
69 };
70 
71 class EGLSyncMtl final : public EGLSyncImpl
72 {
73   public:
74     EGLSyncMtl();
75     ~EGLSyncMtl() override;
76 
77     void onDestroy(const egl::Display *display) override;
78 
79     egl::Error initialize(const egl::Display *display,
80                           const gl::Context *context,
81                           EGLenum type,
82                           const egl::AttributeMap &attribs) override;
83     egl::Error clientWait(const egl::Display *display,
84                           const gl::Context *context,
85                           EGLint flags,
86                           EGLTime timeout,
87                           EGLint *outResult) override;
88     egl::Error serverWait(const egl::Display *display,
89                           const gl::Context *context,
90                           EGLint flags) override;
91     egl::Error getStatus(const egl::Display *display, EGLint *outStatus) override;
92 
93     egl::Error copyMetalSharedEventANGLE(const egl::Display *display, void **result) const override;
94     egl::Error dupNativeFenceFD(const egl::Display *display, EGLint *result) const override;
95 
96   private:
97     mtl::AutoObjCPtr<id<MTLSharedEvent>> mSharedEvent;
98 
99     std::unique_ptr<mtl::SyncImpl> mSync;
100 };
101 
102 }  // namespace rx
103 
104 #endif
105