Commit c17db8da authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

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