| Flutter macOS Embedder |

FlutterResizeSynchronizer.mm
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 "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h"
6 #import "flutter/fml/logging.h"
7
8 #include <atomic>
9
10 @implementation FlutterResizeSynchronizer {
11 std::atomic_bool _inResize;
12 BOOL _shuttingDown;
13 BOOL _didReceiveFrame;
14 CGSize _contentSize;
15 }
16
17 - (void)beginResizeForSize:(CGSize)size notify:(nonnull dispatch_block_t)notify {
18 if (!_didReceiveFrame || _shuttingDown) {
19 notify();
20 return;
21 }
22
23 _inResize = true;
24 _contentSize = CGSizeMake(-1, -1);
25 notify();
26 CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
27 while (true) {
28 if (CGSizeEqualToSize(_contentSize, size) || _shuttingDown) {
29 break;
30 }
31 if (CFAbsoluteTimeGetCurrent() - start > 1.0) {
32 FML_LOG(ERROR) << "Resize timed out.";
33 break;
34 }
35 [FlutterRunLoop.mainRunLoop pollFlutterMessagesOnce];
36 }
37 _inResize = false;
38 }
39
40 - (void)performCommitForSize:(CGSize)size
41 notify:(nonnull dispatch_block_t)notify
42 delay:(NSTimeInterval)delay {
43 if (_inResize) {
44 delay = 0;
45 }
46 [FlutterRunLoop.mainRunLoop
47 performBlock:^{
48 _didReceiveFrame = YES;
49 _contentSize = size;
50 notify();
51 }
52 afterDelay:delay];
53 }
54
55 - (void)shutDown {
56 [FlutterRunLoop.mainRunLoop performBlock:^{
57 _shuttingDown = YES;
58 }];
59 }
60
61 @end
FlutterResizeSynchronizer.h
_shuttingDown
BOOL _shuttingDown
Definition: FlutterResizeSynchronizer.mm:10
_contentSize
CGSize _contentSize
Definition: FlutterResizeSynchronizer.mm:14
_didReceiveFrame
BOOL _didReceiveFrame
Definition: FlutterResizeSynchronizer.mm:13
FlutterResizeSynchronizer
Definition: FlutterResizeSynchronizer.h:17
FlutterRunLoop
Definition: FlutterRunLoop.h:16
-[FlutterRunLoop performBlock:afterDelay:]
void performBlock:afterDelay:(void(^ block)(void),[afterDelay] NSTimeInterval delay)
Definition: FlutterRunLoop.mm:95
-[FlutterRunLoop performBlock:]
void performBlock:(void(^ block)(void))
Definition: FlutterRunLoop.mm:107
-[FlutterRunLoop pollFlutterMessagesOnce]
void pollFlutterMessagesOnce()
Definition: FlutterRunLoop.mm:123