| 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/aiks/aiks_context.h"
9 #include "impeller/display_list/dl_dispatcher.h"
10 #include "impeller/typographer/backends/skia/typographer_context_skia.h"
11 #include "third_party/imgui/imgui.h"
12 #include "third_party/skia/include/core/SkData.h"
13 #include "third_party/skia/include/core/SkFontMgr.h"
14 #include "third_party/skia/include/core/SkTypeface.h"
15 #include "txt/platform.h"
16
17 namespace impeller {
18
19 DlPlayground::DlPlayground() = default;
20
21 DlPlayground::~DlPlayground() = default;
22
23 bool DlPlayground::OpenPlaygroundHere(flutter::DisplayListBuilder& builder) {
24 return OpenPlaygroundHere(builder.Build());
25 }
26
27 bool DlPlayground::OpenPlaygroundHere(sk_sp<flutter::DisplayList> list) {
28 return OpenPlaygroundHere([&list]() { return list; });
29 }
30
31 bool DlPlayground::OpenPlaygroundHere(DisplayListPlaygroundCallback callback) {
32 if (!switches_.enable_playground) {
33 return true;
34 }
35
36 AiksContext context(GetContext(), TypographerContextSkia::Make());
37 if (!context.IsValid()) {
38 return false;
39 }
40 return Playground::OpenPlaygroundHere(
41 [&context, &callback](RenderTarget& render_target) -> bool {
42 static bool wireframe = false;
43 if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
44 wireframe = !wireframe;
45 context.GetContentContext().SetWireframe(wireframe);
46 }
47
48 auto list = callback();
49
50 DlDispatcher dispatcher;
51 list->Dispatch(dispatcher);
52 auto picture = dispatcher.EndRecordingAsPicture();
53
54 return context.Render(picture, render_target);
55 });
56 }
57
58 SkFont DlPlayground::CreateTestFontOfSize(SkScalar scalar) {
59 static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
60 auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture);
61 FML_CHECK(mapping);
62 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
63 return SkFont{font_mgr->makeFromData(mapping), scalar};
64 }
65
66 SkFont DlPlayground::CreateTestFont() {
67 return CreateTestFontOfSize(50);
68 }
69
70 } // namespace impeller
impeller::AiksContext
Definition: aiks_context.h:20
impeller::DlPlayground::DlPlayground
DlPlayground()
impeller::DlDispatcher
Definition: dl_dispatcher.h:14
impeller::AiksContext::GetContentContext
ContentContext & GetContentContext() const
Definition: aiks_context.cc:39
impeller::DlDispatcher::EndRecordingAsPicture
Picture EndRecordingAsPicture()
Definition: dl_dispatcher.cc:1118
aiks_context.h
dl_dispatcher.h
impeller::DlPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(flutter::DisplayListBuilder &builder)
Definition: dl_playground.cc:23
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::DlPlayground::CreateTestFontOfSize
SkFont CreateTestFontOfSize(SkScalar scalar)
Definition: dl_playground.cc:58
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:115
impeller::RenderTarget
Definition: render_target.h:49
impeller::AiksContext::Render
bool Render(const Picture &picture, RenderTarget &render_target)
Definition: aiks_context.cc:43
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Definition: playground.cc:189
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:86
impeller
Definition: aiks_context.cc:10
impeller::PlaygroundSwitches::enable_playground
bool enable_playground
Definition: switches.h:17
impeller::TypographerContextSkia::Make
static std::shared_ptr< TypographerContext > Make()
Definition: typographer_context_skia.cc:30
impeller::AiksContext::IsValid
bool IsValid() const
Definition: aiks_context.cc:31
impeller::DlPlayground::CreateTestFont
SkFont CreateTestFont()
Definition: dl_playground.cc:66