| Flutter Impeller |

entity_playground.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/entity/entity_playground.h"
6
7 #include "impeller/entity/contents/content_context.h"
8 #include "impeller/typographer/backends/skia/typographer_context_skia.h"
9 #include "third_party/imgui/imgui.h"
10
11 namespace impeller {
12
13 EntityPlayground::EntityPlayground()
14 : typographer_context_(TypographerContextSkia::Make()) {}
15
16 EntityPlayground::~EntityPlayground() = default;
17
18 void EntityPlayground::SetTypographerContext(
19 std::shared_ptr<TypographerContext> typographer_context) {
20 typographer_context_ = std::move(typographer_context);
21 }
22
23 bool EntityPlayground::OpenPlaygroundHere(EntityPass& entity_pass) {
24 if (!switches_.enable_playground) {
25 return true;
26 }
27
28 ContentContext content_context(GetContext(), typographer_context_);
29 if (!content_context.IsValid()) {
30 return false;
31 }
32
33 auto callback = [&](RenderTarget& render_target) -> bool {
34 return entity_pass.Render(content_context, render_target);
35 };
36 return Playground::OpenPlaygroundHere(callback);
37 }
38
39 std::shared_ptr<ContentContext> EntityPlayground::GetContentContext() const {
40 return std::make_shared<ContentContext>(GetContext(), typographer_context_);
41 }
42
43 bool EntityPlayground::OpenPlaygroundHere(Entity entity) {
44 if (!switches_.enable_playground) {
45 return true;
46 }
47
48 auto content_context = GetContentContext();
49 if (!content_context->IsValid()) {
50 return false;
51 }
52 SinglePassCallback callback = [&](RenderPass& pass) -> bool {
53 return entity.Render(*content_context, pass);
54 };
55 return Playground::OpenPlaygroundHere(callback);
56 }
57
58 bool EntityPlayground::OpenPlaygroundHere(EntityPlaygroundCallback callback) {
59 if (!switches_.enable_playground) {
60 return true;
61 }
62
63 ContentContext content_context(GetContext(), typographer_context_);
64 if (!content_context.IsValid()) {
65 return false;
66 }
67 SinglePassCallback pass_callback = [&](RenderPass& pass) -> bool {
68 static bool wireframe = false;
69 if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
70 wireframe = !wireframe;
71 content_context.SetWireframe(wireframe);
72 }
73 return callback(content_context, pass);
74 };
75 return Playground::OpenPlaygroundHere(pass_callback);
76 }
77
78 } // namespace impeller
impeller::EntityPlayground::~EntityPlayground
~EntityPlayground()
typographer_context_skia.h
impeller::Entity
Definition: entity.h:21
impeller::Entity::Render
bool Render(const ContentContext &renderer, RenderPass &parent_pass) const
Definition: entity.cc:159
impeller::EntityPass
Definition: entity_pass.h:26
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:115
impeller::RenderTarget
Definition: render_target.h:49
impeller::TypographerContextSkia
Definition: typographer_context_skia.h:13
impeller::Playground::SinglePassCallback
std::function< bool(RenderPass &pass)> SinglePassCallback
Definition: playground.h:52
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
content_context.h
impeller::EntityPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(Entity entity)
Definition: entity_playground.cc:43
impeller::EntityPass::Render
bool Render(ContentContext &renderer, const RenderTarget &render_target) const
Definition: entity_pass.cc:301
impeller::ContentContext::SetWireframe
void SetWireframe(bool wireframe)
Definition: content_context.cc:487
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Definition: playground.cc:189
impeller::EntityPlayground::EntityPlaygroundCallback
std::function< bool(ContentContext &context, RenderPass &pass)> EntityPlaygroundCallback
Definition: entity_playground.h:21
impeller::EntityPlayground::EntityPlayground
EntityPlayground()
Definition: entity_playground.cc:13
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:86
impeller::EntityPlayground::SetTypographerContext
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
Definition: entity_playground.cc:18
impeller
Definition: aiks_context.cc:10
impeller::ContentContext::IsValid
bool IsValid() const
Definition: content_context.cc:406
impeller::ContentContext
Definition: content_context.h:332
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition: switches.h:17
impeller::EntityPlayground::GetContentContext
std::shared_ptr< ContentContext > GetContentContext() const
Definition: entity_playground.cc:39
entity_playground.h