forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add FlutterDesktopWindowProperties to the public API #133
Merged
swift-kim
merged 8 commits into
flutter-tizen:flutter-2.2.1-tizen
from
swift-kim:project-bundle
Jul 8, 2021
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a385454
Refactor using FlutterProjectBundle
swift-kim 0537059
Unsupport relative paths
swift-kim c4ba3de
Reland the support for relative paths
swift-kim 2315735
Add FlutterDesktopWindowProperties to the public API
swift-kim 64f3211
Document undocumented public APIs
swift-kim 2e3cbb9
Rebase and resolve conflicts
swift-kim 04de468
Enable FlutterTizenEngineTest.Run_Twice
swift-kim 0bd5307
Add documentation
swift-kim 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||
// 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 "flutter_project_bundle.h" | ||
|
||
#ifdef __X64_SHELL__ | ||
#include "flutter/shell/platform/common/path_utils.h" | ||
#else | ||
#include <app_common.h> | ||
#endif | ||
|
||
#include <filesystem> | ||
|
||
#include "flutter/shell/platform/tizen/tizen_log.h" | ||
|
||
namespace flutter { | ||
|
||
#ifndef __X64_SHELL__ | ||
namespace { | ||
|
||
// Returns the path of the directory containing the app binary, or an empty | ||
// string if the directory cannot be found. | ||
std::filesystem::path GetExecutableDirectory() { | ||
auto res_path = app_get_resource_path(); | ||
if (res_path == nullptr) { | ||
return std::filesystem::path(); | ||
} | ||
auto bin_path = std::filesystem::path(res_path) / ".." / "bin"; | ||
free(res_path); | ||
return bin_path.lexically_normal(); | ||
} | ||
|
||
} // namespace | ||
#endif | ||
|
||
FlutterProjectBundle::FlutterProjectBundle( | ||
const FlutterDesktopEngineProperties& properties) | ||
: assets_path_(properties.assets_path), | ||
icu_path_(properties.icu_data_path) { | ||
if (properties.aot_library_path != nullptr) { | ||
aot_library_path_ = std::filesystem::path(properties.aot_library_path); | ||
} | ||
|
||
// Resolve any relative paths. | ||
if (assets_path_.is_relative() || icu_path_.is_relative() || | ||
(!aot_library_path_.empty() && aot_library_path_.is_relative())) { | ||
std::filesystem::path executable_location = GetExecutableDirectory(); | ||
if (executable_location.empty()) { | ||
FT_LOGE("Unable to find executable location to resolve resource paths."); | ||
assets_path_ = std::filesystem::path(); | ||
icu_path_ = std::filesystem::path(); | ||
} else { | ||
assets_path_ = std::filesystem::path(executable_location) / assets_path_; | ||
icu_path_ = std::filesystem::path(executable_location) / icu_path_; | ||
if (!aot_library_path_.empty()) { | ||
aot_library_path_ = | ||
std::filesystem::path(executable_location) / aot_library_path_; | ||
} | ||
} | ||
} | ||
|
||
switches_.insert(switches_.end(), properties.switches, | ||
properties.switches + properties.switches_count); | ||
} | ||
|
||
bool FlutterProjectBundle::HasValidPaths() { | ||
return !assets_path_.empty() && !icu_path_.empty(); | ||
} | ||
|
||
// Attempts to load AOT data from the given path, which must be absolute and | ||
// non-empty. Logs and returns nullptr on failure. | ||
UniqueAotDataPtr FlutterProjectBundle::LoadAotData( | ||
const FlutterEngineProcTable& engine_procs) { | ||
if (aot_library_path_.empty()) { | ||
FT_LOGE( | ||
"Attempted to load AOT data, but no aot_library_path was provided."); | ||
return UniqueAotDataPtr(nullptr, nullptr); | ||
} | ||
if (!std::filesystem::exists(aot_library_path_)) { | ||
FT_LOGE("Can't load AOT data from %s; no such file.", | ||
aot_library_path_.u8string().c_str()); | ||
return UniqueAotDataPtr(nullptr, nullptr); | ||
} | ||
std::string path_string = aot_library_path_.u8string(); | ||
FlutterEngineAOTDataSource source = {}; | ||
source.type = kFlutterEngineAOTDataSourceTypeElfPath; | ||
source.elf_path = path_string.c_str(); | ||
FlutterEngineAOTData data = nullptr; | ||
auto result = engine_procs.CreateAOTData(&source, &data); | ||
if (result != kSuccess) { | ||
FT_LOGE("Failed to load AOT data from: %s", path_string.c_str()); | ||
return UniqueAotDataPtr(nullptr, nullptr); | ||
} | ||
return UniqueAotDataPtr(data, engine_procs.CollectAOTData); | ||
} | ||
|
||
FlutterProjectBundle::~FlutterProjectBundle() {} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||
// 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 EMBEDDER_FLUTTER_PROJECT_BUNDLE_H_ | ||
#define EMBEDDER_FLUTTER_PROJECT_BUNDLE_H_ | ||
|
||
#include <filesystem> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "flutter/shell/platform/embedder/embedder.h" | ||
#include "flutter/shell/platform/tizen/public/flutter_tizen.h" | ||
|
||
namespace flutter { | ||
|
||
using UniqueAotDataPtr = | ||
std::unique_ptr<_FlutterEngineAOTData, FlutterEngineCollectAOTDataFnPtr>; | ||
|
||
// The data associated with a Flutter project needed to run it in an engine. | ||
class FlutterProjectBundle { | ||
public: | ||
// Creates a new project bundle from the given properties. | ||
// | ||
// Treats any relative paths as relative to the directory of the app binary. | ||
explicit FlutterProjectBundle( | ||
const FlutterDesktopEngineProperties& properties); | ||
|
||
~FlutterProjectBundle(); | ||
|
||
// Whether or not the bundle is valid. This does not check that the paths | ||
// exist, or contain valid data, just that paths were able to be constructed. | ||
bool HasValidPaths(); | ||
|
||
// Returns the path to the assets directory. | ||
const std::filesystem::path& assets_path() { return assets_path_; } | ||
|
||
// Returns the path to the ICU data file. | ||
const std::filesystem::path& icu_path() { return icu_path_; } | ||
|
||
// Returns any switches that should be passed to the engine. | ||
const std::vector<std::string> switches() { return switches_; } | ||
|
||
// Attempts to load AOT data for this bundle. The returned data must be | ||
// retained until any engine instance it is passed to has been shut down. | ||
// | ||
// Logs and returns nullptr on failure. | ||
UniqueAotDataPtr LoadAotData(const FlutterEngineProcTable& engine_procs); | ||
|
||
private: | ||
std::filesystem::path assets_path_; | ||
std::filesystem::path icu_path_; | ||
std::vector<std::string> switches_ = {}; | ||
|
||
// Path to the AOT library file, if any. | ||
std::filesystem::path aot_library_path_; | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // EMBEDDER_FLUTTER_PROJECT_BUNDLE_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
Oops, something went wrong.
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.
I love this part! ❤️ It's much more intuitive. Thanks