Commit graph

13 commits

Author SHA1 Message Date
2a36975b62 macos: announce frames on the main queue (Kitedesk T-4204)
textureFrameAvailable was called on the thread that pushed the frame, a
Kitedesk video thread. The engine wants it on the platform thread
(Shell::OnPlatformViewMarkTextureFrameAvailable checks it, engine
a18df97c), as it wants registerTexture and unregisterTexture, which already
run there; Kitedesk's own GPU texture (KdMatoyaTexture.swift) posts its
notices the same way.

The notice is now posted to the main queue; the registry is only used on the
main thread.

Tests: frames_are_announced_on_the_main_thread passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 09:56:22 +09:00
11478d230c macos: copy frames outside the queue the raster thread waits on (Kitedesk T-4204)
The whole frame, buffer and copy included, ran in queue.sync, and the
engine's raster thread takes the newest frame in copyPixelBuffer on the same
queue, so it waited for the copy: R T-4201 measured a p90 of 4.0 ms at 60 Hz
(6.5 ms at 120 Hz), and the raster thread draws the whole window.

The frame is now copied into its pool buffer outside the queue; the queue
only guards the pool, the newest frame and the handed buffers, so it is held
for a pointer swap.

Tests: raster_does_not_wait_for_copies passes (4K frames back to back: the
raster's median wait was 0.9 to 1.1 ms in three runs, up to 537 of 600 calls
over 1 ms; now 0.003 ms, at most 0.032 ms).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 09:56:22 +09:00
7af0d01118 macos: take frame buffers from a pool, keep the two last handed (Kitedesk T-4204)
Every frame made a new IOSurface-backed CVPixelBuffer (33 MB at 4K), and
the engine let it go soon after. R T-4201 measured 2.2 to 7.8 ms per 4K
frame alone, up to 110 ms, and a 6.5 ms median at 60 fps; upstream #16922
saw 37% of the CPU and memory swings of 1.85 to 2.43 GB.

Frames now go into the buffers of a CVPixelBufferPool with IOSurface
properties, made again when the frame size changes. A pool hands a buffer
out again as soon as nobody holds it, even while its IOSurface backs a live
Metal texture (measured), and engine a18df97c lets go of the pixel buffer and
of its CVMetalTexture as soon as it has the Metal texture, which Skia then
draws until the next frame. So the texture keeps the buffers it last handed
to the engine: the one drawn, and the one drawn before it, which GPU work
queued meanwhile may still read (the plugin cannot see when the GPU is done,
flutter#157379; inferred). With the newest frame and the one being written, a
texture uses three buffers while the engine keeps up and four when it falls
behind.

Tests: pool_reuses_buffers passes (60 IOSurfaces for 60 frames of a size,
now at most 4). drawn_frame_is_not_overwritten fails when no handed buffer
is kept, frame_drawn_before_is_not_overwritten when one is; both pass with
two.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 09:56:22 +09:00
2c334da6f9 macos: copy rows of another stride one by one (Kitedesk T-4204)
FlutterRgbaRendererPluginOnRgba gets rows padded to stride_align, and the
pixel buffer has its own bytes per row ((width * 4 + 63) & ~63 on Apple
Silicon). The frame was copied in one memcpy of len bytes, so rows came out
shifted whenever the two differ: Kitedesk sends stride_align 1 for a session
drawn in software, whose "all displays" view still uses textures, and any
width that is not a multiple of 16 then shears (1366, 1001, 1279, 3838). A
stride above the pixel buffer's wrote past its data.

Rows are now copied one by one, width * 4 bytes each, when the strides
differ, and in one memcpy of the rows otherwise. A frame shorter than its
rows promise is dropped instead of being read past its end.

Tests: rows_follow_the_frame_stride and short_frames_are_dropped pass; the
other eight that failed still do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 09:56:22 +09:00
fufesou
b91e1b2092
fix memory leak on macOS (#9)
Signed-off-by: fufesou <shuanglongchen@yeah.net>
2023-03-14 12:44:36 +08:00
fufesou
8d66a7c55e
Refact/stride align (#8)
* rename row_align_bytes  to stride_align

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* trivail changes

Signed-off-by: fufesou <shuanglongchen@yeah.net>

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
2023-03-03 09:46:33 +08:00
fufesou
873919902e
Feat/row align bytes (#7)
* better bytes alignment

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* debug macos

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* debug linux

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* windows switch_rgba

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* better switch_rgba

Signed-off-by: fufesou <shuanglongchen@yeah.net>

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
2023-03-03 09:30:05 +08:00
fufesou
044bb260d9
add stride_align for onRgba (#6)
Signed-off-by: fufesou <shuanglongchen@yeah.net>
2023-03-02 21:38:55 +08:00
Kingtous
6fd900c479 feat: texture rgba interface 2023-02-19 19:14:48 -08:00
Kingtous
71e77ef3cf fix: metal issue on macos 2023-02-17 22:23:39 +08:00
Kingtous
0e16af448c opt: add doc for macOS 2023-02-17 01:52:16 -08:00
Kingtous
4221adb1cb feat: initial macos 2023-02-17 01:35:25 -08:00
Kingtous
1f012dffac add: macos impl 2023-02-17 00:55:21 -08:00