| 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
5 #include "impeller/display_list/dl_playground.h"
6
7 #include "flutter/testing/testing.h"
8 #include "impeller/display_list/aiks_context.h"
9 #include "impeller/display_list/dl_dispatcher.h"
10 #include "impeller/display_list/dl_image_impeller.h"
11 #include "impeller/typographer/backends/skia/typographer_context_skia.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
32 bool DlPlayground::OpenPlaygroundHere(DisplayListPlaygroundCallback callback) {
33 if (!switches_.enable_playground) {
34 return true;
35 }
36
37 AiksContext context(GetContext(), TypographerContextSkia::Make());
38 if (!context.IsValid()) {
39 return false;
40 }
41 return Playground::OpenPlaygroundHere(
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 return RenderToTarget(
49 context.GetContentContext(), //
50 render_target, //
51 callback(), //
52 SkIRect::MakeWH(render_target.GetRenderTargetSize().width,
53 render_target.GetRenderTargetSize().height), //
54 /*reset_host_buffer=*/true, //
55 /*is_onscreen=*/false //
56 );
57 });
58 }
59
60 std::unique_ptr<testing::Screenshot> DlPlayground::MakeScreenshot(
61 const sk_sp<flutter::DisplayList>& list) {
62 return nullptr;
63 }
64
65 SkFont DlPlayground::CreateTestFontOfSize(SkScalar scalar) {
66 static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
67 auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture);
68 FML_CHECK(mapping);
69 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
70 return SkFont{font_mgr->makeFromData(mapping), scalar};
71 }
72
73 SkFont DlPlayground::CreateTestFont() {
74 return CreateTestFontOfSize(50);
75 }
76
77 sk_sp<flutter::DlImage> DlPlayground::CreateDlImageForFixture(
78 const char* fixture_name,
79 bool enable_mipmapping) const {
80 std::shared_ptr<fml::Mapping> mapping =
81 flutter::testing::OpenFixtureAsMapping(fixture_name);
82 std::shared_ptr<Texture> texture = Playground::CreateTextureForMapping(
83 GetContext(), mapping, enable_mipmapping);
84 if (texture) {
85 texture->SetLabel(fixture_name);
86 }
87 return DlImageImpeller::Make(texture);
88 }
89
90 } // namespace impeller
impeller::RenderToTarget
bool RenderToTarget(ContentContext &context, RenderTarget render_target, const sk_sp< flutter::DisplayList > &display_list, SkIRect cull_rect, bool reset_host_buffer, bool is_onscreen)
Render the provided display list to the render target.
Definition: dl_dispatcher.cc:1311
impeller::AiksContext
Definition: aiks_context.h:19
impeller::DlPlayground::DlPlayground
DlPlayground()
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:201
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:65
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:122
impeller::RenderTarget
Definition: render_target.h:38
impeller::TSize::width
Type width
Definition: size.h:28
impeller::RenderTarget::GetRenderTargetSize
ISize GetRenderTargetSize() const
Definition: render_target.cc:171
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:432
impeller::DlPlayground::MakeScreenshot
std::unique_ptr< testing::Screenshot > MakeScreenshot(const sk_sp< flutter::DisplayList > &list)
Definition: dl_playground.cc:60
impeller::TSize::height
Type height
Definition: size.h:29
impeller::DlPlayground::CreateDlImageForFixture
sk_sp< flutter::DlImage > CreateDlImageForFixture(const char *fixture_name, bool enable_mipmapping=false) const
Definition: dl_playground.cc:77
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:91
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:77
impeller::AiksContext::IsValid
bool IsValid() const
Definition: aiks_context.cc:34
impeller::DlPlayground::CreateTestFont
SkFont CreateTestFont()
Definition: dl_playground.cc:73
dl_image_impeller.h