Flutter Impeller
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 
10 namespace impeller {
11 
12 SamplerLibraryMTL::SamplerLibraryMTL(id<MTLDevice> device) : device_(device) {}
13 
15 
16 std::shared_ptr<const Sampler> SamplerLibraryMTL::GetSampler(
17  SamplerDescriptor descriptor) {
18  auto found = samplers_.find(descriptor);
19  if (found != samplers_.end()) {
20  return found->second;
21  }
22  if (!device_) {
23  return nullptr;
24  }
25  auto desc = [[MTLSamplerDescriptor alloc] init];
26  desc.minFilter = ToMTLSamplerMinMagFilter(descriptor.min_filter);
27  desc.magFilter = ToMTLSamplerMinMagFilter(descriptor.mag_filter);
28  desc.mipFilter = ToMTLSamplerMipFilter(descriptor.mip_filter);
29  desc.sAddressMode = ToMTLSamplerAddressMode(descriptor.width_address_mode);
30  desc.tAddressMode = ToMTLSamplerAddressMode(descriptor.height_address_mode);
31  desc.rAddressMode = ToMTLSamplerAddressMode(descriptor.depth_address_mode);
32  if (@available(iOS 14.0, macos 10.12, *)) {
33  desc.borderColor = MTLSamplerBorderColorTransparentBlack;
34  }
35  if (!descriptor.label.empty()) {
36  desc.label = @(descriptor.label.c_str());
37  }
38 
39  auto mtl_sampler = [device_ newSamplerStateWithDescriptor:desc];
40  if (!mtl_sampler) {
41  return nullptr;
42  }
43  auto sampler =
44  std::shared_ptr<SamplerMTL>(new SamplerMTL(descriptor, mtl_sampler));
45  if (!sampler->IsValid()) {
46  return nullptr;
47  }
48  samplers_[descriptor] = sampler;
49  return sampler;
50 }
51 
52 } // namespace impeller
impeller::ToMTLSamplerAddressMode
constexpr MTLSamplerAddressMode ToMTLSamplerAddressMode(SamplerAddressMode mode)
Definition: formats_mtl.h:357
formats_mtl.h
impeller::SamplerLibraryMTL::~SamplerLibraryMTL
~SamplerLibraryMTL() override
sampler_library_mtl.h
impeller::ToMTLSamplerMinMagFilter
constexpr MTLSamplerMinMagFilter ToMTLSamplerMinMagFilter(MinMagFilter filter)
Definition: formats_mtl.h:337
impeller::ToMTLSamplerMipFilter
constexpr MTLSamplerMipFilter ToMTLSamplerMipFilter(MipFilter filter)
Definition: formats_mtl.h:347
sampler_mtl.h
impeller
Definition: aiks_context.cc:10