Flutter macOS Embedder
FlutterSurfaceManager.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #import <Cocoa/Cocoa.h>
6 #import <QuartzCore/QuartzCore.h>
7 
8 #include <vector>
9 
11 
12 /**
13  * Surface with additional properties needed for presenting.
14  */
15 @interface FlutterSurfacePresentInfo : NSObject
16 
17 @property(readwrite, strong, nonatomic, nonnull) FlutterSurface* surface;
18 @property(readwrite, nonatomic) CGPoint offset;
19 @property(readwrite, nonatomic) size_t zIndex;
20 @property(readwrite, nonatomic) std::vector<FlutterRect> paintRegion;
21 
22 @end
23 
24 @protocol FlutterSurfaceManagerDelegate <NSObject>
25 
26 /*
27  * Schedules the block on the platform thread and blocks until the block is executed.
28  * Provided `frameSize` is used to unblock the platform thread if it waits for
29  * a certain frame size during resizing.
30  */
31 - (void)onPresent:(CGSize)frameSize withBlock:(nonnull dispatch_block_t)block;
32 
33 @end
34 
35 /**
36  * FlutterSurfaceManager is responsible for providing and presenting Core Animation render
37  * surfaces and managing sublayers.
38  *
39  * Owned by `FlutterView`.
40  */
41 @interface FlutterSurfaceManager : NSObject
42 
43 /**
44  * Initializes and returns a surface manager that renders to a child layer (referred to as the
45  * content layer) of the containing layer.
46  */
47 - (nullable instancetype)initWithDevice:(nonnull id<MTLDevice>)device
48  commandQueue:(nonnull id<MTLCommandQueue>)commandQueue
49  layer:(nonnull CALayer*)containingLayer
50  delegate:(nonnull id<FlutterSurfaceManagerDelegate>)delegate;
51 
52 /**
53  * Returns a back buffer surface of the given size to which Flutter can render content.
54  * A cached surface will be returned if available; otherwise a new one will be created.
55  *
56  * Must be called on raster thread.
57  */
58 - (nonnull FlutterSurface*)surfaceForSize:(CGSize)size;
59 
60 /**
61  * Sets the provided surfaces as contents of FlutterView. Will create, update and
62  * remove sublayers as needed.
63  *
64  * Must be called on raster thread. This will schedule a commit on the platform thread and block the
65  * raster thread until the commit is done. The `notify` block will be invoked on the platform thread
66  * and can be used to perform additional work, such as mutating platform views. It is guaranteed be
67  * called in the same CATransaction.
68  */
69 - (void)present:(nonnull NSArray<FlutterSurfacePresentInfo*>*)surfaces
70  notify:(nullable dispatch_block_t)notify;
71 
72 @end
73 
74 /**
75  * Cache of back buffers to prevent unnecessary IOSurface allocations.
76  */
77 @interface FlutterBackBufferCache : NSObject
78 
79 /**
80  * Removes surface with given size from cache (if available) and returns it.
81  */
82 - (nullable FlutterSurface*)removeSurfaceForSize:(CGSize)size;
83 
84 /**
85  * Removes all cached surfaces replacing them with new ones.
86  */
87 - (void)replaceSurfaces:(nonnull NSArray<FlutterSurface*>*)surfaces;
88 
89 /**
90  * Returns number of surfaces currently in cache. Used for tests.
91  */
92 - (NSUInteger)count;
93 
94 @end
95 
96 /**
97  * Interface to internal properties used for testing.
98  */
100 
101 @property(readonly, nonatomic, nonnull) FlutterBackBufferCache* backBufferCache;
102 @property(readonly, nonatomic, nonnull) NSArray<FlutterSurface*>* frontSurfaces;
103 @property(readonly, nonatomic, nonnull) NSArray<CALayer*>* layers;
104 
105 @end
-[FlutterBackBufferCache count]
NSUInteger count()
Definition: FlutterSurfaceManager.mm:277
FlutterSurfaceManager
Definition: FlutterSurfaceManager.h:41
FlutterBackBufferCache
Definition: FlutterSurfaceManager.h:77
FlutterSurface.h
FlutterSurface
Definition: FlutterSurface.h:13
FlutterSurfaceManagerDelegate-p
Definition: FlutterSurfaceManager.h:24
FlutterSurfacePresentInfo::surface
FlutterSurface * surface
Definition: FlutterSurfaceManager.h:17
FlutterSurfacePresentInfo::offset
CGPoint offset
Definition: FlutterSurfaceManager.h:18
FlutterSurfacePresentInfo
Definition: FlutterSurfaceManager.h:15
FlutterSurfacePresentInfo::zIndex
size_t zIndex
Definition: FlutterSurfaceManager.h:19
FlutterSurfacePresentInfo::paintRegion
std::vector< FlutterRect > paintRegion
Definition: FlutterSurfaceManager.h:20
FlutterSurfaceManager(Private)
Definition: FlutterSurfaceManager.h:99