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

#include <MtlTexture.h>

Inheritance diagram for skgpu::graphite::MtlTexture:
skgpu::graphite::Texture skgpu::graphite::Resource

Public Member Functions

 ~MtlTexture () override
 
id< MTLTexture > mtlTexture () const
 
- Public Member Functions inherited from skgpu::graphite::Texture
 ~Texture () override
 
int numSamples () const
 
Mipmapped mipmapped () const
 
SkISize dimensions () const
 
const TextureInfotextureInfo () const
 
void setReleaseCallback (sk_sp< RefCntedCallback >)
 
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_cfp< id< MTLTexture > > MakeMtlTexture (const MtlSharedContext *, SkISize dimensions, const TextureInfo &)
 
static sk_sp< TextureMake (const MtlSharedContext *, SkISize dimensions, const TextureInfo &, skgpu::Budgeted)
 
static sk_sp< TextureMakeWrapped (const MtlSharedContext *, SkISize dimensions, const TextureInfo &, sk_cfp< id< MTLTexture > >)
 

Additional Inherited Members

- Protected Member Functions inherited from skgpu::graphite::Texture
 Texture (const SharedContext *, SkISize dimensions, const TextureInfo &info, sk_sp< MutableTextureState > mutableState, Ownership, skgpu::Budgeted)
 
MutableTextureStatemutableState () const
 
void invokeReleaseProc () override
 
void onDumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const override
 
- 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 19 of file MtlTexture.h.

Constructor & Destructor Documentation

◆ ~MtlTexture()

skgpu::graphite::MtlTexture::~MtlTexture ( )
inlineoverride

Definition at line 35 of file MtlTexture.h.

35{}

Member Function Documentation

◆ Make()

sk_sp< Texture > skgpu::graphite::MtlTexture::Make ( const MtlSharedContext sharedContext,
SkISize  dimensions,
const TextureInfo info,
skgpu::Budgeted  budgeted 
)
static

Definition at line 80 of file MtlTexture.mm.

83 {
84 sk_cfp<id<MTLTexture>> texture = MakeMtlTexture(sharedContext, dimensions, info);
85 if (!texture) {
86 return nullptr;
87 }
88 return sk_sp<Texture>(new MtlTexture(sharedContext,
90 info,
91 std::move(texture),
93 budgeted));
94}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static sk_cfp< id< MTLTexture > > MakeMtlTexture(const MtlSharedContext *, SkISize dimensions, const TextureInfo &)
Definition: MtlTexture.mm:20
skgpu::Budgeted budgeted() const
Definition: Resource.h:100
const SharedContext * sharedContext() const
Definition: Resource.h:189
SkISize dimensions() const
Definition: Texture.h:31
FlTexture * texture

◆ MakeMtlTexture()

sk_cfp< id< MTLTexture > > skgpu::graphite::MtlTexture::MakeMtlTexture ( const MtlSharedContext sharedContext,
SkISize  dimensions,
const TextureInfo info 
)
static

Definition at line 20 of file MtlTexture.mm.

22 {
23 const Caps* caps = sharedContext->caps();
24 if (dimensions.width() > caps->maxTextureSize() ||
25 dimensions.height() > caps->maxTextureSize()) {
26 return nullptr;
27 }
28
29 const MtlTextureSpec& mtlSpec = info.mtlTextureSpec();
30 SkASSERT(!mtlSpec.fFramebufferOnly);
31
32 if (mtlSpec.fUsage & MTLTextureUsageShaderRead && !caps->isTexturable(info)) {
33 return nullptr;
34 }
35
36 if (mtlSpec.fUsage & MTLTextureUsageRenderTarget &&
37 !(caps->isRenderable(info) || MtlFormatIsDepthOrStencil((MTLPixelFormat)mtlSpec.fFormat))) {
38 return nullptr;
39 }
40
41 if (mtlSpec.fUsage & MTLTextureUsageShaderWrite && !caps->isStorage(info)) {
42 return nullptr;
43 }
44
45 int numMipLevels = 1;
46 if (info.mipmapped() == Mipmapped::kYes) {
48 }
49
50 sk_cfp<MTLTextureDescriptor*> desc([[MTLTextureDescriptor alloc] init]);
51 (*desc).textureType = (info.numSamples() > 1) ? MTLTextureType2DMultisample : MTLTextureType2D;
52 (*desc).pixelFormat = (MTLPixelFormat)mtlSpec.fFormat;
53 (*desc).width = dimensions.width();
54 (*desc).height = dimensions.height();
55 (*desc).depth = 1;
56 (*desc).mipmapLevelCount = numMipLevels;
57 (*desc).sampleCount = info.numSamples();
58 (*desc).arrayLength = 1;
59 (*desc).usage = mtlSpec.fUsage;
60 (*desc).storageMode = (MTLStorageMode)mtlSpec.fStorageMode;
61
62 sk_cfp<id<MTLTexture>> texture([sharedContext->device() newTextureWithDescriptor:desc.get()]);
63 return texture;
64}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition: SkMipmap.cpp:134
const Caps * caps() const
Definition: SharedContext.h:39
static bool init()
bool MtlFormatIsDepthOrStencil(MTLPixelFormat format)
Definition: MtlUtils.mm:18
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37

◆ MakeWrapped()

sk_sp< Texture > skgpu::graphite::MtlTexture::MakeWrapped ( const MtlSharedContext sharedContext,
SkISize  dimensions,
const TextureInfo info,
sk_cfp< id< MTLTexture > >  texture 
)
static

Definition at line 96 of file MtlTexture.mm.

99 {
100 return sk_sp<Texture>(new MtlTexture(sharedContext,
102 info,
103 std::move(texture),
106}

◆ mtlTexture()

id< MTLTexture > skgpu::graphite::MtlTexture::mtlTexture ( ) const
inline

Definition at line 37 of file MtlTexture.h.

37{ return fTexture.get(); }

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