Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
test_metal_surface_impl.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/testing/test_metal_surface_impl.h"
6
7#include <Metal/Metal.h>
8
9#include "flutter/fml/logging.h"
10#include "flutter/fml/platform/darwin/scoped_nsobject.h"
11#include "flutter/testing/test_metal_context.h"
23
24namespace flutter {
25
26void TestMetalSurfaceImpl::Init(const TestMetalContext::TextureInfo& texture_info,
27 const SkISize& surface_size) {
28 id<MTLTexture> texture = (__bridge id<MTLTexture>)texture_info.texture;
29
30 GrMtlTextureInfo skia_texture_info;
31 skia_texture_info.fTexture.reset([texture retain]);
33 surface_size.width(), surface_size.height(), skgpu::Mipmapped::kNo, skia_texture_info);
34
36 test_metal_context_.GetSkiaContext().get(), backend_texture, kTopLeft_GrSurfaceOrigin, 1,
37 kBGRA_8888_SkColorType, nullptr, nullptr);
38
39 if (!surface) {
40 FML_LOG(ERROR) << "Could not create Skia surface from a Metal texture.";
41 return;
42 }
43
44 surface_ = std::move(surface);
45 texture_info_ = texture_info;
46 is_valid_ = true;
47}
48
50 int64_t texture_id,
51 const SkISize& surface_size)
52 : test_metal_context_(test_metal_context) {
54 const_cast<TestMetalContext&>(test_metal_context_).GetTextureInfo(texture_id);
55 Init(texture_info, surface_size);
56}
57
59 const SkISize& surface_size)
60 : test_metal_context_(test_metal_context) {
61 if (surface_size.isEmpty()) {
62 FML_LOG(ERROR) << "Size of test Metal surface was empty.";
63 return;
64 }
66 const_cast<TestMetalContext&>(test_metal_context_).CreateMetalTexture(surface_size);
67 Init(texture_info, surface_size);
68}
69
71 if (!IsValid()) {
72 return nullptr;
73 }
74
75 if (!surface_) {
76 FML_LOG(ERROR) << "Aborting snapshot because of on-screen surface "
77 "acquisition failure.";
78 return nullptr;
79 }
80
81 auto device_snapshot = surface_->makeImageSnapshot();
82
83 if (!device_snapshot) {
84 FML_LOG(ERROR) << "Could not create the device snapshot while attempting "
85 "to snapshot the Metal surface.";
86 return nullptr;
87 }
88
89 auto host_snapshot = device_snapshot->makeRasterImage();
90
91 if (!host_snapshot) {
92 FML_LOG(ERROR) << "Could not create the host snapshot while attempting to "
93 "snapshot the Metal surface.";
94 return nullptr;
95 }
96
97 return host_snapshot;
98}
99
100// |TestMetalSurface|
102
103// |TestMetalSurface|
105 return is_valid_;
106}
107
108// |TestMetalSurface|
110 return IsValid() ? test_metal_context_.GetSkiaContext() : nullptr;
111}
112
113// |TestMetalSurface|
115 return IsValid() ? surface_ : nullptr;
116}
117
118// |TestMetalSurface|
122
123} // namespace flutter
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
Definition SkImage.cpp:267
sk_sp< SkImage > makeImageSnapshot()
Definition SkSurface.cpp:90
sk_sp< GrDirectContext > GetSkiaContext() const
sk_sp< SkImage > GetRasterSurfaceSnapshot() override
TestMetalSurfaceImpl(const TestMetalContext &test_metal_context, const SkISize &surface_size)
sk_sp< SkSurface > GetSurface() const override
sk_sp< GrDirectContext > GetGrContext() const override
TestMetalContext::TextureInfo GetTextureInfo() override
T * get() const
Definition SkRefCnt.h:303
VkSurfaceKHR surface
Definition main.cc:49
#define FML_LOG(severity)
Definition logging.h:82
void Init()
FlTexture * texture
SK_API GrBackendTexture MakeMtl(int width, int height, skgpu::Mipmapped, const GrMtlTextureInfo &mtlInfo, std::string_view label={})
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
bool isEmpty() const
Definition SkSize.h:31
int64_t texture_id
#define ERROR(message)