Skip to content

Commit

Permalink
Add entity playground callback (flutter#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored and dnfield committed Apr 27, 2022
1 parent bafa73b commit 2373da8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 18 additions & 3 deletions impeller/entity/entity_playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions impeller/entity/entity_playground.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
#pragma once

#include "flutter/fml/macros.h"
#include "impeller/entity/content_context.h"
#include "impeller/entity/entity.h"
#include "impeller/playground/playground.h"

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);
};
Expand Down

0 comments on commit 2373da8

Please sign in to comment.