| Flutter Impeller |

metal_screenshot.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/golden_tests/metal_screenshot.h"
6
7 namespace impeller {
8 namespace testing {
9
10 MetalScreenshot::MetalScreenshot(CGImageRef cgImage) : cg_image_(cgImage) {
11 CGDataProviderRef data_provider = CGImageGetDataProvider(cgImage);
12 pixel_data_.Reset(CGDataProviderCopyData(data_provider));
13 }
14
15 MetalScreenshot::~MetalScreenshot() = default;
16
17 const uint8_t* MetalScreenshot::GetBytes() const {
18 return CFDataGetBytePtr(pixel_data_);
19 }
20
21 size_t MetalScreenshot::GetHeight() const {
22 return CGImageGetHeight(cg_image_);
23 }
24
25 size_t MetalScreenshot::GetWidth() const {
26 return CGImageGetWidth(cg_image_);
27 }
28
29 size_t MetalScreenshot::GetBytesPerRow() const {
30 return CGImageGetBytesPerRow(cg_image_);
31 }
32
33 bool MetalScreenshot::WriteToPNG(const std::string& path) const {
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 }
49
50 } // namespace testing
51 } // namespace impeller
impeller::testing::MetalScreenshot::GetBytes
const uint8_t * GetBytes() const override
Access raw data of the screenshot.
Definition: metal_screenshot.mm:17
impeller::testing::MetalScreenshot::WriteToPNG
bool WriteToPNG(const std::string &path) const override
Definition: metal_screenshot.mm:33
impeller::testing::MetalScreenshot::GetHeight
size_t GetHeight() const override
Returns the height of the image in pixels.
Definition: metal_screenshot.mm:21
impeller::testing::MetalScreenshot::GetWidth
size_t GetWidth() const override
Returns the width of the image in pixels.
Definition: metal_screenshot.mm:25
impeller::testing::MetalScreenshot::GetBytesPerRow
size_t GetBytesPerRow() const override
Returns number of bytes required to represent one row of the raw image.
Definition: metal_screenshot.mm:29
impeller::testing::MetalScreenshot::~MetalScreenshot
~MetalScreenshot()
impeller::testing::MetalScreenshot::MetalScreenshot
MetalScreenshot(CGImageRef cgImage)
Definition: metal_screenshot.mm:10
metal_screenshot.h
impeller
Definition: allocation.cc:12