Flutter Engine
The Flutter Engine
Instance Methods | Class Methods | Protected Attributes | List of all members
FlutterSurface Class Reference

#import <FlutterSurface.h>

Inheritance diagram for FlutterSurface:

Instance Methods

(FlutterMetalTexture- asFlutterMetalTexture
 
(IOSurfaceRef) - ioSurface [implementation]
 
(CGSize) - size [implementation]
 
(int64_t) - textureId [implementation]
 
(BOOL- isInUse [implementation]
 
(BOOL- isInUseOverride [implementation]
 
(void) - setIsInUseOverride: [implementation]
 
(instancetype) - initWithSize:device: [implementation]
 
(void) - dealloc [implementation]
 

Class Methods

(nullable FlutterSurface *) + fromFlutterMetalTexture:
 
(static void) + ReleaseSurface [implementation]
 
(FlutterSurface *) + fromFlutterMetalTexture: [implementation]
 
(IOSurfaceRef) + createIOSurfaceWithSize: [implementation]
 
(id< MTLTexture >) + createTextureForIOSurface:size:device: [implementation]
 

Protected Attributes

CGSize _size
 
IOSurfaceRef _ioSurface
 
id< MTLTexture > _texture
 
BOOL _isInUseOverride
 

Detailed Description

Opaque surface type. Can be represented as FlutterMetalTexture to cross the embedder API boundary.

Definition at line 16 of file FlutterSurface.h.

Method Documentation

◆ asFlutterMetalTexture

- (FlutterMetalTexture) asFlutterMetalTexture

Definition at line 53 of file FlutterSurface.mm.

59 {
61 memset(&res, 0, sizeof(FlutterMetalTexture));
62 res.struct_size = sizeof(FlutterMetalTexture);
63 res.texture = (__bridge void*)_texture;
64 res.texture_id = self.textureId;
65 res.user_data = (void*)CFBridgingRetain(self);
67 return res;
68}
static void ReleaseSurface(void *surface)
id< MTLTexture > _texture
FlutterMetalTextureHandle texture
Definition: embedder.h:661
size_t struct_size
The size of this struct. Must be sizeof(FlutterMetalTexture).
Definition: embedder.h:651
int64_t texture_id
Definition: embedder.h:656
VoidCallback destruction_callback
Definition: embedder.h:668

◆ createIOSurfaceWithSize:

+ (IOSurfaceRef) createIOSurfaceWithSize: (CGSize)  size
implementation

Definition at line 53 of file FlutterSurface.mm.

78 :(CGSize)size {
79 unsigned pixelFormat = 'BGRA';
80 unsigned bytesPerElement = 4;
81
82 size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, size.width * bytesPerElement);
83 size_t totalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize, size.height * bytesPerRow);
84 NSDictionary* options = @{
85 (id)kIOSurfaceWidth : @(size.width),
86 (id)kIOSurfaceHeight : @(size.height),
87 (id)kIOSurfacePixelFormat : @(pixelFormat),
88 (id)kIOSurfaceBytesPerElement : @(bytesPerElement),
89 (id)kIOSurfaceBytesPerRow : @(bytesPerRow),
90 (id)kIOSurfaceAllocSize : @(totalBytes),
91 };
92
93 IOSurfaceRef res = IOSurfaceCreate((CFDictionaryRef)options);
94 IOSurfaceSetValue(res, CFSTR("IOSurfaceColorSpace"), kCGColorSpaceSRGB);
95 return res;
96}
const char * options
const uintptr_t id

◆ createTextureForIOSurface:size:device:

+ (id< MTLTexture >) createTextureForIOSurface: (IOSurfaceRef)  surface
size: (CGSize)  size
device: (id<MTLDevice>)  device 
implementation

Definition at line 53 of file FlutterSurface.mm.

98 :(IOSurfaceRef)surface
99 size:(CGSize)size
100 device:(id<MTLDevice>)device {
101 MTLTextureDescriptor* textureDescriptor =
102 [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
103 width:size.width
104 height:size.height
105 mipmapped:NO];
106 textureDescriptor.usage =
107 MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget | MTLTextureUsageShaderWrite;
108 // plane = 0 for BGRA.
109 return [device newTextureWithDescriptor:textureDescriptor iosurface:surface plane:0];
110}
VkDevice device
Definition: main.cc:53
VkSurfaceKHR surface
Definition: main.cc:49

◆ dealloc

- (void) dealloc
implementation

Definition at line 53 of file FlutterSurface.mm.

74 {
75 CFRelease(_ioSurface);
76}
IOSurfaceRef _ioSurface

◆ fromFlutterMetalTexture: [1/2]

+ (FlutterSurface *) fromFlutterMetalTexture: (const FlutterMetalTexture*)  texture
implementation

Definition at line 53 of file FlutterSurface.mm.

71 return (__bridge FlutterSurface*)texture->user_data;
72}
FlTexture * texture

