| 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 #include "third_party/imgui/imgui.h"
13
14 namespace impeller {
15
16 AiksPlayground::AiksPlayground()
17 : typographer_context_(TypographerContextSkia::Make()) {}
18
19 AiksPlayground::~AiksPlayground() = default;
20
21 void AiksPlayground::SetTypographerContext(
22 std::shared_ptr<TypographerContext> typographer_context) {
23 typographer_context_ = std::move(typographer_context);
24 }
25
26 void AiksPlayground::TearDown() {
27 inspector_.HackResetDueToTextureLeaks();
28 PlaygroundTest::TearDown();
29 }
30
31 bool AiksPlayground::OpenPlaygroundHere(Picture picture) {
32 return OpenPlaygroundHere([&picture](AiksContext& renderer) -> Picture {
33 return std::move(picture);
34 });
35 }
36
37 bool AiksPlayground::OpenPlaygroundHere(AiksPlaygroundCallback callback) {
38 if (!switches_.enable_playground) {
39 return true;
40 }
41
42 AiksContext renderer(GetContext(), typographer_context_);
43
44 if (!renderer.IsValid()) {
45 return false;
46 }
47
48 return Playground::OpenPlaygroundHere(
49 [this, &renderer, &callback](RenderTarget& render_target) -> bool {
50 const std::optional<Picture>& picture = inspector_.RenderInspector(
51 renderer, [&]() { return callback(renderer); });
52
53 if (!picture.has_value()) {
54 return false;
55 }
56 return renderer.Render(*picture, render_target);
57 });
58 }
59
60 } // 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
typographer_context.h
impeller::AiksPlayground::AiksPlayground
AiksPlayground()
Definition: aiks_playground.cc:16
impeller::AiksPlayground::SetTypographerContext
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
Definition: aiks_playground.cc:21
typographer_context_skia.h
impeller::AiksPlayground::TearDown
void TearDown() override
Definition: aiks_playground.cc:26
impeller::Picture
Definition: picture.h:19
impeller::AiksPlayground::AiksPlaygroundCallback
std::function< std::optional< Picture >(AiksContext &renderer)> AiksPlaygroundCallback
Definition: aiks_playground.h:19
impeller::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:39
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:91
impeller::RenderTarget
Definition: render_target.h:48
impeller::TypographerContextSkia
Definition: typographer_context_skia.h:12
aiks_playground.h
impeller::AiksPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(Picture picture)
Definition: aiks_playground.cc:31
impeller::AiksContext::Render
bool Render(const Picture &picture, RenderTarget &render_target)
Definition: aiks_context.cc:43
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Definition: playground.cc:189
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:86
impeller::AiksPlayground::~AiksPlayground
~AiksPlayground()
impeller
Definition: aiks_context.cc:10
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition: switches.h:16
impeller::AiksContext::IsValid
bool IsValid() const
Definition: aiks_context.cc:31