Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
skgpu::graphite::MtlSampler Class Reference

#include <MtlSampler.h>

Inheritance diagram for skgpu::graphite::MtlSampler:
skgpu::graphite::Sampler skgpu::graphite::Resource

Public Member Functions

 ~MtlSampler () override
 
id< MTLSamplerState > mtlSamplerState () const
 
- Public Member Functions inherited from skgpu::graphite::Sampler
 ~Sampler () override
 
const char * getResourceType () const override
 
- Public Member Functions inherited from skgpu::graphite::Resource
 Resource (const Resource &)=delete
 
 Resource (Resource &&)=delete
 
Resourceoperator= (const Resource &)=delete
 
Resourceoperator= (Resource &&)=delete
 
void ref () const
 
void unref () const
 
void refCommandBuffer () const
 
void unrefCommandBuffer () const
 
Ownership ownership () const
 
skgpu::Budgeted budgeted () const
 
size_t gpuMemorySize () const
 
UniqueID uniqueID () const
 
virtual const char * getResourceType () const =0
 
std::string getLabel () const
 
void setLabel (std::string_view label)
 
bool wasDestroyed () const
 
const GraphiteResourceKeykey () const
 
void setKey (const GraphiteResourceKey &key)
 
void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
virtual void prepareForReturnToCache (const std::function< void()> &takeRef)
 

Static Public Member Functions

static sk_sp< MtlSamplerMake (const MtlSharedContext *, const SkSamplingOptions &samplingOptions, SkTileMode xTileMode, SkTileMode yTileMode)
 

Additional Inherited Members

- Protected Member Functions inherited from skgpu::graphite::Sampler
 Sampler (const SharedContext *)
 
- Protected Member Functions inherited from skgpu::graphite::Resource
 Resource (const SharedContext *, Ownership, skgpu::Budgeted, size_t gpuMemorySize, bool commandBufferRefsAsUsageRefs=false)
 
virtual ~Resource ()
 
const SharedContextsharedContext () const
 
virtual void onDumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const
 
void setDeleteASAP ()
 

Detailed Description

Definition at line 25 of file MtlSampler.h.

Constructor & Destructor Documentation

◆ ~MtlSampler()

skgpu::graphite::MtlSampler::~MtlSampler ( )
inlineoverride

Definition at line 32 of file MtlSampler.h.

32{}

Member Function Documentation

◆ Make()

sk_sp< MtlSampler > skgpu::graphite::MtlSampler::Make ( const MtlSharedContext sharedContext,
const SkSamplingOptions samplingOptions,
SkTileMode  xTileMode,
SkTileMode  yTileMode 
)
static

Definition at line 47 of file MtlSampler.mm.

50 {
51 sk_cfp<MTLSamplerDescriptor*> desc([[MTLSamplerDescriptor alloc] init]);
52
53 MTLSamplerMinMagFilter minMagFilter = [&] {
54 switch (samplingOptions.filter) {
55 case SkFilterMode::kNearest: return MTLSamplerMinMagFilterNearest;
56 case SkFilterMode::kLinear: return MTLSamplerMinMagFilterLinear;
57 }
59 }();
60
61 MTLSamplerMipFilter mipFilter = [&] {
62 switch (samplingOptions.mipmap) {
63 case SkMipmapMode::kNone: return MTLSamplerMipFilterNotMipmapped;
64 case SkMipmapMode::kNearest: return MTLSamplerMipFilterNearest;
65 case SkMipmapMode::kLinear: return MTLSamplerMipFilterLinear;
66 }
68 }();
69
70 (*desc).rAddressMode = MTLSamplerAddressModeClampToEdge;
71 (*desc).sAddressMode = tile_mode_to_mtl_sampler_address(xTileMode, sharedContext->mtlCaps());
72 (*desc).tAddressMode = tile_mode_to_mtl_sampler_address(yTileMode, sharedContext->mtlCaps());
73 (*desc).magFilter = minMagFilter;
74 (*desc).minFilter = minMagFilter;
75 (*desc).mipFilter = mipFilter;
76 (*desc).lodMinClamp = 0.0f;
77 (*desc).lodMaxClamp = FLT_MAX; // default value according to docs.
78 (*desc).maxAnisotropy = 1; // TODO: if we start using aniso, need to add to key
79 (*desc).normalizedCoordinates = true;
80 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
81 (*desc).compareFunction = MTLCompareFunctionNever;
82 }
83#ifdef SK_ENABLE_MTL_DEBUG_INFO
84 NSString* tileModeLabels[] = {
85 @"Clamp",
86 @"Repeat",
87 @"Mirror",
88 @"Decal"
89 };
90 NSString* minMagFilterLabels[] = {
91 @"Nearest",
92 @"Linear"
93 };
94 NSString* mipFilterLabels[] = {
95 @"MipNone",
96 @"MipNearest",
97 @"MipLinear"
98 };
99
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]];
105#endif
106
107 sk_cfp<id<MTLSamplerState>> sampler(
108 [sharedContext->device() newSamplerStateWithDescriptor:desc.get()]);
109 if (!sampler) {
110 return nullptr;
111 }
112 return sk_sp<MtlSampler>(new MtlSampler(sharedContext, std::move(sampler)));
113}
#define SkUNREACHABLE
Definition: SkAssert.h:135
const SharedContext * sharedContext() const
Definition: Resource.h:189
static bool init()
static MTLSamplerAddressMode tile_mode_to_mtl_sampler_address(SkTileMode tileMode, const Caps &caps)
Definition: MtlSampler.mm:21
const SkFilterMode filter
const SkMipmapMode mipmap

◆ mtlSamplerState()

id< MTLSamplerState > skgpu::graphite::MtlSampler::mtlSamplerState ( ) const
inline

Definition at line 34 of file MtlSampler.h.

34{ return fSamplerState.get(); }

The documentation for this class was generated from the following files: