Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GrMtlRenderTarget Class Reference

#include <GrMtlRenderTarget.h>

Inheritance diagram for GrMtlRenderTarget:
GrRenderTarget GrSurface GrGpuResource GrIORef< GrGpuResource > SkNoncopyable GrMtlTextureRenderTarget

Public Member Functions

 ~GrMtlRenderTarget () override
 
bool canAttemptStencilAttachment (bool useMSAASurface) const override
 
GrMtlAttachmentcolorAttachment () const
 
id< MTLTexture > colorMTLTexture () const
 
GrMtlAttachmentresolveAttachment () const
 
id< MTLTexture > resolveMTLTexture () const
 
GrMtlAttachmentnonMSAAAttachment () const
 
GrBackendRenderTarget getBackendRenderTarget () const override
 
GrBackendFormat backendFormat () const override
 
const GrMtlFramebuffergetFramebuffer (bool withResolve, bool withStencil)
 
- Public Member Functions inherited from GrRenderTarget
virtual bool alwaysClearStencil () const
 
GrRenderTargetasRenderTarget () override
 
const GrRenderTargetasRenderTarget () const override
 
int numSamples () const
 
virtual GrBackendRenderTarget getBackendRenderTarget () const =0
 
GrAttachmentgetStencilAttachment (bool useMSAASurface) const
 
GrAttachmentgetStencilAttachment () const
 
virtual bool canAttemptStencilAttachment (bool useMSAASurface) const =0
 
void attachStencilAttachment (sk_sp< GrAttachment > stencil, bool useMSAASurface)
 
int numStencilBits (bool useMSAASurface) const
 
int getSamplePatternKey ()
 
const skia_private::TArray< SkPoint > & getSampleLocations ()
 
void setRequiresManualMSAAResolve ()
 
bool requiresManualMSAAResolve () const
 
- Public Member Functions inherited from GrSurface
SkISize dimensions () const
 
int width () const
 
int height () const
 
SkRect getBoundsRect () const
 
virtual GrBackendFormat backendFormat () const =0
 
void setRelease (sk_sp< skgpu::RefCntedCallback > releaseHelper)
 
void setRelease (ReleaseProc proc, ReleaseCtx ctx)
 
virtual GrTextureasTexture ()
 
virtual const GrTextureasTexture () const
 
virtual GrRenderTargetasRenderTarget ()
 
virtual const GrRenderTargetasRenderTarget () const
 
GrInternalSurfaceFlags flags () const
 
bool readOnly () const
 
bool framebufferOnly () const
 
bool isProtected () const
 
void setFramebufferOnly ()
 
- Public Member Functions inherited from GrGpuResource
bool wasDestroyed () const
 
const GrDirectContextgetContext () const
 
GrDirectContextgetContext ()
 
size_t gpuMemorySize () const
 
UniqueID uniqueID () const
 
const skgpu::UniqueKeygetUniqueKey () const
 
std::string getLabel () const
 
void setLabel (std::string_view label)
 
CacheAccess cacheAccess ()
 
const CacheAccess cacheAccess () const
 
ProxyAccess proxyAccess ()
 
ResourcePriv resourcePriv ()
 
const ResourcePriv resourcePriv () const
 
virtual void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
virtual const char * getResourceType () const =0
 
- Public Member Functions inherited from GrIORef< GrGpuResource >
bool unique () const
 
void ref () const
 
void unref () const
 
void refCommandBuffer () const
 
void unrefCommandBuffer () const
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 

Static Public Member Functions

static sk_sp< GrMtlRenderTargetMakeWrappedRenderTarget (GrMtlGpu *, SkISize, int sampleCnt, id< MTLTexture >)
 
