Flutter Engine
 
Loading...
Searching...
No Matches
fl_application.cc File Reference

Go to the source code of this file.

Classes

struct  FlApplicationPrivate
 

Macros

#define FL_APPLICATION_GET_PRIVATE(app)
 

Enumerations

enum  {
  SIGNAL_REGISTER_PLUGINS ,
  SIGNAL_CREATE_WINDOW ,
  LAST_SIGNAL
}
 

Functions

 G_DEFINE_TYPE_WITH_CODE (FlApplication, fl_application, GTK_TYPE_APPLICATION, G_ADD_PRIVATE(FlApplication)) static GtkWindow *create_window_cb(FlApplication *self
 
 g_signal_emit (self, fl_application_signals[SIGNAL_CREATE_WINDOW], 0, view, &window)
 
static void first_frame_cb (FlApplication *self, FlView *view)
 
static void fl_application_register_plugins (FlApplication *self, FlPluginRegistry *registry)
 
static GtkWindow * fl_application_create_window (FlApplication *self, FlView *view)
 
static void fl_application_activate (GApplication *application)
 
static gboolean fl_application_local_command_line (GApplication *application, gchar ***arguments, int *exit_status)
 
static void fl_application_dispose (GObject *object)
 
static void fl_application_class_init (FlApplicationClass *klass)
 
static void fl_application_init (FlApplication *self)
 
G_MODULE_EXPORT FlApplication * fl_application_new (const gchar *application_id, GApplicationFlags flags)
 

Variables

static guint fl_application_signals [LAST_SIGNAL]
 
FlView * view
 
return window
 

Macro Definition Documentation

◆ FL_APPLICATION_GET_PRIVATE

#define FL_APPLICATION_GET_PRIVATE (   app)
Value:
((FlApplicationPrivate*)fl_application_get_instance_private( \
FL_APPLICATION(app)))

Definition at line 22 of file fl_application.cc.

26
28
29G_DEFINE_TYPE_WITH_CODE(FlApplication,
30 fl_application,
31 GTK_TYPE_APPLICATION,
32 G_ADD_PRIVATE(FlApplication))
33
34// Called when the platform creates a window.
35static GtkWindow* create_window_cb(FlApplication* self, FlView* view) {
36 GtkWindow* window;
38 &window);
39
40 return window;
41}
42
43// Called when the first frame is received.
44static void first_frame_cb(FlApplication* self, FlView* view) {
45 GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view));
46
47 // Show the main window.
48 if (window != nullptr && GTK_IS_WINDOW(window)) {
49 gtk_window_present(GTK_WINDOW(window));
50 }
51}
52
53// Default implementation of FlApplication::register_plugins
54static void fl_application_register_plugins(FlApplication* self,
55 FlPluginRegistry* registry) {}
56
57// Default implementation of FlApplication::create_window
58static GtkWindow* fl_application_create_window(FlApplication* self,
59 FlView* view) {
60 GtkApplicationWindow* window =
61 GTK_APPLICATION_WINDOW(gtk_application_window_new(GTK_APPLICATION(self)));
62
63 // Use a header bar when running in GNOME as this is the common style used
64 // by applications and is the setup most users will be using (e.g. Ubuntu
65 // desktop).
66 // If running on X and not using GNOME then just use a traditional title bar
67 // in case the window manager does more exotic layout, e.g. tiling.
68 // If running on Wayland assume the header bar will work (may need changing
69 // if future cases occur).
70 gboolean use_header_bar = TRUE;
71#ifdef GDK_WINDOWING_X11
72 GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window));
73 if (GDK_IS_X11_SCREEN(screen)) {
74 const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
75 if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
76 use_header_bar = FALSE;
77 }
78 }
79#endif
80 if (use_header_bar) {
81 GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
82 gtk_widget_show(GTK_WIDGET(header_bar));
83 gtk_header_bar_set_show_close_button(header_bar, TRUE);
84 gtk_window_set_titlebar(GTK_WINDOW(window), GTK_WIDGET(header_bar));
85 }
86
87 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
88
89 return GTK_WINDOW(window);
90}
91
92// Implements GApplication::activate.
93static void fl_application_activate(GApplication* application) {
94 FlApplication* self = FL_APPLICATION(application);
96
97 g_autoptr(FlDartProject) project = fl_dart_project_new();
99 project, priv->dart_entrypoint_arguments);
100
101 FlView* view = fl_view_new(project);
102 g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb),
103 self);
104 gtk_widget_show(GTK_WIDGET(view));
105
106 FlWindowingHandler* windowing_handler =
108 g_signal_connect_swapped(windowing_handler, "create_window",
109 G_CALLBACK(create_window_cb), self);
110
111 GtkWindow* window;
113 &window);
114
115 // Make the resources for the view so rendering can start.
116 // We'll show the view when we have the first frame.
117 gtk_widget_realize(GTK_WIDGET(view));
118
120 FL_PLUGIN_REGISTRY(view));
121}
122
123// Implements GApplication::local_command_line.
124static gboolean fl_application_local_command_line(GApplication* application,
125 gchar*** arguments,
126 int* exit_status) {
127 FlApplication* self = FL_APPLICATION(application);
129
130 // Strip out the first argument as it is the binary name.
131 priv->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
132
133 g_autoptr(GError) error = nullptr;
134 if (!g_application_register(application, nullptr, &error)) {
135 g_warning("Failed to register: %s", error->message);
136 *exit_status = 1;
137 return TRUE;
138 }
139
140 // This will only run on the primary instance or this instance with
141 // G_APPLICATION_NON_UNIQUE
142 g_application_activate(application);
143 *exit_status = 0;
144
145 return TRUE;
146}
147
148// Implements GObject::dispose.
149static void fl_application_dispose(GObject* object) {
150 FlApplication* self = FL_APPLICATION(object);
152
153 g_clear_pointer(&priv->dart_entrypoint_arguments, g_strfreev);
154
155 G_OBJECT_CLASS(fl_application_parent_class)->dispose(object);
156}
157
158static void fl_application_class_init(FlApplicationClass* klass) {
159 G_APPLICATION_CLASS(klass)->activate = fl_application_activate;
160 G_APPLICATION_CLASS(klass)->local_command_line =
162 G_OBJECT_CLASS(klass)->dispose = fl_application_dispose;
163
164 klass->register_plugins = fl_application_register_plugins;
165 klass->create_window = fl_application_create_window;
166
168 "register-plugins", fl_application_get_type(), G_SIGNAL_RUN_LAST,
169 G_STRUCT_OFFSET(FlApplicationClass, register_plugins), nullptr, nullptr,
170 nullptr, G_TYPE_NONE, 1, fl_plugin_registry_get_type());
172 "create-window", fl_application_get_type(), G_SIGNAL_RUN_LAST,
173 G_STRUCT_OFFSET(FlApplicationClass, create_window),
174 g_signal_accumulator_first_wins, nullptr, nullptr, GTK_TYPE_WINDOW, 1,
175 fl_view_get_type());
176}
177
178static void fl_application_init(FlApplication* self) {}
179
180G_MODULE_EXPORT
181FlApplication* fl_application_new(const gchar* application_id,
182 GApplicationFlags flags) {
183 return FL_APPLICATION(g_object_new(fl_application_get_type(),
184 "application-id", application_id, "flags",
185 flags, nullptr));
186}
FlView * view
G_MODULE_EXPORT FlApplication * fl_application_new(const gchar *application_id, GApplicationFlags flags)
static void fl_application_dispose(GObject *object)
static void first_frame_cb(FlApplication *self, FlView *view)
static void fl_application_init(FlApplication *self)
static GtkWindow * fl_application_create_window(FlApplication *self, FlView *view)
static guint fl_application_signals[LAST_SIGNAL]
@ LAST_SIGNAL
@ SIGNAL_CREATE_WINDOW
@ SIGNAL_REGISTER_PLUGINS
static gboolean fl_application_local_command_line(GApplication *application, gchar ***arguments, int *exit_status)
#define FL_APPLICATION_GET_PRIVATE(app)
static void fl_application_register_plugins(FlApplication *self, FlPluginRegistry *registry)
g_signal_emit(self, fl_application_signals[SIGNAL_CREATE_WINDOW], 0, view, &window)
G_DEFINE_TYPE_WITH_CODE(FlApplication, fl_application, GTK_TYPE_APPLICATION, G_ADD_PRIVATE(FlApplication)) static GtkWindow *create_window_cb(FlApplication *self
return window
static void fl_application_class_init(FlApplicationClass *klass)
static void fl_application_activate(GApplication *application)
g_autoptr(GMutexLocker) locker
return TRUE
G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject *self, char **argv)
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
FlWindowingHandler * fl_engine_get_windowing_handler(FlEngine *self)
FlPixelBufferTexturePrivate * priv
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlView * fl_view_new(FlDartProject *project)
Definition fl_view.cc:763
G_MODULE_EXPORT FlEngine * fl_view_get_engine(FlView *self)
Definition fl_view.cc:790
void gtk_widget_show(GtkWidget *widget)
Definition mock_gtk.cc:256
GtkWidget * gtk_widget_get_toplevel(GtkWidget *widget)
Definition mock_gtk.cc:293
void gtk_widget_realize(GtkWidget *widget)
Definition mock_gtk.cc:252

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SIGNAL_REGISTER_PLUGINS 
SIGNAL_CREATE_WINDOW 
LAST_SIGNAL 

