Flutter macOS Embedder
FlutterThreadSynchronizer.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_FLUTTERTHREADSYNCHRONIZER_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERTHREADSYNCHRONIZER_H_
7 
8 #import <Cocoa/Cocoa.h>
9 
11 
12 /**
13  * Takes care of synchronization between raster and platform thread.
14  *
15  * All methods of this class must be called from the platform thread,
16  * except for performCommitForView:size:notify:.
17  */
18 @interface FlutterThreadSynchronizer : NSObject
19 
20 /**
21  * Creates a FlutterThreadSynchronizer that uses the OS main thread as the
22  * platform thread.
23  */
24 - (nullable instancetype)init;
25 
26 /**
27  * Blocks until all views have a commit with their given sizes (or empty) is requested.
28  */
29 - (void)beginResizeForView:(FlutterViewIdentifier)viewIdentifier
30  size:(CGSize)size
31  notify:(nonnull dispatch_block_t)notify;
32 
33 /**
34  * Called from raster thread. Schedules the given block on platform thread
35  * and blocks until it is performed.
36  *
37  * If platform thread is blocked in `beginResize:` for given size (or size is empty),
38  * unblocks platform thread.
39  *
40  * The notify block is guaranteed to be called within a core animation transaction.
41  */
42 - (void)performCommitForView:(FlutterViewIdentifier)viewIdentifier
43  size:(CGSize)size
44  notify:(nonnull dispatch_block_t)notify;
45 
46 /**
47  * Schedules the given block to be performed on the platform thread.
48  * The block will be performed even if the platform thread is blocked waiting
49  * for a commit.
50  */
51 - (void)performOnPlatformThread:(nonnull dispatch_block_t)block;
52 
53 /**
54  * Requests the synchronizer to track another view.
55  *
56  * A view must be registered before calling begineResizeForView: or
57  * performCommitForView:. It is typically done when the view controller is
58  * created.
59  */
60 - (void)registerView:(FlutterViewIdentifier)viewIdentifier;
61 
62 /**
63  * Requests the synchronizer to no longer track a view.
64  *
65  * It is typically done when the view controller is destroyed.
66  */
67 - (void)deregisterView:(FlutterViewIdentifier)viewIdentifier;
68 
69 /**
70  * Called when the engine shuts down.
71  *
72  * Prevents any further synchronization and no longer blocks any threads.
73  */
74 - (void)shutdown;
75 
76 @end
77 
79 
80 /**
81  * Creates a FlutterThreadSynchronizer that uses the specified queue as the
82  * platform thread.
83  */
84 - (nullable instancetype)initWithMainQueue:(nonnull dispatch_queue_t)queue;
85 
86 /**
87  * Blocks current thread until the mutex is available, then return whether the
88  * synchronizer is waiting for a correct commit during resizing.
89  *
90  * After calling an operation of the thread synchronizer, call this method,
91  * and when it returns, the thread synchronizer can be at one of the following 3
92  * states:
93  *
94  * 1. The operation has not started at all (with a return value FALSE.)
95  * 2. The operation has ended (with a return value FALSE.)
96  * 3. beginResizeForView: is in progress, waiting (with a return value TRUE.)
97  *
98  * By eliminating the 1st case (such as using the notify callback), we can use
99  * this return value to decide whether the synchronizer is in case 2 or case 3,
100  * that is whether the resizing is blocked by a mismatching commit.
101  */
102 - (BOOL)isWaitingWhenMutexIsAvailable;
103 
104 /**
105  * Blocks current thread until there is frame available.
106  * Used in FlutterEngineTest.
107  */
108 - (void)blockUntilFrameAvailable;
109 
110 @end
111 
112 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERTHREADSYNCHRONIZER_H_
-[FlutterThreadSynchronizer init]
nullable instancetype init()
Definition: FlutterThreadSynchronizer.mm:47
FlutterThreadSynchronizer(TestUtils)
Definition: FlutterThreadSynchronizer.h:78
FlutterThreadSynchronizer
Definition: FlutterThreadSynchronizer.h:18
FlutterViewIdentifier
int64_t FlutterViewIdentifier
Definition: FlutterViewController.h:21
-[FlutterThreadSynchronizer shutdown]
void shutdown()
Definition: FlutterThreadSynchronizer.mm:192
FlutterViewController.h