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 
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_.Reset(CGDataProviderCopyData(data_provider));
13 }
14 
16 
17 const uint8_t* MetalScreenshot::GetBytes() const {
18  return CFDataGetBytePtr(pixel_data_);
19 }
20 
22  return CGImageGetHeight(cg_image_);
23 }
24 
25 size_t MetalScreenshot::GetWidth() const {
26  return CGImageGetWidth(cg_image_);
27 }
28 
30  return CGImageGetBytesPerRow(cg_image_);
31 }
32 
33 bool MetalScreenshot::WriteToPNG(const std::string& path) const {
34  bool result = false;
35  NSURL* output_url =
36  [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.c_str()]];
37  fml::CFRef<CGImageDestinationRef> destination(CGImageDestinationCreateWithURL(
38  (__bridge CFURLRef)output_url, kUTTypePNG, 1, nullptr));
39  if (destination) {
40  CGImageDestinationAddImage(destination, cg_image_,
41  (__bridge CFDictionaryRef) @{});
42 
43  if (CGImageDestinationFinalize(destination)) {
44  result = true;
45  }
46  }
47  return result;
48 }
49 
50 } // namespace testing
51 } // 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.