Flutter Engine
The Flutter Engine
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"
16#include "txt/platform.h"
17
18#define ENABLE_EXPERIMENTAL_CANVAS false
19
20namespace impeller {
21
23
25
27 return OpenPlaygroundHere(builder.Build());
28}
29
31 return OpenPlaygroundHere([&list]() { return list; });
32}
33
36 return true;
37 }
38
40 if (!context.IsValid()) {
41 return false;
42 }
44 [&context, &callback](RenderTarget& render_target) -> bool {
45 static bool wireframe = false;
46 if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
47 wireframe = !wireframe;
48 context.GetContentContext().SetWireframe(wireframe);
49 }
50
51 auto list = callback();
52
53#if ENABLE_EXPERIMENTAL_CANVAS
54 TextFrameDispatcher collector(context.GetContentContext(), Matrix());
55 list->Dispatch(collector);
56
57 ExperimentalDlDispatcher impeller_dispatcher(
58 context.GetContentContext(), render_target,
59 display_list->root_has_backdrop_filter(),
60 display_list->max_root_blend_mode(), IRect::MakeMaximum());
61 list->Dispatch(impeller_dispatcher);
62 impeller_dispatcher.FinishRecording();
64 context.GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();
65 return true;
66#else
67 DlDispatcher dispatcher;
68 list->Dispatch(dispatcher);
69 auto picture = dispatcher.EndRecordingAsPicture();
70
71 return context.Render(picture, render_target, true);
72#endif
73 });
74}
75
77 static constexpr const char* kTestFontFixture = "Roboto-Regular.ttf";
78 auto mapping = flutter::testing::OpenFixtureAsSkData(kTestFontFixture);
79 FML_CHECK(mapping);
81 return SkFont{font_mgr->makeFromData(mapping), scalar};
82}
83
85 return CreateTestFontOfSize(50);
86}
87
89 const char* fixture_name,
90 bool enable_mipmapping) const {
91 std::shared_ptr<fml::Mapping> mapping =
93 std::shared_ptr<Texture> texture = Playground::CreateTextureForMapping(
94 GetContext(), mapping, enable_mipmapping);
95 if (texture) {
96 texture->SetLabel(fixture_name);
97 }
99}
100
101} // namespace impeller
sk_sp< SkTypeface > makeFromData(sk_sp< SkData >, int ttcIndex=0) const
Definition: SkFontMgr.cpp:120
Definition: SkFont.h:35
ContentContext & GetContentContext() const
Definition: aiks_context.cc:44
bool IsValid() const
Definition: aiks_context.cc:36
bool Render(const Picture &picture, RenderTarget &render_target, bool reset_host_buffer)
Definition: aiks_context.cc:48
const std::shared_ptr< LazyGlyphAtlas > & GetLazyGlyphAtlas() const
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
bool OpenPlaygroundHere(flutter::DisplayListBuilder &builder)
SkFont CreateTestFontOfSize(SkScalar scalar)
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:18
void Reset()
Resets the contents of the HostBuffer to nothing so it can be reused.
Definition: host_buffer.cc:195
const PlaygroundSwitches switches_
Definition: playground.h:118
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:90
bool OpenPlaygroundHere(const Renderer::RenderCallback &render_callback)
Definition: playground.cc:204
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:441
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
FlTexture * texture
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299
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
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
Definition: testing.cc:59
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