Commit graph

64 commits

Author SHA1 Message Date
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
9a377b6155 macos: add headless texture tests (Kitedesk T-4204)
Standalone Objective-C tests for the macOS texture, built against
FlutterMacOS.framework of the active Flutter SDK by macos/test/run_tests.sh
(optionally with ASan or TSan). The plugin sources are compiled into the
test; the plugin registers through a fake plugin registrar and is driven
through handleMethodCall:result:. The fake engine follows
FlutterTextureRegistrar.mm and FlutterExternalTexture.mm of engine a18df97c:
the texture id is the texture's address, the registrar keeps registered
textures, and copyPixelBuffer is wrapped into a Metal texture whose
CVMetalTexture and pixel buffer are released at once while the Metal texture
stays drawn. Frames come through FlutterRgbaRendererPluginOnRgba on a thread
without an autorelease pool. Memory is the task's phys_footprint, which counts
IOSurfaces, read after the engine's CVMetalTextureCache has let go of what it
wrapped (it keeps that until it makes a texture a second later, measured);
it is not checked under ASan, whose shadow of each new IOSurface mapping
counts in it. No app, window or screen capture.

On 50efc18e ten of the thirteen tests fail (Mac mini M4, macOS 26.5.2):
every frame gets a new IOSurface (60 for 60 frames), the raster thread waits
for the copy (median 0.9 to 1.1 ms in three runs, up to 537 of 600 calls over
1 ms, with 4K frames), frames are announced off the main thread, closed
textures keep their last frame (634 MB more after 20 4K textures) and still
take and announce late frames, a texture closed with recycle is never freed,
and rows of another stride than the pixel buffer's are copied in one piece
(shifted rows for 1366, 1001, 1279 and 3838 pixels wide with stride_align 1,
and 1001 with 256), short frames included. The two tests on frames the engine
was handed pass, as no buffer is ever written twice yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 09:56:22 +09:00
50efc18ec5 G26: keep Windows textures alive through asynchronous unregister
Retain closed raw-pointer identities for late frames, release frame buffers
after engine completion, and serialize termination with decoded frame writes.
Add native regression controls for held raster buffers, inline completion,
failed raster posts, missing registrations, teardown and concurrent closure.

