Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial import of GLFW Linux shell from FDE #8159

Merged
merged 12 commits into from
Mar 20, 2019

Conversation

stuartmorgan
Copy link
Contributor

The initial commit in this PR is the flutter-desktop-embedding Linux implementation essentially as-is, but integrated into the engine build. The main things that need review there are:

  • GN files, which are substantially changed from FDE
  • The basic file location (there was no clear consensus in previous discussion, so I used cpp as a straw man for the location of this code, which will be shared between Linux and Windows when I do the Windows migration shortly)

The second commit switches from jsoncpp to RapidJSON, which could also use review. @franciscojma86 please take a look at that part too.

The last two commits are mechanical changes to stop using Embedder in prefixes (and in code and comments in general, to avoid confusion), and to reformat the files with Flutter's format.

Changes include:
- File structure
- Header guards
- Include paths
- Namespaces
- Integration with the engine's GN build

Doesn't yet build due to use of jsoncpp.
RapidJSON is already in use in the engine, so rather than introduce a
second JSON library, converts all JSON handling to rapidjson.

More error-handling is needed in the text code, but since there's a
pending restructuring of that code full error handling is left for a
follow-up.
@stuartmorgan
Copy link
Contributor Author

I expect that landing this will be blocked on adding a script to apt-get the necessary dependencies and running that on the build bots; I'll put that together now, but wanted to get this under review in parallel.

@chinmaygarde
Copy link
Member

Exciting.

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Publishing comments about BUILD system and source code organization while I do a pass over the source.

# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("$flutter_root/common/config.gni")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention followed is //flutter/shell/platform/<name_of_platform>. Since cpp is not a platform, this location does not make sense. Please move this to platform/linux. If this is going to be a thing on Windows too, platform/glfw with its own subdirectory for linux and Windows specific files (if any).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the code into a combination of flutter/glfw and flutter/common/cpp per discussion.

