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