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"
11 #include "third_party/imgui/imgui.h"
12 #include "third_party/skia/include/core/SkData.h"
13 
14 namespace impeller {
15 
16 DlPlayground::DlPlayground() = default;
17 
18 DlPlayground::~DlPlayground() = default;
19 
20 bool DlPlayground::OpenPlaygroundHere(flutter::DisplayListBuilder& builder) {
21  return OpenPlaygroundHere(builder.Build());
22 }
23 
24 bool DlPlayground::OpenPlaygroundHere(sk_sp<flutter::DisplayList> list) {
25  return OpenPlaygroundHere([&list]() { return list; });
26 }
27 
30  return true;
31  }
32 
34  if (!context.IsValid()) {
35  return false;
36  }
38  [&context, &callback](RenderTarget& render_target) -> bool {
39  static bool wireframe = false;
40  if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
41  wireframe = !wireframe;
42  context.GetContentContext().SetWireframe(wireframe);
43  }
44 
45  auto list = callback();
46 
47  DlDispatcher dispatcher;
48  list->Dispatch(dispatcher);
49  auto picture = dispatcher.EndRecordingAsPicture();
50 
51  return context.Render(picture, render_target);
52  });
53 }
54 
55 static sk_sp<SkData> OpenFixtureAsSkData(const char* fixture_name) {
56  auto mapping = flutter::testing::OpenFixtureAsMapping(fixture_name);
57  if (!mapping) {
58  return nullptr;
59  }
60  auto data = SkData::MakeWithProc(
61  mapping->GetMapping(), mapping->GetSize(),
62  [](const void* ptr, void* context) {
63  delete reinterpret_cast<fml::Mapping*>(context);
64  },
65  mapping.get());
66  mapping.release();
67  return data;
68 }
69 
70 SkFont DlPlayground::CreateTestFontOfSize(SkScalar scalar) {
71  static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
72  auto mapping = OpenFixtureAsSkData(kTestFontFixture);
73  FML_CHECK(mapping);
74  return SkFont{SkTypeface::MakeFromData(mapping), scalar};
75 }
76 
78  return CreateTestFontOfSize(50);
79 }
80 
81 } // 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:1135
aiks_context.h
dl_dispatcher.h
impeller::DlPlayground::OpenPlaygroundHere
bool OpenPlaygroundHere(flutter::DisplayListBuilder &builder)
Definition: dl_playground.cc:20
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:70
impeller::Playground::switches_
const PlaygroundSwitches switches_
Definition: playground.h:91
impeller::RenderTarget
Definition: render_target.h:48
impeller::AiksContext::Render
bool Render(const Picture &picture, RenderTarget &render_target)
Definition: aiks_context.cc:43
impeller::OpenFixtureAsSkData
static sk_sp< SkData > OpenFixtureAsSkData(const char *fixture_name)
Definition: dl_playground.cc:55
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:16
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:77