Flutter Impeller
dl_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 "flutter/testing/testing.h"
12 #include "third_party/imgui/imgui.h"
13 #include "third_party/skia/include/core/SkData.h"
14 #include "third_party/skia/include/core/SkFontMgr.h"
15 #include "third_party/skia/include/core/SkTypeface.h"
16 #include "txt/platform.h"
17 
18 namespace impeller {
19 
20 DlPlayground::DlPlayground() = default;
21 
22 DlPlayground::~DlPlayground() = default;
23 
24 bool DlPlayground::OpenPlaygroundHere(flutter::DisplayListBuilder& builder) {
25  return OpenPlaygroundHere(builder.Build());
26 }
27 
28 bool DlPlayground::OpenPlaygroundHere(sk_sp<flutter::DisplayList> list) {
29  return OpenPlaygroundHere([&list]() { return list; });
30 }
31 
34  return true;
35  }
36 
38  if (!context.IsValid()) {
39  return false;
40  }
42  [&context, &callback](RenderTarget& render_target) -> bool {
43  static bool wireframe = false;
44  if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
45  wireframe = !wireframe;
46  context.GetContentContext().SetWireframe(wireframe);
47  }
48 
49  auto list = callback();
50  TextFrameDispatcher collector(context.GetContentContext(), Matrix(),
52  list->Dispatch(collector);
53 
54  CanvasDlDispatcher impeller_dispatcher(
55  context.GetContentContext(), render_target,
56  list->root_has_backdrop_filter(), list->max_root_blend_mode(),
58  list->Dispatch(impeller_dispatcher);
59  impeller_dispatcher.FinishRecording();
61  context.GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();
62  return true;
63  });
64 }
65 
66 std::unique_ptr<testing::Screenshot> DlPlayground::MakeScreenshot(
67  const sk_sp<flutter::DisplayList>& list) {
68  return nullptr;
69 }
70 
71 SkFont DlPlayground::CreateTestFontOfSize(SkScalar scalar) {
72  static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
73  auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture);
74  FML_CHECK(mapping);
75  sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
76  return SkFont{font_mgr->makeFromData(mapping), scalar};
77 }
78 
80  return CreateTestFontOfSize(50);
81 }
82 
83 sk_sp<flutter::DlImage> DlPlayground::CreateDlImageForFixture(
84  const char* fixture_name,
85  bool enable_mipmapping) const {
86  std::shared_ptr<fml::Mapping> mapping =
87  flutter::testing::OpenFixtureAsMapping(fixture_name);
88  std::shared_ptr<Texture> texture = Playground::CreateTextureForMapping(
89  GetContext(), mapping, enable_mipmapping);
90  if (texture) {
91  texture->SetLabel(fixture_name);
92  }
93  return DlImageImpeller::Make(texture);
94 }
95 
96 } // namespace impeller
impeller::CanvasDlDispatcher
Definition: dl_dispatcher.h:246
impeller::CanvasDlDispatcher::FinishRecording
void FinishRecording()
Definition: dl_dispatcher.h:274
impeller::AiksContext
Definition: aiks_context.h:19
impeller::DlPlayground::DlPlayground
DlPlayground()
impeller::ContentContext::GetLazyGlyphAtlas
const std::shared_ptr< LazyGlyphAtlas > & GetLazyGlyphAtlas() const
Definition: content_context.h:721
impeller::AiksContext::GetContentContext
ContentContext & GetContentContext() const
Definition: aiks_context.cc:42
aiks_context.h
dl_dispatcher.h
impeller::DlPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(flutter::DisplayListBuilder &builder)
Definition: dl_playground.cc:24
impeller::DlImageImpeller::Make
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
Definition: dl_image_impeller.cc:23
typographer_context_skia.h
dl_playground.h
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const RenderCallback &render_callback)
Definition: playground.cc:197
impeller::DlPlayground::DisplayListPlaygroundCallback
std::function< sk_sp< flutter::DisplayList >()> DisplayListPlaygroundCallback
Definition: dl_playground.h:19
impeller::DlPlayground::~DlPlayground
~DlPlayground()
impeller::DlPlayground::CreateTestFontOfSize
SkFont CreateTestFontOfSize(SkScalar scalar)
Definition: dl_playground.cc:71
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:121
impeller::RenderTarget
Definition: render_target.h:38
impeller::Playground::CreateTextureForMapping
static std::shared_ptr< Texture > CreateTextureForMapping(const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)
Definition: playground.cc:429
impeller::HostBuffer::Reset
void Reset()
Resets the contents of the HostBuffer to nothing so it can be reused.
Definition: host_buffer.cc:208
impeller::TRect< Scalar >::MakeMaximum
constexpr static TRect MakeMaximum()
Definition: rect.h:178
impeller::DlPlayground::MakeScreenshot
std::unique_ptr< testing::Screenshot > MakeScreenshot(const sk_sp< flutter::DisplayList > &list)
Definition: dl_playground.cc:66
impeller::TextFrameDispatcher
Performs a first pass over the display list to collect all text frames.
Definition: dl_dispatcher.h:288
impeller::DlPlayground::CreateDlImageForFixture
sk_sp< flutter::DlImage > CreateDlImageForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: dl_playground.cc:83
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:90
impeller
Definition: allocation.cc:12
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition: switches.h:16
impeller::TypographerContextSkia::Make
static std::shared_ptr< TypographerContext > Make()
Definition: typographer_context_skia.cc:75
impeller::AiksContext::IsValid
bool IsValid() const
Definition: aiks_context.cc:34
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::ContentContext::GetTransientsBuffer
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
Definition: content_context.h:753
impeller::DlPlayground::CreateTestFont
SkFont CreateTestFont()
Definition: dl_playground.cc:79
dl_image_impeller.h