Updated for openjdk-19-internal
[panamaz] / test-vulkan / src / zvk / PFN_vkDebugReportCallbackEXT.java
1
2 package zvk;
3
4 import java.lang.invoke.*;
5 import jdk.incubator.foreign.*;
6
7 /*
8 callback: typedef VkBool32 (*PFN_vkDebugReportCallbackEXT)(
9  VkDebugReportFlagsEXT flags,
10  VkDebugReportObjectTypeEXT objectType,
11  uint64_t object,
12  size_t location,
13  int32_t messageCode,
14  const char* pLayerPrefix,
15  const char* pMessage,
16  void* pUserData);
17 */
18 public class PFN_vkDebugReportCallbackEXT implements Memory.Addressable {
19
20         NativeSymbol symbol;
21
22         public PFN_vkDebugReportCallbackEXT(NativeSymbol symbol) {
23                 this.symbol = symbol;
24         }
25
26         public MemoryAddress address() {
27                 return symbol.address();
28         }
29
30         public interface Callback {
31                 int call(int flags, int type, long thing, long location, int code, String layer, String message);
32         }
33
34         private interface Trampoline {
35                 int call(int flags, int type, long thing, long location, int code, MemoryAddress layer, MemoryAddress message, MemoryAddress userData);
36         }
37
38         public static NativeSymbol of(Callback target, ResourceScope scope) {
39                 Trampoline trampline = (int flags, int type, long thing, long location, int code, MemoryAddress layer, MemoryAddress message, MemoryAddress userData) -> {
40                         try {
41                                 return target.call(flags, type, thing, location, code,
42                                         layer.getUtf8String(0),
43                                         message.getUtf8String(0));
44                         } catch (Exception x) {
45                         }
46                         return 0;
47                 };
48                 return Memory.upcall(trampline, "call",
49                         "(IIJJILjdk/incubator/foreign/MemoryAddress;Ljdk/incubator/foreign/MemoryAddress;Ljdk/incubator/foreign/MemoryAddress)I",
50                         FunctionDescriptor.of(
51                                 Memory.INT,
52                                 Memory.INT,
53                                 Memory.INT,
54                                 Memory.LONG,
55                                 Memory.LONG,
56                                 Memory.INT,
57                                 Memory.POINTER,
58                                 Memory.POINTER,
59                                 Memory.POINTER),
60                         scope);
61         }
62 }