From e23e70e4e311a4bbe3159efd2a6172f251e89326 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Thu, 20 Dec 2018 21:05:48 -0800 Subject: [PATCH 01/13] Move most C++ library code to common/ and include/ (#177) * Move most C++ library code to common/ and include/ This is a preperatory change for Windows using all of this code. Since it will be shared between multiple platforms, it should live in a shared location. Because the GN build flattens the headers in the generated out/include/, some files have #if/#else branches for #includes. Once there is a final decision on whether to use GN, this can be re-evaluated. * Update header guards for new paths --- example/linux/Makefile | 5 +- example/linux/flutter_embedder_example.cc | 7 +- library/BUILD.gn | 73 +++++++++++-------- library/GN.md | 6 +- .../glfw}/key_event_handler.cc | 4 +- .../glfw}/key_event_handler.h | 10 +-- .../glfw}/keyboard_hook_handler.h | 6 +- .../glfw}/text_input_plugin.cc | 2 +- .../glfw}/text_input_plugin.h | 12 +-- .../internal/engine_method_result.cc | 2 +- .../internal/engine_method_result.h | 12 +-- .../internal/json_message_codec.cc | 2 +- .../internal/json_message_codec.h | 6 +- .../src => common}/internal/plugin_handler.cc | 14 ++-- .../src => common}/internal/plugin_handler.h | 10 +-- .../internal/text_input_model.cc | 2 +- .../internal/text_input_model.h | 6 +- .../{linux/src => common}/json_method_call.cc | 2 +- .../src => common}/json_method_codec.cc | 6 +- library/{linux/src => common}/json_plugin.cc | 4 +- library/{linux/src => common}/method_call.cc | 2 +- .../{linux/src => common}/method_channel.cc | 4 +- library/{linux/src => common}/method_codec.cc | 2 +- .../{linux/src => common}/method_result.cc | 2 +- library/{linux/src => common}/plugin.cc | 4 +- .../binary_messenger.h | 6 +- .../json_method_call.h | 6 +- .../json_method_codec.h | 6 +- .../flutter_desktop_embedding/json_plugin.h | 6 +- .../linux}/embedder.h | 10 ++- .../flutter_desktop_embedding/method_call.h | 6 +- .../method_channel.h | 6 +- .../flutter_desktop_embedding/method_codec.h | 6 +- .../flutter_desktop_embedding/method_result.h | 6 +- .../flutter_desktop_embedding/plugin.h | 6 +- library/linux/.gitignore | 2 +- library/linux/BUILD.gn | 2 +- library/linux/Makefile | 16 ++-- library/linux/src/embedder.cc | 10 +-- plugins/color_panel/BUILD.gn | 2 + plugins/color_panel/linux/Makefile | 12 +-- plugins/file_chooser/BUILD.gn | 2 + plugins/file_chooser/linux/Makefile | 12 +-- plugins/menubar/BUILD.gn | 2 + plugins/menubar/linux/Makefile | 12 +-- 45 files changed, 193 insertions(+), 148 deletions(-) rename library/{linux/src/internal => common/glfw}/key_event_handler.cc (94%) rename library/{linux/src/internal => common/glfw}/key_event_handler.h (81%) rename library/{linux/src/internal => common/glfw}/keyboard_hook_handler.h (84%) rename library/{linux/src/internal => common/glfw}/text_input_plugin.cc (99%) rename library/{linux/src/internal => common/glfw}/text_input_plugin.h (82%) rename library/{linux/src => common}/internal/engine_method_result.cc (97%) rename library/{linux/src => common}/internal/engine_method_result.h (81%) rename library/{linux/src => common}/internal/json_message_codec.cc (97%) rename library/{linux/src => common}/internal/json_message_codec.h (89%) rename library/{linux/src => common}/internal/plugin_handler.cc (90%) rename library/{linux/src => common}/internal/plugin_handler.h (89%) rename library/{linux/src => common}/internal/text_input_model.cc (98%) rename library/{linux/src => common}/internal/text_input_model.h (94%) rename library/{linux/src => common}/json_method_call.cc (93%) rename library/{linux/src => common}/json_method_codec.cc (93%) rename library/{linux/src => common}/json_plugin.cc (92%) rename library/{linux/src => common}/method_call.cc (91%) rename library/{linux/src => common}/method_channel.cc (94%) rename library/{linux/src => common}/method_codec.cc (95%) rename library/{linux/src => common}/method_result.cc (93%) rename library/{linux/src => common}/plugin.cc (89%) rename library/{linux => }/include/flutter_desktop_embedding/binary_messenger.h (90%) rename library/{linux => }/include/flutter_desktop_embedding/json_method_call.h (88%) rename library/{linux => }/include/flutter_desktop_embedding/json_method_codec.h (88%) rename library/{linux => }/include/flutter_desktop_embedding/json_plugin.h (91%) rename library/{linux/include/flutter_desktop_embedding => include/flutter_desktop_embedding/linux}/embedder.h (92%) rename library/{linux => }/include/flutter_desktop_embedding/method_call.h (87%) rename library/{linux => }/include/flutter_desktop_embedding/method_channel.h (91%) rename library/{linux => }/include/flutter_desktop_embedding/method_codec.h (92%) rename library/{linux => }/include/flutter_desktop_embedding/method_result.h (91%) rename library/{linux => }/include/flutter_desktop_embedding/plugin.h (94%) 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..1a030828e 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 diff --git a/library/BUILD.gn b/library/BUILD.gn index 0eb36cd65..6b31ae428 100644 --- a/library/BUILD.gn +++ b/library/BUILD.gn @@ -19,40 +19,51 @@ import("//library/engine.gni") published_shared_library("flutter_embedder") { if (is_linux) { 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", ] 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", + "include/flutter_desktop_embedding/linux/embedder.h", + ] + } + 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", + ] + } + # GLFW-specific code. + if (is_linux || is_win) { + sources += [ + "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", ] } 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/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/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/embedder.h b/library/include/flutter_desktop_embedding/linux/embedder.h similarity index 92% rename from library/linux/include/flutter_desktop_embedding/embedder.h rename to library/include/flutter_desktop_embedding/linux/embedder.h index 217b5a10f..3fc973595 100644 --- a/library/linux/include/flutter_desktop_embedding/embedder.h +++ b/library/include/flutter_desktop_embedding/linux/embedder.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_EMBEDDER_H_ -#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_EMBEDDER_H_ +#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_LINUX_EMBEDDER_H_ +#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_LINUX_EMBEDDER_H_ // Epoxy must be included before any graphics-related code. #include @@ -22,7 +22,11 @@ #include #include +#ifdef USE_FLATTENED_INCLUDES #include "plugin.h" +#else +#include "../plugin.h" +#endif namespace flutter_desktop_embedding { @@ -78,4 +82,4 @@ void FlutterWindowLoop(GLFWwindow *flutter_window); } // namespace flutter_desktop_embedding -#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_EMBEDDER_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_LINUX_EMBEDDER_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..7c7f4db47 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 src/ $(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/src/embedder.cc b/library/linux/src/embedder.cc index 5ce1396e8..b793464a2 100644 --- a/library/linux/src/embedder.cc +++ b/library/linux/src/embedder.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 +#include #include #include @@ -26,10 +26,10 @@ #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" // GLFW_TRUE & GLFW_FALSE are introduced since libglfw-3.3, // add definitions here to compile under the old versions. 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') From e886e57dc7c11b8a80a6425cefff8b1a6e01365e Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Fri, 21 Dec 2018 12:20:18 -0800 Subject: [PATCH 02/13] [macos] Disable automatic signing management (#179) Disable Xcode's default of automatically managing signing for the example application, as this can cause issues for people who have a developer team configured in Xcode. Should address issue #178 --- .../macos/ExampleEmbedder.xcodeproj/project.pbxproj | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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; }; From 800c6b34cdf9f6742915d2abb0e09b11afe84d4f Mon Sep 17 00:00:00 2001 From: Pierre Champion Date: Wed, 26 Dec 2018 16:38:50 +0100 Subject: [PATCH 03/13] Fixes dead link: Engine wiki URL has been moved (#181) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f703698c..b008af414 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ 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. From 560305f3cff0ea0e6e6015c97eb6ce26251dbcf7 Mon Sep 17 00:00:00 2001 From: Rashed Mohammed <25506588+rashedmyt@users.noreply.github.com> Date: Fri, 28 Dec 2018 21:46:50 +0530 Subject: [PATCH 04/13] Fix typo in README (#185) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b008af414..001c63cbf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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. From 5c776513424bc37b1d862b3b0d6ca4563787a001 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Mon, 31 Dec 2018 18:54:12 -0800 Subject: [PATCH 05/13] [windows] Add plugin and text input support (#161) - Adds support for plugins, using the same C++ plugin code currently used by Linux. - Adds text input support, also sharing code with the Linux GLFW text input code. Fixes issue #103 and issue #104 --- README.md | 1 - example/windows/GLFW Example.vcxproj | 6 +- example/windows/flutter_embedder_example.cpp | 12 +- library/windows/.gitignore | 4 + library/windows/GLFW Library.vcxproj | 35 +++-- library/windows/GLFW Library.vcxproj.filters | 67 ++++----- library/windows/dependencies/.gitignore | 1 + library/windows/dependencies/json/.gitkeep | 0 library/windows/embedder.cpp | 139 ++++++++++++++++--- library/windows/embedder.h | 14 +- library/windows/scripts/build_jsonlib.bat | 105 ++++++++++++++ 11 files changed, 309 insertions(+), 75 deletions(-) create mode 100644 library/windows/dependencies/json/.gitkeep create mode 100644 library/windows/scripts/build_jsonlib.bat diff --git a/README.md b/README.md index 001c63cbf..2d5c0398c 100644 --- a/README.md +++ b/README.md @@ -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/example/windows/GLFW Example.vcxproj b/example/windows/GLFW Example.vcxproj index 1da8b14ed..e15a6eda7 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\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..165bbd55e 100644 --- a/example/windows/flutter_embedder_example.cpp +++ b/example/windows/flutter_embedder_example.cpp @@ -15,10 +15,10 @@ #include #include -#include +#include "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. @@ -31,15 +31,15 @@ int main(int argc, char **argv) { #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/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..634ea94d9 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,6 +263,19 @@ + + + + + + + + + + + + + @@ -270,4 +287,4 @@ - + \ No newline at end of file diff --git a/library/windows/GLFW Library.vcxproj.filters b/library/windows/GLFW Library.vcxproj.filters index 58963352d..02a3922cf 100644 --- a/library/windows/GLFW Library.vcxproj.filters +++ b/library/windows/GLFW Library.vcxproj.filters @@ -1,32 +1,35 @@ - - - - - {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 + + + + + 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 index a601c9c73..e76f35f9a 100644 --- a/library/windows/embedder.cpp +++ b/library/windows/embedder.cpp @@ -21,14 +21,33 @@ #include +#include "library/common/glfw/keyboard_hook_handler.h" +#include "library/common/glfw/text_input_plugin.h" +#include "library/common/internal/plugin_handler.h" + static_assert(FLUTTER_ENGINE_VERSION == 1, ""); -static constexpr char kDefaultWindowTitle[] = "Flutter"; +// Struct for storing state within an instance of the GLFW Window. +struct FlutterEmbedderState { + FlutterEngine engine; + std::unique_ptr plugin_handler; -bool FlutterInit() { return glfwInit(); } + // plugin_handler owns these pointers. Destruction happens when this struct is + // deleted from the heap. + std::vector + keyboard_hook_handlers; +}; -void FlutterTerminate() { glfwTerminate(); } +static constexpr char kDefaultWindowTitle[] = "Flutter"; + +// Retreaves state bag for the window in question from the GLFWWindow +static FlutterEmbedderState *GetSavedEmbedderState(GLFWwindow *window) { + return reinterpret_cast( + glfwGetWindowUserPointer(window)); +} +// When GLFW calls back to the window with a cursor position move, forward to +// FlutterEngine as a pointer event with appropriate phase static void GLFWcursorPositionCallbackAtPhase(GLFWwindow *window, FlutterPointerPhase phase, double x, double y) { @@ -41,11 +60,11 @@ static void GLFWcursorPositionCallbackAtPhase(GLFWwindow *window, std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch()) .count(); - FlutterEngineSendPointerEvent( - reinterpret_cast(glfwGetWindowUserPointer(window)), &event, - 1); + FlutterEngineSendPointerEvent(GetSavedEmbedderState(window)->engine, &event, + 1); } +// Report cursor move to engine static void GLFWcursorPositionCallback(GLFWwindow *window, double x, double y) { GLFWcursorPositionCallbackAtPhase(window, FlutterPointerPhase::kMove, x, y); } @@ -65,8 +84,19 @@ static void GLFWmouseButtonCallback(GLFWwindow *window, int key, int action, } } +static void GLFWCharCallback(GLFWwindow *window, unsigned int code_point) { + for (flutter_desktop_embedding::KeyboardHookHandler *handler : + GetSavedEmbedderState(window)->keyboard_hook_handlers) { + handler->CharHook(window, code_point); + } +} + static void GLFWKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) { + for (flutter_desktop_embedding::KeyboardHookHandler *handler : + GetSavedEmbedderState(window)->keyboard_hook_handlers) { + handler->KeyboardHook(window, key, scancode, action, mods); + } if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { glfwSetWindowShouldClose(window, GLFW_TRUE); } @@ -79,9 +109,41 @@ static void GLFWwindowSizeCallback(GLFWwindow *window, int width, int height) { event.height = height; // TODO: Handle pixel ratio for different DPI monitors. event.pixel_ratio = 1.0; - FlutterEngineSendWindowMetricsEvent( - reinterpret_cast(glfwGetWindowUserPointer(window)), - &event); + 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) { @@ -152,6 +214,7 @@ static FlutterEngine RunFlutterEngine( args.icu_data_path = icu_data_path.c_str(); args.command_line_argc = argv.size(); args.command_line_argv = &argv[0]; + args.platform_message_callback = GLFWOnFlutterPlatformMessage; FlutterEngine engine = nullptr; auto result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, window, &engine); @@ -161,6 +224,28 @@ static FlutterEngine RunFlutterEngine( return engine; } +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)); +} + +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); +} + GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height, const std::string &main_path, const std::string &assets_path, @@ -173,35 +258,43 @@ GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height, 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) { + auto engine = RunFlutterEngine(window, main_path, assets_path, packages_path, + icu_data_path, arguments); + if (engine == nullptr) { glfwDestroyWindow(window); return nullptr; } - glfwSetWindowUserPointer(window, flutter_engine_run_result); + + FlutterEmbedderState *state = new FlutterEmbedderState(); + state->plugin_handler = std::make_unique(engine); + state->engine = engine; + auto input_plugin = std::make_unique(); + state->keyboard_hook_handlers.push_back(input_plugin.get()); + + glfwSetWindowUserPointer(window, state); + + AddPlugin(window, std::move(input_plugin)); + int width, height; glfwGetWindowSize(window, &width, &height); GLFWwindowSizeCallback(window, width, height); glfwSetKeyCallback(window, GLFWKeyCallback); glfwSetWindowSizeCallback(window, GLFWwindowSizeCallback); glfwSetMouseButtonCallback(window, GLFWmouseButtonCallback); + GLFWAssignEventCallbacks(window); 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(); + // TODO(awdavies): This will be deprecated soon. + __FlutterEngineFlushPendingTasksNow(); } - FlutterEngineShutdown(reinterpret_cast( - glfwGetWindowUserPointer(flutter_window))); + auto state = GetSavedEmbedderState(flutter_window); + FlutterEngineShutdown(state->engine); + delete state; glfwDestroyWindow(flutter_window); } + +} // namespace flutter_desktop_embedding diff --git a/library/windows/embedder.h b/library/windows/embedder.h index 5d52c1c18..028d418fb 100644 --- a/library/windows/embedder.h +++ b/library/windows/embedder.h @@ -18,7 +18,11 @@ #include #include -#include +#include + +#include "library/include/flutter_desktop_embedding/plugin.h" + +namespace flutter_desktop_embedding { // Calls glfwInit() // @@ -65,6 +69,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 +84,6 @@ GLFWwindow *CreateFlutterWindowInSnapshotMode( // cleanup. void FlutterWindowLoop(GLFWwindow *flutter_window); +} // namespace flutter_desktop_embedding + #endif // WINDOWS_LIBRARY_EMBEDDER_H_ 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 From 29c6a3990ab58c6f1dfbabd53a2f9c199437553f Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Wed, 2 Jan 2019 08:51:38 -0800 Subject: [PATCH 06/13] [windows] Add key event support (#193) Enables the GLFW raw key event handler for Windows. --- library/windows/GLFW Library.vcxproj | 1 + library/windows/GLFW Library.vcxproj.filters | 41 +++++++++++++++++++- library/windows/embedder.cpp | 9 +++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/library/windows/GLFW Library.vcxproj b/library/windows/GLFW Library.vcxproj index 634ea94d9..8ea8c4899 100644 --- a/library/windows/GLFW Library.vcxproj +++ b/library/windows/GLFW Library.vcxproj @@ -263,6 +263,7 @@ + diff --git a/library/windows/GLFW Library.vcxproj.filters b/library/windows/GLFW Library.vcxproj.filters index 02a3922cf..bf7b4fad3 100644 --- a/library/windows/GLFW Library.vcxproj.filters +++ b/library/windows/GLFW Library.vcxproj.filters @@ -21,6 +21,45 @@ 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 + @@ -32,4 +71,4 @@ Source Files - + \ No newline at end of file diff --git a/library/windows/embedder.cpp b/library/windows/embedder.cpp index e76f35f9a..f6522ca3f 100644 --- a/library/windows/embedder.cpp +++ b/library/windows/embedder.cpp @@ -21,6 +21,7 @@ #include +#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" @@ -36,6 +37,10 @@ struct FlutterEmbedderState { // deleted from the heap. std::vector keyboard_hook_handlers; + + // Handles raw key interactions from GLFW. + // TODO: Revisit ownership model once Issue #102 is resolved. + std::unique_ptr key_event_handler; }; static constexpr char kDefaultWindowTitle[] = "Flutter"; @@ -268,6 +273,10 @@ GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height, FlutterEmbedderState *state = new FlutterEmbedderState(); state->plugin_handler = std::make_unique(engine); state->engine = engine; + + state->key_event_handler = + std::make_unique(state->plugin_handler.get()); + state->keyboard_hook_handlers.push_back(state->key_event_handler.get()); auto input_plugin = std::make_unique(); state->keyboard_hook_handlers.push_back(input_plugin.get()); From a304a8671b47353a26df0639f1e95d96b88f064a Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Wed, 2 Jan 2019 11:10:29 -0800 Subject: [PATCH 07/13] Merge GLFW library implementations (#194) Merges the GLFW-based embedding implementations for Windows and Linux into a single shared implementation. At this point the implementations are largely identical, and having two copies is increasingly a maintenance burden. Originally they were separate since they were intended to be throw-away, and their development proceeded at different speeds. Now that they have reached parity, and there's a possibility that the GLFW implementation will be longer-lived than initially expected, having one copy that's testable on several platforms should simplify development. --- example/linux/flutter_embedder_example.cc | 6 +- example/windows/GLFW Example.vcxproj | 2 +- example/windows/flutter_embedder_example.cpp | 2 +- library/BUILD.gn | 28 +- library/README.md | 2 +- .../{linux/src => common/glfw}/embedder.cc | 140 ++++---- .../glfw}/embedder.h | 18 +- .../linux/embedder.h | 85 ----- library/linux/Makefile | 2 +- library/windows/GLFW Library.vcxproj | 4 +- library/windows/GLFW Library.vcxproj.filters | 4 +- library/windows/embedder.cpp | 309 ------------------ 12 files changed, 119 insertions(+), 483 deletions(-) rename library/{linux/src => common/glfw}/embedder.cc (88%) rename library/{windows => include/flutter_desktop_embedding/glfw}/embedder.h (88%) delete mode 100644 library/include/flutter_desktop_embedding/linux/embedder.h delete mode 100644 library/windows/embedder.cpp diff --git a/example/linux/flutter_embedder_example.cc b/example/linux/flutter_embedder_example.cc index 1a030828e..003ecd989 100644 --- a/example/linux/flutter_embedder_example.cc +++ b/example/linux/flutter_embedder_example.cc @@ -26,7 +26,7 @@ #ifdef USE_FLATTENED_INCLUDES #include #else -#include +#include #endif namespace { @@ -53,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; } @@ -78,7 +78,7 @@ int main(int argc, char **argv) { 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/windows/GLFW Example.vcxproj b/example/windows/GLFW Example.vcxproj index e15a6eda7..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\;$(ProjectDir)..\..\;$(IncludePath);$(ProjectDir)..\..\library\windows\ + $(ProjectDir)..\..\library\windows\dependencies\;$(ProjectDir)..\..\;$(IncludePath);$(ProjectDir)..\..\library\windows\;$(ProjectDir)..\..\library\include\ $(ProjectDir)..\..\library\windows\dependencies\GLFW\;$(SolutionDir)bin\$(Platform)\$(Configuration)\GLFW Library\;$(LibraryPath) diff --git a/example/windows/flutter_embedder_example.cpp b/example/windows/flutter_embedder_example.cpp index 165bbd55e..94d4a2d57 100644 --- a/example/windows/flutter_embedder_example.cpp +++ b/example/windows/flutter_embedder_example.cpp @@ -15,7 +15,7 @@ #include #include -#include "embedder.h" +#include "flutter_desktop_embedding/glfw/embedder.h" int main(int argc, char **argv) { if (!flutter_desktop_embedding::FlutterInit()) { diff --git a/library/BUILD.gn b/library/BUILD.gn index 6b31ae428..605deddc5 100644 --- a/library/BUILD.gn +++ b/library/BUILD.gn @@ -17,14 +17,22 @@ import("//build/packaging.gni") import("//library/engine.gni") published_shared_library("flutter_embedder") { - if (is_linux) { - sources = [ - "linux/src/embedder.cc", - ] + # GLFW embedding implementation. + if (is_linux || is_win) { public = [ - "include/flutter_desktop_embedding/linux/embedder.h", + "include/flutter_desktop_embedding/glfw/embedder.h", + ] + sources = [ + "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", ] } + + # Embedding-agnostic shared C++. if (is_linux || is_win) { sources += [ "common/internal/engine_method_result.cc", @@ -56,16 +64,6 @@ published_shared_library("flutter_embedder") { "include/flutter_desktop_embedding/plugin.h", ] } - # GLFW-specific code. - if (is_linux || is_win) { - sources += [ - "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", - ] - } deps = [ ":fetch_flutter_engine", 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 88% rename from library/linux/src/embedder.cc rename to library/common/glfw/embedder.cc index b793464a2..c2a0b6460 100644 --- a/library/linux/src/embedder.cc +++ b/library/common/glfw/embedder.cc @@ -11,18 +11,14 @@ // 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 @@ -31,6 +27,12 @@ #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. #ifndef GLFW_TRUE @@ -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,7 +198,7 @@ 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); @@ -242,6 +248,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 +274,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 +289,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 +313,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/windows/embedder.h b/library/include/flutter_desktop_embedding/glfw/embedder.h similarity index 88% rename from library/windows/embedder.h rename to library/include/flutter_desktop_embedding/glfw/embedder.h index 028d418fb..669ea9d50 100644 --- a/library/windows/embedder.h +++ b/library/include/flutter_desktop_embedding/glfw/embedder.h @@ -12,15 +12,25 @@ // 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 +#ifdef __linux__ +// Epoxy must be included before any graphics-related code. +#include +#endif + #include -#include "library/include/flutter_desktop_embedding/plugin.h" +#ifdef USE_FLATTENED_INCLUDES +#include "plugin.h" +#else +#include "../plugin.h" +#endif namespace flutter_desktop_embedding { @@ -86,4 +96,4 @@ void FlutterWindowLoop(GLFWwindow *flutter_window); } // namespace flutter_desktop_embedding -#endif // WINDOWS_LIBRARY_EMBEDDER_H_ +#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_GLFW_EMBEDDER_H_ diff --git a/library/include/flutter_desktop_embedding/linux/embedder.h b/library/include/flutter_desktop_embedding/linux/embedder.h deleted file mode 100644 index 3fc973595..000000000 --- a/library/include/flutter_desktop_embedding/linux/embedder.h +++ /dev/null @@ -1,85 +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_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_LINUX_EMBEDDER_H_ -#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_LINUX_EMBEDDER_H_ - -// Epoxy must be included before any graphics-related code. -#include - -#include - -#include -#include - -#ifdef USE_FLATTENED_INCLUDES -#include "plugin.h" -#else -#include "../plugin.h" -#endif - -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_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_LINUX_EMBEDDER_H_ diff --git a/library/linux/Makefile b/library/linux/Makefile index 7c7f4db47..6a5810892 100644 --- a/library/linux/Makefile +++ b/library/linux/Makefile @@ -36,7 +36,7 @@ LDFLAGS= -L$(CURDIR) \ LIBRARIES=$(FLUTTER_ENGINE_LIB_FILE) HEADERS=$(shell find $(PROJECT_ROOT)/library/include/ -type f -name '*.h') \ $(FLUTTER_ENGINE_HEADER_DIR)/$(FLUTTER_ENGINE_HEADER) -SOURCES=$(shell find src/ $(PROJECT_ROOT)/library/common/ -type f -name '*.cc') +SOURCES=$(shell find $(PROJECT_ROOT)/library/common/ -type f -name '*.cc') .PHONY: all all: $(LIBRARY_OUT) diff --git a/library/windows/GLFW Library.vcxproj b/library/windows/GLFW Library.vcxproj index 8ea8c4899..f1628bc2d 100644 --- a/library/windows/GLFW Library.vcxproj +++ b/library/windows/GLFW Library.vcxproj @@ -263,6 +263,7 @@ + @@ -277,7 +278,6 @@ - @@ -288,4 +288,4 @@ - \ No newline at end of file + diff --git a/library/windows/GLFW Library.vcxproj.filters b/library/windows/GLFW Library.vcxproj.filters index bf7b4fad3..03dd85a33 100644 --- a/library/windows/GLFW Library.vcxproj.filters +++ b/library/windows/GLFW Library.vcxproj.filters @@ -15,7 +15,7 @@ - + Source Files @@ -71,4 +71,4 @@ Source Files - \ No newline at end of file + diff --git a/library/windows/embedder.cpp b/library/windows/embedder.cpp deleted file mode 100644 index f6522ca3f..000000000 --- a/library/windows/embedder.cpp +++ /dev/null @@ -1,309 +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 - -#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" - -static_assert(FLUTTER_ENGINE_VERSION == 1, ""); - -// Struct for storing state within an instance of the GLFW Window. -struct FlutterEmbedderState { - FlutterEngine engine; - std::unique_ptr plugin_handler; - - // plugin_handler owns these pointers. Destruction happens when this struct is - // deleted from the heap. - std::vector - keyboard_hook_handlers; - - // Handles raw key interactions from GLFW. - // TODO: Revisit ownership model once Issue #102 is resolved. - std::unique_ptr key_event_handler; -}; - -static constexpr char kDefaultWindowTitle[] = "Flutter"; - -// Retreaves state bag for the window in question from the GLFWWindow -static FlutterEmbedderState *GetSavedEmbedderState(GLFWwindow *window) { - return reinterpret_cast( - glfwGetWindowUserPointer(window)); -} - -// When GLFW calls back to the window with a cursor position move, forward to -// FlutterEngine as a pointer event with appropriate phase -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(GetSavedEmbedderState(window)->engine, &event, - 1); -} - -// Report cursor move to engine -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 GLFWCharCallback(GLFWwindow *window, unsigned int code_point) { - for (flutter_desktop_embedding::KeyboardHookHandler *handler : - GetSavedEmbedderState(window)->keyboard_hook_handlers) { - handler->CharHook(window, code_point); - } -} - -static void GLFWKeyCallback(GLFWwindow *window, int key, int scancode, - int action, int mods) { - for (flutter_desktop_embedding::KeyboardHookHandler *handler : - GetSavedEmbedderState(window)->keyboard_hook_handlers) { - handler->KeyboardHook(window, key, scancode, action, 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(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); - 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]; - args.platform_message_callback = GLFWOnFlutterPlatformMessage; - FlutterEngine engine = nullptr; - auto result = - FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, window, &engine); - if (result != kSuccess || engine == nullptr) { - return nullptr; - } - return engine; -} - -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)); -} - -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); -} - -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 engine = RunFlutterEngine(window, main_path, assets_path, packages_path, - icu_data_path, arguments); - if (engine == nullptr) { - glfwDestroyWindow(window); - return nullptr; - } - - FlutterEmbedderState *state = new FlutterEmbedderState(); - state->plugin_handler = std::make_unique(engine); - state->engine = engine; - - state->key_event_handler = - std::make_unique(state->plugin_handler.get()); - state->keyboard_hook_handlers.push_back(state->key_event_handler.get()); - auto input_plugin = std::make_unique(); - state->keyboard_hook_handlers.push_back(input_plugin.get()); - - glfwSetWindowUserPointer(window, state); - - AddPlugin(window, std::move(input_plugin)); - - int width, height; - glfwGetWindowSize(window, &width, &height); - GLFWwindowSizeCallback(window, width, height); - glfwSetKeyCallback(window, GLFWKeyCallback); - glfwSetWindowSizeCallback(window, GLFWwindowSizeCallback); - glfwSetMouseButtonCallback(window, GLFWmouseButtonCallback); - GLFWAssignEventCallbacks(window); - return window; -} - -void FlutterWindowLoop(GLFWwindow *flutter_window) { - while (!glfwWindowShouldClose(flutter_window)) { - glfwWaitEvents(); - // TODO(awdavies): This will be deprecated soon. - __FlutterEngineFlushPendingTasksNow(); - } - auto state = GetSavedEmbedderState(flutter_window); - FlutterEngineShutdown(state->engine); - delete state; - glfwDestroyWindow(flutter_window); -} - -} // namespace flutter_desktop_embedding From 57d7e8d94c7ecbf7d2ee5da20b788d2bd29a3d34 Mon Sep 17 00:00:00 2001 From: Geert-Johan Riemer Date: Wed, 2 Jan 2019 23:48:14 +0100 Subject: [PATCH 08/13] [linux] Add GLFW-based proc resolving (#184) Fixes #170 The default symbol resolver that is used when no specific resolver is given doesn't resolve according to OpenGL features available in the GLFW context. This causes errors for some users. --- library/common/glfw/embedder.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/common/glfw/embedder.cc b/library/common/glfw/embedder.cc index c2a0b6460..6c378538d 100644 --- a/library/common/glfw/embedder.cc +++ b/library/common/glfw/embedder.cc @@ -205,6 +205,12 @@ static void GLFWClearCanvas(GLFWwindow *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 @@ -228,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(); From f6a8878da90b613165942b429fff423fd90f849e Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Wed, 2 Jan 2019 16:19:31 -0800 Subject: [PATCH 09/13] Add project standards section to CONTRIBUTING.md (#196) Makes explicit what style guides and conventions the project follows, so that contributors can see them in advance rather than discovering them through the review process. --- CONTRIBUTING.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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.) From 0a90c93c49ff73764e2accfbf1d8e3a873a3ba04 Mon Sep 17 00:00:00 2001 From: 0xflotus <0xflotus@gmail.com> Date: Thu, 3 Jan 2019 14:50:14 +0100 Subject: [PATCH 10/13] Typo fix in README (#197) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d5c0398c..3d482078f 100644 --- a/README.md +++ b/README.md @@ -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 From 67cbda59d68f150aaf5633c2a7d6c709df80bf94 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Thu, 3 Jan 2019 13:12:13 -0800 Subject: [PATCH 11/13] Update release mode flag (#199) The Flutter engine renamed the flag that controls the "Debug" banner as part of the Dart 2 transition (Engine PR 6977). Update the example apps to pass the new flag in release mode. --- Debugging.md | 2 +- example/linux/flutter_embedder_example.cc | 2 +- example/macos/ExampleWindow.swift | 2 +- example/windows/flutter_embedder_example.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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/example/linux/flutter_embedder_example.cc b/example/linux/flutter_embedder_example.cc index 003ecd989..5cfad92a7 100644 --- a/example/linux/flutter_embedder_example.cc +++ b/example/linux/flutter_embedder_example.cc @@ -72,7 +72,7 @@ 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( 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/flutter_embedder_example.cpp b/example/windows/flutter_embedder_example.cpp index 94d4a2d57..389960b35 100644 --- a/example/windows/flutter_embedder_example.cpp +++ b/example/windows/flutter_embedder_example.cpp @@ -27,7 +27,7 @@ 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. From 82e46dee8b835042361a4f9f0c5184525b2a7f59 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Thu, 3 Jan 2019 19:37:15 -0800 Subject: [PATCH 12/13] Initial Travis configuration (#198) Builds Linux via Make and GN, and builds macOS. --- .travis.yaml | 35 +++++++ build/travis/install_flutter | 40 ++++++++ build/travis/linux/install_dependencies | 20 ++++ build/travis/linux/install_gn | 23 +++++ .../xcschemes/ExampleEmbedder.xcscheme | 91 +++++++++++++++++++ 5 files changed, 209 insertions(+) create mode 100644 .travis.yaml create mode 100755 build/travis/install_flutter create mode 100755 build/travis/linux/install_dependencies create mode 100755 build/travis/linux/install_gn create mode 100644 example/macos/ExampleEmbedder.xcodeproj/xcshareddata/xcschemes/ExampleEmbedder.xcscheme 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/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/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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 370f17fa50d9fd38fe10c422b344ffb97459e4e0 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Thu, 3 Jan 2019 20:44:42 -0800 Subject: [PATCH 13/13] [macos] Fix script handling of spaces in paths (#200) Currently building is broken when there are spaces in the path containing the local checkout of the repository. --- tools/build_flutter_assets | 2 +- tools/update_flutter_engine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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" "$@"