Skip to content

Commit

Permalink
Add a Linux Shell that uses GTK for rendering. (#16977)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-ancell committed Mar 24, 2020
1 parent 3a68f68 commit c93b67a
Show file tree
Hide file tree
Showing 9 changed files with 574 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,11 @@ FILE: ../../../flutter/shell/platform/glfw/platform_handler.h
FILE: ../../../flutter/shell/platform/glfw/public/flutter_glfw.h
FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.cc
FILE: ../../../flutter/shell/platform/glfw/text_input_plugin.h
FILE: ../../../flutter/shell/platform/linux/fl_dart_project.cc
FILE: ../../../flutter/shell/platform/linux/fl_view.cc
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_view.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/flutter_linux.h
FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.cc
FILE: ../../../flutter/shell/platform/windows/angle_surface_manager.h
FILE: ../../../flutter/shell/platform/windows/client_wrapper/dart_project_unittests.cc
Expand Down
56 changes: 55 additions & 1 deletion shell/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
assert(is_linux)

import("//flutter/shell/platform/glfw/config.gni")
import("//flutter/shell/platform/linux/config.gni")

group("linux") {
deps = []
if (build_glfw_shell) {
deps = [
deps += [
":flutter_linux_glfw",
"//flutter/shell/platform/glfw:publish_headers_glfw",
"//flutter/shell/platform/glfw/client_wrapper:publish_wrapper_glfw",
]
}
if (build_linux_shell) {
deps += [
":flutter_linux_gtk",
":publish_headers_linux",
]
}
}

# Temporary workaround for the issue describe in
Expand All @@ -37,3 +45,49 @@ if (build_glfw_shell) {
public_configs = [ "//flutter:config" ]
}
}

if (build_linux_shell) {
_public_headers = [
"public/flutter_linux/fl_dart_project.h",
"public/flutter_linux/fl_view.h",
"public/flutter_linux/flutter_linux.h",
]

config("relative_flutter_linux_headers") {
include_dirs = [ "public" ]
}

source_set("flutter_linux") {
sources = [
"fl_dart_project.cc",
"fl_view.cc",
]

configs += [
"//flutter/shell/platform/linux/config:gtk",
"//flutter/shell/platform/linux/config:egl",
]

# Set flag to stop headers being directly included (library users should not do this)
defines = [ "FLUTTER_LINUX_COMPILATION" ]

deps = [
"//flutter/shell/platform/embedder:embedder_with_symbol_prefix",
]
}

shared_library("flutter_linux_gtk") {
deps = [
":flutter_linux",
]

public_configs = [ "//flutter:config" ]
}

copy("publish_headers_linux") {
sources = _public_headers
outputs = [
"$root_out_dir/flutter_linux/{{source_file_part}}",
]
}
}
11 changes: 11 additions & 0 deletions shell/platform/linux/config.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

declare_args() {
# Whether to build the Linux (GTK) shell for the host platform, if available.
#
# The Linux shell is not currently built by default as the CI system doesn't
# (yet) have GTK as a dependency. When that is ready the flag will be removed.
build_linux_shell = false
}
10 changes: 10 additions & 0 deletions shell/platform/linux/config/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
# found in the LICENSE file.

import("//build/config/linux/pkg_config.gni")
import("//flutter/shell/platform/linux/config.gni")

pkg_config("x11") {
packages = [ "x11" ]
}

if (build_linux_shell) {
pkg_config("gtk") {
packages = [ "gtk+-3.0" ]
}
pkg_config("egl") {
packages = [ "egl" ]
}
}
140 changes: 140 additions & 0 deletions shell/platform/linux/fl_dart_project.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"

#include <gmodule.h>

/**
* FlDartProject:
*
* #FlDartProject represents a Dart project. It is used provide information
* about the application when creating a #FlView.
*/

struct _FlDartProject {
GObject parent_instance;

gchar* assets_path;
gchar* icu_data_path;
};

enum { PROP_ASSETS_PATH = 1, PROP_ICU_DATA_PATH, PROP_LAST };

G_DEFINE_TYPE(FlDartProject, fl_dart_project, G_TYPE_OBJECT)

static void fl_dart_project_set_property(GObject* object,
guint prop_id,
const GValue* value,
GParamSpec* pspec) {
FlDartProject* self = FL_DART_PROJECT(object);

switch (prop_id) {
case PROP_ASSETS_PATH:
g_free(self->assets_path);
self->assets_path = g_strdup(g_value_get_string(value));
break;
case PROP_ICU_DATA_PATH:
g_free(self->icu_data_path);
self->icu_data_path = g_strdup(g_value_get_string(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void fl_dart_project_get_property(GObject* object,
guint prop_id,
GValue* value,
GParamSpec* pspec) {
FlDartProject* self = FL_DART_PROJECT(object);

switch (prop_id) {
case PROP_ASSETS_PATH:
g_value_set_string(value, self->assets_path);
break;
case PROP_ICU_DATA_PATH:
g_value_set_string(value, self->icu_data_path);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void fl_dart_project_dispose(GObject* object) {
FlDartProject* self = FL_DART_PROJECT(object);

g_clear_pointer(&self->assets_path, g_free);
g_clear_pointer(&self->icu_data_path, g_free);

G_OBJECT_CLASS(fl_dart_project_parent_class)->dispose(object);
}

static void fl_dart_project_class_init(FlDartProjectClass* klass) {
G_OBJECT_CLASS(klass)->set_property = fl_dart_project_set_property;
G_OBJECT_CLASS(klass)->get_property = fl_dart_project_get_property;
G_OBJECT_CLASS(klass)->dispose = fl_dart_project_dispose;

g_object_class_install_property(
G_OBJECT_CLASS(klass), PROP_ASSETS_PATH,
g_param_spec_string(
"assets-path", "assets-path", "Path to Flutter assets", nullptr,
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property(
G_OBJECT_CLASS(klass), PROP_ICU_DATA_PATH,
g_param_spec_string(
"icu-data-path", "icu-data-path", "Path to ICU data", nullptr,
static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)));
}

static void fl_dart_project_init(FlDartProject* self) {}

/**
* fl_dart_project_new:
* @assets_path: a file path, e.g. "build/assets"
* @icu_data_path: a file path, e.g. "build/icudtl.dat"
*
* Create a Flutter project.
*
* Returns: a new #FlDartProject
*/
G_MODULE_EXPORT FlDartProject* fl_dart_project_new(const gchar* assets_path,
const gchar* icu_data_path) {
return static_cast<FlDartProject*>(
g_object_new(fl_dart_project_get_type(), "assets-path", assets_path,
"icu-data-path", icu_data_path, nullptr));
}

/**
* fl_dart_project_get_assets_path:
* @view: a #FlDartProject
*
* Get the path to the directory containing the assets used in the Flutter
* application.
*
* Returns: a file path, e.g. "build/assets"
*/
G_MODULE_EXPORT const gchar* fl_dart_project_get_assets_path(
FlDartProject* self) {
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
return self->assets_path;
}

/**
* fl_dart_project_get_icu_data_path:
* @view: a #FlDartProject
*
* Get the path to the ICU data file in the Flutter application.
*
* Returns: a file path, e.g. "build/icudtl.dat"
*/
G_MODULE_EXPORT const gchar* fl_dart_project_get_icu_data_path(
FlDartProject* self) {
g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
return self->icu_data_path;
}
Loading

0 comments on commit c93b67a

Please sign in to comment.