| Flutter Impeller |

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
5 #include "flutter/impeller/golden_tests/metal_screenshotter.h"
6
7 #include <CoreImage/CoreImage.h>
8 #include "impeller/renderer/backend/metal/context_mtl.h"
9 #include "impeller/renderer/backend/metal/texture_mtl.h"
10 #define GLFW_INCLUDE_NONE
11 #include "third_party/glfw/include/GLFW/glfw3.h"
12
13 namespace impeller {
14 namespace testing {
15
16 MetalScreenshotter::MetalScreenshotter(bool enable_wide_gamut) {
17 FML_CHECK(::glfwInit() == GLFW_TRUE);
18 PlaygroundSwitches switches;
19 switches.enable_wide_gamut = enable_wide_gamut;
20 playground_ = PlaygroundImpl::Create(PlaygroundBackend::kMetal, switches);
21 }
22
23 std::unique_ptr<Screenshot> MetalScreenshotter::MakeScreenshot(
24 AiksContext& aiks_context,
25 const std::shared_ptr<Texture> texture) {
26 @autoreleasepool {
27 id<MTLTexture> metal_texture =
28 std::static_pointer_cast<TextureMTL>(texture)->GetMTLTexture();
29
30 CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
31 CIImage* ciImage = [[CIImage alloc]
32 initWithMTLTexture:metal_texture
33 options:@{kCIImageColorSpace : (__bridge id)color_space}];
34 CGColorSpaceRelease(color_space);
35 FML_CHECK(ciImage);
36
37 std::shared_ptr<Context> context = playground_->GetContext();
38 std::shared_ptr<ContextMTL> context_mtl =
39 std::static_pointer_cast<ContextMTL>(context);
40 CIContext* cicontext =
41 [CIContext contextWithMTLDevice:context_mtl->GetMTLDevice()];
42 FML_CHECK(context);
43
44 CIImage* flipped = [ciImage
45 imageByApplyingOrientation:kCGImagePropertyOrientationDownMirrored];
46
47 CGImageRef cgImage = [cicontext createCGImage:flipped
48 fromRect:[ciImage extent]];
49
50 return std::unique_ptr<MetalScreenshot>(new MetalScreenshot(cgImage));
51 }
52 }
53
54 } // namespace testing
55 } // namespace impeller
impeller::AiksContext
Definition: aiks_context.h:19
impeller::testing::MetalScreenshot
A screenshot that was produced from MetalScreenshotter.
Definition: metal_screenshot.h:18
context_mtl.h
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::testing::MetalScreenshotter::MetalScreenshotter
MetalScreenshotter(bool enable_wide_gamut)
Definition: metal_screenshotter.mm:16
impeller::PlaygroundSwitches::enable_wide_gamut
bool enable_wide_gamut
Definition: switches.h:35
impeller::testing::MetalScreenshotter::MakeScreenshot
std::unique_ptr< Screenshot > MakeScreenshot(AiksContext &aiks_context, const std::shared_ptr< Texture > texture) override
Definition: metal_screenshotter.mm:23
impeller::PlaygroundImpl::Create
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
Definition: playground_impl.cc:25
impeller::PlaygroundSwitches
Definition: switches.h:15
texture_mtl.h
metal_screenshotter.h
impeller
Definition: allocation.cc:12