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