Definition at line 26 of file fl_application.cc.

Function Documentation

◆ first_frame_cb()

static void first_frame_cb ( FlApplication *  self,
FlView *  view 
)
static

Definition at line 45 of file fl_application.cc.

45 {
46 GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(view));
47
48 // Show the main window.
49 if (window != nullptr && GTK_IS_WINDOW(window)) {
50 gtk_window_present(GTK_WINDOW(window));
51 }
52}

References gtk_widget_get_toplevel(), view, and window.

Referenced by fl_application_activate().

◆ fl_application_activate()

static void fl_application_activate ( GApplication *  application)
static

Definition at line 94 of file fl_application.cc.

94 {
95 FlApplication* self = FL_APPLICATION(application);
97
98 g_autoptr(FlDartProject) project = fl_dart_project_new();
100 project, priv->dart_entrypoint_arguments);
101
102 FlView* view = fl_view_new(project);
103 g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb),
104 self);
105 gtk_widget_show(GTK_WIDGET(view));
106
107 FlWindowingHandler* windowing_handler =
109 g_signal_connect_swapped(windowing_handler, "create_window",
110 G_CALLBACK(create_window_cb), self);
111
112 GtkWindow* window;
114 &window);
115
116 // Make the resources for the view so rendering can start.
117 // We'll show the view when we have the first frame.
118 gtk_widget_realize(GTK_WIDGET(view));
119
121 FL_PLUGIN_REGISTRY(view));
122}

