|
Flutter Linux Embedder
|
|
Go to the documentation of this file.
32 using FlutterDesktopMessengerScopedLock =
33 std::unique_ptr<FlutterDesktopMessenger,
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) {}
88 const uint8_t* message,
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."
161 const uint8_t* message = data && !data->empty() ? data->data() :
nullptr;
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)) {
228 }
else if (
auto gpu_surface_texture =
229 std::get_if<GpuSurfaceTexture>(texture)) {
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();
ReplyManager(BinaryReply reply_handler_)
TextureRegistrarImpl(FlutterDesktopTextureRegistrarRef texture_registrar_ref)
FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopMessengerAddRef(FlutterDesktopMessengerRef messenger)
FLUTTER_EXPORT void FlutterDesktopMessengerUnlock(FlutterDesktopMessengerRef messenger)
BinaryMessengerImpl(FlutterDesktopMessengerRef core_messenger)
@ kFlutterDesktopGpuSurfaceTexture
static constexpr char kResizeMethod[]
FLUTTER_EXPORT int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture(FlutterDesktopTextureRegistrarRef texture_registrar, const FlutterDesktopTextureInfo *info)
bool MarkTextureFrameAvailable(int64_t texture_id) override
FLUTTER_EXPORT bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
virtual ~BinaryMessengerImpl()
FlutterDesktopPixelBufferTextureCallback callback
static constexpr char kOverflowMethod[]
FlutterDesktopTextureType type
FLUTTER_EXPORT void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, const char *channel, FlutterDesktopMessageCallback callback, void *user_data)
struct FlutterDesktopTextureRegistrar * FlutterDesktopTextureRegistrarRef
FlutterDesktopPixelBufferTextureConfig pixel_buffer_config
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
FlutterDesktopGpuSurfaceType type
const FlutterDesktopPixelBuffer * CopyPixelBuffer(size_t width, size_t height) const
FLUTTER_EXPORT void FlutterDesktopMessengerRelease(FlutterDesktopMessengerRef messenger)
FlutterDesktopGpuSurfaceTextureCallback callback
std::variant< PixelBufferTexture, GpuSurfaceTexture > TextureVariant
FLUTTER_EXPORT void FlutterDesktopMessengerSendResponse(FlutterDesktopMessengerRef messenger, const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
void ResizeChannel(BinaryMessenger *messenger, std::string name, int new_size)
virtual ~TextureRegistrarImpl()
void UnregisterTexture(int64_t texture_id, std::function< void()> callback) override
FlutterDesktopGpuSurfaceTextureConfig gpu_surface_config
FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopMessengerLock(FlutterDesktopMessengerRef messenger)
const uint8_t uint32_t uint32_t * height
static constexpr char kControlChannelName[]
void SetChannelWarnsOnOverflow(BinaryMessenger *messenger, std::string name, bool warns)
void SetMessageHandler(const std::string &channel, BinaryMessageHandler handler) override
FLUTTER_EXPORT bool FlutterDesktopMessengerSend(FlutterDesktopMessengerRef messenger, const char *channel, const uint8_t *message, const size_t message_size)
FLUTTER_EXPORT void FlutterDesktopTextureRegistrarUnregisterExternalTexture(FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id, void(*callback)(void *user_data), void *user_data)
struct FlutterDesktopMessenger * FlutterDesktopMessengerRef
std::vector< EncodableValue > EncodableList
void SendResponseData(const std::vector< uint8_t > *data)
FLUTTER_EXPORT bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id)
int64_t RegisterTexture(TextureVariant *texture) override
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler
const FlutterDesktopGpuSurfaceDescriptor * ObtainDescriptor(size_t width, size_t height) const
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
const FlutterDesktopMessageResponseHandle * response_handle
FLUTTER_EXPORT bool FlutterDesktopMessengerIsAvailable(FlutterDesktopMessengerRef messenger)
const uint8_t uint32_t * width
@ kFlutterDesktopPixelBufferTexture
static const StandardMethodCodec & GetInstance(const StandardCodecSerializer *serializer=nullptr)
void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply) const override