More engine API work

This commit is contained in:
Yoshi Askharoun
2026-07-22 18:34:57 -05:00
parent f8e3051d07
commit 679d2bb902
58 changed files with 5540 additions and 80 deletions
+9 -23
View File
@@ -1,35 +1,21 @@
using System;
using System.Collections.Concurrent;
using Microsoft.Iris.Render.Interop;
namespace Microsoft.Iris.Render.Engine;
// Maps a registered ContextID to the buffer-processing callback it should receive
// deliveries on, via SpBufferOpen -- the smallest coherent slice of "Engine core" (see
// logs/UIXrender/EngineCore.md) needed for SpRenderThreadInit and SpBufferOpen to mean
// anything together. Callback stored as a raw IntPtr (not a typed function pointer
// field) so nothing here needs to be unsafe/deal with function-pointer-as-generic-arg
// concerns; callers cast at the point they actually invoke it.
// Maps a registered ContextID to the handler it should receive deliveries on via
// SendBuffer -- the smallest coherent slice of "Engine core" (see
// logs/UIXrender/EngineCore.md) needed for StartRenderThread and SendBuffer to mean
// anything together. Holds an ordinary delegate now (not a raw callback pointer) --
// pointer marshaling, where it's still needed for native callers, lives entirely in
// Interop/EngineApi.cs.
internal static class ContextRegistry
{
internal readonly struct Entry
{
public readonly IntPtr Callback;
public readonly IntPtr CallbackData;
private static readonly ConcurrentDictionary<uint, BufferReceivedHandler> s_contexts = new();
public Entry(IntPtr callback, IntPtr callbackData)
{
Callback = callback;
CallbackData = callbackData;
}
}
private static readonly ConcurrentDictionary<uint, Entry> s_contexts = new();
public static void Register(ContextID id, IntPtr callback, IntPtr callbackData)
=> s_contexts[id.value] = new Entry(callback, callbackData);
public static void Register(ContextID id, BufferReceivedHandler handler) => s_contexts[id.value] = handler;
public static void Unregister(ContextID id) => s_contexts.TryRemove(id.value, out _);
public static bool TryGet(ContextID id, out Entry entry) => s_contexts.TryGetValue(id.value, out entry);
public static bool TryGet(ContextID id, out BufferReceivedHandler handler) => s_contexts.TryGetValue(id.value, out handler);
}