Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

WIP - [Windows] Expose channel buffers 'resize' and 'overflow' control commands #46998

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class TestBinaryMessenger : public BinaryMessenger {
last_message_handler_ = handler;
}

void Resize(const std::string& channel, int64_t newSize) override {}

void SetWarnsOnOverflow(const std::string& channel, bool warns) override {}

std::string last_message_handler_channel() {
return last_message_handler_channel_;
}
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/common/client_wrapper/binary_messenger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class BinaryMessengerImpl : public BinaryMessenger {
void SetMessageHandler(const std::string& channel,
BinaryMessageHandler handler) override;

// |flutter::BinaryMessenger|
void Resize(const std::string& channel, int64_t newSize) override;

// |flutter::BinaryMessenger|
void SetWarnsOnOverflow(const std::string& channel, bool warns) override;

private:
// Handle for interacting with the C API.
FlutterDesktopMessengerRef messenger_;
Expand Down
9 changes: 9 additions & 0 deletions shell/platform/common/client_wrapper/core_implementations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ void BinaryMessengerImpl::SetMessageHandler(const std::string& channel,
ForwardToHandler, message_handler);
}

void BinaryMessengerImpl::Resize(const std::string& channel, int64_t newSize) {
FlutterDesktopMessengerResize(messenger_, channel.c_str(), newSize);
}

void BinaryMessengerImpl::SetWarnsOnOverflow(const std::string& channel,
bool warns) {
// TODO(bleroux).
}

// ========== engine_method_result.h ==========

namespace internal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class TestBinaryMessenger : public BinaryMessenger {
last_message_handler_ = handler;
}

void Resize(const std::string& channel, int64_t newSize) override {}

void SetWarnsOnOverflow(const std::string& channel, bool warns) override {}

std::string last_message_handler_channel() {
return last_message_handler_channel_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ class BinaryMessenger {
// existing handler.
virtual void SetMessageHandler(const std::string& channel,
BinaryMessageHandler handler) = 0;

// Adjusts the number of messages that will get buffered when sending messages
// to channels that aren't fully set up yet. For example, the engine isn't
// running yet or the channel's message handler isn't set up on the Dart side
// yet.
virtual void Resize(const std::string& channel, int64_t newSize) = 0;

// Defines whether the channel should show warning messages when discarding
// messages due to overflow.
//
// When |warns| is false, the channel is expected to overflow and warning
// messages will not be shown.
virtual void SetWarnsOnOverflow(const std::string& channel, bool warns) = 0;
};

} // namespace flutter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class TestBinaryMessenger : public BinaryMessenger {
last_message_handler_ = handler;
}

void Resize(const std::string& channel, int64_t newSize) override {}

void SetWarnsOnOverflow(const std::string& channel, bool warns) override {}

bool send_called() { return send_called_; }

BinaryReply last_reply_handler() { return last_reply_handler_; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,7 @@ bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(
}
return result;
}

void FlutterDesktopMessengerResize(FlutterDesktopMessengerRef messenger,
const char* channel,
int64_t newSize) {}
5 changes: 5 additions & 0 deletions shell/platform/common/public/flutter_messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ FlutterDesktopMessengerLock(FlutterDesktopMessengerRef messenger);
FLUTTER_EXPORT void FlutterDesktopMessengerUnlock(
FlutterDesktopMessengerRef messenger);

FLUTTER_EXPORT void FlutterDesktopMessengerResize(
FlutterDesktopMessengerRef messenger,
const char* channel,
int64_t newSize);

#if defined(__cplusplus)
} // extern "C"
#endif
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/glfw/flutter_glfw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ void FlutterDesktopMessengerUnlock(FlutterDesktopMessengerRef messenger) {
messenger->GetMutex().unlock();
}

void FlutterDesktopMessengerResize(FlutterDesktopMessengerRef messenger,
const char* channel,
int64_t newSize) {}

// Retrieves state bag for the window in question from the GLFWWindow.
static FlutterDesktopWindowControllerState* GetWindowController(
GLFWwindow* window) {
Expand Down
26 changes: 26 additions & 0 deletions shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
#include <memory>
#include <vector>

#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h"
#include "flutter/shell/platform/common/incoming_message_dispatcher.h"
#include "flutter/shell/platform/common/path_utils.h"
#include "flutter/shell/platform/embedder/embedder.h"
Expand All @@ -27,6 +30,8 @@

static_assert(FLUTTER_ENGINE_VERSION == 1, "");

static constexpr char kControlChannelName[] = "dev.flutter/channel-buffer";

// Returns the engine corresponding to the given opaque API handle.
static flutter::FlutterWindowsEngine* EngineFromHandle(
FlutterDesktopEngineRef ref) {
Expand Down Expand Up @@ -381,3 +386,24 @@ bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(
return TextureRegistrarFromHandle(texture_registrar)
->MarkTextureFrameAvailable(texture_id);
}

void FlutterDesktopMessengerResize(FlutterDesktopMessengerRef messenger,
const char* channel,
int64_t newSize) {
auto binaryMessenger =
std::make_unique<flutter::BinaryMessengerImpl>(messenger);
auto controlChannel =
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
binaryMessenger.release(), kControlChannelName,
&flutter::StandardMethodCodec::GetInstance());

const flutter::StandardMethodCodec& codec =
flutter::StandardMethodCodec::GetInstance();
flutter::MethodCall<> call(
"resize",
std::make_unique<flutter::EncodableValue>(flutter::EncodableList{
flutter::EncodableValue(channel),
flutter::EncodableValue(newSize),
}));
auto encoded = codec.EncodeMethodCall(call);
}
4 changes: 4 additions & 0 deletions shell/platform/windows/testing/test_binary_messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class TestBinaryMessenger : public BinaryMessenger {
}
}

void Resize(const std::string& channel, int64_t newSize) override {}

void SetWarnsOnOverflow(const std::string& channel, bool warns) override {}

private:
// Handler to call for SendMessage.
SendHandler send_handler_;
Expand Down