Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
skwindow::internal::GraphiteMetalWindowContext Class Referenceabstract

#include <GraphiteMetalWindowContext.h>

Inheritance diagram for skwindow::internal::GraphiteMetalWindowContext:
skwindow::WindowContext

Public Member Functions

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

Protected Member Functions

 GraphiteMetalWindowContext (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 ()
 

Protected Attributes

bool fValid
 
sk_cfp< id< MTLDevice > > fDevice
 
sk_cfp< id< MTLCommandQueue > > fQueue
 
CAMetalLayer * fMetalLayer
 
CFTypeRef 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 GraphiteMetalWindowContext.h.

Constructor & Destructor Documentation

◆ GraphiteMetalWindowContext()

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

Member Function Documentation

◆ activate()

void skwindow::internal::GraphiteMetalWindowContext::activate ( bool  isActive)
overridevirtual

Reimplemented from skwindow::WindowContext.

Definition at line 139 of file GraphiteMetalWindowContext.mm.

139{}

◆ destroyContext()

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

Definition at line 74 of file GraphiteMetalWindowContext.mm.

74 {
75 if (fGraphiteContext) {
76 fGraphiteRecorder.reset();
77 fGraphiteContext.reset();
78 }
79
80 this->onDestroyContext();
81
82 fMetalLayer = nil;
83 fValid = false;
84
85 fQueue.reset();
86 fDevice.reset();
87}

◆ getBackbufferSurface()

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

Implements skwindow::WindowContext.

Definition at line 89 of file GraphiteMetalWindowContext.mm.

89 {
91 id<CAMetalDrawable> currentDrawable = [fMetalLayer nextDrawable];
92 if (currentDrawable == nil) {
93 return nullptr;
94 }
95
97 (CFTypeRef)currentDrawable.texture);
98
99 surface = SkSurfaces::WrapBackendTexture(this->graphiteRecorder(),
100 backendTex,
104 fDrawableHandle = CFRetain((CFTypeRef) currentDrawable);
105
106 return surface;
107}
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
SkISize dimensions() const
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SkSurfaceProps fSurfaceProps
sk_sp< SkColorSpace > fColorSpace

◆ initializeContext()

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

Definition at line 35 of file GraphiteMetalWindowContext.mm.

35 {
37 SkASSERT(!fGraphiteContext);
38
39 fDevice.reset(MTLCreateSystemDefaultDevice());
40 fQueue.reset([*fDevice newCommandQueue]);
41
43 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
44 if (![*fDevice supportsTextureSampleCount:fDisplayParams.fMSAASampleCount]) {
45 return;
46 }
47 } else {
48 return;
49 }
50 }
52 fStencilBits = 8;
53
55
56 skgpu::graphite::MtlBackendContext backendContext = {};
57 backendContext.fDevice.retain((CFTypeRef)fDevice.get());
58 backendContext.fQueue.retain((CFTypeRef)fQueue.get());
59
60 fDisplayParams.fGraphiteContextOptions.fOptions.fDisableCachedGlyphUploads = true;
61 // Needed to make synchronous readPixels work:
62 fDisplayParams.fGraphiteContextOptions.fPriv.fStoreContextRefInRecorder = true;
64 backendContext, fDisplayParams.fGraphiteContextOptions.fOptions);
65 fGraphiteRecorder = fGraphiteContext->makeRecorder(ToolUtils::CreateTestingRecorderOptions());
66 // TODO
67// if (!fGraphiteContext && fDisplayParams.fMSAASampleCount > 1) {
68// fDisplayParams.fMSAASampleCount /= 2;
69// this->initializeContext();
70// return;
71// }
72}
#define SkASSERT(cond)
Definition SkAssert.h:116
sk_sp< GrDirectContext > fContext
SK_API std::unique_ptr< Context > MakeMetal(const MtlBackendContext &, const ContextOptions &)

◆ isValid()

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

Implements skwindow::WindowContext.

Definition at line 26 of file GraphiteMetalWindowContext.h.

26{ return fValid; }

◆ onDestroyContext()

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

◆ onInitializeContext()

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

◆ onSwapBuffers()

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

Implements skwindow::WindowContext.

Definition at line 109 of file GraphiteMetalWindowContext.mm.

109 {
110 if (fGraphiteContext) {
111 SkASSERT(fGraphiteRecorder);
112 std::unique_ptr<skgpu::graphite::Recording> recording = fGraphiteRecorder->snap();
113 if (recording) {
115 info.fRecording = recording.get();
116 fGraphiteContext->insertRecording(info);
117 fGraphiteContext->submit(skgpu::graphite::SyncToCpu::kNo);
118 }
119 }
120
121 id<CAMetalDrawable> currentDrawable = (id<CAMetalDrawable>)fDrawableHandle;
122
123 id<MTLCommandBuffer> commandBuffer([*fQueue commandBuffer]);
124 commandBuffer.label = @"Present";
125
126 [commandBuffer presentDrawable:currentDrawable];
127 [commandBuffer commit];
128 // ARC is off in sk_app, so we need to release the CF ref manually
129 CFRelease(fDrawableHandle);
130 fDrawableHandle = nil;
131}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213

◆ setDisplayParams()

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

Member Data Documentation

◆ fDevice

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

Definition at line 48 of file GraphiteMetalWindowContext.h.

◆ fDrawableHandle

CFTypeRef skwindow::internal::GraphiteMetalWindowContext::fDrawableHandle
protected

Definition at line 51 of file GraphiteMetalWindowContext.h.

◆ fMetalLayer

CAMetalLayer* skwindow::internal::GraphiteMetalWindowContext::fMetalLayer
protected

Definition at line 50 of file GraphiteMetalWindowContext.h.

◆ fQueue

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

Definition at line 49 of file GraphiteMetalWindowContext.h.

◆ fValid

bool skwindow::internal::GraphiteMetalWindowContext::fValid
protected

Definition at line 47 of file GraphiteMetalWindowContext.h.


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