Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ae0c022

Browse files
committed
Add a Linux Shell that uses GTK for rendering.
This is a start on a Linux shell, and only supports rendering of Flutter, no input is currently provided. The API is expected to change as we flesh out the shell. The shell doesn't build by default yet, to enable it you need to set the build_linux_flag gn build argument. This is the first stage of flutter/flutter#30729 The shell only works on X servers, the EGL code will need to be updated to cover Wayland. The Flutter engine currently crashes when the widget is destroyed, but this seems to be an issue in the engine. The code is designed to match GTK conventions. A minimal GTK application that uses this looks like: -------- int main (int argc, char **argv) { gtk_init (&argc, &argv); GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_show (window); g_autoptr(FlDartProject) project = fl_dart_project_new ("./build/flutter_assets", "./linux/flutter/ephemeral/icudtl.dat"); g_autoptr(FlView) view = fl_view_new (project); gtk_widget_show (GTK_WIDGET (view)); gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (view)); gtk_main (); return 0; } --------
1 parent e623335 commit ae0c022

File tree

9 files changed

+557
-1
lines changed

9 files changed

+557
-1
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,11 @@ FILE: ../../../flutter/shell/platform/glfw/platform_handler.h
11321132
FILE: ../../../flutter/shell/platform/glfw/public/flutter_glfw.h
11331133
FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.cc
11341134
FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.h
1135+
FILE: ../../../flutter/shell/platform/linux/fl_dart_project.cc
1136+
FILE: ../../../flutter/shell/platform/linux/fl_dart_project.h
1137+
FILE: ../../../flutter/shell/platform/linux/fl_view.cc
1138+
FILE: ../../../flutter/shell/platform/linux/fl_view.h
1139+
FILE: ../../../flutter/shell/platform/linux/flutter_linux.h
11351140
FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.cc
11361141
FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.h
11371142
FILE: ../../../flutter/shell/platform/windows/client_wrapper/flutter_view_controller.cc

shell/platform/linux/BUILD.gn

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@
55
assert(is_linux)
66

77
import("//flutter/shell/platform/glfw/config.gni")
8+
import("//flutter/shell/platform/linux/config.gni")
89

910
group("linux") {
11+
deps = []
1012
if (build_glfw_shell) {
11-
deps = [
13+
deps += [
1214
":flutter_linux_glfw",
1315
"//flutter/shell/platform/glfw:publish_headers_glfw",
1416
"//flutter/shell/platform/glfw/client_wrapper:publish_wrapper_glfw",
1517
]
1618
}
19+
if (build_linux_shell) {
20+
deps += [
21+
":flutter_linux_gtk",
22+
":publish_headers_linux",
23+
]
24+
}
1725
}
1826

1927
# Temporary workaround for the issue describe in
@@ -37,3 +45,45 @@ if (build_glfw_shell) {
3745
public_configs = [ "//flutter:config" ]
3846
}
3947
}
48+
49+
if (build_linux_shell) {
50+
source_set("flutter_linux") {
51+
sources = [
52+
"fl_dart_project.cc",
53+
"fl_dart_project.h",
54+
"fl_view.cc",
55+
"fl_view.h",
56+
]
57+
58+
configs += [
59+
"//flutter/shell/platform/linux/config:gtk",
60+
"//flutter/shell/platform/linux/config:egl",
61+
]
62+
63+
# Set flag to stop headers being directly included (library users should not do this)
64+
defines = [ "FLUTTER_LINUX_COMPILATION" ]
65+
66+
deps = [
67+
"//flutter/shell/platform/embedder:embedder_with_symbol_prefix",
68+
]
69+
}
70+
71+
shared_library("flutter_linux_gtk") {
72+
deps = [
73+
":flutter_linux",
74+
]
75+
76+
public_configs = [ "//flutter:config" ]
77+
}
78+
79+
copy("publish_headers_linux") {
80+
sources = [
81+
"fl_dart_project.h",
82+
"fl_view.h",
83+
"flutter_linux.h",
84+
]
85+
outputs = [
86+
"$root_out_dir/flutter_linux/{{source_file_part}}",
87+
]
88+
}
89+
}

shell/platform/linux/config.gni

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
declare_args() {
6+
# Whether to build the Linux (GTK) shell for the host platform, if available.
7+
#
8+
# The Linux shell is not currently built by default as the CI system doesn't
9+
# (yet) have GTK as a dependency. When that is ready the flag will be removed.
10+
build_linux_shell = false
11+
}

shell/platform/linux/config/BUILD.gn

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
# found in the LICENSE file.
44

55
import("//build/config/linux/pkg_config.gni")
6+
import("//flutter/shell/platform/linux/config.gni")
67

