Flutter Engine
The Flutter Engine
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
6
7namespace impeller {
8namespace testing {
9
10MetalScreenshot::MetalScreenshot(CGImageRef cgImage) : cg_image_(cgImage) {
11 CGDataProviderRef data_provider = CGImageGetDataProvider(cgImage);
12 pixel_data_ = CGDataProviderCopyData(data_provider);
13}
14
16 CFRelease(pixel_data_);
17 CGImageRelease(cg_image_);
18}
19
20const uint8_t* MetalScreenshot::GetBytes() const {
21 return CFDataGetBytePtr(pixel_data_);
22}
23
25 return CGImageGetHeight(cg_image_);
26}
27
29 return CGImageGetWidth(cg_image_);
30}
31
33 return CGImageGetBytesPerRow(cg_image_);
34}
35
36bool 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
const uint8_t * GetBytes() const override
Access raw data of the screenshot.
bool WriteToPNG(const std::string &path) const override
size_t GetHeight() const override
Returns the height of the image in pixels.
size_t GetWidth() const override
Returns the width of the image in pixels.
size_t GetBytesPerRow() const override
Returns number of bytes required to represent one row of the raw image.
GAsyncResult * result
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57