-
Notifications
You must be signed in to change notification settings - Fork 610
[linux/windows] Add FlutterWindowController #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
stuartmorgan-g
merged 5 commits into
google:master
from
stuartmorgan-g:glfw-window-controller
Jan 29, 2019
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2019 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 "library/include/flutter_desktop_embedding/glfw/flutter_window_controller.h" | ||
|
||
#include <iostream> | ||
|
||
namespace flutter_desktop_embedding { | ||
|
||
FlutterWindowController::FlutterWindowController(std::string &icu_data_path) | ||
: icu_data_path_(icu_data_path) { | ||
init_succeeded_ = FlutterInit(); | ||
} | ||
|
||
FlutterWindowController::~FlutterWindowController() { | ||
if (init_succeeded_) { | ||
FlutterTerminate(); | ||
} | ||
} | ||
|
||
bool FlutterWindowController::CreateWindow( | ||
size_t width, size_t height, const std::string &assets_path, | ||
const std::vector<std::string> &arguments) { | ||
if (!init_succeeded_) { | ||
std::cerr << "Could not create window; FlutterInit failed." << std::endl; | ||
return false; | ||
} | ||
|
||
if (window_) { | ||
std::cerr << "Only one Flutter window can exist at a time." << std::endl; | ||
return false; | ||
} | ||
|
||
window_ = CreateFlutterWindow(width, height, assets_path, icu_data_path_, | ||
arguments); | ||
if (!window_) { | ||
std::cerr << "Failed to create window." << std::endl; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
PluginRegistrar *FlutterWindowController::GetRegistrarForPlugin( | ||
const std::string &plugin_name) { | ||
if (!window_) { | ||
return nullptr; | ||
} | ||
return flutter_desktop_embedding::GetRegistrarForPlugin(window_, plugin_name); | ||
} | ||
|
||
void FlutterWindowController::RunEventLoop() { | ||
if (window_) { | ||
FlutterWindowLoop(window_); | ||
} | ||
} | ||
|
||
} // namespace flutter_desktop_embedding |
89 changes: 89 additions & 0 deletions
89
library/include/flutter_desktop_embedding/glfw/flutter_window_controller.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2019 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_GLFW_FLUTTER_WINDOW_CONTROLLER_H_ | ||
#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_GLFW_FLUTTER_WINDOW_CONTROLLER_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "embedder.h" | ||
|
||
#ifdef USE_FLATTENED_INCLUDES | ||
#include "fde_export.h" | ||
#include "plugin_registrar.h" | ||
#else | ||
#include "../fde_export.h" | ||
#include "../plugin_registrar.h" | ||
#endif | ||
|
||
namespace flutter_desktop_embedding { | ||
|
||
// A controller for a window displaying Flutter content. | ||
// | ||
// This is the primary wrapper class for the desktop embedding C API. | ||
// If you use this class, you should not call any of the setup or teardown | ||
// methods in embedder.h directly, as this class will do that internally. | ||
// | ||
// Note: This is an early implementation (using GLFW internally) which | ||
// requires control of the application's event loop, and is thus useful | ||
// primarily for building a simple one-window shell hosting a Flutter | ||
// application. The final implementation and API will be very different. | ||
class FDE_EXPORT FlutterWindowController { | ||
public: | ||
// There must be only one instance of this class in an application at any | ||
// given time, as Flutter does not support multiple engines in one process, | ||
// or multiple views in one engine. | ||
explicit FlutterWindowController(std::string &icu_data_path); | ||
|
||
~FlutterWindowController(); | ||
|
||
// Creates and displays a window for displaying Flutter content. | ||
// | ||
// The |assets_path| is the path to the flutter_assets folder for the Flutter | ||
// application to be run. |icu_data_path| is the path to the icudtl.dat file | ||
// for the version of Flutter you are using. | ||
// | ||
// The |arguments| are passed to the Flutter engine. See: | ||
// https://github.com/flutter/engine/blob/master/shell/common/switches.h for | ||
// for details. Not all arguments will apply to embedding mode. | ||
// | ||
// Only one Flutter window can exist at a time; see constructor comment. | ||
bool CreateWindow(size_t width, size_t height, const std::string &assets_path, | ||
const std::vector<std::string> &arguments); | ||
|
||
// Returns the PluginRegistrar to register a plugin with the given name. | ||
// | ||
// The name must be unique across the application, so the recommended approach | ||
// is to use the fully namespace-qualified name of the plugin class. | ||
PluginRegistrar *GetRegistrarForPlugin(const std::string &plugin_name); | ||
|
||
// Loops on Flutter window events until the window closes. | ||
void RunEventLoop(); | ||
|
||
private: | ||
// The path to the ICU data file. Set at creation time since it is the same | ||
// for any window created. | ||
std::string icu_data_path_; | ||
|
||
// Whether or not FlutterInit succeeded at creation time. | ||
bool init_succeeded_ = false; | ||
|
||
// The curent Flutter window, if any. | ||
GLFWwindow *window_ = nullptr; | ||
}; | ||
|
||
} // namespace flutter_desktop_embedding | ||
|
||
#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_GLFW_FLUTTER_WINDOW_CONTROLLER_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Source Files"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Header Files"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Resource Files"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="..\common\glfw\embedder.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\glfw\text_input_plugin.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\engine_method_result.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\json_message_codec.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\internal\text_input_model.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\json_method_codec.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\glfw\key_event_handler.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\internal\plugin_handler.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="..\include\flutter_desktop_embedding\windows\embedder.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
</Project> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Source Files"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Header Files"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Resource Files"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="..\common\glfw\embedder.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\glfw\text_input_plugin.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\engine_method_result.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\json_message_codec.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\internal\text_input_model.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\json_method_codec.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\glfw\key_event_handler.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\internal\plugin_handler.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="..\common\glfw\flutter_window_controller.cc"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="..\include\flutter_desktop_embedding\windows\embedder.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
</Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this is just a comment rather an actual enforced singleton design is that my hope is that the C++ wrapper layer I'm working on extracting for #230 (which this would be part of) could be header-only, which wouldn't work with a singleton, so I'm structuring it this way to allow flipping to header-only without more API churn.