fix screenshot mem usage + fix backstage not starting after being stopped once

This commit is contained in:
KingKDot
2026-08-01 00:46:03 -05:00
parent b68a306708
commit 7b249457a1
18 changed files with 675 additions and 99 deletions
@@ -136,7 +136,7 @@ func TestHandleScreenshot_RepeatedRequestsDoNotEmitLiveFrames(t *testing.T) {
ctx := context.Background()
writer := &testWriter{}
for i, commandID := range []string{"cmd-1", "cmd-2"} {
if err := HandleScreenshot(ctx, &rt.Env{Conn: writer}, commandID, false); err != nil {
if err := HandleScreenshot(ctx, &rt.Env{Conn: writer}, commandID, false, false); err != nil {
t.Fatalf("HandleScreenshot request %d failed: %v", i+1, err)
}
}
@@ -162,3 +162,47 @@ func TestHandleScreenshot_RepeatedRequestsDoNotEmitLiveFrames(t *testing.T) {
}
}
}
func TestDashboardThumbnailCapsMultiMonitorCaptureBeforeStitching(t *testing.T) {
origMonitorCountFn := monitorCountFn
origBoundsFn := displayBoundsFn
origThumbnailCaptureFn := thumbnailCaptureDisplayFn
t.Cleanup(func() {
monitorCountFn = origMonitorCountFn
displayBoundsFn = origBoundsFn
thumbnailCaptureDisplayFn = origThumbnailCaptureFn
})
monitorCountFn = func() int { return 2 }
displayBoundsFn = func(idx int) image.Rectangle {
if idx == 0 {
return image.Rect(0, 0, 3840, 2160)
}
return image.Rect(3840, 235, 4920, 2155)
}
requestedHeights := make([]int, 0, 2)
thumbnailCaptureDisplayFn = func(display, maxHeight int) (*image.RGBA, error) {
requestedHeights = append(requestedHeights, maxHeight)
if display == 0 {
return image.NewRGBA(image.Rect(0, 0, 1920, 1080)), nil
}
return image.NewRGBA(image.Rect(0, 0, 540, 960)), nil
}
img, _, bounds, err := captureDashboardThumbnailWindows(true)
if err != nil {
t.Fatalf("capture dashboard thumbnail: %v", err)
}
if img == nil {
t.Fatal("expected dashboard thumbnail image")
}
if len(requestedHeights) != 2 || requestedHeights[0] != 1080 || requestedHeights[1] != 960 {
t.Fatalf("unexpected per-monitor capture caps: %v", requestedHeights)
}
if bounds.Dx() != 2460 || bounds.Dy() != 1080 {
t.Fatalf("expected bounded 2460x1080 canvas, got %dx%d", bounds.Dx(), bounds.Dy())
}
if got := int64(len(img.Pix)); got >= int64(4920*2160*4) {
t.Fatalf("thumbnail canvas retained native virtual-desktop allocation: %d bytes", got)
}
}