Flutter Engine
 
Loading...
Searching...
No Matches
dl_test_surface_metal.mm
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
9
10#include "third_party/skia/include/core/SkSurface.h"
11
12namespace flutter {
13namespace testing {
14
16 public:
17 explicit DlMetalSurfaceInstance(std::unique_ptr<TestMetalSurface> metal_surface)
18 : metal_surface_(std::move(metal_surface)),
19 adapter_(metal_surface_->GetSurface()->getCanvas()) {}
21
22 sk_sp<SkSurface> sk_surface() const override { return metal_surface_->GetSurface(); }
23 DlCanvas* GetCanvas() override { return &adapter_; }
24
25 private:
26 std::unique_ptr<TestMetalSurface> metal_surface_;
27 DlSkCanvasAdapter adapter_;
28};
29
32 return false;
33 }
34 metal_context_ = std::make_unique<TestMetalContext>();
35 metal_surface_ = MakeOffscreenSurface(width, height, format);
36 return true;
37}
38
39std::shared_ptr<DlSurfaceInstance> DlMetalSurfaceProvider::GetPrimarySurface() const {
40 if (!metal_surface_) {
41 return nullptr;
42 }
43 return metal_surface_;
44}
45
46std::shared_ptr<DlSurfaceInstance> DlMetalSurfaceProvider::MakeOffscreenSurface(
47 size_t width,
48 size_t height,
49 PixelFormat format) const {
50 auto surface = TestMetalSurface::Create(*metal_context_, DlISize(width, height));
51 surface->GetSurface()->getCanvas()->clear(SK_ColorTRANSPARENT);
52 return std::make_shared<DlMetalSurfaceInstance>(std::move(surface));
53}
54
56 public:
57 explicit DlMetalPixelData(std::unique_ptr<impeller::testing::Screenshot> screenshot)
58 : screenshot_(std::move(screenshot)),
59 addr_(reinterpret_cast<const uint32_t*>(screenshot_->GetBytes())),
60 ints_per_row_(screenshot_->GetBytesPerRow() / 4) {
61 FML_DCHECK(screenshot_->GetBytesPerRow() == ints_per_row_ * 4);
62 }
63 ~DlMetalPixelData() override = default;
64
65 const uint32_t* addr32(int x, int y) const override { return addr_ + (y * ints_per_row_) + x; }
66 size_t width() const override { return screenshot_->GetWidth(); }
67 size_t height() const override { return screenshot_->GetHeight(); }
68 void write(const std::string& path) const override { screenshot_->WriteToPNG(path); }
69
70 private:
71 std::unique_ptr<impeller::testing::Screenshot> screenshot_;
72 const uint32_t* addr_;
73 const uint32_t ints_per_row_;
74};
75
76sk_sp<DlPixelData> DlMetalSurfaceProvider::ImpellerSnapshot(const sk_sp<DisplayList>& list,
77 int width,
78 int height) const {
79 auto texture = DisplayListToTexture(list, {width, height}, *aiks_context_);
80 return sk_make_sp<DlMetalPixelData>(snapshotter_->MakeScreenshot(*aiks_context_, texture));
81}
82
83sk_sp<DlImage> DlMetalSurfaceProvider::MakeImpellerImage(const sk_sp<DisplayList>& list,
84 int width,
85 int height) const {
86 InitScreenShotter();
88 DisplayListToTexture(list, {width, height}, *aiks_context_));
89}
90
91void DlMetalSurfaceProvider::InitScreenShotter() const {
92 if (!snapshotter_) {
94 switches.enable_wide_gamut = false;
95 snapshotter_.reset(new MetalScreenshotter(switches));
96 auto typographer = impeller::TypographerContextSkia::Make();
97 aiks_context_.reset(
98 new impeller::AiksContext(snapshotter_->GetPlayground().GetContext(), typographer));
99 }
100}
101
102} // namespace testing
103} // namespace flutter
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
Backend implementation of |DlCanvas| for |SkCanvas|.
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
static std::unique_ptr< TestMetalSurface > Create(const TestMetalContext &test_metal_context, DlISize surface_size=DlISize())
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
static std::shared_ptr< TypographerContext > Make()
int32_t x
VkSurfaceKHR surface
Definition main.cc:65
uint32_t uint32_t * format
#define FML_DCHECK(condition)
Definition logging.h:122
FlTexture * texture
double y
impeller::testing::MetalScreenshotter MetalScreenshotter
impeller::ISize32 DlISize
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 switch_defs.h:52
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips)
Render the provided display list to a texture with the given size.
Definition ref_ptr.h:261
int32_t height
int32_t width