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 
6 
9 #include "third_party/imgui/imgui.h"
10 
11 namespace impeller {
12 
14  : typographer_context_(TypographerContextSkia::Make()) {}
15 
17 
19  std::shared_ptr<TypographerContext> typographer_context) {
20  typographer_context_ = std::move(typographer_context);
21 }
22 
23 std::shared_ptr<ContentContext> EntityPlayground::GetContentContext() const {
24  return std::make_shared<ContentContext>(GetContext(), typographer_context_);
25 }
26 
29  return true;
30  }
31 
32  auto content_context = GetContentContext();
33  if (!content_context->IsValid()) {
34  return false;
35  }
36  SinglePassCallback callback = [&](RenderPass& pass) -> bool {
37  content_context->GetRenderTargetCache()->Start();
38  bool result = entity.Render(*content_context, pass);
39  content_context->GetRenderTargetCache()->End();
40  content_context->GetTransientsBuffer().Reset();
41  return result;
42  };
43  return Playground::OpenPlaygroundHere(callback);
44 }
45 
48  return true;
49  }
50 
51  ContentContext content_context(GetContext(), typographer_context_);
52  if (!content_context.IsValid()) {
53  return false;
54  }
55  SinglePassCallback pass_callback = [&](RenderPass& pass) -> bool {
56  static bool wireframe = false;
57  if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
58  wireframe = !wireframe;
59  content_context.SetWireframe(wireframe);
60  }
61  content_context.GetRenderTargetCache()->Start();
62  bool result = callback(content_context, pass);
63  content_context.GetRenderTargetCache()->End();
64  content_context.GetTransientsBuffer().Reset();
65  return result;
66  };
67  return Playground::OpenPlaygroundHere(pass_callback);
68 }
69 
70 } // namespace impeller
impeller::EntityPlayground::~EntityPlayground
~EntityPlayground()
typographer_context_skia.h
impeller::Entity
Definition: entity.h:20
impeller::Entity::Render
bool Render(const ContentContext &renderer, RenderPass &parent_pass) const
Definition: entity.cc:156
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const RenderCallback &render_callback)
Definition: playground.cc:197
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:121
impeller::TypographerContextSkia
Definition: typographer_context_skia.h:12
impeller::Playground::SinglePassCallback
std::function< bool(RenderPass &pass)> SinglePassCallback
Definition: playground.h:49
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
content_context.h
impeller::ContentContext::GetRenderTargetCache
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
Definition: content_context.h:725
impeller::EntityPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(Entity entity)
Definition: entity_playground.cc:27
impeller::HostBuffer::Reset
void Reset()
Resets the contents of the HostBuffer to nothing so it can be reused.
Definition: host_buffer.cc:208
impeller::ContentContext::SetWireframe
void SetWireframe(bool wireframe)
Definition: content_context.cc:558
impeller::EntityPlayground::EntityPlaygroundCallback
std::function< bool(ContentContext &context, RenderPass &pass)> EntityPlaygroundCallback
Definition: entity_playground.h:19
impeller::EntityPlayground::EntityPlayground
EntityPlayground()
Definition: entity_playground.cc:13
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:90
impeller::EntityPlayground::SetTypographerContext
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
Definition: entity_playground.cc:18
impeller
Definition: allocation.cc:12
impeller::ContentContext::IsValid
bool IsValid() const
Definition: content_context.cc:470
impeller::ContentContext
Definition: content_context.h:366
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition: switches.h:16
impeller::EntityPlayground::GetContentContext
std::shared_ptr< ContentContext > GetContentContext() const
Definition: entity_playground.cc:23
impeller::ContentContext::GetTransientsBuffer
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
Definition: content_context.h:753
entity_playground.h