提交 9878b588 编写于 作者: A Adam Barth 提交者: GitHub

Get spinning square working on Fuchsia (#2926)

After this patch, we're able to run spinning_square on Fuchsia. I've
left some TODO comments about some shortcuts I've taken that we'll need
to improve in the future.
上级 2c5a71e7
......@@ -12,6 +12,7 @@ group("flutter") {
"//flutter/flow",
"//flutter/runtime",
"//flutter/snapshotter",
"//flutter/snapshotter($host_toolchain)",
]
} else {
deps = [
......
......@@ -9,6 +9,7 @@
#include "apps/dart_content_handler/zip/unzipper.h"
#include "flutter/content_handler/runtime_holder.h"
#include "lib/ftl/logging.h"
#include "lib/mtl/data_pipe/vector.h"
#include "mojo/public/cpp/application/connect.h"
namespace flutter_content_handler {
......@@ -27,11 +28,20 @@ ApplicationImpl::ApplicationImpl(
mojo::InterfaceRequest<mojo::Application> application,
mojo::URLResponsePtr response)
: binding_(this, std::move(application)) {
drainer_.reset(new glue::DrainDataPipeJob(
std::move(response->body), [this](std::vector<char> bundle) {
snapshot_ = ExtractSnapshot(std::move(bundle));
StartRuntimeIfReady();
}));
// TODO(abarth): Currently we block the UI thread to drain the response body,
// but we should do that work asynchronously instead. However, there when I
// tried draining the data pipe asynchronously, the drain didn't complete.
// We'll need to investigate why in more detail.
std::vector<char> bundle;
bool result = mtl::BlockingCopyToVector(std::move(response->body), &bundle);
if (!result) {
FTL_LOG(ERROR) << "Failed to receive bundle.";
return;
}
snapshot_ = ExtractSnapshot(std::move(bundle));
// TODO(abarth): In principle, we should call StartRuntimeIfReady() here but
// because we're draining the data pipe synchronously, we know that we can't
// possibly be ready yet because we haven't received the Initialize() message.
}
ApplicationImpl::~ApplicationImpl() {}
......
......@@ -28,26 +28,19 @@ class App : public mojo::ApplicationImplBase {
public:
App() {}
~App() override {
io_thread_.join();
ui_thread_.join();
gpu_thread_.join();
}
~App() override {}
// Overridden from ApplicationDelegate:
void OnInitialize() override {
ftl::RefPtr<ftl::TaskRunner> gpu_task_runner;
gpu_thread_ = mtl::CreateThread(&gpu_task_runner);
ftl::RefPtr<ftl::TaskRunner> ui_task_runner(
mtl::MessageLoop::GetCurrent()->task_runner());
ftl::RefPtr<ftl::TaskRunner> io_task_runner;
io_thread_ = mtl::CreateThread(&io_task_runner);
blink::Threads::Set(blink::Threads(std::move(gpu_task_runner),
std::move(ui_task_runner),
std::move(io_task_runner)));
// TODO(abarth): Currently we're using one thread for everything, but we
// should use separate threads for GPU, UI, and IO tasks. However, there
// appears to be some issue with running multiple message loops at the same
// time, potentially related to TLS.
blink::Threads::Set(
blink::Threads(ui_task_runner, ui_task_runner, ui_task_runner));
blink::Settings::Set(blink::Settings());
blink::InitDartVM();
}
......@@ -63,10 +56,6 @@ class App : public mojo::ApplicationImplBase {
}
private:
std::thread gpu_thread_;
std::thread ui_thread_;
std::thread io_thread_;
FTL_DISALLOW_COPY_AND_ASSIGN(App);
};
......
......@@ -25,7 +25,8 @@ constexpr ftl::TimeDelta kTargetFrameInterval =
} // namespace
RuntimeHolder::RuntimeHolder() : weak_factory_(this) {}
RuntimeHolder::RuntimeHolder()
: viewport_metrics_(sky::ViewportMetrics::New()), weak_factory_(this) {}
RuntimeHolder::~RuntimeHolder() {
blink::Threads::Gpu()->PostTask(
......@@ -45,12 +46,13 @@ void RuntimeHolder::Init(mojo::ApplicationConnectorPtr connector) {
if (self)
self->DidCreateFramebuffer(std::move(framebuffer), std::move(info));
}));
runtime_ = blink::RuntimeController::Create(this);
}
void RuntimeHolder::Run(const std::string& script_uri,
std::vector<char> snapshot) {
runtime_ = blink::RuntimeController::Create(this);
runtime_->CreateDartController(script_uri);
runtime_->SetViewportMetrics(viewport_metrics_);
runtime_->dart_controller()->RunFromSnapshot(
reinterpret_cast<const uint8_t*>(snapshot.data()), snapshot.size());
}
......@@ -90,10 +92,10 @@ void RuntimeHolder::Render(std::unique_ptr<flow::LayerTree> layer_tree) {
void RuntimeHolder::DidCreateFramebuffer(
mojo::InterfaceHandle<mojo::Framebuffer> framebuffer,
mojo::FramebufferInfoPtr info) {
auto viewport_metrics = sky::ViewportMetrics::New();
viewport_metrics->physical_width = info->size->width;
viewport_metrics->physical_height = info->size->height;
runtime_->SetViewportMetrics(viewport_metrics);
viewport_metrics_->physical_width = info->size->width;
viewport_metrics_->physical_height = info->size->height;
if (runtime_)
runtime_->SetViewportMetrics(viewport_metrics_);
blink::Threads::Gpu()->PostTask(ftl::MakeCopyable([
rasterizer = rasterizer_.get(), framebuffer = std::move(framebuffer),
......
......@@ -8,6 +8,7 @@
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/runtime/runtime_controller.h"
#include "flutter/runtime/runtime_delegate.h"
#include "flutter/services/engine/sky_engine.mojom.h"
#include "lib/ftl/functional/closure.h"
#include "lib/ftl/macros.h"
#include "lib/ftl/memory/weak_ptr.h"
......@@ -43,6 +44,7 @@ class RuntimeHolder : public blink::RuntimeDelegate {
mojo::FramebufferProviderPtr framebuffer_provider_;
std::unique_ptr<Rasterizer> rasterizer_;
std::unique_ptr<blink::RuntimeController> runtime_;
sky::ViewportMetricsPtr viewport_metrics_;
bool runtime_requested_frame_ = false;
bool did_defer_frame_request_ = false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册