| 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* 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
metal_screenshot.h
impeller::testing::MetalScreenshot::GetWidth
size_t GetWidth() const
Definition: metal_screenshot.mm:28
impeller::testing::MetalScreenshot::~MetalScreenshot
~MetalScreenshot()
Definition: metal_screenshot.mm:15
impeller::testing::MetalScreenshot::GetBytesPerRow
size_t GetBytesPerRow() const
Definition: metal_screenshot.mm:32
impeller::testing::MetalScreenshot::GetHeight
size_t GetHeight() const
Definition: metal_screenshot.mm:24
impeller::testing::MetalScreenshot::GetBytes
const UInt8 * GetBytes() const
Definition: metal_screenshot.mm:20
impeller
Definition: aiks_context.cc:10
impeller::testing::MetalScreenshot::WriteToPNG
bool WriteToPNG(const std::string &path) const
Definition: metal_screenshot.mm:36