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