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 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
9 changes: 9 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,8 @@ FILE: ../../../flutter/shell/platform/windows/display_helper_winuwp.h
FILE: ../../../flutter/shell/platform/windows/dpi_utils_win32.cc
FILE: ../../../flutter/shell/platform/windows/dpi_utils_win32.h
FILE: ../../../flutter/shell/platform/windows/dpi_utils_win32_unittests.cc
FILE: ../../../flutter/shell/platform/windows/event_watcher_win32.cc
FILE: ../../../flutter/shell/platform/windows/event_watcher_win32.h
FILE: ../../../flutter/shell/platform/windows/external_texture_gl.cc
FILE: ../../../flutter/shell/platform/windows/external_texture_gl.h
FILE: ../../../flutter/shell/platform/windows/flutter_key_map.cc
Expand Down Expand Up @@ -2283,6 +2285,13 @@ FILE: ../../../flutter/shell/platform/windows/public/flutter_windows.h
FILE: ../../../flutter/shell/platform/windows/sequential_id_generator.cc
FILE: ../../../flutter/shell/platform/windows/sequential_id_generator.h
FILE: ../../../flutter/shell/platform/windows/sequential_id_generator_unittests.cc
FILE: ../../../flutter/shell/platform/windows/settings_plugin.cc
FILE: ../../../flutter/shell/platform/windows/settings_plugin.h
FILE: ../../../flutter/shell/platform/windows/settings_plugin_unittests.cc
FILE: ../../../flutter/shell/platform/windows/settings_plugin_win32.cc
FILE: ../../../flutter/shell/platform/windows/settings_plugin_win32.h
FILE: ../../../flutter/shell/platform/windows/settings_plugin_winuwp.cc
FILE: ../../../flutter/shell/platform/windows/settings_plugin_winuwp.h
FILE: ../../../flutter/shell/platform/windows/system_utils.h
FILE: ../../../flutter/shell/platform/windows/system_utils_unittests.cc
FILE: ../../../flutter/shell/platform/windows/system_utils_win32.cc
Expand Down
9 changes: 9 additions & 0 deletions shell/platform/windows/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ source_set("flutter_windows_source") {
"platform_handler.h",
"sequential_id_generator.cc",
"sequential_id_generator.h",
"settings_plugin.cc",
"settings_plugin.h",
"system_utils.h",
"task_runner.cc",
"task_runner.h",
Expand Down Expand Up @@ -107,6 +109,8 @@ source_set("flutter_windows_source") {
"game_pad_winuwp.h",
"platform_handler_winuwp.cc",
"platform_handler_winuwp.h",
"settings_plugin_winuwp.cc",
"settings_plugin_winuwp.h",
"system_utils_winuwp.cc",
"task_runner_winuwp.cc",
"task_runner_winuwp.h",
Expand All @@ -117,13 +121,17 @@ source_set("flutter_windows_source") {
"accessibility_bridge_delegate_win32.h",
"dpi_utils_win32.cc",
"dpi_utils_win32.h",
"event_watcher_win32.cc",
"event_watcher_win32.h",
"flutter_platform_node_delegate_win32.cc",
"flutter_platform_node_delegate_win32.h",
"flutter_window_win32.cc",
"flutter_window_win32.h",
"flutter_windows_win32.cc",
"platform_handler_win32.cc",
"platform_handler_win32.h",
"settings_plugin_win32.cc",
"settings_plugin_win32.h",
"system_utils_win32.cc",
"task_runner_win32.cc",
"task_runner_win32.h",
Expand Down Expand Up @@ -226,6 +234,7 @@ executable("flutter_windows_unittests") {
# "flutter_project_bundle_unittests.cc", //TODO failing due to switches test failing. Blocked on https://github.com/flutter/flutter/issues/74153
# "flutter_windows_engine_unittests.cc", //TODO failing to send / receive platform message get plugins working first. Blocked on https://github.com/flutter/flutter/issues/74155
"sequential_id_generator_unittests.cc",
"settings_plugin_unittests.cc",
"system_utils_unittests.cc",
"task_runner_unittests.cc",
"testing/engine_modifier.h",
Expand Down
4 changes: 0 additions & 4 deletions shell/platform/windows/client_wrapper/flutter_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ void FlutterEngine::ReloadSystemFonts() {
FlutterDesktopEngineReloadSystemFonts(engine_);
}

void FlutterEngine::ReloadPlatformBrightness() {
FlutterDesktopEngineReloadPlatformBrightness(engine_);
}

FlutterDesktopPluginRegistrarRef FlutterEngine::GetRegistrarForPlugin(
const std::string& plugin_name) {
if (!engine_) {
Expand Down
20 changes: 0 additions & 20 deletions shell/platform/windows/client_wrapper/flutter_engine_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ class TestFlutterWindowsApi : public testing::StubFlutterWindowsApi {
// |flutter::testing::StubFlutterWindowsApi|
void EngineReloadSystemFonts() override { reload_fonts_called_ = true; }

// |flutter::testing::StubFlutterWindowsApi|
void EngineReloadPlatformBrightness() override {
reload_brightness_called_ = true;
}

bool create_called() { return create_called_; }

bool run_called() { return run_called_; }
Expand All @@ -62,8 +57,6 @@ class TestFlutterWindowsApi : public testing::StubFlutterWindowsApi {

bool reload_fonts_called() { return reload_fonts_called_; }

bool reload_brightness_called() { return reload_brightness_called_; }

const std::vector<std::string>& dart_entrypoint_arguments() {
return dart_entrypoint_arguments_;
}
Expand All @@ -73,7 +66,6 @@ class TestFlutterWindowsApi : public testing::StubFlutterWindowsApi {
bool run_called_ = false;
bool destroy_called_ = false;
bool reload_fonts_called_ = false;
bool reload_brightness_called_ = false;
std::vector<std::string> dart_entrypoint_arguments_;
};

Expand Down Expand Up @@ -132,18 +124,6 @@ TEST(FlutterEngineTest, ReloadFonts) {
EXPECT_TRUE(test_api->reload_fonts_called());
}

TEST(FlutterEngineTest, ReloadBrightness) {
testing::ScopedStubFlutterWindowsApi scoped_api_stub(
std::make_unique<TestFlutterWindowsApi>());
auto test_api = static_cast<TestFlutterWindowsApi*>(scoped_api_stub.stub());

FlutterEngine engine(DartProject(L"fake/project/path"));
engine.Run();

engine.ReloadPlatformBrightness();
EXPECT_TRUE(test_api->reload_brightness_called());
}

TEST(FlutterEngineTest, GetMessenger) {
DartProject project(L"data");
testing::ScopedStubFlutterWindowsApi scoped_api_stub(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine) {
}
}

void FlutterDesktopEngineReloadPlatformBrightness(
FlutterDesktopEngineRef engine) {
if (s_stub_implementation) {
s_stub_implementation->EngineReloadPlatformBrightness();
}
}

FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(
FlutterDesktopEngineRef engine,
const char* plugin_name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ class StubFlutterWindowsApi {
// Called for FlutterDesktopEngineReloadSystemFonts.
virtual void EngineReloadSystemFonts() {}

// Called for FlutterDesktopEngineReloadPlatformBrightness.
virtual void EngineReloadPlatformBrightness() {}

// Called for FlutterDesktopViewGetHWND.
virtual HWND ViewGetHWND() { return reinterpret_cast<HWND>(1); }

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

namespace flutter {

EventWatcherWin32::EventWatcherWin32(std::function<void()> callback)
: callback_(callback) {
handle_ = CreateEvent(NULL, TRUE, FALSE, NULL);

RegisterWaitForSingleObject(&handle_for_wait_, handle_, &CallbackForWait,
reinterpret_cast<void*>(this), INFINITE,
WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD);
}

EventWatcherWin32::~EventWatcherWin32() {
UnregisterWait(handle_for_wait_);
CloseHandle(handle_);
}

HANDLE EventWatcherWin32::GetHandle() {
return handle_;
}

// static
VOID CALLBACK EventWatcherWin32::CallbackForWait(PVOID context, BOOLEAN) {
EventWatcherWin32* self = reinterpret_cast<EventWatcherWin32*>(context);
ResetEvent(self->handle_);
self->callback_();
}

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

#include <Windows.h>

#include <functional>

namespace flutter {

// A win32 `HANDLE` wrapper for use as a one-time callback.
class EventWatcherWin32 {
public:
explicit EventWatcherWin32(std::function<void()> callback);
~EventWatcherWin32();

// Returns `HANDLE`, which can be used to register an event listener.
HANDLE GetHandle();

private:
static VOID CALLBACK CallbackForWait(PVOID context, BOOLEAN);

std::function<void()> callback_;

HANDLE handle_;
HANDLE handle_for_wait_;

EventWatcherWin32(const EventWatcherWin32&) = delete;
EventWatcherWin32& operator=(const EventWatcherWin32&) = delete;
};

} // namespace flutter

#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_EVENT_WATCHER_WIN32_H_
9 changes: 0 additions & 9 deletions shell/platform/windows/flutter_window_winuwp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ void FlutterWindowWinUWP::SetEventHandlers() {
window_.PointerWheelChanged(
{this, &FlutterWindowWinUWP::OnPointerWheelChanged});

ui_settings_.ColorValuesChanged(
{this, &FlutterWindowWinUWP::OnColorValuesChanged});

// TODO(clarkezone) support mouse leave handling
// https://github.com/flutter/flutter/issues/70199

Expand Down Expand Up @@ -383,12 +380,6 @@ void FlutterWindowWinUWP::OnCharacterReceived(
}
}

void FlutterWindowWinUWP::OnColorValuesChanged(
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::Foundation::IInspectable const&) {
binding_handler_delegate_->OnPlatformBrightnessChanged();
}

bool FlutterWindowWinUWP::OnBitmapSurfaceUpdated(const void* allocation,
size_t row_bytes,
size_t height) {
Expand Down
8 changes: 0 additions & 8 deletions shell/platform/windows/flutter_window_winuwp.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ class FlutterWindowWinUWP : public WindowBindingHandler {
winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::UI::Core::CharacterReceivedEventArgs const& args);

// Notifies current |WindowBindingHandlerDelegate| of color values changed
// events.
void OnColorValuesChanged(winrt::Windows::Foundation::IInspectable const&,
winrt::Windows::Foundation::IInspectable const&);

// Converts from logical point to physical X value.
double GetPosX(winrt::Windows::UI::Core::PointerEventArgs const& args);

Expand Down Expand Up @@ -168,9 +163,6 @@ class FlutterWindowWinUWP : public WindowBindingHandler {
// SwapChain to the CoreWindow.
winrt::Windows::UI::Composition::SpriteVisual render_target_{nullptr};

// UISettings for observing the color change.
winrt::Windows::UI::ViewManagement::UISettings ui_settings_;

// GamepadCursorWinUWP object used to manage an emulated cursor visual driven
// by gamepad.
std::unique_ptr<GamepadCursorWinUWP> game_pad_cursor_{nullptr};
Expand Down
5 changes: 0 additions & 5 deletions shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine) {
EngineFromHandle(engine)->ReloadSystemFonts();
}

void FlutterDesktopEngineReloadPlatformBrightness(
FlutterDesktopEngineRef engine) {
EngineFromHandle(engine)->ReloadPlatformBrightness();
}

FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(
FlutterDesktopEngineRef engine,
const char* plugin_name) {
Expand Down
32 changes: 7 additions & 25 deletions shell/platform/windows/flutter_windows_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@

#include "flutter/fml/platform/win/wstring_conversion.h"
#include "flutter/shell/platform/common/client_wrapper/binary_messenger_impl.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h"
#include "flutter/shell/platform/common/json_message_codec.h"
#include "flutter/shell/platform/common/path_utils.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/shell/platform/windows/system_utils.h"
#include "flutter/shell/platform/windows/task_runner.h"
#include "third_party/rapidjson/include/rapidjson/document.h"

#if defined(WINUWP)
#include "flutter/shell/platform/windows/accessibility_bridge_delegate_winuwp.h"
Expand Down Expand Up @@ -197,10 +194,8 @@ FlutterWindowsEngine::FlutterWindowsEngine(const FlutterProjectBundle& project)
// Set up internal channels.
// TODO: Replace this with an embedder.h API. See
// https://github.com/flutter/flutter/issues/71099
settings_channel_ =
std::make_unique<BasicMessageChannel<rapidjson::Document>>(
messenger_wrapper_.get(), "flutter/settings",
&JsonMessageCodec::GetInstance());
settings_plugin_ =
SettingsPlugin::Create(messenger_wrapper_.get(), task_runner_.get());
}

FlutterWindowsEngine::~FlutterWindowsEngine() {
Expand Down Expand Up @@ -341,7 +336,10 @@ bool FlutterWindowsEngine::RunWithEntrypoint(const char* entrypoint) {
kFlutterEngineDisplaysUpdateTypeStartup,
displays.data(), displays.size());

SendSystemSettings();
SendSystemLocales();

settings_plugin_->StartWatching();
settings_plugin_->SendSettings();

return true;
}
Expand Down Expand Up @@ -485,13 +483,7 @@ void FlutterWindowsEngine::ReloadSystemFonts() {
embedder_api_.ReloadSystemFonts(engine_);
}

void FlutterWindowsEngine::ReloadPlatformBrightness() {
if (engine_) {
SendSystemSettings();
}
}

void FlutterWindowsEngine::SendSystemSettings() {
void FlutterWindowsEngine::SendSystemLocales() {
std::vector<LanguageInfo> languages = GetPreferredLanguageInfo();
std::vector<FlutterLocale> flutter_locales;
flutter_locales.reserve(languages.size());
Expand All @@ -507,16 +499,6 @@ void FlutterWindowsEngine::SendSystemSettings() {
[](const auto& arg) -> const auto* { return &arg; });
embedder_api_.UpdateLocales(engine_, flutter_locale_list.data(),
flutter_locale_list.size());

rapidjson::Document settings(rapidjson::kObjectType);
auto& allocator = settings.GetAllocator();
settings.AddMember("alwaysUse24HourFormat",
Prefer24HourTime(GetUserTimeFormat()), allocator);
settings.AddMember("textScaleFactor", 1.0, allocator);
settings.AddMember("platformBrightness",
fml::WideStringToUtf8(GetPreferredBrightness()),
allocator);
settings_channel_->Send(settings);
}

bool FlutterWindowsEngine::RegisterExternalTexture(int64_t texture_id) {
Expand Down
12 changes: 5 additions & 7 deletions shell/platform/windows/flutter_windows_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "flutter/shell/platform/windows/flutter_project_bundle.h"
#include "flutter/shell/platform/windows/flutter_windows_texture_registrar.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"
#include "flutter/shell/platform/windows/window_state.h"
#include "third_party/rapidjson/include/rapidjson/document.h"
Expand Down Expand Up @@ -164,9 +165,6 @@ class FlutterWindowsEngine {
// Informs the engine that the system font list has changed.
void ReloadSystemFonts();

// Informs the engine that the platform brightness has changed.
void ReloadPlatformBrightness();

// Attempts to register the texture with the given |texture_id|.
bool RegisterExternalTexture(int64_t texture_id);

Expand Down Expand Up @@ -198,11 +196,11 @@ class FlutterWindowsEngine {
// Allows swapping out embedder_api_ calls in tests.
friend class EngineModifier;

// Sends system settings (e.g., locale) to the engine.
// Sends system locales to the engine.
//
// Should be called just after the engine is run, and after any relevant
// system changes.
void SendSystemSettings();
void SendSystemLocales();

// The handle to the embedder.h engine instance.
FLUTTER_API_SYMBOL(FlutterEngine) engine_ = nullptr;
Expand Down Expand Up @@ -243,8 +241,8 @@ class FlutterWindowsEngine {
// May be nullptr if ANGLE failed to initialize.
std::unique_ptr<AngleSurfaceManager> surface_manager_;

// The MethodChannel used for communication with the Flutter engine.
std::unique_ptr<BasicMessageChannel<rapidjson::Document>> settings_channel_;
// The settings plugin.
std::unique_ptr<SettingsPlugin> settings_plugin_;

// Callbacks to be called when the engine (and thus the plugin registrar) is
// being destroyed.
Expand Down
Loading