| Flutter Impeller |

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

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

`#include <metal_screenshot.h>`

Inheritance diagram for impeller::testing::MetalScreenshot:

## 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 18 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_ = CGDataProviderCopyData(data_provider);
13 }

## ◆ ~MetalScreenshot()

impeller::testing::MetalScreenshot::~MetalScreenshot | ( |  | ) |

Definition at line 15 of file metal_screenshot.mm.

15 {
16 CFRelease(pixel_data_);
17 CGImageRelease(cg_image_);
18 }

## 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 20 of file metal_screenshot.mm.

20 {
21 return CFDataGetBytePtr(pixel_data_);
22 }

## ◆ 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 32 of file metal_screenshot.mm.

32 {
33 return CGImageGetBytesPerRow(cg_image_);
34 }

## ◆ GetHeight()

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

Returns the height of the image in pixels.

Implements impeller::testing::Screenshot.

Definition at line 24 of file metal_screenshot.mm.

24 {
25 return CGImageGetHeight(cg_image_);
26 }

## ◆ GetWidth()

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

Returns the width of the image in pixels.

Implements impeller::testing::Screenshot.

Definition at line 28 of file metal_screenshot.mm.

28 {
29 return CGImageGetWidth(cg_image_);
30 }

## ◆ 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 36 of file metal_screenshot.mm.

36 {
37 bool result = false;
38 NSURL* output_url =
39 [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.c_str()]];
40 CGImageDestinationRef destination = CGImageDestinationCreateWithURL(
41 (__bridge CFURLRef)output_url, kUTTypePNG, 1, nullptr);
42 if (destination != nullptr) {
43 CGImageDestinationAddImage(destination, cg_image_,
44 (__bridge CFDictionaryRef) @{});
45
46 if (CGImageDestinationFinalize(destination)) {
47 result = true;
48 }
49
50 CFRelease(destination);
51 }
52 return result;
53 }

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

- impeller/golden_tests/metal_screenshot.h
- impeller/golden_tests/metal_screenshot.mm