diff --git a/.travis.yaml b/.travis.yaml new file mode 100644 index 000000000..7b115be69 --- /dev/null +++ b/.travis.yaml @@ -0,0 +1,35 @@ +matrix: + include: + - os: linux + languge: cpp + before_install: + - sudo apt-get update + install: + - build/travis/linux/install_dependencies + - build/travis/install_flutter $TRAVIS_BUILD_DIR/.. + before_script: + - export PATH=$PATH:$TRAVIS_BUILD_DIR/../flutter/bin:$TRAVIS_BUILD_DIR/bin + script: + - make -C example/linux + + - os: linux + languge: cpp + before_install: + - sudo apt-get update + install: + - build/travis/linux/install_dependencies + - build/travis/install_flutter $TRAVIS_BUILD_DIR/.. + - sudo apt-get install -y ninja-build + - build/travis/linux/install_gn bin + before_script: + - export PATH=$PATH:$TRAVIS_BUILD_DIR/bin + script: + - make -C example/linux USE_GN=1 + + - os: osx + language: objective-c + xcode_project: example/macos/ExmapleEmbedder.xcodeproj + xcode_scheme: ExampleEmbedder + install: + - build/travis/install_flutter $TRAVIS_BUILD_DIR/.. + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ae319c70a..c90cd5ecf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,3 +21,19 @@ All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more information on using pull requests. + +## Project Standards + +- C++ code should follow + [Google's C++ style guide](https://google.github.io/styleguide/cppguide.html). +- Objective-C code should follow + [Google's Objective-C style guide](http://google.github.io/styleguide/objcguide.html). +- For C++ and Objective-C code, please run `clang-format -style=file` on files + you have changed if possible. If you don't have `clang-format`, don't worry; + a project member can do it prior to submission. +- Dart code should follow the + [Dart style guide](https://www.dartlang.org/guides/language/effective-dart/style) + and use `dartfmt`. +- Build scripts and other tooling should be written it Dart. (Some existing + scripts are `bash` or `.bat` scripts; if you need to make non-trivial changes + to one of those scripts, please convert it to Dart first if possible.) diff --git a/Debugging.md b/Debugging.md index 77321e023..7e27b3b1b 100644 --- a/Debugging.md +++ b/Debugging.md @@ -30,7 +30,7 @@ There are two options: 1. **Hard-code the port**. In your embedder code, add `--observatory-port=49494` (substituting a port of your choice) to the list of arguments passed to the engine. If you are using `example/`, or code based on it, look for the - line that adds `--dart-non-checked-mode` for an example of adding arguments. + line that adds `--disable-dart-asserts` for an example of adding arguments. (Be sure not to add the `observatory-port` argument inside the `#if`, however.) diff --git a/README.md b/README.md index 1f703698c..3d482078f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Desktop Embedding for Flutter -This purpose of this project is to support building +The purpose of this project is to support building applications that use [Flutter](https://github.com/flutter/flutter) on Windows, macOS, and Linux. It consists of libraries that implement [Flutter's embedding -API](https://github.com/flutter/engine/wiki/Custom-Flutter-Engine-Embedders), +API](https://github.com/flutter/flutter/wiki/Custom-Flutter-Engine-Embedders), handling drawing and mouse/keyboard input, as well as optional plugins to access other native platform functionality. @@ -25,7 +25,7 @@ a Flutter tree in the same parent directory as the clone of this project: Alternately, you can place a `.flutter_location_config` file in the directory containing flutter-desktop-embedding, containing a path to the Flutter tree to use, if you prefer not to have the Flutter tree next to -flutter-desktop-emebbing. +flutter-desktop-embedding. ### Repository Structure @@ -82,4 +82,3 @@ speed up the debugging process. request, or [write a plugin](plugins/README.md#writing-your-own-plugins)! * The Linux and Windows implementations currently use GLFW. This is not going to be the final implementation for either platform. -* Plugins and text input do not yet work on Windows. diff --git a/build/travis/install_flutter b/build/travis/install_flutter new file mode 100755 index 000000000..c0a2cc3a5 --- /dev/null +++ b/build/travis/install_flutter @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +readonly CHANNEL="stable" +readonly VERSION="1.0.0" + +if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then + readonly FLUTTER_OS="linux" + readonly ARCHIVE_EXTENSION="tar.xz" +else + readonly FLUTTER_OS="macos" + readonly ARCHIVE_EXTENSION="zip" +fi +readonly DOWNLOAD_BASE="https://storage.googleapis.com/flutter_infra/releases" +readonly DOWNLOAD_URI="${DOWNLOAD_BASE}/${CHANNEL}/${FLUTTER_OS}/flutter_${FLUTTER_OS}_v${VERSION}-${CHANNEL}.${ARCHIVE_EXTENSION}" +readonly TEMP_LOCATION="/tmp/flutter.${ARCHIVE_EXTENSION}" + +echo "Downloading ${DOWNLOAD_URI}" +if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then + wget "${DOWNLOAD_URI}" -O "${TEMP_LOCATION}" + tar xf "${TEMP_LOCATION}" -C "$1" +else + curl -o "${TEMP_LOCATION}" "${DOWNLOAD_URI}" + unzip "${TEMP_LOCATION}" -d "$1" +fi diff --git a/build/travis/linux/install_dependencies b/build/travis/linux/install_dependencies new file mode 100755 index 000000000..44c09e0d2 --- /dev/null +++ b/build/travis/linux/install_dependencies @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +sudo apt-get install -y libglfw3-dev libepoxy-dev libjsoncpp-dev libgtk-3-dev \ + libx11-dev pkg-config diff --git a/build/travis/linux/install_gn b/build/travis/linux/install_gn new file mode 100755 index 000000000..850c9080a --- /dev/null +++ b/build/travis/linux/install_gn @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +readonly DOWNLOAD_URI=https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest +readonly TEMP_LOCATION=/tmp/gn.zip + +wget -O "${TEMP_LOCATION}" "${DOWNLOAD_URI}" +unzip -d "$1" "${TEMP_LOCATION}" diff --git a/example/linux/Makefile b/example/linux/Makefile index 13bacd7e7..5cf7fa045 100644 --- a/example/linux/Makefile +++ b/example/linux/Makefile @@ -37,7 +37,7 @@ ALL_LIBS=$(FLUTTER_EMBEDDER_LIB) $(FLUTTER_ENGINE_LIB) $(PLUGIN_LIBS) # Headers PLUGIN_DIRS=$(patsubst %,$(PLUGINS_DIR)/%/linux,$(PLUGIN_NAMES)) LIBRARY_DIRS=$(FLUTTER_EMBEDDER_LIB_DIR) $(PLUGIN_DIRS) -INCLUDE_DIRS=$(patsubst %,%/include,$(LIBRARY_DIRS)) +INCLUDE_DIRS=$(patsubst %,%/include,$(LIBRARY_DIRS)) $(PROJECT_ROOT)/library/include # Tools BUILD_ASSETS_BIN=$(TOOLS_DIR)/build_flutter_assets @@ -85,6 +85,9 @@ endif CXX=g++ -std=c++14 CXXFLAGS=-Wall -Werror $(shell pkg-config --cflags jsoncpp) CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS)) +ifdef USE_GN +CPPFLAGS+=-DUSE_FLATTENED_INCLUDES +endif LDFLAGS=-L$(OUT_LIB_DIR) \ -lglfw \ $(shell pkg-config --libs jsoncpp) \ diff --git a/example/linux/flutter_embedder_example.cc b/example/linux/flutter_embedder_example.cc index 92232f139..5cfad92a7 100644 --- a/example/linux/flutter_embedder_example.cc +++ b/example/linux/flutter_embedder_example.cc @@ -21,9 +21,14 @@ #include #include -#include #include +#ifdef USE_FLATTENED_INCLUDES +#include +#else +#include +#endif + namespace { // Returns the path of the directory containing this executable, or an empty @@ -48,7 +53,7 @@ std::string GetExecutableDirectory() { } // namespace int main(int argc, char **argv) { - if (!glfwInit()) { + if (!flutter_desktop_embedding::FlutterInit()) { std::cerr << "Couldn't init GLFW" << std::endl; } @@ -67,13 +72,13 @@ int main(int argc, char **argv) { // args. arguments.push_back(argv[0]); #ifdef NDEBUG - arguments.push_back("--dart-non-checked-mode"); + arguments.push_back("--disable-dart-asserts"); #endif // Start the engine. auto window = flutter_desktop_embedding::CreateFlutterWindowInSnapshotMode( 640, 480, assets_path, icu_data_path, arguments); if (window == nullptr) { - glfwTerminate(); + flutter_desktop_embedding::FlutterTerminate(); return EXIT_FAILURE; } diff --git a/example/macos/ExampleEmbedder.xcodeproj/project.pbxproj b/example/macos/ExampleEmbedder.xcodeproj/project.pbxproj index b046f2444..125827f21 100644 --- a/example/macos/ExampleEmbedder.xcodeproj/project.pbxproj +++ b/example/macos/ExampleEmbedder.xcodeproj/project.pbxproj @@ -254,7 +254,7 @@ 33CC10EC2044A3C60003C045 = { CreatedOnToolsVersion = 9.2; LastSwiftMigration = 0920; - ProvisioningStyle = Automatic; + ProvisioningStyle = Manual; }; 33CC111A2044C6BA0003C045 = { CreatedOnToolsVersion = 9.2; @@ -526,12 +526,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.google.FlutterEmbedderMacExample.Example-Embedder"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Example Embedder-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 4.0; @@ -543,12 +545,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_STYLE = Automatic; + CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.google.FlutterEmbedderMacExample.Example-Embedder"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Example Embedder-Bridging-Header.h"; SWIFT_VERSION = 4.0; }; diff --git a/example/macos/ExampleEmbedder.xcodeproj/xcshareddata/xcschemes/ExampleEmbedder.xcscheme b/example/macos/ExampleEmbedder.xcodeproj/xcshareddata/xcschemes/ExampleEmbedder.xcscheme new file mode 100644 index 000000000..294ef25a5 --- /dev/null +++ b/example/macos/ExampleEmbedder.xcodeproj/xcshareddata/xcschemes/ExampleEmbedder.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/macos/ExampleWindow.swift b/example/macos/ExampleWindow.swift index 6d5860b45..c3d88a134 100644 --- a/example/macos/ExampleWindow.swift +++ b/example/macos/ExampleWindow.swift @@ -27,7 +27,7 @@ class ExampleWindow: NSWindow { // command line string. var arguments = [CommandLine.arguments[0]]; #if !DEBUG - arguments.append("--dart-non-checked-mode"); + arguments.append("--disable-dart-asserts"); #endif flutterViewController.launchEngine( withAssetsPath: assets, diff --git a/example/windows/GLFW Example.vcxproj b/example/windows/GLFW Example.vcxproj index 1da8b14ed..c61b451f0 100644 --- a/example/windows/GLFW Example.vcxproj +++ b/example/windows/GLFW Example.vcxproj @@ -72,7 +72,7 @@ $(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\ $(SolutionDir)bin\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\ - $(ProjectDir)..\..\library\windows\dependencies\GLFW\;$(ProjectDir)..\..\library\windows\;$(IncludePath) + $(ProjectDir)..\..\library\windows\dependencies\;$(ProjectDir)..\..\;$(IncludePath);$(ProjectDir)..\..\library\windows\;$(ProjectDir)..\..\library\include\ $(ProjectDir)..\..\library\windows\dependencies\GLFW\;$(SolutionDir)bin\$(Platform)\$(Configuration)\GLFW Library\;$(LibraryPath) @@ -84,7 +84,7 @@ $(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\ $(SolutionDir)bin\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\ - $(ProjectDir)..\..\library\windows\dependencies\GLFW\;$(ProjectDir)..\..\library\windows\;$(IncludePath) + $(ProjectDir)..\..\library\windows\dependencies\;$(ProjectDir)..\..\;$(IncludePath);$(ProjectDir)..\..\library\windows\ $(ProjectDir)..\..\library\windows\dependencies\GLFW\;$(SolutionDir)bin\$(Platform)\$(Configuration)\GLFW Library\;$(LibraryPath) @@ -227,4 +227,4 @@ $(SolutionDir) - + \ No newline at end of file diff --git a/example/windows/flutter_embedder_example.cpp b/example/windows/flutter_embedder_example.cpp index d8485e70f..389960b35 100644 --- a/example/windows/flutter_embedder_example.cpp +++ b/example/windows/flutter_embedder_example.cpp @@ -15,10 +15,10 @@ #include #include -#include +#include "flutter_desktop_embedding/glfw/embedder.h" int main(int argc, char **argv) { - if (!FlutterInit()) { + if (!flutter_desktop_embedding::FlutterInit()) { std::cout << "Couldn't init GLFW" << std::endl; } // Arguments for the Flutter Engine. @@ -27,19 +27,19 @@ int main(int argc, char **argv) { // args. arguments.push_back(argv[0]); #ifndef _DEBUG - arguments.push_back("--dart-non-checked-mode"); + arguments.push_back("--disable-dart-asserts"); #endif // Start the engine. // TODO: Make paths relative to the executable so it can be run from anywhere. - auto window = CreateFlutterWindowInSnapshotMode( + auto window = flutter_desktop_embedding::CreateFlutterWindowInSnapshotMode( 640, 480, "..\\..\\example\\flutter_app\\build\\flutter_assets", "..\\..\\library\\windows\\dependencies\\engine\\icudtl.dat", arguments); if (window == nullptr) { - FlutterTerminate(); + flutter_desktop_embedding::FlutterTerminate(); return EXIT_FAILURE; } - FlutterWindowLoop(window); - FlutterTerminate(); + flutter_desktop_embedding::FlutterWindowLoop(window); + flutter_desktop_embedding::FlutterTerminate(); return EXIT_SUCCESS; } diff --git a/library/BUILD.gn b/library/BUILD.gn index 0eb36cd65..605deddc5 100644 --- a/library/BUILD.gn +++ b/library/BUILD.gn @@ -17,42 +17,51 @@ import("//build/packaging.gni") import("//library/engine.gni") published_shared_library("flutter_embedder") { - if (is_linux) { + # GLFW embedding implementation. + if (is_linux || is_win) { + public = [ + "include/flutter_desktop_embedding/glfw/embedder.h", + ] sources = [ - "linux/src/internal/engine_method_result.cc", - "linux/src/internal/engine_method_result.h", - "linux/src/internal/json_message_codec.cc", - "linux/src/internal/json_message_codec.h", - "linux/src/internal/key_event_handler.cc", - "linux/src/internal/key_event_handler.h", - "linux/src/internal/keyboard_hook_handler.h", - "linux/src/internal/plugin_handler.cc", - "linux/src/internal/plugin_handler.h", - "linux/src/internal/text_input_model.cc", - "linux/src/internal/text_input_model.h", - "linux/src/internal/text_input_plugin.cc", - "linux/src/internal/text_input_plugin.h", - "linux/src/embedder.cc", - "linux/src/json_method_call.cc", - "linux/src/json_method_codec.cc", - "linux/src/json_plugin.cc", - "linux/src/method_call.cc", - "linux/src/method_channel.cc", - "linux/src/method_codec.cc", - "linux/src/method_result.cc", - "linux/src/plugin.cc", + "common/glfw/embedder.cc", + "common/glfw/key_event_handler.cc", + "common/glfw/key_event_handler.h", + "common/glfw/keyboard_hook_handler.h", + "common/glfw/text_input_plugin.cc", + "common/glfw/text_input_plugin.h", ] - public = [ - "linux/include/flutter_desktop_embedding/binary_messenger.h", - "linux/include/flutter_desktop_embedding/embedder.h", - "linux/include/flutter_desktop_embedding/json_method_call.h", - "linux/include/flutter_desktop_embedding/json_method_codec.h", - "linux/include/flutter_desktop_embedding/json_plugin.h", - "linux/include/flutter_desktop_embedding/method_call.h", - "linux/include/flutter_desktop_embedding/method_channel.h", - "linux/include/flutter_desktop_embedding/method_codec.h", - "linux/include/flutter_desktop_embedding/method_result.h", - "linux/include/flutter_desktop_embedding/plugin.h", + } + + # Embedding-agnostic shared C++. + if (is_linux || is_win) { + sources += [ + "common/internal/engine_method_result.cc", + "common/internal/engine_method_result.h", + "common/internal/json_message_codec.cc", + "common/internal/json_message_codec.h", + "common/internal/plugin_handler.cc", + "common/internal/plugin_handler.h", + "common/internal/text_input_model.cc", + "common/internal/text_input_model.h", + "common/json_method_call.cc", + "common/json_method_codec.cc", + "common/json_plugin.cc", + "common/method_call.cc", + "common/method_channel.cc", + "common/method_codec.cc", + "common/method_result.cc", + "common/plugin.cc", + ] + public += [ + "include/flutter_desktop_embedding/binary_messenger.h", + "include/flutter_desktop_embedding/json_method_call.h", + "include/flutter_desktop_embedding/json_method_codec.h", + "include/flutter_desktop_embedding/json_plugin.h", + "include/flutter_desktop_embedding/method_call.h", + "include/flutter_desktop_embedding/method_channel.h", + "include/flutter_desktop_embedding/method_codec.h", + "include/flutter_desktop_embedding/method_result.h", + "include/flutter_desktop_embedding/plugin.h", ] } diff --git a/library/GN.md b/library/GN.md index 32cb98977..2288ee985 100644 --- a/library/GN.md +++ b/library/GN.md @@ -24,7 +24,11 @@ $ tools/gn_dart gen out $ ninja -C out flutter_embedder ``` -The build results will be in the top-level `out/` directory. +The build results will be in the top-level `out/` directory. `out/include/` will +have the public headers for all build libraries, so you can point dependent +builds at that single location rather than the `include/` directories in the +source tree. You will need to set USE\_FLATTENED\_INCLUDES in your build, since +the embedding header library layout is slightly different under `out/include/`. Subsequent builds only require the `ninja` step, as the build will automatically re-run GN generation if necessary. diff --git a/library/README.md b/library/README.md index e325a41d6..79329f705 100644 --- a/library/README.md +++ b/library/README.md @@ -49,7 +49,7 @@ $ sudo apt-get install libglfw3-dev libepoxy-dev libjsoncpp-dev libgtk-3-dev \ #### Using the Library Run `make` under `linux/`, then link `libflutter_embedder.so` into your -binary. See [embedder.h](linux/include/flutter_desktop_embedding/embedder.h) +binary. See [embedder.h](include/flutter_desktop_embedding/glfw/embedder.h) for details on calling into the library. You will also need to link `libflutter_engine.so` into your binary. diff --git a/library/linux/src/embedder.cc b/library/common/glfw/embedder.cc similarity index 84% rename from library/linux/src/embedder.cc rename to library/common/glfw/embedder.cc index 5ce1396e8..6c378538d 100644 --- a/library/linux/src/embedder.cc +++ b/library/common/glfw/embedder.cc @@ -11,25 +11,27 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include -#include -#include -#include +#include "library/include/flutter_desktop_embedding/glfw/embedder.h" +#include #include #include #include #include -#include -#include #include -#include "library/linux/src/internal/key_event_handler.h" -#include "library/linux/src/internal/keyboard_hook_handler.h" -#include "library/linux/src/internal/plugin_handler.h" -#include "library/linux/src/internal/text_input_plugin.h" +#include "library/common/glfw/key_event_handler.h" +#include "library/common/glfw/keyboard_hook_handler.h" +#include "library/common/glfw/text_input_plugin.h" +#include "library/common/internal/plugin_handler.h" + +#ifdef __linux__ +// For plugin-compatible event handling (e.g., modal windows). +#include +#include +#endif // GLFW_TRUE & GLFW_FALSE are introduced since libglfw-3.3, // add definitions here to compile under the old versions. @@ -51,67 +53,22 @@ struct FlutterEmbedderState { // deleted from the heap. std::vector keyboard_hook_handlers; + // Handles raw key interactions from GLFW. - // TODO: Move key_event_handler once - // https://github.com/google/flutter-desktop-embedding/issues/102 is resolved. + // TODO: Revisit ownership model once Issue #102 is resolved. std::unique_ptr key_event_handler; }; static constexpr char kDefaultWindowTitle[] = "Flutter"; -// Callback forward declarations. -static void GLFWKeyCallback(GLFWwindow *window, int key, int scancode, - int action, int mods); -static void GLFWCharCallback(GLFWwindow *window, unsigned int code_point); -static void GLFWmouseButtonCallback(GLFWwindow *window, int key, int action, - int mods); - +// Retrieves state bag for the window in question from the GLFWWindow. static FlutterEmbedderState *GetSavedEmbedderState(GLFWwindow *window) { return reinterpret_cast( glfwGetWindowUserPointer(window)); } -// Flushes event queue and then assigns default window callbacks. -static void GLFWAssignEventCallbacks(GLFWwindow *window) { - glfwPollEvents(); - glfwSetKeyCallback(window, GLFWKeyCallback); - glfwSetCharCallback(window, GLFWCharCallback); - glfwSetMouseButtonCallback(window, GLFWmouseButtonCallback); -} - -// Clears default window events. -static void GLFWClearEventCallbacks(GLFWwindow *window) { - glfwSetKeyCallback(window, nullptr); - glfwSetCharCallback(window, nullptr); - glfwSetMouseButtonCallback(window, nullptr); -} - -static void GLFWwindowSizeCallback(GLFWwindow *window, int width, int height) { - FlutterWindowMetricsEvent event = {}; - event.struct_size = sizeof(event); - event.width = width; - event.height = height; - event.pixel_ratio = 1.0; - auto state = GetSavedEmbedderState(window); - FlutterEngineSendWindowMetricsEvent(state->engine, &event); -} - -static void GLFWOnFlutterPlatformMessage(const FlutterPlatformMessage *message, - void *user_data) { - if (message->struct_size != sizeof(FlutterPlatformMessage)) { - std::cerr << "Invalid message size received. Expected: " - << sizeof(FlutterPlatformMessage) << " but received " - << message->struct_size << std::endl; - return; - } - - GLFWwindow *window = reinterpret_cast(user_data); - auto state = GetSavedEmbedderState(window); - state->plugin_handler->HandleMethodCallMessage( - message, [window] { GLFWClearEventCallbacks(window); }, - [window] { GLFWAssignEventCallbacks(window); }); -} - +// When GLFW calls back to the window with a cursor position move, forwards to +// FlutterEngine as a pointer event with appropriate phase. static void GLFWcursorPositionCallbackAtPhase(GLFWwindow *window, FlutterPointerPhase phase, double x, double y) { @@ -124,14 +81,16 @@ static void GLFWcursorPositionCallbackAtPhase(GLFWwindow *window, std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch()) .count(); - auto state = GetSavedEmbedderState(window); - FlutterEngineSendPointerEvent(state->engine, &event, 1); + FlutterEngineSendPointerEvent(GetSavedEmbedderState(window)->engine, &event, + 1); } +// Reports cursor move to the Flutter engine. static void GLFWcursorPositionCallback(GLFWwindow *window, double x, double y) { GLFWcursorPositionCallbackAtPhase(window, FlutterPointerPhase::kMove, x, y); } +// Reports mouse button press to the Flutter engine. static void GLFWmouseButtonCallback(GLFWwindow *window, int key, int action, int mods) { double x, y; @@ -147,6 +106,7 @@ static void GLFWmouseButtonCallback(GLFWwindow *window, int key, int action, } } +// Passes character input events to registered handlers. static void GLFWCharCallback(GLFWwindow *window, unsigned int code_point) { for (flutter_desktop_embedding::KeyboardHookHandler *handler : GetSavedEmbedderState(window)->keyboard_hook_handlers) { @@ -154,6 +114,7 @@ static void GLFWCharCallback(GLFWwindow *window, unsigned int code_point) { } } +// Passes raw key events to registered handlers. static void GLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) { for (flutter_desktop_embedding::KeyboardHookHandler *handler : @@ -162,6 +123,51 @@ static void GLFWKeyCallback(GLFWwindow *window, int key, int scancode, } } +// Reports window size changes to the Flutter engine. +static void GLFWwindowSizeCallback(GLFWwindow *window, int width, int height) { + FlutterWindowMetricsEvent event = {}; + event.struct_size = sizeof(event); + event.width = width; + event.height = height; + // TODO: Handle pixel ratio for different DPI monitors. + event.pixel_ratio = 1.0; + FlutterEngineSendWindowMetricsEvent(GetSavedEmbedderState(window)->engine, + &event); +} + +// Flushes event queue and then assigns default window callbacks. +static void GLFWAssignEventCallbacks(GLFWwindow *window) { + glfwPollEvents(); + glfwSetKeyCallback(window, GLFWKeyCallback); + glfwSetCharCallback(window, GLFWCharCallback); + glfwSetMouseButtonCallback(window, GLFWmouseButtonCallback); +} + +// Clears default window events. +static void GLFWClearEventCallbacks(GLFWwindow *window) { + glfwSetKeyCallback(window, nullptr); + glfwSetCharCallback(window, nullptr); + glfwSetMouseButtonCallback(window, nullptr); +} + +// The Flutter Engine calls out to this function when new platform messages are +// available +static void GLFWOnFlutterPlatformMessage(const FlutterPlatformMessage *message, + void *user_data) { + if (message->struct_size != sizeof(FlutterPlatformMessage)) { + std::cerr << "Invalid message size received. Expected: " + << sizeof(FlutterPlatformMessage) << " but received " + << message->struct_size << std::endl; + return; + } + + GLFWwindow *window = reinterpret_cast(user_data); + auto state = GetSavedEmbedderState(window); + state->plugin_handler->HandleMethodCallMessage( + message, [window] { GLFWClearEventCallbacks(window); }, + [window] { GLFWAssignEventCallbacks(window); }); +} + static bool GLFWMakeContextCurrent(void *user_data) { GLFWwindow *window = reinterpret_cast(user_data); glfwMakeContextCurrent(window); @@ -192,13 +198,19 @@ static uint32_t GLFWGetActiveFbo(void *user_data) { return 0; } static void GLFWClearCanvas(GLFWwindow *window) { glfwMakeContextCurrent(window); // This color is Material Blue Grey. - glClearColor(0.92549, 0.93725, 0.9451, 0); + glClearColor(236.0 / 255.0, 239.0 / 255.0, 241.0 / 255.0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFlush(); glfwSwapBuffers(window); glfwMakeContextCurrent(nullptr); } +// Resolves the address of the specified OpenGL or OpenGL ES +// core or extension function, if it is supported by the current context. +static void *GLFWProcResolver(void *user_data, const char *name) { + return reinterpret_cast(glfwGetProcAddress(name)); +} + // Spins up an instance of the Flutter Engine. // // This function launches the Flutter Engine in a background thread, supplying @@ -222,6 +234,7 @@ static FlutterEngine RunFlutterEngine( config.open_gl.clear_current = GLFWClearContext; config.open_gl.present = GLFWPresent; config.open_gl.fbo_callback = GLFWGetActiveFbo; + config.open_gl.gl_proc_resolver = GLFWProcResolver; FlutterProjectArgs args = {}; args.struct_size = sizeof(FlutterProjectArgs); args.assets_path = assets_path.c_str(); @@ -242,6 +255,13 @@ static FlutterEngine RunFlutterEngine( namespace flutter_desktop_embedding { +// Initialize glfw +bool FlutterInit() { return glfwInit(); } + +// Tear down glfw +void FlutterTerminate() { glfwTerminate(); } + +// set up embedder state and add the plugin to the plugin_handler bool AddPlugin(GLFWwindow *flutter_window, std::unique_ptr plugin) { auto state = GetSavedEmbedderState(flutter_window); return state->plugin_handler->AddPlugin(std::move(plugin)); @@ -261,7 +281,9 @@ GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height, const std::string &packages_path, const std::string &icu_data_path, const std::vector &arguments) { +#ifdef __linux__ gtk_init(0, nullptr); +#endif auto window = glfwCreateWindow(initial_width, initial_height, kDefaultWindowTitle, NULL, NULL); if (window == nullptr) { @@ -274,6 +296,7 @@ GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height, glfwDestroyWindow(window); return nullptr; } + FlutterEmbedderState *state = new FlutterEmbedderState(); state->plugin_handler = std::make_unique(engine); state->engine = engine; @@ -297,13 +320,19 @@ GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height, } void FlutterWindowLoop(GLFWwindow *flutter_window) { +#ifdef __linux__ // Necessary for GTK thread safety. XInitThreads(); +#endif while (!glfwWindowShouldClose(flutter_window)) { +#ifdef __linux__ glfwPollEvents(); if (gtk_events_pending()) { gtk_main_iteration(); } +#else + glfwWaitEvents(); +#endif // TODO(awdavies): This will be deprecated soon. __FlutterEngineFlushPendingTasksNow(); } diff --git a/library/linux/src/internal/key_event_handler.cc b/library/common/glfw/key_event_handler.cc similarity index 94% rename from library/linux/src/internal/key_event_handler.cc rename to library/common/glfw/key_event_handler.cc index 1013a585b..0b6e4e36d 100644 --- a/library/linux/src/internal/key_event_handler.cc +++ b/library/common/glfw/key_event_handler.cc @@ -11,12 +11,12 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/src/internal/key_event_handler.h" +#include "library/common/glfw/key_event_handler.h" #include #include -#include "library/linux/src/internal/json_message_codec.h" +#include "library/common/internal/json_message_codec.h" static constexpr char kChannelName[] = "flutter/keyevent"; diff --git a/library/linux/src/internal/key_event_handler.h b/library/common/glfw/key_event_handler.h similarity index 81% rename from library/linux/src/internal/key_event_handler.h rename to library/common/glfw/key_event_handler.h index 203917239..1b1793feb 100644 --- a/library/linux/src/internal/key_event_handler.h +++ b/library/common/glfw/key_event_handler.h @@ -11,11 +11,11 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_SRC_INTERNAL_KEY_EVENT_HANDLER_H_ -#define LIBRARY_LINUX_SRC_INTERNAL_kEY_EVENT_HANDLER_H_ +#ifndef LIBRARY_COMMON_GLFW_KEY_EVENT_HANDLER_H_ +#define LIBRARY_COMMON_GLFW_kEY_EVENT_HANDLER_H_ -#include "library/linux/include/flutter_desktop_embedding/binary_messenger.h" -#include "library/linux/src/internal/keyboard_hook_handler.h" +#include "library/common/glfw/keyboard_hook_handler.h" +#include "library/include/flutter_desktop_embedding/binary_messenger.h" namespace flutter_desktop_embedding { @@ -41,4 +41,4 @@ class KeyEventHandler : public KeyboardHookHandler { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_SRC_INTERNAL_KEY_EVENT_HANDLER_H_ +#endif // LIBRARY_COMMON_GLFW_KEY_EVENT_HANDLER_H_ diff --git a/library/linux/src/internal/keyboard_hook_handler.h b/library/common/glfw/keyboard_hook_handler.h similarity index 84% rename from library/linux/src/internal/keyboard_hook_handler.h rename to library/common/glfw/keyboard_hook_handler.h index 18bfe2f56..35d2ff11d 100644 --- a/library/linux/src/internal/keyboard_hook_handler.h +++ b/library/common/glfw/keyboard_hook_handler.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_SRC_INTERNAL_INPUT_KEYBOARD_HOOK_HANDLER_H_ -#define LIBRARY_LINUX_SRC_INTERNAL_INPUT_KEYBOARD_HOOK_HANDLER_H_ +#ifndef LIBRARY_COMMON_GLFW_KEYBOARD_HOOK_HANDLER_H_ +#define LIBRARY_COMMON_GLFW_KEYBOARD_HOOK_HANDLER_H_ #include @@ -31,4 +31,4 @@ class KeyboardHookHandler { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_SRC_INTERNAL_INPUT_KEYBOARD_HOOK_HANDLER_H_ +#endif // LIBRARY_COMMON_GLFW_KEYBOARD_HOOK_HANDLER_H_ diff --git a/library/linux/src/internal/text_input_plugin.cc b/library/common/glfw/text_input_plugin.cc similarity index 99% rename from library/linux/src/internal/text_input_plugin.cc rename to library/common/glfw/text_input_plugin.cc index ffef8ecbd..d9890d13f 100644 --- a/library/linux/src/internal/text_input_plugin.cc +++ b/library/common/glfw/text_input_plugin.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/src/internal/text_input_plugin.h" +#include "library/common/glfw/text_input_plugin.h" #include #include diff --git a/library/linux/src/internal/text_input_plugin.h b/library/common/glfw/text_input_plugin.h similarity index 82% rename from library/linux/src/internal/text_input_plugin.h rename to library/common/glfw/text_input_plugin.h index 9c0c5e3d8..d5016cb64 100644 --- a/library/linux/src/internal/text_input_plugin.h +++ b/library/common/glfw/text_input_plugin.h @@ -11,15 +11,15 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_PLUGIN_H_ -#define LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_PLUGIN_H_ +#ifndef LIBRARY_COMMON_GLFW_TEXT_INPUT_PLUGIN_H_ +#define LIBRARY_COMMON_GLFW_TEXT_INPUT_PLUGIN_H_ #include #include -#include "library/linux/include/flutter_desktop_embedding/json_plugin.h" -#include "library/linux/src/internal/keyboard_hook_handler.h" -#include "library/linux/src/internal/text_input_model.h" +#include "library/common/glfw/keyboard_hook_handler.h" +#include "library/common/internal/text_input_model.h" +#include "library/include/flutter_desktop_embedding/json_plugin.h" namespace flutter_desktop_embedding { @@ -58,4 +58,4 @@ class TextInputPlugin : public KeyboardHookHandler, public JsonPlugin { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_PLUGIN_H_ +#endif // LIBRARY_COMMON_GLFW_TEXT_INPUT_PLUGIN_H_ diff --git a/library/linux/src/internal/engine_method_result.cc b/library/common/internal/engine_method_result.cc similarity index 97% rename from library/linux/src/internal/engine_method_result.cc rename to library/common/internal/engine_method_result.cc index 46850f3f2..91a7d73d1 100644 --- a/library/linux/src/internal/engine_method_result.cc +++ b/library/common/internal/engine_method_result.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/src/internal/engine_method_result.h" +#include "library/common/internal/engine_method_result.h" #include diff --git a/library/linux/src/internal/engine_method_result.h b/library/common/internal/engine_method_result.h similarity index 81% rename from library/linux/src/internal/engine_method_result.h rename to library/common/internal/engine_method_result.h index 23d9427d8..e97c0dedf 100644 --- a/library/linux/src/internal/engine_method_result.h +++ b/library/common/internal/engine_method_result.h @@ -11,15 +11,15 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_SRC_INTERNAL_ENGINE_METHOD_RESULT_H_ -#define LIBRARY_LINUX_SRC_INTERNAL_ENGINE_METHOD_RESULT_H_ +#ifndef LIBRARY_COMMON_INTERNAL_ENGINE_METHOD_RESULT_H_ +#define LIBRARY_COMMON_INTERNAL_ENGINE_METHOD_RESULT_H_ #include #include -#include "library/linux/include/flutter_desktop_embedding/binary_messenger.h" -#include "library/linux/include/flutter_desktop_embedding/method_codec.h" -#include "library/linux/include/flutter_desktop_embedding/method_result.h" +#include "library/include/flutter_desktop_embedding/binary_messenger.h" +#include "library/include/flutter_desktop_embedding/method_codec.h" +#include "library/include/flutter_desktop_embedding/method_result.h" namespace flutter_desktop_embedding { @@ -54,4 +54,4 @@ class EngineMethodResult : public MethodResult { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_SRC_INTERNAL_ENGINE_METHOD_RESULT_H_ +#endif // LIBRARY_COMMON_INTERNAL_ENGINE_METHOD_RESULT_H_ diff --git a/library/linux/src/internal/json_message_codec.cc b/library/common/internal/json_message_codec.cc similarity index 97% rename from library/linux/src/internal/json_message_codec.cc rename to library/common/internal/json_message_codec.cc index ad40e807b..8cf5dfb64 100644 --- a/library/linux/src/internal/json_message_codec.cc +++ b/library/common/internal/json_message_codec.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/src/internal/json_message_codec.h" +#include "library/common/internal/json_message_codec.h" #include #include diff --git a/library/linux/src/internal/json_message_codec.h b/library/common/internal/json_message_codec.h similarity index 89% rename from library/linux/src/internal/json_message_codec.h rename to library/common/internal/json_message_codec.h index 34d47ca88..fbd53e3f9 100644 --- a/library/linux/src/internal/json_message_codec.h +++ b/library/common/internal/json_message_codec.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_MESSAGE_CODEC_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_MESSAGE_CODEC_H_ +#ifndef LIBRARY_COMMON_INTERNAL_JSON_MESSAGE_CODEC_H_ +#define LIBRARY_COMMON_INTERNAL_JSON_MESSAGE_CODEC_H_ #include #include @@ -56,4 +56,4 @@ class JsonMessageCodec { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_MESSAGE_CODEC_H_ +#endif // LIBRARY_COMMON_INTERNAL_JSON_MESSAGE_CODEC_H_ diff --git a/library/linux/src/internal/plugin_handler.cc b/library/common/internal/plugin_handler.cc similarity index 90% rename from library/linux/src/internal/plugin_handler.cc rename to library/common/internal/plugin_handler.cc index 4acb94e5f..9454d84b9 100644 --- a/library/linux/src/internal/plugin_handler.cc +++ b/library/common/internal/plugin_handler.cc @@ -11,10 +11,10 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/src/internal/plugin_handler.h" +#include "library/common/internal/plugin_handler.h" -#include "library/linux/include/flutter_desktop_embedding/method_channel.h" -#include "library/linux/src/internal/engine_method_result.h" +#include "library/common/internal/engine_method_result.h" +#include "library/include/flutter_desktop_embedding/method_channel.h" #include @@ -81,10 +81,10 @@ void PluginHandler::HandleMethodCallMessage( void PluginHandler::Send(const std::string &channel, const uint8_t *message, const size_t message_size) const { FlutterPlatformMessage platform_message = { - .struct_size = sizeof(FlutterPlatformMessage), - .channel = channel.c_str(), - .message = message, - .message_size = message_size, + sizeof(FlutterPlatformMessage), + channel.c_str(), + message, + message_size, }; FlutterEngineSendPlatformMessage(engine_, &platform_message); } diff --git a/library/linux/src/internal/plugin_handler.h b/library/common/internal/plugin_handler.h similarity index 89% rename from library/linux/src/internal/plugin_handler.h rename to library/common/internal/plugin_handler.h index 46c1e06c1..65dfc1bbd 100644 --- a/library/linux/src/internal/plugin_handler.h +++ b/library/common/internal/plugin_handler.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_SRC_INTERNAL_PLUGIN_HANDLER_H_ -#define LIBRARY_LINUX_SRC_INTERNAL_PLUGIN_HANDLER_H_ +#ifndef LIBRARY_COMMON_INTERNAL_PLUGIN_HANDLER_H_ +#define LIBRARY_COMMON_INTERNAL_PLUGIN_HANDLER_H_ #include #include @@ -20,8 +20,8 @@ #include -#include "library/linux/include/flutter_desktop_embedding/binary_messenger.h" -#include "library/linux/include/flutter_desktop_embedding/plugin.h" +#include "library/include/flutter_desktop_embedding/binary_messenger.h" +#include "library/include/flutter_desktop_embedding/plugin.h" namespace flutter_desktop_embedding { @@ -74,4 +74,4 @@ class PluginHandler : public BinaryMessenger { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_SRC_INTERNAL_PLUGIN_HANDLER_H_ +#endif // LIBRARY_COMMON_INTERNAL_PLUGIN_HANDLER_H_ diff --git a/library/linux/src/internal/text_input_model.cc b/library/common/internal/text_input_model.cc similarity index 98% rename from library/linux/src/internal/text_input_model.cc rename to library/common/internal/text_input_model.cc index 127b370b5..579f5cf1c 100644 --- a/library/linux/src/internal/text_input_model.cc +++ b/library/common/internal/text_input_model.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/src/internal/text_input_model.h" +#include "library/common/internal/text_input_model.h" #include diff --git a/library/linux/src/internal/text_input_model.h b/library/common/internal/text_input_model.h similarity index 94% rename from library/linux/src/internal/text_input_model.h rename to library/common/internal/text_input_model.h index 19be7caf3..95058f319 100644 --- a/library/linux/src/internal/text_input_model.h +++ b/library/common/internal/text_input_model.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_MODEL_H_ -#define LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_MODEL_H_ +#ifndef LIBRARY_COMMON_INTERNAL_TEXT_INPUT_MODEL_H_ +#define LIBRARY_COMMON_INTERNAL_TEXT_INPUT_MODEL_H_ #include @@ -95,4 +95,4 @@ class TextInputModel { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_MODEL_H_ +#endif // LIBRARY_COMMON_INTERNAL_TEXT_INPUT_MODEL_H_ diff --git a/library/linux/src/json_method_call.cc b/library/common/json_method_call.cc similarity index 93% rename from library/linux/src/json_method_call.cc rename to library/common/json_method_call.cc index 3acdfaf9e..db2d847ff 100644 --- a/library/linux/src/json_method_call.cc +++ b/library/common/json_method_call.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/include/flutter_desktop_embedding/json_method_call.h" +#include "library/include/flutter_desktop_embedding/json_method_call.h" namespace flutter_desktop_embedding { diff --git a/library/linux/src/json_method_codec.cc b/library/common/json_method_codec.cc similarity index 93% rename from library/linux/src/json_method_codec.cc rename to library/common/json_method_codec.cc index 29107110f..69c3d4f16 100644 --- a/library/linux/src/json_method_codec.cc +++ b/library/common/json_method_codec.cc @@ -11,10 +11,10 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/include/flutter_desktop_embedding/json_method_codec.h" +#include "library/include/flutter_desktop_embedding/json_method_codec.h" -#include "library/linux/include/flutter_desktop_embedding/json_method_call.h" -#include "library/linux/src/internal/json_message_codec.h" +#include "library/common/internal/json_message_codec.h" +#include "library/include/flutter_desktop_embedding/json_method_call.h" namespace flutter_desktop_embedding { diff --git a/library/linux/src/json_plugin.cc b/library/common/json_plugin.cc similarity index 92% rename from library/linux/src/json_plugin.cc rename to library/common/json_plugin.cc index 2cb7b56d9..5f4b12ef9 100644 --- a/library/linux/src/json_plugin.cc +++ b/library/common/json_plugin.cc @@ -11,9 +11,9 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/include/flutter_desktop_embedding/json_plugin.h" +#include "library/include/flutter_desktop_embedding/json_plugin.h" -#include "library/linux/include/flutter_desktop_embedding/json_method_codec.h" +#include "library/include/flutter_desktop_embedding/json_method_codec.h" namespace flutter_desktop_embedding { diff --git a/library/linux/src/method_call.cc b/library/common/method_call.cc similarity index 91% rename from library/linux/src/method_call.cc rename to library/common/method_call.cc index adbcbc972..4dcd4c1cb 100644 --- a/library/linux/src/method_call.cc +++ b/library/common/method_call.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/include/flutter_desktop_embedding/method_call.h" +#include "library/include/flutter_desktop_embedding/method_call.h" namespace flutter_desktop_embedding { diff --git a/library/linux/src/method_channel.cc b/library/common/method_channel.cc similarity index 94% rename from library/linux/src/method_channel.cc rename to library/common/method_channel.cc index b4201310f..8ba9b406b 100644 --- a/library/linux/src/method_channel.cc +++ b/library/common/method_channel.cc @@ -11,11 +11,11 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/include/flutter_desktop_embedding/method_channel.h" +#include "library/include/flutter_desktop_embedding/method_channel.h" #include -#include "library/linux/src/internal/engine_method_result.h" +#include "library/common/internal/engine_method_result.h" namespace flutter_desktop_embedding { diff --git a/library/linux/src/method_codec.cc b/library/common/method_codec.cc similarity index 95% rename from library/linux/src/method_codec.cc rename to library/common/method_codec.cc index 03fb44bb2..9899041d5 100644 --- a/library/linux/src/method_codec.cc +++ b/library/common/method_codec.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/include/flutter_desktop_embedding/method_codec.h" +#include "library/include/flutter_desktop_embedding/method_codec.h" namespace flutter_desktop_embedding { diff --git a/library/linux/src/method_result.cc b/library/common/method_result.cc similarity index 93% rename from library/linux/src/method_result.cc rename to library/common/method_result.cc index 58ed27fce..c81c28fbd 100644 --- a/library/linux/src/method_result.cc +++ b/library/common/method_result.cc @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/include/flutter_desktop_embedding/method_result.h" +#include "library/include/flutter_desktop_embedding/method_result.h" namespace flutter_desktop_embedding { diff --git a/library/linux/src/plugin.cc b/library/common/plugin.cc similarity index 89% rename from library/linux/src/plugin.cc rename to library/common/plugin.cc index aaf63642e..d6587f08f 100644 --- a/library/linux/src/plugin.cc +++ b/library/common/plugin.cc @@ -11,9 +11,9 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include "library/linux/include/flutter_desktop_embedding/plugin.h" +#include "library/include/flutter_desktop_embedding/plugin.h" -#include "library/linux/include/flutter_desktop_embedding/json_method_codec.h" +#include "library/include/flutter_desktop_embedding/json_method_codec.h" namespace flutter_desktop_embedding { diff --git a/library/linux/include/flutter_desktop_embedding/binary_messenger.h b/library/include/flutter_desktop_embedding/binary_messenger.h similarity index 90% rename from library/linux/include/flutter_desktop_embedding/binary_messenger.h rename to library/include/flutter_desktop_embedding/binary_messenger.h index d08bd6a3b..4e6f73b13 100644 --- a/library/linux/include/flutter_desktop_embedding/binary_messenger.h +++ b/library/include/flutter_desktop_embedding/binary_messenger.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_BINARY_MESSENGER_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_BINARY_MESSENGER_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_BINARY_MESSENGER_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_BINARY_MESSENGER_H_ #include #include @@ -59,4 +59,4 @@ class BinaryMessenger { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_BINARY_MESSENGER_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_BINARY_MESSENGER_H_ diff --git a/library/windows/embedder.h b/library/include/flutter_desktop_embedding/glfw/embedder.h similarity index 78% rename from library/windows/embedder.h rename to library/include/flutter_desktop_embedding/glfw/embedder.h index 5d52c1c18..669ea9d50 100644 --- a/library/windows/embedder.h +++ b/library/include/flutter_desktop_embedding/glfw/embedder.h @@ -12,13 +12,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef WINDOWS_LIBRARY_EMBEDDER_H_ -#define WINDOWS_LIBRARY_EMBEDDER_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_GLFW_EMBEDDER_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_GLFW_EMBEDDER_H_ +#include #include #include -#include +#ifdef __linux__ +// Epoxy must be included before any graphics-related code. +#include +#endif + +#include + +#ifdef USE_FLATTENED_INCLUDES +#include "plugin.h" +#else +#include "../plugin.h" +#endif + +namespace flutter_desktop_embedding { // Calls glfwInit() // @@ -65,6 +79,12 @@ GLFWwindow *CreateFlutterWindowInSnapshotMode( const std::string &icu_data_path, const std::vector &arguments); +// Adds a plugin to the flutter_window. +// +// If a plugin already exists for this plugin's channel, returns false. +// Otherwise returns true. +bool AddPlugin(GLFWwindow *flutter_window, std::unique_ptr plugin); + // Loops on flutter window events until termination. // // Must be used instead of glfwWindowShouldClose as it cleans up engine state @@ -74,4 +94,6 @@ GLFWwindow *CreateFlutterWindowInSnapshotMode( // cleanup. void FlutterWindowLoop(GLFWwindow *flutter_window); -#endif // WINDOWS_LIBRARY_EMBEDDER_H_ +} // namespace flutter_desktop_embedding + +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_GLFW_EMBEDDER_H_ diff --git a/library/linux/include/flutter_desktop_embedding/json_method_call.h b/library/include/flutter_desktop_embedding/json_method_call.h similarity index 88% rename from library/linux/include/flutter_desktop_embedding/json_method_call.h rename to library/include/flutter_desktop_embedding/json_method_call.h index 7cb5b3ccd..bfc552468 100644 --- a/library/linux/include/flutter_desktop_embedding/json_method_call.h +++ b/library/include/flutter_desktop_embedding/json_method_call.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CALL_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CALL_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CALL_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CALL_H_ #include @@ -50,4 +50,4 @@ class JsonMethodCall : public MethodCall { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CALL_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CALL_H_ diff --git a/library/linux/include/flutter_desktop_embedding/json_method_codec.h b/library/include/flutter_desktop_embedding/json_method_codec.h similarity index 88% rename from library/linux/include/flutter_desktop_embedding/json_method_codec.h rename to library/include/flutter_desktop_embedding/json_method_codec.h index 38ac8fcc6..a34da1b65 100644 --- a/library/linux/include/flutter_desktop_embedding/json_method_codec.h +++ b/library/include/flutter_desktop_embedding/json_method_codec.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CODEC_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CODEC_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CODEC_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CODEC_H_ #include "method_codec.h" @@ -51,4 +51,4 @@ class JsonMethodCodec : public MethodCodec { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CODEC_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_METHOD_CODEC_H_ diff --git a/library/linux/include/flutter_desktop_embedding/json_plugin.h b/library/include/flutter_desktop_embedding/json_plugin.h similarity index 91% rename from library/linux/include/flutter_desktop_embedding/json_plugin.h rename to library/include/flutter_desktop_embedding/json_plugin.h index 0eaefde2e..59d4a85b4 100644 --- a/library/linux/include/flutter_desktop_embedding/json_plugin.h +++ b/library/include/flutter_desktop_embedding/json_plugin.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_PLUGIN_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_PLUGIN_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_PLUGIN_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_PLUGIN_H_ #include #include @@ -64,4 +64,4 @@ class JsonPlugin : public Plugin { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_PLUGIN_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_PLUGIN_H_ diff --git a/library/linux/include/flutter_desktop_embedding/method_call.h b/library/include/flutter_desktop_embedding/method_call.h similarity index 87% rename from library/linux/include/flutter_desktop_embedding/method_call.h rename to library/include/flutter_desktop_embedding/method_call.h index 6616165a6..1e801718b 100644 --- a/library/linux/include/flutter_desktop_embedding/method_call.h +++ b/library/include/flutter_desktop_embedding/method_call.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CALL_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CALL_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CALL_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CALL_H_ #include @@ -43,4 +43,4 @@ class MethodCall { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CALL_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CALL_H_ diff --git a/library/linux/include/flutter_desktop_embedding/method_channel.h b/library/include/flutter_desktop_embedding/method_channel.h similarity index 91% rename from library/linux/include/flutter_desktop_embedding/method_channel.h rename to library/include/flutter_desktop_embedding/method_channel.h index 6f4f0f604..22b5cf4cd 100644 --- a/library/linux/include/flutter_desktop_embedding/method_channel.h +++ b/library/include/flutter_desktop_embedding/method_channel.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CHANNEL_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CHANNEL_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CHANNEL_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CHANNEL_H_ #include @@ -69,4 +69,4 @@ class MethodChannel { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CHANNEL_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CHANNEL_H_ diff --git a/library/linux/include/flutter_desktop_embedding/method_codec.h b/library/include/flutter_desktop_embedding/method_codec.h similarity index 92% rename from library/linux/include/flutter_desktop_embedding/method_codec.h rename to library/include/flutter_desktop_embedding/method_codec.h index d563c20b4..fc34f4d82 100644 --- a/library/linux/include/flutter_desktop_embedding/method_codec.h +++ b/library/include/flutter_desktop_embedding/method_codec.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CODEC_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CODEC_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CODEC_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CODEC_H_ #include #include @@ -65,4 +65,4 @@ class MethodCodec { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CODEC_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_CODEC_H_ diff --git a/library/linux/include/flutter_desktop_embedding/method_result.h b/library/include/flutter_desktop_embedding/method_result.h similarity index 91% rename from library/linux/include/flutter_desktop_embedding/method_result.h rename to library/include/flutter_desktop_embedding/method_result.h index f1c072d7a..205ca1f51 100644 --- a/library/linux/include/flutter_desktop_embedding/method_result.h +++ b/library/include/flutter_desktop_embedding/method_result.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_RESULT_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_RESULT_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_RESULT_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_RESULT_H_ #include @@ -59,4 +59,4 @@ class MethodResult { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_RESULT_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_METHOD_RESULT_H_ diff --git a/library/linux/include/flutter_desktop_embedding/plugin.h b/library/include/flutter_desktop_embedding/plugin.h similarity index 94% rename from library/linux/include/flutter_desktop_embedding/plugin.h rename to library/include/flutter_desktop_embedding/plugin.h index 02affff86..c69483739 100644 --- a/library/linux/include/flutter_desktop_embedding/plugin.h +++ b/library/include/flutter_desktop_embedding/plugin.h @@ -11,8 +11,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_PLUGIN_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_PLUGIN_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_PLUGIN_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_PLUGIN_H_ #include #include @@ -84,4 +84,4 @@ class Plugin { } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_PLUGIN_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_PLUGIN_H_ diff --git a/library/linux/.gitignore b/library/linux/.gitignore index 61d1051b1..55d8c0ddd 100644 --- a/library/linux/.gitignore +++ b/library/linux/.gitignore @@ -1,3 +1,3 @@ .last_engine_version *.so -flutter_embedder.h +include diff --git a/library/linux/BUILD.gn b/library/linux/BUILD.gn index c9e903509..6b049638c 100644 --- a/library/linux/BUILD.gn +++ b/library/linux/BUILD.gn @@ -19,7 +19,7 @@ import("//library/engine.gni") # inculdes for its header rather than project-relative. config("relative_public_headers") { include_dirs = [ - "include", + "../include" ] } diff --git a/library/linux/Makefile b/library/linux/Makefile index e2f2b4b07..6a5810892 100644 --- a/library/linux/Makefile +++ b/library/linux/Makefile @@ -14,6 +14,8 @@ FLUTTER_ENGINE_LIB_NAME=flutter_engine FLUTTER_ENGINE_LIB_FILE=lib$(FLUTTER_ENGINE_LIB_NAME).so FLUTTER_ENGINE_HEADER=flutter_embedder.h +# Use an include/ directory for the engine header for consistency. +FLUTTER_ENGINE_HEADER_DIR=$(CURDIR)/include PROJECT_ROOT=../.. TOOLS_DIR=$(PROJECT_ROOT)/tools ENGINE_UPDATER=$(TOOLS_DIR)/update_flutter_engine @@ -22,7 +24,8 @@ LIBRARY_OUT=libflutter_embedder.so CXX=g++ -std=c++14 CXXFLAGS= -Wall -Werror -shared -fPIC \ -I$(PROJECT_ROOT) \ - -I$(CURDIR)/include \ + -I$(PROJECT_ROOT)/library/include \ + -I$(FLUTTER_ENGINE_HEADER_DIR) \ $(shell pkg-config --cflags gtk+-3.0 epoxy x11 jsoncpp) LDFLAGS= -L$(CURDIR) \ $(shell pkg-config --libs gtk+-3.0 epoxy x11 jsoncpp) \ @@ -31,8 +34,9 @@ LDFLAGS= -L$(CURDIR) \ LIBRARIES=$(FLUTTER_ENGINE_LIB_FILE) -HEADERS=$(shell find include/ -type f -name '*.h') -SOURCES=$(shell find src/ -type f -name '*.cc') +HEADERS=$(shell find $(PROJECT_ROOT)/library/include/ -type f -name '*.h') \ + $(FLUTTER_ENGINE_HEADER_DIR)/$(FLUTTER_ENGINE_HEADER) +SOURCES=$(shell find $(PROJECT_ROOT)/library/common/ -type f -name '*.cc') .PHONY: all all: $(LIBRARY_OUT) @@ -45,10 +49,12 @@ $(LIBRARY_OUT): $(SOURCES) $(HEADERS) $(LIBRARIES) # time. Instead, this duplicates the dependency information that the script # already has, and makes things slightly more fragile, in exchange for # avoiding unnecessary relinks. -$(FLUTTER_ENGINE_LIB_FILE): $(FLUTTER_DIR)/bin/internal/engine.version +$(FLUTTER_ENGINE_LIB_FILE) $(FLUTTER_ENGINE_HEADER_DIR)/$(FLUTTER_ENGINE_HEADER): \ + $(FLUTTER_DIR)/bin/internal/engine.version $(ENGINE_UPDATER) --flutter_root=$(FLUTTER_DIR) ./ if [ -f $(FLUTTER_ENGINE_HEADER) ]; then \ - mv $(FLUTTER_ENGINE_HEADER) include/; \ + mkdir -p $(FLUTTER_ENGINE_HEADER_DIR) && \ + mv $(FLUTTER_ENGINE_HEADER) $(FLUTTER_ENGINE_HEADER_DIR)/; \ fi .PHONY: clean diff --git a/library/linux/include/flutter_desktop_embedding/embedder.h b/library/linux/include/flutter_desktop_embedding/embedder.h deleted file mode 100644 index 217b5a10f..000000000 --- a/library/linux/include/flutter_desktop_embedding/embedder.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_EMBEDDER_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_EMBEDDER_H_ - -// Epoxy must be included before any graphics-related code. -#include - -#include - -#include -#include - -#include "plugin.h" - -namespace flutter_desktop_embedding { - -// Creates a GLFW Window running a Flutter Application. -// -// glfwInit() must be called prior to this function. -// -// The arguments are to configure the paths when launching the engine. See: -// https://github.com/flutter/engine/wiki/Custom-Flutter-Engine-Embedders for -// more details on Flutter Engine embedding. -// -// Returns a null pointer in the event of an error. The caller owns the pointer -// when it is non-null. -GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height, - const std::string &main_path, - const std::string &assets_path, - const std::string &packages_path, - const std::string &icu_data_path, - const std::vector &arguments); - -// Creates a GLFW Window running a Flutter Application in snapshot mode. -// -// glfwInit() must be called prior to this function. -// -// In snapshot mode the assets directory snapshot is used to run the application -// instead of the sources. -// -// The arguments are to configure the paths when launching the engine. See: -// https://github.com/flutter/engine/wiki/Custom-Flutter-Engine-Embedders for -// more details on Flutter Engine embedding. -// -// Returns a null pointer in the event of an error. The caller owns the pointer -// when it is non-null. -GLFWwindow *CreateFlutterWindowInSnapshotMode( - size_t initial_width, size_t initial_height, const std::string &assets_path, - const std::string &icu_data_path, - const std::vector &arguments); - -// Adds a plugin to the flutter_window. -// -// If a plugin already exists for this plugin's channel, returns false. -// Otherwise returns true. -bool AddPlugin(GLFWwindow *flutter_window, std::unique_ptr plugin); - -// Loops on flutter window events until termination. -// -// Must be used instead of glfwWindowShouldClose as it cleans up engine state -// after termination. -// -// After this function the user must eventually call glfwTerminate() if doing -// cleanup. -void FlutterWindowLoop(GLFWwindow *flutter_window); - -} // namespace flutter_desktop_embedding - -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_EMBEDDER_H_ diff --git a/library/windows/.gitignore b/library/windows/.gitignore index f431ddc7c..099c5cb6a 100644 --- a/library/windows/.gitignore +++ b/library/windows/.gitignore @@ -1,3 +1,6 @@ +# Ignore third party code fetched as part of build process of the Flutter embedding library +third_party + ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## @@ -327,3 +330,4 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ + diff --git a/library/windows/GLFW Library.vcxproj b/library/windows/GLFW Library.vcxproj index 2df1af2eb..f1628bc2d 100644 --- a/library/windows/GLFW Library.vcxproj +++ b/library/windows/GLFW Library.vcxproj @@ -75,8 +75,9 @@ $(SolutionDir)bin\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\ flutter_embedder .dll - $(ProjectDir)dependencies\engine\;$(ProjectDir)dependencies\GLFW\;$(IncludePath) - $(ProjectDir)dependencies\engine\;$(ProjectDir)dependencies\GLFW\;$(LibraryPath) + $(ProjectDir)dependencies\engine\;$(ProjectDir)dependencies;$(ProjectDir)third_party\jsoncpp\include;$(ProjectDir)..\..\;$(IncludePath) + $(ProjectDir)dependencies\engine\;$(ProjectDir)dependencies\json\x64\debug;$(ProjectDir)dependencies\GLFW\;$(LibraryPath) + $(ProjectDir)..\..\library\common\internal;$(SourcePath) $(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\ @@ -91,8 +92,9 @@ $(SolutionDir)bin\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\ flutter_embedder .dll - $(ProjectDir)dependencies\engine\;$(ProjectDir)dependencies\GLFW\;$(IncludePath) - $(ProjectDir)dependencies\engine\;$(ProjectDir)dependencies\GLFW\;$(LibraryPath) + $(ProjectDir)dependencies\engine\;$(ProjectDir)dependencies;$(ProjectDir)third_party\jsoncpp\include;$(ProjectDir)..\..\;$(IncludePath) + $(ProjectDir)dependencies\engine\;$(ProjectDir)dependencies\json\x64\release;;$(ProjectDir)dependencies\GLFW\;$(LibraryPath) + $(ProjectDir)..\..\library\common\internal;$(SourcePath) $(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\ @@ -108,9 +110,10 @@ Disabled true true + MultiThreadedDebugDLL - flutter_engine.dll.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies) + flutter_engine.dll.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies);json_vc71_libmtd.lib exports.def @@ -123,7 +126,7 @@ - $(ProjectDir)scripts\update_flutter_engine && $(ProjectDir)scripts\get_engine_artifacts && $(ProjectDir)scripts\get_GLFW + $(ProjectDir)scripts\update_flutter_engine && $(ProjectDir)scripts\get_engine_artifacts && $(ProjectDir)scripts\get_GLFW && $(ProjectDir)scripts\build_jsonlib Get the flutter engine, engine artifacts and GLFW @@ -186,11 +189,12 @@ true true true + MultiThreadedDLL true true - flutter_engine.dll.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies) + flutter_engine.dll.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies);json_vc71_libmt.lib exports.def $(OutDir)$(TargetName)$(TargetExt) $(OutDir)$(TargetName).lib @@ -201,7 +205,7 @@ - $(ProjectDir)scripts\update_flutter_engine && $(ProjectDir)scripts\get_engine_artifacts && $(ProjectDir)scripts\get_GLFW + $(ProjectDir)scripts\update_flutter_engine && $(ProjectDir)scripts\get_engine_artifacts && $(ProjectDir)scripts\get_GLFW && $(ProjectDir)scripts\build_jsonlib Get the flutter engine, engine artifacts and GLFW @@ -259,7 +263,21 @@ - + + + + + + + + + + + + + + + diff --git a/library/windows/GLFW Library.vcxproj.filters b/library/windows/GLFW Library.vcxproj.filters index 58963352d..03dd85a33 100644 --- a/library/windows/GLFW Library.vcxproj.filters +++ b/library/windows/GLFW Library.vcxproj.filters @@ -1,32 +1,74 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - - - Header Files - - - - - Source Files - - - \ No newline at end of file + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + + + Source Files + + + diff --git a/library/windows/dependencies/.gitignore b/library/windows/dependencies/.gitignore index 443ccd53a..7f1435b47 100644 --- a/library/windows/dependencies/.gitignore +++ b/library/windows/dependencies/.gitignore @@ -3,3 +3,4 @@ flutter_engine.* .last_engine_version icudtl.dat glfw3.* +json diff --git a/library/windows/dependencies/json/.gitkeep b/library/windows/dependencies/json/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/library/windows/embedder.cpp b/library/windows/embedder.cpp deleted file mode 100644 index a601c9c73..000000000 --- a/library/windows/embedder.cpp +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "embedder.h" - -#include -#include -#include -#include - -#include - -static_assert(FLUTTER_ENGINE_VERSION == 1, ""); - -static constexpr char kDefaultWindowTitle[] = "Flutter"; - -bool FlutterInit() { return glfwInit(); } - -void FlutterTerminate() { glfwTerminate(); } - -static void GLFWcursorPositionCallbackAtPhase(GLFWwindow *window, - FlutterPointerPhase phase, - double x, double y) { - FlutterPointerEvent event = {}; - event.struct_size = sizeof(event); - event.phase = phase; - event.x = x; - event.y = y; - event.timestamp = - std::chrono::duration_cast( - std::chrono::high_resolution_clock::now().time_since_epoch()) - .count(); - FlutterEngineSendPointerEvent( - reinterpret_cast(glfwGetWindowUserPointer(window)), &event, - 1); -} - -static void GLFWcursorPositionCallback(GLFWwindow *window, double x, double y) { - GLFWcursorPositionCallbackAtPhase(window, FlutterPointerPhase::kMove, x, y); -} - -static void GLFWmouseButtonCallback(GLFWwindow *window, int key, int action, - int mods) { - double x, y; - if (key == GLFW_MOUSE_BUTTON_1 && action == GLFW_PRESS) { - glfwGetCursorPos(window, &x, &y); - GLFWcursorPositionCallbackAtPhase(window, FlutterPointerPhase::kDown, x, y); - glfwSetCursorPosCallback(window, GLFWcursorPositionCallback); - } - if (key == GLFW_MOUSE_BUTTON_1 && action == GLFW_RELEASE) { - glfwGetCursorPos(window, &x, &y); - GLFWcursorPositionCallbackAtPhase(window, FlutterPointerPhase::kUp, x, y); - glfwSetCursorPosCallback(window, nullptr); - } -} - -static void GLFWKeyCallback(GLFWwindow *window, int key, int scancode, - int action, int mods) { - if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { - glfwSetWindowShouldClose(window, GLFW_TRUE); - } -} - -static void GLFWwindowSizeCallback(GLFWwindow *window, int width, int height) { - FlutterWindowMetricsEvent event = {}; - event.struct_size = sizeof(event); - event.width = width; - event.height = height; - // TODO: Handle pixel ratio for different DPI monitors. - event.pixel_ratio = 1.0; - FlutterEngineSendWindowMetricsEvent( - reinterpret_cast(glfwGetWindowUserPointer(window)), - &event); -} - -static bool GLFWMakeContextCurrent(void *user_data) { - GLFWwindow *window = reinterpret_cast(user_data); - glfwMakeContextCurrent(window); - return true; -} - -static bool GLFWClearContext(void *user_data) { - glfwMakeContextCurrent(nullptr); - return true; -} - -static bool GLFWPresent(void *user_data) { - GLFWwindow *window = reinterpret_cast(user_data); - glfwSwapBuffers(window); - return true; -} - -static uint32_t GLFWGetActiveFbo(void *user_data) { return 0; } - -// Clears the GLFW window to Material Blue-Grey. -// -// This function is primarily to fix an issue when the Flutter Engine is -// spinning up, wherein artifacts of existing windows are rendered onto the -// canvas for a few moments. -// -// This function isn't necessary, but makes starting the window much easier on -// the eyes. -static void GLFWClearCanvas(GLFWwindow *window) { - glfwMakeContextCurrent(window); - // This color is Material Blue Grey. - glClearColor(236, 239, 241, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glFlush(); - glfwSwapBuffers(window); - glfwMakeContextCurrent(nullptr); -} - -// Spins up an instance of the Flutter Engine. -// -// This function launches the Flutter Engine in a background thread, supplying -// the necessary callbacks for rendering within a GLFWwindow. -// -// Returns a caller-owned pointer to the engine. -static FlutterEngine RunFlutterEngine( - GLFWwindow *window, const std::string &main_path, - const std::string &assets_path, const std::string &packages_path, - const std::string &icu_data_path, - const std::vector &arguments) { - std::vector argv; - std::transform( - arguments.begin(), arguments.end(), std::back_inserter(argv), - [](const std::string &arg) -> const char * { return arg.c_str(); }); - - FlutterRendererConfig config = {}; - config.type = kOpenGL; - config.open_gl.struct_size = sizeof(config.open_gl); - config.open_gl.make_current = GLFWMakeContextCurrent; - config.open_gl.clear_current = GLFWClearContext; - config.open_gl.present = GLFWPresent; - config.open_gl.fbo_callback = GLFWGetActiveFbo; - FlutterProjectArgs args = {}; - args.struct_size = sizeof(FlutterProjectArgs); - args.assets_path = assets_path.c_str(); - args.main_path = main_path.c_str(); - args.packages_path = packages_path.c_str(); - args.icu_data_path = icu_data_path.c_str(); - args.command_line_argc = argv.size(); - args.command_line_argv = &argv[0]; - FlutterEngine engine = nullptr; - auto result = - FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, window, &engine); - if (result != kSuccess || engine == nullptr) { - return nullptr; - } - return engine; -} - -GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height, - const std::string &main_path, - const std::string &assets_path, - const std::string &packages_path, - const std::string &icu_data_path, - const std::vector &arguments) { - auto window = glfwCreateWindow(initial_width, initial_height, - kDefaultWindowTitle, NULL, NULL); - if (window == nullptr) { - return nullptr; - } - GLFWClearCanvas(window); - auto flutter_engine_run_result = RunFlutterEngine( - window, main_path, assets_path, packages_path, icu_data_path, arguments); - if (flutter_engine_run_result == nullptr) { - glfwDestroyWindow(window); - return nullptr; - } - glfwSetWindowUserPointer(window, flutter_engine_run_result); - int width, height; - glfwGetWindowSize(window, &width, &height); - GLFWwindowSizeCallback(window, width, height); - glfwSetKeyCallback(window, GLFWKeyCallback); - glfwSetWindowSizeCallback(window, GLFWwindowSizeCallback); - glfwSetMouseButtonCallback(window, GLFWmouseButtonCallback); - return window; -} - -GLFWwindow *CreateFlutterWindowInSnapshotMode( - size_t initial_width, size_t initial_height, const std::string &assets_path, - const std::string &icu_data_path, - const std::vector &arguments) { - return CreateFlutterWindow(initial_width, initial_height, "", assets_path, "", - icu_data_path, arguments); -} - -void FlutterWindowLoop(GLFWwindow *flutter_window) { - while (!glfwWindowShouldClose(flutter_window)) { - glfwWaitEvents(); - } - FlutterEngineShutdown(reinterpret_cast( - glfwGetWindowUserPointer(flutter_window))); - glfwDestroyWindow(flutter_window); -} diff --git a/library/windows/scripts/build_jsonlib.bat b/library/windows/scripts/build_jsonlib.bat new file mode 100644 index 000000000..17f663456 --- /dev/null +++ b/library/windows/scripts/build_jsonlib.bat @@ -0,0 +1,105 @@ +:: Copyright 2018 Google LLC +:: +:: Licensed under the Apache License, Version 2.0 (the "License"); +:: you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, +:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +:: See the License for the specific language governing permissions and +:: limitations under the License. +@echo off + +:: Find where VS lives and start a VC command prompt +set pre=Microsoft.VisualStudio.Product. +set ids=%pre%Community %pre%Professional %pre%Enterprise %pre%BuildTools + +pushd "C:\Program Files (x86)\Microsoft Visual Studio\Installer\" +for /f "usebackq tokens=1* delims=: " %%i in (`vswhere -latest -products *`) do (if /i "%%i"=="installationPath" set InstallDir=%%j) +popd + +pushd %InstallDir%\VC\Auxiliary\Build +call vcvarsall.bat x86_amd64 +popd + +set JSONDEBUGLIBEXISTS=true +if not exist %~dp0..\dependencies\json\x64\debug\json_vc71_libmtd.lib set JSONDEBUGLIBEXISTS=false + +set JSONRELEASELIBEXISTS=true +if not exist %~dp0..\dependencies\json\x64\release\json_vc71_libmt.lib set JSONRELEASELIBEXISTS=false + +if %JSONDEBUGLIBEXISTS% == true ( + if %JSONRELEASELIBEXISTS% == true ( + echo jsoncpp found. + goto DONE + ) +) + +set THIRDPARTYDIREXISTS=true +if not exist %~dp0..\third_party set THIRDPARTYDIREXISTS=false + +if %THIRDPARTYDIREXISTS% == false ( + mkdir %~dp0..\third_party +) + +set JSONDIREXISTS=true +if not exist %~dp0..\third_party\jsoncpp set JSONDIREXISTS=false + +if %JSONDIREXISTS% == false ( + mkdir %~dp0..\third_party\jsoncpp +) + +set JSONEXISTS=true +if not exist %~dp0..\third_party\jsoncpp\README.md set JSONEXISTS=false + +:: Clone source +if %JSONEXISTS% == false ( + :: PR opened on json cpp for VS2017 support: https://github.com/open-source-parsers/jsoncpp/pull/853 + echo Cloning via git clone --branch supportvs2017 https://github.com/clarkezone/jsoncpp.git %~dp0..\third_party\jsoncpp + call git clone --branch supportvs2017 https://github.com/clarkezone/jsoncpp.git %~dp0..\third_party\jsoncpp + + pushd %~dp0..\third_party\jsoncpp + + call git checkout 3ae7e8073a425c93329c8577a3c813c206322ca4 + + popd +) + +:: Build debug lib +echo Building debug lib: msbuild %~dp0..\third_party\jsoncpp\makefiles\msvc2017\lib_json.vcxproj +msbuild %~dp0..\third_party\jsoncpp\makefiles\msvc2017\lib_json.vcxproj + +set DEPBINDIREXISTS=true +if not exist %~dp0..\dependencies\json\x64 set DEPBINDIREXISTS=false + +if %DEPBINDIREXISTS% == false ( + mkdir %~dp0..\dependencies\json\x64 +) + +set DEPBINDBGDIREXISTS=true +if not exist %~dp0..\dependencies\json\x64\debug set DEPBINDBGDIREXISTS=false + +if %DEPBINDBGDIREXISTS% == false ( + mkdir %~dp0..\dependencies\json\x64\debug +) + +copy %~dp0..\third_party\jsoncpp\makefiles\msvc2017\x64\debug\json_vc71_libmtd.lib %~dp0..\dependencies\json\x64\debug\. + +:: Build release lib +echo Building release lib: msbuild %~dp0..\third_party\jsoncpp\makefiles\msvc2017\lib_json.vcxproj /p:Configuration=Release +msbuild %~dp0..\third_party\jsoncpp\makefiles\msvc2017\lib_json.vcxproj /p:Configuration=Release + +set DEPBINRELDIREXISTS=true +if not exist %~dp0..\dependencies\json\x64\release set DEPBINRELDIREXISTS=false + +if %DEPBINRELDIREXISTS% == false ( + mkdir %~dp0..\dependencies\json\x64\release +) + +copy %~dp0..\third_party\jsoncpp\makefiles\msvc2017\x64\release\json_vc71_libmt.lib %~dp0..\dependencies\json\x64\release\. + +:DONE +echo jsoncpplib complete. \ No newline at end of file diff --git a/plugins/color_panel/BUILD.gn b/plugins/color_panel/BUILD.gn index 60ce61462..0b6bf3c8e 100644 --- a/plugins/color_panel/BUILD.gn +++ b/plugins/color_panel/BUILD.gn @@ -30,6 +30,8 @@ published_shared_library("color_panel") { ] } + defines = ["USE_FLATTENED_INCLUDES"] + deps = [ "//library:flutter_embedder", ] diff --git a/plugins/color_panel/linux/Makefile b/plugins/color_panel/linux/Makefile index b753a32df..4f8e167a8 100644 --- a/plugins/color_panel/linux/Makefile +++ b/plugins/color_panel/linux/Makefile @@ -15,21 +15,23 @@ LIBRARY_OUT=libflutter_embedder_color_panel.so PROJECT_ROOT=$(CURDIR)/../../.. # For dependency on the embedder shared library. -EMBEDDER_LIBRARY_DIR=$(PROJECT_ROOT)/library/linux +EMBEDDER_LIBRARY_DIR=$(PROJECT_ROOT)/library +EMBEDDER_LIBRARY_OUT_DIR=$(EMBEDDER_LIBRARY_DIR)/linux +EMBEDDER_LIBRARY_HEADER_DIR=$(EMBEDDER_LIBRARY_DIR)/include EMBEDDER_LIB_NAME=flutter_engine -EMBEDDER_LIB_FILE=$(EMBEDDER_LIBRARY_DIR)/lib$(EMBEDDER_LIB_NAME).so +EMBEDDER_LIB_FILE=$(EMBEDDER_LIBRARY_OUT_DIR)/lib$(EMBEDDER_LIB_NAME).so COMMON_DIR=$(CURDIR)/../common CXX=g++ -std=c++14 CXXFLAGS= -Wall -Werror -shared -fPIC \ -I$(PROJECT_ROOT) \ - -I$(EMBEDDER_LIBRARY_DIR)/include \ + -I$(EMBEDDER_LIBRARY_HEADER_DIR) \ $(shell pkg-config --cflags gtk+-3.0 jsoncpp) -LDFLAGS= -L$(EMBEDDER_LIBRARY_DIR) \ +LDFLAGS= -L$(EMBEDDER_LIBRARY_OUT_DIR) \ $(shell pkg-config --libs gtk+-3.0 jsoncpp) \ -l$(EMBEDDER_LIB_NAME) \ - -Wl,-rpath=$(EMBEDDER_LIBRARY_DIR) + -Wl,-rpath=$(EMBEDDER_LIBRARY_OUT_DIR) LIBRARIES=$(EMBEDDER_LIB_FILE) HEADERS=$(shell find include/ $(COMMON_DIR)/ -type f -name '*.h') diff --git a/plugins/file_chooser/BUILD.gn b/plugins/file_chooser/BUILD.gn index f38e4baef..86b3e8837 100644 --- a/plugins/file_chooser/BUILD.gn +++ b/plugins/file_chooser/BUILD.gn @@ -30,6 +30,8 @@ published_shared_library("file_chooser") { ] } + defines = ["USE_FLATTENED_INCLUDES"] + deps = [ "//library:flutter_embedder", ] diff --git a/plugins/file_chooser/linux/Makefile b/plugins/file_chooser/linux/Makefile index 419f5de08..bb2bf3f87 100644 --- a/plugins/file_chooser/linux/Makefile +++ b/plugins/file_chooser/linux/Makefile @@ -15,21 +15,23 @@ LIBRARY_OUT=libflutter_embedder_file_chooser.so PROJECT_ROOT=$(CURDIR)/../../.. # For dependency on the embedder shared library. -EMBEDDER_LIBRARY_DIR=$(PROJECT_ROOT)/library/linux +EMBEDDER_LIBRARY_DIR=$(PROJECT_ROOT)/library +EMBEDDER_LIBRARY_OUT_DIR=$(EMBEDDER_LIBRARY_DIR)/linux +EMBEDDER_LIBRARY_HEADER_DIR=$(EMBEDDER_LIBRARY_DIR)/include EMBEDDER_LIB_NAME=flutter_engine -EMBEDDER_LIB_FILE=$(EMBEDDER_LIBRARY_DIR)/lib$(EMBEDDER_LIB_NAME).so +EMBEDDER_LIB_FILE=$(EMBEDDER_LIBRARY_OUT_DIR)/lib$(EMBEDDER_LIB_NAME).so COMMON_DIR=$(CURDIR)/../common CXX=g++ -std=c++14 CXXFLAGS= -Wall -Werror -shared -fPIC \ -I$(PROJECT_ROOT) \ - -I$(EMBEDDER_LIBRARY_DIR)/include \ + -I$(EMBEDDER_LIBRARY_HEADER_DIR) \ $(shell pkg-config --cflags gtk+-3.0 jsoncpp) -LDFLAGS= -L$(EMBEDDER_LIBRARY_DIR) \ +LDFLAGS= -L$(EMBEDDER_LIBRARY_OUT_DIR) \ $(shell pkg-config --libs gtk+-3.0 jsoncpp) \ -l$(EMBEDDER_LIB_NAME) \ - -Wl,-rpath=$(EMBEDDER_LIBRARY_DIR) + -Wl,-rpath=$(EMBEDDER_LIBRARY_OUT_DIR) LIBRARIES=$(EMBEDDER_LIB_FILE) HEADERS=$(shell find include/ $(COMMON_DIR)/ -type f -name '*.h') diff --git a/plugins/menubar/BUILD.gn b/plugins/menubar/BUILD.gn index c4f8aa690..ab431f8ef 100644 --- a/plugins/menubar/BUILD.gn +++ b/plugins/menubar/BUILD.gn @@ -30,6 +30,8 @@ published_shared_library("menubar") { ] } + defines = ["USE_FLATTENED_INCLUDES"] + deps = [ "//library:flutter_embedder", ] diff --git a/plugins/menubar/linux/Makefile b/plugins/menubar/linux/Makefile index e867b8131..0ee350ef1 100644 --- a/plugins/menubar/linux/Makefile +++ b/plugins/menubar/linux/Makefile @@ -15,21 +15,23 @@ LIBRARY_OUT=libflutter_embedder_menubar.so PROJECT_ROOT=$(CURDIR)/../../.. # For dependency on the embedder shared library. -EMBEDDER_LIBRARY_DIR=$(PROJECT_ROOT)/library/linux +EMBEDDER_LIBRARY_DIR=$(PROJECT_ROOT)/library +EMBEDDER_LIBRARY_OUT_DIR=$(EMBEDDER_LIBRARY_DIR)/linux +EMBEDDER_LIBRARY_HEADER_DIR=$(EMBEDDER_LIBRARY_DIR)/include EMBEDDER_LIB_NAME=flutter_engine -EMBEDDER_LIB_FILE=$(EMBEDDER_LIBRARY_DIR)/lib$(EMBEDDER_LIB_NAME).so +EMBEDDER_LIB_FILE=$(EMBEDDER_LIBRARY_OUT_DIR)/lib$(EMBEDDER_LIB_NAME).so COMMON_DIR=$(CURDIR)/../common CXX=g++ -std=c++14 CXXFLAGS= -Wall -Werror -shared -fPIC \ -I$(PROJECT_ROOT) \ - -I$(EMBEDDER_LIBRARY_DIR)/include \ + -I$(EMBEDDER_LIBRARY_HEADER_DIR) \ $(shell pkg-config --cflags gtk+-3.0 jsoncpp) -LDFLAGS= -L$(EMBEDDER_LIBRARY_DIR) \ +LDFLAGS= -L$(EMBEDDER_LIBRARY_OUT_DIR) \ $(shell pkg-config --libs gtk+-3.0 jsoncpp) \ -l$(EMBEDDER_LIB_NAME) \ - -Wl,-rpath=$(EMBEDDER_LIBRARY_DIR) + -Wl,-rpath=$(EMBEDDER_LIBRARY_OUT_DIR) LIBRARIES=$(EMBEDDER_LIB_FILE) HEADERS=$(shell find include/ $(COMMON_DIR)/ -type f -name '*.h') diff --git a/tools/build_flutter_assets b/tools/build_flutter_assets index c88e5a0d6..426faf88c 100755 --- a/tools/build_flutter_assets +++ b/tools/build_flutter_assets @@ -30,6 +30,6 @@ readonly flutter_binary="$flutter_dir/bin/flutter" #readonly build_type=host_debug_unopt #readonly extra_flags=(--local-engine-src-path $engine_src_path --local-engine=$build_type) -cd $1 +cd "$1" echo Running "$flutter_binary" ${extra_flags[*]} build bundle exec "$flutter_binary" ${extra_flags[*]} build bundle diff --git a/tools/update_flutter_engine b/tools/update_flutter_engine index c0619f122..e6e655549 100755 --- a/tools/update_flutter_engine +++ b/tools/update_flutter_engine @@ -21,4 +21,4 @@ readonly dart_bin_dir="$flutter_bin_dir/cache/dart-sdk/bin" if [[ ! -e $dart_bin_dir ]]; then "$flutter_bin_dir/flutter" precache fi -exec "$dart_bin_dir/dart" "$base_dir/dart_tools/bin/update_flutter_engine.dart" $@ +exec "$dart_bin_dir/dart" "$base_dir/dart_tools/bin/update_flutter_engine.dart" "$@"