32using FlutterDesktopMessengerScopedLock =
45 auto* response_handle =
message->response_handle;
46 auto messenger_ptr = std::shared_ptr<FlutterDesktopMessenger>(
49 BinaryReply reply_handler = [messenger_ptr, response_handle](
51 size_t reply_size)
mutable {
53 auto lock = FlutterDesktopMessengerScopedLock(
60 if (!response_handle) {
61 std::cerr <<
"Error: Response can be set only once. Ignoring "
70 response_handle =
nullptr;
77 std::move(reply_handler));
83 : messenger_(core_messenger) {}
91 if (reply ==
nullptr) {
99 auto captures =
new Captures();
100 captures->reply = reply;
102 auto message_reply = [](
const uint8_t*
data,
size_t data_size,
104 auto captures =
reinterpret_cast<Captures*
>(
user_data);
105 captures->reply(
data, data_size);
109 messenger_, channel.c_str(),
message, message_size, message_reply,
119 handlers_.erase(channel);
125 handlers_[channel] = std::move(handler);
129 ForwardToHandler, message_handler);
137 : reply_handler_(
std::move(reply_handler)) {
138 assert(reply_handler_);
142 if (reply_handler_) {
146 <<
"Warning: Failed to respond to a message. This is a memory leak."
152 if (!reply_handler_) {
154 <<
"Error: Only one of Success, Error, or NotImplemented can be "
156 <<
" and it can be called exactly once. Ignoring duplicate result."
162 size_t message_size =
data ?
data->size() : 0;
163 reply_handler_(
message, message_size);
164 reply_handler_ =
nullptr;
182 auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
187 control_channel->InvokeMethod(
197 auto control_channel = std::make_unique<MethodChannel<EncodableValue>>(
213 : texture_registrar_ref_(texture_registrar_ref) {}
219 if (
auto pixel_buffer_texture = std::get_if<PixelBufferTexture>(
texture)) {
221 info.pixel_buffer_config.user_data = pixel_buffer_texture;
222 info.pixel_buffer_config.callback =
228 }
else if (
auto gpu_surface_texture =
229 std::get_if<GpuSurfaceTexture>(
texture)) {
231 info.gpu_surface_config.struct_size =
233 info.gpu_surface_config.type = gpu_surface_texture->surface_type();
234 info.gpu_surface_config.user_data = gpu_surface_texture;
235 info.gpu_surface_config.callback =
242 std::cerr <<
"Attempting to register unknown texture variant." << std::endl;
247 texture_registrar_ref_, &
info);
260 texture_registrar_ref_,
texture_id,
nullptr,
nullptr);
267 auto captures =
new Captures();
268 captures->callback = std::move(
callback);
272 auto captures =
reinterpret_cast<Captures*
>(opaque);
273 captures->callback();
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static NSString *const kOverflowMethod
static NSString *const kResizeMethod
virtual ~BinaryMessengerImpl()
BinaryMessengerImpl(FlutterDesktopMessengerRef core_messenger)
void SetMessageHandler(const std::string &channel, BinaryMessageHandler handler) override
void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply) const override
static const StandardMethodCodec & GetInstance(const StandardCodecSerializer *serializer=nullptr)
int64_t RegisterTexture(TextureVariant *texture) override
bool MarkTextureFrameAvailable(int64_t texture_id) override
TextureRegistrarImpl(FlutterDesktopTextureRegistrarRef texture_registrar_ref)
void UnregisterTexture(int64_t texture_id, std::function< void()> callback) override
virtual ~TextureRegistrarImpl()
ReplyManager(BinaryReply reply_handler_)
void SendResponseData(const std::vector< uint8_t > *data)
static constexpr char kControlChannelName[]
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
struct FlutterDesktopTextureRegistrar * FlutterDesktopTextureRegistrarRef
@ kFlutterDesktopGpuSurfaceTexture
@ kFlutterDesktopPixelBufferTexture
Dart_NativeFunction function
void SetChannelWarnsOnOverflow(BinaryMessenger *messenger, std::string name, bool warns)
void ResizeChannel(BinaryMessenger *messenger, std::string name, int new_size)
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
DEF_SWITCHES_START aot vmservice shared library name
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
std::vector< EncodableValue > EncodableList
std::variant< PixelBufferTexture, GpuSurfaceTexture > TextureVariant
void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, const char *channel, FlutterDesktopMessageCallback callback, void *user_data)
int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture(FlutterDesktopTextureRegistrarRef texture_registrar, const FlutterDesktopTextureInfo *info)
void FlutterDesktopMessengerSendResponse(FlutterDesktopMessengerRef messenger, const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id)
FlutterDesktopMessengerRef FlutterDesktopMessengerLock(FlutterDesktopMessengerRef messenger)
void FlutterDesktopTextureRegistrarUnregisterExternalTexture(FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id, void(*callback)(void *user_data), void *user_data)
bool FlutterDesktopMessengerIsAvailable(FlutterDesktopMessengerRef messenger)
bool FlutterDesktopMessengerSend(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size)
void FlutterDesktopMessengerUnlock(FlutterDesktopMessengerRef messenger)
void FlutterDesktopMessengerRelease(FlutterDesktopMessengerRef messenger)
FlutterDesktopMessengerRef FlutterDesktopMessengerAddRef(FlutterDesktopMessengerRef messenger)