Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
500e60c
Define structs, class
yaakovschectman Feb 8, 2024
8dd4543
Define PV type registration runner API function
yaakovschectman Feb 8, 2024
ae0d049
Bare minimum PlatformViewHandler
yaakovschectman Feb 8, 2024
5f14af0
Compositor owns platform view manager
yaakovschectman Feb 8, 2024
200f13a
Set up for mocking
yaakovschectman Feb 8, 2024
ed90810
Add unit test
yaakovschectman Feb 13, 2024
5d410ff
Formatting
yaakovschectman Feb 13, 2024
484c8c1
License fix, await future
yaakovschectman Feb 13, 2024
b8fadd7
PR Feedback
yaakovschectman Feb 13, 2024
1d203f4
_internal header file
yaakovschectman Feb 14, 2024
b9acc1a
Wait to add manager to compositors
yaakovschectman Feb 14, 2024
35eb688
Rename fixture function
yaakovschectman Feb 14, 2024
659ebd6
Reorder parameters
yaakovschectman Feb 14, 2024
db2851b
Use constants
yaakovschectman Feb 14, 2024
db48ddd
Reorder params in test
yaakovschectman Feb 14, 2024
f87ed96
Format
yaakovschectman Feb 14, 2024
42f976e
License
yaakovschectman Feb 14, 2024
284b309
Break up PlatformViewManager
yaakovschectman Feb 16, 2024
e000930
PR Feedback
yaakovschectman Feb 16, 2024
676868f
Formatting
yaakovschectman Feb 16, 2024
6e6ef7e
PR Feedback
yaakovschectman Feb 16, 2024
22a9e46
Update shell/platform/windows/flutter_windows_engine_unittests.cc
yaakovschectman Feb 21, 2024
95a8498
Update shell/platform/windows/platform_view_manager.h
yaakovschectman Feb 21, 2024
1fa97f3
Update shell/platform/windows/public/flutter_windows.h
yaakovschectman Feb 21, 2024
5453b29
Update shell/platform/windows/flutter_windows_engine_unittests.cc
yaakovschectman Feb 21, 2024
dfa6b73
PR Feedback
yaakovschectman Feb 21, 2024
cde468e
Merge branch 'main' into win_pv_i
yaakovschectman Feb 21, 2024
585ca11
Include internal header
yaakovschectman Feb 22, 2024
54d91a3
Merge branch 'main' into win_pv_i
yaakovschectman Feb 22, 2024
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
Prev Previous commit
Next Next commit
Break up PlatformViewManager
  • Loading branch information
