| 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 bool EntityPlayground::OpenPlaygroundHere(Entity entity) {
40 if (!switches_.enable_playground) {
41 return true;
42 }
43
44 ContentContext content_context(GetContext(), typographer_context_);
45 if (!content_context.IsValid()) {
46 return false;
47 }
48 SinglePassCallback callback = [&](RenderPass& pass) -> bool {
49 return entity.Render(content_context, pass);
50 };
51 return Playground::OpenPlaygroundHere(callback);
52 }
53
54 bool EntityPlayground::OpenPlaygroundHere(EntityPlaygroundCallback callback) {
55 if (!switches_.enable_playground) {
56 return true;
57 }
58
59 ContentContext content_context(GetContext(), typographer_context_);
60 if (!content_context.IsValid()) {
61 return false;
62 }
63 SinglePassCallback pass_callback = [&](RenderPass& pass) -> bool {
64 static bool wireframe = false;
65 if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
66 wireframe = !wireframe;
67 content_context.SetWireframe(wireframe);
68 }
69 return callback(content_context, pass);
70 };
71 return Playground::OpenPlaygroundHere(pass_callback);
72 }
73
74 } // 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:91
impeller::RenderTarget
Definition: render_target.h:48
impeller::TypographerContextSkia
Definition: typographer_context_skia.h:12
impeller::Playground::SinglePassCallback
std::function< bool(RenderPass &pass)> SinglePassCallback
Definition: playground.h:35
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
content_context.h
impeller::EntityPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(Entity entity)
Definition: entity_playground.cc:39
impeller::EntityPass::Render
bool Render(ContentContext &renderer, const RenderTarget &render_target) const
Definition: entity_pass.cc:323
impeller::ContentContext::SetWireframe
void SetWireframe(bool wireframe)
Definition: content_context.cc:448
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:20
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:369
impeller::ContentContext
Definition: content_context.h:344
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition: switches.h:16
entity_playground.h