- Static Public Member Functions inherited from GrSurface
static size_t ComputeSize (const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
 
- Static Public Member Functions inherited from GrGpuResource
static uint32_t CreateUniqueID ()
 

Protected Member Functions

 GrMtlRenderTarget (GrMtlGpu *gpu, SkISize, sk_sp< GrMtlAttachment > colorAttachment, sk_sp< GrMtlAttachment > resolveAttachment, std::string_view label)
 
GrMtlGpugetMtlGpu () const
 
void onAbandon () override
 
void onRelease () override
 
size_t onGpuMemorySize () const override
 
void onSetLabel () override
 
- Protected Member Functions inherited from GrRenderTarget
 GrRenderTarget (GrGpu *, const SkISize &, int sampleCount, GrProtected, std::string_view label, sk_sp< GrAttachment > stenicl=nullptr)
 
 ~GrRenderTarget () override
 
void onAbandon () override
 
void onRelease () override
 
- Protected Member Functions inherited from GrSurface
void setGLRTFBOIDIs0 ()
 
bool glRTFBOIDis0 () const
 
void setRequiresManualMSAAResolve ()
 
bool requiresManualMSAAResolve () const
 
void setReadOnly ()
 
void setVkRTSupportsInputAttachment ()
 
 GrSurface (GrGpu *gpu, const SkISize &dimensions, skgpu::Protected isProtected, std::string_view label)
 
 ~GrSurface () override
 
void onRelease () override
 
void onAbandon () override
 
- Protected Member Functions inherited from GrGpuResource
void registerWithCache (skgpu::Budgeted)
 
void registerWithCacheWrapped (GrWrapCacheable)
 
 GrGpuResource (GrGpu *, std::string_view label)
 
virtual ~GrGpuResource ()
 
GrGpugetGpu () const
 
virtual void onRelease ()
 
virtual void onAbandon ()
 
virtual void setMemoryBacking (SkTraceMemoryDump *, const SkString &) const
 
SkString getResourceName () const
 
void dumpMemoryStatisticsPriv (SkTraceMemoryDump *traceMemoryDump, const SkString &resourceName, const char *type, size_t size) const
 
- Protected Member Functions inherited from GrIORef< GrGpuResource >
 GrIORef ()
 
bool internalHasRef () const
 
bool internalHasNoCommandBufferUsages () const
 
void addInitialRef () const
 

Protected Attributes

sk_sp< GrMtlAttachmentfColorAttachment
 
sk_sp< GrMtlAttachmentfResolveAttachment
 

Additional Inherited Members

- Public Types inherited from GrSurface
typedef void * ReleaseCtx
 
typedef void(* ReleaseProc) (ReleaseCtx)
 
- Public Types inherited from GrIORef< GrGpuResource >
enum  LastRemovedRef
 

Detailed Description

Definition at line 22 of file GrMtlRenderTarget.h.

Constructor & Destructor Documentation

◆ ~GrMtlRenderTarget()

GrMtlRenderTarget::~GrMtlRenderTarget ( )
override

Definition at line 103 of file GrMtlRenderTarget.mm.

103 {
106}
#define SkASSERT(cond)
Definition: SkAssert.h:116
sk_sp< GrMtlAttachment > fColorAttachment
sk_sp< GrMtlAttachment > fResolveAttachment

◆ GrMtlRenderTarget()

GrMtlRenderTarget::GrMtlRenderTarget ( GrMtlGpu gpu,
SkISize  dimensions,
sk_sp< GrMtlAttachment colorAttachment,
sk_sp< GrMtlAttachment resolveAttachment,
std::string_view  label 
)
protected

Definition at line 38 of file GrMtlRenderTarget.mm.

47}
int numSamples() const
Definition: GrAttachment.h:38
GrMtlAttachment * colorAttachment() const
GrMtlAttachment * resolveAttachment() const
GrRenderTarget(GrGpu *, const SkISize &, int sampleCount, GrProtected, std::string_view label, sk_sp< GrAttachment > stenicl=nullptr)
SkISize dimensions() const
Definition: GrSurface.h:27
GrSurface(GrGpu *gpu, const SkISize &dimensions, skgpu::Protected isProtected, std::string_view label)
Definition: GrSurface.h:140

Member Function Documentation

◆ backendFormat()

GrBackendFormat GrMtlRenderTarget::backendFormat ( ) const
overridevirtual

Implements GrSurface.

Reimplemented in GrMtlTextureRenderTarget.

Definition at line 114 of file GrMtlRenderTarget.mm.

114 {
116}
MTLPixelFormat mtlFormat() const
SK_API GrBackendFormat MakeMtl(GrMTLPixelFormat format)

◆ canAttemptStencilAttachment()

bool GrMtlRenderTarget::canAttemptStencilAttachment ( bool  useMSAASurface) const
inlineoverridevirtual

Implements GrRenderTarget.

Definition at line 33 of file GrMtlRenderTarget.h.

33 {
34 SkASSERT(useMSAASurface == (this->numSamples() > 1));
35 return true;
36 }
int numSamples() const

◆ colorAttachment()

GrMtlAttachment * GrMtlRenderTarget::colorAttachment ( ) const
inline

Definition at line 38 of file GrMtlRenderTarget.h.

38{ return fColorAttachment.get(); }
T * get() const
Definition: SkRefCnt.h:303

◆ colorMTLTexture()

id< MTLTexture > GrMtlRenderTarget::colorMTLTexture ( ) const
inline

Definition at line 39 of file GrMtlRenderTarget.h.

