mirror of
https://github.com/encounter/engine.git
synced 2026-03-30 11:09:55 -07:00
[flutter_runner] Port Expose ViewBound Wireframe Functionality (#11635)
Expose scenic's ability to toggle wireframe debug rendering of view bounds in flutter_runner. This is done by registering a new function on the platform_views channel with the PlatformView. Note: Unittests have not been enabled, will enable once we have sufficient infra. SCN-1351 #done Change-Id: Id4c8ef65cc39a967087d7fa6c9f595da8cfe5f01
This commit is contained in:
@@ -83,6 +83,10 @@ void CompositorContext::OnSessionSizeChangeHint(float width_change_factor,
|
||||
height_change_factor);
|
||||
}
|
||||
|
||||
void CompositorContext::OnWireframeEnabled(bool enabled) {
|
||||
session_connection_.set_enable_wireframe(enabled);
|
||||
}
|
||||
|
||||
CompositorContext::~CompositorContext() = default;
|
||||
|
||||
std::unique_ptr<flutter::CompositorContext::ScopedFrame>
|
||||
|
||||
@@ -32,6 +32,8 @@ class CompositorContext final : public flutter::CompositorContext {
|
||||
void OnSessionSizeChangeHint(float width_change_factor,
|
||||
float height_change_factor);
|
||||
|
||||
void OnWireframeEnabled(bool enabled);
|
||||
|
||||
private:
|
||||
const std::string debug_label_;
|
||||
SessionConnection session_connection_;
|
||||
|
||||
@@ -87,6 +87,9 @@ Engine::Engine(Delegate& delegate,
|
||||
std::bind(&Engine::OnSessionSizeChangeHint, this, std::placeholders::_1,
|
||||
std::placeholders::_2);
|
||||
|
||||
OnEnableWireframe on_enable_wireframe_callback = std::bind(
|
||||
&Engine::OnDebugWireframeSettingsChanged, this, std::placeholders::_1);
|
||||
|
||||
// SessionListener has a OnScenicError method; invoke this callback on the
|
||||
// platform thread when that happens. The Session itself should also be
|
||||
// disconnected when this happens, and it will also attempt to terminate.
|
||||
@@ -113,6 +116,8 @@ Engine::Engine(Delegate& delegate,
|
||||
std::move(on_session_metrics_change_callback),
|
||||
on_session_size_change_hint_callback =
|
||||
std::move(on_session_size_change_hint_callback),
|
||||
on_enable_wireframe_callback =
|
||||
std::move(on_enable_wireframe_callback),
|
||||
vsync_handle = vsync_event_.get()](flutter::Shell& shell) mutable {
|
||||
return std::make_unique<flutter_runner::PlatformView>(
|
||||
shell, // delegate
|
||||
@@ -123,6 +128,7 @@ Engine::Engine(Delegate& delegate,
|
||||
std::move(on_session_listener_error_callback),
|
||||
std::move(on_session_metrics_change_callback),
|
||||
std::move(on_session_size_change_hint_callback),
|
||||
std::move(on_enable_wireframe_callback),
|
||||
vsync_handle // vsync handle
|
||||
);
|
||||
});
|
||||
@@ -412,6 +418,23 @@ void Engine::OnSessionMetricsDidChange(
|
||||
});
|
||||
}
|
||||
|
||||
void Engine::OnDebugWireframeSettingsChanged(bool enabled) {
|
||||
if (!shell_) {
|
||||
return;
|
||||
}
|
||||
|
||||
shell_->GetTaskRunners().GetGPUTaskRunner()->PostTask(
|
||||
[rasterizer = shell_->GetRasterizer(), enabled]() {
|
||||
if (rasterizer) {
|
||||
auto compositor_context =
|
||||
reinterpret_cast<flutter_runner::CompositorContext*>(
|
||||
rasterizer->compositor_context());
|
||||
|
||||
compositor_context->OnWireframeEnabled(enabled);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Engine::OnSessionSizeChangeHint(float width_change_factor,
|
||||
float height_change_factor) {
|
||||
if (!shell_) {
|
||||
|
||||
@@ -67,6 +67,8 @@ class Engine final {
|
||||
void OnSessionSizeChangeHint(float width_change_factor,
|
||||
float height_change_factor);
|
||||
|
||||
void OnDebugWireframeSettingsChanged(bool enabled);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Engine);
|
||||
};
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ static constexpr char kFlutterPlatformChannel[] = "flutter/platform";
|
||||
static constexpr char kTextInputChannel[] = "flutter/textinput";
|
||||
static constexpr char kKeyEventChannel[] = "flutter/keyevent";
|
||||
static constexpr char kAccessibilityChannel[] = "flutter/accessibility";
|
||||
static constexpr char kFlutterPlatformViewsChannel[] = "flutter/platform_views";
|
||||
|
||||
// FL(77): Terminate engine if Fuchsia system FIDL connections have error.
|
||||
template <class T>
|
||||
@@ -86,6 +87,7 @@ PlatformView::PlatformView(
|
||||
fit::closure session_listener_error_callback,
|
||||
OnMetricsUpdate session_metrics_did_change_callback,
|
||||
OnSizeChangeHint session_size_change_hint_callback,
|
||||
OnEnableWireframe wireframe_enabled_callback,
|
||||
zx_handle_t vsync_event_handle)
|
||||
: flutter::PlatformView(delegate, std::move(task_runners)),
|
||||
debug_label_(std::move(debug_label)),
|
||||
@@ -94,6 +96,7 @@ PlatformView::PlatformView(
|
||||
std::move(session_listener_error_callback)),
|
||||
metrics_changed_callback_(std::move(session_metrics_did_change_callback)),
|
||||
size_change_hint_callback_(std::move(session_size_change_hint_callback)),
|
||||
wireframe_enabled_callback_(std::move(wireframe_enabled_callback)),
|
||||
ime_client_(this),
|
||||
surface_(std::make_unique<Surface>(debug_label_)),
|
||||
vsync_event_handle_(vsync_event_handle) {
|
||||
@@ -136,6 +139,9 @@ void PlatformView::RegisterPlatformMessageHandlers() {
|
||||
platform_message_handlers_[kAccessibilityChannel] =
|
||||
std::bind(&PlatformView::HandleAccessibilityChannelPlatformMessage, this,
|
||||
std::placeholders::_1);
|
||||
platform_message_handlers_[kFlutterPlatformViewsChannel] =
|
||||
std::bind(&PlatformView::HandleFlutterPlatformViewsChannelPlatformMessage,
|
||||
this, std::placeholders::_1);
|
||||
}
|
||||
|
||||
void PlatformView::OnPropertiesChanged(
|
||||
@@ -730,4 +736,41 @@ void PlatformView::HandleFlutterTextInputChannelPlatformMessage(
|
||||
}
|
||||
}
|
||||
|
||||
void PlatformView::HandleFlutterPlatformViewsChannelPlatformMessage(
|
||||
fml::RefPtr<flutter::PlatformMessage> message) {
|
||||
FML_DCHECK(message->channel() == kFlutterPlatformViewsChannel);
|
||||
const auto& data = message->data();
|
||||
rapidjson::Document document;
|
||||
document.Parse(reinterpret_cast<const char*>(data.data()), data.size());
|
||||
if (document.HasParseError() || !document.IsObject()) {
|
||||
FML_LOG(ERROR) << "Could not parse document";
|
||||
return;
|
||||
}
|
||||
auto root = document.GetObject();
|
||||
auto method = root.FindMember("method");
|
||||
if (method == root.MemberEnd() || !method->value.IsString()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (method->value == "View.enableWireframe") {
|
||||
auto args_it = root.FindMember("args");
|
||||
if (args_it == root.MemberEnd() || !args_it->value.IsObject()) {
|
||||
FML_LOG(ERROR) << "No arguments found.";
|
||||
return;
|
||||
}
|
||||
const auto& args = args_it->value;
|
||||
|
||||
auto enable = args.FindMember("enable");
|
||||
if (!enable->value.IsBool()) {
|
||||
FML_LOG(ERROR) << "Argument 'enable' is not a bool";
|
||||
return;
|
||||
}
|
||||
|
||||
wireframe_enabled_callback_(enable->value.GetBool());
|
||||
} else {
|
||||
FML_DLOG(ERROR) << "Unknown " << message->channel() << " method "
|
||||
<< method->value.GetString();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace flutter_runner
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace flutter_runner {
|
||||
using OnMetricsUpdate = fit::function<void(const fuchsia::ui::gfx::Metrics&)>;
|
||||
using OnSizeChangeHint =
|
||||
fit::function<void(float width_change_factor, float height_change_factor)>;
|
||||
using OnEnableWireframe = fit::function<void(bool)>;
|
||||
|
||||
// The per engine component residing on the platform thread is responsible for
|
||||
// all platform specific integrations.
|
||||
@@ -48,6 +49,7 @@ class PlatformView final : public flutter::PlatformView,
|
||||
fit::closure on_session_listener_error_callback,
|
||||
OnMetricsUpdate session_metrics_did_change_callback,
|
||||
OnSizeChangeHint session_size_change_hint_callback,
|
||||
OnEnableWireframe wireframe_enabled_callback,
|
||||
zx_handle_t vsync_event_handle);
|
||||
PlatformView(PlatformView::Delegate& delegate,
|
||||
std::string debug_label,
|
||||
@@ -67,6 +69,7 @@ class PlatformView final : public flutter::PlatformView,
|
||||
fit::closure session_listener_error_callback_;
|
||||
OnMetricsUpdate metrics_changed_callback_;
|
||||
OnSizeChangeHint size_change_hint_callback_;
|
||||
OnEnableWireframe wireframe_enabled_callback_;
|
||||
|
||||
int current_text_input_client_ = 0;
|
||||
fidl::Binding<fuchsia::ui::input::InputMethodEditorClient> ime_client_;
|
||||
@@ -160,6 +163,10 @@ class PlatformView final : public flutter::PlatformView,
|
||||
void HandleFlutterTextInputChannelPlatformMessage(
|
||||
fml::RefPtr<flutter::PlatformMessage> message);
|
||||
|
||||
// Channel handler for kPlatformViewsChannel.
|
||||
void HandleFlutterPlatformViewsChannelPlatformMessage(
|
||||
fml::RefPtr<flutter::PlatformMessage> message);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(PlatformView);
|
||||
};
|
||||
|
||||
|
||||
@@ -79,6 +79,11 @@ void SessionConnection::OnSessionSizeChangeHint(float width_change_factor,
|
||||
height_change_factor);
|
||||
}
|
||||
|
||||
void SessionConnection::set_enable_wireframe(bool enable) {
|
||||
session_wrapper_.Enqueue(
|
||||
scenic::NewSetEnableDebugViewBoundsCmd(root_view_.id(), enable));
|
||||
}
|
||||
|
||||
void SessionConnection::EnqueueClearOps() {
|
||||
// We are going to be sending down a fresh node hierarchy every frame. So just
|
||||
// enqueue a detach op on the imported root node.
|
||||
|
||||
@@ -48,6 +48,8 @@ class SessionConnection final {
|
||||
fidl::MakeOptional(std::move(metrics_copy)));
|
||||
}
|
||||
|
||||
void set_enable_wireframe(bool enable);
|
||||
|
||||
flutter::SceneUpdateContext& scene_update_context() {
|
||||
return scene_update_context_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user