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
C++
44 lines
1.5 KiB
C++
// Modified by the Kitedesk fork (2026, B252): closeTexture keeps the texture
|
|
// alive until the engine has unregistered it, and for good unless "recycle"
|
|
// says that nothing pushes frames to its pointer any more.
|
|
|
|
#ifndef FLUTTER_PLUGIN_TEXTURE_RGBA_RENDERER_PLUGIN_H_
|
|
#define FLUTTER_PLUGIN_TEXTURE_RGBA_RENDERER_PLUGIN_H_
|
|
|
|
#include <flutter/method_channel.h>
|
|
#include <flutter/plugin_registrar_windows.h>
|
|
#include <flutter/texture_registrar.h>
|
|
#include "texture_rgba.h"
|
|
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
|
|
namespace texture_rgba_renderer {
|
|
|
|
class TextureRgbaRendererPlugin : public flutter::Plugin {
|
|
public:
|
|
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
|
|
|
|
TextureRgbaRendererPlugin();
|
|
|
|
virtual ~TextureRgbaRendererPlugin();
|
|
|
|
// Disallow copy and assign.
|
|
TextureRgbaRendererPlugin(const TextureRgbaRendererPlugin&) = delete;
|
|
TextureRgbaRendererPlugin& operator=(const TextureRgbaRendererPlugin&) = delete;
|
|
|
|
flutter::TextureRegistrar* texture_registrar;
|
|
std::unordered_map<int64_t, std::unique_ptr<TextureRgba>> textures_;
|
|
|
|
private:
|
|
// Called when a method is called on this plugin's channel from Dart.
|
|
void HandleMethodCall(
|
|
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
|
|
|
void CloseTexture(std::unique_ptr<TextureRgba> texture, bool recycle);
|
|
};
|
|
|
|
} // namespace texture_rgba_renderer
|
|
|
|
#endif // FLUTTER_PLUGIN_TEXTURE_RGBA_RENDERER_PLUGIN_H_
|