39{ return fColorAttachment->mtlTexture(); }
id< MTLTexture > mtlTexture() const

◆ getBackendRenderTarget()

GrBackendRenderTarget GrMtlRenderTarget::getBackendRenderTarget ( ) const
overridevirtual

Implements GrRenderTarget.

Definition at line 108 of file GrMtlRenderTarget.mm.

108 {
109 GrMtlTextureInfo info;
111 return GrBackendRenderTargets::MakeMtl(this->width(), this->height(), info);
112}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SK_ALWAYS_INLINE CF_RETURNS_RETAINED const void * GrRetainPtrFromId(id idObject)
Definition: GrMtlUtil.h:59
int height() const
Definition: GrSurface.h:37
int width() const
Definition: GrSurface.h:32
SK_API GrBackendRenderTarget MakeMtl(int width, int height, const GrMtlTextureInfo &mtlInfo)

◆ getFramebuffer()

const GrMtlFramebuffer * GrMtlRenderTarget::getFramebuffer ( bool  withResolve,
bool  withStencil 
)

Definition at line 129 of file GrMtlRenderTarget.mm.

130 {
131 int cacheIndex =
132 renderpass_features_to_index(withResolve, withStencil);
133 SkASSERT(cacheIndex < GrMtlRenderTarget::kNumCachedFramebuffers);
134
135 if (fCachedFramebuffers[cacheIndex]) {
136 return fCachedFramebuffers[cacheIndex].get();
137 }
138
139 GrMtlAttachment* resolve = withResolve ? this->resolveAttachment() : nullptr;
141
142 // Stencil attachment view is stored in the base RT stencil attachment
143 GrMtlAttachment* stencil =
144 withStencil ? static_cast<GrMtlAttachment*>(this->getStencilAttachment())
145 : nullptr;
146 fCachedFramebuffers[cacheIndex] =
147 GrMtlFramebuffer::Make(colorAttachment, resolve, stencil);
148 return fCachedFramebuffers[cacheIndex].get();
149}
static int renderpass_features_to_index(bool hasResolve, bool hasStencil)
static sk_sp< const GrMtlFramebuffer > Make(GrMtlAttachment *colorAttachment, GrMtlAttachment *resolveAttachment, GrMtlAttachment *stencilAttachment)
GrAttachment * getStencilAttachment() const

◆ getMtlGpu()

GrMtlGpu * GrMtlRenderTarget::getMtlGpu ( ) const
protected

Definition at line 151 of file GrMtlRenderTarget.mm.

151 {
152 SkASSERT(!this->wasDestroyed());
153 return static_cast<GrMtlGpu*>(this->getGpu());
154}
GrGpu * getGpu() const
bool wasDestroyed() const

◆ MakeWrappedRenderTarget()

sk_sp< GrMtlRenderTarget > GrMtlRenderTarget::MakeWrappedRenderTarget ( GrMtlGpu gpu,
SkISize  dimensions,
int  sampleCnt,
id< MTLTexture >  texture 
)
static

Definition at line 49 of file GrMtlRenderTarget.mm.

52 {
53 SkASSERT(nil != texture);
54 SkASSERT(1 == texture.mipmapLevelCount);
55 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
56 SkASSERT(MTLTextureUsageRenderTarget & texture.usage);
57 }
58
59 sk_sp<GrMtlAttachment> textureAttachment =
63 /*label=*/"MtlAttachment_TextureAttachment");
64
65 GrMtlRenderTarget* mtlRT;
66 if (sampleCnt > 1) {
67 if ([texture sampleCount] == 1) {
68 MTLPixelFormat format = texture.pixelFormat;
69 if (!gpu->mtlCaps().isFormatRenderable(format, sampleCnt)) {
70 return nullptr;
71 }
72 auto rp = gpu->getContext()->priv().resourceProvider();
73 sk_sp<GrAttachment> msaaAttachment =
74 rp->makeMSAAAttachment(dimensions,
76 sampleCnt,
79 if (!msaaAttachment) {
80 return nullptr;
81 }
83 sk_sp<GrMtlAttachment>(static_cast<GrMtlAttachment*>(msaaAttachment.release()));
84 mtlRT = new GrMtlRenderTarget(
85 gpu, dimensions, std::move(colorAttachment), std::move(textureAttachment),
86 kWrapped, /*label=*/"MakeWrappedRenderTargetWithOneTextureSampleCount");
88 } else {
89 SkASSERT(sampleCnt == static_cast<int>([texture sampleCount]));
90 mtlRT = new GrMtlRenderTarget(gpu, dimensions, std::move(textureAttachment), nil,
91 kWrapped,
92 /*label=*/"MakeWrappedRenderTargetWithManySampleCount");
93 }
94 } else {
95 mtlRT = new GrMtlRenderTarget(gpu, dimensions, std::move(textureAttachment), nil,
96 kWrapped,
97 /*label=*/"MakeWrappedRenderTargetWithOneOrLessSampleCount");
98 }
99
100 return sk_sp<GrMtlRenderTarget>(mtlRT);
101}
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
GrDirectContext * getContext()
Definition: GrGpu.h:67
static sk_sp< GrMtlAttachment > MakeWrapped(GrMtlGpu *gpu, SkISize dimensions, id< MTLTexture >, UsageFlags attachmentUsages, GrWrapCacheable, std::string_view label)
bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const override
Definition: GrMtlCaps.mm:490
const GrMtlCaps & mtlCaps() const
Definition: GrMtlGpu.h:47
GrMtlRenderTarget(GrMtlGpu *gpu, SkISize, sk_sp< GrMtlAttachment > colorAttachment, sk_sp< GrMtlAttachment > resolveAttachment, std::string_view label)
void setRequiresManualMSAAResolve()
Definition: GrSurface.h:121
T * release()
Definition: SkRefCnt.h:324
uint32_t uint32_t * format
FlTexture * texture

