gaaclarke 3d8fa621c1
[Reland3] Implements UISceneDelegate dynamically w/ FlutterLaunchEngine (#169276) (#169365)
## **BREAKING CHANGE**

Adopting Apple's UISceneDelegate protocol shifts the initialization
order of apps. For the common cases we've made sure they will work
without change. The one case that will require a change is any app that
in `-[UIApplicateDelegate didFinishLaunchingWithOptions:]` assumes that
`UIApplicationDelegate.window.rootViewController` is a
`FlutterViewController` instance. Users should follow the [migration
guide](https://docs.google.com/document/d/16WsqYbANmhupw-gxGPQPZ9B3yz1YBIviS-N1UyIQNSE/edit?tab=t.0#heading=h.txry2otwqko3)
to update that usage.

## Changes since revert
It's been rebased onto the FlutterPluginRegistrant PR which was used for
migration. The dynamic selection of the UISceneDelegate has been
removed, instead there is a flutter tool migration to the Info.plist.

## Description
fixes: https://github.com/flutter/flutter/issues/167267

design doc:


https://docs.google.com/document/d/1ZfcQOs-UKRa9jsFG84-MTFeibZTLKCvPQLxF2eskx44/edit?tab=t.0

relands https://github.com/flutter/flutter/pull/168396 
relands https://github.com/flutter/flutter/pull/168914
relands https://github.com/flutter/flutter/pull/169276

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
2025-05-30 20:57:40 +00:00

76 lines
2.8 KiB
Objective-C

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "TextureViewController.h"
#import "AppDelegate.h"
@interface TextureViewController () <FlutterTexture>
@property (nonatomic, assign) uint64_t textureId;
@property (nonatomic, assign) int framesProduced;
@property (nonatomic, assign) int framesConsumed;
@property (nonatomic, assign) int lastFrameConsumed;
@property (nonatomic, assign) double startTime;
@property (nonatomic, assign) double endTime;
@property (nonatomic, assign) double frameRate;
@property (nonatomic, assign) double frameStartTime;
@property (nonatomic, strong) NSTimer* timer;
- (void)tick:(NSTimer*)timer;
@end
@implementation TextureViewController
- (void)awakeFromNib {
[super awakeFromNib];
FlutterMethodChannel* channel =
[FlutterMethodChannel methodChannelWithName:@"texture"
binaryMessenger:self.binaryMessenger];
[channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
if ([@"start" isEqualToString:call.method]) {
_framesProduced = 0;
_framesConsumed = 0;
_frameRate = 1.0 / [(NSNumber*) call.arguments intValue];
_timer = [NSTimer scheduledTimerWithTimeInterval:_frameRate
target:self
selector:@selector(tick:)
userInfo:nil
repeats:YES];
_startTime = [[NSDate date] timeIntervalSince1970];
result(nil);
} else if ([@"stop" isEqualToString:call.method]) {
[_timer invalidate];
_endTime = [[NSDate date] timeIntervalSince1970];
result(nil);
} else if ([@"getProducedFrameRate" isEqualToString:call.method]) {
result(@(_framesProduced / (_endTime - _startTime)));
} else if ([@"getConsumedFrameRate" isEqualToString:call.method]) {
result(@(_framesConsumed / (_endTime - _startTime)));
} else {
result(FlutterMethodNotImplemented);
}
}];
_textureId = [self registerTexture:self];
}
- (void)tick:(NSTimer*)timer {
[self textureFrameAvailable:_textureId];
_frameStartTime = [[NSDate date] timeIntervalSince1970];
// We just pretend to be producing a frame.
_framesProduced++;
}
- (CVPixelBufferRef)copyPixelBuffer {
double now = [[NSDate date] timeIntervalSince1970];
if (now < _frameStartTime
|| _frameStartTime + _frameRate < now
|| _framesProduced == _lastFrameConsumed) return nil;
_framesConsumed++;
_lastFrameConsumed = _framesProduced;
// We just pretend to be handing over the produced frame to the consumer.
return nil;
}
@end