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 
6 
7 #include <memory>
8 #include <optional>
9 
14 
15 namespace impeller {
16 
18  : typographer_context_(TypographerContextSkia::Make()) {}
19 
21 
23  std::shared_ptr<TypographerContext> typographer_context) {
24  typographer_context_ = std::move(typographer_context);
25 }
26 
29 }
30 
33  return true;
34  }
35 
36  AiksContext renderer(GetContext(), typographer_context_);
37 
38  if (!renderer.IsValid()) {
39  return false;
40  }
41 
43  [&renderer, &picture](RenderTarget& render_target) -> bool {
44  return renderer.Render(picture, render_target, true);
45  });
46 }
47 
50  return true;
51  }
52 
53  AiksContext renderer(GetContext(), typographer_context_);
54 
55  if (!renderer.IsValid()) {
56  return false;
57  }
58 
60  [&renderer, &callback](RenderTarget& render_target) -> bool {
61  std::optional<Picture> picture = callback(renderer);
62  if (!picture.has_value()) {
63  return false;
64  }
65  return renderer.Render(*picture, render_target, true);
66  });
67 }
68 
69 bool AiksPlayground::ImGuiBegin(const char* name,
70  bool* p_open,
71  ImGuiWindowFlags flags) {
72  ImGui::Begin(name, p_open, flags);
73  return true;
74 }
75 
77  const sk_sp<flutter::DisplayList>& list) {
78  DlDispatcher dispatcher;
79  list->Dispatch(dispatcher);
80  Picture picture = dispatcher.EndRecordingAsPicture();
81  return OpenPlaygroundHere(std::move(picture));
82 }
83 
85  const AiksDlPlaygroundCallback& callback) {
86  AiksContext renderer(GetContext(), typographer_context_);
87 
88  if (!renderer.IsValid()) {
89  return false;
90  }
91 
93  [&renderer, &callback](RenderTarget& render_target) -> bool {
94  auto display_list = callback();
95  DlDispatcher dispatcher;
96  display_list->Dispatch(dispatcher);
97  Picture picture = dispatcher.EndRecordingAsPicture();
98 
99  return renderer.Render(picture, render_target, true);
100  });
101 }
102 
103 } // namespace impeller
impeller::DlDispatcherBase::EndRecordingAsPicture
Picture EndRecordingAsPicture()
Definition: dl_dispatcher.cc:1203
impeller::AiksContext
Definition: aiks_context.h:19
impeller::DlDispatcher
Definition: dl_dispatcher.h:261
aiks_context.h
dl_dispatcher.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:17
impeller::AiksPlayground::SetTypographerContext
void SetTypographerContext(std::shared_ptr< TypographerContext > typographer_context)
Definition: aiks_playground.cc:22
typographer_context_skia.h
impeller::AiksPlayground::TearDown
void TearDown() override
Definition: aiks_playground.cc:27
impeller::Picture
Definition: picture.h:17
impeller::AiksPlayground::AiksPlaygroundCallback
std::function< std::optional< Picture >(AiksContext &renderer)> AiksPlaygroundCallback
Definition: aiks_playground.h:20
impeller::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:61
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:118
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:31
impeller::AiksPlayground::AiksDlPlaygroundCallback
std::function< sk_sp< flutter::DisplayList >()> AiksDlPlaygroundCallback
Definition: aiks_playground.h:22
impeller::AiksPlayground::ImGuiBegin
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
Definition: aiks_playground.cc:69
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Definition: playground.cc:204
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:90
impeller::AiksPlayground::~AiksPlayground
~AiksPlayground()
impeller
Definition: aiks_blend_unittests.cc:18
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition: switches.h:16
impeller::AiksContext::IsValid
bool IsValid() const
Definition: aiks_context.cc:36