| 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 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
32 bool EntityPlayground::OpenPlaygroundHere(Entity entity) {
33 if (!switches_.enable_playground) {
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->GetTransientsDataBuffer().Reset();
46 content_context->GetTransientsIndexesBuffer().Reset();
47 return result;
48 };
49 return Playground::OpenPlaygroundHere(callback);
50 }
51
52 bool EntityPlayground::OpenPlaygroundHere(EntityPlaygroundCallback callback) {
53 if (!switches_.enable_playground) {
54 return true;
55 }
56
57 ContentContext content_context(GetContext(), typographer_context_);
58 if (!content_context.IsValid()) {
59 return false;
60 }
61 SinglePassCallback pass_callback = [&](RenderPass& pass) -> bool {
62 content_context.GetRenderTargetCache()->Start();
63 bool result = callback(content_context, pass);
64 content_context.GetRenderTargetCache()->End();
65 content_context.GetTransientsDataBuffer().Reset();
66 content_context.GetTransientsIndexesBuffer().Reset();
67 return result;
68 };
69 return Playground::OpenPlaygroundHere(pass_callback);
70 }
71
72 } // namespace impeller
impeller::ContentContext
Definition: content_context.h:122
impeller::ContentContext::GetTransientsIndexesBuffer
HostBuffer & GetTransientsIndexesBuffer() const
Retrieve the current host buffer for transient storage of indexes used for indexed draws.
Definition: content_context.h:290
impeller::ContentContext::GetTransientsDataBuffer
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
Definition: content_context.h:299
impeller::ContentContext::GetRenderTargetCache
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
Definition: content_context.h:258
impeller::ContentContext::IsValid
bool IsValid() const
Definition: content_context.cc:876
impeller::Entity
Definition: entity.h:26
impeller::Entity::Render
bool Render(const ContentContext &renderer, RenderPass &parent_pass) const
Definition: entity.cc:145
impeller::EntityPlayground::~EntityPlayground
~EntityPlayground()
impeller::EntityPlayground::EntityPlayground
EntityPlayground()
Definition: entity_playground.cc:13
impeller::EntityPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(Entity entity)
Definition: entity_playground.cc:32
impeller::EntityPlayground::GetContentContext
std::shared_ptr< ContentContext > GetContentContext() const
Definition: entity_playground.cc:28
impeller::EntityPlayground::GetTypographerContext
std::shared_ptr< TypographerContext > GetTypographerContext() const
Definition: entity_playground.cc:23
impeller::EntityPlayground::EntityPlaygroundCallback
std::function< bool(ContentContext &context, RenderPass &pass)> EntityPlaygroundCallback
Definition: entity_playground.h:19
impeller::EntityPlayground::SetTypographerContext
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
Definition: entity_playground.cc:18
impeller::HostBuffer::Reset
void Reset()
Resets the contents of the HostBuffer to nothing so it can be reused.
Definition: host_buffer.cc:229
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const RenderCallback &render_callback)
Definition: playground.cc:201
impeller::Playground::SinglePassCallback
std::function< bool(RenderPass &pass)> SinglePassCallback
Definition: playground.h:50
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:131
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:91
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
impeller::TypographerContextSkia
Definition: typographer_context_skia.h:12
content_context.h
entity_playground.h
impeller
Definition: allocation.cc:12
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition: switches.h:17
typographer_context_skia.h