-
Notifications
You must be signed in to change notification settings - Fork 6k
Preserve specified AssetResolvers when performing a hot restart or updating the asset directory #21611
Preserve specified AssetResolvers when performing a hot restart or updating the asset directory #21611
Changes from 7 commits
ff717e6
bfa9783
13fb0c1
6810d05
4bfc73a
27b200a
5a4d2ab
980ecb7
2e94df6
5f920da
9a8269f
c336ec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,17 @@ class AssetResolver { | |
|
|
||
| virtual bool IsValid() const = 0; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Certain asset resolvers need to be preserved when the asset | ||
| /// directory is updated or the isolate recreated. While some | ||
| /// could be recated from the settings object, the Android | ||
| /// specific asset resolvers require a reference to the JNI to | ||
| /// create. | ||
| /// | ||
| /// @return Returns whether this resolver should be preserved. | ||
| /// | ||
| virtual bool ShouldPreserve() const = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we come up with a better name for this? Maybe something like "Should" is a bit of a weak word to use (we usually prefer "must"), and it'd be helpful to have more context when reading the code about when or why I should care about this parameter.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about something like: Asset resolvers that are valid after a reload or a restart must be preserved and inserted into the newly created asset manager or run configuration. This allows the tooling to avoid copying assets through the device devFS on start, which has
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That might help with the docs, but I'm looking for a better member name than And it this something we could combine with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its not just restarts though, its also the first hot reload.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Just something that gives me a slightly better clue as I go to use the API and read the code. And then in the docs we can describe when an asset manager changes or why I'd want to check this. |
||
|
|
||
| [[nodiscard]] virtual std::unique_ptr<fml::Mapping> GetAsMapping( | ||
| const std::string& asset_name) const = 0; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,13 @@ | |
|
|
||
| namespace flutter { | ||
|
|
||
| DirectoryAssetBundle::DirectoryAssetBundle(fml::UniqueFD descriptor) | ||
| DirectoryAssetBundle::DirectoryAssetBundle(fml::UniqueFD descriptor, | ||
| bool should_preserve) | ||
| : descriptor_(std::move(descriptor)) { | ||
| if (!fml::IsDirectory(descriptor_)) { | ||
| return; | ||
| } | ||
| should_preserve_ = should_preserve; | ||
| is_valid_ = true; | ||
| } | ||
|
|
||
|
|
@@ -27,6 +29,11 @@ bool DirectoryAssetBundle::IsValid() const { | |
| return is_valid_; | ||
| } | ||
|
|
||
| // |AssetResolver| | ||
| bool DirectoryAssetBundle::ShouldPreserve() const { | ||
| return should_preserve_; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you missed this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotem |
||
| } | ||
|
|
||
| // |AssetResolver| | ||
| std::unique_ptr<fml::Mapping> DirectoryAssetBundle::GetAsMapping( | ||
| const std::string& asset_name) const { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,17 +14,21 @@ namespace flutter { | |
|
|
||
| class DirectoryAssetBundle : public AssetResolver { | ||
| public: | ||
| explicit DirectoryAssetBundle(fml::UniqueFD descriptor); | ||
| explicit DirectoryAssetBundle(fml::UniqueFD descriptor, bool should_preserve); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drop explicit since this is no longer a one arg ctor. |
||
|
|
||
| ~DirectoryAssetBundle() override; | ||
|
|
||
| private: | ||
| const fml::UniqueFD descriptor_; | ||
| bool is_valid_ = false; | ||
| bool should_preserve_ = false; | ||
|
|
||
| // |AssetResolver| | ||
| bool IsValid() const override; | ||
|
|
||
| // |AssetResolver| | ||
| bool ShouldPreserve() const override; | ||
|
|
||
| // |AssetResolver| | ||
| std::unique_ptr<fml::Mapping> GetAsMapping( | ||
| const std::string& asset_name) const override; | ||
|
|
||
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.
No idea if this is reasonable :)
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'm pretty sure that this is correct because resolvers_ is an lvalue here.
This is behaviorally the same as making a copy of the deque and clearing the original, but the compiler should be able to optimize this to not do the copy now.
@jason-simmons or @chinmaygarde could verify that though.
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.
Even with the copy, the most frequent number of elements seems to be 1, and with this change that will grow to 2
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.
In case I wasn't clear, this way of doing things avoids a copy.
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.
ahh ... good, right :)