| Flutter Impeller |

Public Member Functions | List of all members
impeller::testing::MetalScreenshotter Class Reference

`#include <metal_screenshotter.h>`

Inheritance diagram for impeller::testing::MetalScreenshotter:

## Public Member Functions
| MetalScreenshotter (bool enable_wide_gamut)
std::unique_ptr< Screenshot > | MakeScreenshot (AiksContext &aiks_context, const Picture &picture, const ISize &size={300, 300}, bool scale_content=true) override
PlaygroundImpl & | GetPlayground () override
Public Member Functions inherited from impeller::testing::Screenshotter
virtual | ~Screenshotter ()=default

## Detailed Description

Converts `Picture`s and `DisplayList`s to `MetalScreenshot`s with the playground backend.

Definition at line 18 of file metal_screenshotter.h.

## Constructor & Destructor Documentation

## ◆ MetalScreenshotter()

impeller::testing::MetalScreenshotter::MetalScreenshotter | ( | bool | enable_wide_gamut | ) |
| explicit

Definition at line 16 of file metal_screenshotter.mm.

16 {
17 FML_CHECK(::glfwInit() == GLFW_TRUE);
18 PlaygroundSwitches switches;
19 switches.enable_wide_gamut = enable_wide_gamut;
20 playground_ = PlaygroundImpl::Create(PlaygroundBackend::kMetal, switches);
21 }

References impeller::PlaygroundImpl::Create(), impeller::PlaygroundSwitches::enable_wide_gamut, and impeller::kMetal.

## Member Function Documentation

## ◆ GetPlayground()

PlaygroundImpl& impeller::testing::MetalScreenshotter::GetPlayground | ( |  | ) |
| inline override virtual

Implements impeller::testing::Screenshotter.

Definition at line 28 of file metal_screenshotter.h.

28 { return *playground_; }

## ◆ MakeScreenshot()

std::unique_ptr< Screenshot > impeller::testing::MetalScreenshotter::MakeScreenshot | ( | AiksContext & | aiks_context,
|  | const Picture & | picture,
|  | const ISize & | size = `{300, 300}`,
|  | bool | scale_content = `true`
| ) |  |
| override virtual

Implements impeller::testing::Screenshotter.

Definition at line 23 of file metal_screenshotter.mm.

27 {
28 Vector2 content_scale =
29 scale_content ? playground_->GetContentScale() : Vector2{1, 1};
30 std::shared_ptr<Image> image = picture.ToImage(
31 aiks_context,
32 ISize(size.width * content_scale.x, size.height * content_scale.y));
33 std::shared_ptr<Texture> texture = image->GetTexture();
34 id<MTLTexture> metal_texture =
35 std::static_pointer_cast<TextureMTL>(texture)->GetMTLTexture();
36
37 CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
38 CIImage* ciImage = [[CIImage alloc]
39 initWithMTLTexture:metal_texture
40 options:@{kCIImageColorSpace : (__bridge id)color_space}];
41 CGColorSpaceRelease(color_space);
42 FML_CHECK(ciImage);
43
44 std::shared_ptr<Context> context = playground_->GetContext();
45 std::shared_ptr<ContextMTL> context_mtl =
46 std::static_pointer_cast<ContextMTL>(context);
47 CIContext* cicontext =
48 [CIContext contextWithMTLDevice:context_mtl->GetMTLDevice()];
49 FML_CHECK(context);
50
51 CIImage* flipped = [ciImage
52 imageByApplyingOrientation:kCGImagePropertyOrientationDownMirrored];
53
54 CGImageRef cgImage = [cicontext createCGImage:flipped
55 fromRect:[ciImage extent]];
56
57 return std::unique_ptr<MetalScreenshot>(new MetalScreenshot(cgImage));
58 }

References impeller::TSize< T >::height, impeller::Picture::ToImage(), impeller::TSize< T >::width, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

The documentation for this class was generated from the following files:

- impeller/golden_tests/metal_screenshotter.h
- impeller/golden_tests/metal_screenshotter.mm

impeller::ISize
ISize64 ISize
Definition: size.h:140
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::Vector2
Point Vector2
Definition: point.h:326
impeller::PlaygroundImpl::Create
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
Definition: playground_impl.cc:25