| Flutter macOS Embedder |

Classes | Functions
FlutterDisplayLinkTest.mm File Reference
`#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDisplayLink.h"`
`#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterRunLoop.h"`
`#import <AppKit/AppKit.h>`
`#include <numeric>`
`#include "flutter/fml/synchronization/waitable_event.h"`
`#include "flutter/testing/testing.h"`

Go to the source code of this file.

## Classes
class | TestDisplayLinkDelegate
class | FlutterDisplayLinkTest

## Functions
| TEST_F (FlutterDisplayLinkTest, ViewAddedToWindowFirst)
| TEST_F (FlutterDisplayLinkTest, ViewAddedToWindowLater)
| TEST_F (FlutterDisplayLinkTest, ViewRemovedFromWindow)
| TEST_F (FlutterDisplayLinkTest, CVDisplayLinkInterval)

## Function Documentation

## ◆ TEST_F() [1/4]

TEST_F | ( | FlutterDisplayLinkTest | ,
|  | CVDisplayLinkInterval |
| ) |  |

Definition at line 135 of file FlutterDisplayLinkTest.mm.

135 {
136 CVDisplayLinkRef link;
137 CVDisplayLinkCreateWithCGDisplay(CGMainDisplayID(), &link);
138 __block CFTimeInterval last = 0;
139 auto intervals = std::make_shared<std::vector<CFTimeInterval>>();
140 auto event = std::make_shared<fml::AutoResetWaitableEvent>();
141 CVDisplayLinkSetOutputHandler(
142 link, ^(CVDisplayLinkRef displayLink, const CVTimeStamp* inNow,
143 const CVTimeStamp* inOutputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut) {
144 if (last != 0) {
145 intervals->push_back(CACurrentMediaTime() - last);
146 }
147 last = CACurrentMediaTime();
148 if (intervals->size() == 10) {
149 event->Signal();
150 }
151 return 0;
152 });
153
154 CVDisplayLinkStart(link);
155 event->Wait();
156 CVDisplayLinkStop(link);
157 CVDisplayLinkRelease(link);
158 CFTimeInterval average = std::reduce(intervals->begin(), intervals->end()) / intervals->size();
159 CFTimeInterval max = *std::max_element(intervals->begin(), intervals->end());
160 CFTimeInterval min = *std::min_element(intervals->begin(), intervals->end());
161 NSLog(@"CVDisplayLink Interval: Average: %fs, Max: %fs, Min: %fs", average, max, min);
162 }

## ◆ TEST_F() [2/4]

TEST_F | ( | FlutterDisplayLinkTest | ,
|  | ViewAddedToWindowFirst |
| ) |  |

Definition at line 42 of file FlutterDisplayLinkTest.mm.

42 {
43 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
44 styleMask:NSWindowStyleMaskTitled
45 backing:NSBackingStoreNonretained
46 defer:NO];
47 NSView* view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
48 [window setContentView:view];
49
50 __block BOOL signalled = NO;
51
52 TestDisplayLinkDelegate* delegate = [[TestDisplayLinkDelegate alloc]
53 initWithBlock:^(CFTimeInterval timestamp, CFTimeInterval targetTimestamp) {
54 signalled = YES;
55 }];
56
57 FlutterDisplayLink* displayLink = [FlutterDisplayLink displayLinkWithView:view];
58 displayLink.delegate = delegate;
59 displayLink.paused = NO;
60
61 while (!signalled) {
62 [FlutterRunLoop.mainRunLoop pollFlutterMessagesOnce];
63 }
64
65 [displayLink invalidate];
66 }
FlutterDisplayLink
Definition: FlutterDisplayLink.h:19
FlutterDisplayLink::paused
BOOL paused
Pauses and resumes the display link.
Definition: FlutterDisplayLink.h:30
FlutterDisplayLink::delegate
id< FlutterDisplayLinkDelegate > delegate
Definition: FlutterDisplayLink.h:27
FlutterRunLoop
Definition: FlutterRunLoop.h:16
+[FlutterRunLoop mainRunLoop]
FlutterRunLoop * mainRunLoop()
Definition: FlutterRunLoop.mm:118
TestDisplayLinkDelegate
Definition: FlutterDisplayLinkTest.mm:14

References FlutterDisplayLink::delegate, FlutterDisplayLink::displayLinkWithView:, FlutterDisplayLink::invalidate, FlutterDisplayLink::paused, and FlutterRunLoop::pollFlutterMessagesOnce.

## ◆ TEST_F() [3/4]

TEST_F | ( | FlutterDisplayLinkTest | ,
|  | ViewAddedToWindowLater |
| ) |  |

Definition at line 68 of file FlutterDisplayLinkTest.mm.

68 {
69 NSView* view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
70
71 __block BOOL signalled = NO;
72
73 TestDisplayLinkDelegate* delegate = [[TestDisplayLinkDelegate alloc]
74 initWithBlock:^(CFTimeInterval timestamp, CFTimeInterval targetTimestamp) {
75 signalled = YES;
76 }];
77
78 FlutterDisplayLink* displayLink = [FlutterDisplayLink displayLinkWithView:view];
79 displayLink.delegate = delegate;
80 displayLink.paused = NO;
81
82 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
83 styleMask:NSWindowStyleMaskTitled
84 backing:NSBackingStoreNonretained
85 defer:NO];
86 [window setContentView:view];
87
88 while (!signalled) {
89 [FlutterRunLoop.mainRunLoop pollFlutterMessagesOnce];
90 }
91
92 [displayLink invalidate];
93 }

References FlutterDisplayLink::delegate, FlutterDisplayLink::displayLinkWithView:, FlutterDisplayLink::invalidate, FlutterDisplayLink::paused, and FlutterRunLoop::pollFlutterMessagesOnce.

## ◆ TEST_F() [4/4]

TEST_F | ( | FlutterDisplayLinkTest | ,
|  | ViewRemovedFromWindow |
| ) |  |

Definition at line 95 of file FlutterDisplayLinkTest.mm.

95 {
96 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
97 styleMask:NSWindowStyleMaskTitled
98 backing:NSBackingStoreNonretained
99 defer:NO];
100 NSView* view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
101 [window setContentView:view];
102
103 __block BOOL signalled = NO;
104
105 TestDisplayLinkDelegate* delegate = [[TestDisplayLinkDelegate alloc]
106 initWithBlock:^(CFTimeInterval timestamp, CFTimeInterval targetTimestamp) {
107 signalled = YES;
108 }];
109
110 FlutterDisplayLink* displayLink = [FlutterDisplayLink displayLinkWithView:view];
111 displayLink.delegate = delegate;
112 displayLink.paused = NO;
113
114 while (!signalled) {
115 [FlutterRunLoop.mainRunLoop pollFlutterMessagesOnce];
116 }
117 displayLink.paused = YES;
118
119 signalled = false;
120
121 displayLink.paused = NO;
122
123 [window setContentView:nil];
124
125 CFTimeInterval start = CACurrentMediaTime();
126 while (CACurrentMediaTime() < start + 0.1) {
127 [FlutterRunLoop.mainRunLoop pollFlutterMessagesOnce];
128 }
129
130 EXPECT_FALSE(signalled);
131
132 [displayLink invalidate];
133 }

References FlutterDisplayLink::delegate, FlutterDisplayLink::displayLinkWithView:, FlutterDisplayLink::invalidate, FlutterDisplayLink::paused, and FlutterRunLoop::pollFlutterMessagesOnce.