Updated for openjdk-19-internal
[panamaz] / test-vulkan / src / zvk / PFN_vkDebugUtilsMessengerCallbackEXT.java
1
2 package zvk;
3
4 import java.lang.invoke.*;
5 import jdk.incubator.foreign.*;
6
7 public class PFN_vkDebugUtilsMessengerCallbackEXT implements Memory.Addressable {
8
9         NativeSymbol symbol;
10
11         public PFN_vkDebugUtilsMessengerCallbackEXT(NativeSymbol symbol) {
12                 this.symbol = symbol;
13         }
14
15         public MemoryAddress address() {
16                 return symbol.address();
17         }
18
19         public interface Callback {
20                 int call(int severity, int flags, VkDebugUtilsMessengerCallbackDataEXT data);
21         }
22
23         private interface Trampoline {
24                 int call(int severity, int flags, MemoryAddress addr, MemoryAddress userData);
25         }
26
27         public static NativeSymbol of(Callback target, ResourceScope scope) {
28                 Trampoline trampline = (severity, flags, addr, userData) -> {
29                         try {
30                                 return target.call(severity, flags,
31                                         new VkDebugUtilsMessengerCallbackDataEXT(
32                                                 MemorySegment.ofAddress(addr,
33                                                         VkDebugUtilsMessengerCallbackDataEXT.LAYOUT.byteSize(),
34                                                         ResourceScope.globalScope())));
35                         } catch (Exception x) {
36                         }
37                         return 0;
38                 };
39                 return Memory.upcall(trampline, "call",
40                         "(IILjdk/incubator/foreign/MemoryAddress;Ljdk/incubator/foreign/MemoryAddress;)I",
41                         FunctionDescriptor.of(
42                                 Memory.INT,
43                                 Memory.INT,
44                                 Memory.INT,
45                                 Memory.POINTER,
46                                 Memory.POINTER),
47                         scope);
48         }
49 }