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
12#include "third_party/glfw/include/GLFW/glfw3.h"
13
14namespace impeller {
15namespace testing {
16
21
22std::unique_ptr<Screenshot> MetalScreenshotter::MakeScreenshot(
23 const AiksContext& aiks_context,
24 const std::shared_ptr<Texture> texture) {
25 @autoreleasepool {
26 std::shared_ptr<Context> context = aiks_context.GetContext();
28 if (auto cmd_buffer = context->CreateCommandBuffer()) {
29 if (context->GetCommandQueue()
30 ->Submit({cmd_buffer},
31 [&latch](CommandBuffer::Status status) {
32 FML_CHECK(status == CommandBuffer::Status::kCompleted);
33 latch.Signal();
34 })
35 .ok()) {
36 latch.Wait();
37 }
38 }
39
40 id<MTLTexture> metal_texture =
41 std::static_pointer_cast<TextureMTL>(texture)->GetMTLTexture();
42
43 CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
44 CIImage* ciImage = [[CIImage alloc]
45 initWithMTLTexture:metal_texture
46 options:@{kCIImageColorSpace : (__bridge id)color_space}];
47 CGColorSpaceRelease(color_space);
48 FML_CHECK(ciImage);
49
50 std::shared_ptr<ContextMTL> context_mtl =
51 std::static_pointer_cast<ContextMTL>(context);
52 CIContext* cicontext =
53 [CIContext contextWithMTLDevice:context_mtl->GetMTLDevice()];
54 FML_CHECK(context);
55
56 CIImage* flipped = [ciImage
57 imageByApplyingOrientation:kCGImagePropertyOrientationDownMirrored];
58
59 CGImageRef cgImage = [cicontext createCGImage:flipped
60 fromRect:[flipped extent]];
61
62 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
63 return std::unique_ptr<MetalScreenshot>(new MetalScreenshot(cgImage));
64 }
65}
66
67} // namespace testing
68} // namespace impeller
std::shared_ptr< Context > GetContext() const
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
A screenshot that was produced from MetalScreenshotter.
std::unique_ptr< Screenshot > MakeScreenshot(const AiksContext &aiks_context, const std::shared_ptr< Texture > texture) override
MetalScreenshotter(const PlaygroundSwitches &switches)
#define GLFW_TRUE
#define FML_CHECK(condition)
Definition logging.h:104
FlTexture * texture
const uintptr_t id