Skip to content
Snippets Groups Projects
Commit c17db8da authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

performance: use OpenGLLayer only during call

Once added to a view OpenGLLayer starts  drawing content.
This patch uses OpenGLLayer only during video calls.

Change-Id: I52ddb1f3ba9b0cd1a9b3846a43573a41aea6a66f
parent a8525943
Branches
Tags
No related merge requests found
...@@ -31,7 +31,6 @@ class Call; ...@@ -31,7 +31,6 @@ class Call;
@interface CurrentCallVC : NSViewController <NSSplitViewDelegate, CallDelegate> { @interface CurrentCallVC : NSViewController <NSSplitViewDelegate, CallDelegate> {
} }
-(void) initFrame; -(void) initFrame;
-(void) showWithAnimation:(BOOL)animate; -(void) showWithAnimation:(BOOL)animate;
-(void) hideWithAnimation:(BOOL)animate; -(void) hideWithAnimation:(BOOL)animate;
......
...@@ -387,6 +387,7 @@ ...@@ -387,6 +387,7 @@
&lrc::api::NewCallModel::remotePreviewStarted, &lrc::api::NewCallModel::remotePreviewStarted,
[self](const std::string& callId, Video::Renderer* renderer) { [self](const std::string& callId, Video::Renderer* renderer) {
NSLog(@"Video started!"); NSLog(@"Video started!");
[videoView setLayer:[[CallLayer alloc] init]];
[videoView setShouldAcceptInteractions:YES]; [videoView setShouldAcceptInteractions:YES];
[self mouseIsMoving: NO]; [self mouseIsMoving: NO];
[self connectVideoRenderer:renderer]; [self connectVideoRenderer:renderer];
...@@ -395,6 +396,7 @@ ...@@ -395,6 +396,7 @@
if (callModel->hasCall(callUid_)) { if (callModel->hasCall(callUid_)) {
if (auto renderer = callModel->getRenderer(callUid_)) { if (auto renderer = callModel->getRenderer(callUid_)) {
QObject::disconnect(self.videoStarted); QObject::disconnect(self.videoStarted);
[videoView setLayer:[[CallLayer alloc] init]];
[self connectVideoRenderer: renderer]; [self connectVideoRenderer: renderer];
} }
} }
...@@ -465,6 +467,8 @@ ...@@ -465,6 +467,8 @@
videoHolder.stopped = QObject::connect(renderer, videoHolder.stopped = QObject::connect(renderer,
&Video::Renderer::stopped, &Video::Renderer::stopped,
[=]() { [=]() {
[videoView setLayer:[CALayer layer]];
[videoView.layer setBackgroundColor:[[NSColor blackColor] CGColor]];
[self mouseIsMoving: YES]; [self mouseIsMoving: YES];
[videoView setShouldAcceptInteractions:NO]; [videoView setShouldAcceptInteractions:NO];
QObject::disconnect(videoHolder.frameUpdated); QObject::disconnect(videoHolder.frameUpdated);
...@@ -559,7 +563,8 @@ ...@@ -559,7 +563,8 @@
QObject::disconnect(previewHolder.started); QObject::disconnect(previewHolder.started);
QObject::disconnect(self.messageConnection); QObject::disconnect(self.messageConnection);
[previewView.layer setContents:nil]; [previewView.layer setContents:nil];
[(CallLayer*)videoView.layer setVideoRunning:NO]; [videoView setLayer:[CALayer layer]];
[videoView.layer setBackgroundColor:[[NSColor blackColor] CGColor]];
[_brokerPopoverVC performClose:self]; [_brokerPopoverVC performClose:self];
[self.addToContactPopover performClose:self]; [self.addToContactPopover performClose:self];
......
...@@ -56,6 +56,14 @@ ...@@ -56,6 +56,14 @@
#import "utils.h" #import "utils.h"
#import "RingWizardWC.h" #import "RingWizardWC.h"
#import "AccountSettingsVC.h" #import "AccountSettingsVC.h"
#import "views/CallLayer.h"
typedef NS_ENUM(NSInteger, ViewState) {
SHOW_WELCOME_SCREEN = 0,
SHOW_CONVERSATION_SCREEN,
SHOW_CALL_SCREEN,
SHOW_SETTINGS_SCREEN,
};
@interface RingWindowController () <MigrateRingAccountsDelegate, NSToolbarDelegate> @interface RingWindowController () <MigrateRingAccountsDelegate, NSToolbarDelegate>
...@@ -104,6 +112,58 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI ...@@ -104,6 +112,58 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
return self; return self;
} }
-(void)changeViewTo:(ViewState) state {
switch (state) {
case SHOW_WELCOME_SCREEN:
[self accountSettingsShouldOpen: NO];
[conversationVC hideWithAnimation:false];
[currentCallVC hideWithAnimation:false];
[currentCallVC.view removeFromSuperview];
[welcomeContainer setHidden: NO];
[smartViewVC.view setHidden: NO];
[settingsVC hide];
break;
case SHOW_CONVERSATION_SCREEN:
[self accountSettingsShouldOpen: NO];
[conversationVC showWithAnimation:false];
[currentCallVC hideWithAnimation:false];
[currentCallVC.view removeFromSuperview];
[welcomeContainer setHidden: YES];
[smartViewVC.view setHidden: NO];
[settingsVC hide];
break;
case SHOW_CALL_SCREEN:
[self accountSettingsShouldOpen: NO];
if (![currentCallVC.view superview]) {
[callView addSubview:[currentCallVC view] positioned:NSWindowAbove relativeTo:nil];
[currentCallVC initFrame];
[currentCallVC showWithAnimation:false];
[conversationVC hideWithAnimation:false];
[welcomeContainer setHidden: YES];
[smartViewVC.view setHidden: NO];
[settingsVC hide];
}
[currentCallVC showWithAnimation:false];
break;
case SHOW_SETTINGS_SCREEN:
@try {
[self accountSettingsShouldOpen: YES];
}
@catch (NSException *ex) {
return;
}
[welcomeContainer setHidden: YES];
[currentCallVC hideWithAnimation:false];
[currentCallVC.view removeFromSuperview];
[conversationVC hideWithAnimation:false];
[smartViewVC.view setHidden: YES];
[settingsVC show];
break;
default:
break;
}
}
- (void)windowDidLoad { - (void)windowDidLoad {
[super windowDidLoad]; [super windowDidLoad];
[self.window setMovableByWindowBackground:YES]; [self.window setMovableByWindowBackground:YES];
...@@ -120,11 +180,9 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI ...@@ -120,11 +180,9 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
[[conversationVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [[conversationVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[settingsVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [[settingsVC view] setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[callView addSubview:[currentCallVC view] positioned:NSWindowAbove relativeTo:nil];
[callView addSubview:[conversationVC view] positioned:NSWindowAbove relativeTo:nil]; [callView addSubview:[conversationVC view] positioned:NSWindowAbove relativeTo:nil];
[self.window.contentView addSubview:[settingsVC view] positioned:NSWindowAbove relativeTo:nil]; [self.window.contentView addSubview:[settingsVC view] positioned:NSWindowAbove relativeTo:nil];
[currentCallVC initFrame];
[conversationVC initFrame]; [conversationVC initFrame];
[settingsVC initFrame]; [settingsVC initFrame];
@try { @try {
...@@ -173,10 +231,8 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI ...@@ -173,10 +231,8 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
conversation:convInfo.uid conversation:convInfo.uid
account:accInfo]; account:accInfo];
[smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()]; [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()];
[currentCallVC showWithAnimation:false]; [self changeViewTo:SHOW_CALL_SCREEN];
[conversationVC hideWithAnimation:false];
[self accountSettingsShouldOpen: NO];
[welcomeContainer setHidden: YES];
}); });
QObject::connect(self.behaviorController, QObject::connect(self.behaviorController,
...@@ -193,10 +249,7 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI ...@@ -193,10 +249,7 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
conversation:convInfo.uid conversation:convInfo.uid
account:accInfo]; account:accInfo];
[smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()]; [smartViewVC selectConversation: convInfo model:accInfo->conversationModel.get()];
[currentCallVC showWithAnimation:false]; [self changeViewTo:SHOW_CALL_SCREEN];
[conversationVC hideWithAnimation:false];
[self accountSettingsShouldOpen: NO];
[welcomeContainer setHidden: YES];
}); });
QObject::connect(self.behaviorController, QObject::connect(self.behaviorController,
...@@ -206,10 +259,7 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI ...@@ -206,10 +259,7 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
auto& accInfo = self.accountModel->getAccountInfo(accountId); auto& accInfo = self.accountModel->getAccountInfo(accountId);
[conversationVC setConversationUid:convInfo.uid model:accInfo.conversationModel.get()]; [conversationVC setConversationUid:convInfo.uid model:accInfo.conversationModel.get()];
[smartViewVC selectConversation: convInfo model:accInfo.conversationModel.get()]; [smartViewVC selectConversation: convInfo model:accInfo.conversationModel.get()];
[conversationVC showWithAnimation:false]; [self changeViewTo:SHOW_CONVERSATION_SCREEN];
[currentCallVC hideWithAnimation:false];
[self accountSettingsShouldOpen: NO];
[welcomeContainer setHidden: YES];
}); });
} }
...@@ -420,25 +470,17 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI ...@@ -420,25 +470,17 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
- (void) selectAccount:(const lrc::api::account::Info&)accInfo currentRemoved:(BOOL) removed - (void) selectAccount:(const lrc::api::account::Info&)accInfo currentRemoved:(BOOL) removed
{ {
// If the selected account has been changed, we close any open panel // If the selected account has been changed, we close any open panel
if ([smartViewVC setConversationModel:accInfo.conversationModel.get()]) { [smartViewVC setConversationModel:accInfo.conversationModel.get()];
[currentCallVC hideWithAnimation:false];
[conversationVC hideWithAnimation:false];
}
// Welcome view informations are also updated // Welcome view informations are also updated
[self updateRingID]; [self updateRingID];
[settingsVC setSelectedAccount:accInfo.id]; [settingsVC setSelectedAccount:accInfo.id];
if (removed) { [self changeViewTo: ([settingsVC.view isHidden] || removed) ? SHOW_WELCOME_SCREEN : SHOW_SETTINGS_SCREEN];
[self accountSettingsShouldOpen: NO];
}
} }
-(void)allAccountsDeleted -(void)allAccountsDeleted
{ {
[smartViewVC clearConversationModel]; [smartViewVC clearConversationModel];
[currentCallVC hideWithAnimation:false]; [self changeViewTo:SHOW_WELCOME_SCREEN];
[conversationVC hideWithAnimation:false];
[self accountSettingsShouldOpen: NO];
[self updateRingID]; [self updateRingID];
} }
...@@ -454,10 +496,7 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI ...@@ -454,10 +496,7 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
} }
-(void) listTypeChanged { -(void) listTypeChanged {
[conversationVC hideWithAnimation:false]; [self changeViewTo:SHOW_WELCOME_SCREEN];
[currentCallVC hideWithAnimation:false];
[self accountSettingsShouldOpen: NO];
[welcomeContainer setHidden: NO];
} }
#pragma mark - NSToolbarDelegate #pragma mark - NSToolbarDelegate
...@@ -493,39 +532,21 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI ...@@ -493,39 +532,21 @@ NSString* const kOpenAccountToolBarItemIdentifier = @"OpenAccountToolBarItemI
- (IBAction)openAccountSettings:(NSButton *)sender - (IBAction)openAccountSettings:(NSButton *)sender
{ {
if(![settingsVC.view isHidden]) { [self changeViewTo: [settingsVC.view isHidden] ? SHOW_SETTINGS_SCREEN : SHOW_WELCOME_SCREEN];
[self accountSettingsShouldOpen: NO];
return;
}
[self accountSettingsShouldOpen: YES];
} }
- (void) createNewAccount { - (void) createNewAccount {
[self accountSettingsShouldOpen: NO]; [self changeViewTo:SHOW_WELCOME_SCREEN];
[currentCallVC hideWithAnimation:false];
[conversationVC hideWithAnimation:false];
wizard = [[RingWizardWC alloc] initWithNibName:@"RingWizard" bundle: nil accountmodel: self.accountModel]; wizard = [[RingWizardWC alloc] initWithNibName:@"RingWizard" bundle: nil accountmodel: self.accountModel];
[wizard showChooseWithCancelButton: YES andAdvanced: YES]; [wizard showChooseWithCancelButton: YES andAdvanced: YES];
[self.window beginSheet:wizard.window completionHandler:nil]; [self.window beginSheet:wizard.window completionHandler:nil];
} }
-(void) accountSettingsShouldOpen: (BOOL) open { -(void) accountSettingsShouldOpen: (BOOL) open {
[smartViewVC.view setHidden:open];
[welcomeContainer setHidden: open];
if (open) { if (open) {
@try {
[settingsVC setSelectedAccount: [chooseAccountVC selectedAccount].id]; [settingsVC setSelectedAccount: [chooseAccountVC selectedAccount].id];
} }
@catch (NSException *ex) {
NSLog(@"Caught exception %@: %@", [ex name], [ex reason]);
return;
}
[currentCallVC hideWithAnimation:false];
[conversationVC hideWithAnimation:false];
[settingsVC show];
} else {
[settingsVC hide];
}
NSToolbar *toolbar = self.window.toolbar; NSToolbar *toolbar = self.window.toolbar;
NSArray *settings = [toolbar items]; NSArray *settings = [toolbar items];
......
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
{ {
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]]; [self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
[self setWantsLayer:YES]; [self setWantsLayer:YES];
[self setLayer:[CALayer layer]];
[self.layer setBackgroundColor:[[NSColor blackColor] CGColor]];
} }
[self.window setAcceptsMouseMovedEvents:YES]; [self.window setAcceptsMouseMovedEvents:YES];
...@@ -66,12 +68,6 @@ ...@@ -66,12 +68,6 @@
return self; return self;
} }
- (CALayer *)makeBackingLayer
{
return (CALayer*) [[CallLayer alloc] init];
}
#pragma mark - Destination Operations #pragma mark - Destination Operations
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment