Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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
13#include "third_party/imgui/imgui.h"
14#include "third_party/skia/include/core/SkData.h"
15#include "third_party/skia/include/core/SkFontMgr.h"
16#include "third_party/skia/include/core/SkTypeface.h"
17#include "txt/platform.h"
18
19namespace impeller {
20
22
24
28
29bool DlPlayground::OpenPlaygroundHere(sk_sp<flutter::DisplayList> list) {
30 return OpenPlaygroundHere([&list]() { return list; });
31}
32
35 if (!context.IsValid()) {
36 return false;
37 }
39 [&context, &callback](RenderTarget& render_target) -> bool {
40 return RenderToTarget(
41 context.GetContentContext(), //
42 render_target, //
43 callback(), //
45 render_target.GetRenderTargetSize().height), //
46 /*reset_host_buffer=*/true, //
47 /*is_onscreen=*/false //
48 );
49 });
50}
51
52std::unique_ptr<testing::Screenshot> DlPlayground::MakeScreenshot(
53 const sk_sp<flutter::DisplayList>& list) {
54 std::shared_ptr<Context> context = GetContext();
56 Point content_scale = GetContentScale();
57
58 ISize physical_window_size(
59 std::round(GetWindowSize().width * content_scale.x),
60 std::round(GetWindowSize().height * content_scale.y));
62 context, DisplayListToTexture(list, physical_window_size, renderer));
63}
64
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
76
78 const char* fixture_name,
79 bool enable_mipmapping) const {
80 std::shared_ptr<fml::Mapping> mapping =
82 std::shared_ptr<Texture> texture = Playground::CreateTextureForMapping(
83 GetContext(), mapping, enable_mipmapping);
84 if (texture) {
85 texture->SetLabel(fixture_name);
86 }
88}
89
90} // namespace impeller
sk_sp< DisplayList > Build()
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
SkFont CreateTestFontOfSize(Scalar scalar)
bool OpenPlaygroundHere(flutter::DisplayListBuilder &builder)
std::unique_ptr< testing::Screenshot > MakeScreenshot(const sk_sp< flutter::DisplayList > &list)
sk_sp< flutter::DlImage > CreateDlImageForFixture(const char *fixture_name, bool enable_mipmapping=false) const
std::function< sk_sp< flutter::DisplayList >()> DisplayListPlaygroundCallback
bool OpenPlaygroundHere(const RenderCallback &render_callback)
ISize GetWindowSize() const
std::shared_ptr< TypographerContext > GetTypographerContext() const
std::shared_ptr< Context > GetContext() const
static std::shared_ptr< Texture > CreateTextureForMapping(const std::shared_ptr< Context > &context, std::shared_ptr< fml::Mapping > mapping, bool enable_mipmapping=false)
Point GetContentScale() const
ISize GetRenderTargetSize() const
static std::shared_ptr< TypographerContext > Make()
static std::unique_ptr< Screenshot > MakeScreenshot(std::shared_ptr< Context > &context, const std::shared_ptr< Texture > &texture)
FlutterDesktopBinaryReply callback
#define FML_CHECK(condition)
Definition logging.h:104
FlTexture * texture
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:63
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:58
float Scalar
Definition scalar.h:19
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips, std::optional< PixelFormat > target_pixel_format)
Render the provided display list to a texture with the given size.
bool RenderToTarget(ContentContext &context, RenderTarget render_target, const sk_sp< flutter::DisplayList > &display_list, Rect cull_rect, bool reset_host_buffer, bool is_onscreen)
Render the provided display list to the render target.
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
Definition platform.cc:17
std::shared_ptr< ContextGLES > context
int32_t height
int32_t width
static constexpr TRect MakeWH(Type width, Type height)
Definition rect.h:140
Type height
Definition size.h:29
Type width
Definition size.h:28