| 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 bool MetalScreenshot::WriteToPNG(const std::string& path) const {
33 bool result = false;
34 NSURL* output_url =
35 [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.c_str()]];
36 CGImageDestinationRef destination = CGImageDestinationCreateWithURL(
37 (__bridge CFURLRef)output_url, kUTTypePNG, 1, nullptr);
38 if (destination != nullptr) {
39 CGImageDestinationAddImage(destination, cg_image_,
40 (__bridge CFDictionaryRef) @{});
41
42 if (CGImageDestinationFinalize(destination)) {
43 result = true;
44 }
45
46 CFRelease(destination);
47 }
48 return result;
49 }
50
51 } // namespace testing
52 } // 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::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:32