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 
6 #import "flutter/fml/logging.h"
7 
8 #include <atomic>
9 
10 @implementation FlutterResizeSynchronizer {
11  std::atomic_bool _inResize;
14  CGSize _contentSize;
15 }
16 
17 - (void)beginResizeForSize:(CGSize)size notify:(nonnull dispatch_block_t)notify {
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  }
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
BOOL _shuttingDown
CGSize _contentSize
BOOL _didReceiveFrame
void performBlock:afterDelay:(void(^ block)(void),[afterDelay] NSTimeInterval delay)
void performBlock:(void(^ block)(void))
void pollFlutterMessagesOnce()