Flutter Impeller
impeller::testing::MetalScreenshotter Class Reference

#include <metal_screenshotter.h>

Inheritance diagram for impeller::testing::MetalScreenshotter:
impeller::testing::Screenshotter

Public Member Functions

 MetalScreenshotter (const PlaygroundSwitches &switches)
 
std::unique_ptr< ScreenshotMakeScreenshot (AiksContext &aiks_context, const std::shared_ptr< Texture > texture) override
 
PlaygroundImplGetPlayground () override
 
- Public Member Functions inherited from impeller::testing::Screenshotter
virtual ~Screenshotter ()=default
 

Detailed Description

Converts Pictures and DisplayLists to MetalScreenshots with the playground backend.

Definition at line 18 of file metal_screenshotter.h.

Constructor & Destructor Documentation

◆ MetalScreenshotter()

impeller::testing::MetalScreenshotter::MetalScreenshotter ( const PlaygroundSwitches switches)
explicit

Definition at line 16 of file metal_screenshotter.mm.

16  {
17  FML_CHECK(::glfwInit() == GLFW_TRUE);
18  playground_ = PlaygroundImpl::Create(PlaygroundBackend::kMetal, switches);
19 }
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)

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

Member Function Documentation

◆ GetPlayground()

PlaygroundImpl& impeller::testing::MetalScreenshotter::GetPlayground ( )
inlineoverridevirtual

Implements impeller::testing::Screenshotter.

Definition at line 26 of file metal_screenshotter.h.

26 { return *playground_; }

◆ MakeScreenshot()

std::unique_ptr< Screenshot > impeller::testing::MetalScreenshotter::MakeScreenshot ( AiksContext aiks_context,
const std::shared_ptr< Texture texture 
)
overridevirtual

Implements impeller::testing::Screenshotter.

Definition at line 21 of file metal_screenshotter.mm.

23  {
24  @autoreleasepool {
25  id<MTLTexture> metal_texture =
26  std::static_pointer_cast<TextureMTL>(texture)->GetMTLTexture();
27 
28  CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
29  CIImage* ciImage = [[CIImage alloc]
30  initWithMTLTexture:metal_texture
31  options:@{kCIImageColorSpace : (__bridge id)color_space}];
32  CGColorSpaceRelease(color_space);
33  FML_CHECK(ciImage);
34 
35  std::shared_ptr<Context> context = playground_->GetContext();
36  std::shared_ptr<ContextMTL> context_mtl =
37  std::static_pointer_cast<ContextMTL>(context);
38  CIContext* cicontext =
39  [CIContext contextWithMTLDevice:context_mtl->GetMTLDevice()];
40  FML_CHECK(context);
41 
42  CIImage* flipped = [ciImage
43  imageByApplyingOrientation:kCGImagePropertyOrientationDownMirrored];
44 
45  CGImageRef cgImage = [cicontext createCGImage:flipped
46  fromRect:[flipped extent]];
47 
48  // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
49  return std::unique_ptr<MetalScreenshot>(new MetalScreenshot(cgImage));
50  }
51 }

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