yaakovschectman committed Feb 16, 2024
commit 284b309bb9234c0fd258a161d127d0e8ae06fe67
2 changes: 2 additions & 0 deletions shell/platform/windows/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ source_set("flutter_windows_source") {
"platform_handler.h",
"platform_view_manager.cc",
"platform_view_manager.h",
"platform_view_plugin.cc",
"platform_view_plugin.h",
"sequential_id_generator.cc",
"sequential_id_generator.h",
"settings_plugin.cc",
Expand Down
6 changes: 3 additions & 3 deletions shell/platform/windows/flutter_windows_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ bool FlutterWindowsEngine::Run(std::string_view entrypoint) {

args.custom_task_runners = &custom_task_runners;

if (!platform_view_manager_) {
platform_view_manager_ = std::make_unique<PlatformViewManager>(
task_runner_.get(), messenger_wrapper_.get());
if (!platform_view_plugin_) {
platform_view_plugin_ = std::make_unique<PlatformViewPlugin>(
messenger_wrapper_.get(), task_runner_.get());
}
if (egl_manager_) {
auto resolver = [](const char* name) -> void* {
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/windows/flutter_windows_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "flutter/shell/platform/windows/keyboard_handler_base.h"
#include "flutter/shell/platform/windows/keyboard_key_embedder_handler.h"
#include "flutter/shell/platform/windows/platform_handler.h"
#include "flutter/shell/platform/windows/platform_view_manager.h"
#include "flutter/shell/platform/windows/platform_view_plugin.h"
#include "flutter/shell/platform/windows/public/flutter_windows.h"
#include "flutter/shell/platform/windows/settings_plugin.h"
#include "flutter/shell/platform/windows/task_runner.h"
Expand Down Expand Up @@ -430,7 +430,7 @@ class FlutterWindowsEngine {

std::shared_ptr<egl::ProcTable> gl_;

std::unique_ptr<PlatformViewManager> platform_view_manager_;
std::unique_ptr<PlatformViewPlugin> platform_view_plugin_;

FML_DISALLOW_COPY_AND_ASSIGN(FlutterWindowsEngine);
};
Expand Down
5 changes: 3 additions & 2 deletions shell/platform/windows/flutter_windows_engine_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1181,11 +1181,12 @@ TEST_F(FlutterWindowsEngineTest, ReceivePlatformViewMessage) {
bool received_call = false;

auto manager = std::make_unique<MockPlatformViewManager>(engine.get());
EXPECT_CALL(*manager, QueuePlatformViewCreation)
EXPECT_CALL(*manager, AddPlatformView)
.WillRepeatedly([&](PlatformViewId id, std::string_view type_name) {
received_call = true;
return true;
});
modifier.SetPlatformViewManager(std::move(manager));
modifier.SetPlatformViewPlugin(std::move(manager));

engine->Run();

Expand Down
47 changes: 22 additions & 25 deletions shell/platform/windows/platform_view_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ 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>>(
PlatformViewManager::PlatformViewManager(BinaryMessenger* binary_messenger)
: channel_(std::make_unique<MethodChannel<EncodableValue>>(
binary_messenger,
kChannelName,
&StandardMethodCodec::GetInstance())) {
Expand All @@ -28,31 +26,30 @@ PlatformViewManager::PlatformViewManager(TaskRunner* task_runner,
std::get<std::string>(args.find(EncodableValue("type"))->second);
const auto& id =
std::get<std::int32_t>(args.find(EncodableValue("id"))->second);
QueuePlatformViewCreation(id, type);
if (AddPlatformView(id, type)) {
result->Success();
} else {
result->Error("AddPlatformView", "Failed to add platform view");
}
return;
} else if (call.method_name() == "focus") {
const auto& id =
std::get<std::int32_t>(args.find(EncodableValue("id"))->second);
const auto& direction =
std::get<std::int32_t>(args.find(EncodableValue("direction"))->second);
const auto& focus =
std::get<bool>(args.find(EncodableValue("focus"))->second);
if (FocusPlatformView(id, static_cast<FocusChangeDirection>(direction), focus)) {
result->Success();
} else {
result->Error("FocusPlatformView", "Failed to focus platform view");
}
return;
}
result->Success();
result->NotImplemented();
});
}

PlatformViewManager::~PlatformViewManager() {}

void PlatformViewManager::QueuePlatformViewCreation(
PlatformViewId id,
std::string_view type_name) {}

void PlatformViewManager::InstantiatePlatformView(PlatformViewId id) {}

void PlatformViewManager::RegisterPlatformViewType(
std::string_view type_name,
const FlutterPlatformViewTypeEntry& type) {}

void PlatformViewManager::FocusPlatformView(PlatformViewId id,
FocusChangeDirection direction,
bool focus) {}

std::optional<HWND> PlatformViewManager::GetNativeHandleForId(
PlatformViewId id) const {
return std::nullopt;
}

} // namespace flutter
36 changes: 5 additions & 31 deletions shell/platform/windows/platform_view_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_MANAGER_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_MANAGER_H_

#include <functional>
#include <map>
#include <memory>
#include <optional>

#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
#include "flutter/shell/platform/windows/public/flutter_windows.h"
Expand All @@ -28,47 +25,24 @@ enum class FocusChangeDirection {
// method invokations from the framework.
class PlatformViewManager {
public:
PlatformViewManager(TaskRunner* task_runner,
BinaryMessenger* binary_messenger);
PlatformViewManager(BinaryMessenger* binary_messenger);

virtual ~PlatformViewManager();

// Add a new platform view instance to be lazily instantiated when it is next
// composited.
virtual void QueuePlatformViewCreation(PlatformViewId id,
std::string_view type_name);

// Create a queued platform view instance.
void InstantiatePlatformView(PlatformViewId id);

// The runner-facing API calls this method to register a window type
// corresponding to a platform view identifier supplied to the widget tree.
void RegisterPlatformViewType(std::string_view type_name,
const FlutterPlatformViewTypeEntry& type);
virtual bool AddPlatformView(PlatformViewId id,
std::string_view type_name) = 0;

// The framework may invoke this method when keyboard focus must be given to
// the platform view.
void FocusPlatformView(PlatformViewId id,
virtual bool FocusPlatformView(PlatformViewId id,
FocusChangeDirection direction,
bool focus);

// Find the HWND corresponding to a platform view id. Returns null if the id
// has no associated platform view.
std::optional<HWND> GetNativeHandleForId(PlatformViewId id) const;
bool focus) = 0;

private:
std::unique_ptr<MethodChannel<EncodableValue>> channel_;

std::unordered_map<std::string, FlutterPlatformViewTypeEntry>
platform_view_types_;

std::unordered_map<PlatformViewId, HWND> platform_views_;

std::unordered_map<PlatformViewId, std::function<HWND()>>
pending_platform_views_;

// Pointer to the task runner of the associated engine.
TaskRunner* task_runner_;
};

} // namespace flutter
Expand Down
29 changes: 29 additions & 0 deletions shell/platform/windows/platform_view_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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_plugin.h"

namespace flutter {

PlatformViewPlugin::PlatformViewPlugin(BinaryMessenger* messenger, TaskRunner* task_runner) : PlatformViewManager(messenger), task_runner_(task_runner) {}

PlatformViewPlugin::~PlatformViewPlugin() {}

std::optional<HWND> PlatformViewPlugin::GetNativeHandleForId(PlatformViewId id) const {
return std::nullopt;
}

void PlatformViewPlugin::RegisterPlatformViewType(std::string_view type_name, const FlutterPlatformViewTypeEntry& type) {}

void PlatformViewPlugin::InstantiatePlatformView(PlatformViewId id) {}

bool PlatformViewPlugin::AddPlatformView(PlatformViewId id, std::string_view type_name) {
return true;
}

bool PlatformViewPlugin::FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus) {
return true;
}

} // namespace flutter
55 changes: 55 additions & 0 deletions shell/platform/windows/platform_view_plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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.

#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_PLUGIN_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_PLUGIN_H_

#include "flutter/shell/platform/windows/platform_view_manager.h"

#include <functional>
#include <map>
#include <optional>

namespace flutter {

class PlatformViewPlugin : public PlatformViewManager {
public:
PlatformViewPlugin(BinaryMessenger* messenger, TaskRunner* task_runner);

~PlatformViewPlugin();

// Find the HWND corresponding to a platform view id. Returns null if the id
// has no associated platform view.
std::optional<HWND> GetNativeHandleForId(PlatformViewId id) const;

// Create a queued platform view instance.
void InstantiatePlatformView(PlatformViewId id);

// The runner-facing API calls this method to register a window type
// corresponding to a platform view identifier supplied to the widget tree.
void RegisterPlatformViewType(std::string_view type_name,
const FlutterPlatformViewTypeEntry& type);

// | PlatformViewManager |
bool AddPlatformView(PlatformViewId id, std::string_view type_name) override;

// | PlatformViewManager |
bool FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus) override;

private:
std::unordered_map<std::string, FlutterPlatformViewTypeEntry>
platform_view_types_;

std::unordered_map<PlatformViewId, HWND> platform_views_;

std::unordered_map<PlatformViewId, std::function<HWND()>>
pending_platform_views_;

// Pointer to the task runner of the associated engine.
TaskRunner* task_runner_;
};

} // namespace flutter

#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_PLATFORM_VIEW_PLUGIN_H_
4 changes: 2 additions & 2 deletions shell/platform/windows/testing/engine_modifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class EngineModifier {
engine_->lifecycle_manager_ = std::move(handler);
}

void SetPlatformViewManager(std::unique_ptr<PlatformViewManager>&& manager) {
engine_->platform_view_manager_ = std::move(manager);
void SetPlatformViewPlugin(std::unique_ptr<PlatformViewPlugin>&& manager) {
engine_->platform_view_plugin_ = std::move(manager);
}

private:
Expand Down
11 changes: 5 additions & 6 deletions shell/platform/windows/testing/mock_platform_view_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_PLATFORM_VIEW_MANAGER_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_MOCK_PLATFORM_VIEW_MANAGER_H_

#include "flutter/shell/platform/windows/platform_view_manager.h"
#include "flutter/shell/platform/windows/platform_view_plugin.h"

#include "flutter/shell/platform/windows/flutter_windows_engine.h"
#include "gmock/gmock.h"

namespace flutter {

class MockPlatformViewManager : public PlatformViewManager {
class MockPlatformViewManager : public PlatformViewPlugin {
public:
MockPlatformViewManager(FlutterWindowsEngine* engine)
: PlatformViewManager(engine->task_runner(),
engine->messenger_wrapper()) {}
: PlatformViewPlugin(engine->messenger_wrapper(), engine->task_runner()) {}

~MockPlatformViewManager() {}

MOCK_METHOD(void,
QueuePlatformViewCreation,
MOCK_METHOD(bool,
AddPlatformView,
(PlatformViewId id, std::string_view));
};

Expand Down