Viewing is open to everyone. Downloading and starring need a GitHub sign-in. Sign in with GitHub

NativeStructs.cs

v0.1.0-build.85 Latest Commit ede38f5

Size
8.3 KB
Lines
200
Language
csharp
SHA-256
492c7ed9a1be…
View on GitHub

Sign in with GitHub to download. Each download is recorded with your GitHub username.

1using System;
2using System.Runtime.InteropServices;
3
4// Managed mirrors of the C structs in include/ckey/ckey.h and
5// include/ckey/telemetry.h (CKEY_ABI_VERSION 4).
6//
7// Every struct is blittable and LayoutKind.Sequential with fields in header
8// order and the exact C field types, so the runtime applies the same natural
9// alignment the C compiler does. Pointers are IntPtr, size_t is nuint, and
10// C enums are int/uint (4 bytes on every supported ABI).
11//
12// The numbers in the comments are sizeof/offsetof on the 64-bit ABIs we ship
13// (win-x64 LLP64, linux-x64 / osx-x64 / osx-arm64 LP64), printed by
14// sdk/dotnet/native/tools/layout_probe.c and recorded in
15// sdk/dotnet/native/tools/layout_expected.txt. StructLayoutTests asserts the
16// same numbers with Marshal.SizeOf / Marshal.OffsetOf.
17namespace OpenCKey.Interop
18{
19 internal static class NativeConstants
20 {
21 internal const uint AbiVersion = 4; // CKEY_ABI_VERSION
22 internal const int ScalableVersionCount = 31; // CKEY_SCALABLE_VERSION_COUNT
23 internal const int ScalableMaxCodewordBytes = 8192; // CKEY_SCALABLE_MAX_CODEWORD_BYTES
24 internal const int LocatorPayloadBytes = 16; // CKEY_LOCATOR_PAYLOAD_BYTES
25 internal const int ExtendedPayloadMaxBytes = 2048; // CKEY_EXTENDED_PAYLOAD_MAX_BYTES
26 internal const int DiagnosticsMessageBytes = 96;
27 internal const int CertificationMessageBytes = 256;
28 internal const int TelemetryBuckets = 10; // CKEY_TELEMETRY_BUCKETS
29 internal const int TelemetryProfiles = 5; // CKEY_TELEMETRY_PROFILES
30 internal const int FieldScalable = 0, FieldLocator = 1, FieldText = 2, FieldExtended = 3; // ckey_field
31 internal const int PixelsRgba8 = 0, PixelsGray8 = 1; // ckey_pixel_format
32 internal const int PngRgba8 = 0, PngGray8 = 1, PngGray1 = 2; // ckey_png_format
33 }
34
35 /// <summary>ckey_diagnostics: size 112.</summary>
36 [StructLayout(LayoutKind.Sequential)]
37 internal unsafe struct NativeDiagnostics
38 {
39 public uint AbiVersion; // 0
40 public int Status; // 4 ckey_status
41 public uint CorrectedSymbols; // 8
42 public uint ErasuresUsed; // 12
43 public fixed byte Message[96]; // 16
44 }
45
46 /// <summary>ckey_scalable_symbol: size 8216.</summary>
47 [StructLayout(LayoutKind.Sequential)]
48 internal unsafe struct NativeScalableSymbol
49 {
50 public uint AbiVersion; // 0
51 public uint Version; // 4
52 public uint EccLevel; // 8
53 public uint Layout; // 12
54 public uint PayloadLength; // 16
55 public uint CodewordLength; // 20
56 public fixed byte Codeword[8192]; // 24
57 }
58
59 /// <summary>ckey_rgb: size 3, alignment 1.</summary>
60 [StructLayout(LayoutKind.Sequential)]
61 internal struct NativeRgb
62 {
63 public byte R, G, B;
64 }
65
66 /// <summary>ckey_style: size 96 (ABI 4 added <c>policy</c> at 92, inside the old tail padding).</summary>
67 [StructLayout(LayoutKind.Sequential)]
68 internal struct NativeStyle
69 {
70 public NativeRgb Background; // 0
71 public NativeRgb BackgroundEdge; // 3
72 public NativeRgb Ink; // 6
73 public NativeRgb InkShade; // 9
74 public NativeRgb Accent0; // 12 accents[4]
75 public NativeRgb Accent1; // 15
76 public NativeRgb Accent2; // 18
77 public NativeRgb Accent3; // 21
78 public uint AccentCount; // 24
79 public uint AccentPercent; // 28
80 public int Modules; // 32 ckey_module_shape
81 public int Rings; // 36 ckey_ring_style
82 public int Rays; // 40 ckey_ray_cap
83 // 44 4 bytes padding
84 public double Bevel; // 48
85 public double Shadow; // 56
86 public double Texture; // 64
87 public IntPtr LogoHref; // 72 const char* (UTF-8, NUL-terminated)
88 public double LogoRadius; // 80
89 public uint LogoPlate; // 88
90 public uint Policy; // 92 ckey_style_policy
91 }
92
93 /// <summary>ckey_logo_image: size 24.</summary>
94 [StructLayout(LayoutKind.Sequential)]
95 internal struct NativeLogoImage
96 {
97 public IntPtr Rgba; // 0 const uint8_t*
98 public uint Width; // 8
99 public uint Height; // 12
100 public nuint Stride; // 16
101 }
102
103 /// <summary>ckey_raster_options: size 48.</summary>
104 [StructLayout(LayoutKind.Sequential)]
105 internal struct NativeRasterOptions
106 {
107 public uint AbiVersion; // 0
108 public uint SizePx; // 4
109 public uint Policy; // 8 ckey_raster_policy
110 public uint Format; // 12 ckey_pixel_format
111 public uint Transparent; // 16
112 public uint Supersample; // 20
113 public double MinFeaturePx; // 24
114 public uint Materials; // 32
115 // 36 4 bytes padding
116 public IntPtr Logo; // 40 const ckey_logo_image*
117 }
118
119 /// <summary>ckey_backdrop: size 40.</summary>
120 [StructLayout(LayoutKind.Sequential)]
121 internal struct NativeBackdrop
122 {
123 public IntPtr Colours; // 0 const ckey_rgb*
124 public uint ColourCount; // 8
125 // 12 4 bytes padding
126 public IntPtr Rgba; // 16 const uint8_t*
127 public uint Width; // 24
128 public uint Height; // 28
129 public nuint Stride; // 32
130 }
131
132 /// <summary>ckey_scan_model: size 48.</summary>
133 [StructLayout(LayoutKind.Sequential)]
134 internal struct NativeScanModel
135 {
136 public uint AbiVersion; // 0
137 // 4 4 bytes padding
138 public double PxPerModule; // 8
139 public double BlurPx; // 16
140 public double Noise; // 24
141 public double Glare; // 32
142 public uint Trials; // 40
143 // 44 4 bytes tail padding
144 }
145
146 /// <summary>ckey_certification: size 304.</summary>
147 [StructLayout(LayoutKind.Sequential)]
148 internal unsafe struct NativeCertification
149 {
150 public uint AbiVersion; // 0
151 public uint Certified; // 4
152 public uint Policy; // 8
153 public uint Adjustments; // 12
154 public uint Trials; // 16
155 public uint TrialsPassed; // 20
156 public double MinContrast; // 24
157 public double FeatureSeparation; // 32
158 public double LogoLoad; // 40
159 public fixed byte Message[256]; // 48
160 }
161
162 /// <summary>ckey_telemetry_histogram: size 96.</summary>
163 [StructLayout(LayoutKind.Sequential)]
164 internal unsafe struct NativeTelemetryHistogram
165 {
166 public ulong Count; // 0
167 public ulong Sum; // 8
168 public fixed ulong Buckets[10]; // 16
169 }
170
171 /// <summary>ckey_telemetry_counters: size 264.</summary>
172 [StructLayout(LayoutKind.Sequential)]
173 internal unsafe struct NativeTelemetryCounters
174 {
175 public ulong SessionsStarted; // 0
176 public ulong SessionsSucceeded; // 8
177 public ulong SessionsFailed; // 16
178 public ulong Frames; // 24
179 public fixed ulong Decoded[5]; // 32
180 public NativeTelemetryHistogram TimeToDecodeMs; // 72
181 public NativeTelemetryHistogram FrameMs; // 168
182 }
183
184 /// <summary>ckey_safe_action: size 1736.</summary>
185 [StructLayout(LayoutKind.Sequential)]
186 internal unsafe struct NativeSafeAction
187 {
188 public uint AbiVersion; // 0
189 public uint Scope; // 4 ckey_safe_action_scope
190 public fixed byte Issuer[254]; // 8
191 public fixed byte App[256]; // 262
192 public fixed byte Action[65]; // 518
193 public fixed byte KeyId[33]; // 583
194 public fixed byte RequestId[65]; // 616
195 public ulong IssuedAt; // 688
196 public ulong ExpiresAt; // 696
197 public fixed byte Params[1024]; // 704
198 public nuint ParamsLength; // 1728
199 }
200}