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  return RenderToTarget(
44  context.GetContentContext(), //
45  render_target, //
46  callback(), //
47  Rect::MakeWH(render_target.GetRenderTargetSize().width,
48  render_target.GetRenderTargetSize().height), //
49  /*reset_host_buffer=*/true, //
50  /*is_onscreen=*/false //
51  );
52  });
53 }
54 
55 std::unique_ptr<testing::Screenshot> DlPlayground::MakeScreenshot(
56  const sk_sp<flutter::DisplayList>& list) {
57  return nullptr;
58 }
59 
61  static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
62  auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture);
63  FML_CHECK(mapping);
64  sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
65  return SkFont{font_mgr->makeFromData(mapping), scalar};
66 }
67 
69  return CreateTestFontOfSize(50);
70 }
71 
72 sk_sp<flutter::DlImage> DlPlayground::CreateDlImageForFixture(
73  const char* fixture_name,
74  bool enable_mipmapping) const {
75  std::shared_ptr<fml::Mapping> mapping =
76  flutter::testing::OpenFixtureAsMapping(fixture_name);
77  std::shared_ptr<Texture> texture = Playground::CreateTextureForMapping(
78  GetContext(), mapping, enable_mipmapping);
79  if (texture) {
80  texture->SetLabel(fixture_name);
81  }
82  return DlImageImpeller::Make(texture);
83 }
84 
85 } // namespace impeller
ContentContext & GetContentContext() const
Definition: aiks_context.cc:42
bool IsValid() const
Definition: aiks_context.cc:34
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
SkFont CreateTestFontOfSize(Scalar scalar)
bool OpenPlaygroundHere(flutter::DisplayListBuilder &builder)
std::unique_ptr< testing::Screenshot > MakeScreenshot(const sk_sp< flutter::DisplayList > &list)
sk_sp< flutter::DlImage > CreateDlImageForFixture(const char *fixture_name, bool enable_mipmapping=false) const
std::function< sk_sp< flutter::DisplayList >()> DisplayListPlaygroundCallback
Definition: dl_playground.h:19
bool OpenPlaygroundHere(const RenderCallback &render_callback)
Definition: playground.cc:201
const PlaygroundSwitches switches_
Definition: playground.h:131
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:91
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:433
ISize GetRenderTargetSize() const
static std::shared_ptr< TypographerContext > Make()
float Scalar
Definition: scalar.h:19
bool RenderToTarget(ContentContext &context, RenderTarget render_target, const sk_sp< flutter::DisplayList > &display_list, Rect cull_rect, bool reset_host_buffer, bool is_onscreen)
Render the provided display list to the render target.
constexpr static TRect MakeWH(Type width, Type height)
Definition: rect.h:140
Type height
Definition: size.h:29
Type width
Definition: size.h:28