提交 881fc584 编写于 作者: A Adam Barth 提交者: GitHub

Remove failed UIDelegate abstraction (#3106)

We only ever had one UIDelegate. We might as well have people use the Engine
interface directly.
上级 fdf13d72
......@@ -40,8 +40,6 @@ source_set("common") {
"switches.h",
"tracing_controller.cc",
"tracing_controller.h",
"ui_delegate.cc",
"ui_delegate.h",
]
deps = [
......
......@@ -11,7 +11,6 @@
#include "flutter/runtime/runtime_delegate.h"
#include "flutter/services/engine/sky_engine.mojom.h"
#include "flutter/shell/common/rasterizer.h"
#include "flutter/shell/common/ui_delegate.h"
#include "lib/ftl/macros.h"
#include "lib/ftl/memory/weak_ptr.h"
#include "mojo/public/cpp/application/service_provider_impl.h"
......@@ -27,9 +26,7 @@ namespace shell {
class Animator;
using PointerDataPacket = blink::PointerDataPacket;
class Engine : public UIDelegate,
public sky::SkyEngine,
public blink::RuntimeDelegate {
class Engine : public sky::SkyEngine, public blink::RuntimeDelegate {
public:
explicit Engine(Rasterizer* rasterizer);
......@@ -49,14 +46,12 @@ class Engine : public UIDelegate,
std::string GetUIIsolateName();
void ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request);
void OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation);
void OnOutputSurfaceDestroyed(const ftl::Closure& gpu_continuation);
void DispatchPointerDataPacket(const PointerDataPacket& packet);
private:
// UIDelegate implementation:
void ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request) override;
void OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation) override;
void OnOutputSurfaceDestroyed(const ftl::Closure& gpu_continuation) override;
// SkyEngine implementation:
void SetServices(sky::ServicesDataPtr services) override;
void OnViewportMetricsChanged(sky::ViewportMetricsPtr metrics) override;
......
......@@ -7,7 +7,6 @@
#include <utility>
#include "flutter/common/threads.h"
#include "flutter/glue/movable_wrapper.h"
#include "flutter/lib/ui/painting/resource_context.h"
#include "flutter/shell/common/rasterizer.h"
#include "lib/ftl/functional/wrap_lambda.h"
......@@ -15,17 +14,9 @@
namespace shell {
PlatformView::Config::Config() : rasterizer(nullptr) {}
PlatformView::Config::~Config() = default;
PlatformView::PlatformView(std::unique_ptr<Rasterizer> rasterizer)
: rasterizer_(std::move(rasterizer)), size_(SkISize::Make(0, 0)) {
engine_.reset(new Engine(rasterizer_.get()));
// Setup the platform config.
config_.ui_delegate = engine_->GetWeakPtr();
config_.rasterizer = rasterizer_.get();
}
PlatformView::~PlatformView() {
......@@ -41,15 +32,14 @@ PlatformView::~PlatformView() {
void PlatformView::ConnectToEngine(
mojo::InterfaceRequest<sky::SkyEngine> request) {
ftl::WeakPtr<UIDelegate> ui_delegate = config_.ui_delegate;
auto wrapped_request = glue::WrapMovable(std::move(request));
blink::Threads::UI()->PostTask([ui_delegate, wrapped_request]() mutable {
if (ui_delegate)
ui_delegate->ConnectToEngine(wrapped_request.Unwrap());
});
ftl::WeakPtr<PlatformView> view = GetWeakViewPtr();
blink::Threads::UI()->PostTask(
[view]() { Shell::Shared().AddPlatformView(view); });
blink::Threads::UI()->PostTask(ftl::WrapLambda([
view = GetWeakViewPtr(), engine = engine().GetWeakPtr(),
request = std::move(request)
]() mutable {
if (engine.get())
engine->ConnectToEngine(std::move(request));
Shell::Shared().AddPlatformView(view);
}));
}
void PlatformView::NotifyCreated(std::unique_ptr<Surface> surface) {
......@@ -58,29 +48,26 @@ void PlatformView::NotifyCreated(std::unique_ptr<Surface> surface) {
void PlatformView::NotifyCreated(std::unique_ptr<Surface> surface,
ftl::Closure caller_continuation) {
FTL_CHECK(config_.rasterizer);
ftl::AutoResetWaitableEvent latch;
auto ui_continuation = ftl::WrapLambda([
delegate = config_.ui_delegate, //
rasterizer = config_.rasterizer, //
surface = std::move(surface), //
caller_continuation, //
this, //
surface = std::move(surface), //
caller_continuation, //
&latch
]() mutable {
auto gpu_continuation = ftl::WrapLambda([
rasterizer, //
this, //
surface = std::move(surface), //
caller_continuation, //
&latch
]() mutable {
// Runs on the GPU Thread. So does the Caller Continuation.
surface->Setup();
rasterizer->Setup(std::move(surface), caller_continuation, &latch);
rasterizer_->Setup(std::move(surface), caller_continuation, &latch);
});
// Runs on the UI Thread.
delegate->OnOutputSurfaceCreated(std::move(gpu_continuation));
engine_->OnOutputSurfaceCreated(std::move(gpu_continuation));
});
// Runs on the Platform Thread.
......@@ -90,23 +77,14 @@ void PlatformView::NotifyCreated(std::unique_ptr<Surface> surface,
}
void PlatformView::NotifyDestroyed() {
FTL_CHECK(config_.rasterizer != nullptr);
auto delegate = config_.ui_delegate;
auto rasterizer = config_.rasterizer->GetWeakRasterizerPtr();
ftl::AutoResetWaitableEvent latch;
auto delegate_continuation = [rasterizer, &latch]() {
if (rasterizer)
rasterizer->Teardown(&latch);
// TODO(abarth): We should signal the latch if the rasterizer is gone.
auto engine_continuation = [this, &latch]() {
rasterizer_->Teardown(&latch);
};
blink::Threads::UI()->PostTask([delegate, delegate_continuation]() {
if (delegate)
delegate->OnOutputSurfaceDestroyed(delegate_continuation);
// TODO(abarth): We should signal the latch if the delegate is gone.
blink::Threads::UI()->PostTask([this, engine_continuation]() {
engine_->OnOutputSurfaceDestroyed(engine_continuation);
});
latch.Wait();
......
......@@ -10,7 +10,6 @@
#include "flutter/shell/common/engine.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/surface.h"
#include "flutter/shell/common/ui_delegate.h"
#include "lib/ftl/macros.h"
#include "lib/ftl/memory/weak_ptr.h"
#include "lib/ftl/synchronization/waitable_event.h"
......@@ -23,15 +22,6 @@ class Rasterizer;
class PlatformView {
public:
struct Config {
Config();
~Config();
ftl::WeakPtr<UIDelegate> ui_delegate;
Rasterizer* rasterizer;
};
struct SurfaceConfig {
uint8_t red_bits = 8;
uint8_t green_bits = 8;
......@@ -62,6 +52,7 @@ class PlatformView {
virtual void Resize(const SkISize& size);
Rasterizer& rasterizer() { return *rasterizer_; }
Engine& engine() { return *engine_; }
virtual void RunFromSource(const std::string& main,
......@@ -69,7 +60,6 @@ class PlatformView {
const std::string& assets_directory) = 0;
protected:
Config config_;
SurfaceConfig surface_config_;
std::unique_ptr<Rasterizer> rasterizer_;
std::unique_ptr<Engine> engine_;
......
// 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.
#include "flutter/shell/common/ui_delegate.h"
namespace shell {
UIDelegate::~UIDelegate() = default;
} // namespace shell
// 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.
#ifndef SHELL_COMMON_DELEGATE_H_
#define SHELL_COMMON_DELEGATE_H_
#include "flutter/services/engine/sky_engine.mojom.h"
#include "lib/ftl/functional/closure.h"
#include "mojo/public/cpp/bindings/interface_request.h"
namespace shell {
class UIDelegate {
public:
virtual void ConnectToEngine(
mojo::InterfaceRequest<sky::SkyEngine> request) = 0;
virtual void OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation) = 0;
virtual void OnOutputSurfaceDestroyed(
const ftl::Closure& gpu_continuation) = 0;
protected:
virtual ~UIDelegate();
};
} // namespace shell
#endif // SHELL_COMMON_DELEGATE_H_
......@@ -73,7 +73,7 @@ void PlatformViewAndroid::SurfaceChanged(JNIEnv* env,
auto surface = std::make_unique<GPUSurfaceGL>(surface_gl_.get());
NotifyCreated(std::move(surface), [this, backgroundColor] {
config_.rasterizer->Clear(backgroundColor, GetSize());
rasterizer().Clear(backgroundColor, GetSize());
});
SetupResourceContextOnIOThread();
UpdateThreadPriorities();
......
......@@ -21,7 +21,6 @@
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/switches.h"
#include "flutter/shell/common/tracing_controller.h"
#include "flutter/shell/common/ui_delegate.h"
#include "flutter/sky/engine/wtf/MakeUnique.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/simple_platform_support.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册