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

Commit 22dd8a8

Browse files
committed
[Windows] Expose channel buffers 'resize' and 'overflow' control commands
1 parent d28fdb0 commit 22dd8a8

File tree

11 files changed

+83
-0
lines changed

11 files changed

+83
-0
lines changed

shell/platform/common/client_wrapper/basic_message_channel_unittests.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class TestBinaryMessenger : public BinaryMessenger {
2828
last_message_handler_ = handler;
2929
}
3030

31+
void Resize(const std::string& channel, int64_t newSize) override {}
32+
33+
void SetWarnsOnOverflow(const std::string& channel, bool warns) override {}
34+
3135
std::string last_message_handler_channel() {
3236
return last_message_handler_channel_;
3337
}

shell/platform/common/client_wrapper/binary_messenger_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class BinaryMessengerImpl : public BinaryMessenger {
3636
void SetMessageHandler(const std::string& channel,
3737
BinaryMessageHandler handler) override;
3838

39+
// |flutter::BinaryMessenger|
40+
void Resize(const std::string& channel, int64_t newSize) override;
41+
42+
// |flutter::BinaryMessenger|
43+
void SetWarnsOnOverflow(const std::string& channel, bool warns) override;
44+
3945
private:
4046
// Handle for interacting with the C API.
4147
FlutterDesktopMessengerRef messenger_;

shell/platform/common/client_wrapper/core_implementations.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ void BinaryMessengerImpl::SetMessageHandler(const std::string& channel,
127127
ForwardToHandler, message_handler);
128128
}
129129

130+
void BinaryMessengerImpl::Resize(const std::string& channel, int64_t newSize) {
131+
FlutterDesktopMessengerResize(messenger_, channel.c_str(), newSize);
132+
}
133+
134+
void BinaryMessengerImpl::SetWarnsOnOverflow(const std::string& channel,
135+
bool warns) {
136+
// TODO(bleroux).
137+
}
138+
130139
// ========== engine_method_result.h ==========
131140

132141
namespace internal {

shell/platform/common/client_wrapper/event_channel_unittests.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class TestBinaryMessenger : public BinaryMessenger {
2929
last_message_handler_ = handler;
3030
}
3131

32+
void Resize(const std::string& channel, int64_t newSize) override {}
33+
34+
void SetWarnsOnOverflow(const std::string& channel, bool warns) override {}
35+
3236
std::string last_message_handler_channel() {
3337
return last_message_handler_channel_;
3438
}

shell/platform/common/client_wrapper/include/flutter/binary_messenger.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ class BinaryMessenger {
4545
// existing handler.
4646
virtual void SetMessageHandler(const std::string& channel,
4747
BinaryMessageHandler handler) = 0;
48+
49+
// Adjusts the number of messages that will get buffered when sending messages
50+
// to channels that aren't fully set up yet. For example, the engine isn't
51+
// running yet or the channel's message handler isn't set up on the Dart side
52+
// yet.
53+
virtual void Resize(const std::string& channel, int64_t newSize) = 0;
54+
55+
// Defines whether the channel should show warning messages when discarding
56+
// messages due to overflow.
57+
//
58+
// When |warns| is false, the channel is expected to overflow and warning
59+
// messages will not be shown.
60+
virtual void SetWarnsOnOverflow(const std::string& channel, bool warns) = 0;
4861
};
4962

5063
} // namespace flutter

shell/platform/common/client_wrapper/method_channel_unittests.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class TestBinaryMessenger : public BinaryMessenger {
3232
last_message_handler_ = handler;
3333
}
3434

35+
void Resize(const std::string& channel, int64_t newSize) override {}
36+
37+
void SetWarnsOnOverflow(const std::string& channel, bool warns) override {}
38+
3539
bool send_called() { return send_called_; }
3640

3741
BinaryReply last_reply_handler() { return last_reply_handler_; }

shell/platform/common/client_wrapper/testing/stub_flutter_api.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,7 @@ bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(
159159
}
160160
return result;
161161
}
162+
163+
void FlutterDesktopMessengerResize(FlutterDesktopMessengerRef messenger,
164+
const char* channel,
165+
int64_t newSize) {}

shell/platform/common/public/flutter_messenger.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ FlutterDesktopMessengerLock(FlutterDesktopMessengerRef messenger);
137137
FLUTTER_EXPORT void FlutterDesktopMessengerUnlock(
138138
FlutterDesktopMessengerRef messenger);
139139

140+
FLUTTER_EXPORT void FlutterDesktopMessengerResize(
141+
FlutterDesktopMessengerRef messenger,
142+
const char* channel,
143+
int64_t newSize);
144+
140145
#if defined(__cplusplus)
141146
} // extern "C"
142147
#endif

shell/platform/glfw/flutter_glfw.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ void FlutterDesktopMessengerUnlock(FlutterDesktopMessengerRef messenger) {
224224
messenger->GetMutex().unlock();
225225
}
226226

227+
void FlutterDesktopMessengerResize(FlutterDesktopMessengerRef messenger,
228+
const char* channel,
229+
int64_t newSize) {}
230+
227231
// Retrieves state bag for the window in question from the GLFWWindow.
228232
static FlutterDesktopWindowControllerState* GetWindowController(
229233
GLFWwindow* window) {

shell/platform/windows/flutter_windows.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
#include <memory>
1414
#include <vector>
1515

16+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h"
17+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
1618
#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
19+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h"
1720
#include "flutter/shell/platform/common/incoming_message_dispatcher.h"
1821
#include "flutter/shell/platform/common/path_utils.h"
1922
#include "flutter/shell/platform/embedder/embedder.h"
@@ -27,6 +30,8 @@
2730

2831
static_assert(FLUTTER_ENGINE_VERSION == 1, "");
2932

33+
static constexpr char kControlChannelName[] = "dev.flutter/channel-buffer";
34+
3035
// Returns the engine corresponding to the given opaque API handle.
3136
static flutter::FlutterWindowsEngine* EngineFromHandle(
3237
FlutterDesktopEngineRef ref) {
@@ -381,3 +386,24 @@ bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(
381386
return TextureRegistrarFromHandle(texture_registrar)
382387
->MarkTextureFrameAvailable(texture_id);
383388
}
389+
390+
void FlutterDesktopMessengerResize(FlutterDesktopMessengerRef messenger,
391+
const char* channel,
392+
int64_t newSize) {
393+
auto binaryMessenger =
394+
std::make_unique<flutter::BinaryMessengerImpl>(messenger);
395+
auto controlChannel =
396+
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
397+
binaryMessenger.release(), kControlChannelName,
398+
&flutter::StandardMethodCodec::GetInstance());
399+
400+
const flutter::StandardMethodCodec& codec =
401+
flutter::StandardMethodCodec::GetInstance();
402+
flutter::MethodCall<> call(
403+
"resize",
404+
std::make_unique<flutter::EncodableValue>(flutter::EncodableList{
405+
flutter::EncodableValue(channel),
406+
flutter::EncodableValue(newSize),
407+
}));
408+
auto encoded = codec.EncodeMethodCall(call);
409+
}

0 commit comments

Comments
 (0)