Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
sampler_library_mtl.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
9
10namespace impeller {
11
12SamplerLibraryMTL::SamplerLibraryMTL(id<MTLDevice> device) : device_(device) {}
13
14SamplerLibraryMTL::~SamplerLibraryMTL() = default;
15
16static const std::unique_ptr<const Sampler> kNullSampler = nullptr;
17
18const std::unique_ptr<const Sampler>& SamplerLibraryMTL::GetSampler(
19 SamplerDescriptor descriptor) {
20 auto found = samplers_.find(descriptor);
21 if (found != samplers_.end()) {
22 return found->second;
23 }
24 if (!device_) {
25 return kNullSampler;
26 }
27 auto desc = [[MTLSamplerDescriptor alloc] init];
28 desc.minFilter = ToMTLSamplerMinMagFilter(descriptor.min_filter);
29 desc.magFilter = ToMTLSamplerMinMagFilter(descriptor.mag_filter);
30 desc.mipFilter = ToMTLSamplerMipFilter(descriptor.mip_filter);
31 desc.sAddressMode = ToMTLSamplerAddressMode(descriptor.width_address_mode);
32 desc.tAddressMode = ToMTLSamplerAddressMode(descriptor.height_address_mode);
33 desc.rAddressMode = ToMTLSamplerAddressMode(descriptor.depth_address_mode);
34 if (@available(iOS 14.0, macos 10.12, *)) {
35 desc.borderColor = MTLSamplerBorderColorTransparentBlack;
36 }
37 if (!descriptor.label.empty()) {
38 desc.label = @(descriptor.label.c_str());
39 }
40
41 auto mtl_sampler = [device_ newSamplerStateWithDescriptor:desc];
42 if (!mtl_sampler) {
43 return kNullSampler;
44 }
45 auto sampler =
46 std::unique_ptr<SamplerMTL>(new SamplerMTL(descriptor, mtl_sampler));
47
48 return (samplers_[descriptor] = std::move(sampler));
49}
50
51} // namespace impeller
VkDevice device
Definition main.cc:53
constexpr MTLSamplerMipFilter ToMTLSamplerMipFilter(MipFilter filter)
constexpr MTLSamplerAddressMode ToMTLSamplerAddressMode(SamplerAddressMode mode)
constexpr MTLSamplerMinMagFilter ToMTLSamplerMinMagFilter(MinMagFilter filter)
static const std::unique_ptr< const Sampler > kNullSampler
SamplerAddressMode depth_address_mode
SamplerAddressMode width_address_mode
SamplerAddressMode height_address_mode