Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
15#include "txt/platform.h"
16
17#define ENABLE_EXPERIMENTAL_CANVAS false
18
19namespace impeller {
20
22
24
28
30 return OpenPlaygroundHere([&list]() { return list; });
31}
32
35 return true;
36 }
37
39 if (!context.IsValid()) {
40 return false;
41 }
43 [&context, &callback](RenderTarget& render_target) -> bool {
44 static bool wireframe = false;
45 if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
46 wireframe = !wireframe;
47 context.GetContentContext().SetWireframe(wireframe);
48 }
49
50 auto list = callback();
51
52#if ENABLE_EXPERIMENTAL_CANVAS
53 TextFrameDispatcher collector(context.GetContentContext(), Matrix());
54 list->Dispatch(collector);
55
56 ExperimentalDlDispatcher impeller_dispatcher(
57 context.GetContentContext(), render_target, IRect::MakeMaximum());
58 list->Dispatch(impeller_dispatcher);
59 impeller_dispatcher.FinishRecording();
61 context.GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();
62 return true;
63#else
64 DlDispatcher dispatcher;
65 list->Dispatch(dispatcher);
66 auto picture = dispatcher.EndRecordingAsPicture();
67
68 return context.Render(picture, render_target, true);
69#endif
70 });
71}
72
74 static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
75 auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture);
76 FML_CHECK(mapping);
78 return SkFont{font_mgr->makeFromData(mapping), scalar};
79}
80
84
85} // namespace impeller
ContentContext & GetContentContext() const
bool Render(const Picture &picture, RenderTarget &render_target, bool reset_host_buffer)
const std::shared_ptr< LazyGlyphAtlas > & GetLazyGlyphAtlas() const
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
bool OpenPlaygroundHere(flutter::DisplayListBuilder &builder)
SkFont CreateTestFontOfSize(SkScalar scalar)
std::function< sk_sp< flutter::DisplayList >()> DisplayListPlaygroundCallback
void Reset()
Resets the contents of the HostBuffer to nothing so it can be reused.
const PlaygroundSwitches switches_
Definition playground.h:120
std::shared_ptr< Context > GetContext() const
Definition playground.cc:89
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Performs a first pass over the display list to collect all text frames.
static std::shared_ptr< TypographerContext > Make()
float SkScalar
Definition extension.cpp:12
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_CHECK(condition)
Definition logging.h:85
sk_sp< SkData > OpenFixtureAsSkData(const std::string &fixture_name)
Opens a fixture of the given file name and returns a Skia SkData holding its contents.
Definition testing.cc:64
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
Definition platform.cc:17
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static constexpr TRect MakeMaximum()
Definition rect.h:174