Remove the interactive mode on the Linux test shell. (flutter/engine#3510)
This commit is contained in:
@@ -7,10 +7,6 @@ executable("linux") {
|
||||
|
||||
sources = [
|
||||
"main_linux.cc",
|
||||
"message_pump_glfw.cc",
|
||||
"message_pump_glfw.h",
|
||||
"platform_view_glfw.cc",
|
||||
"platform_view_glfw.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
@@ -26,7 +22,6 @@ executable("linux") {
|
||||
# Required by FontCacheLinux. Not Skia. Skia uses a custom font manager
|
||||
# that delegates to us.
|
||||
"//third_party:fontconfig",
|
||||
"//third_party/glfw",
|
||||
"//third_party/skia",
|
||||
]
|
||||
|
||||
|
||||
@@ -8,11 +8,9 @@
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "dart/runtime/bin/embedded_dart_io.h"
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/shell/common/platform_view.h"
|
||||
#include "flutter/shell/common/shell.h"
|
||||
#include "flutter/shell/common/switches.h"
|
||||
#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"
|
||||
@@ -113,57 +111,6 @@ void RunNonInteractive(ftl::CommandLine initial_command_line,
|
||||
exit(ConvertErrorTypeToExitCode(error));
|
||||
}
|
||||
|
||||
static bool IsDartFile(const std::string& path) {
|
||||
std::string dart_extension = ".dart";
|
||||
return path.rfind(dart_extension) == (path.size() - dart_extension.size());
|
||||
}
|
||||
|
||||
int RunInteractive(ftl::CommandLine initial_command_line) {
|
||||
base::MessageLoop message_loop(shell::MessagePumpGLFW::Create());
|
||||
|
||||
shell::Shell::InitStandalone(std::move(initial_command_line));
|
||||
|
||||
const auto& command_line = shell::Shell::Shared().GetCommandLine();
|
||||
|
||||
std::string target = command_line.GetOptionValueWithDefault(
|
||||
shell::FlagForSwitch(shell::Switch::FLX), "");
|
||||
|
||||
if (target.empty()) {
|
||||
// Alternatively, use the first positional argument.
|
||||
auto args = command_line.positional_args();
|
||||
if (args.empty())
|
||||
return 1;
|
||||
target = args[0];
|
||||
}
|
||||
|
||||
if (target.empty())
|
||||
return 1;
|
||||
|
||||
std::unique_ptr<shell::PlatformViewGLFW> platform_view(
|
||||
new shell::PlatformViewGLFW());
|
||||
|
||||
platform_view->NotifyCreated(
|
||||
std::make_unique<shell::GPUSurfaceGL>(platform_view.get()));
|
||||
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = platform_view->engine().GetWeakPtr(), target ] {
|
||||
if (engine) {
|
||||
if (IsDartFile(target)) {
|
||||
engine->RunBundleAndSource(std::string(), target, std::string());
|
||||
|
||||
} else {
|
||||
engine->RunBundle(target);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
message_loop.Run();
|
||||
|
||||
platform_view->NotifyDestroyed();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -176,16 +123,11 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
if (command_line.HasOption(shell::FlagForSwitch(shell::Switch::Help))) {
|
||||
shell::PrintUsage("sky_shell");
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (command_line.HasOption(
|
||||
shell::FlagForSwitch(shell::Switch::NonInteractive))) {
|
||||
bool run_forever =
|
||||
command_line.HasOption(shell::FlagForSwitch(shell::Switch::RunForever));
|
||||
RunNonInteractive(std::move(command_line), run_forever);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return RunInteractive(std::move(command_line));
|
||||
bool run_forever =
|
||||
command_line.HasOption(shell::FlagForSwitch(shell::Switch::RunForever));
|
||||
RunNonInteractive(std::move(command_line), run_forever);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
// Copyright 2016 The Chromium 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/shell/platform/linux/message_pump_glfw.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "base/auto_reset.h"
|
||||
#include "base/time/time.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
MessagePumpGLFW::MessagePumpGLFW() : in_run_(false), should_quit_(false) {}
|
||||
|
||||
MessagePumpGLFW::~MessagePumpGLFW() = default;
|
||||
|
||||
scoped_ptr<base::MessagePump> MessagePumpGLFW::Create() {
|
||||
return scoped_ptr<MessagePump>(new MessagePumpGLFW());
|
||||
}
|
||||
|
||||
void MessagePumpGLFW::Run(Delegate* delegate) {
|
||||
base::AutoReset<bool> auto_reset_keep_running(&should_quit_, false);
|
||||
base::AutoReset<bool> auto_reset_in_run(&in_run_, true);
|
||||
|
||||
for (;;) {
|
||||
bool did_work = delegate->DoWork();
|
||||
if (should_quit_)
|
||||
break;
|
||||
|
||||
did_work |= delegate->DoDelayedWork(&delayed_work_time_);
|
||||
if (should_quit_)
|
||||
break;
|
||||
|
||||
if (did_work)
|
||||
continue;
|
||||
|
||||
did_work = delegate->DoIdleWork();
|
||||
if (should_quit_)
|
||||
break;
|
||||
|
||||
if (did_work)
|
||||
continue;
|
||||
|
||||
if (delayed_work_time_.is_null()) {
|
||||
glfwWaitEvents();
|
||||
} else {
|
||||
base::TimeDelta delay = delayed_work_time_ - base::TimeTicks::Now();
|
||||
if (delay > base::TimeDelta()) {
|
||||
glfwWaitEventsTimeout(delay.InSecondsF());
|
||||
} else {
|
||||
// It looks like delayed_work_time_ indicates a time in the past, so we
|
||||
// need to call DoDelayedWork now.
|
||||
delayed_work_time_ = base::TimeTicks();
|
||||
}
|
||||
}
|
||||
|
||||
if (should_quit_)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MessagePumpGLFW::Quit() {
|
||||
DCHECK(in_run_) << "Quit was called outside of Run!";
|
||||
should_quit_ = true;
|
||||
ScheduleWork();
|
||||
}
|
||||
|
||||
void MessagePumpGLFW::ScheduleWork() {
|
||||
glfwPostEmptyEvent();
|
||||
}
|
||||
|
||||
void MessagePumpGLFW::ScheduleDelayedWork(
|
||||
const base::TimeTicks& delayed_work_time) {
|
||||
// We know that we can't be blocked on Wait right now since this method can
|
||||
// only be called on the same thread as Run, so we only need to update our
|
||||
// record of how long to sleep when we do sleep.
|
||||
delayed_work_time_ = delayed_work_time;
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2016 The Chromium 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 SHELL_PLATFORM_GLFW_MESSAGE_PUMP_GLFW_H_
|
||||
#define SHELL_PLATFORM_GLFW_MESSAGE_PUMP_GLFW_H_
|
||||
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/message_loop/message_pump.h"
|
||||
#include "base/time/time.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
class MessagePumpGLFW : public base::MessagePump {
|
||||
public:
|
||||
MessagePumpGLFW();
|
||||
|
||||
~MessagePumpGLFW() override;
|
||||
|
||||
static scoped_ptr<base::MessagePump> Create();
|
||||
|
||||
void Run(Delegate* delegate) override;
|
||||
|
||||
void Quit() override;
|
||||
|
||||
void ScheduleWork() override;
|
||||
|
||||
void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override;
|
||||
|
||||
private:
|
||||
bool in_run_;
|
||||
bool should_quit_;
|
||||
base::TimeTicks delayed_work_time_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(MessagePumpGLFW);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
|
||||
#endif // SHELL_PLATFORM_GLFW_MESSAGE_PUMP_GLFW_H_
|
||||
@@ -1,191 +0,0 @@
|
||||
// Copyright 2016 The Chromium 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/shell/platform/linux/platform_view_glfw.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/shell/gpu/gpu_rasterizer.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
inline PlatformViewGLFW* ToPlatformView(GLFWwindow* window) {
|
||||
return static_cast<PlatformViewGLFW*>(glfwGetWindowUserPointer(window));
|
||||
}
|
||||
|
||||
PlatformViewGLFW::PlatformViewGLFW()
|
||||
: PlatformView(std::make_unique<GPURasterizer>(nullptr)),
|
||||
valid_(false),
|
||||
glfw_window_(nullptr),
|
||||
buttons_(0) {
|
||||
CreateEngine();
|
||||
|
||||
if (!glfwInit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
glfw_window_ = glfwCreateWindow(640, 480, "Flutter", NULL, NULL);
|
||||
if (glfw_window_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
glfwSetWindowUserPointer(glfw_window_, this);
|
||||
|
||||
glfwSetWindowSizeCallback(
|
||||
glfw_window_, [](GLFWwindow* window, int width, int height) {
|
||||
ToPlatformView(window)->OnWindowSizeChanged(width, height);
|
||||
});
|
||||
|
||||
glfwSetMouseButtonCallback(
|
||||
glfw_window_, [](GLFWwindow* window, int button, int action, int mods) {
|
||||
ToPlatformView(window)->OnMouseButtonChanged(button, action, mods);
|
||||
});
|
||||
|
||||
glfwSetKeyCallback(glfw_window_, [](GLFWwindow* window, int key, int scancode,
|
||||
int action, int mods) {
|
||||
ToPlatformView(window)->OnKeyEvent(key, scancode, action, mods);
|
||||
});
|
||||
|
||||
valid_ = true;
|
||||
|
||||
PostAddToShellTask();
|
||||
}
|
||||
|
||||
PlatformViewGLFW::~PlatformViewGLFW() {
|
||||
if (glfw_window_ != nullptr) {
|
||||
glfwSetWindowUserPointer(glfw_window_, nullptr);
|
||||
glfwDestroyWindow(glfw_window_);
|
||||
glfw_window_ = nullptr;
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
bool PlatformViewGLFW::IsValid() const {
|
||||
return valid_;
|
||||
}
|
||||
|
||||
intptr_t PlatformViewGLFW::GLContextFBO() const {
|
||||
// The default window bound FBO.
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool PlatformViewGLFW::GLContextMakeCurrent() {
|
||||
glfwMakeContextCurrent(glfw_window_);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlatformViewGLFW::GLContextClearCurrent() {
|
||||
glfwMakeContextCurrent(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlatformViewGLFW::ResourceContextMakeCurrent() {
|
||||
// Resource loading contexts are not supported on this platform.
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PlatformViewGLFW::GLContextPresent() {
|
||||
glfwSwapBuffers(glfw_window_);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlatformViewGLFW::RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) {}
|
||||
|
||||
void PlatformViewGLFW::OnWindowSizeChanged(int width, int height) {
|
||||
blink::ViewportMetrics metrics;
|
||||
metrics.physical_width = width;
|
||||
metrics.physical_height = height;
|
||||
|
||||
blink::Threads::UI()->PostTask([ engine = engine().GetWeakPtr(), metrics ] {
|
||||
if (engine.get())
|
||||
engine->SetViewportMetrics(metrics);
|
||||
});
|
||||
}
|
||||
|
||||
void PlatformViewGLFW::OnMouseButtonChanged(int button, int action, int mods) {
|
||||
blink::PointerData::Change change = blink::PointerData::Change::kCancel;
|
||||
if (action == GLFW_PRESS) {
|
||||
if (!buttons_) {
|
||||
change = blink::PointerData::Change::kDown;
|
||||
glfwSetCursorPosCallback(
|
||||
glfw_window_, [](GLFWwindow* window, double x, double y) {
|
||||
ToPlatformView(window)->OnCursorPosChanged(x, y);
|
||||
});
|
||||
} else {
|
||||
change = blink::PointerData::Change::kMove;
|
||||
}
|
||||
// GLFW's button order matches what we want:
|
||||
// https://github.com/flutter/engine/blob/master/sky/specs/pointer.md
|
||||
// http://www.glfw.org/docs/3.2/group__buttons.html
|
||||
buttons_ |= 1 << button;
|
||||
} else if (action == GLFW_RELEASE) {
|
||||
buttons_ &= ~(1 << button);
|
||||
if (!buttons_) {
|
||||
change = blink::PointerData::Change::kUp;
|
||||
glfwSetCursorPosCallback(glfw_window_, nullptr);
|
||||
} else {
|
||||
change = blink::PointerData::Change::kMove;
|
||||
}
|
||||
} else {
|
||||
FTL_DLOG(INFO) << "Unknown mouse action: " << action;
|
||||
return;
|
||||
}
|
||||
|
||||
double x = 0.0;
|
||||
double y = 0.0;
|
||||
glfwGetCursorPos(glfw_window_, &x, &y);
|
||||
|
||||
blink::PointerData pointer_data;
|
||||
pointer_data.Clear();
|
||||
pointer_data.time_stamp =
|
||||
ftl::TimePoint::Now().ToEpochDelta().ToMicroseconds();
|
||||
pointer_data.change = change;
|
||||
pointer_data.kind = blink::PointerData::DeviceKind::kMouse;
|
||||
pointer_data.physical_x = x;
|
||||
pointer_data.physical_y = y;
|
||||
pointer_data.buttons = buttons_;
|
||||
pointer_data.pressure = 1.0;
|
||||
pointer_data.pressure_max = 1.0;
|
||||
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine().GetWeakPtr(), pointer_data ] {
|
||||
if (engine.get()) {
|
||||
blink::PointerDataPacket packet(1);
|
||||
packet.SetPointerData(0, pointer_data);
|
||||
engine->DispatchPointerDataPacket(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void PlatformViewGLFW::OnCursorPosChanged(double x, double y) {
|
||||
blink::PointerData pointer_data;
|
||||
pointer_data.Clear();
|
||||
pointer_data.time_stamp =
|
||||
ftl::TimePoint::Now().ToEpochDelta().ToMicroseconds();
|
||||
pointer_data.change = blink::PointerData::Change::kMove;
|
||||
pointer_data.kind = blink::PointerData::DeviceKind::kMouse;
|
||||
pointer_data.physical_x = x;
|
||||
pointer_data.physical_y = y;
|
||||
pointer_data.buttons = buttons_;
|
||||
pointer_data.pressure = 1.0;
|
||||
pointer_data.pressure_max = 1.0;
|
||||
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine().GetWeakPtr(), pointer_data ] {
|
||||
if (engine.get()) {
|
||||
blink::PointerDataPacket packet(1);
|
||||
packet.SetPointerData(0, pointer_data);
|
||||
engine->DispatchPointerDataPacket(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void PlatformViewGLFW::OnKeyEvent(int key, int scancode, int action, int mods) {
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
@@ -1,57 +0,0 @@
|
||||
// Copyright 2016 The Chromium 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 SHELL_PLATFORM_GLFW_PLATFORM_VIEW_GLFW_H_
|
||||
#define SHELL_PLATFORM_GLFW_PLATFORM_VIEW_GLFW_H_
|
||||
|
||||
#include <string>
|
||||
#include "flutter/shell/common/platform_view.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_gl.h"
|
||||
#include "lib/ftl/memory/weak_ptr.h"
|
||||
|
||||
struct GLFWwindow;
|
||||
|
||||
namespace shell {
|
||||
|
||||
class PlatformViewGLFW : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
public:
|
||||
PlatformViewGLFW();
|
||||
|
||||
~PlatformViewGLFW() override;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool ResourceContextMakeCurrent() override;
|
||||
|
||||
bool GLContextMakeCurrent() override;
|
||||
|
||||
bool GLContextClearCurrent() override;
|
||||
|
||||
bool GLContextPresent() override;
|
||||
|
||||
intptr_t GLContextFBO() const override;
|
||||
|
||||
void RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) override;
|
||||
|
||||
private:
|
||||
bool valid_;
|
||||
GLFWwindow* glfw_window_;
|
||||
int buttons_;
|
||||
|
||||
void OnWindowSizeChanged(int width, int height);
|
||||
|
||||
void OnMouseButtonChanged(int button, int action, int mods);
|
||||
|
||||
void OnCursorPosChanged(double x, double y);
|
||||
|
||||
void OnKeyEvent(int key, int scancode, int action, int mods);
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewGLFW);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
|
||||
#endif // SHELL_PLATFORM_GLFW_PLATFORM_VIEW_GLFW_H_
|
||||
Reference in New Issue
Block a user