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<TypographerContext> EntityPlayground::GetTypographerContext()
24  const {
25  return typographer_context_;
26 }
27 
28 std::shared_ptr<ContentContext> EntityPlayground::GetContentContext() const {
29  return std::make_shared<ContentContext>(GetContext(), typographer_context_);
30 }
31 
34  return true;
35  }
36 
37  auto content_context = GetContentContext();
38  if (!content_context->IsValid()) {
39  return false;
40  }
41  SinglePassCallback callback = [&](RenderPass& pass) -> bool {
42  content_context->GetRenderTargetCache()->Start();
43  bool result = entity.Render(*content_context, pass);
44  content_context->GetRenderTargetCache()->End();
45  content_context->GetTransientsBuffer().Reset();
46  return result;
47  };
48  return Playground::OpenPlaygroundHere(callback);
49 }
50 
53  return true;
54  }
55 
56  ContentContext content_context(GetContext(), typographer_context_);
57  if (!content_context.IsValid()) {
58  return false;
59  }
60  SinglePassCallback pass_callback = [&](RenderPass& pass) -> bool {
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
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
bool Render(const ContentContext &renderer, RenderPass &parent_pass) const
Definition: entity.cc:144
bool OpenPlaygroundHere(Entity entity)
std::shared_ptr< ContentContext > GetContentContext() const
std::shared_ptr< TypographerContext > GetTypographerContext() const
std::function< bool(ContentContext &context, RenderPass &pass)> EntityPlaygroundCallback
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
void Reset()
Resets the contents of the HostBuffer to nothing so it can be reused.
Definition: host_buffer.cc:229
bool OpenPlaygroundHere(const RenderCallback &render_callback)
Definition: playground.cc:201
std::function< bool(RenderPass &pass)> SinglePassCallback
Definition: playground.h:50
const PlaygroundSwitches switches_
Definition: playground.h:131
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:91
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30