| Flutter Impeller |

aiks_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/aiks/aiks_playground.h"
6
7 #include <memory>
8
9 #include "impeller/aiks/aiks_context.h"
10 #include "impeller/typographer/backends/skia/typographer_context_skia.h"
11 #include "impeller/typographer/typographer_context.h"
12
13 namespace impeller {
14
15 AiksPlayground::AiksPlayground()
16 : typographer_context_(TypographerContextSkia::Make()) {}
17
18 AiksPlayground::~AiksPlayground() = default;
19
20 void AiksPlayground::SetTypographerContext(
21 std::shared_ptr<TypographerContext> typographer_context) {
22 typographer_context_ = std::move(typographer_context);
23 }
24
25 void AiksPlayground::TearDown() {
26 inspector_.HackResetDueToTextureLeaks();
27 PlaygroundTest::TearDown();
28 }
29
30 bool AiksPlayground::OpenPlaygroundHere(Picture picture) {
31 return OpenPlaygroundHere([&picture](AiksContext& renderer) -> Picture {
32 return std::move(picture);
33 });
34 }
35
36 bool AiksPlayground::OpenPlaygroundHere(AiksPlaygroundCallback callback) {
37 if (!switches_.enable_playground) {
38 return true;
39 }
40
41 AiksContext renderer(GetContext(), typographer_context_);
42
43 if (!renderer.IsValid()) {
44 return false;
45 }
46
47 return Playground::OpenPlaygroundHere(
48 [this, &renderer, &callback](RenderTarget& render_target) -> bool {
49 const std::optional<Picture>& picture = inspector_.RenderInspector(
50 renderer, [&]() { return callback(renderer); });
51
52 if (!picture.has_value()) {
53 return false;
54 }
55 return renderer.Render(*picture, render_target, true);
56 });
57 }
58
59 bool AiksPlayground::ImGuiBegin(const char* name,
60 bool* p_open,
61 ImGuiWindowFlags flags) {
62 ImGui::Begin(name, p_open, flags);
63 return true;
64 }
65
66 } // namespace impeller
impeller::AiksContext
Definition: aiks_context.h:20
impeller::AiksInspector::RenderInspector
const std::optional< Picture > & RenderInspector(AiksContext &aiks_context, const std::function< std::optional< Picture >()> &picture_callback)
Definition: aiks_playground_inspector.cc:25
impeller::AiksInspector::HackResetDueToTextureLeaks
void HackResetDueToTextureLeaks()
Definition: aiks_playground_inspector.cc:66
aiks_context.h
impeller::AiksContext::Render
bool Render(const Picture &picture, RenderTarget &render_target, bool reset_host_buffer)
Definition: aiks_context.cc:48
typographer_context.h
impeller::AiksPlayground::AiksPlayground
AiksPlayground()
Definition: aiks_playground.cc:15
impeller::AiksPlayground::SetTypographerContext
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
Definition: aiks_playground.cc:20
typographer_context_skia.h
impeller::AiksPlayground::TearDown
void TearDown() override
Definition: aiks_playground.cc:25
impeller::Picture
Definition: picture.h:20
impeller::AiksPlayground::AiksPlaygroundCallback
std::function< std::optional< Picture >(AiksContext &renderer)> AiksPlaygroundCallback
Definition: aiks_playground.h:21
impeller::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:39
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
aiks_playground.h
impeller::AiksPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(Picture picture)
Definition: aiks_playground.cc:30
impeller::AiksPlayground::ImGuiBegin
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
Definition: aiks_playground.cc:59
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Definition: playground.cc:198
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:89
impeller::AiksPlayground::~AiksPlayground
~AiksPlayground()
impeller
Definition: aiks_blur_unittests.cc:20
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition: switches.h:17
impeller::AiksContext::IsValid
bool IsValid() const
Definition: aiks_context.cc:36