| 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 static const std::unique_ptr<const Sampler> kNullSampler = nullptr;
17
18 const 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
impeller::ToMTLSamplerAddressMode
constexpr MTLSamplerAddressMode ToMTLSamplerAddressMode(SamplerAddressMode mode)
Definition: formats_mtl.h:354
formats_mtl.h
impeller::SamplerLibraryMTL::~SamplerLibraryMTL
~SamplerLibraryMTL() override
sampler_library_mtl.h
impeller::SamplerDescriptor::mag_filter
MinMagFilter mag_filter
Definition: sampler_descriptor.h:17
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:15
impeller::SamplerDescriptor::min_filter
MinMagFilter min_filter
Definition: sampler_descriptor.h:16
impeller::ToMTLSamplerMinMagFilter
constexpr MTLSamplerMinMagFilter ToMTLSamplerMinMagFilter(MinMagFilter filter)
Definition: formats_mtl.h:334
impeller::SamplerDescriptor::width_address_mode
SamplerAddressMode width_address_mode
Definition: sampler_descriptor.h:20
impeller::SamplerDescriptor::depth_address_mode
SamplerAddressMode depth_address_mode
Definition: sampler_descriptor.h:22
impeller::SamplerDescriptor::mip_filter
MipFilter mip_filter
Definition: sampler_descriptor.h:18
impeller::ToMTLSamplerMipFilter
constexpr MTLSamplerMipFilter ToMTLSamplerMipFilter(MipFilter filter)
Definition: formats_mtl.h:344
impeller::SamplerDescriptor::label
std::string label
Definition: sampler_descriptor.h:24
sampler_mtl.h
impeller::kNullSampler
static const std::unique_ptr< const Sampler > kNullSampler
Definition: sampler_library_gles.cc:14
impeller::SamplerMTL
Definition: sampler_mtl.h:18
impeller::SamplerDescriptor::height_address_mode
SamplerAddressMode height_address_mode
Definition: sampler_descriptor.h:21
impeller
Definition: aiks_blur_unittests.cc:20