Flutter Engine
 
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
11#include "third_party/glfw/include/GLFW/glfw3.h"
12
13namespace impeller {
14namespace testing {
15
20
21std::unique_ptr<Screenshot> MetalScreenshotter::MakeScreenshot(
22 AiksContext& aiks_context,
23 const std::shared_ptr<Texture> texture) {
24 @autoreleasepool {
25 id<MTLTexture> metal_texture =
26 std::static_pointer_cast<TextureMTL>(texture)->GetMTLTexture();
27
28 CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
29 CIImage* ciImage = [[CIImage alloc]
30 initWithMTLTexture:metal_texture
31 options:@{kCIImageColorSpace : (__bridge id)color_space}];
32 CGColorSpaceRelease(color_space);
33 FML_CHECK(ciImage);
34
35 std::shared_ptr<Context> context = playground_->GetContext();
36 std::shared_ptr<ContextMTL> context_mtl =
37 std::static_pointer_cast<ContextMTL>(context);
38 CIContext* cicontext =
39 [CIContext contextWithMTLDevice:context_mtl->GetMTLDevice()];
40 FML_CHECK(context);
41
42 CIImage* flipped = [ciImage
43 imageByApplyingOrientation:kCGImagePropertyOrientationDownMirrored];
44
45 CGImageRef cgImage = [cicontext createCGImage:flipped
46 fromRect:[flipped extent]];
47
48 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
49 return std::unique_ptr<MetalScreenshot>(new MetalScreenshot(cgImage));
50 }
51}
52
53} // namespace testing
54} // namespace impeller
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
A screenshot that was produced from MetalScreenshotter.
std::unique_ptr< Screenshot > MakeScreenshot(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