Measure the running composer border once per size
The highlight's outline was rebuilt and measured (computeMetrics) on every animation frame of a running turn, the largest app cost while a reply streams (about 600 ms of CPU over 15 s at 4K). The painter now keeps the measured outline for its size and only extracts the moving pieces per frame. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -208,4 +208,33 @@ void main() {
|
||||
// Curve metrics are approximations; a fraction of a pixel is exact enough.
|
||||
expect(_length(pieceMetrics), closeTo(20, .5));
|
||||
});
|
||||
|
||||
test('a measured outline draws the same strokes as measuring each time', () {
|
||||
final outline = Path()
|
||||
..addRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
const Rect.fromLTWH(0, 0, 300, 56),
|
||||
const Radius.circular(28),
|
||||
),
|
||||
);
|
||||
final measured = RunningOutline(outline);
|
||||
for (final progress in [0.0, 0.3, 0.97]) {
|
||||
final once = runningHighlightStrokes(
|
||||
outline: outline,
|
||||
progress: progress,
|
||||
primary: const Color(0xFF0000FF),
|
||||
tertiary: const Color(0xFFFF0000),
|
||||
);
|
||||
final kept = measured.strokes(
|
||||
progress: progress,
|
||||
primary: const Color(0xFF0000FF),
|
||||
tertiary: const Color(0xFFFF0000),
|
||||
);
|
||||
expect(kept.length, once.length);
|
||||
for (var i = 0; i < kept.length; i++) {
|
||||
expect(kept[i].color, once[i].color);
|
||||
expect(kept[i].path.getBounds(), once[i].path.getBounds());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user