namespace XFESystem.Desktop;
/// Explicit platform worker. Native implementations enable it only after their EH/GC preemption checks pass.
public interface IEditorBackgroundWorkScheduler
{
bool TryQueue(Action work);
}
/// Each call returns worker-owned real font metrics/rasterization, with no shared display/font-cache writes.
public interface IEditorPreparationCanvasFactory
{
IDesktopCanvas CreateEditorPreparationCanvas();
}
/// Private worker font caches. Only after publication may their owner
/// transfer them to an equivalent display canvas on the UI thread.
public interface IEditorPreparationCanvasHandoff
{
void PrepareEditorText(string text, double fontSize, string fontFamily, int fontWeight);
bool TryCompleteEditorPreparationHandoff(IDesktopCanvas target);
}
public enum EditorPreparationKind { Editor, Document, Navigation }
public sealed record EditorPreparationRequest(int WindowId, long Generation, string Source, string Path, int ViewportWidth, int ViewportHeight, long MonotonicMilliseconds = 0,
EditorPreparationKind Kind = EditorPreparationKind.Editor, bool Dark = true);
public sealed record EditorPreparationResult(IInteractiveBrowserSession? Page, string? Error, int WorkerThreadId, IDesktopCanvas? PreparedCanvas = null);
public interface IEditorPreparationOperation
{
EditorPreparationRequest Request { get; }
void Cancel();
bool TryTakeResult(out EditorPreparationResult result);
bool IsRetired => true;
void AdvanceRetirement(long monotonicMilliseconds) { }
}
public interface IEditorPreparationService
{
IEditorPreparationOperation Begin(EditorPreparationRequest request);
}
/// Safe UI-side snapshots. The actual engine and DOM remain owned by
/// the verified worker for their entire lifetime, including timers and input.
public interface IBackgroundEditorSession : IInteractiveBrowserSession
{
bool IsRetired { get; }
BackgroundEditorDiagnostics Diagnostics { get; }
long RasterPaintCount { get; }
long CachedPaintCount { get; }
bool RequestEditorReadback(Action completed);
void Cancel();
}
public sealed record BackgroundEditorDiagnostics(string MonacoProof, string LastInputTrace,
long LayoutPassCount, long ScrollLayoutReuseCount, long PackagedScriptCacheHits, long PackagedScriptPreparations,
int WorkerThreadId, string? Error = null);