fuchsia: Fix View create vs render race (flutter/engine#26368)

This commit is contained in:
David Worsham
2021-05-24 17:46:23 -07:00
committed by GitHub
parent 58a9482d4b
commit efff0a7bb1
9 changed files with 44 additions and 20 deletions

View File

@@ -218,16 +218,18 @@ void SceneUpdateContext::UpdateView(int64_t view_id,
}
void SceneUpdateContext::CreateView(int64_t view_id,
ViewHolder::ViewIdCallback on_view_created,
ViewCallback on_view_created,
ViewHolder::ViewIdCallback on_view_bound,
bool hit_testable,
bool focusable) {
FML_LOG(INFO) << "CreateView for view holder: " << view_id;
zx_handle_t handle = (zx_handle_t)view_id;
flutter::ViewHolder::Create(handle, std::move(on_view_created),
flutter::ViewHolder::Create(handle, std::move(on_view_bound),
scenic::ToViewHolderToken(zx::eventpair(handle)));
on_view_created();
auto* view_holder = ViewHolder::FromId(view_id);
FML_DCHECK(view_holder);
view_holder->set_hit_testable(hit_testable);
view_holder->set_focusable(focusable);
}

View File

@@ -120,6 +120,8 @@ class SceneUpdateContext : public flutter::ExternalViewEmbedder {
std::vector<Layer*> layers;
};
using ViewCallback = std::function<void()>;
SceneUpdateContext(std::string debug_label,
fuchsia::ui::views::ViewToken view_token,
scenic::ViewRefPair view_ref_pair,
@@ -170,7 +172,8 @@ class SceneUpdateContext : public flutter::ExternalViewEmbedder {
// View manipulation.
void CreateView(int64_t view_id,
ViewHolder::ViewIdCallback on_view_created,
ViewCallback on_view_created,
ViewHolder::ViewIdCallback on_view_bound,
bool hit_testable,
bool focusable);
void DestroyView(int64_t view_id,

View File

@@ -202,7 +202,7 @@ Engine::Engine(Delegate& delegate,
OnCreateView on_create_view_callback = std::bind(
&Engine::CreateView, this, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4);
std::placeholders::_3, std::placeholders::_4, std::placeholders::_5);
OnUpdateView on_update_view_callback = std::bind(
&Engine::UpdateView, this, std::placeholders::_1, std::placeholders::_2,
@@ -626,6 +626,7 @@ void Engine::DebugWireframeSettingsChanged(bool enabled) {
}
void Engine::CreateView(int64_t view_id,
ViewCallback on_view_created,
ViewIdCallback on_view_bound,
bool hit_testable,
bool focusable) {
@@ -633,18 +634,20 @@ void Engine::CreateView(int64_t view_id,
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask(
[this, view_id, hit_testable, focusable,
on_view_created = std::move(on_view_created),
on_view_bound = std::move(on_view_bound)]() {
#if defined(LEGACY_FUCHSIA_EMBEDDER)
if (use_legacy_renderer_) {
FML_CHECK(legacy_external_view_embedder_);
legacy_external_view_embedder_->CreateView(
view_id, std::move(on_view_bound), hit_testable, focusable);
view_id, std::move(on_view_created), std::move(on_view_bound),
hit_testable, focusable);
} else
#endif
{
FML_CHECK(external_view_embedder_);
external_view_embedder_->CreateView(view_id,
std::move(on_view_bound));
external_view_embedder_->CreateView(
view_id, std::move(on_view_created), std::move(on_view_bound));
external_view_embedder_->SetViewProperties(
view_id, SkRect::MakeEmpty(), hit_testable, focusable);
}

View File

@@ -109,6 +109,7 @@ class Engine final {
void DebugWireframeSettingsChanged(bool enabled);
void CreateView(int64_t view_id,
ViewCallback on_view_created,
ViewIdCallback on_view_bound,
bool hit_testable,
bool focusable);

View File

@@ -508,6 +508,7 @@ void FuchsiaExternalViewEmbedder::EnableWireframe(bool enable) {
}
void FuchsiaExternalViewEmbedder::CreateView(int64_t view_id,
ViewCallback on_view_created,
ViewIdCallback on_view_bound) {
FML_CHECK(scenic_views_.find(view_id) == scenic_views_.end());
@@ -519,6 +520,7 @@ void FuchsiaExternalViewEmbedder::CreateView(int64_t view_id,
scenic::ToViewHolderToken(zx::eventpair((zx_handle_t)view_id)),
"Flutter::PlatformView"),
};
on_view_created();
on_view_bound(new_view.view_holder.id());
new_view.opacity_node.SetLabel("flutter::PlatformView::OpacityMutator");

View File

@@ -32,6 +32,7 @@
namespace flutter_runner {
using ViewCallback = std::function<void()>;
using ViewIdCallback = std::function<void(scenic::ResourceId)>;
// This class orchestrates interaction with the Scenic compositor on Fuchsia. It
@@ -93,7 +94,9 @@ class FuchsiaExternalViewEmbedder final : public flutter::ExternalViewEmbedder {
// |SetViewProperties| doesn't manipulate the view directly -- it sets pending
// properties for the next |UpdateView| call.
void EnableWireframe(bool enable);
void CreateView(int64_t view_id, ViewIdCallback on_view_bound);
void CreateView(int64_t view_id,
ViewCallback on_view_created,
ViewIdCallback on_view_bound);
void DestroyView(int64_t view_id, ViewIdCallback on_view_unbound);
void SetViewProperties(int64_t view_id,
const SkRect& occlusion_hint,

View File

@@ -953,6 +953,18 @@ void PlatformView::HandleFlutterPlatformViewsChannelPlatformMessage(
}
const int64_t view_id_raw = view_id->value.GetUint64();
auto on_view_created = fml::MakeCopyable(
[weak = weak_factory_.GetWeakPtr(),
platform_task_runner = task_runners_.GetPlatformTaskRunner(),
message = std::move(message)]() {
// The client is waiting for view creation. Send an empty response
// back to signal the view was created.
if (message->response().get()) {
message->response()->Complete(
std::make_unique<fml::NonOwnedMapping>((const uint8_t*)"[0]",
3u));
}
});
auto on_view_bound =
[weak = weak_factory_.GetWeakPtr(),
platform_task_runner = task_runners_.GetPlatformTaskRunner(),
@@ -969,16 +981,9 @@ void PlatformView::HandleFlutterPlatformViewsChannelPlatformMessage(
weak->child_view_ids_[resource_id] = view_id;
});
};
on_create_view_callback_(view_id_raw, std::move(on_view_bound),
hit_testable->value.GetBool(),
focusable->value.GetBool());
// The client is waiting for view creation. Send an empty response back
// to signal the view was created.
if (message->response().get()) {
message->response()->Complete(
std::make_unique<fml::NonOwnedMapping>((const uint8_t*)"[0]", 3u));
}
on_create_view_callback_(
view_id_raw, std::move(on_view_created), std::move(on_view_bound),
hit_testable->value.GetBool(), focusable->value.GetBool());
} else if (method->value == "View.update") {
auto args_it = root.FindMember("args");
if (args_it == root.MemberEnd() || !args_it->value.IsObject()) {

View File

@@ -30,7 +30,8 @@
namespace flutter_runner {
using OnEnableWireframe = fit::function<void(bool)>;
using OnCreateView = fit::function<void(int64_t, ViewIdCallback, bool, bool)>;
using OnCreateView =
fit::function<void(int64_t, ViewCallback, ViewIdCallback, bool, bool)>;
using OnUpdateView = fit::function<void(int64_t, SkRect, bool, bool)>;
using OnDestroyView = fit::function<void(int64_t, ViewIdCallback)>;
using OnCreateSurface = fit::function<std::unique_ptr<flutter::Surface>()>;

View File

@@ -607,9 +607,11 @@ TEST_F(PlatformViewTests, CreateViewTest) {
bool create_view_called = false;
auto CreateViewCallback = [&create_view_called](
int64_t view_id,
flutter_runner::ViewCallback on_view_created,
flutter_runner::ViewIdCallback on_view_bound,
bool hit_testable, bool focusable) {
create_view_called = true;
on_view_created();
on_view_bound(0);
};
@@ -843,9 +845,11 @@ TEST_F(PlatformViewTests, ViewEventsTest) {
);
auto on_create_view = [kViewId](int64_t view_id,
flutter_runner::ViewCallback on_view_created,
flutter_runner::ViewIdCallback on_view_bound,
bool hit_testable, bool focusable) {
ASSERT_EQ(view_id, kViewId);
on_view_created();
on_view_bound(kViewHolderId);
};