Flutter Impeller
impeller::testing::MetalScreenshot Class Reference

A screenshot that was produced from MetalScreenshotter. More...

#include <metal_screenshot.h>

Inheritance diagram for impeller::testing::MetalScreenshot:
impeller::testing::Screenshot

Public Member Functions

 MetalScreenshot (CGImageRef cgImage)
 
 ~MetalScreenshot ()
 
const uint8_t * GetBytes () const override
 Access raw data of the screenshot. More...
 
size_t GetHeight () const override
 Returns the height of the image in pixels. More...
 
size_t GetWidth () const override
 Returns the width of the image in pixels. More...
 
size_t GetBytesPerRow () const override
 Returns number of bytes required to represent one row of the raw image. More...
 
bool WriteToPNG (const std::string &path) const override
 
- Public Member Functions inherited from impeller::testing::Screenshot
virtual ~Screenshot ()=default
 

Detailed Description

A screenshot that was produced from MetalScreenshotter.

Definition at line 32 of file metal_screenshot.h.

Constructor & Destructor Documentation

◆ MetalScreenshot()

impeller::testing::MetalScreenshot::MetalScreenshot ( CGImageRef  cgImage)
explicit

Definition at line 10 of file metal_screenshot.mm.

10  : cg_image_(cgImage) {
11  CGDataProviderRef data_provider = CGImageGetDataProvider(cgImage);
12  pixel_data_.Reset(CGDataProviderCopyData(data_provider));
13 }

◆ ~MetalScreenshot()

impeller::testing::MetalScreenshot::~MetalScreenshot ( )
default

Member Function Documentation

◆ GetBytes()

const uint8_t * impeller::testing::MetalScreenshot::GetBytes ( ) const
overridevirtual

Access raw data of the screenshot.

Implements impeller::testing::Screenshot.

Definition at line 17 of file metal_screenshot.mm.

17  {
18  return CFDataGetBytePtr(pixel_data_);
19 }

◆ GetBytesPerRow()

size_t impeller::testing::MetalScreenshot::GetBytesPerRow ( ) const
overridevirtual

Returns number of bytes required to represent one row of the raw image.

Implements impeller::testing::Screenshot.

Definition at line 29 of file metal_screenshot.mm.

29  {
30  return CGImageGetBytesPerRow(cg_image_);
31 }

◆ GetHeight()

size_t impeller::testing::MetalScreenshot::GetHeight ( ) const
overridevirtual

Returns the height of the image in pixels.

Implements impeller::testing::Screenshot.

Definition at line 21 of file metal_screenshot.mm.

21  {
22  return CGImageGetHeight(cg_image_);
23 }

◆ GetWidth()

size_t impeller::testing::MetalScreenshot::GetWidth ( ) const
overridevirtual

Returns the width of the image in pixels.

Implements impeller::testing::Screenshot.

Definition at line 25 of file metal_screenshot.mm.

25  {
26  return CGImageGetWidth(cg_image_);
27 }

◆ WriteToPNG()

bool impeller::testing::MetalScreenshot::WriteToPNG ( const std::string &  path) const
overridevirtual

Synchronously write the screenshot to disk as a PNG at path. Returns true if it succeeded.

Implements impeller::testing::Screenshot.

Definition at line 33 of file metal_screenshot.mm.

33  {
34  bool result = false;
35  NSURL* output_url =
36  [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.c_str()]];
37  fml::CFRef<CGImageDestinationRef> destination(CGImageDestinationCreateWithURL(
38  (__bridge CFURLRef)output_url, kUTTypePNG, 1, nullptr));
39  if (destination) {
40  CGImageDestinationAddImage(destination, cg_image_,
41  (__bridge CFDictionaryRef) @{});
42 
43  if (CGImageDestinationFinalize(destination)) {
44  result = true;
45  }
46  }
47  return result;
48 }

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