| Flutter Impeller |

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

`#include <metal_screenshotter.h>`

## Public Member Functions
| MetalScreenshotter ()
std::unique_ptr< MetalScreenshot > | MakeScreenshot (AiksContext &aiks_context, const Picture &picture, const ISize &size={300, 300}, bool scale_content=true)
PlaygroundImpl & | GetPlayground ()

## 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 | ( |  | ) |

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

Definition at line 28 of file metal_screenshotter.h.

28 { return *playground_; }

## ◆ MakeScreenshot()

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

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 CIImage* ciImage = [[CIImage alloc] initWithMTLTexture:metal_texture
41 options:@{}];
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::PlaygroundBackend::kMetal
@ kMetal
impeller::Vector2
Point Vector2
Definition: point.h:312
impeller::PlaygroundImpl::Create
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
Definition: playground_impl.cc:24
impeller::ISize
TSize< int64_t > ISize
Definition: size.h:138