diff --git a/frontend/app/components/trace_viewer_v2/application.cc b/frontend/app/components/trace_viewer_v2/application.cc index fc0692021..c537131c8 100644 --- a/frontend/app/components/trace_viewer_v2/application.cc +++ b/frontend/app/components/trace_viewer_v2/application.cc @@ -180,6 +180,14 @@ EMSCRIPTEN_KEEPALIVE emscripten::val GetPresetPalettes() { return result; } +// Sets the visible time range of the timeline. `start_us` and `end_us` are in +// microseconds. This is primarily used by the Live Trace Viewer to auto-follow +// the newest sliding window as new streaming data arrives. +EMSCRIPTEN_KEEPALIVE void SetVisibleRange(double start_us, double end_us) { + Application::Instance().timeline().SetVisibleRange({start_us, end_us}); + Application::Instance().RequestRedraw(); +} + EMSCRIPTEN_BINDINGS(traceviewer) { emscripten::function("SetPalette", &SetPalette); emscripten::function("SetColor", &SetColor); @@ -194,6 +202,7 @@ EMSCRIPTEN_BINDINGS(traceviewer) { emscripten::function("RequestRedraw", &RequestRedraw); emscripten::function("SetPlaybackState", &SetPlaybackState); emscripten::function("GetPresetPalettes", &GetPresetPalettes); + emscripten::function("setVisibleRange", &SetVisibleRange); } EMSCRIPTEN_BINDINGS(colors) { diff --git a/frontend/app/components/trace_viewer_v2/main.ts b/frontend/app/components/trace_viewer_v2/main.ts index a4062c298..2682cd7cd 100644 --- a/frontend/app/components/trace_viewer_v2/main.ts +++ b/frontend/app/components/trace_viewer_v2/main.ts @@ -176,6 +176,11 @@ declare global { * off. Hover highlighting, hover events and selection are unaffected. */ SetEventTooltipEnabled?(enabled: boolean): void; + // Sets the visible time range of the timeline. Both arguments are in + // microseconds. Registered as a module-level Emscripten function (see + // `SetVisibleRange` in application.cc). Used by the Live Trace Viewer to + // auto-follow the newest sliding window as streaming data arrives. + setVisibleRange(startUs: number, endUs: number): void; canvas: HTMLCanvasElement; callMain(args: string[]): void; preinitializedWebGPUDevice: GPUDevice | null;