References first_frame_cb(), FL_APPLICATION_GET_PRIVATE, fl_application_signals, fl_dart_project_new(), fl_dart_project_set_dart_entrypoint_arguments(), fl_engine_get_windowing_handler(), fl_view_get_engine(), fl_view_new(), g_autoptr(), g_signal_emit(), gtk_widget_realize(), gtk_widget_show(), priv, self, SIGNAL_CREATE_WINDOW, SIGNAL_REGISTER_PLUGINS, view, and window.

Referenced by fl_application_class_init().

◆ fl_application_class_init()

static void fl_application_class_init ( FlApplicationClass *  klass)
static

Definition at line 159 of file fl_application.cc.

159 {
160 G_APPLICATION_CLASS(klass)->activate = fl_application_activate;
161 G_APPLICATION_CLASS(klass)->local_command_line =
163 G_OBJECT_CLASS(klass)->dispose = fl_application_dispose;
164
165 klass->register_plugins = fl_application_register_plugins;
166 klass->create_window = fl_application_create_window;
167
169 "register-plugins", fl_application_get_type(), G_SIGNAL_RUN_LAST,
170 G_STRUCT_OFFSET(FlApplicationClass, register_plugins), nullptr, nullptr,
171 nullptr, G_TYPE_NONE, 1, fl_plugin_registry_get_type());
173 "create-window", fl_application_get_type(), G_SIGNAL_RUN_LAST,
174 G_STRUCT_OFFSET(FlApplicationClass, create_window),
175 g_signal_accumulator_first_wins, nullptr, nullptr, GTK_TYPE_WINDOW, 1,
176 fl_view_get_type());
177}

