5#include "flutter/testing/test_metal_surface_impl.h"
7#include <Metal/Metal.h>
9#include "flutter/fml/logging.h"
10#include "flutter/fml/platform/darwin/scoped_nsobject.h"
11#include "flutter/testing/test_metal_context.h"
26void TestMetalSurfaceImpl::Init(
const TestMetalContext::TextureInfo& texture_info,
28 id<MTLTexture>
texture = (__bridge id<MTLTexture>)texture_info.texture;
30 GrMtlTextureInfo skia_texture_info;
31 skia_texture_info.fTexture.reset([
texture retain]);
40 FML_LOG(
ERROR) <<
"Could not create Skia surface from a Metal texture.";
45 texture_info_ = texture_info;
52 : test_metal_context_(test_metal_context) {
55 Init(texture_info, surface_size);
60 : test_metal_context_(test_metal_context) {
62 FML_LOG(
ERROR) <<
"Size of test Metal surface was empty.";
66 const_cast<TestMetalContext&
>(test_metal_context_).CreateMetalTexture(surface_size);
67 Init(texture_info, surface_size);
76 FML_LOG(
ERROR) <<
"Aborting snapshot because of on-screen surface "
77 "acquisition failure.";
83 if (!device_snapshot) {
84 FML_LOG(
ERROR) <<
"Could not create the device snapshot while attempting "
85 "to snapshot the Metal surface.";
89 auto host_snapshot = device_snapshot->makeRasterImage();
92 FML_LOG(
ERROR) <<
"Could not create the host snapshot while attempting to "
93 "snapshot the Metal surface.";
104bool TestMetalSurfaceImpl::IsValid()
const {
110 return IsValid() ? test_metal_context_.
GetSkiaContext() :
nullptr;
115 return IsValid() ? surface_ :
nullptr;
119TestMetalContext::TextureInfo TestMetalSurfaceImpl::GetTextureInfo() {
120 return IsValid() ? texture_info_ : TestMetalContext::TextureInfo();
@ kTopLeft_GrSurfaceOrigin
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
sk_sp< SkImage > makeImageSnapshot()
sk_sp< GrDirectContext > GetSkiaContext() const
#define FML_LOG(severity)
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)
constexpr int32_t width() const
constexpr int32_t height() const