Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
GrMtlSampler Class Reference

#include <GrMtlSampler.h>

Inheritance diagram for GrMtlSampler:
GrManagedResource SkNoncopyable

Public Types

typedef uint32_t Key
 

Public Member Functions

 ~GrMtlSampler () override
 
id< MTLSamplerState > mtlSampler () const
 
void freeGPUData () const override
 
- Public Member Functions inherited from GrManagedResource
 GrManagedResource ()
 
virtual ~GrManagedResource ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static GrMtlSamplerCreate (const GrMtlGpu *gpu, GrSamplerState)
 
static Key GenerateKey (GrSamplerState)
 
static const KeyGetKey (const GrMtlSampler &sampler)
 
static uint32_t Hash (const Key &key)
 

Detailed Description

Definition at line 21 of file GrMtlSampler.h.

Member Typedef Documentation

◆ Key

typedef uint32_t GrMtlSampler::Key

Definition at line 28 of file GrMtlSampler.h.

Constructor & Destructor Documentation

◆ ~GrMtlSampler()

GrMtlSampler::~GrMtlSampler ( )
inlineoverride

Definition at line 24 of file GrMtlSampler.h.

24{ fMtlSamplerState = nil; }

Member Function Documentation

◆ Create()

GrMtlSampler * GrMtlSampler::Create ( const GrMtlGpu gpu,
GrSamplerState  samplerState 
)
static

Definition at line 45 of file GrMtlSampler.mm.

45 {
46 MTLSamplerMinMagFilter minMagFilter = [&] {
47 switch (samplerState.filter()) {
48 case GrSamplerState::Filter::kNearest: return MTLSamplerMinMagFilterNearest;
49 case GrSamplerState::Filter::kLinear: return MTLSamplerMinMagFilterLinear;
50 }
52 }();
53
54 MTLSamplerMipFilter mipFilter = [&] {
55 switch (samplerState.mipmapMode()) {
56 case GrSamplerState::MipmapMode::kNone: return MTLSamplerMipFilterNotMipmapped;
57 case GrSamplerState::MipmapMode::kNearest: return MTLSamplerMipFilterNearest;
58 case GrSamplerState::MipmapMode::kLinear: return MTLSamplerMipFilterLinear;
59 }
61 }();
62
63 auto samplerDesc = [[MTLSamplerDescriptor alloc] init];
64 samplerDesc.rAddressMode = MTLSamplerAddressModeClampToEdge;
65 samplerDesc.sAddressMode = wrap_mode_to_mtl_sampler_address(samplerState.wrapModeX(),
66 gpu->mtlCaps());
67 samplerDesc.tAddressMode = wrap_mode_to_mtl_sampler_address(samplerState.wrapModeY(),
68 gpu->mtlCaps());
69 samplerDesc.magFilter = minMagFilter;
70 samplerDesc.minFilter = minMagFilter;
71 samplerDesc.mipFilter = mipFilter;
72 samplerDesc.lodMinClamp = 0.0f;
73 samplerDesc.lodMaxClamp = FLT_MAX; // default value according to docs.
74 // Metal documents that maxAnisotropy must be between 1 and 16 inclusive.
75 samplerDesc.maxAnisotropy = std::min(samplerState.maxAniso(), 16);
76 samplerDesc.normalizedCoordinates = true;
77 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
78 samplerDesc.compareFunction = MTLCompareFunctionNever;
79 }
80
81 return new GrMtlSampler([gpu->device() newSamplerStateWithDescriptor: samplerDesc],
82 GenerateKey(samplerState));
83}
static GR_NORETAIN_BEGIN MTLSamplerAddressMode wrap_mode_to_mtl_sampler_address(GrSamplerState::WrapMode wrapMode, const GrCaps &caps)
#define SkUNREACHABLE
Definition SkAssert.h:135
const GrMtlCaps & mtlCaps() const
Definition GrMtlGpu.h:47
id< MTLDevice > device() const
Definition GrMtlGpu.h:49
static Key GenerateKey(GrSamplerState)
constexpr WrapMode wrapModeX() const
constexpr Filter filter() const
constexpr MipmapMode mipmapMode() const
int maxAniso() const
constexpr WrapMode wrapModeY() const
init(device_serial, adb_binary)
Definition _adb_path.py:12

◆ freeGPUData()

void GrMtlSampler::freeGPUData ( ) const
inlineoverridevirtual

Must be implemented by any subclasses. Deletes any GPU data associated with this resource

Implements GrManagedResource.

Definition at line 47 of file GrMtlSampler.h.

47 {
48 fMtlSamplerState = nil;
49 }

◆ GenerateKey()

GrMtlSampler::Key GrMtlSampler::GenerateKey ( GrSamplerState  samplerState)
static

Definition at line 85 of file GrMtlSampler.mm.

85 {
86 // We haven't found any documentation on how anisotropy interacts with other filter settings
87 // so assume they are all considered.
88 return samplerState.asKey(/*anisoIsOrthogonal=*/true);
89}
uint32_t asKey(bool anisoIsOrthogonal) const

◆ GetKey()

static const Key & GrMtlSampler::GetKey ( const GrMtlSampler sampler)
inlinestatic

Definition at line 33 of file GrMtlSampler.h.

33{ return sampler.fKey; }

◆ Hash()

static uint32_t GrMtlSampler::Hash ( const Key key)
inlinestatic

Definition at line 34 of file GrMtlSampler.h.

34 {
35 return SkChecksum::Hash32(&key, sizeof(Key));
36 }
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)

◆ mtlSampler()

id< MTLSamplerState > GrMtlSampler::mtlSampler ( ) const
inline

Definition at line 26 of file GrMtlSampler.h.

26{ return fMtlSamplerState; }

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