Flutter Engine
The 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
5#include "flutter/impeller/golden_tests/metal_screenshotter.h"
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
17 FML_CHECK(::glfwInit() == GLFW_TRUE);
18 PlaygroundSwitches switches;
19 switches.enable_wide_gamut = enable_wide_gamut;
21}
22
23std::unique_ptr<Screenshot> MetalScreenshotter::MakeScreenshot(
24 AiksContext& aiks_context,
25 const Picture& picture,
26 const ISize& size,
27 bool scale_content) {
28 Vector2 content_scale =
29 scale_content ? playground_->GetContentScale() : Vector2{1, 1};
30 std::shared_ptr<Image> image = picture.ToImage(
31 aiks_context,
32 ISize(size.width * content_scale.x, size.height * content_scale.y));
33 std::shared_ptr<Texture> texture = image->GetTexture();
34 id<MTLTexture> metal_texture =
35 std::static_pointer_cast<TextureMTL>(texture)->GetMTLTexture();
36
37 CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
38 CIImage* ciImage = [[CIImage alloc]
39 initWithMTLTexture:metal_texture
40 options:@{kCIImageColorSpace : (__bridge id)color_space}];
41 CGColorSpaceRelease(color_space);
42 FML_CHECK(ciImage);
43
44 std::shared_ptr<Context> context = playground_->GetContext();
45 std::shared_ptr<ContextMTL> context_mtl =
46 std::static_pointer_cast<ContextMTL>(context);
47 CIContext* cicontext =
48 [CIContext contextWithMTLDevice:context_mtl->GetMTLDevice()];
49 FML_CHECK(context);
50
51 CIImage* flipped = [ciImage
52 imageByApplyingOrientation:kCGImagePropertyOrientationDownMirrored];
53
54 CGImageRef cgImage = [cicontext createCGImage:flipped
55 fromRect:[ciImage extent]];
56
57 return std::unique_ptr<MetalScreenshot>(new MetalScreenshot(cgImage));
58}
59
60} // namespace testing
61} // namespace impeller
const char * options
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 Picture &picture, const ISize &size={300, 300}, bool scale_content=true) override
sk_sp< SkImage > image
Definition examples.cpp:29
#define GLFW_TRUE
#define FML_CHECK(condition)
Definition logging.h:85
FlTexture * texture
TSize< int64_t > ISize
Definition size.h:138
const uintptr_t id