Commit0b033525Recorded14 Oct 2026Repositoryphantom-burn

Use shared integer view fitting without changing the compositor

Changed
 src/phantom/render.sgl     | 17 +++++++++--------
 src/phantom/view/frame.sgl | 11 +++++++++++
 test/test-frame-fit.sgl    | 23 +++++++++++++++++++++++
 3 files changed, 43 insertions(+), 8 deletions(-)
Diff
src/phantom/render.sglmodified
@@ -22,11 +22,12 @@
22
;;; off, render-post! does nothing and the composite shows the raw frame.
23
24
(define-library (phantom render)
−25
(import (sigil core)
−26
(sigil math)
+25
(import (sigil math)
26
(sigil time)
27
(sigil graphics)
28
(sigil geometry)
+29
(phantom view frame)
+30
(only (substratic view fit) fit-scale fit-x fit-y fit-w fit-h)
31
(phantom dither))
32
33
(export VIEW-W VIEW-H
@@ -51,8 +52,6 @@
52
53
(begin
54
−54
(define VIEW-W 480)
−55
(define VIEW-H 270)
55
(define NLIGHTS 24)
56
;; C-BG, the colour the distance fades to and the clear colour
57
(define BG-R (/ 13.0 255.0))
@@ -1165,7 +1164,8 @@ void main() {
1164
;; Put the frame on a w x h window at the largest whole scale that
1165
;; fits, centred; returns the scale.
1166
(define (render-composite! w h)
−1168
(let* ((k (max 1 (exact (floor (min (/ w VIEW-W) (/ h VIEW-H))))))
+1167
(let* ((fit (frame-fit w h))
+1168
(k (fit-scale fit))
1169
(css (/ k *dpr*))
1170
(_ (when (and *spread-auto* (not (= css *pixel-css*)))
1171
(set! *pixel-css* css)
@@ -1176,7 +1176,8 @@ void main() {
1176
" css-px " (number->string css)
1177
" spread " (number->string *spread*) " (auto)"))
1178
(newline)))
−1179
(ox (exact (floor (/ (- w (* VIEW-W k)) 2))))
−1180
(oy (exact (floor (/ (- h (* VIEW-H k)) 2)))))
−1181
(draw-render-target (if (or *dither* *card*) *post* *view*) ox oy (* VIEW-W k) (* VIEW-H k))
+1179
(ox (fit-x fit))
+1180
(oy (fit-y fit)))
+1181
(draw-render-target (if (or *dither* *card*) *post* *view*)
+1182
ox oy (fit-w fit) (fit-h fit))
1183
k))))
src/phantom/view/frame.sgladded
@@ -0,0 +1,11 @@
+1
;;; Phantom keeps its 480x270 view and integer-only presentation policy.
+2
(define-library (phantom view frame)
+3
(import (substratic view fit))
+4
(export VIEW-W VIEW-H frame-fit)
+5
+6
(begin
+7
(define VIEW-W 480)
+8
(define VIEW-H 270)
+9
+10
(define (frame-fit width height)
+11
(view-fit width height VIEW-W VIEW-H integer-only: #t))))
test/test-frame-fit.sgladded
@@ -0,0 +1,23 @@
+1
(import (sigil test)
+2
(phantom view frame)
+3
(substratic view fit))
+4
+5
(define (placement width height)
+6
(let ((fit (frame-fit width height)))
+7
(list (fit-mode fit) (fit-scale fit)
+8
(fit-x fit) (fit-y fit) (fit-w fit) (fit-h fit))))
+9
+10
(test-group "Phantom integer frame placement"
+11
(test "the 1440x810 native default keeps its exact 3x view"
+12
(assert-equal 480 VIEW-W)
+13
(assert-equal 270 VIEW-H)
+14
(assert-equal '(integer 3 0 0 1440 810) (placement 1440 810)))
+15
(test "odd window margins retain the old floor rounding"
+16
(assert-equal '(integer 2 20 40 960 540) (placement 1001 621)))
+17
(test "a landscape phone retains integer scale and black margins"
+18
(assert-equal '(integer 2 364 120 960 540) (placement 1688 780)))
+19
(test "a window smaller than the view keeps 1x and crops"
+20
(assert-equal '(integer 1 -90 -85 480 270) (placement 300 100))
+21
(assert-equal '(integer 1 -240 -135 480 270) (placement 0 0))))
+22
+23
(run-tests)