References fl_application_activate(), fl_application_create_window(), fl_application_dispose(), fl_application_local_command_line(), fl_application_register_plugins(), fl_application_signals, SIGNAL_CREATE_WINDOW, and SIGNAL_REGISTER_PLUGINS.

◆ fl_application_create_window()

static GtkWindow * fl_application_create_window ( FlApplication *  self,
FlView *  view 
)
static

Definition at line 59 of file fl_application.cc.

60 {
61 GtkApplicationWindow* window =
62 GTK_APPLICATION_WINDOW(gtk_application_window_new(GTK_APPLICATION(self)));
63
64 // Use a header bar when running in GNOME as this is the common style used
65 // by applications and is the setup most users will be using (e.g. Ubuntu
66 // desktop).
67 // If running on X and not using GNOME then just use a traditional title bar
68 // in case the window manager does more exotic layout, e.g. tiling.
69 // If running on Wayland assume the header bar will work (may need changing
70 // if future cases occur).
71 gboolean use_header_bar = TRUE;
72#ifdef GDK_WINDOWING_X11
73 GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window));
74 if (GDK_IS_X11_SCREEN(screen)) {
75 const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
76 if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
77 use_header_bar = FALSE;
78 }
79 }
80#endif
81 if (use_header_bar) {
82 GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
83 gtk_widget_show(GTK_WIDGET(header_bar));
84 gtk_header_bar_set_show_close_button(header_bar, TRUE);
85 gtk_window_set_titlebar(GTK_WINDOW(window), GTK_WIDGET(header_bar));
86 }
87
88 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
89
90 return GTK_WINDOW(window);
91}

References gtk_widget_show(), self, TRUE, view, and window.

Referenced by fl_application_class_init().

◆ fl_application_dispose()

static void fl_application_dispose ( GObject *  object)
static

Definition at line 150 of file fl_application.cc.

150 {
151 FlApplication* self = FL_APPLICATION(object);
153
154 g_clear_pointer(&priv->dart_entrypoint_arguments, g_strfreev);
155
156 G_OBJECT_CLASS(fl_application_parent_class)->dispose(object);
157}

References FL_APPLICATION_GET_PRIVATE, priv, and self.

Referenced by fl_application_class_init().

◆ fl_application_init()

static void fl_application_init ( FlApplication *  self)
static

Definition at line 179 of file fl_application.cc.

179{}

◆ fl_application_local_command_line()

static gboolean fl_application_local_command_line ( GApplication *  application,
gchar ***  arguments,
int *  exit_status 
)
static

Definition at line 125 of file fl_application.cc.

127 {
128 FlApplication* self = FL_APPLICATION(application);
130
131 // Strip out the first argument as it is the binary name.
132 priv->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
133
134 g_autoptr(GError) error = nullptr;
135 if (!g_application_register(application, nullptr, &error)) {
136 g_warning("Failed to register: %s", error->message);
137 *exit_status = 1;
138 return TRUE;
139 }
140
141 // This will only run on the primary instance or this instance with
142 // G_APPLICATION_NON_UNIQUE
143 g_application_activate(application);
144 *exit_status = 0;
145
146 return TRUE;
147}

References error, FL_APPLICATION_GET_PRIVATE, g_autoptr(), priv, self, and TRUE.

Referenced by fl_application_class_init().

◆ fl_application_new()

