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
// Resolve any lingering tracked clips by assigning an arbitrarily high
34
// number. The number to assign just needs to be at least as high as larger
35
// any previously assigned clip depth in the scene. Normally, Aiks handles
36
// this correctly when wrapping up the base pass as an `impeller::Picture`.
37
entity_pass.
PopAllClips
(99999);
38
39
auto
callback = [&](
RenderTarget
& render_target) ->
bool
{
40
return
entity_pass.
Render
(content_context, render_target);
41
};
42
return
Playground::OpenPlaygroundHere
(callback);
43
}
44
45
std::shared_ptr<ContentContext>
EntityPlayground::GetContentContext
()
const
{
46
return
std::make_shared<ContentContext>(
GetContext
(), typographer_context_);
47
}
48
49
bool
EntityPlayground::OpenPlaygroundHere
(
Entity
entity) {
50
if
(!
switches_
.
enable_playground
) {
51
return
true
;
52
}
53
54
auto
content_context =
GetContentContext
();
55
if
(!content_context->IsValid()) {
56
return
false
;
57
}
58
SinglePassCallback
callback = [&](
RenderPass
& pass) ->
bool
{
59
content_context->GetRenderTargetCache()->Start();
60
bool
result = entity.
Render
(*content_context, pass);
61
content_context->GetRenderTargetCache()->End();
62
content_context->GetTransientsBuffer().Reset();
63
return
result;
64
};
65
return
Playground::OpenPlaygroundHere
(callback);
66
}
67
68
bool
EntityPlayground::OpenPlaygroundHere
(
EntityPlaygroundCallback
callback) {
69
if
(!
switches_
.
enable_playground
) {
70
return
true
;
71
}
72
73
ContentContext
content_context(
GetContext
(), typographer_context_);
74
if
(!content_context.
IsValid
()) {
75
return
false
;
76
}
77
SinglePassCallback
pass_callback = [&](
RenderPass
& pass) ->
bool
{
78
static
bool
wireframe =
false
;
79
if
(ImGui::IsKeyPressed(ImGuiKey_Z)) {
80
wireframe = !wireframe;
81
content_context.
SetWireframe
(wireframe);
82
}
83
content_context.
GetRenderTargetCache
()->Start();
84
bool
result = callback(content_context, pass);
85
content_context.
GetRenderTargetCache
()->End();
86
content_context.
GetTransientsBuffer
().
Reset
();
87
return
result;
88
};
89
return
Playground::OpenPlaygroundHere
(pass_callback);
90
}
91
92
}
// namespace impeller
impeller::EntityPass::PopAllClips
void PopAllClips(uint64_t depth)
Definition:
entity_pass.cc:141
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:188
impeller::EntityPass
Definition:
entity_pass.h:43
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition:
playground.h:117
impeller::RenderTarget
Definition:
render_target.h:38
impeller::TypographerContextSkia
Definition:
typographer_context_skia.h:12
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:33
content_context.h
impeller::ContentContext::GetRenderTargetCache
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
Definition:
content_context.h:805
impeller::EntityPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(Entity entity)
Definition:
entity_playground.cc:49
impeller::HostBuffer::Reset
void Reset()
Resets the contents of the HostBuffer to nothing so it can be reused.
Definition:
host_buffer.cc:189
impeller::EntityPass::Render
bool Render(ContentContext &renderer, const RenderTarget &render_target) const
Definition:
entity_pass.cc:376
impeller::ContentContext::SetWireframe
void SetWireframe(bool wireframe)
Definition:
content_context.cc:572
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Definition:
playground.cc:198
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:89
impeller::EntityPlayground::SetTypographerContext
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
Definition:
entity_playground.cc:18
impeller
Definition:
aiks_blur_unittests.cc:20
impeller::ContentContext::IsValid
bool IsValid() const
Definition:
content_context.cc:474
impeller::ContentContext
Definition:
content_context.h:392
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition:
switches.h:17
impeller::EntityPlayground::GetContentContext
std::shared_ptr< ContentContext > GetContentContext() const
Definition:
entity_playground.cc:45
impeller::ContentContext::GetTransientsBuffer
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
Definition:
content_context.h:833
entity_playground.h
impeller
entity
entity_playground.cc
Generated by
1.8.17