-
Notifications
You must be signed in to change notification settings - Fork 6k
Add Platform View Manager to Windows shell #50598
Changes from 7 commits
500e60c
8dd4543
ae0d049
5f14af0
200f13a
ed90810
5d410ff
484c8c1
b8fadd7
1d203f4
b9acc1a
35eb688
659ebd6
db2851b
db48ddd
f87ed96
42f976e
284b309
e000930
676868f
6e6ef7e
22a9e46
95a8498
1fa97f3
5453b29
dfa6b73
cde468e
585ca11
54d91a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
|
|
||
| #include "flutter/shell/platform/embedder/embedder.h" | ||
|
|
||
| #include "flutter/shell/platform/windows/platform_view_manager.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| // Enables the Flutter engine to render content on Windows. | ||
|
|
@@ -19,6 +21,7 @@ namespace flutter { | |
| // Platform views are not yet supported. | ||
| class Compositor { | ||
| public: | ||
| Compositor(PlatformViewManager* manager) : platform_view_manager_(manager) {} | ||
| virtual ~Compositor() = default; | ||
|
|
||
| // Creates a backing store used for rendering Flutter content. | ||
|
|
@@ -32,6 +35,9 @@ class Compositor { | |
|
|
||
| // Present Flutter content and platform views onto the view. | ||
| virtual bool Present(const FlutterLayer** layers, size_t layers_count) = 0; | ||
|
|
||
| protected: | ||
| PlatformViewManager* platform_view_manager_; | ||
|
||
| }; | ||
|
|
||
| } // namespace flutter | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
|
|
||
| import 'dart:async'; | ||
| import 'dart:io' as io; | ||
| import 'dart:typed_data' show ByteData, Uint8List; | ||
| import 'dart:typed_data' show ByteData, Endian, Uint8List; | ||
| import 'dart:ui' as ui; | ||
| import 'dart:convert'; | ||
|
|
||
|
|
@@ -159,6 +159,26 @@ void enableLifecycleToFrom() async { | |
| }); | ||
| } | ||
|
|
||
| @pragma('vm:entry-point') | ||
| void sendCreationMethod() async { | ||
loic-sharma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final List<int> data = <int>[ | ||
| // Method name | ||
| 7, 'create'.length, ...utf8.encode('create'), | ||
|
||
| // Method arguments: {'type': 'type':, 'id': 0} | ||
| 13, 2, | ||
| 7, 'type'.length, ...utf8.encode('type'), | ||
| 7, 'type'.length, ...utf8.encode('type'), | ||
| 7, 'id'.length, ...utf8.encode('id'), | ||
| 3, 0, 0, 0, 0, | ||
| ]; | ||
|
|
||
| final Completer<ByteData?> completed = Completer<ByteData?>(); | ||
cbracken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| final ByteData bytes = ByteData.sublistView(Uint8List.fromList(data)); | ||
| ui.PlatformDispatcher.instance.sendPlatformMessage('flutter/platform_views', bytes, (ByteData? response) { | ||
| completed.complete(response); | ||
| }); | ||
| } | ||
|
|
||
| @pragma('vm:entry-point') | ||
| void customEntrypoint() {} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| #include "flutter/shell/platform/windows/testing/egl/mock_manager.h" | ||
| #include "flutter/shell/platform/windows/testing/engine_modifier.h" | ||
| #include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h" | ||
| #include "flutter/shell/platform/windows/testing/mock_platform_view_manager.h" | ||
| #include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h" | ||
| #include "flutter/shell/platform/windows/testing/mock_windows_proc_table.h" | ||
| #include "flutter/shell/platform/windows/testing/test_keyboard.h" | ||
|
|
@@ -1169,5 +1170,29 @@ TEST_F(FlutterWindowsEngineTest, ChannelListenedTo) { | |
| } | ||
| } | ||
|
|
||
| TEST_F(FlutterWindowsEngineTest, ReceivePlatformViewMessage) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my understanding, this file is more for engine unit tests. Since this launches & runs a full app, should we move this to the integration tests in I don't feel strongly about this, feel free to keep as is.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to me that this test is quite similar in most regards to the handful of unit tests immediately preceding it in this file. Would you disagree?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's probably fine to land as-is, but I do think we should probably do a followup evaluation of which tests belong where. We're definitely not super consistent and to be honest, I'm not sure we've ever drawn a really clear line (not just in the Windows embedder but also on macOS). |
||
| FlutterWindowsEngineBuilder builder{GetContext()}; | ||
| builder.SetDartEntrypoint("sendCreationMethod"); | ||
| auto engine = builder.Build(); | ||
|
|
||
| EngineModifier modifier(engine.get()); | ||
yaakovschectman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; }; | ||
|
|
||
| bool received_call = false; | ||
|
|
||
| auto manager = std::make_unique<MockPlatformViewManager>(engine.get()); | ||
| EXPECT_CALL(*manager, QueuePlatformViewCreation) | ||
| .WillRepeatedly([&](std::string_view type_name, int64_t id) { | ||
| received_call = true; | ||
| }); | ||
| modifier.SetPlatformViewManager(std::move(manager)); | ||
|
|
||
| engine->Run(); | ||
|
|
||
| while (!received_call) { | ||
| engine->task_runner()->ProcessTasks(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/shell/platform/windows/platform_view_manager.h" | ||
|
|
||
| #include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| namespace { | ||
| constexpr char kChannelName[] = "flutter/platform_views"; | ||
| } | ||
|
|
||
| PlatformViewManager::PlatformViewManager(TaskRunner* task_runner, | ||
| BinaryMessenger* binary_messenger) | ||
| : task_runner_(task_runner), | ||
| channel_(std::make_unique<MethodChannel<EncodableValue>>( | ||
| binary_messenger, | ||
| kChannelName, | ||
| &StandardMethodCodec::GetInstance())) { | ||
| channel_->SetMethodCallHandler( | ||
| [this](const MethodCall<EncodableValue>& call, | ||
| std::unique_ptr<MethodResult<EncodableValue>> result) { | ||
| const auto& args = std::get<EncodableMap>(*call.arguments()); | ||
| if (call.method_name() == "create") { | ||
| const auto& type = | ||
| std::get<std::string>(args.find(EncodableValue("type"))->second); | ||
loic-sharma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const auto& id = | ||
| std::get<std::int32_t>(args.find(EncodableValue("id"))->second); | ||
loic-sharma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| QueuePlatformViewCreation(type, id); | ||
| } | ||
| result->Success(); | ||
| }); | ||
loic-sharma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| PlatformViewManager::~PlatformViewManager() {} | ||
|
|
||
| void PlatformViewManager::QueuePlatformViewCreation(std::string_view type_name, | ||
| int64_t id) {} | ||
|
|
||
| void PlatformViewManager::InstantiatePlatformView(int64_t id) {} | ||
|
|
||
| void PlatformViewManager::RegisterPlatformViewType( | ||
| std::string_view type_name, | ||
| const FlutterPlatformViewTypeEntry& type) {} | ||
|
|
||
| void PlatformViewManager::FocusPlatformView(int64_t id, | ||
| FocusChangeDirection direction, | ||
| bool focus) {} | ||
|
|
||
| std::optional<HWND> PlatformViewManager::GetNativeHandleForId( | ||
| int64_t id) const { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| } // namespace flutter | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compositoris just an interface that knows nothing about the implementation. I'd remove theplatform_view_manager_field from this type and move it to the software & opengl compositors.... but since these compositors don't use this platform view manager yet, I wouldn't update them to accept this platform view manager yet.