Add entity playground callback (flutter/engine#27)

This commit is contained in:
Brandon DeRosier 2022-02-24 15:01:18 -08:00 committed by Dan Field
parent 55b7b49549
commit 1b50769d71
2 changed files with 24 additions and 3 deletions

View File

@ -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

View File

@ -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<bool(ContentContext& context, RenderPass& pass)>;
EntityPlayground();
~EntityPlayground();
bool OpenPlaygroundHere(Entity entity);
bool OpenPlaygroundHere(EntityPlaygroundCallback callback);
private:
FML_DISALLOW_COPY_AND_ASSIGN(EntityPlayground);
};