Remove last mojom interface (flutter/engine#3184)
We no longer use mojom to transport messages. We still use the Mojo EDK to spin the event loop, however.
This commit is contained in:
@@ -6,27 +6,15 @@ source_set("assets") {
|
||||
sources = [
|
||||
"directory_asset_bundle.cc",
|
||||
"directory_asset_bundle.h",
|
||||
"unzip_job.cc",
|
||||
"unzip_job.h",
|
||||
"unzipper_provider.cc",
|
||||
"unzipper_provider.h",
|
||||
"zip_asset_bundle.cc",
|
||||
"zip_asset_bundle.h",
|
||||
"zip_asset_store.cc",
|
||||
"zip_asset_store.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//flutter/glue",
|
||||
"//lib/ftl",
|
||||
"//lib/zip",
|
||||
"//mojo/public/cpp/bindings:callback",
|
||||
"//mojo/public/cpp/system",
|
||||
"//mojo/public/cpp/bindings:utility",
|
||||
"//third_party/zlib:minizip",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//mojo/services/asset_bundle/interfaces",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/glue/data_pipe_utils.h"
|
||||
#include "lib/ftl/files/eintr_wrapper.h"
|
||||
#include "lib/ftl/files/file.h"
|
||||
#include "lib/ftl/files/path.h"
|
||||
@@ -17,24 +16,6 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
void DirectoryAssetBundle::GetAsStream(
|
||||
const mojo::String& asset_name,
|
||||
const mojo::Callback<void(mojo::ScopedDataPipeConsumerHandle)>& callback) {
|
||||
mojo::DataPipe pipe;
|
||||
callback.Run(std::move(pipe.consumer_handle));
|
||||
|
||||
std::string asset_path = GetPathForAsset(asset_name.get());
|
||||
if (asset_path.empty())
|
||||
return;
|
||||
|
||||
// TODO(abarth): Consider moving the |open| call to task_runner_.
|
||||
ftl::UniqueFD fd(HANDLE_EINTR(open(asset_path.c_str(), O_RDONLY)));
|
||||
if (fd.get() < 0)
|
||||
return;
|
||||
glue::CopyFromFileDescriptor(std::move(fd), std::move(pipe.producer_handle),
|
||||
task_runner_, [](bool ignored) {});
|
||||
}
|
||||
|
||||
bool DirectoryAssetBundle::GetAsBuffer(const std::string& asset_name,
|
||||
std::vector<uint8_t>* data) {
|
||||
std::string asset_path = GetPathForAsset(asset_name);
|
||||
@@ -45,13 +26,8 @@ bool DirectoryAssetBundle::GetAsBuffer(const std::string& asset_name,
|
||||
|
||||
DirectoryAssetBundle::~DirectoryAssetBundle() {}
|
||||
|
||||
DirectoryAssetBundle::DirectoryAssetBundle(
|
||||
mojo::InterfaceRequest<AssetBundle> request,
|
||||
std::string directory,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner)
|
||||
: binding_(this, std::move(request)),
|
||||
directory_(std::move(directory)),
|
||||
task_runner_(std::move(task_runner)) {}
|
||||
DirectoryAssetBundle::DirectoryAssetBundle(std::string directory)
|
||||
: directory_(std::move(directory)) {}
|
||||
|
||||
std::string DirectoryAssetBundle::GetPathForAsset(
|
||||
const std::string& asset_name) {
|
||||
|
||||
@@ -5,37 +5,24 @@
|
||||
#ifndef FLUTTER_ASSETS_DIRECTORY_ASSET_BUNDLE_H_
|
||||
#define FLUTTER_ASSETS_DIRECTORY_ASSET_BUNDLE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "lib/ftl/tasks/task_runner.h"
|
||||
#include "mojo/public/cpp/bindings/binding.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "mojo/public/cpp/environment/async_waiter.h"
|
||||
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
// A mojo service that serves assets out of a directory.
|
||||
class DirectoryAssetBundle : public mojo::asset_bundle::AssetBundle {
|
||||
class DirectoryAssetBundle {
|
||||
public:
|
||||
DirectoryAssetBundle(mojo::InterfaceRequest<AssetBundle> request,
|
||||
std::string directory,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner);
|
||||
~DirectoryAssetBundle() override;
|
||||
|
||||
// mojo::assert_bundle::AssetBundle implementation:
|
||||
void GetAsStream(
|
||||
const mojo::String& asset_name,
|
||||
const mojo::Callback<void(mojo::ScopedDataPipeConsumerHandle)>& callback)
|
||||
override;
|
||||
explicit DirectoryAssetBundle(std::string directory);
|
||||
~DirectoryAssetBundle();
|
||||
|
||||
bool GetAsBuffer(const std::string& asset_name, std::vector<uint8_t>* data);
|
||||
|
||||
private:
|
||||
std::string GetPathForAsset(const std::string& asset_name);
|
||||
|
||||
mojo::Binding<mojo::asset_bundle::AssetBundle> binding_;
|
||||
const std::string directory_;
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(DirectoryAssetBundle);
|
||||
};
|
||||
|
||||
@@ -1,90 +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/assets/unzip_job.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "mojo/public/cpp/environment/environment.h"
|
||||
#include "third_party/zlib/contrib/minizip/unzip.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
UnzipJob::UnzipJob(zip::UniqueUnzipper unzipper,
|
||||
std::string asset_name,
|
||||
mojo::ScopedDataPipeProducerHandle producer,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner)
|
||||
: unzipper_(std::move(unzipper)),
|
||||
asset_name_(std::move(asset_name)),
|
||||
producer_(std::move(producer)),
|
||||
task_runner_(std::move(task_runner)),
|
||||
waiter_(mojo::Environment::GetDefaultAsyncWaiter()),
|
||||
wait_id_(0) {
|
||||
FTL_DCHECK(unzipper_.is_valid());
|
||||
task_runner_->PostTask([this]() { Start(); });
|
||||
}
|
||||
|
||||
UnzipJob::~UnzipJob() {}
|
||||
|
||||
void UnzipJob::Start() {
|
||||
int result = unzLocateFile(unzipper_.get(), asset_name_.c_str(), 0);
|
||||
if (result != UNZ_OK) {
|
||||
FTL_LOG(WARNING) << "Requested asset '" << asset_name_
|
||||
<< "' does not exist.";
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
|
||||
result = unzOpenCurrentFile(unzipper_.get());
|
||||
if (result != UNZ_OK) {
|
||||
FTL_LOG(WARNING) << "unzOpenCurrentFile failed, error=" << result;
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
|
||||
OnHandleReady(MOJO_RESULT_OK);
|
||||
}
|
||||
|
||||
void UnzipJob::OnHandleReady(MojoResult result) {
|
||||
if (result == MOJO_RESULT_OK) {
|
||||
void* buffer = nullptr;
|
||||
uint32_t size = 0;
|
||||
result = mojo::BeginWriteDataRaw(producer_.get(), &buffer, &size,
|
||||
MOJO_WRITE_DATA_FLAG_NONE);
|
||||
if (result == MOJO_RESULT_OK) {
|
||||
FTL_DCHECK(size < static_cast<uint32_t>(std::numeric_limits<int>::max()));
|
||||
ssize_t bytes_read = unzReadCurrentFile(unzipper_.get(), buffer, size);
|
||||
result = mojo::EndWriteDataRaw(producer_.get(),
|
||||
std::max<ssize_t>(0l, bytes_read));
|
||||
if (bytes_read < 0) {
|
||||
FTL_LOG(WARNING) << "Asset unzip failed, error=" << bytes_read;
|
||||
delete this;
|
||||
} else if (result != MOJO_RESULT_OK) {
|
||||
FTL_LOG(WARNING) << "Mojo EndWrite failed, error=" << result;
|
||||
delete this;
|
||||
} else if (bytes_read < size) {
|
||||
// Reached EOF. Stop the process.
|
||||
delete this;
|
||||
} else {
|
||||
task_runner_->PostTask([this]() { OnHandleReady(MOJO_RESULT_OK); });
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (result == MOJO_RESULT_SHOULD_WAIT) {
|
||||
wait_id_ =
|
||||
waiter_->AsyncWait(producer_.get().value(), MOJO_HANDLE_SIGNAL_WRITABLE,
|
||||
MOJO_DEADLINE_INDEFINITE, &WaitComplete, this);
|
||||
return;
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
void UnzipJob::WaitComplete(void* context, MojoResult result) {
|
||||
UnzipJob* job = static_cast<UnzipJob*>(context);
|
||||
job->wait_id_ = 0;
|
||||
job->OnHandleReady(result);
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
@@ -1,46 +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 FLUTTER_ASSETS_UNZIP_JOB_H_
|
||||
#define FLUTTER_ASSETS_UNZIP_JOB_H_
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "lib/ftl/memory/ref_counted.h"
|
||||
#include "lib/ftl/tasks/task_runner.h"
|
||||
#include "lib/zip/unique_unzipper.h"
|
||||
#include "mojo/public/cpp/environment/async_waiter.h"
|
||||
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class UnzipJob {
|
||||
public:
|
||||
UnzipJob(zip::UniqueUnzipper unzipper,
|
||||
std::string asset_name,
|
||||
mojo::ScopedDataPipeProducerHandle producer,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner);
|
||||
~UnzipJob();
|
||||
|
||||
private:
|
||||
void Start();
|
||||
void OnHandleReady(MojoResult result);
|
||||
static void WaitComplete(void* context, MojoResult result);
|
||||
|
||||
zip::UniqueUnzipper unzipper_;
|
||||
const std::string asset_name_;
|
||||
mojo::ScopedDataPipeProducerHandle producer_;
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner_;
|
||||
|
||||
const MojoAsyncWaiter* waiter_;
|
||||
MojoAsyncWaitID wait_id_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(UnzipJob);
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // FLUTTER_ASSETS_UNZIP_JOB_H_
|
||||
@@ -1,26 +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/assets/zip_asset_bundle.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace blink {
|
||||
|
||||
void ZipAssetBundle::GetAsStream(
|
||||
const mojo::String& asset_name,
|
||||
const mojo::Callback<void(mojo::ScopedDataPipeConsumerHandle)>& callback) {
|
||||
mojo::DataPipe pipe;
|
||||
callback.Run(std::move(pipe.consumer_handle));
|
||||
store_->GetAsStream(asset_name.get(), std::move(pipe.producer_handle));
|
||||
}
|
||||
|
||||
ZipAssetBundle::ZipAssetBundle(
|
||||
mojo::InterfaceRequest<mojo::asset_bundle::AssetBundle> request,
|
||||
ftl::RefPtr<ZipAssetStore> store)
|
||||
: binding_(this, std::move(request)), store_(std::move(store)) {}
|
||||
|
||||
ZipAssetBundle::~ZipAssetBundle() {}
|
||||
|
||||
} // namespace blink
|
||||
@@ -1,35 +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 FLUTTER_ASSETS_ZIP_ASSET_BUNDLE_H_
|
||||
#define FLUTTER_ASSETS_ZIP_ASSET_BUNDLE_H_
|
||||
|
||||
#include "flutter/assets/zip_asset_store.h"
|
||||
#include "mojo/public/cpp/bindings/binding.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class ZipAssetBundle : public mojo::asset_bundle::AssetBundle {
|
||||
public:
|
||||
ZipAssetBundle(
|
||||
mojo::InterfaceRequest<mojo::asset_bundle::AssetBundle> request,
|
||||
ftl::RefPtr<ZipAssetStore> store);
|
||||
~ZipAssetBundle() override;
|
||||
|
||||
// mojo::assert_bundle::AssetBundle implementation:
|
||||
void GetAsStream(
|
||||
const mojo::String& asset_name,
|
||||
const mojo::Callback<void(mojo::ScopedDataPipeConsumerHandle)>& callback)
|
||||
override;
|
||||
|
||||
private:
|
||||
mojo::Binding<mojo::asset_bundle::AssetBundle> binding_;
|
||||
ftl::RefPtr<ZipAssetStore> store_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
||||
#endif // FLUTTER_ASSETS_ZIP_ASSET_BUNDLE_H_
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/assets/unzip_job.h"
|
||||
#include "flutter/glue/data_pipe_utils.h"
|
||||
#include "lib/ftl/files/eintr_wrapper.h"
|
||||
#include "lib/ftl/files/unique_fd.h"
|
||||
#include "lib/zip/unique_unzipper.h"
|
||||
@@ -18,37 +16,11 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
ZipAssetStore::ZipAssetStore(UnzipperProvider unzipper_provider,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner)
|
||||
: unzipper_provider_(std::move(unzipper_provider)),
|
||||
task_runner_(std::move(task_runner)) {}
|
||||
ZipAssetStore::ZipAssetStore(UnzipperProvider unzipper_provider)
|
||||
: unzipper_provider_(std::move(unzipper_provider)) {}
|
||||
|
||||
ZipAssetStore::~ZipAssetStore() {}
|
||||
|
||||
void ZipAssetStore::AddOverlayFile(std::string asset_name,
|
||||
std::string file_path) {
|
||||
overlay_files_.emplace(std::move(asset_name), std::move(file_path));
|
||||
}
|
||||
|
||||
void ZipAssetStore::GetAsStream(const std::string& asset_name,
|
||||
mojo::ScopedDataPipeProducerHandle producer) {
|
||||
auto overlay = overlay_files_.find(asset_name);
|
||||
if (overlay != overlay_files_.end()) {
|
||||
// TODO(abarth): Consider moving the |open| call to task_runner_.
|
||||
ftl::UniqueFD fd(HANDLE_EINTR(open(overlay->second.c_str(), O_RDONLY)));
|
||||
if (fd.get() < 0)
|
||||
return;
|
||||
glue::CopyFromFileDescriptor(std::move(fd), std::move(producer),
|
||||
task_runner_, [](bool ignored) {});
|
||||
} else {
|
||||
zip::UniqueUnzipper unzipper = unzipper_provider_();
|
||||
if (!unzipper.is_valid())
|
||||
return;
|
||||
new UnzipJob(std::move(unzipper), asset_name, std::move(producer),
|
||||
task_runner_);
|
||||
}
|
||||
}
|
||||
|
||||
bool ZipAssetStore::GetAsBuffer(const std::string& asset_name,
|
||||
std::vector<uint8_t>* data) {
|
||||
zip::UniqueUnzipper unzipper = unzipper_provider_();
|
||||
|
||||
@@ -11,28 +11,18 @@
|
||||
#include "flutter/assets/unzipper_provider.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "lib/ftl/memory/ref_counted.h"
|
||||
#include "lib/ftl/tasks/task_runner.h"
|
||||
#include "mojo/public/cpp/system/data_pipe.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
class ZipAssetStore : public ftl::RefCountedThreadSafe<ZipAssetStore> {
|
||||
public:
|
||||
ZipAssetStore(UnzipperProvider unzipper_provider,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner);
|
||||
explicit ZipAssetStore(UnzipperProvider unzipper_provider);
|
||||
~ZipAssetStore();
|
||||
|
||||
// Serve this asset from another file instead of using the ZIP contents.
|
||||
void AddOverlayFile(std::string asset_name, std::string file_path);
|
||||
|
||||
void GetAsStream(const std::string& asset_name,
|
||||
mojo::ScopedDataPipeProducerHandle producer);
|
||||
bool GetAsBuffer(const std::string& asset_name, std::vector<uint8_t>* data);
|
||||
|
||||
private:
|
||||
UnzipperProvider unzipper_provider_;
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner_;
|
||||
std::map<std::string, std::string> overlay_files_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(ZipAssetStore);
|
||||
};
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
|
||||
source_set("glue") {
|
||||
sources = [
|
||||
"data_pipe_utils.cc",
|
||||
"data_pipe_utils.h",
|
||||
"drain_data_pipe_job.h",
|
||||
"movable_wrapper.h",
|
||||
"stack_trace.h",
|
||||
"thread.h",
|
||||
@@ -21,6 +18,7 @@ source_set("glue") {
|
||||
|
||||
if (is_fuchsia) {
|
||||
sources += [
|
||||
"drain_data_pipe_job.h",
|
||||
"drain_data_pipe_job_fuchsia.cc",
|
||||
"stack_trace_fuchsia.cc",
|
||||
"thread_fuchsia.cc",
|
||||
@@ -35,7 +33,6 @@ source_set("glue") {
|
||||
]
|
||||
} else {
|
||||
sources += [
|
||||
"drain_data_pipe_job_base.cc",
|
||||
"stack_trace_base.cc",
|
||||
"task_runner_adaptor.cc",
|
||||
"task_runner_adaptor.h",
|
||||
@@ -44,7 +41,6 @@ source_set("glue") {
|
||||
|
||||
deps += [
|
||||
"//base",
|
||||
"//mojo/data_pipe_utils",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
// Copyright 2016 The Fuchsia 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/glue/data_pipe_utils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
#include "lib/ftl/files/file_descriptor.h"
|
||||
#include "mojo/public/cpp/environment/async_waiter.h"
|
||||
#include "mojo/public/cpp/environment/environment.h"
|
||||
|
||||
namespace glue {
|
||||
namespace {
|
||||
|
||||
// CopyToFileHandler -----------------------------------------------------------
|
||||
|
||||
class CopyToFileHandler {
|
||||
public:
|
||||
CopyToFileHandler(mojo::ScopedDataPipeConsumerHandle source,
|
||||
ftl::UniqueFD destination,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner,
|
||||
const std::function<void(bool)>& callback);
|
||||
|
||||
private:
|
||||
~CopyToFileHandler();
|
||||
|
||||
void SendCallback(bool value);
|
||||
void OnHandleReady(MojoResult result);
|
||||
static void WaitComplete(void* context, MojoResult result);
|
||||
|
||||
mojo::ScopedDataPipeConsumerHandle source_;
|
||||
ftl::UniqueFD destination_;
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner_;
|
||||
std::function<void(bool)> callback_;
|
||||
const MojoAsyncWaiter* waiter_;
|
||||
MojoAsyncWaitID wait_id_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(CopyToFileHandler);
|
||||
};
|
||||
|
||||
CopyToFileHandler::CopyToFileHandler(mojo::ScopedDataPipeConsumerHandle source,
|
||||
ftl::UniqueFD destination,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner,
|
||||
const std::function<void(bool)>& callback)
|
||||
: source_(std::move(source)),
|
||||
destination_(std::move(destination)),
|
||||
task_runner_(std::move(task_runner)),
|
||||
callback_(callback),
|
||||
waiter_(mojo::Environment::GetDefaultAsyncWaiter()),
|
||||
wait_id_(0) {
|
||||
task_runner_->PostTask([this]() { OnHandleReady(MOJO_RESULT_OK); });
|
||||
}
|
||||
|
||||
CopyToFileHandler::~CopyToFileHandler() {}
|
||||
|
||||
void CopyToFileHandler::SendCallback(bool value) {
|
||||
FTL_DCHECK(!wait_id_);
|
||||
auto callback = callback_;
|
||||
delete this;
|
||||
callback(value);
|
||||
}
|
||||
|
||||
void CopyToFileHandler::OnHandleReady(MojoResult result) {
|
||||
if (result == MOJO_RESULT_OK) {
|
||||
const void* buffer = nullptr;
|
||||
uint32_t size = 0;
|
||||
result = BeginReadDataRaw(source_.get(), &buffer, &size,
|
||||
MOJO_READ_DATA_FLAG_NONE);
|
||||
if (result == MOJO_RESULT_OK) {
|
||||
bool write_success = ftl::WriteFileDescriptor(
|
||||
destination_.get(), static_cast<const char*>(buffer), size);
|
||||
result = EndReadDataRaw(source_.get(), size);
|
||||
if (!write_success || result != MOJO_RESULT_OK) {
|
||||
SendCallback(false);
|
||||
} else {
|
||||
task_runner_->PostTask([this]() { OnHandleReady(MOJO_RESULT_OK); });
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (result == MOJO_RESULT_FAILED_PRECONDITION) {
|
||||
SendCallback(true);
|
||||
return;
|
||||
}
|
||||
if (result == MOJO_RESULT_SHOULD_WAIT) {
|
||||
wait_id_ =
|
||||
waiter_->AsyncWait(source_.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
|
||||
MOJO_DEADLINE_INDEFINITE, &WaitComplete, this);
|
||||
return;
|
||||
}
|
||||
SendCallback(false);
|
||||
}
|
||||
|
||||
void CopyToFileHandler::WaitComplete(void* context, MojoResult result) {
|
||||
CopyToFileHandler* handler = static_cast<CopyToFileHandler*>(context);
|
||||
handler->wait_id_ = 0;
|
||||
handler->OnHandleReady(result);
|
||||
}
|
||||
|
||||
// CopyFromFileHandler ---------------------------------------------------------
|
||||
|
||||
class CopyFromFileHandler {
|
||||
public:
|
||||
CopyFromFileHandler(ftl::UniqueFD source,
|
||||
mojo::ScopedDataPipeProducerHandle destination,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner,
|
||||
const std::function<void(bool)>& callback);
|
||||
|
||||
private:
|
||||
~CopyFromFileHandler();
|
||||
|
||||
void SendCallback(bool value);
|
||||
void OnHandleReady(MojoResult result);
|
||||
static void WaitComplete(void* context, MojoResult result);
|
||||
|
||||
ftl::UniqueFD source_;
|
||||
mojo::ScopedDataPipeProducerHandle destination_;
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner_;
|
||||
std::function<void(bool)> callback_;
|
||||
const MojoAsyncWaiter* waiter_;
|
||||
MojoAsyncWaitID wait_id_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(CopyFromFileHandler);
|
||||
};
|
||||
|
||||
CopyFromFileHandler::CopyFromFileHandler(
|
||||
ftl::UniqueFD source,
|
||||
mojo::ScopedDataPipeProducerHandle destination,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner,
|
||||
const std::function<void(bool)>& callback)
|
||||
: source_(std::move(source)),
|
||||
destination_(std::move(destination)),
|
||||
task_runner_(std::move(task_runner)),
|
||||
callback_(callback),
|
||||
waiter_(mojo::Environment::GetDefaultAsyncWaiter()),
|
||||
wait_id_(0) {
|
||||
task_runner_->PostTask([this]() { OnHandleReady(MOJO_RESULT_OK); });
|
||||
}
|
||||
|
||||
CopyFromFileHandler::~CopyFromFileHandler() {}
|
||||
|
||||
void CopyFromFileHandler::SendCallback(bool value) {
|
||||
FTL_DCHECK(!wait_id_);
|
||||
auto callback = callback_;
|
||||
delete this;
|
||||
callback(value);
|
||||
}
|
||||
|
||||
void CopyFromFileHandler::OnHandleReady(MojoResult result) {
|
||||
if (result == MOJO_RESULT_OK) {
|
||||
void* buffer = nullptr;
|
||||
uint32_t size = 0;
|
||||
result = BeginWriteDataRaw(destination_.get(), &buffer, &size,
|
||||
MOJO_WRITE_DATA_FLAG_NONE);
|
||||
if (result == MOJO_RESULT_OK) {
|
||||
FTL_DCHECK(size < static_cast<uint32_t>(std::numeric_limits<int>::max()));
|
||||
ssize_t bytes_read = ftl::ReadFileDescriptor(
|
||||
source_.get(), static_cast<char*>(buffer), size);
|
||||
result = EndWriteDataRaw(destination_.get(),
|
||||
std::max<ssize_t>(0l, bytes_read));
|
||||
if (bytes_read == -1 || result != MOJO_RESULT_OK) {
|
||||
SendCallback(false);
|
||||
} else if (bytes_read < size) {
|
||||
// Reached EOF. Stop the process.
|
||||
SendCallback(true);
|
||||
} else {
|
||||
task_runner_->PostTask([this]() { OnHandleReady(MOJO_RESULT_OK); });
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (result == MOJO_RESULT_SHOULD_WAIT) {
|
||||
wait_id_ = waiter_->AsyncWait(
|
||||
destination_.get().value(), MOJO_HANDLE_SIGNAL_WRITABLE,
|
||||
MOJO_DEADLINE_INDEFINITE, &WaitComplete, this);
|
||||
return;
|
||||
}
|
||||
SendCallback(false);
|
||||
}
|
||||
|
||||
void CopyFromFileHandler::WaitComplete(void* context, MojoResult result) {
|
||||
CopyFromFileHandler* handler = static_cast<CopyFromFileHandler*>(context);
|
||||
handler->wait_id_ = 0;
|
||||
handler->OnHandleReady(result);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void CopyToFileDescriptor(mojo::ScopedDataPipeConsumerHandle source,
|
||||
ftl::UniqueFD destination,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner,
|
||||
const std::function<void(bool)>& callback) {
|
||||
new CopyToFileHandler(std::move(source), std::move(destination),
|
||||
std::move(task_runner), callback);
|
||||
}
|
||||
|
||||
void CopyFromFileDescriptor(ftl::UniqueFD source,
|
||||
mojo::ScopedDataPipeProducerHandle destination,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner,
|
||||
const std::function<void(bool)>& callback) {
|
||||
new CopyFromFileHandler(std::move(source), std::move(destination),
|
||||
std::move(task_runner), callback);
|
||||
}
|
||||
|
||||
} // namespace glue
|
||||
@@ -1,38 +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 FLUTTER_GLU_DATA_PIPE_FILES_H_
|
||||
#define FLUTTER_GLU_DATA_PIPE_FILES_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "lib/ftl/files/unique_fd.h"
|
||||
#include "lib/ftl/tasks/task_runner.h"
|
||||
#include "mojo/public/cpp/system/data_pipe.h"
|
||||
|
||||
namespace glue {
|
||||
|
||||
// Asynchronously copies data from source to the destination file descriptor.
|
||||
// The given |callback| is run upon completion. File writes and |callback| will
|
||||
// be scheduled on the given |task_runner|.
|
||||
void CopyToFileDescriptor(
|
||||
mojo::ScopedDataPipeConsumerHandle source,
|
||||
ftl::UniqueFD destination,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner,
|
||||
const std::function<void(bool /*success*/)>& callback);
|
||||
|
||||
// Asynchronously copies data from source file to the destination. The given
|
||||
// |callback| is run upon completion. File reads and |callback| will be
|
||||
// scheduled to the given |task_runner|.
|
||||
void CopyFromFileDescriptor(
|
||||
ftl::UniqueFD source,
|
||||
mojo::ScopedDataPipeProducerHandle destination,
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner,
|
||||
const std::function<void(bool /*success*/)>& callback);
|
||||
|
||||
} // namespace glue
|
||||
|
||||
#endif // FLUTTER_GLU_DATA_PIPE_FILES_H_
|
||||
@@ -1,43 +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/glue/drain_data_pipe_job.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "mojo/data_pipe_utils/data_pipe_drainer.h"
|
||||
|
||||
using mojo::common::DataPipeDrainer;
|
||||
|
||||
namespace glue {
|
||||
|
||||
class DrainDataPipeJob::JobImpl : public DataPipeDrainer::Client {
|
||||
public:
|
||||
explicit JobImpl(mojo::ScopedDataPipeConsumerHandle handle,
|
||||
const ResultCallback& callback)
|
||||
: callback_(callback), drainer_(this, std::move(handle)) {}
|
||||
|
||||
private:
|
||||
// mojo::common::DataPipeDrainer::Client
|
||||
void OnDataAvailable(const void* data, size_t num_bytes) override {
|
||||
const uint8_t* bytes = static_cast<const uint8_t*>(data);
|
||||
buffer_.insert(buffer_.end(), bytes, bytes + num_bytes);
|
||||
}
|
||||
|
||||
void OnDataComplete() override { callback_(std::move(buffer_)); }
|
||||
|
||||
std::vector<uint8_t> buffer_;
|
||||
ResultCallback callback_;
|
||||
DataPipeDrainer drainer_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(JobImpl);
|
||||
};
|
||||
|
||||
DrainDataPipeJob::DrainDataPipeJob(mojo::ScopedDataPipeConsumerHandle handle,
|
||||
const ResultCallback& callback)
|
||||
: impl_(new JobImpl(std::move(handle), callback)) {}
|
||||
|
||||
DrainDataPipeJob::~DrainDataPipeJob() {}
|
||||
|
||||
} // namespace glue
|
||||
@@ -12,6 +12,7 @@ source_set("mojo") {
|
||||
"//dart/runtime:libdart",
|
||||
"//lib/ftl",
|
||||
"//lib/tonic",
|
||||
"//mojo/public/cpp/environment:standalone",
|
||||
"//mojo/public/cpp/system",
|
||||
"//mojo/public/platform/dart:mojo_internal_impl",
|
||||
]
|
||||
|
||||
@@ -76,7 +76,6 @@ source_set("ui") {
|
||||
"//flutter/common",
|
||||
"//flutter/flow",
|
||||
"//flutter/glue",
|
||||
"//flutter/services/engine:interfaces",
|
||||
"//flutter/skia",
|
||||
"//flutter/sky/engine",
|
||||
"//lib/tonic",
|
||||
|
||||
@@ -27,9 +27,6 @@ typedef void PlatformMessageCallback(String name, ByteData data, PlatformMessage
|
||||
|
||||
/// States that an application can be in.
|
||||
enum AppLifecycleState {
|
||||
// These values must match the order of the values of
|
||||
// AppLifecycleState in sky_engine.mojom
|
||||
|
||||
/// The application is not currently visible to the user. When the
|
||||
/// application is in this state, the engine will not call the
|
||||
/// [onBeginFrame] callback.
|
||||
|
||||
@@ -73,7 +73,6 @@ source_set("runtime") {
|
||||
"//flutter/lib/io",
|
||||
"//flutter/lib/mojo",
|
||||
"//flutter/lib/ui",
|
||||
"//flutter/services/engine:interfaces",
|
||||
"//flutter/skia",
|
||||
"//flutter/sky/engine/platform",
|
||||
"//lib/ftl",
|
||||
|
||||
@@ -136,8 +136,7 @@ RegisterNativeServiceProtocolExtensionHook
|
||||
void IsolateShutdownCallback(void* callback_data) {
|
||||
if (tonic::DartStickyError::IsSet()) {
|
||||
tonic::DartApiScope api_scope;
|
||||
FTL_LOG(ERROR) << "Isolate "
|
||||
<< tonic::StdStringFromDart(Dart_DebugName())
|
||||
FTL_LOG(ERROR) << "Isolate " << tonic::StdStringFromDart(Dart_DebugName())
|
||||
<< " exited with an error";
|
||||
Dart_Handle sticky_error = Dart_GetStickyError();
|
||||
FTL_CHECK(LogIfError(sticky_error));
|
||||
@@ -191,9 +190,8 @@ static bool StringEndsWith(const std::string& string,
|
||||
if (ending.size() > string.size())
|
||||
return false;
|
||||
|
||||
return string.compare(string.size() - ending.size(),
|
||||
ending.size(),
|
||||
ending) == 0;
|
||||
return string.compare(string.size() - ending.size(), ending.size(), ending) ==
|
||||
0;
|
||||
}
|
||||
|
||||
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_RELEASE
|
||||
@@ -210,8 +208,8 @@ Dart_Isolate ServiceIsolateCreateCallback(const char* script_uri,
|
||||
tonic::DartState* dart_state = new tonic::DartState();
|
||||
Dart_Isolate isolate = Dart_CreateIsolate(
|
||||
script_uri, "main",
|
||||
reinterpret_cast<const uint8_t*>(DART_SYMBOL(kIsolateSnapshot)),
|
||||
nullptr, dart_state, error);
|
||||
reinterpret_cast<const uint8_t*>(DART_SYMBOL(kIsolateSnapshot)), nullptr,
|
||||
dart_state, error);
|
||||
FTL_CHECK(isolate) << error;
|
||||
dart_state->SetIsolate(isolate);
|
||||
FTL_CHECK(Dart_IsServiceIsolate(isolate));
|
||||
@@ -277,8 +275,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
|
||||
const std::string& bundle_path = entry_path;
|
||||
ftl::RefPtr<ZipAssetStore> zip_asset_store =
|
||||
ftl::MakeRefCounted<ZipAssetStore>(
|
||||
GetUnzipperProviderForPath(std::move(bundle_path)),
|
||||
ftl::RefPtr<ftl::TaskRunner>());
|
||||
GetUnzipperProviderForPath(std::move(bundle_path)));
|
||||
zip_asset_store->GetAsBuffer(kSnapshotAssetKey, &snapshot_data);
|
||||
}
|
||||
|
||||
@@ -287,8 +284,8 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
|
||||
|
||||
Dart_Isolate isolate = Dart_CreateIsolate(
|
||||
script_uri, main,
|
||||
reinterpret_cast<uint8_t*>(DART_SYMBOL(kIsolateSnapshot)),
|
||||
nullptr, dart_state, error);
|
||||
reinterpret_cast<uint8_t*>(DART_SYMBOL(kIsolateSnapshot)), nullptr,
|
||||
dart_state, error);
|
||||
FTL_CHECK(isolate) << error;
|
||||
dart_state->SetIsolate(isolate);
|
||||
FTL_CHECK(!LogIfError(
|
||||
@@ -607,16 +604,17 @@ void InitDartVM() {
|
||||
}
|
||||
|
||||
#if defined(OS_FUCHSIA) && defined(NDEBUG)
|
||||
if (false) {
|
||||
// Do not enable checked mode for Fuchsia release builds
|
||||
// TODO(mikejurka): remove this once precompiled code is working on Fuchsia
|
||||
// Do not enable checked mode for Fuchsia release builds
|
||||
// TODO(mikejurka): remove this once precompiled code is working on Fuchsia
|
||||
const bool use_checked_mode = false;
|
||||
#else
|
||||
if (!IsRunningPrecompiledCode()) {
|
||||
// Enable checked mode if we are not running precompiled code. We run non-
|
||||
// precompiled code only in the debug product mode.
|
||||
// Enable checked mode if we are not running precompiled code. We run non-
|
||||
// precompiled code only in the debug product mode.
|
||||
const bool use_checked_mode = !IsRunningPrecompiledCode();
|
||||
#endif
|
||||
|
||||
if (use_checked_mode)
|
||||
PushBackAll(&args, kDartCheckedModeArgs, arraysize(kDartCheckedModeArgs));
|
||||
}
|
||||
|
||||
if (settings.start_paused)
|
||||
PushBackAll(&args, kDartStartPausedArgs, arraysize(kDartStartPausedArgs));
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "flutter/lib/ui/ui_dart_state.h"
|
||||
#include "flutter/lib/ui/window/pointer_data_packet.h"
|
||||
#include "flutter/lib/ui/window/window.h"
|
||||
#include "flutter/services/engine/sky_engine.mojom.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
@@ -57,17 +57,12 @@ source_set("common") {
|
||||
"//flutter/glue",
|
||||
"//flutter/lib/ui",
|
||||
"//flutter/runtime",
|
||||
"//flutter/services/engine:interfaces",
|
||||
"//flutter/skia",
|
||||
"//flutter/sky/engine/wtf",
|
||||
"//flutter/synchronization",
|
||||
"//lib/ftl",
|
||||
"//lib/tonic",
|
||||
"//mojo/application",
|
||||
"//mojo/message_pump",
|
||||
"//mojo/public/cpp/bindings:utility",
|
||||
"//mojo/public/interfaces/application",
|
||||
"//mojo/services/vsync/interfaces",
|
||||
"//third_party/libjpeg",
|
||||
"//third_party/rapidjson",
|
||||
":generate_embedder_diagnostic_server_resources_cc",
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "flutter/assets/directory_asset_bundle.h"
|
||||
#include "flutter/assets/unzipper_provider.h"
|
||||
#include "flutter/assets/zip_asset_bundle.h"
|
||||
#include "flutter/assets/zip_asset_store.h"
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/glue/movable_wrapper.h"
|
||||
#include "flutter/glue/trace_event.h"
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "lib/ftl/files/file.h"
|
||||
#include "lib/ftl/files/path.h"
|
||||
#include "lib/ftl/functional/make_copyable.h"
|
||||
#include "mojo/public/cpp/application/connect.h"
|
||||
#include "third_party/rapidjson/rapidjson/document.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkPictureRecorder.h"
|
||||
@@ -65,7 +64,6 @@ Engine::Engine(PlatformView* platform_view)
|
||||
platform_view->rasterizer().GetWeakRasterizerPtr(),
|
||||
platform_view->GetVsyncWaiter(),
|
||||
this)),
|
||||
binding_(this),
|
||||
activity_running_(false),
|
||||
have_surface_(false),
|
||||
weak_factory_(this) {}
|
||||
@@ -155,10 +153,6 @@ std::string Engine::GetUIIsolateName() {
|
||||
return runtime_->GetIsolateName();
|
||||
}
|
||||
|
||||
void Engine::ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request) {
|
||||
binding_.Bind(request.Pass());
|
||||
}
|
||||
|
||||
void Engine::OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation) {
|
||||
blink::Threads::Gpu()->PostTask(gpu_continuation);
|
||||
have_surface_ = true;
|
||||
@@ -280,7 +274,8 @@ void Engine::ConfigureAssetBundle(const std::string& path) {
|
||||
struct stat stat_result = {0};
|
||||
|
||||
directory_asset_bundle_.reset();
|
||||
zip_asset_bundle_.reset();
|
||||
// TODO(abarth): We should reset asset_store_ as well, but that might break
|
||||
// custom font loading in hot reload.
|
||||
|
||||
if (::stat(path.c_str(), &stat_result) != 0) {
|
||||
LOG(INFO) << "Could not configure asset bundle at path: " << path;
|
||||
@@ -288,24 +283,19 @@ void Engine::ConfigureAssetBundle(const std::string& path) {
|
||||
}
|
||||
|
||||
if (S_ISDIR(stat_result.st_mode)) {
|
||||
// Directory asset bundle.
|
||||
directory_asset_bundle_ = std::make_unique<blink::DirectoryAssetBundle>(
|
||||
mojo::GetProxy(&root_bundle_), path, blink::Threads::IO());
|
||||
directory_asset_bundle_ =
|
||||
std::make_unique<blink::DirectoryAssetBundle>(path);
|
||||
return;
|
||||
}
|
||||
|
||||
if (S_ISREG(stat_result.st_mode)) {
|
||||
// Zip asset bundle.
|
||||
asset_store_ = ftl::MakeRefCounted<blink::ZipAssetStore>(
|
||||
blink::GetUnzipperProviderForPath(path), blink::Threads::IO());
|
||||
zip_asset_bundle_ = std::make_unique<blink::ZipAssetBundle>(
|
||||
mojo::GetProxy(&root_bundle_), asset_store_);
|
||||
blink::GetUnzipperProviderForPath(path));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::ConfigureRuntime(const std::string& script_uri) {
|
||||
snapshot_drainer_.reset();
|
||||
runtime_ = blink::RuntimeController::Create(this);
|
||||
runtime_->CreateDartController(std::move(script_uri));
|
||||
runtime_->SetViewportMetrics(viewport_metrics_);
|
||||
@@ -315,27 +305,6 @@ void Engine::ConfigureRuntime(const std::string& script_uri) {
|
||||
runtime_->DispatchPlatformMessage(std::move(pending_push_route_message_));
|
||||
}
|
||||
|
||||
void Engine::RunFromPrecompiledSnapshot(const mojo::String& bundle_path) {
|
||||
RunBundle(bundle_path);
|
||||
}
|
||||
|
||||
void Engine::RunFromFile(const mojo::String& main,
|
||||
const mojo::String& packages,
|
||||
const mojo::String& bundle) {
|
||||
RunBundleAndSource(bundle, main, packages);
|
||||
}
|
||||
|
||||
void Engine::RunFromBundle(const mojo::String& script_uri,
|
||||
const mojo::String& bundle_path) {
|
||||
RunBundle(bundle_path);
|
||||
}
|
||||
|
||||
void Engine::RunFromBundleAndSnapshot(const mojo::String& script_uri,
|
||||
const mojo::String& bundle_path,
|
||||
const mojo::String& snapshot_path) {
|
||||
RunBundleAndSnapshot(bundle_path, snapshot_path);
|
||||
}
|
||||
|
||||
void Engine::DidCreateMainIsolate(Dart_Isolate isolate) {
|
||||
if (asset_store_)
|
||||
blink::AssetFontSelector::Install(asset_store_);
|
||||
|
||||
@@ -6,22 +6,13 @@
|
||||
#define SHELL_COMMON_ENGINE_H_
|
||||
|
||||
#include "flutter/assets/zip_asset_store.h"
|
||||
#include "flutter/glue/drain_data_pipe_job.h"
|
||||
#include "flutter/lib/ui/window/platform_message.h"
|
||||
#include "flutter/lib/ui/window/viewport_metrics.h"
|
||||
#include "flutter/runtime/runtime_controller.h"
|
||||
#include "flutter/runtime/runtime_delegate.h"
|
||||
#include "flutter/services/engine/sky_engine.mojom.h"
|
||||
#include "flutter/shell/common/rasterizer.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "lib/ftl/memory/weak_ptr.h"
|
||||
#include "mojo/public/cpp/application/service_provider_impl.h"
|
||||
#include "mojo/public/cpp/bindings/binding.h"
|
||||
#include "mojo/public/cpp/bindings/binding_set.h"
|
||||
#include "mojo/public/cpp/system/data_pipe.h"
|
||||
#include "mojo/public/cpp/system/handle.h"
|
||||
#include "mojo/public/interfaces/application/service_provider.mojom.h"
|
||||
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
|
||||
#include "third_party/skia/include/core/SkPicture.h"
|
||||
|
||||
namespace blink {
|
||||
@@ -34,7 +25,7 @@ class PlatformView;
|
||||
class Animator;
|
||||
using PointerDataPacket = blink::PointerDataPacket;
|
||||
|
||||
class Engine : public sky::SkyEngine, public blink::RuntimeDelegate {
|
||||
class Engine : public blink::RuntimeDelegate {
|
||||
public:
|
||||
explicit Engine(PlatformView* platform_view);
|
||||
|
||||
@@ -68,7 +59,6 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate {
|
||||
|
||||
std::string GetUIIsolateName();
|
||||
|
||||
void ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request);
|
||||
void OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation);
|
||||
void OnOutputSurfaceDestroyed(const ftl::Closure& gpu_continuation);
|
||||
void SetViewportMetrics(const blink::ViewportMetrics& metrics);
|
||||
@@ -78,17 +68,6 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate {
|
||||
void SetSemanticsEnabled(bool enabled);
|
||||
|
||||
private:
|
||||
// SkyEngine implementation:
|
||||
void RunFromFile(const mojo::String& main,
|
||||
const mojo::String& packages,
|
||||
const mojo::String& bundle) override;
|
||||
void RunFromPrecompiledSnapshot(const mojo::String& bundle_path) override;
|
||||
void RunFromBundle(const mojo::String& script_uri,
|
||||
const mojo::String& bundle_path) override;
|
||||
void RunFromBundleAndSnapshot(const mojo::String& script_uri,
|
||||
const mojo::String& bundle_path,
|
||||
const mojo::String& snapshot_path) override;
|
||||
|
||||
// RuntimeDelegate methods:
|
||||
void ScheduleFrame() override;
|
||||
void Render(std::unique_ptr<flow::LayerTree> layer_tree) override;
|
||||
@@ -115,22 +94,17 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate {
|
||||
|
||||
ftl::WeakPtr<PlatformView> platform_view_;
|
||||
std::unique_ptr<Animator> animator_;
|
||||
|
||||
mojo::asset_bundle::AssetBundlePtr root_bundle_;
|
||||
std::unique_ptr<blink::RuntimeController> runtime_;
|
||||
|
||||
std::unique_ptr<glue::DrainDataPipeJob> snapshot_drainer_;
|
||||
|
||||
ftl::RefPtr<blink::PlatformMessage> pending_push_route_message_;
|
||||
blink::ViewportMetrics viewport_metrics_;
|
||||
std::string language_code_;
|
||||
std::string country_code_;
|
||||
bool semantics_enabled_ = false;
|
||||
mojo::Binding<SkyEngine> binding_;
|
||||
|
||||
// TODO(abarth): Unify these two behind a common interface.
|
||||
ftl::RefPtr<blink::ZipAssetStore> asset_store_;
|
||||
std::unique_ptr<blink::DirectoryAssetBundle> directory_asset_bundle_;
|
||||
std::unique_ptr<blink::ZipAssetBundle> zip_asset_bundle_;
|
||||
|
||||
// TODO(eseidel): This should move into an AnimatorStateMachine.
|
||||
bool activity_running_;
|
||||
|
||||
@@ -18,11 +18,13 @@ namespace shell {
|
||||
PlatformView::PlatformView(std::unique_ptr<Rasterizer> rasterizer)
|
||||
: rasterizer_(std::move(rasterizer)),
|
||||
size_(SkISize::Make(0, 0)),
|
||||
weak_factory_(this) {}
|
||||
weak_factory_(this) {
|
||||
blink::Threads::UI()->PostTask(
|
||||
[self = GetWeakPtr()] { Shell::Shared().AddPlatformView(self); });
|
||||
}
|
||||
|
||||
PlatformView::~PlatformView() {
|
||||
blink::Threads::UI()->PostTask(
|
||||
[]() { Shell::Shared().PurgePlatformViews(); });
|
||||
blink::Threads::UI()->PostTask([] { Shell::Shared().PurgePlatformViews(); });
|
||||
|
||||
Rasterizer* rasterizer = rasterizer_.release();
|
||||
blink::Threads::Gpu()->PostTask([rasterizer]() { delete rasterizer; });
|
||||
@@ -63,18 +65,6 @@ void PlatformView::SetSemanticsEnabled(bool enabled) {
|
||||
});
|
||||
}
|
||||
|
||||
void PlatformView::ConnectToEngine(
|
||||
mojo::InterfaceRequest<sky::SkyEngine> request) {
|
||||
blink::Threads::UI()->PostTask(ftl::MakeCopyable([
|
||||
view = GetWeakPtr(), engine = engine().GetWeakPtr(),
|
||||
request = std::move(request)
|
||||
]() mutable {
|
||||
if (engine)
|
||||
engine->ConnectToEngine(std::move(request));
|
||||
Shell::Shared().AddPlatformView(view);
|
||||
}));
|
||||
}
|
||||
|
||||
void PlatformView::NotifyCreated(std::unique_ptr<Surface> surface) {
|
||||
NotifyCreated(std::move(surface), []() {});
|
||||
}
|
||||
|
||||
@@ -41,8 +41,6 @@ class PlatformView {
|
||||
void DispatchSemanticsAction(int32_t id, blink::SemanticsAction action);
|
||||
void SetSemanticsEnabled(bool enabled);
|
||||
|
||||
void ConnectToEngine(mojo::InterfaceRequest<sky::SkyEngine> request);
|
||||
|
||||
void NotifyCreated(std::unique_ptr<Surface> surface);
|
||||
|
||||
void NotifyCreated(std::unique_ptr<Surface> surface,
|
||||
@@ -64,9 +62,9 @@ class PlatformView {
|
||||
Rasterizer& rasterizer() { return *rasterizer_; }
|
||||
Engine& engine() { return *engine_; }
|
||||
|
||||
virtual void RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) = 0;
|
||||
virtual void RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) = 0;
|
||||
|
||||
protected:
|
||||
explicit PlatformView(std::unique_ptr<Rasterizer> rasterizer);
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
#define SHELL_COMMON_RASTERIZER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/flow/layers/layer_tree.h"
|
||||
#include "flutter/shell/common/surface.h"
|
||||
#include "flutter/synchronization/pipeline.h"
|
||||
#include "lib/ftl/functional/closure.h"
|
||||
#include "lib/ftl/memory/weak_ptr.h"
|
||||
#include "lib/ftl/synchronization/waitable_event.h"
|
||||
#include "mojo/public/cpp/bindings/binding.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
|
||||
@@ -316,7 +316,7 @@ void Shell::RunInPlatformViewUIThread(uintptr_t view_id,
|
||||
PlatformView* view = it->get();
|
||||
if (reinterpret_cast<uintptr_t>(view) == view_id) {
|
||||
*view_existed = true;
|
||||
view->RunFromSource(main, packages, assets_directory);
|
||||
view->RunFromSource(assets_directory, main, packages);
|
||||
*dart_isolate_id = view->engine().GetUIIsolateMainPort();
|
||||
*isolate_name = view->engine().GetUIIsolateName();
|
||||
break;
|
||||
|
||||
@@ -22,10 +22,7 @@ class Shell {
|
||||
public:
|
||||
~Shell();
|
||||
|
||||
// Init the shell to stand alone from MojoShell.
|
||||
static void InitStandalone(std::string icu_data_path = "");
|
||||
|
||||
// Init the shell to run inside MojoShell.
|
||||
static void Init();
|
||||
|
||||
static Shell& Shared();
|
||||
|
||||
@@ -13,13 +13,12 @@ source_set("gpu") {
|
||||
]
|
||||
|
||||
deps = [
|
||||
"../common",
|
||||
"//flutter/common",
|
||||
"//flutter/flow",
|
||||
"//flutter/glue",
|
||||
"//flutter/shell/common",
|
||||
"//flutter/skia",
|
||||
"//flutter/synchronization",
|
||||
"//lib/ftl",
|
||||
"//mojo/public/cpp/system",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "flutter/shell/common/picture_serializer.h"
|
||||
#include "flutter/shell/common/platform_view.h"
|
||||
#include "flutter/shell/common/shell.h"
|
||||
#include "mojo/public/cpp/system/data_pipe.h"
|
||||
#include "third_party/skia/include/core/SkPicture.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
@@ -50,7 +50,6 @@ shared_library("sky_shell") {
|
||||
"//flutter/skia",
|
||||
"//flutter/vulkan",
|
||||
"//lib/ftl",
|
||||
"//mojo/android:libsystem_java",
|
||||
"//mojo/edk/base_edk",
|
||||
"//mojo/edk/system",
|
||||
":jni_headers",
|
||||
@@ -78,9 +77,6 @@ android_library("java") {
|
||||
"io/flutter/view/ResourceCleaner.java",
|
||||
"io/flutter/view/ResourceExtractor.java",
|
||||
"io/flutter/view/ResourcePaths.java",
|
||||
"io/flutter/view/ServiceFactory.java",
|
||||
"io/flutter/view/ServiceProviderImpl.java",
|
||||
"io/flutter/view/ServiceRegistry.java",
|
||||
"io/flutter/view/VsyncWaiter.java",
|
||||
"org/domokit/sky/shell/SkyActivity.java",
|
||||
"org/domokit/sky/shell/SkyApplication.java",
|
||||
@@ -88,13 +84,6 @@ android_library("java") {
|
||||
|
||||
deps = [
|
||||
"//base:base_java",
|
||||
"//flutter/services/engine:interfaces_java",
|
||||
"//flutter/services/platform:interfaces_java",
|
||||
"//mojo/android:system_java",
|
||||
"//mojo/public/interfaces/application:application_java",
|
||||
"//mojo/public/java:bindings",
|
||||
"//mojo/public/java:system",
|
||||
"//mojo/services/vsync/interfaces:interfaces_java",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,6 @@ import org.chromium.base.PathUtils;
|
||||
import org.chromium.base.library_loader.LibraryLoader;
|
||||
import org.chromium.base.library_loader.LibraryProcessType;
|
||||
import org.chromium.base.library_loader.ProcessInitException;
|
||||
import org.chromium.mojo.bindings.Interface.Binding;
|
||||
import org.chromium.mojo.system.Core;
|
||||
import org.chromium.mojo.system.impl.CoreImpl;
|
||||
import org.chromium.mojo.system.MessagePipeHandle;
|
||||
|
||||
/**
|
||||
* A class to intialize the Flutter engine.
|
||||
@@ -163,8 +159,6 @@ public class FlutterMain {
|
||||
|
||||
nativeInit(applicationContext, shellArgs.toArray(new String[0]));
|
||||
|
||||
// Create the mojo run loop.
|
||||
CoreImpl.getInstance().createDefaultRunLoop();
|
||||
sInitialized = true;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Flutter initialization failed.", e);
|
||||
|
||||
@@ -36,14 +36,6 @@ import org.json.JSONObject;
|
||||
|
||||
import org.chromium.base.CalledByNative;
|
||||
import org.chromium.base.JNINamespace;
|
||||
import org.chromium.mojo.bindings.Interface.Binding;
|
||||
import org.chromium.mojo.bindings.InterfaceRequest;
|
||||
import org.chromium.mojo.system.Core;
|
||||
import org.chromium.mojo.system.MessagePipeHandle;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
import org.chromium.mojo.system.Pair;
|
||||
import org.chromium.mojo.system.impl.CoreImpl;
|
||||
import org.chromium.mojom.sky.SkyEngine;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
@@ -81,7 +73,6 @@ public class FlutterView extends SurfaceView
|
||||
private long mNativePlatformView;
|
||||
private TextInputPlugin mTextInputPlugin;
|
||||
|
||||
private SkyEngine.Proxy mSkyEngine;
|
||||
private HashMap<String, OnMessageListener> mOnMessageListeners;
|
||||
private HashMap<String, OnMessageListenerAsync> mAsyncOnMessageListeners;
|
||||
private final SurfaceHolder.Callback mSurfaceCallback;
|
||||
@@ -134,8 +125,6 @@ public class FlutterView extends SurfaceView
|
||||
};
|
||||
getHolder().addCallback(mSurfaceCallback);
|
||||
|
||||
Core core = CoreImpl.getInstance();
|
||||
|
||||
mAccessibilityManager = (AccessibilityManager)getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
|
||||
|
||||
mOnMessageListeners = new HashMap<String, OnMessageListener>();
|
||||
@@ -264,8 +253,6 @@ public class FlutterView extends SurfaceView
|
||||
getHolder().removeCallback(mSurfaceCallback);
|
||||
nativeDetach(mNativePlatformView);
|
||||
mNativePlatformView = 0;
|
||||
|
||||
mSkyEngine.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -457,12 +444,7 @@ public class FlutterView extends SurfaceView
|
||||
}
|
||||
|
||||
private void attach() {
|
||||
Core core = CoreImpl.getInstance();
|
||||
Pair<SkyEngine.Proxy, InterfaceRequest<SkyEngine>> engine =
|
||||
SkyEngine.MANAGER.getInterfaceRequest(core);
|
||||
mSkyEngine = engine.first;
|
||||
mNativePlatformView =
|
||||
nativeAttach(engine.second.passHandle().releaseNativeHandle(), this);
|
||||
mNativePlatformView = nativeAttach(this);
|
||||
}
|
||||
|
||||
private void preRun() {
|
||||
@@ -470,35 +452,21 @@ public class FlutterView extends SurfaceView
|
||||
}
|
||||
|
||||
private void postRun() {
|
||||
Core core = CoreImpl.getInstance();
|
||||
}
|
||||
|
||||
public void runFromBundle(String bundlePath, String snapshotPath) {
|
||||
public void runFromBundle(String bundlePath, String snapshotOverride) {
|
||||
preRun();
|
||||
|
||||
if (FlutterMain.isRunningPrecompiledCode()) {
|
||||
mSkyEngine.runFromPrecompiledSnapshot(bundlePath);
|
||||
} else {
|
||||
String scriptUri = "file://" + bundlePath;
|
||||
if (snapshotPath != null) {
|
||||
mSkyEngine.runFromBundleAndSnapshot(scriptUri, bundlePath, snapshotPath);
|
||||
} else {
|
||||
mSkyEngine.runFromBundle(scriptUri, bundlePath);
|
||||
}
|
||||
}
|
||||
|
||||
nativeRunBundleAndSnapshot(mNativePlatformView, bundlePath, snapshotOverride);
|
||||
postRun();
|
||||
}
|
||||
|
||||
public void runFromSource(final String main,
|
||||
final String packages,
|
||||
final String assetsDirectory) {
|
||||
private void runFromSource(final String assetsDirectory,
|
||||
final String main,
|
||||
final String packages) {
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
preRun();
|
||||
mSkyEngine.runFromFile(main,
|
||||
packages,
|
||||
assetsDirectory);
|
||||
nativeRunBundleAndSource(mNativePlatformView, assetsDirectory, main, packages);
|
||||
postRun();
|
||||
synchronized (this) {
|
||||
notify();
|
||||
@@ -523,8 +491,7 @@ public class FlutterView extends SurfaceView
|
||||
return nativeGetBitmap(mNativePlatformView);
|
||||
}
|
||||
|
||||
private static native long nativeAttach(int skyEngineHandle,
|
||||
FlutterView view);
|
||||
private static native long nativeAttach(FlutterView view);
|
||||
private static native int nativeGetObservatoryPort();
|
||||
private static native void nativeDetach(long nativePlatformViewAndroid);
|
||||
private static native void nativeSurfaceCreated(long nativePlatformViewAndroid,
|
||||
@@ -534,6 +501,15 @@ public class FlutterView extends SurfaceView
|
||||
int width,
|
||||
int height);
|
||||
private static native void nativeSurfaceDestroyed(long nativePlatformViewAndroid);
|
||||
|
||||
private static native void nativeRunBundleAndSnapshot(long nativePlatformViewAndroid,
|
||||
String bundlePath,
|
||||
String snapshotOverride);
|
||||
private static native void nativeRunBundleAndSource(long nativePlatformViewAndroid,
|
||||
String bundlePath,
|
||||
String main,
|
||||
String packages);
|
||||
|
||||
private static native void nativeSetViewportMetrics(long nativePlatformViewAndroid,
|
||||
float devicePixelRatio,
|
||||
int physicalWidth,
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
package io.flutter.view;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.chromium.mojo.bindings.Interface.Binding;
|
||||
import org.chromium.mojo.system.Core;
|
||||
import org.chromium.mojo.system.MessagePipeHandle;
|
||||
|
||||
/**
|
||||
* An interface for creating services. Instances of this interface can be
|
||||
* registered with ServiceRegistry and thereby made available to non-Java
|
||||
* clients.
|
||||
**/
|
||||
interface ServiceFactory {
|
||||
Binding connectToService(FlutterView view, Core core, MessagePipeHandle pipe);
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
package io.flutter.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.chromium.mojo.bindings.ConnectionErrorHandler;
|
||||
import org.chromium.mojo.bindings.Interface.Binding;
|
||||
import org.chromium.mojo.system.Core;
|
||||
import org.chromium.mojo.system.MessagePipeHandle;
|
||||
import org.chromium.mojo.system.MojoException;
|
||||
import org.chromium.mojo.system.impl.CoreImpl;
|
||||
import org.chromium.mojom.mojo.ServiceProvider;
|
||||
|
||||
/**
|
||||
* A collection of services.
|
||||
**/
|
||||
class ServiceProviderImpl implements ServiceProvider {
|
||||
private static final String TAG = "ServiceProviderImpl";
|
||||
|
||||
private Core mCore;
|
||||
private FlutterView mView;
|
||||
private ServiceRegistry mRegistry;
|
||||
private HashSet<Binding> mBindings = new HashSet<Binding>();
|
||||
|
||||
ServiceProviderImpl(Core core, FlutterView view, ServiceRegistry registry) {
|
||||
assert core != null;
|
||||
assert view != null;
|
||||
mCore = core;
|
||||
mView = view;
|
||||
mRegistry = registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {}
|
||||
|
||||
@Override
|
||||
public void connectToService(String interfaceName, MessagePipeHandle pipe) {
|
||||
ServiceFactory factory = mRegistry.get(interfaceName);
|
||||
if (factory == null) {
|
||||
pipe.close();
|
||||
return;
|
||||
}
|
||||
final Binding binding = factory.connectToService(mView, mCore, pipe);
|
||||
mBindings.add(binding);
|
||||
binding.registerErrorHandler(new ConnectionErrorHandler() {
|
||||
@Override
|
||||
public void onConnectionError(MojoException e) {
|
||||
Log.w(TAG, "Flutter service provider connection error", e);
|
||||
mBindings.remove(binding);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void unbindServices() {
|
||||
for (Binding binding : mBindings) {
|
||||
binding.unbind().close();
|
||||
}
|
||||
mBindings.clear();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
package io.flutter.view;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* An registry for services.
|
||||
**/
|
||||
class ServiceRegistry {
|
||||
private static final String TAG = "ServiceRegistry";
|
||||
private Map<String, ServiceFactory> mRegistrations;
|
||||
|
||||
static final ServiceRegistry SHARED = new ServiceRegistry();
|
||||
|
||||
ServiceRegistry() {
|
||||
mRegistrations = new TreeMap<String, ServiceFactory>();
|
||||
}
|
||||
|
||||
void register(String interfaceName, ServiceFactory connector) {
|
||||
assert !mRegistrations.containsKey(interfaceName);
|
||||
assert connector != null;
|
||||
mRegistrations.put(interfaceName, connector);
|
||||
}
|
||||
|
||||
ServiceFactory get(String interfaceName) {
|
||||
if (!mRegistrations.containsKey(interfaceName)) {
|
||||
Log.e(TAG, "Unknown service " + interfaceName);
|
||||
}
|
||||
return mRegistrations.get(interfaceName);
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,6 @@
|
||||
#include "base/bind.h"
|
||||
#include "base/logging.h"
|
||||
#include "flutter/lib/jni/dart_jni.h"
|
||||
#include "mojo/android/system/base_run_loop.h"
|
||||
#include "mojo/android/system/core_impl.h"
|
||||
#include "flutter/shell/platform/android/flutter_main.h"
|
||||
#include "flutter/shell/platform/android/platform_view_android.h"
|
||||
#include "flutter/shell/platform/android/vsync_waiter_android.h"
|
||||
@@ -19,8 +17,6 @@
|
||||
namespace {
|
||||
|
||||
base::android::RegistrationMethod kSkyRegisteredMethods[] = {
|
||||
{"CoreImpl", mojo::android::RegisterCoreImpl},
|
||||
{"BaseRunLoop", mojo::android::RegisterBaseRunLoop},
|
||||
{"FlutterView", shell::PlatformViewAndroid::Register},
|
||||
{"VsyncWaiter", shell::VsyncWaiterAndroid::Register},
|
||||
{"FlutterMain", shell::RegisterFlutterMain},
|
||||
|
||||
@@ -138,6 +138,40 @@ void PlatformViewAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) {
|
||||
ReleaseSurface();
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::RunBundleAndSnapshot(JNIEnv* env,
|
||||
jobject obj,
|
||||
jstring java_bundle_path,
|
||||
jstring java_snapshot_override) {
|
||||
std::string bundle_path =
|
||||
base::android::ConvertJavaStringToUTF8(env, java_bundle_path);
|
||||
std::string snapshot_override =
|
||||
base::android::ConvertJavaStringToUTF8(env, java_snapshot_override);
|
||||
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine_->GetWeakPtr(), bundle_path, snapshot_override ] {
|
||||
if (engine)
|
||||
engine->RunBundleAndSnapshot(bundle_path, snapshot_override);
|
||||
});
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::RunBundleAndSource(JNIEnv* env,
|
||||
jobject obj,
|
||||
jstring java_bundle_path,
|
||||
jstring java_main,
|
||||
jstring java_packages) {
|
||||
std::string bundle_path =
|
||||
base::android::ConvertJavaStringToUTF8(env, java_bundle_path);
|
||||
std::string main = base::android::ConvertJavaStringToUTF8(env, java_main);
|
||||
std::string packages =
|
||||
base::android::ConvertJavaStringToUTF8(env, java_packages);
|
||||
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine_->GetWeakPtr(), bundle_path, main, packages ] {
|
||||
if (engine)
|
||||
engine->RunBundleAndSource(bundle_path, main, packages);
|
||||
});
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::SetViewportMetrics(JNIEnv* env,
|
||||
jobject obj,
|
||||
jfloat device_pixel_ratio,
|
||||
@@ -157,7 +191,7 @@ void PlatformViewAndroid::SetViewportMetrics(JNIEnv* env,
|
||||
metrics.physical_padding_left = physical_padding_left;
|
||||
|
||||
blink::Threads::UI()->PostTask([ engine = engine_->GetWeakPtr(), metrics ] {
|
||||
if (engine.get())
|
||||
if (engine)
|
||||
engine->SetViewportMetrics(metrics);
|
||||
});
|
||||
}
|
||||
@@ -346,9 +380,9 @@ void PlatformViewAndroid::UpdateSemantics(
|
||||
}
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) {
|
||||
void PlatformViewAndroid::RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) {
|
||||
FTL_CHECK(base::android::IsVMInitialized());
|
||||
JNIEnv* env = base::android::AttachCurrentThread();
|
||||
FTL_CHECK(env);
|
||||
@@ -372,14 +406,14 @@ void PlatformViewAndroid::RunFromSource(const std::string& main,
|
||||
FTL_CHECK(run_from_source_method_id);
|
||||
|
||||
// Invoke runFromSource on the Android UI thread.
|
||||
jstring java_assets_directory = env->NewStringUTF(assets_directory.c_str());
|
||||
FTL_CHECK(java_assets_directory);
|
||||
jstring java_main = env->NewStringUTF(main.c_str());
|
||||
FTL_CHECK(java_main);
|
||||
jstring java_packages = env->NewStringUTF(packages.c_str());
|
||||
FTL_CHECK(java_packages);
|
||||
jstring java_assets_directory = env->NewStringUTF(assets_directory.c_str());
|
||||
FTL_CHECK(java_assets_directory);
|
||||
env->CallVoidMethod(local_flutter_view.obj(), run_from_source_method_id,
|
||||
java_main, java_packages, java_assets_directory);
|
||||
java_assets_directory, java_main, java_packages);
|
||||
}
|
||||
|
||||
// Detaching from the VM deletes any stray local references.
|
||||
@@ -496,14 +530,8 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
|
||||
return RegisterNativesImpl(env);
|
||||
}
|
||||
|
||||
static jlong Attach(JNIEnv* env,
|
||||
jclass clazz,
|
||||
jint skyEngineHandle,
|
||||
jobject flutterView) {
|
||||
static jlong Attach(JNIEnv* env, jclass clazz, jobject flutterView) {
|
||||
PlatformViewAndroid* view = new PlatformViewAndroid();
|
||||
view->ConnectToEngine(mojo::InterfaceRequest<sky::SkyEngine>(
|
||||
mojo::ScopedMessagePipeHandle(mojo::MessagePipeHandle(skyEngineHandle))));
|
||||
|
||||
// Create a weak reference to the flutterView Java object so that we can make
|
||||
// calls into it later.
|
||||
view->set_flutter_view(JavaObjectWeakGlobalRef(env, flutterView));
|
||||
|
||||
@@ -35,6 +35,17 @@ class PlatformViewAndroid : public PlatformView {
|
||||
|
||||
void SurfaceChanged(JNIEnv* env, jobject obj, jint width, jint height);
|
||||
|
||||
void RunBundleAndSnapshot(JNIEnv* env,
|
||||
jobject obj,
|
||||
jstring bundle_path,
|
||||
jstring snapshot_override);
|
||||
|
||||
void RunBundleAndSource(JNIEnv* env,
|
||||
jobject obj,
|
||||
jstring bundle_path,
|
||||
jstring main,
|
||||
jstring packages);
|
||||
|
||||
void SurfaceDestroyed(JNIEnv* env, jobject obj);
|
||||
|
||||
void SetViewportMetrics(JNIEnv* env,
|
||||
@@ -82,9 +93,9 @@ class PlatformViewAndroid : public PlatformView {
|
||||
void HandlePlatformMessageResponse(int response_id,
|
||||
std::vector<uint8_t> data);
|
||||
|
||||
void RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) override;
|
||||
void RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) override;
|
||||
|
||||
void set_flutter_view(const JavaObjectWeakGlobalRef& flutter_view) {
|
||||
flutter_view_ = flutter_view;
|
||||
|
||||
@@ -18,19 +18,15 @@ source_set("common") {
|
||||
"//base",
|
||||
"//base:i18n",
|
||||
"//dart/runtime:libdart",
|
||||
"//flutter/common",
|
||||
"//flutter/runtime",
|
||||
"//flutter/services/engine:interfaces",
|
||||
"//flutter/services/platform",
|
||||
"//flutter/shell/common",
|
||||
"//flutter/shell/gpu",
|
||||
"//flutter/shell/testing",
|
||||
"//flutter/skia",
|
||||
"//flutter/sky/engine/wtf",
|
||||
"//lib/ftl",
|
||||
"//mojo/common",
|
||||
"//mojo/edk/base_edk",
|
||||
"//mojo/edk/system",
|
||||
"//mojo/public/cpp/bindings:utility",
|
||||
"//mojo/public/interfaces/application",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#ifndef SHELL_PLATFORM_MAC_PLATFORM_MAC_H_
|
||||
#define SHELL_PLATFORM_MAC_PLATFORM_MAC_H_
|
||||
|
||||
#include "flutter/services/engine/sky_engine.mojom.h"
|
||||
#include "flutter/shell/common/engine.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
void PlatformMacMain(int argc, const char* argv[], std::string icu_data_path);
|
||||
|
||||
bool AttemptLaunchFromCommandLineSwitches(sky::SkyEnginePtr& engine);
|
||||
bool AttemptLaunchFromCommandLineSwitches(Engine* engine);
|
||||
|
||||
} // namespace shell
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "dart/runtime/include/dart_tools_api.h"
|
||||
#include "flutter/runtime/start_up.h"
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/shell/common/shell.h"
|
||||
#include "flutter/shell/common/switches.h"
|
||||
#include "flutter/shell/common/tracing_controller.h"
|
||||
@@ -118,10 +119,10 @@ void PlatformMacMain(int argc, const char* argv[], std::string icu_data_path) {
|
||||
});
|
||||
}
|
||||
|
||||
static bool FlagsValidForCommandLineLaunch(const std::string& dart_main,
|
||||
const std::string& packages,
|
||||
const std::string& bundle) {
|
||||
if (dart_main.empty() || packages.empty() || bundle.empty()) {
|
||||
static bool FlagsValidForCommandLineLaunch(const std::string& bundle_path,
|
||||
const std::string& main,
|
||||
const std::string& packages) {
|
||||
if (main.empty() || packages.empty() || bundle_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ static bool FlagsValidForCommandLineLaunch(const std::string& dart_main,
|
||||
|
||||
NSFileManager* manager = [NSFileManager defaultManager];
|
||||
|
||||
if (![manager fileExistsAtPath:@(dart_main.c_str())]) {
|
||||
if (![manager fileExistsAtPath:@(main.c_str())]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ static bool FlagsValidForCommandLineLaunch(const std::string& dart_main,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (![manager fileExistsAtPath:@(bundle.c_str())]) {
|
||||
if (![manager fileExistsAtPath:@(bundle_path.c_str())]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -163,46 +164,50 @@ static std::string ResolveCommandLineLaunchFlag(const char* name) {
|
||||
return "";
|
||||
}
|
||||
|
||||
bool AttemptLaunchFromCommandLineSwitches(sky::SkyEnginePtr& engine) {
|
||||
bool AttemptLaunchFromCommandLineSwitches(Engine* engine) {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
auto command_line = *base::CommandLine::ForCurrentProcess();
|
||||
|
||||
if (command_line.HasSwitch(switches::kMainDartFile) ||
|
||||
command_line.HasSwitch(switches::kPackages) ||
|
||||
command_line.HasSwitch(switches::kFLX)) {
|
||||
if (command_line.HasSwitch(switches::kFLX) ||
|
||||
command_line.HasSwitch(switches::kMainDartFile) ||
|
||||
command_line.HasSwitch(switches::kPackages)) {
|
||||
// The main dart file, flx bundle and the package root must be specified in
|
||||
// one go. We dont want to end up in a situation where we take one value
|
||||
// from the command line and the others from user defaults. In case, any
|
||||
// new flags are specified, forget about all the old ones.
|
||||
[defaults removeObjectForKey:@(switches::kFLX)];
|
||||
[defaults removeObjectForKey:@(switches::kMainDartFile)];
|
||||
[defaults removeObjectForKey:@(switches::kPackages)];
|
||||
[defaults removeObjectForKey:@(switches::kFLX)];
|
||||
|
||||
[defaults synchronize];
|
||||
}
|
||||
|
||||
std::string dart_main = ResolveCommandLineLaunchFlag(switches::kMainDartFile);
|
||||
std::string bundle_path = ResolveCommandLineLaunchFlag(switches::kFLX);
|
||||
std::string main = ResolveCommandLineLaunchFlag(switches::kMainDartFile);
|
||||
std::string packages = ResolveCommandLineLaunchFlag(switches::kPackages);
|
||||
std::string bundle = ResolveCommandLineLaunchFlag(switches::kFLX);
|
||||
|
||||
if (!FlagsValidForCommandLineLaunch(dart_main, packages, bundle)) {
|
||||
if (!FlagsValidForCommandLineLaunch(bundle_path, main, packages)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save the newly resolved dart main file and the package root to user
|
||||
// defaults so that the next time the user launches the application in the
|
||||
// simulator without the tooling, the application boots up.
|
||||
[defaults setObject:@(dart_main.c_str()) forKey:@(switches::kMainDartFile)];
|
||||
[defaults setObject:@(bundle_path.c_str()) forKey:@(switches::kFLX)];
|
||||
[defaults setObject:@(main.c_str()) forKey:@(switches::kMainDartFile)];
|
||||
[defaults setObject:@(packages.c_str()) forKey:@(switches::kPackages)];
|
||||
[defaults setObject:@(bundle.c_str()) forKey:@(switches::kFLX)];
|
||||
|
||||
[defaults synchronize];
|
||||
|
||||
// Finally launch with the newly resolved arguments.
|
||||
engine->RunFromFile(dart_main, packages, bundle);
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine->GetWeakPtr(), bundle_path, main, packages ] {
|
||||
if (engine)
|
||||
engine->RunBundleAndSource(bundle_path, main, packages);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ class PlatformViewMac : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
|
||||
void SetupAndLoadDart();
|
||||
|
||||
sky::SkyEnginePtr& engineProxy();
|
||||
|
||||
bool GLContextMakeCurrent() override;
|
||||
|
||||
bool GLContextClearCurrent() override;
|
||||
@@ -37,22 +35,19 @@ class PlatformViewMac : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
|
||||
bool ResourceContextMakeCurrent() override;
|
||||
|
||||
void RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) override;
|
||||
void RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) override;
|
||||
|
||||
private:
|
||||
base::scoped_nsobject<NSOpenGLView> opengl_view_;
|
||||
base::scoped_nsobject<NSOpenGLContext> resource_loading_context_;
|
||||
sky::SkyEnginePtr sky_engine_;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void ConnectToEngineAndSetupServices();
|
||||
|
||||
void SetupAndLoadFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory);
|
||||
void SetupAndLoadFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages);
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewMac);
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/shell/common/switches.h"
|
||||
#include "flutter/shell/gpu/gpu_rasterizer.h"
|
||||
#include "flutter/shell/platform/darwin/common/platform_mac.h"
|
||||
@@ -35,14 +36,8 @@ PlatformViewMac::PlatformViewMac(NSOpenGLView* gl_view)
|
||||
|
||||
PlatformViewMac::~PlatformViewMac() = default;
|
||||
|
||||
void PlatformViewMac::ConnectToEngineAndSetupServices() {
|
||||
ConnectToEngine(mojo::GetProxy(&sky_engine_));
|
||||
}
|
||||
|
||||
void PlatformViewMac::SetupAndLoadDart() {
|
||||
ConnectToEngineAndSetupServices();
|
||||
|
||||
if (AttemptLaunchFromCommandLineSwitches(sky_engine_)) {
|
||||
if (AttemptLaunchFromCommandLineSwitches(&engine())) {
|
||||
// This attempts launching from an FLX bundle that does not contain a
|
||||
// dart snapshot.
|
||||
return;
|
||||
@@ -52,30 +47,37 @@ void PlatformViewMac::SetupAndLoadDart() {
|
||||
|
||||
std::string bundle_path = command_line.GetSwitchValueASCII(switches::kFLX);
|
||||
if (!bundle_path.empty()) {
|
||||
std::string script_uri = std::string("file://") + bundle_path;
|
||||
sky_engine_->RunFromBundle(script_uri, bundle_path);
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine().GetWeakPtr(), bundle_path ] {
|
||||
if (engine)
|
||||
engine->RunBundle(bundle_path);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
auto args = command_line.GetArgs();
|
||||
if (args.size() > 0) {
|
||||
auto packages = command_line.GetSwitchValueASCII(switches::kPackages);
|
||||
sky_engine_->RunFromFile(args[0], packages, "");
|
||||
std::string main = args[0];
|
||||
std::string packages =
|
||||
command_line.GetSwitchValueASCII(switches::kPackages);
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine().GetWeakPtr(), main, packages ] {
|
||||
if (engine)
|
||||
engine->RunBundleAndSource(std::string(), main, packages);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PlatformViewMac::SetupAndLoadFromSource(
|
||||
const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) {
|
||||
ConnectToEngineAndSetupServices();
|
||||
|
||||
sky_engine_->RunFromFile(main, packages, assets_directory);
|
||||
}
|
||||
|
||||
sky::SkyEnginePtr& PlatformViewMac::engineProxy() {
|
||||
return sky_engine_;
|
||||
const std::string& packages) {
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine().GetWeakPtr(), assets_directory, main, packages ] {
|
||||
if (engine)
|
||||
engine->RunBundleAndSource(assets_directory, main, packages);
|
||||
});
|
||||
}
|
||||
|
||||
intptr_t PlatformViewMac::GLContextFBO() const {
|
||||
@@ -144,13 +146,13 @@ bool PlatformViewMac::IsValid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlatformViewMac::RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) {
|
||||
void PlatformViewMac::RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) {
|
||||
auto latch = new ftl::ManualResetWaitableEvent();
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
SetupAndLoadFromSource(main, packages, assets_directory);
|
||||
SetupAndLoadFromSource(assets_directory, main, packages);
|
||||
latch->Signal();
|
||||
});
|
||||
|
||||
|
||||
@@ -54,8 +54,6 @@ shared_library("flutter_framework_dylib") {
|
||||
"//base:base",
|
||||
"//dart/runtime:libdart",
|
||||
"//flutter/lib/ui",
|
||||
"//flutter/services/engine:interfaces",
|
||||
"//flutter/services/platform",
|
||||
"//flutter/shell/common",
|
||||
"//flutter/shell/gpu",
|
||||
"//flutter/shell/platform/darwin/common",
|
||||
@@ -65,9 +63,6 @@ shared_library("flutter_framework_dylib") {
|
||||
"//lib/ftl",
|
||||
"//mojo/edk/base_edk",
|
||||
"//mojo/edk/system",
|
||||
"//mojo/public/cpp/application",
|
||||
"//mojo/public/cpp/bindings",
|
||||
"//mojo/public/interfaces/application",
|
||||
]
|
||||
|
||||
defines = [
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "dart/runtime/include/dart_api.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartSource.h"
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/shell/common/switches.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartSource.h"
|
||||
|
||||
static NSURL* URLForSwitch(const char* name) {
|
||||
auto cmd = *base::CommandLine::ForCurrentProcess();
|
||||
@@ -143,7 +144,7 @@ static NSString* NSStringFromVMType(VMType type) {
|
||||
return @"Unknown";
|
||||
}
|
||||
|
||||
- (void)launchInEngine:(sky::SkyEnginePtr&)engine
|
||||
- (void)launchInEngine:(shell::Engine*)engine
|
||||
embedderVMType:(VMType)embedderVMType
|
||||
result:(LaunchResult)result {
|
||||
if (_vmTypeRequirement == VMTypeInvalid) {
|
||||
@@ -184,7 +185,7 @@ static NSString* NSStringFromVMType(VMType type) {
|
||||
|
||||
#pragma mark - Running from precompiled application bundles
|
||||
|
||||
- (void)runFromPrecompiledSourceInEngine:(sky::SkyEnginePtr&)engine
|
||||
- (void)runFromPrecompiledSourceInEngine:(shell::Engine*)engine
|
||||
result:(LaunchResult)result {
|
||||
if (![_precompiledDartBundle load]) {
|
||||
NSString* message = [NSString
|
||||
@@ -207,13 +208,19 @@ static NSString* NSStringFromVMType(VMType type) {
|
||||
return;
|
||||
}
|
||||
|
||||
engine->RunFromPrecompiledSnapshot(path.UTF8String);
|
||||
std::string bundle_path = path.UTF8String;
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine->GetWeakPtr(), bundle_path ] {
|
||||
if (engine)
|
||||
engine->RunBundle(bundle_path);
|
||||
});
|
||||
|
||||
result(YES, @"Success");
|
||||
}
|
||||
|
||||
#pragma mark - Running from source
|
||||
|
||||
- (void)runFromSourceInEngine:(sky::SkyEnginePtr&)engine
|
||||
- (void)runFromSourceInEngine:(shell::Engine*)engine
|
||||
result:(LaunchResult)result {
|
||||
if (_dartSource == nil) {
|
||||
result(NO, @"Dart source not specified.");
|
||||
@@ -225,13 +232,23 @@ static NSString* NSStringFromVMType(VMType type) {
|
||||
return result(NO, message);
|
||||
}
|
||||
|
||||
std::string bundle_path =
|
||||
_dartSource.flxArchive.absoluteURL.path.UTF8String;
|
||||
|
||||
if (_dartSource.archiveContainsScriptSnapshot) {
|
||||
engine->RunFromBundle("file://script_snapshot",
|
||||
_dartSource.flxArchive.absoluteURL.path.UTF8String);
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine->GetWeakPtr(), bundle_path ] {
|
||||
if (engine)
|
||||
engine->RunBundle(bundle_path);
|
||||
});
|
||||
} else {
|
||||
engine->RunFromFile(_dartSource.dartMain.absoluteURL.path.UTF8String,
|
||||
_dartSource.packages.absoluteURL.path.UTF8String,
|
||||
_dartSource.flxArchive.absoluteURL.path.UTF8String);
|
||||
std::string main = _dartSource.dartMain.absoluteURL.path.UTF8String;
|
||||
std::string packages = _dartSource.packages.absoluteURL.path.UTF8String;
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine->GetWeakPtr(), bundle_path, main, packages ] {
|
||||
if (engine)
|
||||
engine->RunBundleAndSource(bundle_path, main, packages);
|
||||
});
|
||||
}
|
||||
|
||||
result(YES, @"Success");
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
#ifndef SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERDARTPROJECT_INTERNAL_H_
|
||||
#define SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERDARTPROJECT_INTERNAL_H_
|
||||
|
||||
#include "flutter/shell/common/engine.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h"
|
||||
|
||||
#include "flutter/services/engine/sky_engine.mojom.h"
|
||||
|
||||
enum VMType {
|
||||
// An invalid VM configuration.
|
||||
VMTypeInvalid = 0,
|
||||
@@ -22,7 +21,7 @@ typedef void (^LaunchResult)(BOOL success, NSString* message);
|
||||
|
||||
@interface FlutterDartProject ()
|
||||
|
||||
- (void)launchInEngine:(sky::SkyEnginePtr&)engine
|
||||
- (void)launchInEngine:(shell::Engine*)engine
|
||||
embedderVMType:(VMType)type
|
||||
result:(LaunchResult)result;
|
||||
|
||||
|
||||
@@ -181,13 +181,11 @@ void FlutterInit(int argc, const char* argv[]) {
|
||||
- (void)connectToEngineAndLoad {
|
||||
TRACE_EVENT0("flutter", "connectToEngineAndLoad");
|
||||
|
||||
_platformView->ConnectToEngineAndSetupServices();
|
||||
|
||||
// We ask the VM to check what it supports.
|
||||
const enum VMType type =
|
||||
Dart_IsPrecompiledRuntime() ? VMTypePrecompilation : VMTypeInterpreter;
|
||||
|
||||
[_dartProject launchInEngine:_platformView->engineProxy()
|
||||
[_dartProject launchInEngine:&_platformView->engine()
|
||||
embedderVMType:type
|
||||
result:^(BOOL success, NSString* message) {
|
||||
if (!success) {
|
||||
|
||||
@@ -30,10 +30,6 @@ class PlatformViewIOS : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
|
||||
void ToggleAccessibility(UIView* view, bool enabled);
|
||||
|
||||
void ConnectToEngineAndSetupServices();
|
||||
|
||||
sky::SkyEnginePtr& engineProxy();
|
||||
|
||||
PlatformMessageRouter& platform_message_router() {
|
||||
return platform_message_router_;
|
||||
}
|
||||
@@ -59,20 +55,19 @@ class PlatformViewIOS : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
|
||||
void UpdateSemantics(std::vector<blink::SemanticsNode> update) override;
|
||||
|
||||
void RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) override;
|
||||
void RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IOSGLContext> context_;
|
||||
sky::SkyEnginePtr engine_;
|
||||
PlatformMessageRouter platform_message_router_;
|
||||
std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
|
||||
ftl::WeakPtrFactory<PlatformViewIOS> weak_factory_;
|
||||
|
||||
void SetupAndLoadFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory);
|
||||
void SetupAndLoadFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages);
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS);
|
||||
};
|
||||
|
||||
@@ -3,18 +3,19 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/shell/platform/darwin/ios/platform_view_ios.h"
|
||||
|
||||
#import <OpenGLES/EAGL.h>
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
#import <QuartzCore/CAEAGLLayer.h>
|
||||
#include <utility>
|
||||
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/shell/gpu/gpu_rasterizer.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h"
|
||||
#include "lib/ftl/synchronization/waitable_event.h"
|
||||
#include "mojo/public/cpp/application/connect.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
@@ -283,10 +284,6 @@ PlatformViewIOS::PlatformViewIOS(CAEAGLLayer* layer)
|
||||
|
||||
PlatformViewIOS::~PlatformViewIOS() = default;
|
||||
|
||||
sky::SkyEnginePtr& PlatformViewIOS::engineProxy() {
|
||||
return engine_;
|
||||
}
|
||||
|
||||
void PlatformViewIOS::ToggleAccessibility(UIView* view, bool enabled) {
|
||||
if (enabled) {
|
||||
if (!accessibility_bridge_) {
|
||||
@@ -298,16 +295,15 @@ void PlatformViewIOS::ToggleAccessibility(UIView* view, bool enabled) {
|
||||
SetSemanticsEnabled(enabled);
|
||||
}
|
||||
|
||||
void PlatformViewIOS::ConnectToEngineAndSetupServices() {
|
||||
ConnectToEngine(mojo::GetProxy(&engine_));
|
||||
}
|
||||
|
||||
void PlatformViewIOS::SetupAndLoadFromSource(
|
||||
const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) {
|
||||
ConnectToEngineAndSetupServices();
|
||||
engine_->RunFromFile(main, packages, assets_directory);
|
||||
const std::string& packages) {
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = engine().GetWeakPtr(), assets_directory, main, packages ] {
|
||||
if (engine)
|
||||
engine->RunBundleAndSource(assets_directory, main, packages);
|
||||
});
|
||||
}
|
||||
|
||||
ftl::WeakPtr<PlatformViewIOS> PlatformViewIOS::GetWeakPtr() {
|
||||
@@ -361,13 +357,13 @@ void PlatformViewIOS::HandlePlatformMessage(
|
||||
platform_message_router_.HandlePlatformMessage(std::move(message));
|
||||
}
|
||||
|
||||
void PlatformViewIOS::RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) {
|
||||
void PlatformViewIOS::RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) {
|
||||
auto latch = new ftl::ManualResetWaitableEvent();
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
SetupAndLoadFromSource(main, packages, assets_directory);
|
||||
SetupAndLoadFromSource(assets_directory, main, packages);
|
||||
latch->Signal();
|
||||
});
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ executable("linux") {
|
||||
output_name = "sky_shell"
|
||||
|
||||
sources = [
|
||||
"glfw_service_provider.cc",
|
||||
"glfw_service_provider.h",
|
||||
"main_linux.cc",
|
||||
"message_pump_glfw.cc",
|
||||
"message_pump_glfw.h",
|
||||
@@ -18,17 +16,13 @@ executable("linux") {
|
||||
deps = [
|
||||
"//base",
|
||||
"//flutter/common",
|
||||
"//flutter/services/engine:interfaces",
|
||||
"//flutter/shell/common",
|
||||
"//flutter/shell/gpu",
|
||||
"//flutter/shell/testing",
|
||||
"//flutter/skia",
|
||||
"//lib/ftl",
|
||||
"//mojo/common",
|
||||
"//mojo/edk/base_edk",
|
||||
"//mojo/edk/system",
|
||||
"//mojo/public/cpp/bindings:utility",
|
||||
"//mojo/public/interfaces/application",
|
||||
"//third_party/glfw",
|
||||
]
|
||||
|
||||
|
||||
@@ -1,19 +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 "glfw_service_provider.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
GLFWServiceProvider::GLFWServiceProvider(
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> request)
|
||||
: binding_(this, request.Pass()) {}
|
||||
|
||||
GLFWServiceProvider::~GLFWServiceProvider() {}
|
||||
|
||||
void GLFWServiceProvider::ConnectToService(
|
||||
const mojo::String& service_name,
|
||||
mojo::ScopedMessagePipeHandle client_handle) {}
|
||||
|
||||
} // namespace shell
|
||||
@@ -1,31 +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 FLUTTER_SHELL_PLATFORM_LINUX_GLFW_SERVICE_PROVIDER_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_LINUX_GLFW_SERVICE_PROVIDER_H_
|
||||
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "mojo/public/cpp/bindings/strong_binding.h"
|
||||
#include "mojo/public/interfaces/application/service_provider.mojom.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
class GLFWServiceProvider : public mojo::ServiceProvider {
|
||||
public:
|
||||
GLFWServiceProvider(mojo::InterfaceRequest<mojo::ServiceProvider> request);
|
||||
|
||||
~GLFWServiceProvider() override;
|
||||
|
||||
void ConnectToService(const mojo::String& service_name,
|
||||
mojo::ScopedMessagePipeHandle client_handle) override;
|
||||
|
||||
private:
|
||||
mojo::StrongBinding<mojo::ServiceProvider> binding_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(GLFWServiceProvider);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_LINUX_GLFW_SERVICE_PROVIDER_H_
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "base/command_line.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/shell/common/shell.h"
|
||||
#include "flutter/shell/common/switches.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_gl.h"
|
||||
@@ -34,10 +35,9 @@ int RunNonInteractive() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool IsDartFile(const std::string& script_uri) {
|
||||
static bool IsDartFile(const std::string& path) {
|
||||
std::string dart_extension = ".dart";
|
||||
return script_uri.rfind(dart_extension) ==
|
||||
(script_uri.size() - dart_extension.size());
|
||||
return path.rfind(dart_extension) == (path.size() - dart_extension.size());
|
||||
}
|
||||
|
||||
int RunInteractive() {
|
||||
@@ -48,37 +48,36 @@ int RunInteractive() {
|
||||
mojo::embedder::Init(mojo::embedder::CreateSimplePlatformSupport());
|
||||
shell::Shell::InitStandalone();
|
||||
|
||||
std::string bundle_path =
|
||||
command_line.GetSwitchValueASCII(shell::switches::kFLX);
|
||||
std::string target = command_line.GetSwitchValueASCII(shell::switches::kFLX);
|
||||
|
||||
if (bundle_path.empty()) {
|
||||
if (target.empty()) {
|
||||
// Alternatively, use the first positional argument.
|
||||
auto args = command_line.GetArgs();
|
||||
if (args.empty())
|
||||
return 1;
|
||||
bundle_path = args[0];
|
||||
target = args[0];
|
||||
}
|
||||
|
||||
if (bundle_path.empty())
|
||||
if (target.empty())
|
||||
return 1;
|
||||
|
||||
std::unique_ptr<shell::PlatformViewGLFW> platform_view(
|
||||
new shell::PlatformViewGLFW());
|
||||
|
||||
platform_view->ConnectToEngineAndSetupServices();
|
||||
|
||||
platform_view->NotifyCreated(
|
||||
std::make_unique<shell::GPUSurfaceGL>(platform_view.get()));
|
||||
|
||||
if (IsDartFile(bundle_path)) {
|
||||
// Load directly from source.
|
||||
platform_view->EngineProxy()->RunFromFile(bundle_path, "", "");
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = platform_view->engine().GetWeakPtr(), target ] {
|
||||
if (engine) {
|
||||
if (IsDartFile(target)) {
|
||||
engine->RunBundleAndSource(std::string(), target, std::string());
|
||||
|
||||
} else {
|
||||
// Load from a bundle.
|
||||
std::string script_uri = std::string("file://") + bundle_path;
|
||||
platform_view->EngineProxy()->RunFromBundle(script_uri, bundle_path);
|
||||
}
|
||||
} else {
|
||||
engine->RunBundle(target);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
message_loop.Run();
|
||||
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
// 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"
|
||||
#include "flutter/shell/platform/linux/glfw_service_provider.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
@@ -60,14 +61,6 @@ PlatformViewGLFW::~PlatformViewGLFW() {
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
void PlatformViewGLFW::ConnectToEngineAndSetupServices() {
|
||||
ConnectToEngine(mojo::GetProxy(&engine_));
|
||||
}
|
||||
|
||||
sky::SkyEnginePtr& PlatformViewGLFW::EngineProxy() {
|
||||
return engine_;
|
||||
}
|
||||
|
||||
bool PlatformViewGLFW::IsValid() const {
|
||||
return valid_;
|
||||
}
|
||||
@@ -97,9 +90,9 @@ bool PlatformViewGLFW::GLContextPresent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlatformViewGLFW::RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) {}
|
||||
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;
|
||||
|
||||
@@ -20,10 +20,6 @@ class PlatformViewGLFW : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
|
||||
~PlatformViewGLFW() override;
|
||||
|
||||
void ConnectToEngineAndSetupServices();
|
||||
|
||||
sky::SkyEnginePtr& EngineProxy();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool ResourceContextMakeCurrent() override;
|
||||
@@ -36,14 +32,13 @@ class PlatformViewGLFW : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
|
||||
intptr_t GLContextFBO() const override;
|
||||
|
||||
void RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) override;
|
||||
void RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) override;
|
||||
|
||||
private:
|
||||
bool valid_;
|
||||
GLFWwindow* glfw_window_;
|
||||
sky::SkyEnginePtr engine_;
|
||||
int buttons_;
|
||||
|
||||
void OnWindowSizeChanged(int width, int height);
|
||||
|
||||
@@ -15,10 +15,8 @@ source_set("testing") {
|
||||
deps = [
|
||||
"//base",
|
||||
"//flutter/common",
|
||||
"//flutter/services/engine:interfaces",
|
||||
"//flutter/shell/common",
|
||||
"//flutter/skia",
|
||||
"//lib/ftl",
|
||||
"//mojo/public/cpp/bindings",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ bool PlatformViewTest::ResourceContextMakeCurrent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void PlatformViewTest::RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) {}
|
||||
void PlatformViewTest::RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) {}
|
||||
|
||||
} // namespace shell
|
||||
|
||||
@@ -21,9 +21,9 @@ class PlatformViewTest : public PlatformView {
|
||||
|
||||
bool ResourceContextMakeCurrent() override;
|
||||
|
||||
void RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
const std::string& assets_directory) override;
|
||||
void RunFromSource(const std::string& assets_directory,
|
||||
const std::string& main,
|
||||
const std::string& packages) override;
|
||||
|
||||
private:
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewTest);
|
||||
|
||||
@@ -13,17 +13,14 @@
|
||||
|
||||
namespace shell {
|
||||
|
||||
TestRunner::TestRunner()
|
||||
: platform_view_(new PlatformViewTest()), weak_ptr_factory_(this) {
|
||||
platform_view_->ConnectToEngine(GetProxy(&sky_engine_));
|
||||
|
||||
TestRunner::TestRunner() : platform_view_(new PlatformViewTest()) {
|
||||
blink::ViewportMetrics metrics;
|
||||
metrics.physical_width = 800;
|
||||
metrics.physical_height = 600;
|
||||
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = platform_view_->engine().GetWeakPtr(), metrics ] {
|
||||
if (engine.get())
|
||||
if (engine)
|
||||
engine->SetViewportMetrics(metrics);
|
||||
});
|
||||
}
|
||||
@@ -38,7 +35,11 @@ TestRunner& TestRunner::Shared() {
|
||||
}
|
||||
|
||||
void TestRunner::Run(const TestDescriptor& test) {
|
||||
sky_engine_->RunFromFile(test.path, test.packages, "");
|
||||
blink::Threads::UI()->PostTask(
|
||||
[ engine = platform_view_->engine().GetWeakPtr(), test ] {
|
||||
if (engine)
|
||||
engine->RunBundleAndSource(std::string(), test.path, test.packages);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flutter/services/engine/sky_engine.mojom.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "lib/ftl/memory/weak_ptr.h"
|
||||
|
||||
@@ -32,9 +31,6 @@ class TestRunner {
|
||||
~TestRunner();
|
||||
|
||||
std::unique_ptr<PlatformView> platform_view_;
|
||||
sky::SkyEnginePtr sky_engine_;
|
||||
|
||||
ftl::WeakPtrFactory<TestRunner> weak_ptr_factory_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(TestRunner);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user