Flutter Engine
The Flutter Engine
windows_test_config_builder.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/shell/platform/windows/testing/windows_test_config_builder.h"
6
7#include <combaseapi.h>
8
9#include <string>
10#include <string_view>
11#include <vector>
12
13#include "flutter/fml/logging.h"
14#include "flutter/shell/platform/windows/flutter_windows_engine.h"
15#include "flutter/shell/platform/windows/public/flutter_windows.h"
16#include "flutter/shell/platform/windows/testing/windows_test_context.h"
17
18namespace flutter {
19namespace testing {
20
22 : context_(context) {}
23
25
26void WindowsConfigBuilder::SetDartEntrypoint(std::string_view entrypoint) {
27 if (entrypoint.empty()) {
28 return;
29 }
30 dart_entrypoint_ = entrypoint;
31}
32
34 if (arg.empty()) {
35 return;
36 }
37
38 dart_entrypoint_arguments_.emplace_back(std::move(arg));
39}
40
42 const {
43 FlutterDesktopEngineProperties engine_properties = {};
44 engine_properties.assets_path = context_.GetAssetsPath().c_str();
45 engine_properties.icu_data_path = context_.GetIcuDataPath().c_str();
46
47 // Set Dart entrypoint.
48 engine_properties.dart_entrypoint = dart_entrypoint_.c_str();
49
50 // Set Dart entrypoint argc, argv.
51 std::vector<const char*> dart_args;
52 dart_args.reserve(dart_entrypoint_arguments_.size());
53 for (const auto& arg : dart_entrypoint_arguments_) {
54 dart_args.push_back(arg.c_str());
55 }
56 if (!dart_args.empty()) {
57 engine_properties.dart_entrypoint_argv = dart_args.data();
58 engine_properties.dart_entrypoint_argc = dart_args.size();
59 } else {
60 // Clear this out in case this is not the first engine launch from the
61 // embedder config builder.
62 engine_properties.dart_entrypoint_argv = nullptr;
63 engine_properties.dart_entrypoint_argc = 0;
64 }
65
66 return engine_properties;
67}
68
71 return EnginePtr{FlutterDesktopEngineCreate(&engine_properties)};
72}
73
75 InitializeCOM();
76
78 if (!engine) {
79 return {};
80 }
81
82 // Register native functions.
83 FlutterWindowsEngine* windows_engine =
84 reinterpret_cast<FlutterWindowsEngine*>(engine.get());
85 windows_engine->SetRootIsolateCreateCallback(
86 context_.GetRootIsolateCallback());
87
88 if (!FlutterDesktopEngineRun(engine.get(), /* entry_point */ nullptr)) {
89 return {};
90 }
91
92 return engine;
93}
94
96 InitializeCOM();
97
99 if (!engine) {
100 return {};
101 }
102
103 // Register native functions.
104 FlutterWindowsEngine* windows_engine =
105 reinterpret_cast<FlutterWindowsEngine*>(engine.get());
106 windows_engine->SetRootIsolateCreateCallback(
107 context_.GetRootIsolateCallback());
108
109 int width = 600;
110 int height = 400;
111
112 // Create a view controller that owns the engine.
113 ViewControllerPtr controller{
115 if (!controller) {
116 return {};
117 }
118
119 return controller;
120}
121
122void WindowsConfigBuilder::InitializeCOM() const {
123 FML_CHECK(SUCCEEDED(::CoInitializeEx(nullptr, COINIT_MULTITHREADED)));
124}
125
126} // namespace testing
127} // namespace flutter
void SetRootIsolateCreateCallback(const fml::closure &callback)
FlutterDesktopEngineProperties GetEngineProperties() const
void SetDartEntrypoint(std::string_view entrypoint)
const std::wstring & GetIcuDataPath() const
const std::wstring & GetAssetsPath() const
FlutterEngine engine
Definition: main.cc:68
#define FML_CHECK(condition)
Definition: logging.h:85
std::unique_ptr< FlutterDesktopEngine, EngineDeleter > EnginePtr
std::unique_ptr< FlutterDesktopViewController, ViewControllerDeleter > ViewControllerPtr
int32_t height
int32_t width
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties *engine_properties)
FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)
#define SUCCEEDED(hr)