blob: fa43295ba1fb768dba77f32ac7cdec1c699b5b36 [file] [log] [blame]
Greg Daniel0576a452017-07-31 16:32:36 -04001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrMtlUtil_DEFINED
9#define GrMtlUtil_DEFINED
10
Greg Daniel0576a452017-07-31 16:32:36 -040011#import <Metal/Metal.h>
12
Brian Salomona6a3df72018-03-23 16:32:22 -040013#include "GrTypesPriv.h"
Timothy Liange30739a2018-07-31 10:51:17 -040014#include "ir/SkSLProgram.h"
Brian Salomona6a3df72018-03-23 16:32:22 -040015
Timothy Liange30739a2018-07-31 10:51:17 -040016class GrMtlGpu;
17class GrSurface;
Brian Salomona6a3df72018-03-23 16:32:22 -040018
Greg Daniel0576a452017-07-31 16:32:36 -040019/**
20 * Returns the Metal texture format for the given GrPixelConfig
21 */
22bool GrPixelConfigToMTLFormat(GrPixelConfig config, MTLPixelFormat* format);
23
24/**
25* Returns the GrPixelConfig for the given Metal texture format
26*/
27GrPixelConfig GrMTLFormatToPixelConfig(MTLPixelFormat format);
28
Timothy Liang4e85e802018-06-28 16:37:18 -040029/**
30 * Returns a id<MTLTexture> to the MTLTexture pointed at by the const void*. Will use
31 * __bridge_transfer if we are adopting ownership.
32 */
33id<MTLTexture> GrGetMTLTexture(const void* mtlTexture, GrWrapOwnership);
34
Timothy Liange886e802018-07-02 16:03:28 -040035/**
36 * Returns a const void* to whatever the id object is pointing to. Always uses __bridge.
37 */
38const void* GrGetPtrFromId(id idObject);
39
Timothy Liangff19c8f2018-07-11 13:27:21 -040040/**
Timothy Liang760dbc42018-07-17 13:28:20 -040041 * Returns a const void* to whatever the id object is pointing to. Always uses __bridge_retained.
42 */
43const void* GrReleaseId(id idObject);
44
45/**
Timothy Liangff19c8f2018-07-11 13:27:21 -040046 * Returns a MTLTextureDescriptor which describes the MTLTexture. Useful when creating a duplicate
47 * MTLTexture without the same storage allocation.
48 */
49MTLTextureDescriptor* GrGetMTLTextureDescriptor(id<MTLTexture> mtlTexture);
50
Timothy Liange30739a2018-07-31 10:51:17 -040051/**
52 * Returns a compiled MTLLibrary created from MSL code generated by SkSLC
53 */
54id<MTLLibrary> GrCompileMtlShaderLibrary(const GrMtlGpu* gpu,
55 const char* shaderString,
56 SkSL::Program::Kind kind,
57 const SkSL::Program::Settings& settings,
58 SkSL::Program::Inputs* outInputs);
59
60/**
61 * Returns a MTLTexture corresponding to the GrSurface. Optionally can do a resolve.
62 */
63id<MTLTexture> GrGetMTLTextureFromSurface(GrSurface* surface, bool doResolve);
64
Greg Daniel0576a452017-07-31 16:32:36 -040065#endif