From 7c42713be3b2ab999da5ad79154c01e01fefce29 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 4 Dec 2026 00:12:44 +0000 Subject: [PATCH] Retro CRT: scanlines as one solid path, no vignette The full-screen repeating gradient and radial vignette doubled CPU raster time per frame in the browser bench; solid non-AA bands cost about nothing. Co-Authored-By: Claude Opus 5.5 --- app/lib/ui/theme/app_design_styles.dart | 16 +++---- app/lib/ui/theme/app_design_tokens.dart | 2 +- app/lib/ui/theme/crt_theme.dart | 5 +-- app/lib/ui/theme/design_screen_overlay.dart | 49 +++++++-------------- app/notes/design-retro-crt.md | 25 +++++++---- 5 files changed, 38 insertions(+), 59 deletions(-) diff --git a/app/lib/ui/theme/app_design_styles.dart b/app/lib/ui/theme/app_design_styles.dart index cd7647a4..43c53dc1 100644 --- a/app/lib/ui/theme/app_design_styles.dart +++ b/app/lib/ui/theme/app_design_styles.dart @@ -114,12 +114,11 @@ class ReadingType { } /// A static pattern a design lays over the whole app, painted once into its -/// own layer (see `DesignScreenOverlay`): horizontal scanlines and a soft -/// vignette darkening the corners. It never animates and never repaints with -/// the content beneath it. +/// own layer (see `DesignScreenOverlay`): horizontal scanlines. It never +/// animates and never repaints with the content beneath it. @immutable class ScreenPattern { - const ScreenPattern({required this.scanline, this.period = 3, this.vignette}); + const ScreenPattern({required this.scanline, this.period = 3}); /// The colour of each scanline's dark band (a translucent shade). final Color scanline; @@ -129,17 +128,12 @@ class ScreenPattern { /// pixel ratio. final int period; - /// The colour the corners fade to, transparent at the centre; null for - /// no vignette. - final Color? vignette; - @override bool operator ==(Object other) => other is ScreenPattern && other.scanline == scanline && - other.period == period && - other.vignette == vignette; + other.period == period; @override - int get hashCode => Object.hash(scanline, period, vignette); + int get hashCode => Object.hash(scanline, period); } diff --git a/app/lib/ui/theme/app_design_tokens.dart b/app/lib/ui/theme/app_design_tokens.dart index 9d4a9f9a..af3e286d 100644 --- a/app/lib/ui/theme/app_design_tokens.dart +++ b/app/lib/ui/theme/app_design_tokens.dart @@ -121,7 +121,7 @@ class AppDesignTokens extends ThemeExtension { final Color? monochrome; /// A static pattern painted once over the whole app (Retro CRT's - /// scanlines and vignette); null paints nothing. + /// scanlines); null paints nothing. final ScreenPattern? screen; /// How tightly the interface is packed: spacing, icon and avatar sizes, diff --git a/app/lib/ui/theme/crt_theme.dart b/app/lib/ui/theme/crt_theme.dart index 6ba7e388..e06c9ddd 100644 --- a/app/lib/ui/theme/crt_theme.dart +++ b/app/lib/ui/theme/crt_theme.dart @@ -36,10 +36,7 @@ ThemeData crtTheme( selectedRow: SelectedRowStyle.framed, monochrome: ramp.text, screen: dark - ? const ScreenPattern( - scanline: Color(0x29000000), - vignette: Color(0x47000000), - ) + ? const ScreenPattern(scanline: Color(0x29000000)) : ScreenPattern(scanline: ramp.text.withValues(alpha: 0.035)), ); final theme = terminalStructureTheme( diff --git a/app/lib/ui/theme/design_screen_overlay.dart b/app/lib/ui/theme/design_screen_overlay.dart index 3ee8dcdf..02329f5b 100644 --- a/app/lib/ui/theme/design_screen_overlay.dart +++ b/app/lib/ui/theme/design_screen_overlay.dart @@ -1,11 +1,9 @@ -import 'dart:ui' as ui; - import 'package:flutter/material.dart'; import 'app_design_tokens.dart'; /// [child] under the design's [AppDesignTokens.screen] pattern (Retro CRT's -/// scanlines and vignette), or [child] alone under a design without one. +/// scanlines), or [child] alone under a design without one. /// /// The pattern is one [CustomPaint] in its own [RepaintBoundary]: it paints /// once (again only on a resize, a pixel-ratio change or a design switch) @@ -44,9 +42,11 @@ class DesignScreenOverlay extends StatelessWidget { } } -/// Paints a [ScreenPattern]: one rectangle filled with a hard-stopped, -/// repeating vertical gradient (the scanlines, snapped to device pixels) and -/// one with a radial gradient (the vignette). Two draws, no layers. +/// Paints a [ScreenPattern]: its scanlines as one path of thin rectangles, +/// snapped to device pixels and filled solid without anti-aliasing. One draw +/// with no shader: a full-screen gradient (and a vignette tried with it) +/// doubled the CPU raster time per frame in the browser bench, while solid +/// bands touch only a third of the pixels and blend at memory speed. class ScreenPatternPainter extends CustomPainter { const ScreenPatternPainter(this.pattern, this.pixelRatio); @@ -55,39 +55,20 @@ class ScreenPatternPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { - final rect = Offset.zero & size; final period = pattern.period.clamp(2, 12); final band = (period / 3).round().clamp(1, period - 1); // In logical pixels, on device-pixel boundaries. final step = period / pixelRatio; - final clear = (period - band) / period; - canvas.drawRect( - rect, + final height = band / pixelRatio; + final lines = Path(); + for (var y = step - height; y < size.height; y += step) { + lines.addRect(Rect.fromLTWH(0, y, size.width, height)); + } + canvas.drawPath( + lines, Paint() - ..shader = ui.Gradient.linear( - Offset.zero, - Offset(0, step), - [ - const Color(0x00000000), - const Color(0x00000000), - pattern.scanline, - pattern.scanline, - ], - [0, clear, clear, 1], - TileMode.repeated, - ), - ); - final vignette = pattern.vignette; - if (vignette == null) return; - canvas.drawRect( - rect, - Paint() - ..shader = ui.Gradient.radial( - rect.center, - size.longestSide * 0.75, - [const Color(0x00000000), const Color(0x00000000), vignette], - [0, 0.55, 1], - ), + ..color = pattern.scanline + ..isAntiAlias = false, ); } diff --git a/app/notes/design-retro-crt.md b/app/notes/design-retro-crt.md index 9ec71f8c..39982804 100644 --- a/app/notes/design-retro-crt.md +++ b/app/notes/design-retro-crt.md @@ -55,15 +55,22 @@ device in light mode still gets a light page. blur in the text draw, not a layer filter. - Screen (`AppDesignTokens.screen`, `ScreenPattern`): scanlines every 3 device pixels (a 1-device-pixel band of 16 % black; snapped to device - pixels so they never moiré) and a vignette fading the corners to 28 % - black. `DesignScreenOverlay` (in the `MaterialApp.builder` of the app, the - connect flow and detached windows) paints it with one `CustomPaint` in its - own `RepaintBoundary` above everything (menus and dialogs included), - `IgnorePointer`, no semantics: two gradient-filled rectangles, painted - once, repainted only on a resize, pixel-ratio or design change. No - saveLayer, no filter, no animation (so nothing for reduced motion to stop). - The app stays the Stack's first child, so a design switch does not remount - it. + pixels so they never moiré). `DesignScreenOverlay` (in the + `MaterialApp.builder` of the app, the connect flow and detached windows) + paints it with one `CustomPaint` in its own `RepaintBoundary` above + everything (menus and dialogs included), `IgnorePointer`, no semantics: + one solid, non-anti-aliased path of thin rectangles, recorded once and + re-recorded only on a resize, pixel-ratio or design change. No saveLayer, + no shader, no filter, no animation (so nothing for reduced motion to + stop). The app stays the Stack's first child, so a design switch does not + remount it. +- No vignette. The first version drew the scanlines as a full-screen + repeating gradient plus a full-screen radial vignette; the browser bench + showed those two shaded fills, replayed every frame, more than doubled the + CPU raster time of scrolling (an experiment build with the overlay but no + glow: 77 ms vs Terminal's 33 ms raster per frame; with the glow but no + overlay: 30 ms, i.e. the glow is about free). Solid bands fixed it; the + vignette was optional and is dropped. ## Tokens added to `AppDesignTokens` (defaults keep every other design)