Flutter Impeller
impeller::testing::MetalScreenshoter Class Reference

Converts Pictures to MetalScreenshots with the playground backend. More...

#include <metal_screenshoter.h>

Public Member Functions

 MetalScreenshoter ()
 
std::unique_ptr< MetalScreenshotMakeScreenshot (AiksContext &aiks_context, const Picture &picture, const ISize &size={300, 300})
 
const PlaygroundImplGetPlayground () const
 

Detailed Description

Converts Pictures to MetalScreenshots with the playground backend.

Definition at line 16 of file metal_screenshoter.h.

Constructor & Destructor Documentation

◆ MetalScreenshoter()

impeller::testing::MetalScreenshoter::MetalScreenshoter ( )

Definition at line 16 of file metal_screenshoter.mm.

16  {
17  FML_CHECK(::glfwInit() == GLFW_TRUE);
18  playground_ =
20 }

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

Member Function Documentation

◆ GetPlayground()

const PlaygroundImpl& impeller::testing::MetalScreenshoter::GetPlayground ( ) const
inline

Definition at line 25 of file metal_screenshoter.h.

25 { return *playground_; }

◆ MakeScreenshot()

std::unique_ptr< MetalScreenshot > impeller::testing::MetalScreenshoter::MakeScreenshot ( AiksContext aiks_context,
const Picture picture,
const ISize size = {300, 300} 
)

Definition at line 22 of file metal_screenshoter.mm.

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

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::PlaygroundBackend::kMetal
@ kMetal
impeller::Vector2
Point Vector2
Definition: point.h:310
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:136