| 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 ()
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 19 of file metal_screenshotter.h.

## Constructor & Destructor Documentation

## ◆ MetalScreenshotter()

impeller::testing::MetalScreenshotter::MetalScreenshotter | ( |  | ) |

Definition at line 16 of file metal_screenshotter.mm.

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

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

## Member Function Documentation

## ◆ GetPlayground()

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

Implements impeller::testing::Screenshotter.

Definition at line 29 of file metal_screenshotter.h.

29 { 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 22 of file metal_screenshotter.mm.

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

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::PlaygroundBackend::kMetal
@ kMetal
impeller::Vector2
Point Vector2
Definition: point.h:320
impeller::PlaygroundImpl::Create
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
Definition: playground_impl.cc:25
impeller::ISize
TSize< int64_t > ISize
Definition: size.h:138