Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private 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
 
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 > >)
 

Private Member Functions

void freeGpuData () override
 

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, std::string_view label, bool commandBufferRefsAsUsageRefs=false)
 
virtual ~Resource ()
 
const SharedContextsharedContext () 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

◆ freeGpuData()

void skgpu::graphite::MtlTexture::freeGpuData ( )
overrideprivatevirtual

Implements skgpu::graphite::Resource.

Definition at line 131 of file MtlTexture.mm.

131 {
132 fTexture.reset();
133}

◆ Make()

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

Definition at line 103 of file MtlTexture.mm.

106 {
107 sk_cfp<id<MTLTexture>> texture = MakeMtlTexture(sharedContext, dimensions, info);
108 if (!texture) {
109 return nullptr;
110 }
111 return sk_sp<Texture>(new MtlTexture(sharedContext,
113 info,
114 std::move(texture),
116 budgeted));
117}
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:187
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#ifdef SK_ENABLE_MTL_DEBUG_INFO
64 if (mtlSpec.fUsage & MTLTextureUsageRenderTarget) {
65 if (MtlFormatIsDepthOrStencil((MTLPixelFormat)mtlSpec.fFormat)) {
66 (*texture).label = @"DepthStencil";
67 } else {
68 if (info.numSamples() > 1) {
69 if (mtlSpec.fUsage & MTLTextureUsageShaderRead) {
70 (*texture).label = @"MSAA SampledTexture-ColorAttachment";
71 } else {
72 (*texture).label = @"MSAA ColorAttachment";
73 }
74 } else {
75 if (mtlSpec.fUsage & MTLTextureUsageShaderRead) {
76 (*texture).label = @"SampledTexture-ColorAttachment";
77 } else {
78 (*texture).label = @"ColorAttachment";
79 }
80 }
81 }
82 } else if (mtlSpec.fUsage & MTLTextureUsageShaderWrite) {
83 SkASSERT(mtlSpec.fUsage & MTLTextureUsageShaderRead);
84 (*texture).label = @"StorageTexture";
85 } else {
86 SkASSERT(mtlSpec.fUsage & MTLTextureUsageShaderRead);
87 (*texture).label = @"SampledTexture";
88 }
89#endif
90
91 return texture;
92}
#define SkASSERT(cond)
Definition SkAssert.h:116
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition SkMipmap.cpp:134
const Caps * caps() const
const myers::Point & get(const myers::Segment &)
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 119 of file MtlTexture.mm.

122 {
123 return sk_sp<Texture>(new MtlTexture(sharedContext,
125 info,
126 std::move(texture),
129}

◆ 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: