Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

refactor(preview): remove the CPU and web fallbacks — one native path

Etienne Lescot2a7db1c50fae
diff --git a/src/components/ai-edition/ExportDialog.tsx b/src/components/ai-edition/ExportDialog.tsx
index 280c1a9da..2baf205d9 100644
--- a/src/components/ai-edition/ExportDialog.tsx
+++ b/src/components/ai-edition/ExportDialog.tsx
@@ -42,7 +42,6 @@ import {
} from "@/utils/aspectRatioUtils";
import { ModalShell } from "./Modals";
import styles from "./NewEditorShell.module.css";
-import { NATIVE_COMPOSITOR_ENABLED } from "./Preview";
type Phase = "idle" | "configuring" | "rendering" | "writing" | "done" | "error";
@@ -314,11 +313,11 @@ export function ExportDialog({ open, onClose, document }: ExportDialogProps) {
return;
}
- // Native compositor POC: route the real export modal to the native D3D exporter.
- // Background/layout/webcam/cursor/effects come from the same scene as the live
- // preview; size/fps/codec below are now plugged in too. Flag-gated so the web
- // exporter is the default path and untouched when the flag is off.
- if (NATIVE_COMPOSITOR_ENABLED) {
+ // MP4: the native D3D exporter is the only path (no CPU/web fallback — that
+ // path silently regressed to an ultra-slow CPU render once, which is exactly
+ // the failure mode a flag-gated fallback invites). Background/layout/webcam/
+ // cursor/effects come from the same scene as the live preview.
+ if (format === "mp4") {
setPhase("rendering");
try {
// Render the real timeline when there are clips; else fall back to the fixture.
@@ -355,6 +354,8 @@ export function ExportDialog({ open, onClose, document }: ExportDialogProps) {
return;
}
+ // GIF: no native encoder for this format yet, so this is the only
+ // implementation — not a fallback for MP4, a distinct code path.
setPhase("rendering");
const options: DocumentExportOptions = {
format,
@@ -384,18 +385,15 @@ export function ExportDialog({ open, onClose, document }: ExportDialogProps) {
}
setSavedPath(pickedPath);
setPhase("done");
- toast.success(
- format === "gif" ? t("exportDialog.exportedGif") : t("exportDialog.exportedVideo"),
- {
- description: pickedPath,
- action: {
- label: t("exportDialog.showInFolder"),
- onClick: () => {
- void window.electronAPI?.revealInFolder?.(pickedPath);
- },
+ toast.success(t("exportDialog.exportedGif"), {
+ description: pickedPath,
+ action: {
+ label: t("exportDialog.showInFolder"),
+ onClick: () => {
+ void window.electronAPI?.revealInFolder?.(pickedPath);
},
},
- );
+ });
// Touch the bridge so it stays referenced even when export
// is invoked from a non-Electron shim.
void nativeBridgeClient.aiEdition.llmGetSnapshot;
@@ -552,9 +550,7 @@ export function ExportDialog({ open, onClose, document }: ExportDialogProps) {
<div
style={{
display: "grid",
- gridTemplateColumns: NATIVE_COMPOSITOR_ENABLED
- ? "repeat(2, 1fr)"
- : "repeat(3, 1fr)",
+ gridTemplateColumns: "repeat(2, 1fr)",
gap: 6,
}}
>
@@ -563,10 +559,9 @@ export function ExportDialog({ open, onClose, document }: ExportDialogProps) {
["h264", "H.264"],
["h265", "H.265"],
// VP9 has no AMF hardware encoder on this GPU — the native pipeline
- // rejects it outright (tested: a software libvpx-vp9 fallback worked
- // but was too slow to be worth shipping). Hidden here rather than
- // left selectable-then-erroring, only while native export is active.
- ...(NATIVE_COMPOSITOR_ENABLED ? [] : [["vp9", "VP9"]]),
+ // (the only MP4 export path now) rejects it outright (tested: a
+ // software libvpx-vp9 fallback worked but was too slow to ship).
+ // Hidden here rather than left selectable-then-erroring.
] as Array<[ExportVideoCodec, string]>
).map(([value, label]) => (
<button
diff --git a/src/components/ai-edition/NativeCompositorOverlay.tsx b/src/components/ai-edition/NativeCompositorOverlay.tsx
index 030cec9b6..e12f9e37a 100644
--- a/src/components/ai-edition/NativeCompositorOverlay.tsx
+++ b/src/components/ai-edition/NativeCompositorOverlay.tsx
@@ -26,9 +26,12 @@ import { buildSceneDescription } from "@/native/sceneDescription";
* Aucun contrôle ici : paramètres via l'inspector (`setNativeParam`), lecture via
* `useNativePlaybackSync`, export via la vraie modale (`ExportDialog`).
*
- * Opt-in via le flag Vite `VITE_NATIVE_COMPOSITOR=1`.
+ * Chemin unique : c'est le SEUL renderer de preview (plus de fallback web/CPU).
+ * Monté par `PreviewCanvas` en premier enfant de `.previewFrame`, sous les
+ * calques interactifs (zoom gimbal, annotations, drag webcam) qui restent des
+ * éléments DOM cliquables au-dessus.
*/
-export function NativeCompositorOverlay({ enabled }: { enabled: boolean }) {
+export function NativeCompositorOverlay() {
const canvasRef = useRef<HTMLCanvasElement>(null);
const previousActiveClipIdRef = useRef<string | null>(null);
const document = useProjectStore((s) => s.document);
@@ -77,7 +80,7 @@ export function NativeCompositorOverlay({ enabled }: { enabled: boolean }) {
const ready = sources !== null;
const { viewId } = useNativeCompositorView(canvasRef, {
- enabled: enabled && ready,
+ enabled: ready,
sources: sources ?? undefined,
});
@@ -132,19 +135,22 @@ export function NativeCompositorOverlay({ enabled }: { enabled: boolean }) {
previousActiveClipIdRef.current = activeClip.id;
}, [viewId, document, activeClip]);
- if (!enabled) {
+ if (!ready) {
return null;
}
// The canvas's CSS box (width: 100%; height: 100%) is what drives the
// geometry; the hook manages the DRAWING BUFFER (canvas.width/height DOM
// attrs) to match the offscreen render-target resolution, and paints each
- // pulled frame via `ctx.putImageData`.
+ // pulled frame via `ctx.putImageData`. z-index 0: sits below the
+ // interactive-only DOM layers (zoom gimbal, annotations, webcam drag
+ // hitbox) that PreviewCanvas renders after it, but above nothing else —
+ // the CPU-rendered video/webcam/blur pixels it replaces are hidden via CSS.
return (
<canvas
ref={canvasRef}
data-testid="native-compositor-mount"
- style={{ position: "absolute", inset: 0, zIndex: 5, width: "100%", height: "100%" }}
+ style={{ position: "absolute", inset: 0, zIndex: 0, width: "100%", height: "100%" }}
/>
);
}
diff --git a/src/components/ai-edition/NewEditorShell.module.css b/src/components/ai-edition/NewEditorShell.module.css
index f16303839..e396623b2 100644
--- a/src/components/ai-edition/NewEditorShell.module.css
+++ b/src/components/ai-edition/NewEditorShell.module.css
@@ -736,17 +736,17 @@
letter-spacing: 0.06em;
text-transform: uppercase;
}
-.bgBlur {
- position: absolute;
- inset: 0;
- pointer-events: none;
- z-index: 0;
- transform: scale(1.06);
-}
-.previewFrame > .screenStage > video,
-.previewFrame > .screenStage > div > video {
+.previewFrame > .screenStage video {
position: relative;
z-index: 1;
+ /* Pixels come from the native canvas now; this <video> stays mounted (and
+ playing) purely as the decode/playback-clock/metadata source. A plain
+ descendant selector (not a fixed child-depth chain) is required here:
+ VirtualPreview nests the actual <video> THREE levels down
+ (.screenStage > .container > .videoFrame > video), not one or two —
+ the previous `>` chain silently never matched, leaving this video
+ fully visible (and on top of the native canvas) the whole time. */
+ visibility: hidden;
}
.pipCircle {
border-radius: 9999px !important;
@@ -771,6 +771,10 @@
width: 100%;
height: 100%;
object-fit: cover;
+ /* Native canvas already draws the composited webcam PiP; this <video> stays
+ mounted (playing) only to drive the camera's own decode/sync clock. The
+ slot div itself stays visible/clickable for the drag-to-reposition hitbox. */
+ visibility: hidden;
display: block;
}
/* ─── transport bar (lives inside .timelineHead, next to the tool icons) ─ */
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsx
index c60799171..40fccbd76 100644
--- a/src/components/ai-edition/NewEditorShell.tsx
+++ b/src/components/ai-edition/NewEditorShell.tsx
@@ -24,7 +24,7 @@ import {
UnsavedChangesModal,
type UnsavedChoice,
} from "./Modals";
-import { NATIVE_COMPOSITOR_ENABLED, Preview } from "./Preview";
+import { Preview } from "./Preview";
import v4 from "./v4/EditorShellV4.module.css";
import { type EditorMode, EditorTopBar } from "./v4/EditorTopBar";
import { type Facet, FloatingInspector } from "./v4/FloatingInspector";
@@ -1177,15 +1177,12 @@ export function NewEditorShell() {
// fixed chunk that dwarfs the card on smaller windows.
//
// Native compositor: the D3D overlay is an opaque, always-on-top
- // window that would DRAW OVER the floating inspector (airspace —
- // it can't sit behind a DOM layer), truncating the panel. The web
- // design lets the translucent panel float over the video (320 < the
- // inspector's real 380px footprint = right:20 + rail:50 + gap:10 +
- // panel:300), but in native mode we must reserve the full footprint
- // so the overlay stops clear of it (≈400 = 380 + a small gap).
- padding: `16px ${
- inspectorOpen ? (NATIVE_COMPOSITOR_ENABLED ? 400 : 320) : 74
- }px 16px 16px`,
+ // design lets the translucent panel float over the video, but the
+ // preview is now a plain in-DOM <canvas> (no OS window/airspace
+ // issue) — still reserve the inspector's real footprint (right:20 +
+ // rail:50 + gap:10 + panel:300 ≈ 380, +a small gap) so it doesn't
+ // draw its own translucent panel flush against the canvas edge.
+ padding: `16px ${inspectorOpen ? 400 : 74}px 16px 16px`,
boxSizing: "border-box",
}}
>
diff --git a/src/components/ai-edition/Preview.tsx b/src/components/ai-edition/Preview.tsx
index 957c2e733..5e1c75642 100644
--- a/src/components/ai-edition/Preview.tsx
+++ b/src/components/ai-edition/Preview.tsx
@@ -8,16 +8,11 @@ import type {
} from "@/lib/ai-edition/schema";
import type { SpeedRegion } from "@/lib/ai-edition/timeline/speed";
import { EditorEmptyState } from "./EditorEmptyState";
-import { NativeCompositorOverlay } from "./NativeCompositorOverlay";
import styles from "./NewEditorShell.module.css";
import { PreviewCanvas } from "./PreviewCanvas";
type BlurData = NonNullable<AxcutAnnotationRegion["blurData"]>;
-// POC Option A : preview rendue par la fenêtre D3D native embarquée (opt-in via flag Vite).
-export const NATIVE_COMPOSITOR_ENABLED =
- (import.meta.env as Record<string, string | undefined>).VITE_NATIVE_COMPOSITOR === "1";
-
interface PreviewProps {
hasProject: boolean;
hasAsset: boolean;
@@ -99,7 +94,6 @@ export function Preview({
data-current-time-sec={currentTimeSec.toFixed(3)}
data-is-playing={playing ? "true" : "false"}
>
- <NativeCompositorOverlay enabled={NATIVE_COMPOSITOR_ENABLED} />
{hasProject && hasAsset && !videoError ? (
<PreviewCanvas
videoSources={videoSources}
diff --git a/src/components/ai-edition/PreviewCanvas.tsx b/src/components/ai-edition/PreviewCanvas.tsx
index 6c1d5dec2..8943944bc 100644
--- a/src/components/ai-edition/PreviewCanvas.tsx
+++ b/src/components/ai-edition/PreviewCanvas.tsx
@@ -1,22 +1,20 @@
-// CSS-driven canvas shell that wraps the active source video with the
-// editor's background, frame, and overlay settings.
+// Hosts the native D3D preview canvas (the sole pixel source) plus the
+// interactive-only DOM overlays (zoom gimbal, annotations, webcam drag) that
+// still need real hitboxes. The shared source of truth is `useEditorSettings`,
+// so toggling a slider here updates both the live preview (via the pushed
+// scene) and the eventual native export.
//
-// ponytail: mouse-driven overlays (cursor, zoom, annotations) and motion blur
-// still render through the legacy canvas preview pipeline for export. The
-// shared source of truth is `useEditorSettings`, so toggling a slider here
-// updates both the live preview and the eventual render.
-//
-// Architecture (matches the legacy `compositeLayout.computeCompositeLayout`):
-// .previewFrame → canvas (wallpaper bg + blurred copy behind the
-// video when showBlur is on; never receives padding
+// Architecture (matches the legacy `compositeLayout.computeCompositeLayout`,
+// which this file still uses to POSITION the interactive overlays/hitboxes —
+// the actual pixels come from the native canvas, not from this layout):
+// .previewFrame → canvas (wallpaper bg; never receives padding
// from the slider directly).
-// .screenStage → active source video; positioned/sized by the
-// composite-layout math (PiP/dual/stack/no-cam).
-// Carries the drop-shadow that gives the active
-// recording its lifted look.
-// .webcamSlot → live WebcamOverlay container; positioned/sized
-// by the same math.
-// .bgBlur → blurred wallpaper peeking around the video.
+// .screenStage → sizes/positions the zoom/annotation overlays by
+// the composite-layout math (PiP/dual/stack/no-cam);
+// its own <video> is CSS-hidden (decode/clock only).
+// .webcamSlot → drag-to-reposition hitbox for the webcam PiP,
+// positioned by the same math; its <video> is
+// CSS-hidden too.
//
// The composite layout is computed from `.previewFrame`'s actual rendered
// size (via ResizeObserver), so the camera + screen both resize correctly
@@ -56,6 +54,7 @@ import { classifyWallpaper, resolveImageWallpaperUrl } from "@/lib/wallpaper";
import { getCssClipPath } from "@/lib/webcamMaskShapes";
import { getAspectRatioValue } from "@/utils/aspectRatioUtils";
import { AnnotationLayer } from "./AnnotationLayer";
+import { NativeCompositorOverlay } from "./NativeCompositorOverlay";
import styles from "./NewEditorShell.module.css";
import { type VideoSource, VirtualPreview } from "./VirtualPreview";
import { WebcamOverlay } from "./WebcamOverlay";
@@ -289,7 +288,6 @@ export function PreviewCanvas(props: PreviewCanvasProps) {
}, [layout, cameraFullscreenProgress, canvasSize]);
const frameStyle = useMemo(() => buildFrameStyle(settings), [settings]);
- const blurStyle = useMemo(() => buildBlurStyle(settings), [settings]);
const screenStyle = useMemo(
() => buildScreenStyle(layout, settings, canvasSize),
[layout, settings, canvasSize],
@@ -389,7 +387,14 @@ export function PreviewCanvas(props: PreviewCanvasProps) {
className={styles.previewFrame}
style={{ ...frameStyle, width: frameSize.width, height: frameSize.height }}
>
- <div className={styles.bgBlur} style={blurStyle} aria-hidden />
+ {/* Sole pixel source: the D3D-composited frame (wallpaper + screen + webcam +
+ cursor), streamed into a canvas. The <video> elements below are CSS-hidden
+ (visibility only — they stay mounted for decode/playback-clock/metadata
+ duties, since the native compositor doesn't drive playback itself), and the
+ interactive-only layers (ZoomFocusOverlay, AnnotationLayer, webcam drag
+ hitbox) still render on top as normal DOM so they stay clickable. No more
+ dual preview path. */}
+ <NativeCompositorOverlay />
{layout?.screenRect ? (
<div className={styles.screenStage} style={screenStyle}>
{(() => {
@@ -576,29 +581,6 @@ function buildWebcamStyle(
return clipPath ? { ...base, clipPath } : base;
}
-// Blurred wallpaper copy. Hidden when showBlur is off.
-function buildBlurStyle(
- settings: ReturnType<typeof useEditorSettings>["settings"],
-): React.CSSProperties {
- if (!settings.showBlur) return { display: "none" };
- const w = classifyWallpaper(settings.wallpaper);
- if (w.kind === "color") {
- return { backgroundColor: w.value, filter: "blur(28px)", opacity: 1 };
- }
- if (w.kind === "gradient") {
- return { background: w.value, backgroundSize: "cover", filter: "blur(28px)", opacity: 1 };
- }
- const url = resolveWallpaperImageUrl(w.path);
- if (!url) return { display: "none" };
- return {
- backgroundImage: `url(${url})`,
- backgroundSize: "cover",
- backgroundPosition: "center",
- filter: "blur(28px)",
- opacity: 1,
- };
-}
-
function clamp(v: number, min: number, max: number): number {
return Math.min(Math.max(v, min), max);
}
diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsx
index 9efdfa687..698ec852b 100644
--- a/src/components/ai-edition/VirtualPreview.tsx
+++ b/src/components/ai-edition/VirtualPreview.tsx
@@ -1,5 +1,4 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
-import { fromFileUrl } from "@/components/video-editor/projectPersistence";
import {
type CropRegion,
DEFAULT_CROP_REGION,
@@ -19,7 +18,6 @@ import {
computeZoomPreviewTransform,
IDENTITY_ZOOM_TRANSFORM,
} from "@/lib/ai-edition/timeline/zoom-preview";
-import { CursorPreviewLayer } from "./CursorPreviewLayer";
import styles from "./VirtualPreview.module.css";
export interface VideoSource {
@@ -107,7 +105,7 @@ export function VirtualPreview({
// matching clip, even while a later one is the one actually playing.
const activeClipIdRef = useRef<string | null>(null);
const [virtualTimeSec, setVirtualTimeSec] = useState(0);
- const [isPlaying, setIsPlaying] = useState(false);
+ const [, setIsPlaying] = useState(false);
const [loadState, setLoadState] = useState<"idle" | "loading" | "ready" | "error">("idle");
const [sourceIndex, setSourceIndex] = useState(0);
@@ -472,22 +470,9 @@ export function VirtualPreview({
</div>
)}
</div>
- {/* ponytail: CursorPreviewLayer must NOT nest inside .videoFrame — that
- container has a hardcoded `overflow: hidden` (needed for the oversized/
- offset video crop trick, see .videoFrame in the CSS module) which clips
- ANY child regardless of that child's own overflow/clip-path. A child's
- `overflow: visible` can never escape an ancestor's `overflow: hidden`, so
- the "Clip to canvas" toggle's internal CSS override was silently powerless
- whenever it lived inside .videoFrame — the cursor was always cut at the
- video frame edge no matter the setting. Rendered here as a sibling instead,
- positioned absolutely over the same box (.container has no overflow
- clipping of its own), so the toggle's own clip-path/overflow logic is the
- only thing constraining it. */}
- <CursorPreviewLayer
- videoPath={activeSource ? fromFileUrl(activeSource.src) : null}
- currentTimeSec={sourceTimeSec}
- isPlaying={isPlaying}
- />
+ {/* The native D3D canvas already draws the recorded-cursor sprite as part
+ of the composited frame (same cursor sidecar file, single source of
+ truth) — this CPU-rendered duplicate (CursorPreviewLayer) is removed. */}
</>
) : (
<div className={styles.placeholder}>Attach a video to start previewing.</div>
diff --git a/src/native/nativeCompositorStore.ts b/src/native/nativeCompositorStore.ts
index 8344753b3..7dd651b8c 100644
--- a/src/native/nativeCompositorStore.ts
+++ b/src/native/nativeCompositorStore.ts
@@ -2,7 +2,7 @@
* Petit store global de la vue native active. `NativeCompositorOverlay` crée la vue et
* enregistre son id ici ; n'importe quel contrôle (inspector, transport…) peut alors
* pousser un paramètre via `setNativeParam` sans connaître l'overlay. No-op tant qu'aucune
- * vue n'est active (flag `VITE_NATIVE_COMPOSITOR` off ou addon absent).
+ * vue n'est active (pas encore de document/asset chargé, ou addon absent).
*/
import {
setCompositorParam,