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 2 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
13 changes: 8 additions & 5 deletions shell/platform/windows/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,23 @@ source_set("flutter_windows_source") {
sources = [
"angle_surface_manager.cc",
"angle_surface_manager.h",
"dpi_utils.cc",
"dpi_utils.h",
"flutter_windows.cc",
"flutter_windows_view.cc",
"flutter_windows_view.h",
"key_event_handler.cc",
"key_event_handler.h",
"keyboard_hook_handler.h",
"platform_handler.cc",
"platform_handler.h",
"string_conversion.cc",
"string_conversion.h",
"text_input_plugin.cc",
"text_input_plugin.h",
"window_binding_handler.h",
"win32_dpi_utils.cc",
"win32_dpi_utils.h",
"win32_flutter_window.cc",
"win32_flutter_window.h",
"win32_platform_handler.cc",
"win32_platform_handler.h",
"win32_task_runner.cc",
"win32_task_runner.h",
"win32_window.cc",
Expand Down Expand Up @@ -110,12 +113,12 @@ executable("flutter_windows_unittests") {
testonly = true

sources = [
"dpi_utils_unittests.cc",
"string_conversion_unittests.cc",
"testing/win32_flutter_window_test.cc",
"testing/win32_flutter_window_test.h",
"testing/win32_window_test.cc",
"testing/win32_window_test.h",
"win32_dpi_utils_unittests.cc",
"win32_flutter_window_unittests.cc",
"win32_window_unittests.cc",
]
Expand Down
12 changes: 7 additions & 5 deletions shell/platform/windows/angle_surface_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,20 @@ void AngleSurfaceManager::CleanUp() {
}
}

EGLSurface AngleSurfaceManager::CreateSurface(HWND window) {
if (!window || !initialize_succeeded_) {
EGLSurface AngleSurfaceManager::CreateSurface(
WindowsRenderTarget* render_target) {
if (!render_target || !initialize_succeeded_) {
return EGL_NO_SURFACE;
}

EGLSurface surface = EGL_NO_SURFACE;

const EGLint surfaceAttributes[] = {EGL_NONE};

surface = eglCreateWindowSurface(egl_display_, egl_config_,
static_cast<EGLNativeWindowType>(window),
surfaceAttributes);
surface = eglCreateWindowSurface(
egl_display_, egl_config_,
static_cast<EGLNativeWindowType>(render_target->GetWindowHandle()),
Comment thread
clarkezone marked this conversation as resolved.
Outdated
surfaceAttributes);
if (surface == EGL_NO_SURFACE) {
std::cerr << "Surface creation failed." << std::endl;
}
Expand Down
8 changes: 5 additions & 3 deletions shell/platform/windows/angle_surface_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// Windows platform specific includes
#include <windows.h>

#include "window_binding_handler.h"

namespace flutter {

// An manager for inializing ANGLE correctly and using it to create and
Expand All @@ -29,9 +31,9 @@ class AngleSurfaceManager {
AngleSurfaceManager& operator=(const AngleSurfaceManager&) = delete;

// Creates and returns an EGLSurface wrapper and backing DirectX 11 SwapChain
// asociated with window, in the appropriate format for display in a
// HWND-backed window.
EGLSurface CreateSurface(HWND window);
// asociated with window, in the appropriate format for display.
// Target represents the visual entity to bind to.
EGLSurface CreateSurface(WindowsRenderTarget* render_target);

// queries EGL for the dimensions of surface in physical
// pixels returning width and height as out params.
Expand Down
34 changes: 20 additions & 14 deletions shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
#include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h"
#include "flutter/shell/platform/common/cpp/path_utils.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/windows/dpi_utils.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/shell/platform/windows/key_event_handler.h"
#include "flutter/shell/platform/windows/keyboard_hook_handler.h"
#include "flutter/shell/platform/windows/platform_handler.h"
#include "flutter/shell/platform/windows/text_input_plugin.h"
#include "flutter/shell/platform/windows/win32_dpi_utils.h"
#include "flutter/shell/platform/windows/win32_flutter_window.h"
#include "flutter/shell/platform/windows/win32_platform_handler.h"
#include "flutter/shell/platform/windows/win32_task_runner.h"
#include "flutter/shell/platform/windows/window_binding_handler.h"
#include "flutter/shell/platform/windows/window_state.h"

static_assert(FLUTTER_ENGINE_VERSION == 1, "");
Expand Down Expand Up @@ -66,7 +68,7 @@ UniqueAotDataPtr LoadAotData(std::filesystem::path aot_data_path) {
// Returns the state object for the engine, or null on failure to start the
// engine.
static std::unique_ptr<FlutterDesktopEngineState> RunFlutterEngine(
flutter::Win32FlutterWindow* window,
flutter::FlutterWindowsView* view,
const FlutterDesktopEngineProperties& engine_properties) {
auto state = std::make_unique<FlutterDesktopEngineState>();

Expand All @@ -79,22 +81,22 @@ static std::unique_ptr<FlutterDesktopEngineState> RunFlutterEngine(
&engine_properties.switches[engine_properties.switches_count]);
}

window->CreateRenderSurface();
view->CreateRenderSurface();

// Provide the necessary callbacks for rendering within a win32 child window.
FlutterRendererConfig config = {};
config.type = kOpenGL;
config.open_gl.struct_size = sizeof(config.open_gl);
config.open_gl.make_current = [](void* user_data) -> bool {
auto host = static_cast<flutter::Win32FlutterWindow*>(user_data);
auto host = static_cast<flutter::FlutterWindowsView*>(user_data);
return host->MakeCurrent();
};
config.open_gl.clear_current = [](void* user_data) -> bool {
auto host = static_cast<flutter::Win32FlutterWindow*>(user_data);
auto host = static_cast<flutter::FlutterWindowsView*>(user_data);
return host->ClearContext();
};
config.open_gl.present = [](void* user_data) -> bool {
auto host = static_cast<flutter::Win32FlutterWindow*>(user_data);
auto host = static_cast<flutter::FlutterWindowsView*>(user_data);
return host->SwapBuffers();
};
config.open_gl.fbo_callback = [](void* user_data) -> uint32_t { return 0; };
Expand All @@ -103,7 +105,7 @@ static std::unique_ptr<FlutterDesktopEngineState> RunFlutterEngine(
return reinterpret_cast<void*>(eglGetProcAddress(what));
};
config.open_gl.make_resource_current = [](void* user_data) -> bool {
auto host = static_cast<flutter::Win32FlutterWindow*>(user_data);
auto host = static_cast<flutter::FlutterWindowsView*>(user_data);
return host->MakeResourceCurrent();
};

Expand Down Expand Up @@ -178,7 +180,7 @@ static std::unique_ptr<FlutterDesktopEngineState> RunFlutterEngine(
args.platform_message_callback =
[](const FlutterPlatformMessage* engine_message,
void* user_data) -> void {
auto window = reinterpret_cast<flutter::Win32FlutterWindow*>(user_data);
auto window = reinterpret_cast<flutter::FlutterWindowsView*>(user_data);
return window->HandlePlatformMessage(engine_message);
};
args.custom_task_runners = &custom_task_runners;
Expand All @@ -188,7 +190,7 @@ static std::unique_ptr<FlutterDesktopEngineState> RunFlutterEngine(

FLUTTER_API_SYMBOL(FlutterEngine) engine = nullptr;
auto result =
FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, window, &engine);
FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, view, &engine);
if (result != kSuccess || engine == nullptr) {
std::cerr << "Failed to start Flutter engine: error " << result
<< std::endl;
Expand All @@ -202,8 +204,12 @@ FlutterDesktopViewControllerRef FlutterDesktopCreateViewController(
int width,
int height,
const FlutterDesktopEngineProperties& engine_properties) {
std::unique_ptr<flutter::FlutterWindowBindingHandler> window_wrapper =
std::make_unique<flutter::Win32FlutterWindow>(width, height);

FlutterDesktopViewControllerRef state =
flutter::Win32FlutterWindow::CreateWin32FlutterWindow(width, height);
flutter::FlutterWindowsView::CreateFlutterWindowsView(
std::move(window_wrapper));

auto engine_state = RunFlutterEngine(state->view.get(), engine_properties);

Expand Down Expand Up @@ -261,8 +267,8 @@ FlutterDesktopViewRef FlutterDesktopGetView(
return controller->view_wrapper.get();
}

HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view) {
return view->window->GetWindowHandle();
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef view_ref) {
return view_ref->view->GetRenderTarget()->GetWindowHandle();
}

UINT FlutterDesktopGetDpiForHWND(HWND hwnd) {
Expand Down Expand Up @@ -316,7 +322,7 @@ void FlutterDesktopRegistrarSetDestructionHandler(

FlutterDesktopViewRef FlutterDesktopRegistrarGetView(
FlutterDesktopPluginRegistrarRef registrar) {
return registrar->window;
return registrar->view;
}

bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger,
Expand Down
Loading