Windows: closeTexture hands the texture to UnregisterTexture's callback and frees its frame buffers there; frames pushed after close are dropped. Without "recycle" the object is kept for the process lifetime (the session may still hold its pointer); an engine that shuts down keeps its open textures the same way. A duplicate createTexture key gets -1, getTexturePtr of an unknown key 0. macOS: closeTexture drops the frame and closes the texture to later frames; only "recycle" removes it from the plugin. Linux: the frame handed to the engine last is freed at that engine's next copy_pixels or once the engine has shut down, not at close: from Flutter 3.32 the raster thread can still be uploading it. Tests: windows/test/run_tests.sh (plain, --asan, --tsan) and linux/test/run_tests.sh (plain, --asan). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
1.5 KiB
Dart
44 lines
1.5 KiB
Dart
// Modified by the Kitedesk fork (2026, B212, B252): closeTexture takes
|
|
// `recycle`.
|
|
import 'dart:typed_data';
|
|
|
|
export './texture_rgba_ffi.dart' show Native;
|
|
|
|
import 'texture_rgba_renderer_platform_interface.dart';
|
|
|
|
class TextureRgbaRenderer {
|
|
/// Create a texture with unique [key].
|
|
///
|
|
/// @return a texture id which can be used with
|
|
/// ```dart
|
|
/// Texture(textureId: textureId)
|
|
/// ```
|
|
Future<int> createTexture(int key) {
|
|
return TextureRgbaRendererPlatform.instance.createTexture(key);
|
|
}
|
|
|
|
/// Close a texture with unique identifier [key].
|
|
///
|
|
/// Pass [recycle] = true only when nothing calls `onRgba` with the pointer
|
|
/// from [getTexturePtr] any more: Linux then keeps the texture for the next
|
|
/// [createTexture] of the same window, and Windows and macOS release it.
|
|
/// Without it the texture stays a valid object that drops the frames still
|
|
/// pushed to that pointer (Kitedesk fork, B212, B252).
|
|
///
|
|
/// @return a boolean to indicate whether the operation is sucessfully executed.
|
|
Future<bool> closeTexture(int key, {bool recycle = false}) {
|
|
return TextureRgbaRendererPlatform.instance
|
|
.closeTexture(key, recycle: recycle);
|
|
}
|
|
|
|
/// Provide the rgba data to the texture.
|
|
Future<bool> onRgba(
|
|
int key, Uint8List data, int height, int width, int strideAlign) {
|
|
return TextureRgbaRendererPlatform.instance
|
|
.onRgba(key, data, height, width, strideAlign);
|
|
}
|
|
|
|
Future<int> getTexturePtr(int key) {
|
|
return TextureRgbaRendererPlatform.instance.getTexturePtr(key);
|
|
}
|
|
}
|