Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Instance Methods | Class Methods | Protected Attributes | Properties | List of all members
FlutterView Class Reference

#include <FlutterView.h>

Inheritance diagram for FlutterView:
<FlutterSurfaceManagerDelegate> TestFlutterView

Instance Methods

(instancetype) - NS_UNAVAILABLE
 
(instancetype) - initWithFrame:
 
(instancetype) - initWithCoder:
 
(instancetype) - initWithDelegate:opaque:enableWideGamut:
 
(UIScreen *) - screen
 
(MTLPixelFormat) - pixelFormat
 
(nullable instancetype) - initWithMTLDevice:commandQueue:delegate:threadSynchronizer:viewIdentifier:
 
(nullable instancetype) - initWithFrame:pixelFormat:
 
(nonnull instancetype) - initWithFrame:
 
(nullable instancetype) - initWithCoder:
 
(nonnull instancetype) - NS_UNAVAILABLE
 
(void) - setBackgroundColor:
 
(void) - didUpdateMouseCursor:
 
(instancetype) - init [implementation]
 
(BOOL- isWideGamutSupported [implementation]
 
(void) - layoutSubviews [implementation]
 
(void) - drawLayer:inContext: [implementation]
 
(BOOL- isAccessibilityElement [implementation]
 
(instancetype) - initWithMTLDevice:commandQueue:delegate:threadSynchronizer:viewIdentifier: [implementation]
 
(void) - onPresent:withBlock: [implementation]
 
(void) - reshaped [implementation]
 
(void) - setBackgroundColor: [implementation]
 
(void) - setFrameSize: [implementation]
 
(BOOL- isFlipped [implementation]
 
(BOOL- isOpaque [implementation]
 
(BOOL- acceptsFirstMouse: [implementation]
 
(BOOL- acceptsFirstResponder [implementation]
 
(void) - didUpdateMouseCursor: [implementation]
 
(void) - cursorUpdate: [implementation]
 
(void) - viewDidChangeBackingProperties [implementation]
 
(BOOL- layer:shouldInheritContentsScale:fromWindow: [implementation]
 
(NSAccessibilityRole) - accessibilityRole [implementation]
 
(NSString *) - accessibilityLabel [implementation]
 
- Instance Methods inherited from <FlutterSurfaceManagerDelegate>
(void) - onPresent:withBlock:
 

Class Methods

(instancetype) + NS_UNAVAILABLE
 
(static void) + PrintWideGamutWarningOnce [implementation]
 
(void) + setForceSoftwareRendering: [implementation]
 
(Class) + layerClass [implementation]
 

Protected Attributes

FlutterViewIdentifier _viewIdentifier
 
__weak id< FlutterViewDelegate_viewDelegate
 
FlutterThreadSynchronizer_threadSynchronizer
 
FlutterSurfaceManager_surfaceManager
 
NSCursor * _lastCursor
 

Properties

BOOL forceSoftwareRendering
 
FlutterSurfaceManagersurfaceManager
 

Detailed Description

View capable of acting as a rendering target and input source for the Flutter engine.

Definition at line 34 of file FlutterView.h.

Method Documentation

◆ acceptsFirstMouse:

- (BOOL) acceptsFirstMouse: (NSEvent*)  event
implementation

Declares that the initial mouse-down when the view is not in focus will send an event to the view.

Definition at line 17 of file FlutterView.mm.

88 :(NSEvent*)event {
89 return YES;
90}
FlKeyEvent * event

◆ acceptsFirstResponder

- (BOOL) acceptsFirstResponder
implementation

Definition at line 17 of file FlutterView.mm.

92 {
93 // This is to ensure that FlutterView does not take first responder status from TextInputPlugin
94 // on mouse clicks.
95 return [_viewDelegate viewShouldAcceptFirstResponder:self];
96}

◆ accessibilityLabel

- (NSString *) accessibilityLabel
implementation

Definition at line 17 of file FlutterView.mm.

146 {
147 // TODO(chunhtai): Provides a way to let developer customize the accessibility
148 // label.
149 // https://github.com/flutter/flutter/issues/75446
150 NSString* applicationName =
151 [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
152 if (!applicationName) {
153 applicationName = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleName"];
154 }
155 return applicationName;
156}

◆ accessibilityRole

- (NSAccessibilityRole) accessibilityRole
implementation

Definition at line 17 of file FlutterView.mm.

142 {
143 return NSAccessibilityGroupRole;
144}

◆ cursorUpdate:

- (void) cursorUpdate: (NSEvent*)  event
implementation

Definition at line 17 of file FlutterView.mm.

108 :(NSEvent*)event {
109 // Make sure to not override cursor when over a platform view.
110 NSView* hitTestView = [self hitTest:[self convertPoint:event.locationInWindow fromView:nil]];
111 if (hitTestView != self) {
112 return;
113 }
114 [_lastCursor set];
115 // It is possible that there is a platform view with NSTrackingArea below flutter content.
116 // This could override the mouse cursor as a result of mouse move event. There is no good way
117 // to prevent that short of swizzling [NSCursor set], so as a workaround force flutter cursor
118 // in next runloop turn. This is not ideal, as it may cause the cursor flicker a bit.
119 [[NSRunLoop currentRunLoop] performBlock:^{
120 [_lastCursor set];
121 }];
122}

◆ didUpdateMouseCursor: [1/2]

- (void) didUpdateMouseCursor: (nonnull NSCursor *)  cursor

Called from the engine to notify the view that mouse cursor was updated while the mouse is over the view. The view is responsible from restoring the cursor when the mouse enters the view from another subview.

◆ didUpdateMouseCursor: [2/2]

- (void) didUpdateMouseCursor: (NSCursor*)  cursor
implementation

Definition at line 17 of file FlutterView.mm.

98 :(NSCursor*)cursor {
99 _lastCursor = cursor;
100}
NSCursor * _lastCursor

◆ drawLayer:inContext:

- (void) drawLayer: (CALayer*)  layer
inContext: (CGContextRef)  context 
implementation

Definition at line 123 of file FlutterView.mm.

138 :(CALayer*)layer inContext:(CGContextRef)context {
139 TRACE_EVENT0("flutter", "SnapshotFlutterView");
140
141 if (layer != self.layer || context == nullptr) {
142 return;
143 }
144
145 auto screenshot = [_delegate takeScreenshot:flutter::Rasterizer::ScreenshotType::UncompressedImage
146 asBase64Encoded:NO];
147
148 if (!screenshot.data || screenshot.data->isEmpty() || screenshot.frame_size.isEmpty()) {
149 return;
150 }
151
152 NSData* data = [NSData dataWithBytes:const_cast<void*>(screenshot.data->data())
153 length:screenshot.data->size()];
154
155 fml::CFRef<CGDataProviderRef> image_data_provider(
156 CGDataProviderCreateWithCFData(reinterpret_cast<CFDataRef>(data)));
157
158 fml::CFRef<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB());
159
160 // Defaults for RGBA8888.
161 size_t bits_per_component = 8u;
162 size_t bits_per_pixel = 32u;
163 size_t bytes_per_row_multiplier = 4u;
164 CGBitmapInfo bitmap_info =
165 static_cast<CGBitmapInfo>(static_cast<uint32_t>(kCGImageAlphaPremultipliedLast) |
166 static_cast<uint32_t>(kCGBitmapByteOrder32Big));
167
168 switch (screenshot.pixel_format) {
171 // Assume unknown is Skia and is RGBA8888. Keep defaults.
172 break;
174 // Treat this as little endian with the alpha first so that it's read backwards.
175 bitmap_info =
176 static_cast<CGBitmapInfo>(static_cast<uint32_t>(kCGImageAlphaPremultipliedFirst) |
177 static_cast<uint32_t>(kCGBitmapByteOrder32Little));
178 break;
180 bits_per_component = 16u;
181 bits_per_pixel = 64u;
182 bytes_per_row_multiplier = 8u;
183 bitmap_info =
184 static_cast<CGBitmapInfo>(static_cast<uint32_t>(kCGImageAlphaPremultipliedLast) |
185 static_cast<uint32_t>(kCGBitmapFloatComponents) |
186 static_cast<uint32_t>(kCGBitmapByteOrder16Little));
187 break;
188 }
189
190 fml::CFRef<CGImageRef> image(CGImageCreate(
191 screenshot.frame_size.width(), // size_t width
192 screenshot.frame_size.height(), // size_t height
193 bits_per_component, // size_t bitsPerComponent
194 bits_per_pixel, // size_t bitsPerPixel,
195 bytes_per_row_multiplier * screenshot.frame_size.width(), // size_t bytesPerRow
196 colorspace, // CGColorSpaceRef space
197 bitmap_info, // CGBitmapInfo bitmapInfo
198 image_data_provider, // CGDataProviderRef provider
199 nullptr, // const CGFloat* decode
200 false, // bool shouldInterpolate
201 kCGRenderingIntentDefault // CGColorRenderingIntent intent
202 ));
203
204 const CGRect frame_rect =
205 CGRectMake(0.0, 0.0, screenshot.frame_size.width(), screenshot.frame_size.height());
206 CGContextSaveGState(context);
207 // If the CGContext is not a bitmap based context, this returns zero.
208 CGFloat height = CGBitmapContextGetHeight(context);
209 if (height == 0) {
210 height = CGFloat(screenshot.frame_size.height());
211 }
212 CGContextTranslateCTM(context, 0.0, height);
213 CGContextScaleCTM(context, 1.0, -1.0);
214 CGContextDrawImage(context, frame_rect, image);
215 CGContextRestoreGState(context);
216}
sk_sp< SkImage > image
Definition examples.cpp:29
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
int32_t height
#define TRACE_EVENT0(category_group, name)

◆ init

- (instancetype) init
implementation

Definition at line 11 of file FlutterView.mm.

14 {
15 NSAssert(NO, @"FlutterView must initWithDelegate");
16 return nil;
17}

◆ initWithCoder: [1/2]

- (nullable instancetype) initWithCoder: (nonnull NSCoder *)  NS_UNAVAILABLE

◆ initWithCoder: [2/2]

- (instancetype) initWithCoder: (NSCoder*)  NS_UNAVAILABLE

Definition at line 11 of file FlutterView.mm.

24 :(NSCoder*)aDecoder {
25 NSAssert(NO, @"FlutterView must initWithDelegate");
26 return nil;
27}

◆ initWithDelegate:opaque:enableWideGamut:

- (instancetype) initWithDelegate: (id<FlutterViewEngineDelegate>)  delegate
opaque: (BOOL opaque
enableWideGamut: (BOOL NS_DESIGNATED_INITIALIZER 

Definition at line 11 of file FlutterView.mm.

60 :(id<FlutterViewEngineDelegate>)delegate
61 opaque:(BOOL)opaque
62 enableWideGamut:(BOOL)isWideGamutEnabled {
63 if (delegate == nil) {
64 NSLog(@"FlutterView delegate was nil.");
65 [self release];
66 return nil;
67 }
68
69 self = [super initWithFrame:CGRectNull];
70
71 if (self) {
72 _delegate = delegate;
73 _isWideGamutEnabled = isWideGamutEnabled;
74 self.layer.opaque = opaque;
75
76 // This line is necessary. CoreAnimation(or UIKit) may take this to do
77 // something to compute the final frame presented on screen, if we don't set this,
78 // it will make it take long time for us to take next CAMetalDrawable and will
79 // cause constant junk during rendering.
80 self.backgroundColor = UIColor.clearColor;
81 }
82
83 return self;
84}
if(end==-1)
BOOL _isWideGamutEnabled
int BOOL

◆ initWithFrame: [1/2]

- (instancetype) initWithFrame: (CGRect)  NS_UNAVAILABLE

Definition at line 11 of file FlutterView.mm.

19 :(CGRect)frame {
20 NSAssert(NO, @"FlutterView must initWithDelegate");
21 return nil;
22}
double frame
Definition examples.cpp:31

◆ initWithFrame: [2/2]

- (nonnull instancetype) initWithFrame: (NSRect)  NS_UNAVAILABLE

◆ initWithFrame:pixelFormat:

- (nullable instancetype) initWithFrame: (NSRect)  frameRect
pixelFormat: (nullable NSOpenGLPixelFormat *)  NS_UNAVAILABLE 

◆ initWithMTLDevice:commandQueue:delegate:threadSynchronizer:viewIdentifier: [1/2]

- (instancetype) initWithMTLDevice: (id<MTLDevice>)  device
commandQueue: (id<MTLCommandQueue>)  commandQueue
delegate: (id<FlutterViewDelegate>)  delegate
threadSynchronizer: (FlutterThreadSynchronizer*)  threadSynchronizer
viewIdentifier: (FlutterViewIdentifier viewIdentifier 
implementation

Definition at line 17 of file FlutterView.mm.

24 :(id<MTLDevice>)device
25 commandQueue:(id<MTLCommandQueue>)commandQueue
26 delegate:(id<FlutterViewDelegate>)delegate
27 threadSynchronizer:(FlutterThreadSynchronizer*)threadSynchronizer
28 viewIdentifier:(FlutterViewIdentifier)viewIdentifier {
29 self = [super initWithFrame:NSZeroRect];
30 if (self) {
31 [self setWantsLayer:YES];
32 [self setBackgroundColor:[NSColor blackColor]];
33 [self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawDuringViewResize];
34 _viewIdentifier = viewIdentifier;
35 _viewDelegate = delegate;
36 _threadSynchronizer = threadSynchronizer;
37 _surfaceManager = [[FlutterSurfaceManager alloc] initWithDevice:device
38 commandQueue:commandQueue
39 layer:self.layer
40 delegate:self];
41 }
42 return self;
43}
VkDevice device
Definition main.cc:53
__weak id< FlutterViewDelegate > _viewDelegate
FlutterSurfaceManager * _surfaceManager
FlutterViewIdentifier _viewIdentifier
instancetype initWithFrame
int64_t FlutterViewIdentifier
FlutterThreadSynchronizer * _threadSynchronizer
const uintptr_t id

◆ initWithMTLDevice:commandQueue:delegate:threadSynchronizer:viewIdentifier: [2/2]

- (nullable instancetype) initWithMTLDevice: (nonnull id< MTLDevice >)  device
commandQueue: (nonnull id< MTLCommandQueue >)  commandQueue
delegate: (nonnull id< FlutterViewDelegate >)  delegate
threadSynchronizer: (nonnull FlutterThreadSynchronizer *)  threadSynchronizer
viewIdentifier: (FlutterViewIdentifier NS_DESIGNATED_INITIALIZER 

Initialize a FlutterView that will be rendered to using Metal rendering apis.

◆ isAccessibilityElement

- (BOOL) isAccessibilityElement
implementation

Definition at line 123 of file FlutterView.mm.

218 {
219 // iOS does not provide an API to query whether the voice control
220 // is turned on or off. It is likely at least one of the assitive
221 // technologies is turned on if this method is called. If we do
222 // not catch it in notification center, we will catch it here.
223 //
224 // TODO(chunhtai): Remove this workaround once iOS provides an
225 // API to query whether voice control is enabled.
226 // https://github.com/flutter/flutter/issues/76808.
227 [_delegate flutterViewAccessibilityDidCall];
228 return NO;
229}

◆ isFlipped

- (BOOL) isFlipped
implementation

Declares that the view uses a flipped coordinate system, consistent with Flutter conventions.

Definition at line 17 of file FlutterView.mm.

76 {
77 return YES;
78}

◆ isOpaque

- (BOOL) isOpaque
implementation

Definition at line 17 of file FlutterView.mm.

80 {
81 return YES;
82}

◆ isWideGamutSupported

- (BOOL) isWideGamutSupported
implementation

Definition at line 11 of file FlutterView.mm.

47 {
48 if (![_delegate isUsingImpeller]) {
49 return NO;
50 }
51
52 FML_DCHECK(self.screen);
53
54 // This predicates the decision on the capabilities of the iOS device's
55 // display. This means external displays will not support wide gamut if the
56 // device's display doesn't support it. It practice that should be never.
57 return self.screen.traitCollection.displayGamut != UIDisplayGamutSRGB;
58}
#define FML_DCHECK(condition)
Definition logging.h:103
UIScreen * screen()

◆ layer:shouldInheritContentsScale:fromWindow:

- (BOOL) layer: (CALayer*)  layer
shouldInheritContentsScale: (CGFloat)  newScale
fromWindow: (NSWindow*)  window 
implementation

Definition at line 17 of file FlutterView.mm.

130 :(CALayer*)layer
131 shouldInheritContentsScale:(CGFloat)newScale
132 fromWindow:(NSWindow*)window {
133 return YES;
134}
GLFWwindow * window
Definition main.cc:45

◆ layerClass

+ (Class) layerClass
implementation

Definition at line 123 of file FlutterView.mm.

133 {
136}
BOOL forceSoftwareRendering
Definition FlutterView.h:49
IOSRenderingAPI GetRenderingAPIForProcess(bool force_software)
Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api)

◆ layoutSubviews

- (void) layoutSubviews
implementation

Definition at line 86 of file FlutterView.mm.

96 {
97 if ([self.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]) {
98// It is a known Apple bug that CAMetalLayer incorrectly reports its supported
99// SDKs. It is, in fact, available since iOS 8.
100#pragma clang diagnostic push
101#pragma clang diagnostic ignored "-Wunguarded-availability-new"
102 CAMetalLayer* layer = (CAMetalLayer*)self.layer;
103#pragma clang diagnostic pop
104 CGFloat screenScale = self.screen.scale;
105 layer.allowsGroupOpacity = YES;
106 layer.contentsScale = screenScale;
107 layer.rasterizationScale = screenScale;
108 layer.framebufferOnly = flutter::Settings::kSurfaceDataAccessible ? NO : YES;
109 BOOL isWideGamutSupported = self.isWideGamutSupported;
111 CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
112 layer.colorspace = srgb;
113 CFRelease(srgb);
114 layer.pixelFormat = MTLPixelFormatBGRA10_XR;
117 }
118 }
119
120 [super layoutSubviews];
121}
BOOL isWideGamutSupported()
static void PrintWideGamutWarningOnce()
static constexpr bool kSurfaceDataAccessible
Definition settings.h:113

◆ NS_UNAVAILABLE [1/3]

+ (instancetype) NS_UNAVAILABLE

◆ NS_UNAVAILABLE [2/3]

- (instancetype) NS_UNAVAILABLE

◆ NS_UNAVAILABLE [3/3]

- (nonnull instancetype) NS_UNAVAILABLE

◆ onPresent:withBlock:

- (void) onPresent: (CGSize)  frameSize
withBlock: (dispatch_block_t)  block 
implementation

Definition at line 17 of file FlutterView.mm.

45 :(CGSize)frameSize withBlock:(dispatch_block_t)block {
46 [_threadSynchronizer performCommitForView:_viewIdentifier size:frameSize notify:block];
47}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259

◆ pixelFormat

- (MTLPixelFormat) pixelFormat

Definition at line 11 of file FlutterView.mm.

36 {
37 if ([self.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]) {
38// It is a known Apple bug that CAMetalLayer incorrectly reports its supported
39// SDKs. It is, in fact, available since iOS 8.
40#pragma clang diagnostic push
41#pragma clang diagnostic ignored "-Wunguarded-availability-new"
42 CAMetalLayer* layer = (CAMetalLayer*)self.layer;
43 return layer.pixelFormat;
44 }
45 return MTLPixelFormatBGRA8Unorm;
46}

◆ PrintWideGamutWarningOnce

+ (static void) PrintWideGamutWarningOnce
implementation

Definition at line 86 of file FlutterView.mm.

86 {
87 static BOOL did_print = NO;
88 if (did_print) {
89 return;
90 }
91 FML_DLOG(WARNING) << "Rendering wide gamut colors is turned on but isn't "
92 "supported, downgrading the color gamut to sRGB.";
93 did_print = YES;
94}
#define FML_DLOG(severity)
Definition logging.h:102

◆ reshaped

- (void) reshaped
implementation

Reimplemented in TestFlutterView.

Definition at line 17 of file FlutterView.mm.

53 {
54 CGSize scaledSize = [self convertSizeToBacking:self.bounds.size];
55 [_threadSynchronizer beginResizeForView:_viewIdentifier
56 size:scaledSize
57 notify:^{
58 [_viewDelegate viewDidReshape:self];
59 }];
60}

◆ screen

- (UIScreen *) screen

Definition at line 11 of file FlutterView.mm.

29 {
30 if (@available(iOS 13.0, *)) {
31 return self.window.windowScene.screen;
32 }
33 return UIScreen.mainScreen;
34}

◆ setBackgroundColor: [1/2]

- (void) setBackgroundColor: (nonnull NSColor *)  color

By default, the FlutterSurfaceManager creates two layers to manage Flutter content, the content layer and containing layer. To set the native background color, onto which the Flutter content is drawn, call this method with the NSColor which you would like to override the default, black background color with.

◆ setBackgroundColor: [2/2]

- (void) setBackgroundColor: (NSColor*)  color
implementation

Definition at line 17 of file FlutterView.mm.

62 :(NSColor*)color {
63 self.layer.backgroundColor = color.CGColor;
64}
SkColor4f color

◆ setForceSoftwareRendering:

+ (void) setForceSoftwareRendering: (BOOL forceSoftwareRendering
implementation

Definition at line 123 of file FlutterView.mm.

◆ setFrameSize:

- (void) setFrameSize: (NSSize)  newSize
implementation

Definition at line 17 of file FlutterView.mm.

68 :(NSSize)newSize {
69 [super setFrameSize:newSize];
70 [self reshaped];
71}

◆ viewDidChangeBackingProperties

- (void) viewDidChangeBackingProperties
implementation

Definition at line 17 of file FlutterView.mm.

124 {
125 [super viewDidChangeBackingProperties];
126 // Force redraw
127 [_viewDelegate viewDidReshape:self];
128}

Member Data Documentation

◆ _lastCursor

- (NSCursor*) _lastCursor
protected

Provided by category FlutterView().

Definition at line 17 of file FlutterView.mm.

◆ _surfaceManager

- (FlutterSurfaceManager*) _surfaceManager
protected

Provided by category FlutterView().

Definition at line 16 of file FlutterView.mm.

◆ _threadSynchronizer

- (FlutterThreadSynchronizer*) _threadSynchronizer
protected

Provided by category FlutterView().

Definition at line 15 of file FlutterView.mm.

◆ _viewDelegate

- (__weak id<FlutterViewDelegate>) _viewDelegate
protected

Provided by category FlutterView().

Definition at line 14 of file FlutterView.mm.

◆ _viewIdentifier

- (FlutterViewIdentifier) _viewIdentifier
protected

Provided by category FlutterView().

Definition at line 13 of file FlutterView.mm.

Property Documentation

◆ forceSoftwareRendering

- (BOOL) forceSoftwareRendering
readwritenonatomicassign

Definition at line 49 of file FlutterView.h.

◆ surfaceManager

- (FlutterSurfaceManager *) surfaceManager
readnonatomicassign

Returns SurfaceManager for this view. SurfaceManager is responsible for providing and presenting render surfaces.

Definition at line 57 of file FlutterView.h.


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