From 1b50769d713a2eaed6779589d4e2ca69b1df3e25 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Thu, 24 Feb 2022 15:01:18 -0800 Subject: [PATCH] Add entity playground callback (flutter/engine#27) --- .../impeller/entity/entity_playground.cc | 21 ++++++++++++++++--- .../impeller/entity/entity_playground.h | 6 ++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/impeller/entity/entity_playground.cc b/engine/src/flutter/impeller/entity/entity_playground.cc index 4c76be6088b..e65451ac865 100644 --- a/engine/src/flutter/impeller/entity/entity_playground.cc +++ b/engine/src/flutter/impeller/entity/entity_playground.cc @@ -17,14 +17,29 @@ bool EntityPlayground::OpenPlaygroundHere(Entity entity) { return true; } - ContentContext context_context(GetContext()); - if (!context_context.IsValid()) { + ContentContext content_context(GetContext()); + if (!content_context.IsValid()) { return false; } Renderer::RenderCallback callback = [&](RenderPass& pass) -> bool { - return entity.Render(context_context, pass); + return entity.Render(content_context, pass); }; return Playground::OpenPlaygroundHere(callback); } +bool EntityPlayground::OpenPlaygroundHere(EntityPlaygroundCallback callback) { + if (!Playground::is_enabled()) { + return true; + } + + ContentContext content_context(GetContext()); + if (!content_context.IsValid()) { + return false; + } + Renderer::RenderCallback render_callback = [&](RenderPass& pass) -> bool { + return callback(content_context, pass); + }; + return Playground::OpenPlaygroundHere(render_callback); +} + } // namespace impeller diff --git a/engine/src/flutter/impeller/entity/entity_playground.h b/engine/src/flutter/impeller/entity/entity_playground.h index 9d16caab30a..c506b72dc53 100644 --- a/engine/src/flutter/impeller/entity/entity_playground.h +++ b/engine/src/flutter/impeller/entity/entity_playground.h @@ -5,6 +5,7 @@ #pragma once #include "flutter/fml/macros.h" +#include "impeller/entity/content_context.h" #include "impeller/entity/entity.h" #include "impeller/playground/playground.h" @@ -12,12 +13,17 @@ namespace impeller { class EntityPlayground : public Playground { public: + using EntityPlaygroundCallback = + std::function; + EntityPlayground(); ~EntityPlayground(); bool OpenPlaygroundHere(Entity entity); + bool OpenPlaygroundHere(EntityPlaygroundCallback callback); + private: FML_DISALLOW_COPY_AND_ASSIGN(EntityPlayground); };