B252; Apache-2.0 dependency license and upstream history preserved.
2026-10-29 12:13:44 +09:00
8cd34a80ff linux: recycle closed textures per engine, closeTexture(recycle:) (Kitedesk B212)
Each session created a new TextureRgba and closeTexture never released it, so
the engine's FlPixelBufferTexture kept its GL texture (one frame of GPU or,
with llvmpipe, process memory per session). Releasing the object is not safe:
FlPixelBufferTexture deletes its GL texture in dispose without selecting a GL
context, so a release from another window deletes that window's texture of
the same name (upstream PR #2 turned the remaining window white).

closeTexture(key, recycle: true) now keeps the texture in a list of the
plugin instance, i.e. of the engine (window) that created it, and the next
createTexture of that engine registers it again. Its GL texture is only ever
touched by that engine's populate in its own context, nothing is released,
and the GL memory is bounded by the number of textures a window had open at
once. When the engine goes away the recycled textures stay referenced for the
same reason. Without recycle (old callers, or a tab that moves to another
window while its session still holds the pointer) a closed texture stays
terminated and is never handed out again.

With no frame waiting, copy_pixels hands out one transparent pixel instead
of no buffer, so a recycled texture cannot show the last frame of its previous
session before the first new frame.

Dart: closeTexture(int key, {bool recycle = false}) sends "recycle"; other
platforms ignore it. Tests: all ten Linux lifecycle tests pass (clang and
gcc, -Wall -Werror, also under ASan/UBSan); Dart 4/4.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-11 15:38:06 +09:00
48fa1d7ddf linux: free frame buffers on closeTexture and in finalize (Kitedesk B212)
closeTexture marked the texture terminated but kept the frame last handed to
the engine and any frame still waiting, and TextureRgba had no finalize, so
each closed session kept one or two frame-sized buffers forever (2 x
width x height x 4 bytes measured per 1080p session).

terminate now frees both buffers under the texture mutex: the texture is
already unregistered and OnRgba stops copying once terminated is set. A
finalize frees them as well. GObject and GL lifetime are unchanged here.

Tests: close_frees_frame_buffers, closed_texture_ignores_late_frames,
finalize_frees_frame_buffers and frames_racing_close pass (also under ASan);
the four recycling tests still fail.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-11 15:34:27 +09:00
ec78a48bd9 linux: add texture lifecycle tests (Kitedesk B212)
Standalone C++ tests for the Linux texture, built against the engine of the
active Flutter SDK by linux/test/run_tests.sh (optionally with ASan/UBSan).
The plugin source is compiled into the test and driven through a real
FlMethodChannel on fake engine objects (binary messenger, texture registrar
with the reference rules of engine a18df97c, plugin registrar); frame
buffers copied with new[] are counted.

On 42797e0f eight of the ten tests fail: closing a texture keeps both frame
buffers, the GObject has no finalize, and closed textures are never reused,
so every session leaves a frame buffer and an engine GL texture behind.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-11 15:33:50 +09:00
RustDesk
42797e0f03
Merge pull request #1 from 21pages/rm_switch_rgba
Remove switch rgba
2024-11-27 13:01:19 +09:00
21pages
c615e9507a windows: avoid unnecessary memory allocation
Signed-off-by: 21pages <sunboeasy@gmail.com>
2024-11-27 03:48:28 +08:00
21pages
96ed6df4a9 remove switch rgba
Signed-off-by: 21pages <sunboeasy@gmail.com>
2024-11-26 22:02:57 +08:00
Kingtous
c5922f891f bump: 0.0.16 2023-03-25 21:35:14 +08:00
Kingtous
bca854ff18 opt: remove len check 2023-03-25 21:34:25 +08:00
Kingtous
785c34f36b bump: 0.0.15 2023-03-23 23:34:09 +08:00
Kingtous
40fd713395 fix: remove unnecessary rgba class func pointer 2023-03-21 21:17:43 +08:00
Kingtous
937c10ffd9 bump: 0.0.13 2023-03-14 06:07:04 +00:00
fufesou
b91e1b2092
fix memory leak on macOS (#9)
Signed-off-by: fufesou <shuanglongchen@yeah.net>
2023-03-14 12:44:36 +08:00
Kingtous
f15e5eee20 bump: 0.0.12 2023-03-03 02:16:13 +00: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
1c79d8dd88 bump: 0.0.11 2023-03-01 08:54:55 +08:00
Chieh Wang
11cf53bac6
fix compile err (#5)
texture_rgba_renderer.h:86:19: error: assigning to 'const uint8_t *' (aka 'const unsigned char *') from incompatible type 'void *'
2023-03-01 08:53:00 +08:00
Kingtous
8208587b23 refactor: use instance instead 2023-02-28 19:25:22 +08:00
Kingtous
8682d1d564 bump: 0.0.10 2023-02-28 17:04:06 +08:00
Kingtous
bcd8fad1c0 refactor: change to pixel rgba 2023-02-28 17:00:48 +08:00
Kingtous
c37336cd9b opt: try to fix the memory corrupt issue on Linux 2023-02-28 15:37:20 +08:00
Kingtous
c3297dfd05 opt: move unordered_map to the global 2023-02-28 10:52:59 +08:00
Kingtous
686d6edaa5 fix: linux read on write 2023-02-21 16:39:28 +08:00
fufesou
69a51033bf
Win bg fg buffer (#4)
* better frame available

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

* fix win, bg fg buffers

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

* swap -1

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

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
2023-02-21 09:03:18 +08:00
fufesou
749acc2f87
fix win crash (#3)
* fix win crash

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

* better lock guard

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

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
2023-02-20 23:16:44 +08:00
Kingtous
1306df8554 opt: only show Native 2023-02-20 17:58:19 +08:00
Kingtous
05a3bfc959 opt: add example 2023-02-20 17:31:34 +08:00
Kingtous
f898d19a27 add: bench 2023-02-20 16:46:45 +08:00
Kingtous
f49e41fffc update: README.md 2023-02-20 16:23:07 +08:00
Kingtous
0cda2d38d4 bump: 0.0.7 2023-02-19 23:54:22 -08:00
Kingtous
4f059a9138 fix: macos ptr access 2023-02-19 23:22:40 -08:00
Kingtous
6fd900c479 feat: texture rgba interface 2023-02-19 19:14:48 -08:00
Kingtous
44d3a78b9b bump: 0.0.6 2023-02-19 15:36:42 +08:00
Kingtous
7f6b8b0d66 update: README 2023-02-19 15:20:03 +08:00
Kingtous
7d465293fa fix: use BGRA for linux 2023-02-19 15:19:20 +08:00
Kingtous
4bdb5b430e fix: memory leak on Linux 2023-02-19 14:44:08 +08:00
Kingtous
e118e96341
win test commit (#2)
Signed-off-by: fufesou <shuanglongchen@yeah.net>
Co-authored-by: fufesou <shuanglongchen@yeah.net>
Co-authored-by: fufesou <fufesou@users.noreply.github.com>
2023-02-18 20:39:00 +08:00
Kingtous
35e480aa73 fix: may memory issue on linux 2023-02-18 19:17:07 +08:00
Kingtous
3e42db31d1 fix: linux syn 2023-02-18 19:10:08 +08:00
Kingtous
0f59fef831 feat: getTexturePtr 2023-02-18 00:53:26 +08:00
Kingtous
1a164ee5a0 feat: add onRgba c api on windows 2023-02-18 00:34:46 +08:00
Kingtous
71e77ef3cf fix: metal issue on macos 2023-02-17 22:23:39 +08:00
Kingtous
befadf9e8f bump: 0.0.5 2023-02-17 17:57:00 +08:00
Kingtous
05ef060220 opt: README 2023-02-17 01:52:57 -08:00
Kingtous
0e16af448c opt: add doc for macOS 2023-02-17 01:52:16 -08:00