提交 fdcd65ee 编写于 作者: J Jason Simmons 提交者: GitHub

Exit the non-interactive sky_shell on Linux when the Dart script has completed (#3358)

The script will be finished when the microtask queue has been drained and
Dart_HasLivePorts is returning false for the main isolate
上级 16b2964f
......@@ -137,4 +137,16 @@ std::string RuntimeController::GetIsolateName() {
return dart_controller_->dart_state()->debug_name();
}
bool RuntimeController::HasLivePorts() {
if (!dart_controller_) {
return false;
}
UIDartState* dart_state = dart_controller_->dart_state();
if (!dart_state) {
return false;
}
DartState::Scope scope(dart_state);
return Dart_HasLivePorts();
}
} // namespace blink
......@@ -44,6 +44,8 @@ class RuntimeController : public WindowClient, public IsolateClient {
std::string GetIsolateName();
bool HasLivePorts();
private:
explicit RuntimeController(RuntimeDelegate* client);
......
......@@ -155,6 +155,12 @@ std::string Engine::GetUIIsolateName() {
return runtime_->GetIsolateName();
}
bool Engine::UIIsolateHasLivePorts() {
if (!runtime_)
return false;
return runtime_->HasLivePorts();
}
void Engine::OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation) {
blink::Threads::Gpu()->PostTask(gpu_continuation);
have_surface_ = true;
......
......@@ -59,6 +59,8 @@ class Engine : public blink::RuntimeDelegate {
std::string GetUIIsolateName();
bool UIIsolateHasLivePorts();
void OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation);
void OnOutputSurfaceDestroyed(const ftl::Closure& gpu_continuation);
void SetViewportMetrics(const blink::ViewportMetrics& metrics);
......
......@@ -14,22 +14,57 @@
#include "flutter/shell/gpu/gpu_surface_gl.h"
#include "flutter/shell/platform/linux/message_pump_glfw.h"
#include "flutter/shell/platform/linux/platform_view_glfw.h"
#include "flutter/shell/testing/test_runner.h"
#include "flutter/shell/testing/testing.h"
#include "flutter/sky/engine/public/web/Sky.h"
namespace {
int RunNonInteractive() {
// Checks whether the engine's main Dart isolate has no pending work. If so,
// then exit the given message loop.
class ScriptCompletionTaskObserver : public base::MessageLoop::TaskObserver {
public:
ScriptCompletionTaskObserver(base::MessageLoop& main_message_loop)
: main_message_loop_(main_message_loop), prev_live_(false) {}
void WillProcessTask(const base::PendingTask& pending_task) override {}
void DidProcessTask(const base::PendingTask& pending_task) override {
shell::TestRunner& test_runner = shell::TestRunner::Shared();
bool live = test_runner.platform_view().engine().UIIsolateHasLivePorts();
if (prev_live_ && !live)
main_message_loop_.PostTask(FROM_HERE,
main_message_loop_.QuitWhenIdleClosure());
prev_live_ = live;
}
private:
base::MessageLoop& main_message_loop_;
bool prev_live_;
};
void RunNonInteractive() {
base::MessageLoop message_loop;
shell::Shell::InitStandalone();
// Note that this task observer must be added after the observer that drains
// the microtask queue.
ScriptCompletionTaskObserver task_observer(message_loop);
blink::Threads::UI()->PostTask([&task_observer] {
base::MessageLoop::current()->AddTaskObserver(&task_observer);
});
if (!shell::InitForTesting()) {
shell::PrintUsage("sky_shell");
return 1;
exit(1);
}
message_loop.Run();
return 0;
// The script has completed and the engine may not be in a clean state,
// so just stop the process.
exit(0);
}
static bool IsDartFile(const std::string& path) {
......@@ -98,7 +133,8 @@ int main(int argc, const char* argv[]) {
if (command_line.HasSwitch(
shell::FlagForSwitch(shell::Switch::NonInteractive))) {
return RunNonInteractive();
RunNonInteractive();
return 0;
}
return RunInteractive();
......
......@@ -26,6 +26,8 @@ class TestRunner {
void Run(const TestDescriptor& test);
PlatformView& platform_view() { return *platform_view_; }
private:
TestRunner();
~TestRunner();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册