1 module skia.GRVkBackendContext;
2 
3 import skia.DelegateProxies;
4 import skia.IDisposable;
5 import skia.SKObject;
6 import skia.SkiaApi;
7 import skia.GRVkExtensions;
8 import skia.Definitions;
9 
10 // #if THROW_OBJECT_EXCEPTIONS
11 // using GCHandle = SkiaSharp.GCHandleProxy;
12 // #endif
13 
14 class GCHandle
15 {
16 }
17 
18 public enum GCHandleType
19 {
20 	Weak = 0,
21 	WeakTrackResurrection = 1,
22 	Normal = 2,
23 	Pinned = 3
24 }
25 
26 class GRVkBackendContext : IDisposable
27 {
28 	private GRVkGetProcedureAddressDelegate getProc;
29 	private GRVkGetProcProxyDelegate getProcProxy;
30 	// private GCHandle getProcHandle;
31 	private void* getProcContext;
32 
33 	// protected virtual void Dispose (bool disposing)
34 	// {
35 	// 	if (disposing) {
36 	// 		if (getProcHandle.IsAllocated) {
37 	// 			getProcHandle.Free ();
38 	// 			getProcHandle = default;
39 	// 		}
40 	// 	}
41 	// }
42 
43 	void Dispose()
44 	{
45 		// Dispose (true);
46 		// GC.SuppressFinalize (this);
47 	}
48 
49 	void* VkInstance;
50 
51 	void* VkPhysicalDevice;
52 
53 	void* VkDevice;
54 
55 	void* VkQueue;
56 
57 	uint GraphicsQueueIndex;
58 
59 	uint MaxAPIVersion;
60 
61 	GRVkExtensions Extensions;
62 
63 	void* VkPhysicalDeviceFeatures;
64 
65 	void* VkPhysicalDeviceFeatures2;
66 
67 	GRVkGetProcedureAddressDelegate GetProcedureAddress()
68 	{
69 		return getProc;
70 	}
71 
72 	void SetProcedureAddress(GRVkGetProcedureAddressDelegate value)
73 	{
74 		getProc = value;
75 
76 		// if (getProcHandle.IsAllocated)
77 		// 	getProcHandle.Free();
78 
79 		getProcProxy = null;
80 		// getProcHandle = default;
81 		getProcContext = null;
82 
83 		if (value !is null)
84 		{
85 
86 			GRVkGetProcedureAddressDelegateWrapper wrapper = GRVkGetProcedureAddressDelegateWrapper(
87 					value);
88 
89 			void* ctx = cast(void*)&wrapper;
90 			GRVkGetProcProxyDelegate releaseProxy = DelegateProxies.GRVkGetProcDelegateProxy;
91 			getProcProxy = DelegateProxies.Create(releaseProxy, ctx);
92 			getProcContext = cast(void*) ctx;
93 		}
94 	}
95 
96 	bool ProtectedContext;
97 
98 	GRVkBackendContextNative ToNative()
99 	{
100 		GRVkBackendContextNative backendContextNative = GRVkBackendContextNative();
101 		backendContextNative.fInstance = cast(vk_instance_t*) VkInstance;
102 		backendContextNative.fDevice = cast(vk_device_t*) VkDevice;
103 		backendContextNative.fPhysicalDevice = cast(vk_physical_device_t*) VkPhysicalDevice;
104 		backendContextNative.fQueue = cast(vk_queue_t*) VkQueue;
105 		backendContextNative.fGraphicsQueueIndex = GraphicsQueueIndex;
106 		backendContextNative.fMaxAPIVersion = MaxAPIVersion;
107 		backendContextNative.fVkExtensions = cast(gr_vk_extensions_t*)(Extensions.Handle
108 				? Extensions.Handle : null);
109 		backendContextNative.fDeviceFeatures = cast(
110 				vk_physical_device_features_t*) VkPhysicalDeviceFeatures;
111 		backendContextNative.fDeviceFeatures2 = cast(
112 				vk_physical_device_features_2_t*) VkPhysicalDeviceFeatures2;
113 		backendContextNative.fGetProcUserData = getProcContext;
114 		backendContextNative.fGetProc = getProcProxy;
115 		backendContextNative.fProtectedContext = ProtectedContext ? cast(byte) 1 : cast(byte) 0;
116 
117 		return backendContextNative;
118 	}
119 
120 }