78
pkg_config("x11") {
89
packages = [ "x11" ]
910
}
11+
12+
if (build_linux_shell) {
13+
pkg_config("gtk") {
14+
packages = [ "gtk+-3.0" ]
15+
}
16+
pkg_config("egl") {
17+
packages = [ "egl" ]
18+
}
19+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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 "fl_dart_project.h"
6+
7+
#include <gmodule.h>
8+
9+
struct _FlDartProject {
10+
GObject parent_instance;
11+
12+
gchar* assets_path;
13+
gchar* icu_data_path;
14+
};
15+
16+
enum { PROP_ASSETS_PATH = 1, PROP_ICU_DATA_PATH, PROP_LAST };
17+
18+
G_DEFINE_TYPE(FlDartProject, fl_dart_project, G_TYPE_OBJECT)
19+
20+
static void fl_dart_project_set_property(GObject* object,
21+
guint prop_id,
22+
const GValue* value,
23+
GParamSpec* pspec) {
24+
FlDartProject* self = FL_DART_PROJECT(object);
25+
26+
switch (prop_id) {
27+
case PROP_ASSETS_PATH:
28+
g_free(self->assets_path);
29+
self->assets_path = g_strdup(g_value_get_string(value));
30+
break;
31+
case PROP_ICU_DATA_PATH:
32+
g_free(self->icu_data_path);
33+
self->icu_data_path = g_strdup(g_value_get_string(value));
34+
break;
35+
default:
36+
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
37+
break;
38+
}
39+
}
40+
41+
static void fl_dart_project_get_property(GObject* object,
42+
guint prop_id,
43+
GValue* value,
44+
GParamSpec* pspec) {
45+
FlDartProject* self = FL_DART_PROJECT(object);
46+
47+
switch (prop_id) {
48+
case PROP_ASSETS_PATH:
49+
g_value_set_string(value, self->assets_path);
50+
break;
51+
case PROP_ICU_DATA_PATH:
52+
g_value_set_string(value, self->icu_data_path);
53+
break;
54+
default:
55+
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
56+
break;
57+
}
58+
}
59+
60+
static void fl_dart_project_dispose(GObject* object) {
61+
FlDartProject* self = FL_DART_PROJECT(object);
62+
63+
g_clear_pointer(&self->assets_path, g_free);
64+
g_clear_pointer(&self->icu_data_path, g_free);
65+
66+
G_OBJECT_CLASS(fl_dart_project_parent_class)->dispose(object);
67+
}
68+
69+
static void fl_dart_project_class_init(FlDartProjectClass* klass) {
70+
G_OBJECT_CLASS(klass)->set_property = fl_dart_project_set_property;
71+
G_OBJECT_CLASS(klass)->get_property = fl_dart_project_get_property;
72+
G_OBJECT_CLASS(klass)->dispose = fl_dart_project_dispose;
73+
74+
g_object_class_install_property(
75+
G_OBJECT_CLASS(klass), PROP_ASSETS_PATH,
76+
g_param_spec_string(
77+
"assets-path", "assets-path", "Path to Flutter assets", nullptr,
78+
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
79+
G_PARAM_STATIC_STRINGS)));
80+
g_object_class_install_property(
81+
G_OBJECT_CLASS(klass), PROP_ICU_DATA_PATH,
82+
g_param_spec_string(
83+
"icu-data-path", "icu-data-path", "Path to ICU data", nullptr,
84+
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
85+
G_PARAM_STATIC_STRINGS)));
86+
}
87+
88+
static void fl_dart_project_init(FlDartProject* self) {}
89+
90+
/**
91+
* fl_dart_project_new:
92+
* @assets_path: a file path, e.g. "build/assets"
93+
* @icu_data_path: a file path, e.g. "build/icudtl.dat"
94+
*
95+
* Create a Flutter project.
96+
*
97+
* Returns: a new #FlDartProject
98+
*/
99+
G_MODULE_EXPORT FlDartProject* fl_dart_project_new(const gchar* assets_path,
100+
const gchar* icu_data_path) {
101+
return static_cast<FlDartProject*>(
102+
g_object_new(fl_dart_project_get_type(), "assets-path", assets_path,
103+
"icu-data-path", icu_data_path, nullptr));
104+
}
105+
106+
/**
107+
* fl_dart_project_get_assets_path:
108+
* @view: a #FlDartProject
109+
*
110+
* Get the path to the directory containing the assets used in the Flutter
111+
* application.
112+
*
113+
* Returns: a file path, e.g. "build/assets"
114+
*/
115+
G_MODULE_EXPORT const gchar* fl_dart_project_get_assets_path(
116+
FlDartProject* self) {
117+
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
118+
return self->assets_path;
119+
}
120+
121+
/**
122+
* fl_dart_project_get_icu_data_path:
123+
* @view: a #FlDartProject
124+
*
125+
* Get the path to the ICU data file in the Flutter application.
126+
*
127+
* Returns: a file path, e.g. "build/icudtl.dat"
128+
*/
129+
G_MODULE_EXPORT const gchar* fl_dart_project_get_icu_data_path(
130+
FlDartProject* self) {
131+
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
132+
return self->icu_data_path;
133+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_DART_PROJECT_H_
6+
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_DART_PROJECT_H_
7+
8+
#include <glib-object.h>
9+
10+
#if !defined(__FLUTTER_LINUX_INSIDE__) && !defined(FLUTTER_LINUX_COMPILATION)
11+
#error "Only <flutter_linux/flutter_linux.h> can be included directly."
12+
#endif
13+
14+
G_BEGIN_DECLS
15+
16+
G_DECLARE_FINAL_TYPE(FlDartProject, fl_dart_project, FL, DART_PROJECT, GObject)
17+
18+
FlDartProject* fl_dart_project_new(const gchar* assets_path,
19+
const gchar* icu_data_path);
20+
21+
const gchar* fl_dart_project_get_assets_path(FlDartProject* project);
22+
23+
const gchar* fl_dart_project_get_icu_data_path(FlDartProject* project);
24+
25+
G_END_DECLS
26+
27+
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_DART_PROJECT_H_

0 commit comments

Comments
 (0)