Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
metal_screenshotter.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#include <CoreImage/CoreImage.h>
10#define GLFW_INCLUDE_NONE
13
14namespace impeller {
15namespace testing {
16
18
19std::unique_ptr<Screenshot> MetalScreenshotter::MakeScreenshot(
20 const AiksContext& aiks_context,
21 const std::shared_ptr<Texture>& texture) {
22 return MakeScreenshot(aiks_context.GetContext(), texture);
23}
24
25std::unique_ptr<Screenshot> Screenshotter::MakeMetalScreenshot(
26 std::shared_ptr<Context>& context,
27 const std::shared_ptr<Texture>& texture) {
29}
30
31std::unique_ptr<Screenshot> MetalScreenshotter::MakeScreenshot(
32 const std::shared_ptr<Context>& context,
33 const std::shared_ptr<Texture>& texture) {
34 @autoreleasepool {
36 if (auto cmd_buffer = context->CreateCommandBuffer()) {
37 if (context->GetCommandQueue()
38 ->Submit({cmd_buffer},
39 [&latch](CommandBuffer::Status status) {
40 FML_CHECK(status == CommandBuffer::Status::kCompleted);
41 latch.Signal();
42 })
43 .ok()) {
44 latch.Wait();
45 }
46 }
47
48 id<MTLTexture> metal_texture =
49 std::static_pointer_cast<TextureMTL>(texture)->GetMTLTexture();
50
51 CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
52 CIImage* ciImage = [[CIImage alloc]
53 initWithMTLTexture:metal_texture
54 options:@{kCIImageColorSpace : (__bridge id)color_space}];
55 CGColorSpaceRelease(color_space);
56 FML_CHECK(ciImage);
57
58 std::shared_ptr<ContextMTL> context_mtl =
59 std::static_pointer_cast<ContextMTL>(context);
60 CIContext* cicontext =
61 [CIContext contextWithMTLDevice:context_mtl->GetMTLDevice()];
63
64 CIImage* flipped = [ciImage
65 imageByApplyingOrientation:kCGImagePropertyOrientationDownMirrored];
66
67 CGImageRef cgImage = [cicontext createCGImage:flipped
68 fromRect:[flipped extent]];
69
70 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
71 return std::unique_ptr<MetalScreenshot>(new MetalScreenshot(cgImage));
72 }
73}
74
75} // namespace testing
76} // namespace impeller
std::shared_ptr< Context > GetContext() const
A screenshot that was produced from MetalScreenshotter.
static std::unique_ptr< Screenshot > MakeScreenshot(const std::shared_ptr< Context > &context, const std::shared_ptr< Texture > &texture)
#define FML_CHECK(condition)
Definition logging.h:104
FlTexture * texture
std::shared_ptr< ContextGLES > context
const uintptr_t id