Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
skwindow::internal::MetalWindowContext Class Referenceabstract

#include <MetalWindowContext.h>

Inheritance diagram for skwindow::internal::MetalWindowContext:
skwindow::WindowContext

Public Member Functions

sk_sp< SkSurfacegetBackbufferSurface () override
 
bool isValid () override
 
void setDisplayParams (const DisplayParams &params) override
 
- Public Member Functions inherited from skwindow::WindowContext
 WindowContext (const DisplayParams &)
 
virtual ~WindowContext ()
 
virtual sk_sp< SkSurfacegetBackbufferSurface ()=0
 
void swapBuffers ()
 
virtual bool isValid ()=0
 
virtual void resize (int w, int h)=0
 
virtual void activate (bool isActive)
 
const DisplayParamsgetDisplayParams ()
 
virtual void setDisplayParams (const DisplayParams &params)=0
 
GrDirectContextdirectContext () const
 
int width () const
 
int height () const
 
SkISize dimensions () const
 
int sampleCount () const
 
int stencilBits () const
 

Protected Member Functions

 MetalWindowContext (const DisplayParams &)
 
void initializeContext ()
 
virtual bool onInitializeContext ()=0
 
void destroyContext ()
 
virtual void onDestroyContext ()=0
 
void onSwapBuffers () override
 
- Protected Member Functions inherited from skwindow::WindowContext
virtual bool isGpuContext ()
 
virtual void onSwapBuffers ()=0
 

Protected Attributes

bool fValid
 
sk_cfp< id< MTLDevice > > fDevice
 
sk_cfp< id< MTLCommandQueue > > fQueue
 
CAMetalLayer * fMetalLayer
 
GrMTLHandle fDrawableHandle
 
- Protected Attributes inherited from skwindow::WindowContext
sk_sp< GrDirectContextfContext
 
int fWidth
 
int fHeight
 
DisplayParams fDisplayParams
 
int fSampleCount = 1
 
int fStencilBits = 0
 

Detailed Description

Definition at line 22 of file MetalWindowContext.h.

Constructor & Destructor Documentation

◆ MetalWindowContext()

skwindow::internal::MetalWindowContext::MetalWindowContext ( const DisplayParams params)
protected

Definition at line 30 of file MetalWindowContext.mm.

32 , fValid(false)
33 , fDrawableHandle(nil) {
35}
static uint32_t GrNextPow2(uint32_t n)
Definition: SkMathPriv.h:302
DisplayParams fDisplayParams
Definition: WindowContext.h:71
WindowContext(const DisplayParams &)
const EmbeddedViewParams * params

Member Function Documentation

◆ destroyContext()

void skwindow::internal::MetalWindowContext::destroyContext ( )
protected

Definition at line 68 of file MetalWindowContext.mm.

68 {
69 if (fContext) {
70 // in case we have outstanding refs to this (lua?)
73 }
74
75 this->onDestroyContext();
76
77 fMetalLayer = nil;
78 fValid = false;
79
80 fQueue.reset();
81 fDevice.reset();
82}
void abandonContext() override
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
sk_sp< GrDirectContext > fContext
Definition: WindowContext.h:63
sk_cfp< id< MTLCommandQueue > > fQueue

◆ getBackbufferSurface()

sk_sp< SkSurface > skwindow::internal::MetalWindowContext::getBackbufferSurface ( )
overridevirtual

Implements skwindow::WindowContext.

Definition at line 84 of file MetalWindowContext.mm.

