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

#import <FlutterSurfaceManager.h>

Inheritance diagram for FlutterBackBufferCache:

Instance Methods

(nullable FlutterSurface *) - removeSurfaceForSize:
 
(void) - returnSurfaces:
 
(NSUInteger) - count
 
(instancetype) - init [implementation]
 
(int- ageForSurface: [implementation]
 
(void) - setAge:forSurface: [implementation]
 
(void) - onIdle [implementation]
 
(void) - reschedule [implementation]
 
(void) - dealloc [implementation]
 

Protected Attributes

NSMutableArray< FlutterSurface * > * _surfaces
 
NSMapTable< FlutterSurface *, NSNumber * > * _surfaceAge
 

Detailed Description

Cache of back buffers to prevent unnecessary IOSurface allocations.

Definition at line 81 of file FlutterSurfaceManager.h.

Method Documentation

◆ ageForSurface:

- (int) ageForSurface: (FlutterSurface*)  surface
implementation

Definition at line 277 of file FlutterSurfaceManager.mm.

293 NSNumber* age = [_surfaceAge objectForKey:surface];
294 return age != nil ? age.intValue : 0;
295}
VkSurfaceKHR surface
Definition: main.cc:49

◆ count

- (NSUInteger) count

Returns number of surfaces currently in cache. Used for tests.

Definition at line 277 of file FlutterSurfaceManager.mm.

352 {
353 @synchronized(self) {
354 return _surfaces.count;
355 }
356}
NSMutableArray< FlutterSurface * > * _surfaces

◆ dealloc

- (void) dealloc
implementation

Definition at line 277 of file FlutterSurfaceManager.mm.

369 {
370 [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(onIdle) object:nil];
371}

◆ init

- (instancetype) init
implementation

Definition at line 277 of file FlutterSurfaceManager.mm.

284 {
285 if (self = [super init]) {
286 self->_surfaces = [[NSMutableArray alloc] init];
287 self->_surfaceAge = [NSMapTable weakToStrongObjectsMapTable];
288 }
289 return self;
290}

◆ onIdle

- (void) onIdle
implementation

Definition at line 277 of file FlutterSurfaceManager.mm.

358 {
359 @synchronized(self) {
360 [_surfaces removeAllObjects];
361 }
362}

◆ removeSurfaceForSize:

- (nullable FlutterSurface *) removeSurfaceForSize: (CGSize)  size

Removes surface with given size from cache (if available) and returns it.

Definition at line 277 of file FlutterSurfaceManager.mm.

301 :(CGSize)size {
302 @synchronized(self) {
303 // Purge all cached surfaces if the size has changed.
304 if (_surfaces.firstObject != nil && !CGSizeEqualToSize(_surfaces.firstObject.size, size)) {
305 [_surfaces removeAllObjects];
306 }
307
308 FlutterSurface* res;
309
310 // Returns youngest surface that is not in use. Returning youngest surface ensures
311 // that the cache doesn't keep more surfaces than it needs to, as the unused surfaces
312 // kept in cache will have their age kept increasing until purged (inside [returnSurfaces:]).
314 if (!surface.isInUse &&
315 (res == nil || [self ageForSurface:res] > [self ageForSurface:surface])) {
316 res = surface;
317 }
318 }
319 if (res != nil) {
320 [_surfaces removeObject:res];
321 }
322 return res;
323 }
324}
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

◆ reschedule

- (void) reschedule
implementation

Definition at line 277 of file FlutterSurfaceManager.mm.

364 {
365 [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(onIdle) object:nil];
366 [self performSelector:@selector(onIdle) withObject:nil afterDelay:kIdleDelay];
367}

◆ returnSurfaces:

- (void) returnSurfaces: (nonnull NSArray<FlutterSurface*>*)  surfaces

Removes all cached surfaces replacing them with new ones.

Definition at line 277 of file FlutterSurfaceManager.mm.

326 :(nonnull NSArray<FlutterSurface*>*)returnedSurfaces {
327 @synchronized(self) {
328 for (FlutterSurface* surface in returnedSurfaces) {
329 [self setAge:0 forSurface:surface];
330 }
332 [self setAge:[self ageForSurface:surface] + 1 forSurface:surface];
333 }
334
335 [_surfaces addObjectsFromArray:returnedSurfaces];
336
337 // Purge all surface with age = kSurfaceEvictionAge. Reaching this age can mean two things:
338 // - Surface is still in use and we can't return it. This can happen in some edge
339 // cases where the compositor holds on to the surface for much longer than expected.
340 // - Surface is not in use but it hasn't been requested from the cache for a while.
341 // This means there are too many surfaces in the cache.
342 [_surfaces filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(FlutterSurface* surface,
343 NSDictionary* bindings) {
344 return [self ageForSurface:surface] < kSurfaceEvictionAge;
345 }]];
346 }
347
348 // performSelector:withObject:afterDelay needs to be performed on RunLoop thread
349 [self performSelectorOnMainThread:@selector(reschedule) withObject:nil waitUntilDone:NO];
350}

◆ setAge:forSurface:

- (void) setAge: (int age
forSurface: (FlutterSurface*)  surface 
implementation

Definition at line 277 of file FlutterSurfaceManager.mm.

297 :(int)age forSurface:(FlutterSurface*)surface {
298 [_surfaceAge setObject:@(age) forKey:surface];
299}

Member Data Documentation

◆ _surfaceAge

- (NSMapTable<FlutterSurface*, NSNumber*>*) _surfaceAge
protected

Definition at line 277 of file FlutterSurfaceManager.mm.

◆ _surfaces

- (NSMutableArray<FlutterSurface*>*) _surfaces
protected

Definition at line 276 of file FlutterSurfaceManager.mm.


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