-
Notifications
You must be signed in to change notification settings - Fork 6k
Remove get engine #9747
Remove get engine #9747
Conversation
shell/common/shell.cc
Outdated
| // to purge them. | ||
| } | ||
|
|
||
| Engine::RunStatus Shell::RunEngine(RunConfiguration run_configuration) { |
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 expectation is that all shell methods are called on the platform task runner. So let's post the task to the correct task runner. I don't think anyone ever uses the run status to log an error. So, we can return void here. Or, better still, take a callback that returns the result.
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.
Fixed. I've also "fixed" the problems I was having with Flutter tester by just exposing the things it needs through the shell. We may want to remove those but that will be an effort I'm less familiar with the internals of at this point.
Additionally, I'm adding back the getEngine but marking ti deprecated to make the eventual roll to Fuchsia less painful.
| } | ||
|
|
||
| void Shell::RunEngine(RunConfiguration run_configuration, | ||
| std::function<void(Engine::RunStatus)> result_callback) { |
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 think it would be better to have the result callback be executed on the calling task runner (the platform task runner in this case). Since doing the re-threading at the each possible call-site is tedious, you can wrap the same in and closure that does the re-threading and then pass that around as normal. See the image decoder for a use of this pattern.
On a related note, since forgetting to invoke the closure in the error case is possible, maybe we should have an RAII wrapper for the same. I have a prototype for this in a different patch that is not in yet.
That way, you can wrap the callback in a closure that does the re-threading and put it in that RAII wrapper. You could then invoke the same only in the success case and ensure that all erroneous cases invoke the callback and on the right thread.
Something like the following should work for now:
auto result = [runner = task_runner_.GetPlatformTaskRunner(), result_callback]
(Engine::RunStatus status){
if (!result_callback) {
return;
}
runner->PostTask([result_callback, status](){ result_callback(status); });
};
// Pass result around and invoke it directly (no null check is necessary as it is performed in the wrapper).
// In the future, result can be stuffed inside an AutoFireClosure.
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.
Done
shell/common/shell.cc
Outdated
| task_runners_.GetUITaskRunner(), | ||
| fml::MakeCopyable([run_configuration = std::move(run_configuration), | ||
| weak_engine = weak_engine_, | ||
| result_callback = |
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.
std::move on closures is not necessary.
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.
Done
shell/common/shell.h
Outdated
| public ServiceProtocol::Handler { | ||
| public: | ||
| /// The Dart error code for an API error. | ||
| const int kApiErrorExitCode = 253; |
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.
Can we make these enums instead now?
shell/common/shell.cc
Outdated
| if (!weak_engine_) { | ||
| return std::nullopt; | ||
| } | ||
| switch (weak_engine_->GetUIIsolateLastError()) { |
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.
Using a weak pointer on the non-originating thread is not thread safe. See the comment in weak_ptr.h that describes safe use. I have pasted the relevant bits below.
Now in this particular case, the engine provides a guarantee that shell subcomponents will be destroyed before its destructor finishes execution on the platform task runner. So, it happens to work out. But I would still be more comfortable if code didn't break safe threading rules because of the lifecycle assumptions. It is not immediately clear from reading just this bit of code about why this is safe even though it breaks rules of safe weak pointer use.
You can use the same pattern used right above in the RunEngine call.
// Weak pointers are not in general thread-safe. They may only be *used* on a
// single thread, namely the same thread as the "originating" |WeakPtrFactory|
// (which can invalidate the weak pointers that it generates).
//
// However, weak pointers may be passed to other threads, reset on other
// threads, or destroyed on other threads. They may also be reassigned on other
// threads (in which case they should then only be used on the thread
// corresponding to the new "originating" |WeakPtrFactory|).
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.
Going with the unique_ptr and a comment, as discussed offline
| } | ||
| } | ||
|
|
||
| bool Shell::EngineHasLivePorts() const { |
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.
Ditto on the comment in Shell::GetUIIsolateLastError
shell/common/shell.cc
Outdated
| case tonic::kUnknownErrorType: | ||
| return kErrorExitCode; | ||
| default: | ||
| return 0; |
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.
0 is actually EXIT_SUCCESS. So we will end up saying an unknown failure is no failure. This seems dodgy. Lets use kErrorExitCode as the default.
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 was under the impression the engine method returned 0 if ther ewas no error. Is that not the case?
The tester_main was defaulting this case to 0 as well AFAICT
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.
It seems to be tonic::kNoError. You can return 0 in that case instead of just defaulting to success.
dnfield
left a comment
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.
Updated
| } | ||
|
|
||
| void Shell::RunEngine(RunConfiguration run_configuration, | ||
| std::function<void(Engine::RunStatus)> result_callback) { |
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.
Done
shell/common/shell.cc
Outdated
| task_runners_.GetUITaskRunner(), | ||
| fml::MakeCopyable([run_configuration = std::move(run_configuration), | ||
| weak_engine = weak_engine_, | ||
| result_callback = |
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.
Done
shell/common/shell.cc
Outdated
| if (!weak_engine_) { | ||
| return std::nullopt; | ||
| } | ||
| switch (weak_engine_->GetUIIsolateLastError()) { |
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.
Going with the unique_ptr and a comment, as discussed offline
| sync_run_latch.Signal(); | ||
| })); | ||
| sync_run_latch.Wait(); | ||
| fml::MessageLoop::GetCurrent().AddTaskObserver( |
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.
Much clearer. Thanks.
flutter/engine@b43178e...a29ef66 git log b43178e..a29ef66 --no-merges --oneline a29ef66 [fuchsia] Remove extraneous ShapeNodes (flutter/engine#10150) 8ef792f Roll src/third_party/skia a13c7744f154f434b5415688280b4e127a2ce8f5..6808e2d1faaccd6fc739f436c2470f199aa4d1a8 (2 commits) (flutter/engine#10281) ca29c72 Roll fuchsia/sdk/core/mac-amd64 from fuchsia/sdk/core/mac-amd64:vjX_DhfQqJjsX26pl5-vNNM3Lfb0Vwl9l09abYj-D1oC to fuchsia/sdk/core/mac-amd64:A4Ah4g0K30dWnbolQ7Z3zyXapbAyy3d9l4IeLGAG9YQC (flutter/engine#10280) 75970d7 Roll fuchsia/sdk/core/linux-amd64 from fuchsia/sdk/core/linux-amd64:om5F-s2gIabc-Toen2VT6nnosnQvTKI1e6Nz2zg8P40C to fuchsia/sdk/core/linux-amd64:6j9WXOOtqKZzSKIgQi-12GJ1MYzPDJvq-RLAtpJpGB0C (flutter/engine#10279) 6a69cd5 Roll src/third_party/skia 6980c4e0aef8ab9546e25d8160c05a716f1c3ce3..a13c7744f154f434b5415688280b4e127a2ce8f5 (1 commits) (flutter/engine#10278) 7a7afab Roll fuchsia/sdk/core/linux-amd64 from fuchsia/sdk/core/linux-amd64:MuVYOXXS9sxCbxvFCJDHfuF5pkWXIgS0uUlBFdIuQPsC to fuchsia/sdk/core/linux-amd64:om5F-s2gIabc-Toen2VT6nnosnQvTKI1e6Nz2zg8P40C (flutter/engine#10277) 02649bd Roll fuchsia/sdk/core/mac-amd64 from fuchsia/sdk/core/mac-amd64:kSzcB40iCqsXbCka_VUf4jB5iRl2G9gLM_xDbbGg5GwC to fuchsia/sdk/core/mac-amd64:vjX_DhfQqJjsX26pl5-vNNM3Lfb0Vwl9l09abYj-D1oC (flutter/engine#10276) e8b19de Roll src/third_party/skia 6e86c1b05eeedc3b6be0e98001b7b5d6bab71b74..6980c4e0aef8ab9546e25d8160c05a716f1c3ce3 (4 commits) (flutter/engine#10275) 3be7523 Roll fuchsia/sdk/core/linux-amd64 from fuchsia/sdk/core/linux-amd64:pGTb76UZ-PsJzdatSNkJIkEGLESaGa_S2wtZfgHPU5EC to fuchsia/sdk/core/linux-amd64:MuVYOXXS9sxCbxvFCJDHfuF5pkWXIgS0uUlBFdIuQPsC (flutter/engine#10274) ed8e35c Remove get engine (flutter/engine#9747) The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md If the roll is causing failures, please contact the current sheriff ([email protected]), and stop the roller if necessary.
Fixes flutter/flutter#35889
Removes access do the engine pointer from shell holders, so that they don't bypass PlatformView or Shell methods to do things like set viewport metrics or dispatching pointer data packets.
This will break the flutter_runner - will prepare a patch in topaz to avoid that.I'm going to leave the engine getter in for Fuchsia only for now. We can work this out once flutter_runner is completely built out of our repo.