-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DartProject for Windows embedding API (#17210)
This is a step toward aligning the API with macOS, and will make it easier to add the precompiled library later for release mode (since it can just be added to the project directory, without any code changes required for wrapper clients). At the C API, uses a struct instead of individual arguments, mirroring a change that was already made on the Linux side to make the C API cleaner. Functional changes in addition to the restructuring: adds relative path support, as was recently added for GLFW Uses wstring, rather than string, for paths; the conversion to UTF-8 is actually a potential problem on Windows, so pushing it into the embedding allows us the possibility of removing it later (if we can figure out a good solution at the embedder.h layer) without API breakage. The old APIs used by the standard runner are left in place for now to avoid breaking the template on an engine roll. Once the framework template has been updated, the old API paths will be removed.
- Loading branch information
1 parent
8a8b298
commit 33a21d1
Showing
12 changed files
with
281 additions
and
100 deletions.
There are no files selected for viewing
This file contains 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 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 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
46 changes: 46 additions & 0 deletions
46
shell/platform/windows/client_wrapper/dart_project_unittests.cc
This file contains 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,46 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "flutter/shell/platform/windows/client_wrapper/include/flutter/dart_project.h" | ||
#include "gtest/gtest.h" | ||
|
||
namespace flutter { | ||
|
||
class DartProjectTest : public ::testing::Test { | ||
protected: | ||
// Wrapper for accessing private icu_data_path. | ||
std::wstring GetProjectIcuDataPath(const DartProject& project) { | ||
return project.icu_data_path(); | ||
} | ||
|
||
// Wrapper for accessing private assets_path. | ||
std::wstring GetProjectAssetsPath(const DartProject& project) { | ||
return project.assets_path(); | ||
} | ||
|
||
// Wrapper for accessing private engine_switches. | ||
std::vector<std::string> GetProjectEngineSwitches( | ||
const DartProject& project) { | ||
return project.engine_switches(); | ||
} | ||
}; | ||
|
||
TEST_F(DartProjectTest, StandardProjectFormat) { | ||
DartProject project(L"test"); | ||
EXPECT_EQ(GetProjectIcuDataPath(project), L"test\\icudtl.dat"); | ||
EXPECT_EQ(GetProjectAssetsPath(project), L"test\\flutter_assets"); | ||
} | ||
|
||
TEST_F(DartProjectTest, Switches) { | ||
DartProject project(L"test"); | ||
std::vector<std::string> switches = {"--foo", "--bar"}; | ||
project.SetEngineSwitches(switches); | ||
EXPECT_EQ(GetProjectEngineSwitches(project).size(), 2); | ||
EXPECT_EQ(GetProjectEngineSwitches(project)[0], "--foo"); | ||
} | ||
|
||
} // namespace flutter |
This file contains 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 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
65 changes: 65 additions & 0 deletions
65
shell/platform/windows/client_wrapper/include/flutter/dart_project.h
This file contains 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,65 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_ | ||
#define FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace flutter { | ||
|
||
// A set of Flutter and Dart assets used to initialize a Flutter engine. | ||
class DartProject { | ||
public: | ||
// Creates a DartProject from a directory path. The directory should contain | ||
// the following top-level items: | ||
// - icudtl.dat (provided as a resource by the Flutter tool) | ||
// - flutter_assets (as built by the Flutter tool) | ||
// | ||
// The path can either be absolute, or relative to the directory containing | ||
// the running executable. | ||
explicit DartProject(const std::wstring& path) { | ||
assets_path_ = path + L"\\flutter_assets"; | ||
icu_data_path_ = path + L"\\icudtl.dat"; | ||
} | ||
|
||
~DartProject() = default; | ||
|
||
// Switches to pass to the Flutter engine. See | ||
// https://github.com/flutter/engine/blob/master/shell/common/switches.h | ||
// for details. Not all switches will apply to embedding mode. Switches have | ||
// not stability guarantee, and are subject to change without notice. | ||
// | ||
// Note: This WILL BE REMOVED in the future. If you call this, please see | ||
// https://github.com/flutter/flutter/issues/38569. | ||
void SetEngineSwitches(const std::vector<std::string>& switches) { | ||
engine_switches_ = switches; | ||
} | ||
|
||
private: | ||
// Accessors for internals are private, so that they can be changed if more | ||
// flexible options for project structures are needed later without it | ||
// being a breaking change. Provide access to internal classes that need | ||
// them. | ||
friend class FlutterViewController; | ||
friend class DartProjectTest; | ||
|
||
const std::wstring& assets_path() const { return assets_path_; } | ||
const std::wstring& icu_data_path() const { return icu_data_path_; } | ||
const std::vector<std::string>& engine_switches() const { | ||
return engine_switches_; | ||
} | ||
|
||
// The path to the assets directory. | ||
std::wstring assets_path_; | ||
// The path to the ICU data. | ||
std::wstring icu_data_path_; | ||
// Switches to pass to the engine. | ||
std::vector<std::string> engine_switches_; | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_ |
This file contains 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 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 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
Oops, something went wrong.