windowing/windowserver/nga/SERVER/wsdisplaychangeao.cpp
changeset 0 5d03bc08d59c
child 97 0e9202c0340c
child 110 7f25ef56562d
child 116 171fae344dd4
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18 */
       
    19 
       
    20 #include "wsdisplaychangeao.h"
       
    21 #include "ScrDev.H"
       
    22 #include "server.h"
       
    23 
       
    24 CWsDisplayChangeNotifier::CWsDisplayChangeNotifier(MWsDisplayControl* aNextLevelInterface, CScreen *aOwner)
       
    25 :CActive(EEventPriority), iNextLevelInterface(aNextLevelInterface), iOwner(aOwner)
       
    26 	{
       
    27 	CActiveScheduler::Add(this);
       
    28 	}
       
    29 
       
    30 CWsDisplayChangeNotifier* CWsDisplayChangeNotifier::NewL(MWsDisplayControl* aNextLevelInterface, CScreen *aOwner)
       
    31 	{
       
    32 	CWsDisplayChangeNotifier* self = new(ELeave) CWsDisplayChangeNotifier(aNextLevelInterface, aOwner);
       
    33 	CleanupStack::PushL(self);
       
    34 	self->ConstructL();
       
    35 	CleanupStack::Pop();
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 void CWsDisplayChangeNotifier::ConstructL()
       
    40 	{
       
    41 	iRetry = CEventQueueRetry::NewL();
       
    42 	}
       
    43 
       
    44 void CWsDisplayChangeNotifier::IssueNotificationRequest()
       
    45 	{
       
    46 	//before submitting request, save the last resolution list
       
    47 	iLastErr = iNextLevelInterface->GetResolutions(iLastResList);
       
    48 	if(iLastErr != KErrNone)
       
    49 		{
       
    50 		//probabally KErrDisconnect
       
    51 		iLastResList.Reset();
       
    52 		}
       
    53 	iNextLevelInterface->NotifyOnDisplayChange(iStatus);
       
    54 	SetActive();
       
    55 	}
       
    56 
       
    57 void CWsDisplayChangeNotifier::CancelNotificationRequest()
       
    58 	{
       
    59 	Cancel();
       
    60 	}
       
    61 
       
    62 void CWsDisplayChangeNotifier::RunL()
       
    63 	{
       
    64 	if(iStatus == KErrNone)
       
    65 		{
       
    66 		//IssueNotificationRequest() will overwrite iLastResList and iLastErr, save a copy first
       
    67 		TInt lastErr = iLastErr;
       
    68 		RArray<MWsDisplayControl::TResolution> lastResList;
       
    69 		CleanupClosePushL(lastResList);
       
    70 		lastResList.ReserveL(iLastResList.Count());
       
    71 		for(TInt i = 0; i < iLastResList.Count(); i++)
       
    72 			{
       
    73 			lastResList.Append(iLastResList[i]);
       
    74 			}
       
    75 		//submit request again, this should be called as early as possible in RunL(). Otherwise display change occurs
       
    76 		//before submitting the request will be missed.
       
    77 		IssueNotificationRequest();
       
    78 		
       
    79 		RArray<MWsDisplayControl::TResolution> currentResList;
       
    80 		CleanupClosePushL(currentResList);
       
    81 		TInt err = iNextLevelInterface->GetResolutions(currentResList);
       
    82 		if(err != KErrNone)
       
    83 			{
       
    84 			//probabally KErrDisconnect
       
    85 			currentResList.Reset();
       
    86 			}
       
    87 		//return code not equal also counts as an event
       
    88 		if(!IsResListEqual(currentResList, lastResList) || lastErr != err)
       
    89 			{
       
    90 			//first thing is to cancel the retry AO if it's running for the last event
       
    91 			iRetry->CancelRetry();
       
    92 			
       
    93 			iOwner->IncreaseDisplaySpinner();
       
    94 			//put display change event on queue
       
    95 			RPointerArray<CWsClient> clientArray;
       
    96 			CleanupClosePushL(clientArray);
       
    97 			User::LeaveIfError(iOwner->GetNotificationClients(clientArray));
       
    98 			TBool eventOnAllQueues = ETrue;
       
    99 			for(TInt i = 0; i < clientArray.Count(); i++)
       
   100 				{
       
   101 				if(!TWindowServerEvent::SendDisplayChangedEvents(clientArray[i], iOwner->ScreenNumber(),
       
   102 						iOwner->ConfigSpinner(), iOwner->DisplaySpinner()))
       
   103 					{
       
   104 					eventOnAllQueues = EFalse;
       
   105 					clientArray[i]->SetRetryFlag(EEventDisplayChanged);
       
   106 					}
       
   107 				}
       
   108 			CleanupStack::PopAndDestroy(&clientArray);
       
   109 			
       
   110 			//some event queues are full, kick off retry AO
       
   111 			if(!eventOnAllQueues)
       
   112 				{
       
   113 				iRetry->Init(iOwner);
       
   114 				iRetry->Retry(KRetryInitialDelay);
       
   115 				}
       
   116 						
       
   117 			//codes below are dealing with detach/attach
       
   118 			MWsDisplayPolicy* policy = iOwner->DisplayPolicy();
       
   119 			if((err == KErrDisconnected && lastErr != KErrDisconnected)
       
   120 					||(currentResList.Count() == 0 && lastResList.Count() != 0))
       
   121 				{
       
   122 				//The display is disconnected
       
   123 				if(policy)
       
   124 					{
       
   125 					TInt appMode = policy->SuitableAppMode(MWsDisplayPolicy::EDetach);
       
   126 					//Last app mode can be resumed when display is connected again from disconnection
       
   127 					iOwner->DisplayPolicy()->SetLastAppMode(iOwner->ScreenSizeMode());
       
   128 					//This gonna set the screen mode to smallest app mode
       
   129 					if(appMode >= 0)
       
   130 						{
       
   131 						iOwner->doSetScreenMode(appMode);
       
   132 						}
       
   133 					}
       
   134 				else
       
   135 					{
       
   136 					//if policy is not available, do a SetConfiguration set to the same config before disconnect
       
   137 					//this will update parameters for MDisplayMapping stored in CDisplayPolicy
       
   138 					TDisplayConfiguration config;
       
   139 					iNextLevelInterface->GetConfiguration(config);
       
   140 					iNextLevelInterface->SetConfiguration(config);
       
   141 					}
       
   142 				//stop DSA drawing as the above set screen mode is under disconnection and it won't
       
   143 				//go the normal routine to stop DSA drawing
       
   144 				iOwner->AbortAllDirectDrawing(RDirectScreenAccess::ETerminateScreenMode);
       
   145 				}
       
   146 			
       
   147 			if(currentResList.Count() > 0 && lastResList.Count() == 0)
       
   148 				{
       
   149 				//The display is connected
       
   150 				if(policy)
       
   151 					{
       
   152 					TInt appMode = policy->SuitableAppMode(MWsDisplayPolicy::EAttach);
       
   153 					//This gonna resume the screen mode to the one before disconnection
       
   154 					if(appMode >= 0)
       
   155 						{
       
   156 						iOwner->doSetScreenMode(appMode);
       
   157 						}
       
   158 					}
       
   159 				else
       
   160 					{
       
   161 					//if policy is not available, force a SetConfiguration to trigger a config change notification
       
   162 					//as the twips size in config is changed on attaching display though resolution may remain 0x0 
       
   163 					TDisplayConfiguration config;
       
   164 					config.SetResolution(currentResList[0].iPixelSize);
       
   165 					iOwner->SetConfiguration(config);
       
   166 					}
       
   167 				iOwner->RecalculateModeTwips();
       
   168 				}
       
   169 			}
       
   170 		CleanupStack::PopAndDestroy(2, &lastResList);
       
   171 		}
       
   172 	else if(iStatus != KErrCancel && iStatus != KErrNotSupported)
       
   173 		{
       
   174 		IssueNotificationRequest();	//This should be ok, not deadlock
       
   175 		}
       
   176 		
       
   177 	}
       
   178 
       
   179 TBool CWsDisplayChangeNotifier::IsResListEqual(RArray<MWsDisplayControl::TResolution>& aResListA, RArray<MWsDisplayControl::TResolution>& aResListB)
       
   180 	{
       
   181 	if (aResListA.Count() != aResListB.Count())
       
   182 		return EFalse;
       
   183 	
       
   184 	for(TInt i = 0; i < aResListA.Count(); i++)
       
   185 		{
       
   186 		if(aResListA[i].iPixelSize != aResListB[i].iPixelSize)
       
   187 			{
       
   188 			return EFalse;
       
   189 			}
       
   190 		if(aResListA[i].iTwipsSize != aResListB[i].iTwipsSize)
       
   191 			{
       
   192 			return EFalse;
       
   193 			}
       
   194 		if(!(aResListA[i].iFlags == aResListB[i].iFlags))
       
   195 			{
       
   196 			return EFalse;
       
   197 			}
       
   198 		}
       
   199 	
       
   200 	return ETrue;
       
   201 	}
       
   202 
       
   203 void CWsDisplayChangeNotifier::DoCancel()
       
   204 	{}
       
   205 
       
   206 CWsDisplayChangeNotifier::~CWsDisplayChangeNotifier()
       
   207 	{
       
   208 	Cancel();
       
   209 	iLastResList.Close();
       
   210 	delete iRetry;
       
   211 	}
       
   212 
       
   213 CWsConfigChangeNotifier::CWsConfigChangeNotifier(MWsDisplayControl* aNextLevelInterface, CScreen *aOwner)
       
   214 :CActive(EEventPriority), iNextLevelInterface(aNextLevelInterface), iOwner(aOwner)
       
   215 	{
       
   216 	CActiveScheduler::Add(this);
       
   217 	}
       
   218 
       
   219 CWsConfigChangeNotifier* CWsConfigChangeNotifier::NewL(MWsDisplayControl* aNextLevelInterface, CScreen *aOwner)
       
   220 	{
       
   221 	CWsConfigChangeNotifier* self = new(ELeave) CWsConfigChangeNotifier(aNextLevelInterface, aOwner);
       
   222 	CleanupStack::PushL(self);
       
   223 	self->ConstructL();
       
   224 	CleanupStack::Pop();
       
   225 	return self;
       
   226 	}
       
   227 
       
   228 void CWsConfigChangeNotifier::ConstructL()
       
   229 	{
       
   230 	iRetry = CEventQueueRetry::NewL();
       
   231 	}
       
   232 
       
   233 void CWsConfigChangeNotifier::IssueNotificationRequest()
       
   234 	{
       
   235 	//Before submitting the request, save last configuration
       
   236 	iNextLevelInterface->GetConfiguration(iLastConfig);
       
   237 	iNextLevelInterface->NotifyOnConfigChange(iStatus);
       
   238 	SetActive();
       
   239 	}
       
   240 
       
   241 void CWsConfigChangeNotifier::CancelNotificationRequest()
       
   242 	{
       
   243 	Cancel();
       
   244 	}
       
   245 
       
   246 void CWsConfigChangeNotifier::RunL()
       
   247 	{
       
   248 	if(iStatus == KErrNone)
       
   249 		{
       
   250 		//IssueNotificationRequest() will overwrite iLastConfig, save a copy first
       
   251 		TDisplayConfiguration lastConfig(iLastConfig);
       
   252 		IssueNotificationRequest();
       
   253 		
       
   254 		TDisplayConfiguration currentConfig;
       
   255 		iNextLevelInterface->GetConfiguration(currentConfig);
       
   256 		if(!(currentConfig == lastConfig))
       
   257 			{
       
   258 			//first thing is to cancel the retry AO if it's running for the last event
       
   259 			iRetry->CancelRetry();
       
   260 			
       
   261 			iOwner->IncreaseConfigSpinner();
       
   262 			//put config change event on queue
       
   263 			RPointerArray<CWsClient> clientArray;
       
   264 			CleanupClosePushL(clientArray);
       
   265 			User::LeaveIfError(iOwner->GetNotificationClients(clientArray));
       
   266 			TBool eventOnAllQueues = ETrue;
       
   267 			for(TInt i = 0; i < clientArray.Count(); i++)
       
   268 				{
       
   269 				if(!TWindowServerEvent::SendDisplayChangedEvents(clientArray[i], iOwner->ScreenNumber(),
       
   270 						iOwner->ConfigSpinner(), iOwner->DisplaySpinner()))
       
   271 					{
       
   272 					eventOnAllQueues = EFalse;
       
   273 					clientArray[i]->SetRetryFlag(EEventDisplayChanged);					
       
   274 					}
       
   275 				}
       
   276 			
       
   277 			CleanupStack::PopAndDestroy(&clientArray);
       
   278 			//some event queues are full, kick off retry AO
       
   279 			if(!eventOnAllQueues)
       
   280 				{
       
   281 				iRetry->Init(iOwner);
       
   282 				iRetry->Retry(KRetryInitialDelay);
       
   283 				}
       
   284 			}
       
   285 		}
       
   286 	else if(iStatus != KErrCancel && iStatus != KErrNotSupported)
       
   287 		{
       
   288 		IssueNotificationRequest();
       
   289 		}
       
   290 	
       
   291 	}
       
   292 
       
   293 
       
   294 void CWsConfigChangeNotifier::DoCancel()
       
   295 	{}
       
   296 
       
   297 CWsConfigChangeNotifier::~CWsConfigChangeNotifier()
       
   298 	{
       
   299 	Cancel();
       
   300 	delete iRetry;
       
   301 	}
       
   302 
       
   303