16MtlSampler::MtlSampler(
const MtlSharedContext* sharedContext,
17 sk_cfp<id<MTLSamplerState>> samplerState)
19 , fSamplerState(
std::move(samplerState)) {}
25 return MTLSamplerAddressModeClampToEdge;
27 return MTLSamplerAddressModeRepeat;
29 return MTLSamplerAddressModeMirrorRepeat;
36 if (@available(macOS 10.12, iOS 14.0, tvOS 14.0, *)) {
38 return MTLSamplerAddressModeClampToBorderColor;
41 return MTLSamplerAddressModeClampToZero;
51 sk_cfp<MTLSamplerDescriptor*>
desc([[MTLSamplerDescriptor alloc]
init]);
53 MTLSamplerMinMagFilter minMagFilter = [&] {
54 switch (samplingOptions.
filter) {
61 MTLSamplerMipFilter mipFilter = [&] {
62 switch (samplingOptions.
mipmap) {
70 (*desc).rAddressMode = MTLSamplerAddressModeClampToEdge;
73 (*desc).magFilter = minMagFilter;
74 (*desc).minFilter = minMagFilter;
75 (*desc).mipFilter = mipFilter;
76 (*desc).lodMinClamp = 0.0f;
77 (*desc).lodMaxClamp = FLT_MAX;
78 (*desc).maxAnisotropy = 1;
79 (*desc).normalizedCoordinates =
true;
80 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
81 (*desc).compareFunction = MTLCompareFunctionNever;
83#ifdef SK_ENABLE_MTL_DEBUG_INFO
84 NSString* tileModeLabels[] = {
90 NSString* minMagFilterLabels[] = {
94 NSString* mipFilterLabels[] = {
100 (*desc).label = [NSString stringWithFormat:
@"X%@Y%@%@%@",
101 tileModeLabels[(
int)xTileMode],
102 tileModeLabels[(
int)yTileMode],
103 minMagFilterLabels[(
int)samplingOptions.
filter],
104 mipFilterLabels[(
int)samplingOptions.
mipmap]];
107 sk_cfp<id<MTLSamplerState>> sampler(
108 [sharedContext->
device() newSamplerStateWithDescriptor:
desc.get()]);
115void MtlSampler::freeGpuData() {
116 fSamplerState.reset();
bool clampToBorderSupport() const
const MtlCaps & mtlCaps() const
id< MTLDevice > device() const
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
std::function< ProfileSample(void)> Sampler
Sampler is run during SamplingProfiler::SampleRepeatedly. Each platform should implement its version ...
static MTLSamplerAddressMode tile_mode_to_mtl_sampler_address(SkTileMode tileMode, const Caps &caps)
const SkFilterMode filter
const SkMipmapMode mipmap