| 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_ = CGDataProviderCopyData(data_provider);
13 }
14
15 MetalScreenshot::~MetalScreenshot() {
16 CFRelease(pixel_data_);
17 CGImageRelease(cg_image_);
18 }
19
20 const uint8_t* MetalScreenshot::GetBytes() const {
21 return CFDataGetBytePtr(pixel_data_);
22 }
23
24 size_t MetalScreenshot::GetHeight() const {
25 return CGImageGetHeight(cg_image_);
26 }
27
28 size_t MetalScreenshot::GetWidth() const {
29 return CGImageGetWidth(cg_image_);
30 }
31
32 size_t MetalScreenshot::GetBytesPerRow() const {
33 return CGImageGetBytesPerRow(cg_image_);
34 }
35
36 bool MetalScreenshot::WriteToPNG(const std::string& path) const {
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 }
54
55 } // namespace testing
56 } // namespace impeller
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:32
impeller::testing::MetalScreenshot::GetBytes
const uint8_t * GetBytes() const override
Access raw data of the screenshot.
Definition: metal_screenshot.mm:20
metal_screenshot.h
impeller::testing::MetalScreenshot::MetalScreenshot
MetalScreenshot(CGImageRef cgImage)
Definition: metal_screenshot.mm:10
impeller::testing::MetalScreenshot::WriteToPNG
bool WriteToPNG(const std::string &path) const override
Definition: metal_screenshot.mm:36
impeller::testing::MetalScreenshot::GetHeight
size_t GetHeight() const override
Returns the height of the image in pixels.
Definition: metal_screenshot.mm:24
impeller::testing::MetalScreenshot::~MetalScreenshot
~MetalScreenshot()
Definition: metal_screenshot.mm:15
impeller::testing::MetalScreenshot::GetWidth
size_t GetWidth() const override
Returns the width of the image in pixels.
Definition: metal_screenshot.mm:28
impeller
Definition: aiks_blur_unittests.cc:20