| Flutter Impeller |

metal_screenshot.h
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 #ifndef FLUTTER_IMPELLER_GOLDEN_TESTS_METAL_SCREENSHOT_H_
6 #define FLUTTER_IMPELLER_GOLDEN_TESTS_METAL_SCREENSHOT_H_
7
8 #include "flutter/impeller/golden_tests/screenshot.h"
9
10 #include <CoreFoundation/CoreFoundation.h>
11 #include <CoreImage/CoreImage.h>
12 #include <string>
13
14 #include "flutter/fml/platform/darwin/cf_utils.h"
15
16 namespace fml {
17
18 /// fml::CFRef retain and release implementations for CGImageRef.
19 template <>
20 struct CFRefTraits<CGImageRef> {
21 static constexpr CGImageRef kNullValue = nullptr;
22 static void Retain(CGImageRef instance) { CGImageRetain(instance); }
23 static void Release(CGImageRef instance) { CGImageRelease(instance); }
24 };
25
26 } // namespace fml
27
28 namespace impeller {
29 namespace testing {
30
31 /// A screenshot that was produced from `MetalScreenshotter`.
32 class MetalScreenshot : public Screenshot {
33 public:
34 explicit MetalScreenshot(CGImageRef cgImage);
35
36 ~MetalScreenshot();
37
38 const uint8_t* GetBytes() const override;
39
40 size_t GetHeight() const override;
41
42 size_t GetWidth() const override;
43
44 size_t GetBytesPerRow() const override;
45
46 bool WriteToPNG(const std::string& path) const override;
47
48 private:
49 MetalScreenshot(const MetalScreenshot&) = delete;
50
51 MetalScreenshot& operator=(const MetalScreenshot&) = delete;
52 fml::CFRef<CGImageRef> cg_image_;
53 fml::CFRef<CFDataRef> pixel_data_;
54 };
55 } // namespace testing
56 } // namespace impeller
57
58 #endif // FLUTTER_IMPELLER_GOLDEN_TESTS_METAL_SCREENSHOT_H_
impeller::testing::MetalScreenshot
A screenshot that was produced from MetalScreenshotter.
Definition: metal_screenshot.h:32
impeller::testing::MetalScreenshot::GetBytes
const uint8_t * GetBytes() const override
Access raw data of the screenshot.
Definition: metal_screenshot.mm:17
impeller::testing::MetalScreenshot::WriteToPNG
bool WriteToPNG(const std::string &path) const override
Definition: metal_screenshot.mm:33
impeller::testing::MetalScreenshot::GetHeight
size_t GetHeight() const override
Returns the height of the image in pixels.
Definition: metal_screenshot.mm:21
impeller::testing::MetalScreenshot::GetWidth
size_t GetWidth() const override
Returns the width of the image in pixels.
Definition: metal_screenshot.mm:25
impeller::testing::MetalScreenshot::GetBytesPerRow
size_t GetBytesPerRow() const override
Returns number of bytes required to represent one row of the raw image.
Definition: metal_screenshot.mm:29
impeller::testing::MetalScreenshot::~MetalScreenshot
~MetalScreenshot()
impeller::testing::MetalScreenshot::MetalScreenshot
MetalScreenshot(CGImageRef cgImage)
Definition: metal_screenshot.mm:10
impeller::testing::Screenshot
Definition: screenshot.h:16
fml
Definition: metal_screenshot.h:16
impeller
Definition: allocation.cc:12
screenshot.h
fml::CFRefTraits< CGImageRef >::Release
static void Release(CGImageRef instance)
Definition: metal_screenshot.h:23
fml::CFRefTraits< CGImageRef >::Retain
static void Retain(CGImageRef instance)
Definition: metal_screenshot.h:22