G_MODULE_EXPORT FlApplication * fl_application_new ( const gchar *  application_id,
GApplicationFlags  flags 
)

FlApplication:

#Flutter-based application with the GTK embedder.

Provides default behaviour for basic Flutter applications. fl_application_new: @application_id: (allow-none): The application ID or NULL. @flags: The application flags.

Creates a new Flutter-based application.

Returns: a new #FlApplication

Definition at line 182 of file fl_application.cc.

183 {
184 return FL_APPLICATION(g_object_new(fl_application_get_type(),
185 "application-id", application_id, "flags",
186 flags, nullptr));
187}

Referenced by TEST().

◆ fl_application_register_plugins()

static void fl_application_register_plugins ( FlApplication *  self,
FlPluginRegistry *  registry 
)
static

Definition at line 55 of file fl_application.cc.

56 {}

Referenced by fl_application_class_init().

◆ G_DEFINE_TYPE_WITH_CODE()

G_DEFINE_TYPE_WITH_CODE ( FlApplication  ,
fl_application  ,
GTK_TYPE_APPLICATION  ,
G_ADD_PRIVATE(FlApplication)   
)

◆ g_signal_emit()

Variable Documentation

◆ fl_application_signals

guint fl_application_signals[LAST_SIGNAL]
static

Definition at line 28 of file fl_application.cc.

Referenced by fl_application_activate(), and fl_application_class_init().

◆ view

FlView* view
Initial value:
{
GtkWindow* window

Definition at line 36 of file fl_application.cc.

Referenced by flutter_runner::testing::TouchEventBuilder::AddViewParameters(), flutter_runner::testing::MouseEventBuilder::AddViewParameters(), flutter::AccessibilityPlugin::Announce(), impeller::Bind(), impeller::RenderPass::BindDynamicResource(), impeller::testing::RecordingRenderPass::BindDynamicResource(), impeller::testing::RecordingRenderPass::BindResource(), impeller::RenderPass::BindResource(), fuchsia_test_utils::CheckViewExistsInSnapshot(), create_regular(), flutter::FlutterCompositor::CreateBackingStore(), flutter::FlutterWindowsEngine::CreateView(), CreateViewController(), flutter_runner::ExternalViewEmbedder::DestroyView(), flutter::testing::FilterMutationsByType(), first_frame_cb(), fl_application_activate(), fl_application_create_window(), fl_plugin_registrar_new(), fl_windowing_handler_create_window(), FlutterDesktopViewGetGraphicsAdapter(), FlutterDesktopViewGetHWND(), G_DECLARE_FINAL_TYPE(), G_DEFINE_TYPE_WITH_PRIVATE(), get_view(), flutter::testing::GetTotalMutationTransformationMatrix(), flutter::PluginRegistrarWindows::GetViewById(), HandleForView(), flutter::WindowManager::HandleMessage(), flutter::HostWindow::HostWindow(), InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(), impeller::KHRSwapchainImageVK::KHRSwapchainImageVK(), fuchsia_test_utils::PortableUITest::LaunchClientWithEmbeddedView(), flutter::FlutterWindowsEngine::OnViewFocusChangeRequest(), flutter::AndroidExternalViewEmbedder::PrerollCompositeEmbeddedView(), flutter::AndroidExternalViewEmbedder2::PrerollCompositeEmbeddedView(), flutter::FlutterCompositor::Present(), flutter::CompositorOpenGL::Present(), flutter::CompositorSoftware::Present(), flutter::EmbedderLayers::PushPlatformViewLayer(), flutter::FlutterWindowsEngine::Run(), flutter::EngineModifier::SetImplicitView(), flutter::EngineModifier::SetViewById(), flutter::PersistentCache::SkKeyToFilePath(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), TEST(), TEST(), TEST(), flutter::TEST(), flutter::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), TEST(), TEST(), TEST(), TEST(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), TEST_F(), TEST_F(), TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), flutter::testing::TEST_F(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), window_data_new(), and flutter::ServiceProtocol::Handler::Description::Write().

◆ window

return window