forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmetal_screenshot.mm
More file actions
52 lines (41 loc) · 1.43 KB
/
metal_screenshot.mm
File metadata and controls
52 lines (41 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/golden_tests/metal_screenshot.h"
namespace impeller {
namespace testing {
MetalScreenshot::MetalScreenshot(CGImageRef cgImage) : cgImage_(cgImage) {
CGDataProviderRef data_provider = CGImageGetDataProvider(cgImage);
pixel_data_ = CGDataProviderCopyData(data_provider);
}
MetalScreenshot::~MetalScreenshot() {
CFRelease(pixel_data_);
CGImageRelease(cgImage_);
}
const UInt8* MetalScreenshot::GetBytes() const {
return CFDataGetBytePtr(pixel_data_);
}
size_t MetalScreenshot::GetHeight() const {
return CGImageGetHeight(cgImage_);
}
size_t MetalScreenshot::GetWidth() const {
return CGImageGetWidth(cgImage_);
}
bool MetalScreenshot::WriteToPNG(const std::string& path) const {
bool result = false;
NSURL* output_url =
[NSURL fileURLWithPath:[NSString stringWithUTF8String:path.c_str()]];
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(
(__bridge CFURLRef)output_url, kUTTypePNG, 1, nullptr);
if (destination != nullptr) {
CGImageDestinationAddImage(destination, cgImage_,
(__bridge CFDictionaryRef) @{});
if (CGImageDestinationFinalize(destination)) {
result = true;
}
CFRelease(destination);
}
return result;
}
} // namespace testing
} // namespace impeller