mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[iOS] Fixes DisplayLinkManager leaks (#22194)
This commit is contained in:
parent
5cf3eaed11
commit
fd9a079ac1
@ -635,7 +635,7 @@ static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSS
|
||||
}
|
||||
|
||||
- (void)initializeDisplays {
|
||||
double refresh_rate = [[[DisplayLinkManager alloc] init] displayRefreshRate];
|
||||
double refresh_rate = [DisplayLinkManager displayRefreshRate];
|
||||
auto display = flutter::Display(refresh_rate);
|
||||
_shell->OnDisplayUpdates(flutter::DisplayUpdateType::kStartup, {display});
|
||||
}
|
||||
|
||||
@ -12,8 +12,6 @@
|
||||
|
||||
@interface DisplayLinkManager : NSObject
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief The display refresh rate used for reporting purposes. The engine does not care
|
||||
/// about this for frame scheduling. It is only used by tools for instrumentation. The
|
||||
@ -23,7 +21,7 @@
|
||||
///
|
||||
/// @return The refresh rate in frames per second.
|
||||
///
|
||||
- (double)displayRefreshRate;
|
||||
+ (double)displayRefreshRate;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@ -91,26 +91,16 @@ void VsyncWaiterIOS::AwaitVSync() {
|
||||
|
||||
@end
|
||||
|
||||
@implementation DisplayLinkManager {
|
||||
fml::scoped_nsobject<CADisplayLink> display_link_;
|
||||
}
|
||||
@implementation DisplayLinkManager
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
display_link_ = fml::scoped_nsobject<CADisplayLink> {
|
||||
[[CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLink:)] retain]
|
||||
};
|
||||
display_link_.get().paused = YES;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (double)displayRefreshRate {
|
||||
+ (double)displayRefreshRate {
|
||||
if (@available(iOS 10.3, *)) {
|
||||
auto preferredFPS = display_link_.get().preferredFramesPerSecond; // iOS 10.0
|
||||
fml::scoped_nsobject<CADisplayLink> display_link = fml::scoped_nsobject<CADisplayLink> {
|
||||
[[CADisplayLink displayLinkWithTarget:[[DisplayLinkManager new] autorelease]
|
||||
selector:@selector(onDisplayLink:)] retain]
|
||||
};
|
||||
display_link.get().paused = YES;
|
||||
auto preferredFPS = display_link.get().preferredFramesPerSecond; // iOS 10.0
|
||||
|
||||
// From Docs:
|
||||
// The default value for preferredFramesPerSecond is 0. When this value is 0, the preferred
|
||||
@ -131,10 +121,4 @@ void VsyncWaiterIOS::AwaitVSync() {
|
||||
// no-op.
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[display_link_.get() invalidate];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user