optimize resolution update handling logic
This commit is contained in:
1 parent
f62a405979
commit
fb04850ae8
4 files changed
+56
-81
No files matched your search
@@ -14,11 +14,11 @@
|
|||||||
@implementation CustomEdgeSlideGestureRecognizer
|
@implementation CustomEdgeSlideGestureRecognizer
|
||||||
UITouch* capturedUITouch;
|
UITouch* capturedUITouch;
|
||||||
CGFloat startPointX;
|
CGFloat startPointX;
|
||||||
static CGFloat screenWidthInPoints;
|
//static CGFloat screenWidthInPoints;
|
||||||
|
|
||||||
- (instancetype)initWithTarget:(nullable id)target action:(nullable SEL)action {
|
- (instancetype)initWithTarget:(nullable id)target action:(nullable SEL)action {
|
||||||
self = [super initWithTarget:target action:action];
|
self = [super initWithTarget:target action:action];
|
||||||
screenWidthInPoints = CGRectGetWidth([UIApplication.sharedApplication.windows.firstObject.screen bounds]); // Get the screen's bounds (in points)
|
// screenWidthInPoints = CGRectGetWidth([UIApplication.sharedApplication.windows.firstObject.screen bounds]); // Get the screen's bounds (in points)
|
||||||
_immediateTriggering = false;
|
_immediateTriggering = false;
|
||||||
_EDGE_TOLERANCE = 10.0f;
|
_EDGE_TOLERANCE = 10.0f;
|
||||||
return self;
|
return self;
|
||||||
@@ -29,6 +29,7 @@ static CGFloat screenWidthInPoints;
|
|||||||
UITouch *touch = [touches anyObject];
|
UITouch *touch = [touches anyObject];
|
||||||
capturedUITouch = touch;
|
capturedUITouch = touch;
|
||||||
startPointX = [capturedUITouch locationInView:self.view].x;
|
startPointX = [capturedUITouch locationInView:self.view].x;
|
||||||
|
CGFloat screenWidthInPoints = self.view.frame.size.width;
|
||||||
if(_immediateTriggering){
|
if(_immediateTriggering){
|
||||||
|
|
||||||
if(self.edges & UIRectEdgeLeft){
|
if(self.edges & UIRectEdgeLeft){
|
||||||
@@ -52,6 +53,7 @@ static CGFloat screenWidthInPoints;
|
|||||||
|
|
||||||
if([touches containsObject:capturedUITouch]){
|
if([touches containsObject:capturedUITouch]){
|
||||||
CGFloat _endPointX = [capturedUITouch locationInView:self.view].x;
|
CGFloat _endPointX = [capturedUITouch locationInView:self.view].x;
|
||||||
|
CGFloat screenWidthInPoints = self.view.frame.size.width;
|
||||||
CGFloat normalizedGestureDistance = fabs(_endPointX - startPointX)/screenWidthInPoints;
|
CGFloat normalizedGestureDistance = fabs(_endPointX - startPointX)/screenWidthInPoints;
|
||||||
|
|
||||||
if(self.edges & UIRectEdgeLeft){
|
if(self.edges & UIRectEdgeLeft){
|
||||||
|
|||||||
@@ -34,5 +34,6 @@
|
|||||||
-(void)reloadStreamConfig;
|
-(void)reloadStreamConfig;
|
||||||
-(bool)isIPhonePortrait;
|
-(bool)isIPhonePortrait;
|
||||||
#endif
|
#endif
|
||||||
|
- (void)fillResolutionTable:(CGSize*)resolutionTable externalDisplayMode:(NSInteger)externalDisplayMode;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -1599,50 +1599,56 @@ static NSMutableSet* hostList;
|
|||||||
// });
|
// });
|
||||||
//}
|
//}
|
||||||
|
|
||||||
-(void) updateResolutionAccordingly {
|
-(void) fillResolutionTable:(CGSize*)resolutionTable externalDisplayMode:(NSInteger)externalDisplayMode{
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
UIWindow *window = self.view.window;
|
||||||
Settings *currentSettings = [dataMan retrieveSettings];
|
NSLog(@" window %@", window);
|
||||||
UIWindow *window = UIApplication.sharedApplication.windows.firstObject;
|
|
||||||
CGFloat screenScale = window.screen.scale;
|
|
||||||
CGFloat appWindowWidth = CGRectGetWidth(window.frame) * screenScale;
|
|
||||||
CGFloat appWindowHeight = CGRectGetHeight(window.frame) * screenScale;
|
|
||||||
CGFloat screenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]);
|
|
||||||
CGFloat screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]);
|
|
||||||
|
|
||||||
if(currentSettings.externalDisplayMode.intValue == 1 && UIScreen.screens.count > 1){
|
CGFloat screenScale = window.screen.scale;
|
||||||
|
CGFloat safeAreaWidth = (window.frame.size.width - window.safeAreaInsets.left - window.safeAreaInsets.right) * screenScale;
|
||||||
|
CGFloat appWindowWidth = window.frame.size.width * screenScale;
|
||||||
|
CGFloat appWindowHeight = window.frame.size.height * screenScale;
|
||||||
|
|
||||||
|
if(externalDisplayMode == 1 && UIScreen.screens.count > 1){
|
||||||
CGRect bounds = [UIScreen.screens.lastObject bounds];
|
CGRect bounds = [UIScreen.screens.lastObject bounds];
|
||||||
screenScale = [UIScreen.screens.lastObject scale];
|
screenScale = [UIScreen.screens.lastObject scale];
|
||||||
appWindowWidth = bounds.size.width * screenScale;
|
appWindowWidth = bounds.size.width * screenScale;
|
||||||
appWindowHeight = bounds.size.height * screenScale;
|
appWindowHeight = bounds.size.height * screenScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needSwap = false;
|
bool needSwapWidthAndHeight = appWindowWidth < appWindowHeight;
|
||||||
|
|
||||||
if([self isFullScreenRequired]){ // if force fullscreen is enabled in app bundle, we use screen bounds to tell if a swap between width & height is needed
|
resolutionTable[0] = CGSizeMake(1280, 720);
|
||||||
needSwap = (currentSettings.width.floatValue - currentSettings.height.floatValue) * (screenWidthInPoints - screenHeightInPoints) < 0; //update the current resolution accordingly
|
resolutionTable[1] = CGSizeMake(1920, 1080);
|
||||||
NSLog(@"need to swap width & height (non-app window mode): %d", needSwap);
|
resolutionTable[2] = CGSizeMake(3840, 2160);
|
||||||
if(needSwap){
|
|
||||||
CGFloat tmpLength = currentSettings.width.floatValue;
|
for(uint8_t i=0;i<6;i++){
|
||||||
currentSettings.width = @(currentSettings.height.floatValue);
|
CGFloat longSideLen = resolutionTable[i].height > resolutionTable[i].width ? resolutionTable[i].height : resolutionTable[i].width;
|
||||||
currentSettings.height = @(tmpLength);
|
CGFloat shortSideLen = resolutionTable[i].height < resolutionTable[i].width ? resolutionTable[i].height : resolutionTable[i].width;
|
||||||
}
|
if(needSwapWidthAndHeight) resolutionTable[i] = CGSizeMake(shortSideLen, longSideLen);
|
||||||
|
else resolutionTable[i] = CGSizeMake(longSideLen, shortSideLen);
|
||||||
}
|
}
|
||||||
else{// if force fullscreen is disabled in app bundle, we use appWindowSize to directly update or to get if we need a swap
|
|
||||||
if(currentSettings.resolutionSelected.intValue == 5){ // app window res, previous fullscreen, update resolution directly
|
// add app window resolution and not swap width and height
|
||||||
currentSettings.width = @(appWindowWidth);
|
resolutionTable[3] = CGSizeMake(safeAreaWidth, appWindowHeight);
|
||||||
currentSettings.height = @(appWindowHeight);
|
resolutionTable[4] = CGSizeMake(appWindowWidth, appWindowHeight);
|
||||||
NSLog(@"Directly Update app window resolution: %f, %f", appWindowWidth, appWindowHeight);
|
}
|
||||||
}
|
|
||||||
else if(currentSettings.resolutionSelected.intValue){
|
-(void) updateResolutionAccordingly {
|
||||||
needSwap = (currentSettings.width.floatValue - currentSettings.height.floatValue) * (appWindowWidth - appWindowHeight) < 0;
|
DataManager* dataMan = [[DataManager alloc] init];
|
||||||
if(needSwap){
|
Settings *currentSettings = [dataMan retrieveSettings];
|
||||||
CGFloat tmpLength = currentSettings.width.floatValue;
|
|
||||||
currentSettings.width = @(currentSettings.height.floatValue);
|
CGSize tempResolutionTable[6] = {0};
|
||||||
currentSettings.height = @(tmpLength);
|
tempResolutionTable[5] = CGSizeMake(currentSettings.width.intValue, currentSettings.height.intValue);
|
||||||
NSLog(@"Swap resolution width & height");
|
[self fillResolutionTable:tempResolutionTable externalDisplayMode:currentSettings.externalDisplayMode.intValue];
|
||||||
}
|
|
||||||
}
|
int selectedIndex = currentSettings.resolutionSelected.intValue;
|
||||||
|
if (selectedIndex >= 0 && selectedIndex < 6) {
|
||||||
|
CGSize selectedSize = tempResolutionTable[selectedIndex];
|
||||||
|
currentSettings.width = @(selectedSize.width);
|
||||||
|
currentSettings.height = @(selectedSize.height);
|
||||||
|
NSLog(@"Updated resolution to: %@ x %@", currentSettings.width, currentSettings.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
[dataMan saveData];
|
[dataMan saveData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -250,19 +250,8 @@ CGSize resolutionTable[RESOLUTION_TABLE_SIZE];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL isCustomResolution(CGSize res) {
|
BOOL isCustomResolution(int resolutionSelected) {
|
||||||
if (res.width == 0 && res.height == 0) {
|
return resolutionSelected == RESOLUTION_TABLE_CUSTOM_INDEX;
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < RESOLUTION_TABLE_CUSTOM_INDEX; i++) {
|
|
||||||
NSLog(@"customRes: %f, %f, isrl: %f, %f", res.width, res.height, resolutionTable[i].width, resolutionTable[i].height);
|
|
||||||
if ((res.width == resolutionTable[i].width && res.height == resolutionTable[i].height) || (res.height == resolutionTable[i].width && res.width == resolutionTable[i].height)) {
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (bool)isLandscapeNow {
|
+ (bool)isLandscapeNow {
|
||||||
@@ -287,31 +276,9 @@ BOOL isCustomResolution(CGSize res) {
|
|||||||
- (void)updateResolutionTable{
|
- (void)updateResolutionTable{
|
||||||
if(self.mainFrameViewController.settingsExpandedInStreamView) return;
|
if(self.mainFrameViewController.settingsExpandedInStreamView) return;
|
||||||
|
|
||||||
UIWindow *window = self.view.window;
|
NSInteger externalDisplayMode = [self.externalDisplayModeSelector selectedSegmentIndex];
|
||||||
NSLog(@" window %@", window);
|
// 调用主界面方法统一填充 resolutionTable
|
||||||
|
[self.mainFrameViewController fillResolutionTable:resolutionTable externalDisplayMode:externalDisplayMode];
|
||||||
CGFloat screenScale = window.screen.scale;
|
|
||||||
CGFloat safeAreaWidth = (window.frame.size.width - window.safeAreaInsets.left - window.safeAreaInsets.right) * screenScale;
|
|
||||||
CGFloat appWindowWidth = window.frame.size.width * screenScale;
|
|
||||||
CGFloat appWindowHeight = window.frame.size.height * screenScale;
|
|
||||||
if([self isAirPlayEnabled] && UIScreen.screens.count > 1){
|
|
||||||
CGRect bounds = [UIScreen.screens.lastObject bounds];
|
|
||||||
screenScale = [UIScreen.screens.lastObject scale];
|
|
||||||
appWindowWidth = bounds.size.width * screenScale;
|
|
||||||
appWindowHeight = bounds.size.height * screenScale;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool needSwapWidthAndHeight = appWindowWidth < appWindowHeight;
|
|
||||||
|
|
||||||
for(uint8_t i=0;i<6;i++){
|
|
||||||
CGFloat longSideLen = resolutionTable[i].height > resolutionTable[i].width ? resolutionTable[i].height : resolutionTable[i].width;
|
|
||||||
CGFloat shortSideLen = resolutionTable[i].height < resolutionTable[i].width ? resolutionTable[i].height : resolutionTable[i].width;
|
|
||||||
if(needSwapWidthAndHeight) resolutionTable[i] = CGSizeMake(shortSideLen, longSideLen);
|
|
||||||
else resolutionTable[i] = CGSizeMake(longSideLen, shortSideLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
resolutionTable[3] = CGSizeMake(safeAreaWidth, appWindowHeight);
|
|
||||||
resolutionTable[4] = CGSizeMake(appWindowWidth, appWindowHeight);
|
|
||||||
|
|
||||||
[self updateResolutionDisplayLabel];
|
[self updateResolutionDisplayLabel];
|
||||||
}
|
}
|
||||||
@@ -340,8 +307,8 @@ BOOL isCustomResolution(CGSize res) {
|
|||||||
DataManager* dataMan = [[DataManager alloc] init];
|
DataManager* dataMan = [[DataManager alloc] init];
|
||||||
TemporarySettings *currentSettings = [dataMan getSettings];
|
TemporarySettings *currentSettings = [dataMan getSettings];
|
||||||
|
|
||||||
CGSize currentResolution = CGSizeMake(currentSettings.width.intValue, currentSettings.height.intValue);
|
//CGSize currentResolution = CGSizeMake(currentSettings.width.intValue, currentSettings.height.intValue);
|
||||||
[self.customResolutionSwitch setOn: isCustomResolution(currentResolution)];
|
[self.customResolutionSwitch setOn: isCustomResolution(currentSettings.resolutionSelected.intValue)];
|
||||||
[self.resolutionSelector setEnabled:!self.customResolutionSwitch.isOn];
|
[self.resolutionSelector setEnabled:!self.customResolutionSwitch.isOn];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1290,12 +1257,8 @@ BOOL isCustomResolution(CGSize res) {
|
|||||||
[self.resolutionSelector removeSegmentAtIndex:0 animated:NO]; // remove 360p
|
[self.resolutionSelector removeSegmentAtIndex:0 animated:NO]; // remove 360p
|
||||||
[self.resolutionSelector removeSegmentAtIndex:5 animated:NO]; // remove custom segment
|
[self.resolutionSelector removeSegmentAtIndex:5 animated:NO]; // remove custom segment
|
||||||
|
|
||||||
resolutionTable[0] = CGSizeMake(1280, 720);
|
|
||||||
resolutionTable[1] = CGSizeMake(1920, 1080);
|
|
||||||
resolutionTable[2] = CGSizeMake(3840, 2160);
|
|
||||||
resolutionTable[3] = CGSizeMake(safeAreaWidth, fullScreenHeight);
|
|
||||||
resolutionTable[4] = CGSizeMake(fullScreenWidth, fullScreenHeight);
|
|
||||||
resolutionTable[5] = CGSizeMake([currentSettings.width integerValue], [currentSettings.height integerValue]); // custom initial value
|
resolutionTable[5] = CGSizeMake([currentSettings.width integerValue], [currentSettings.height integerValue]); // custom initial value
|
||||||
|
[self updateResolutionTable];
|
||||||
|
|
||||||
|
|
||||||
NSInteger framerate;
|
NSInteger framerate;
|
||||||
@@ -2135,6 +2098,9 @@ BOOL isCustomResolution(CGSize res) {
|
|||||||
BOOL enableHdr = self.hdrSwitch.isOn;
|
BOOL enableHdr = self.hdrSwitch.isOn;
|
||||||
BOOL unlockDisplayOrientation = [self.unlockDisplayOrientationSelector selectedSegmentIndex] == 1;
|
BOOL unlockDisplayOrientation = [self.unlockDisplayOrientationSelector selectedSegmentIndex] == 1;
|
||||||
NSInteger resolutionSelected = [self.resolutionSelector selectedSegmentIndex];
|
NSInteger resolutionSelected = [self.resolutionSelector selectedSegmentIndex];
|
||||||
|
if (self.customResolutionSwitch.isOn) {
|
||||||
|
resolutionSelected = RESOLUTION_TABLE_CUSTOM_INDEX;
|
||||||
|
}
|
||||||
NSInteger externalDisplayMode = [self.externalDisplayModeSelector selectedSegmentIndex];
|
NSInteger externalDisplayMode = [self.externalDisplayModeSelector selectedSegmentIndex];
|
||||||
NSInteger localMousePointerMode = [self.localMousePointerModeSelector selectedSegmentIndex];
|
NSInteger localMousePointerMode = [self.localMousePointerModeSelector selectedSegmentIndex];
|
||||||
NSInteger backgroundSessionTimer = self.backgroundSessionTimerSlider.value == self.backgroundSessionTimerSlider.maximumValue ? (uint32_t) INT16_MAX : (uint32_t)self.backgroundSessionTimerSlider.value;
|
NSInteger backgroundSessionTimer = self.backgroundSessionTimerSlider.value == self.backgroundSessionTimerSlider.maximumValue ? (uint32_t) INT16_MAX : (uint32_t)self.backgroundSessionTimerSlider.value;
|
||||||
|
|||||||
Reference in new issue
Block a user