source_set("common_cpp_library_headers") {
public = _public_headers

defines = _common_defines
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use gn configs for this purpose (see gn help config).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

source_set("common_cpp") {
public = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto about the use of configs. Use a public and private config and targets can selectively import. For the SDK export, you can use a variable that both that copy target and the configs reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per offline discussion, I'm not clear on what to change here, and the decisions was to revisit this in a follow-up.

@@ -16,6 +16,9 @@ declare_args() {

# The runtime mode ("debug", "profile", "release", "dynamic_profile", or "dynamic_release")
flutter_runtime_mode = "debug"

# Whether or not to use the GLFW desktop shell implementation.
use_glfw_desktop = is_linux || is_win
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is not common to all targets. Please move this into a new config.gni file in platform/foo with its own declare_args block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up removing this in the re-org; the reason it was here already (even though turning it off wouldn't work yet) was to help enforce a separation between code that would be used for any C++ implementation and code that's GLFW-specific. With the reorg the file structure does that even more strongly, so the variable isn't needed.

shell/platform/BUILD.gn Outdated Show resolved Hide resolved
]
}

copy("_publish_includes") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why the target names have the _ prefix. If you meant to restrict visibility, use visibility = [ ":*" ] (see gn help visibility) and get rid of the prefix. That will prevent incorrect use by GN.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I misread the GN docs and thought the _ applied to targets as well as variables. Fixed.

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another take with minor nits about convention and such.

BasicMessageChannel(BinaryMessenger* messenger,
const std::string& name,
const MessageCodec<T>* codec)
: messenger_(messenger), name_(name), codec_(codec) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The engine uses the = default convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you meant this for the next line, since this constructor takes arguments and thus isn't a default constructor.

Done for all default constructors/destructors that weren't already using default.

~BasicMessageChannel() {}

// Prevent copying.
BasicMessageChannel(BasicMessageChannel const&) = delete;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding a macro.h file with these decorations for reuse. Seems like boilerplate that is repeated elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DISALLOW_COPY-style macro you are describing is no longer allowed by Google style; explicit deletion is the preferred approach. See
https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types
and
https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros

#include <vector>

#ifdef FLUTTER_DESKTOP_LIBRARY
#include "flutter/shell/platform/cpp/public/flutter_glfw.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify the header search paths in the GN rule to not have to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

JsonMethodCodec() = default;

// MethodCodec:
std::unique_ptr<MethodCall<JsonValueType>> DecodeMethodCallInternal(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention, every overridden method name has a comment right above it listing the superclass that specifies the virtual method. See files like this as an example. Also a single empty newline after each method definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done everywhere.

// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef FLUTTER_DESKTOP_LIBRARY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify the header search paths to make this consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,9 @@
This code is intended to be built into plugins and applications to provide
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see a unittest target for this. If there are not currently available, please create a stub target so folks know where to begin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far FDE didn't have any tests :( Added test targets for the client wrappers, some infrastructure for writing non-trivial tests, and a couple of starter tests. It'll need a bunch of test coverage as follow-up.


ReplyManager::ReplyManager(BinaryReply reply_handler)
: reply_handler_(std::move(reply_handler)) {
if (!reply_handler_) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just be an assertion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All comments from the last round should be addressed; PTAL

~BasicMessageChannel() {}

// Prevent copying.
BasicMessageChannel(BasicMessageChannel const&) = delete;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DISALLOW_COPY-style macro you are describing is no longer allowed by Google style; explicit deletion is the preferred approach. See
https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types
and
https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros

source_set("common_cpp_library_headers") {
public = _public_headers

defines = _common_defines
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

]
}

copy("_publish_includes") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I misread the GN docs and thought the _ applied to targets as well as variables. Fixed.


ReplyManager::ReplyManager(BinaryReply reply_handler)
: reply_handler_(std::move(reply_handler)) {
if (!reply_handler_) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

BasicMessageChannel(BinaryMessenger* messenger,
const std::string& name,
const MessageCodec<T>* codec)
: messenger_(messenger), name_(name), codec_(codec) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you meant this for the next line, since this constructor takes arguments and thus isn't a default constructor.

Done for all default constructors/destructors that weren't already using default.

}

source_set("common_cpp") {
public = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per offline discussion, I'm not clear on what to change here, and the decisions was to revisit this in a follow-up.

# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("$flutter_root/common/config.gni")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the code into a combination of flutter/glfw and flutter/common/cpp per discussion.

#include <vector>

#ifdef FLUTTER_DESKTOP_LIBRARY
#include "flutter/shell/platform/cpp/public/flutter_glfw.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

shell/platform/BUILD.gn Outdated Show resolved Hide resolved
@@ -0,0 +1,9 @@
This code is intended to be built into plugins and applications to provide
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far FDE didn't have any tests :( Added test targets for the client wrappers, some infrastructure for writing non-trivial tests, and a couple of starter tests. It'll need a bunch of test coverage as follow-up.

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admittedly, this PR is a bit too large for me to review thoroughly (and I am sure it is unwieldy for you to have it one another branch while under review). I think the structure is fine and I have done my best to go over everything. Let's land this ASAP and tinker on it once it is in the tree. LGTM. Thanks!

@stuartmorgan stuartmorgan merged commit d452dd5 into flutter:master Mar 20, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 21, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Mar 21, 2019
flutter/engine@d8c89e2...188adf7

git log d8c89e2..188adf7 --no-merges --oneline
188adf7 Removed Activity reference from AccessibilityBridge by using a View for insets instead of the Activity (#18115) (flutter/engine#8231)
d452dd5 Initial import of GLFW Linux shell from FDE (flutter/engine#8159)
5120045 Remove jsoncpp from desktop Linux shell setup (flutter/engine#8230)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff (liyuqian@google.com), and stop
the roller if necessary.
RBogie pushed a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
Changes include:
- File structure
- Header guards
- Include paths
- Namespaces
- Integration with the engine's GN build
- Conversion from jsoncpp to rapidjson
- Style and clang-format adjustment to match engine repository
RBogie added a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
RBogie added a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants