1 /* 2 * Copyright 2023 Google LLC 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 SkSurfaceMetal_DEFINED 9 #define SkSurfaceMetal_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/core/SkSurface.h" 13 #include "include/gpu/ganesh/GrTypes.h" 14 #include "include/gpu/ganesh/SkSurfaceGanesh.h" 15 #include "include/gpu/ganesh/mtl/GrMtlTypes.h" 16 17 namespace SkSurfaces { 18 /** Creates SkSurface from CAMetalLayer. 19 Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be 20 released when the SkSurface is destroyed. 21 22 Only available when Metal API is enabled. 23 24 Will grab the current drawable from the layer and use its texture as a backendRT to 25 create a renderable surface. 26 27 @param context GPU context 28 @param layer GrMTLHandle (expected to be a CAMetalLayer*) 29 @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing 30 @param colorSpace range of colors; may be nullptr 31 @param surfaceProps LCD striping orientation and setting for device independent 32 fonts; may be nullptr 33 @param drawable Pointer to drawable to be filled in when this surface is 34 instantiated; may not be nullptr 35 @return created SkSurface, or nullptr 36 */ 37 SK_API sk_sp<SkSurface> WrapCAMetalLayer(GrRecordingContext* context, 38 GrMTLHandle layer, 39 GrSurfaceOrigin origin, 40 int sampleCnt, 41 SkColorType colorType, 42 sk_sp<SkColorSpace> colorSpace, 43 const SkSurfaceProps* surfaceProps, 44 GrMTLHandle* drawable) SK_API_AVAILABLE_CA_METAL_LAYER; 45 46 /** Creates SkSurface from MTKView. 47 Returned SkSurface takes a reference on the MTKView. The ref on the layer will be 48 released when the SkSurface is destroyed. 49 50 Only available when Metal API is enabled. 51 52 Will grab the current drawable from the layer and use its texture as a backendRT to 53 create a renderable surface. 54 55 @param context GPU context 56 @param layer GrMTLHandle (expected to be a MTKView*) 57 @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing 58 @param colorSpace range of colors; may be nullptr 59 @param surfaceProps LCD striping orientation and setting for device independent 60 fonts; may be nullptr 61 @return created SkSurface, or nullptr 62 */ 63 SK_API sk_sp<SkSurface> WrapMTKView(GrRecordingContext* context, 64 GrMTLHandle mtkView, 65 GrSurfaceOrigin origin, 66 int sampleCnt, 67 SkColorType colorType, 68 sk_sp<SkColorSpace> colorSpace, 69 const SkSurfaceProps* surfaceProps) 70 SK_API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0)); 71 } // namespace SkSurfaces 72 73 #endif 74