◆ fromFlutterMetalTexture: [2/2]

+ (nullable FlutterSurface *) fromFlutterMetalTexture: (nonnull const FlutterMetalTexture *)  texture

◆ initWithSize:device:

- (instancetype) initWithSize: (CGSize)  size
device: (id<MTLDevice>)  device 
implementation

Provided by category FlutterSurface(Private).

Definition at line 14 of file FlutterSurface.mm.

44 :(CGSize)size device:(id<MTLDevice>)device {
45 if (self = [super init]) {
46 self->_size = size;
47 self->_ioSurface = [FlutterSurface createIOSurfaceWithSize:size];
48 self->_texture = [FlutterSurface createTextureForIOSurface:_ioSurface size:size device:device];
49 }
50 return self;
51}
IOSurfaceRef createIOSurfaceWithSize:(CGSize size)
id< MTLTexture > createTextureForIOSurface:size:device:(IOSurfaceRef surface, [size] CGSize size, [device] id< MTLDevice > device)
static bool init()

◆ ioSurface

- (IOSurfaceRef) ioSurface
implementation

Provided by category FlutterSurface(Private).

Definition at line 14 of file FlutterSurface.mm.

20 {
21 return _ioSurface;
22}

◆ isInUse

- (BOOL) isInUse
implementation

Provided by category FlutterSurface(Private).

Definition at line 14 of file FlutterSurface.mm.

32 {
33 return _isInUseOverride || IOSurfaceIsInUse(_ioSurface);
34}

◆ isInUseOverride

- (BOOL) isInUseOverride
implementation

Provided by category FlutterSurface(Testing).

Definition at line 14 of file FlutterSurface.mm.

36 {
37 return _isInUseOverride;
38}

◆ ReleaseSurface

+ (static void) ReleaseSurface (void *)  surface
implementation

Definition at line 53 of file FlutterSurface.mm.

53 {
54 if (surface != nullptr) {
55 CFBridgingRelease(surface);
56 }
57}

◆ setIsInUseOverride:

- (void) setIsInUseOverride: (BOOL isInUseOverride
implementation

Definition at line 14 of file FlutterSurface.mm.

◆ size

- (CGSize) size
implementation

Provided by category FlutterSurface(Private).

Definition at line 14 of file FlutterSurface.mm.

24 {
25 return _size;
26}

◆ textureId

- (int64_t) textureId
implementation

Provided by category FlutterSurface(Private).

Definition at line 14 of file FlutterSurface.mm.

28 {
29 return reinterpret_cast<int64_t>(_texture);
30}

Member Data Documentation

◆ _ioSurface

- (IOSurfaceRef) _ioSurface
protected

Definition at line 11 of file FlutterSurface.mm.

◆ _isInUseOverride

- (BOOL) _isInUseOverride
protected

Definition at line 14 of file FlutterSurface.mm.

◆ _size

- (CGSize) _size
protected

Definition at line 10 of file FlutterSurface.mm.

◆ _texture

- (id<MTLTexture>) _texture
protected

Definition at line 12 of file FlutterSurface.mm.


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