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