84 {
86 if (fContext) {
89 (__bridge GrMTLHandle)fMetalLayer,
96 } else {
97 id<CAMetalDrawable> currentDrawable = [fMetalLayer nextDrawable];
98 if (currentDrawable == nil) {
99 return nullptr;
100 }
101
102 GrMtlTextureInfo fbInfo;
103 fbInfo.fTexture.retain(currentDrawable.texture);
104
105 GrBackendRenderTarget backendRT =
107
109 backendRT,
114
115 fDrawableHandle = CFRetain((GrMTLHandle) currentDrawable);
116 }
117 }
118
119 return surface;
120}
const void * GrMTLHandle
Definition: GrMtlTypes.h:20
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
T * get() const
Definition: SkRefCnt.h:303
VkSurfaceKHR surface
Definition: main.cc:49
SK_API GrBackendRenderTarget MakeMtl(int width, int height, const GrMtlTextureInfo &mtlInfo)
SK_API sk_sp< SkSurface > WrapCAMetalLayer(GrRecordingContext *context, GrMTLHandle layer, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, GrMTLHandle *drawable) SK_API_AVAILABLE_CA_METAL_LAYER
SK_API sk_sp< SkSurface > WrapBackendRenderTarget(GrRecordingContext *context, const GrBackendRenderTarget &backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, RenderTargetReleaseProc releaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SkSurfaceProps fSurfaceProps
Definition: DisplayParams.h:68
sk_sp< SkColorSpace > fColorSpace
Definition: DisplayParams.h:59

◆ initializeContext()

void skwindow::internal::MetalWindowContext::initializeContext ( )
protected

Definition at line 37 of file MetalWindowContext.mm.

37 {
39
40 fDevice.reset(MTLCreateSystemDefaultDevice());
41 fQueue.reset([*fDevice newCommandQueue]);
42
44 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
45 if (![*fDevice supportsTextureSampleCount:fDisplayParams.fMSAASampleCount]) {
46 return;
47 }
48 } else {
49 return;
50 }
51 }
53 fStencilBits = 8;
54
56
57 GrMtlBackendContext backendContext = {};
58 backendContext.fDevice.retain((GrMTLHandle)fDevice.get());
59 backendContext.fQueue.retain((GrMTLHandle)fQueue.get());
63 this->initializeContext();
64 return;
65 }
66}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SK_API sk_sp< GrDirectContext > MakeMetal(const GrMtlBackendContext &, const GrContextOptions &)
sk_cfp< GrMTLHandle > fDevice
sk_cfp< GrMTLHandle > fQueue
GrContextOptions fGrContextOptions
Definition: DisplayParams.h:61

◆ isValid()

bool skwindow::internal::MetalWindowContext::isValid ( )
inlineoverridevirtual

Implements skwindow::WindowContext.

Definition at line 26 of file MetalWindowContext.h.

26{ return fValid; }

◆ onDestroyContext()

virtual void skwindow::internal::MetalWindowContext::onDestroyContext ( )
protectedpure virtual

◆ onInitializeContext()

virtual bool skwindow::internal::MetalWindowContext::onInitializeContext ( )
protectedpure virtual

◆ onSwapBuffers()

void skwindow::internal::MetalWindowContext::onSwapBuffers ( )
overrideprotectedvirtual

Implements skwindow::WindowContext.

Definition at line 122 of file MetalWindowContext.mm.

122 {
123 id<CAMetalDrawable> currentDrawable = (id<CAMetalDrawable>)fDrawableHandle;
124
125 id<MTLCommandBuffer> commandBuffer([*fQueue commandBuffer]);
126 commandBuffer.label = @"Present";
127
128 [commandBuffer presentDrawable:currentDrawable];
129 [commandBuffer commit];
130 // ARC is off in sk_app, so we need to release the CF ref manually
131 CFRelease(fDrawableHandle);
132 fDrawableHandle = nil;
133}

◆ setDisplayParams()

void skwindow::internal::MetalWindowContext::setDisplayParams ( const DisplayParams params)
overridevirtual

Implements skwindow::WindowContext.

Definition at line 135 of file MetalWindowContext.mm.

Member Data Documentation

◆ fDevice

sk_cfp<id<MTLDevice> > skwindow::internal::MetalWindowContext::fDevice
protected

Definition at line 46 of file MetalWindowContext.h.

◆ fDrawableHandle

GrMTLHandle skwindow::internal::MetalWindowContext::fDrawableHandle
protected

Definition at line 49 of file MetalWindowContext.h.

◆ fMetalLayer

CAMetalLayer* skwindow::internal::MetalWindowContext::fMetalLayer
protected

Definition at line 48 of file MetalWindowContext.h.

◆ fQueue

sk_cfp<id<MTLCommandQueue> > skwindow::internal::MetalWindowContext::fQueue
protected

Definition at line 47 of file MetalWindowContext.h.

◆ fValid

bool skwindow::internal::MetalWindowContext::fValid
protected

Definition at line 45 of file MetalWindowContext.h.


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