Use metal as backend in skia

Viewed 1507

I want to try the metal with skia, but the surface always return null, and can't find any sample code around..

Here is the code:

_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);

The surface always create failed, return null, the context and target is valid. also I tried another pixelformat, like BGRA8888Unorm, still not work.

0 Answers
Related