Flutter Engine
The Flutter Engine
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
28
29/*
30 * Schedules the block on the platform thread and blocks until the block is executed.
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 withBlock:(nonnull dispatch_block_t)block;
35
36@end
37
38/**
39 * FlutterSurfaceManager is responsible for providing and presenting Core Animation render
40 * surfaces and managing sublayers.
41 *
42 * Owned by `FlutterView`.
43 */
44@interface FlutterSurfaceManager : NSObject
45
46/**
47 * Initializes and returns a surface manager that renders to a child layer (referred to as the
48 * content layer) of the containing layer.
49 */
50- (nullable instancetype)initWithDevice:(nonnull id<MTLDevice>)device
51 commandQueue:(nonnull id<MTLCommandQueue>)commandQueue
52 layer:(nonnull CALayer*)containingLayer
53 delegate:(nonnull id<FlutterSurfaceManagerDelegate>)delegate;
54
55/**
56 * Returns a back buffer surface of the given size to which Flutter can render content.
57 * A cached surface will be returned if available; otherwise a new one will be created.
58 *
59 * Must be called on raster thread.
60 */
61- (nonnull FlutterSurface*)surfaceForSize:(CGSize)size;
62
63/**
64 * Sets the provided surfaces as contents of FlutterView. Will create, update and
65 * remove sublayers as needed.
66 *
67 * Must be called on raster thread. This will schedule a commit on the platform thread and block the
68 * raster thread until the commit is done. The `notify` block will be invoked on the platform thread
69 * and can be used to perform additional work, such as mutating platform views. It is guaranteed be
70 * called in the same CATransaction.
71 */
72- (void)presentSurfaces:(nonnull NSArray<FlutterSurfacePresentInfo*>*)surfaces
73 atTime:(CFTimeInterval)presentationTime
74 notify:(nullable dispatch_block_t)notify;
75
76@end
77
78/**
79 * Cache of back buffers to prevent unnecessary IOSurface allocations.
80 */
81@interface FlutterBackBufferCache : NSObject
82
83/**
84 * Removes surface with given size from cache (if available) and returns it.
85 */
86- (nullable FlutterSurface*)removeSurfaceForSize:(CGSize)size;
87
88/**
89 * Removes all cached surfaces replacing them with new ones.
90 */
91- (void)returnSurfaces:(nonnull NSArray<FlutterSurface*>*)surfaces;
92
93/**
94 * Returns number of surfaces currently in cache. Used for tests.
95 */
96- (NSUInteger)count;
97
98@end
99
100/**
101 * Interface to internal properties used for testing.
102 */
104
105@property(readonly, nonatomic, nonnull) FlutterBackBufferCache* backBufferCache;
106@property(readonly, nonatomic, nonnull) NSArray<FlutterSurface*>* frontSurfaces;
107@property(readonly, nonatomic, nonnull) NSArray<CALayer*>* layers;
108
109@end
110
111#endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERSURFACEMANAGER_H_
int count
Definition: FontMgrTest.cpp:50
std::vector< FlutterRect > paintRegion