Flutter Engine
The Flutter Engine
dl_test_surface_metal.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 "flutter/display_list/testing/dl_test_surface_metal.h"
6#include "flutter/impeller/display_list/dl_dispatcher.h"
7#include "flutter/impeller/display_list/dl_image_impeller.h"
8#include "flutter/impeller/typographer/backends/skia/typographer_context_skia.h"
9
12
13namespace flutter {
14namespace testing {
15
17 public:
19 std::unique_ptr<TestMetalSurface> metal_surface)
20 : metal_surface_(std::move(metal_surface)) {}
22
23 sk_sp<SkSurface> sk_surface() const override {
24 return metal_surface_->GetSurface();
25 }
26
27 private:
28 std::unique_ptr<TestMetalSurface> metal_surface_;
29};
30
32 size_t height,
35 return false;
36 }
37 metal_context_ = std::make_unique<TestMetalContext>();
38 metal_surface_ = MakeOffscreenSurface(width, height, format);
39 return true;
40}
41
42std::shared_ptr<DlSurfaceInstance> DlMetalSurfaceProvider::GetPrimarySurface()
43 const {
44 if (!metal_surface_) {
45 return nullptr;
46 }
47 return metal_surface_;
48}
49
50std::shared_ptr<DlSurfaceInstance> DlMetalSurfaceProvider::MakeOffscreenSurface(
51 size_t width,
52 size_t height,
53 PixelFormat format) const {
54 auto surface =
56 surface->GetSurface()->getCanvas()->clear(SK_ColorTRANSPARENT);
57 return std::make_shared<DlMetalSurfaceInstance>(std::move(surface));
58}
59
61 public:
63 std::unique_ptr<impeller::testing::Screenshot> screenshot)
64 : screenshot_(std::move(screenshot)),
65 addr_(reinterpret_cast<const uint32_t*>(screenshot_->GetBytes())),
66 ints_per_row_(screenshot_->GetBytesPerRow() / 4) {
67 FML_DCHECK(screenshot_->GetBytesPerRow() == ints_per_row_ * 4);
68 }
69 ~DlMetalPixelData() override = default;
70
71 const uint32_t* addr32(int x, int y) const override {
72 return addr_ + (y * ints_per_row_) + x;
73 }
74 size_t width() const override { return screenshot_->GetWidth(); }
75 size_t height() const override { return screenshot_->GetHeight(); }
76 void write(const std::string& path) const override {
77 screenshot_->WriteToPNG(path);
78 }
79
80 private:
81 std::unique_ptr<impeller::testing::Screenshot> screenshot_;
82 const uint32_t* addr_;
83 const uint32_t ints_per_row_;
84};
85
87 const sk_sp<DisplayList>& list,
88 int width,
89 int height) const {
90 InitScreenShotter();
91 impeller::DlDispatcher dispatcher;
94 list->Dispatch(dispatcher);
95 auto picture = dispatcher.EndRecordingAsPicture();
96 return sk_make_sp<DlMetalPixelData>(snapshotter_->MakeScreenshot(
97 *aiks_context_, picture, {width, height}, false));
98}
99
101 const sk_sp<DisplayList>& list,
102 int width,
103 int height) const {
104 InitScreenShotter();
105 impeller::DlDispatcher dispatcher;
108 list->Dispatch(dispatcher);
109 auto picture = dispatcher.EndRecordingAsPicture();
110 std::shared_ptr<impeller::Image> image =
111 picture.ToImage(*aiks_context_, {width, height});
112 std::shared_ptr<impeller::Texture> texture = image->GetTexture();
114}
115
116void DlMetalSurfaceProvider::InitScreenShotter() const {
117 if (!snapshotter_) {
118 snapshotter_.reset(new MetalScreenshotter(/*enable_wide_gamut=*/false));
119 auto typographer = impeller::TypographerContextSkia::Make();
120 aiks_context_.reset(new impeller::AiksContext(
121 snapshotter_->GetPlayground().GetContext(), typographer));
122 }
123}
124
125} // namespace testing
126} // namespace flutter
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
static std::unique_ptr< TestMetalSurface > Create(const TestMetalContext &test_metal_context, SkISize surface_size=SkISize::MakeEmpty())
DlMetalPixelData(std::unique_ptr< impeller::testing::Screenshot > screenshot)
~DlMetalPixelData() override=default
const uint32_t * addr32(int x, int y) const override
void write(const std::string &path) const override
DlMetalSurfaceInstance(std::unique_ptr< TestMetalSurface > metal_surface)
sk_sp< SkSurface > sk_surface() const override
std::shared_ptr< DlSurfaceInstance > GetPrimarySurface() const override
sk_sp< DlPixelData > ImpellerSnapshot(const sk_sp< DisplayList > &list, int width, int height) const override
bool InitializeSurface(size_t width, size_t height, PixelFormat format) override
std::shared_ptr< DlSurfaceInstance > MakeOffscreenSurface(size_t width, size_t height, PixelFormat format) const override
virtual sk_sp< DlImage > MakeImpellerImage(const sk_sp< DisplayList > &list, int width, int height) const override
void drawColor(flutter::DlColor color, flutter::DlBlendMode mode) override
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
static std::shared_ptr< TypographerContext > Make()
VkSurfaceKHR surface
Definition: main.cc:49
#define FML_DCHECK(condition)
Definition: logging.h:103
FlTexture * texture
double y
double x
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299
impeller::testing::MetalScreenshotter MetalScreenshotter
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent Remove all existing persistent cache This is mainly for debugging purposes such as reproducing the shader compilation jank trace to Write the timeline trace to a file at the specified path The file will be in Perfetto s proto format
Definition: switches.h:203
Definition: ref_ptr.h:256
int32_t height
int32_t width
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr DlColor kTransparent()
Definition: dl_color.h:21