Skip to content

Commit

Permalink
[flutter] Create the compositor context on the GPU task runner. (flut…
Browse files Browse the repository at this point in the history
…ter#10781)

The compositor context owns the session connection. The creation of the
session connection also does the initial present to clear the node
hierarchy. This present was happening perviously on the platform task
runner while all subsequent presents were on the GPU task runner. This
has now been rectified so all presents are on the GPU task runner.

BUG: FL-288
Change-Id: Ib294666ffb3b4575f93ad0b02a5d0fda71bfa0a8
  • Loading branch information
iskakaushik committed Aug 9, 2019
1 parent 7cfb3de commit 6c0c731
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 33 deletions.
4 changes: 2 additions & 2 deletions shell/platform/fuchsia/flutter/compositor_context.cc
Expand Up @@ -62,13 +62,13 @@ CompositorContext::CompositorContext(
std::string debug_label,
fuchsia::ui::views::ViewToken view_token,
fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session,
fit::closure session_error_callback,
fml::closure session_error_callback,
zx_handle_t vsync_event_handle)
: debug_label_(std::move(debug_label)),
session_connection_(debug_label_,
std::move(view_token),
std::move(session),
std::move(session_error_callback),
session_error_callback,
vsync_event_handle) {}

void CompositorContext::OnSessionMetricsDidChange(
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/fuchsia/flutter/compositor_context.h
Expand Up @@ -23,7 +23,7 @@ class CompositorContext final : public flutter::CompositorContext {
CompositorContext(std::string debug_label,
fuchsia::ui::views::ViewToken view_token,
fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session,
fit::closure session_error_callback,
fml::closure session_error_callback,
zx_handle_t vsync_event_handle);

~CompositorContext() override;
Expand Down
53 changes: 28 additions & 25 deletions shell/platform/fuchsia/flutter/engine.cc
Expand Up @@ -134,7 +134,7 @@ Engine::Engine(Delegate& delegate,
// This handles the fidl error callback when the Session connection is
// broken. The SessionListener interface also has an OnError method, which is
// invoked on the platform thread (in PlatformView).
fit::closure on_session_error_callback =
fml::closure on_session_error_callback =
[dispatcher = async_get_default_dispatcher(),
weak = weak_factory_.GetWeakPtr()]() {
async::PostTask(dispatcher, [weak]() {
Expand All @@ -144,30 +144,6 @@ Engine::Engine(Delegate& delegate,
});
};

// Create the compositor context from the scenic pointer to create the
// rasterizer.
std::unique_ptr<flutter::CompositorContext> compositor_context;
{
TRACE_EVENT0("flutter", "CreateCompositorContext");
compositor_context = std::make_unique<flutter_runner::CompositorContext>(
thread_label_, // debug label
std::move(view_token), // scenic view we attach our tree to
std::move(session), // scenic session
std::move(on_session_error_callback), // session did encounter error
vsync_event_.get() // vsync event handle
);
}

// Setup the callback that will instantiate the rasterizer.
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
fml::MakeCopyable([compositor_context = std::move(compositor_context)](
flutter::Shell& shell) mutable {
return std::make_unique<flutter::Rasterizer>(
shell.GetTaskRunners(), // task runners
std::move(compositor_context) // compositor context
);
});

// Get the task runners from the managed threads. The current thread will be
// used as the "platform" thread.
const flutter::TaskRunners task_runners(
Expand All @@ -178,6 +154,33 @@ Engine::Engine(Delegate& delegate,
CreateFMLTaskRunner(threads_[2]->dispatcher()) // io
);

// Setup the callback that will instantiate the rasterizer.
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
fml::MakeCopyable([thread_label = thread_label_, //
view_token = std::move(view_token), //
session = std::move(session), //
on_session_error_callback, //
vsync_event = vsync_event_.get() //
](flutter::Shell& shell) mutable {
std::unique_ptr<flutter_runner::CompositorContext> compositor_context;
{
TRACE_DURATION("flutter", "CreateCompositorContext");
compositor_context =
std::make_unique<flutter_runner::CompositorContext>(
thread_label, // debug label
std::move(view_token), // scenic view we attach our tree to
std::move(session), // scenic session
on_session_error_callback, // session did encounter error
vsync_event // vsync event handle
);
}

return std::make_unique<flutter::Rasterizer>(
shell.GetTaskRunners(), // task runners
std::move(compositor_context) // compositor context
);
});

UpdateNativeThreadLabelNames(thread_label_, task_runners);

settings_.verbose_logging = true;
Expand Down
6 changes: 2 additions & 4 deletions shell/platform/fuchsia/flutter/session_connection.cc
Expand Up @@ -16,7 +16,7 @@ SessionConnection::SessionConnection(
std::string debug_label,
fuchsia::ui::views::ViewToken view_token,
fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session,
fit::closure session_error_callback,
fml::closure session_error_callback,
zx_handle_t vsync_event_handle)
: debug_label_(std::move(debug_label)),
session_wrapper_(session.Bind(), nullptr),
Expand All @@ -27,9 +27,7 @@ SessionConnection::SessionConnection(
scene_update_context_(&session_wrapper_, surface_producer_.get()),
vsync_event_handle_(vsync_event_handle) {
session_wrapper_.set_error_handler(
[callback = std::move(session_error_callback)](zx_status_t status) {
callback();
});
[callback = session_error_callback](zx_status_t status) { callback(); });

session_wrapper_.SetDebugName(debug_label_);

Expand Down
4 changes: 3 additions & 1 deletion shell/platform/fuchsia/flutter/session_connection.h
Expand Up @@ -16,6 +16,7 @@

#include "flutter/flow/compositor_context.h"
#include "flutter/flow/scene_update_context.h"
#include "flutter/fml/closure.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/trace_event.h"
#include "vulkan_surface_producer.h"
Expand All @@ -29,7 +30,7 @@ class SessionConnection final {
SessionConnection(std::string debug_label,
fuchsia::ui::views::ViewToken view_token,
fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session,
fit::closure session_error_callback,
fml::closure session_error_callback,
zx_handle_t vsync_event_handle);

~SessionConnection();
Expand Down Expand Up @@ -68,6 +69,7 @@ class SessionConnection final {

std::unique_ptr<VulkanSurfaceProducer> surface_producer_;
flutter::SceneUpdateContext scene_update_context_;

zx_handle_t vsync_event_handle_;

// A flow event trace id for following |Session::Present| calls into
Expand Down

0 comments on commit 6c0c731

Please sign in to comment.