我想尝试带金属的金属,但是表面总是返回null,并且周围找不到任何示例代码。
代码如下:
_device = MTLCreateSystemDefaultDevice();
MTLTextureDescriptor* textureDst = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm width:480 height:320 mipmapped:NO];
_texture = [_device newTextureWithDescriptor:textureDst];
_queue = [_device newCommandQueue];
auto context = (GrContext::MakeMetal((__bridge_retained void*)_device,
(__bridge_retained void*)_queue));
GrMtlTextureInfo info;
info.fTexture = (__bridge_retained void*)_texture;
GrBackendRenderTarget target(480, 320, 1, info);
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeSRGB();
SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
const SkImageInfo infos = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
sk_sp<SkSurface> surface(SkSurface::MakeFromBackendRenderTarget(context.get(), target, kBottomLeft_GrSurfaceOrigin,nullptr,&props);
表面始终创建失败,返回null,上下文和目标有效。
我也尝试了另一种像素格式,例如BGRA8888Unorm
,仍然无法正常工作。