| Flutter macOS Embedder |

Instance Methods | List of all members
FlutterBackBufferCache Class Reference

`#import <FlutterSurfaceManager.h>`

Inheritance diagram for FlutterBackBufferCache:

## Instance Methods
(nullable FlutterSurface *) | - removeSurfaceForSize:
(void) | - returnSurfaces:
(void) | - flush
(NSUInteger) | - count

## Detailed Description

Cache of back buffers to prevent unnecessary IOSurface allocations.

Definition at line 92 of file FlutterSurfaceManager.h.

## Method Documentation

## ◆ count

- (NSUInteger) count |  |  |

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

Definition at line 295 of file FlutterSurfaceManager.mm.

376 {
377 @synchronized(self) {
378 return _surfaces.count;
379 }
380 }

Referenced by flutter::testing::TEST().

## ◆ flush

- (void) flush |  |  |

Removes all cached surfaces.

Definition at line 295 of file FlutterSurfaceManager.mm.

370 {
371 @synchronized(self) {
372 [_surfaces removeAllObjects];
373 }
374 }

## ◆ removeSurfaceForSize:

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

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

Definition at line 295 of file FlutterSurfaceManager.mm.

319 :(CGSize)size {
320 @synchronized(self) {
321 // Purge all cached surfaces if the size has changed.
322 if (_surfaces.firstObject != nil && !CGSizeEqualToSize(_surfaces.firstObject.size, size)) {
323 [_surfaces removeAllObjects];
324 }
325
326 FlutterSurface* res;
327
328 // Returns youngest surface that is not in use. Returning youngest surface ensures
329 // that the cache doesn't keep more surfaces than it needs to, as the unused surfaces
330 // kept in cache will have their age kept increasing until purged (inside [returnSurfaces:]).
331 for (FlutterSurface* surface in _surfaces) {
332 if (!surface.isInUse &&
333 (res == nil || [self ageForSurface:res] > [self ageForSurface:surface])) {
334 res = surface;
335 }
336 }
337 if (res != nil) {
338 [_surfaces removeObject:res];
339 }
340 return res;
341 }
342 }
FlutterSurface
Definition: FlutterSurface.h:17

## ◆ returnSurfaces:

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

Removes all cached surfaces replacing them with new ones.

Definition at line 295 of file FlutterSurfaceManager.mm.

344 :(nonnull NSArray<FlutterSurface*>*)returnedSurfaces {
345 @synchronized(self) {
346 for (FlutterSurface* surface in returnedSurfaces) {
347 [self setAge:0 forSurface:surface];
348 }
349 for (FlutterSurface* surface in _surfaces) {
350 [self setAge:[self ageForSurface:surface] + 1 forSurface:surface];
351 }
352
353 [_surfaces addObjectsFromArray:returnedSurfaces];
354
355 // Purge all surface with age = kSurfaceEvictionAge. Reaching this age can mean two things:
356 // - Surface is still in use and we can't return it. This can happen in some edge
357 // cases where the compositor holds on to the surface for much longer than expected.
358 // - Surface is not in use but it hasn't been requested from the cache for a while.
359 // This means there are too many surfaces in the cache.
360 [_surfaces filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(FlutterSurface* surface,
361 NSDictionary* bindings) {
362 return [self ageForSurface:surface] < kSurfaceEvictionAge;
363 }]];
364 }
365
366 // performSelector:withObject:afterDelay needs to be performed on RunLoop thread
367 [self performSelectorOnMainThread:@selector(reschedule) withObject:nil waitUntilDone:NO];
368 }

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

- shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h
- shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm