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

Commit 8182418

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 7df0a6e commit 8182418

File tree

9 files changed

+572
-1
lines changed

9 files changed

+572
-1
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,11 @@ FILE: ../../../flutter/shell/platform/glfw/platform_handler.h
11151115
FILE: ../../../flutter/shell/platform/glfw/public/flutter_glfw.h
11161116
FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.cc
11171117
FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.h
1118+
FILE: ../../../flutter/shell/platform/linux/fl-dart-project.cc
1119+
FILE: ../../../flutter/shell/platform/linux/fl-dart-project.h
1120+
FILE: ../../../flutter/shell/platform/linux/fl-view.cc
1121+
FILE: ../../../flutter/shell/platform/linux/fl-view.h
1122+
FILE: ../../../flutter/shell/platform/linux/flutter-gtk.h
11181123
FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.cc
11191124
FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.h
11201125
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_GTK_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-gtk.h",
84+
]
85+
outputs = [
86+
"$root_out_dir/flutter-gtk/{{source_file_part}}",
87+
]
88+
}
89+
}

shell/platform/linux/config.gni

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
build_linux_shell = false
7+
}

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 <gmodule.h>
6+
7+
#include "fl-dart-project.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", NULL,
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", NULL,
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, NULL));
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), NULL);
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), NULL);
132+
return self->icu_data_path;
133+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
#pragma once
6+
7+
#include <glib-object.h>
8+
9+
#if !defined(__FLUTTER_GTK_INSIDE__) && !defined(FLUTTER_GTK_COMPILATION)
10+
#error "Only <flutter-gtk/flutter-gtk.h> can be included directly."
11+
#endif
12+
13+
G_BEGIN_DECLS
14+
15+
G_DECLARE_FINAL_TYPE(FlDartProject, fl_dart_project, FL, DART_PROJECT, GObject)
16+
17+
FlDartProject* fl_dart_project_new(const gchar* assets_path,
18+
const gchar* icu_data_path);
19+
20+
const gchar* fl_dart_project_get_assets_path(FlDartProject* project);
21+
22+
const gchar* fl_dart_project_get_icu_data_path(FlDartProject* project);
23+
24+
G_END_DECLS

0 commit comments

Comments
 (0)