| 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
5 #include "impeller/renderer/backend/metal/sampler_library_mtl.h"
6
7 #include "impeller/renderer/backend/metal/formats_mtl.h"
8 #include "impeller/renderer/backend/metal/sampler_mtl.h"
9
10 namespace impeller {
11
12 SamplerLibraryMTL::SamplerLibraryMTL(id<MTLDevice> device) : device_(device) {}
13
14 SamplerLibraryMTL::~SamplerLibraryMTL() = default;
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
33 if (!descriptor.label.empty()) {
34 desc.label = @(descriptor.label.c_str());
35 }
36
37 auto mtl_sampler = [device_ newSamplerStateWithDescriptor:desc];
38 if (!mtl_sampler) {
39 return nullptr;
40 }
41 auto sampler =
42 std::shared_ptr<SamplerMTL>(new SamplerMTL(descriptor, mtl_sampler));
43 if (!sampler->IsValid()) {
44 return nullptr;
45 }
46 samplers_[descriptor] = sampler;
47 return sampler;
48 }
49
50 } // namespace impeller
impeller::ToMTLSamplerAddressMode
constexpr MTLSamplerAddressMode ToMTLSamplerAddressMode(SamplerAddressMode mode)
Definition: formats_mtl.h:355
formats_mtl.h
impeller::SamplerLibraryMTL::~SamplerLibraryMTL
~SamplerLibraryMTL() override
sampler_library_mtl.h
impeller::ToMTLSamplerMinMagFilter
constexpr MTLSamplerMinMagFilter ToMTLSamplerMinMagFilter(MinMagFilter filter)
Definition: formats_mtl.h:335
impeller::ToMTLSamplerMipFilter
constexpr MTLSamplerMipFilter ToMTLSamplerMipFilter(MipFilter filter)
Definition: formats_mtl.h:345
sampler_mtl.h
impeller
Definition: aiks_context.cc:10