◆ nonMSAAAttachment()

GrMtlAttachment * GrMtlRenderTarget::nonMSAAAttachment ( ) const
inline

Definition at line 45 of file GrMtlRenderTarget.h.

45 {
46 if (fColorAttachment->numSamples() == 1) {
47 return fColorAttachment.get();
48 } else {
49 return fResolveAttachment.get();
50 }
51 }

◆ onAbandon()

void GrMtlRenderTarget::onAbandon ( )
overrideprotectedvirtual

Overridden to abandon any internal handles, ptrs, etc to backend API resources. This may be called when the underlying 3D context is no longer valid and so no backend API calls should be made.

Reimplemented from GrRenderTarget.

Reimplemented in GrMtlTextureRenderTarget.

Definition at line 156 of file GrMtlRenderTarget.mm.

156 {
157 fColorAttachment = nil;
158 fResolveAttachment = nil;
160}
void onAbandon() override

◆ onGpuMemorySize()

size_t GrMtlRenderTarget::onGpuMemorySize ( ) const
inlineoverrideprotectedvirtual

Implements GrGpuResource.

Definition at line 73 of file GrMtlRenderTarget.h.

73{ return 0; }

◆ onRelease()

void GrMtlRenderTarget::onRelease ( )
overrideprotectedvirtual

Overridden to free GPU resources in the backend API.

Reimplemented from GrRenderTarget.

Reimplemented in GrMtlTextureRenderTarget.

Definition at line 162 of file GrMtlRenderTarget.mm.

162 {
163 fColorAttachment = nil;
164 fResolveAttachment = nil;
166}
void onRelease() override

◆ onSetLabel()

void GrMtlRenderTarget::onSetLabel ( )
overrideprotectedvirtual

Implements GrGpuResource.

Definition at line 173 of file GrMtlRenderTarget.mm.

173 {
175 if (!this->getLabel().empty()) {
176 NSString* labelStr = @(this->getLabel().c_str());
177 if (fResolveAttachment) {
179 [@"_Skia_MSAA_" stringByAppendingString:labelStr];
181 [@"_Skia_Resolve_" stringByAppendingString:labelStr];
182 } else {
183 fColorAttachment->mtlTexture().label = [@"_Skia_" stringByAppendingString:labelStr];
184 }
185 }
186}
std::string getLabel() const
EMSCRIPTEN_KEEPALIVE void empty()

◆ resolveAttachment()

GrMtlAttachment * GrMtlRenderTarget::resolveAttachment ( ) const
inline

Definition at line 40 of file GrMtlRenderTarget.h.

40{ return fResolveAttachment.get(); }

◆ resolveMTLTexture()

id< MTLTexture > GrMtlRenderTarget::resolveMTLTexture ( ) const
inline

Definition at line 41 of file GrMtlRenderTarget.h.

41{ return fResolveAttachment->mtlTexture(); }

Member Data Documentation

◆ fColorAttachment

sk_sp<GrMtlAttachment> GrMtlRenderTarget::fColorAttachment
protected

Definition at line 77 of file GrMtlRenderTarget.h.

◆ fResolveAttachment

sk_sp<GrMtlAttachment> GrMtlRenderTarget::fResolveAttachment
protected

Definition at line 78 of file GrMtlRenderTarget.h.


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