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 #define ENABLE_EXPERIMENTAL_CANVAS false
19 
20 namespace impeller {
21 
22 DlPlayground::DlPlayground() = default;
23 
24 DlPlayground::~DlPlayground() = default;
25 
26 bool DlPlayground::OpenPlaygroundHere(flutter::DisplayListBuilder& builder) {
27  return OpenPlaygroundHere(builder.Build());
28 }
29 
30 bool DlPlayground::OpenPlaygroundHere(sk_sp<flutter::DisplayList> list) {
31  return OpenPlaygroundHere([&list]() { return list; });
32 }
33 
36  return true;
37  }
38 
40  if (!context.IsValid()) {
41  return false;
42  }
44  [&context, &callback](RenderTarget& render_target) -> bool {
45  static bool wireframe = false;
46  if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
47  wireframe = !wireframe;
48  context.GetContentContext().SetWireframe(wireframe);
49  }
50 
51  auto list = callback();
52 
53 #if ENABLE_EXPERIMENTAL_CANVAS
54  TextFrameDispatcher collector(context.GetContentContext(), Matrix());
55  list->Dispatch(collector);
56 
57  ExperimentalDlDispatcher impeller_dispatcher(
58  context.GetContentContext(), render_target,
59  list->root_has_backdrop_filter(), list->max_root_blend_mode(),
61  list->Dispatch(impeller_dispatcher);
62  impeller_dispatcher.FinishRecording();
64  context.GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();
65  return true;
66 #else
67  DlDispatcher dispatcher;
68  list->Dispatch(dispatcher);
69  auto picture = dispatcher.EndRecordingAsPicture();
70 
71  return context.Render(picture, render_target, true);
72 #endif
73  });
74 }
75 
76 SkFont DlPlayground::CreateTestFontOfSize(SkScalar scalar) {
77  static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
78  auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture);
79  FML_CHECK(mapping);
80  sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
81  return SkFont{font_mgr->makeFromData(mapping), scalar};
82 }
83 
85  return CreateTestFontOfSize(50);
86 }
87 
88 sk_sp<flutter::DlImage> DlPlayground::CreateDlImageForFixture(
89  const char* fixture_name,
90  bool enable_mipmapping) const {
91  std::shared_ptr<fml::Mapping> mapping =
92  flutter::testing::OpenFixtureAsMapping(fixture_name);
93  std::shared_ptr<Texture> texture = Playground::CreateTextureForMapping(
94  GetContext(), mapping, enable_mipmapping);
95  if (texture) {
96  texture->SetLabel(fixture_name);
97  }
98  return DlImageImpeller::Make(texture);
99 }
100 
101 } // namespace impeller
impeller::DlDispatcherBase::EndRecordingAsPicture
Picture EndRecordingAsPicture()
Definition: dl_dispatcher.cc:1203
impeller::ExperimentalDlDispatcher::FinishRecording
void FinishRecording()
Definition: dl_dispatcher.h:326
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:720
impeller::DlDispatcher
Definition: dl_dispatcher.h:261
impeller::AiksContext::GetContentContext
ContentContext & GetContentContext() const
Definition: aiks_context.cc:44
aiks_context.h
dl_dispatcher.h
impeller::DlPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(flutter::DisplayListBuilder &builder)
Definition: dl_playground.cc:26
impeller::AiksContext::Render
bool Render(const Picture &picture, RenderTarget &render_target, bool reset_host_buffer)
Definition: aiks_context.cc:48
impeller::DlImageImpeller::Make
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
Definition: dl_image_impeller.cc:12
typographer_context_skia.h
dl_playground.h
impeller::DlPlayground::DisplayListPlaygroundCallback
std::function< sk_sp< flutter::DisplayList >()> DisplayListPlaygroundCallback
Definition: dl_playground.h:18
impeller::DlPlayground::~DlPlayground
~DlPlayground()
impeller::ExperimentalDlDispatcher
Definition: dl_dispatcher.h:298
impeller::DlPlayground::CreateTestFontOfSize
SkFont CreateTestFontOfSize(SkScalar scalar)
Definition: dl_playground.cc:76
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:118
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:441
impeller::HostBuffer::Reset
void Reset()
Resets the contents of the HostBuffer to nothing so it can be reused.
Definition: host_buffer.cc:195
impeller::TRect::MakeMaximum
constexpr static TRect MakeMaximum()
Definition: rect.h:174
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Definition: playground.cc:204
impeller::TextFrameDispatcher
Performs a first pass over the display list to collect all text frames.
Definition: dl_dispatcher.h:335
impeller::DlPlayground::CreateDlImageForFixture
sk_sp< flutter::DlImage > CreateDlImageForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: dl_playground.cc:88
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:90
impeller
Definition: aiks_blend_unittests.cc:18
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:78
impeller::AiksContext::IsValid
bool IsValid() const
Definition: aiks_context.cc:36
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:752
impeller::DlPlayground::CreateTestFont
SkFont CreateTestFont()
Definition: dl_playground.cc:84
dl_image_impeller.h