windowing/windowserver/nga/CLIENT/RBUFFER.CPP
branchRCL_3
changeset 163 bbf46f59e123
parent 26 15986eb6c500
child 164 25ffed67c7ef
equal deleted inserted replaced
150:57c618273d5c 163:bbf46f59e123
     1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1994-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    41 		iAutoFlush(ETrue),
    41 		iAutoFlush(ETrue),
    42 	#else
    42 	#else
    43 		iAutoFlush(EFalse),
    43 		iAutoFlush(EFalse),
    44 	#endif
    44 	#endif
    45 	iBuf(NULL,0,0), iNext(NULL), iPreviousHandle(0), iBufSize(0), iMaxBufSize(EMinBufferSize),
    45 	iBuf(NULL,0,0), iNext(NULL), iPreviousHandle(0), iBufSize(0), iMaxBufSize(EMinBufferSize),
       
    46 	#if defined(_DEBUG)
       
    47 	iAppendDataLength(0),
       
    48 	#endif
    46 	iDirectAcessCount(0), iInvalidBitmapArray(EFalse), iWindowSizeCache(NULL)
    49 	iDirectAcessCount(0), iInvalidBitmapArray(EFalse), iWindowSizeCache(NULL)
    47 #ifdef SYMBIAN_GRAPHICS_FIXNATIVEORIENTATION
       
    48 , iWindowNativeSizeCache(NULL)
       
    49 #endif // SYMBIAN_GRAPHICS_FIXNATIVEORIENTATION
       
    50 	{
    50 	{
    51 	}
    51 	}
    52 
    52 
    53 TInt WsFbsDestroyCallBack(TAny* aBitmapHandle)
    53 TInt WsFbsDestroyCallBack(TAny* aBitmapHandle)
    54 	{
    54 	{
   101 	    {
   101 	    {
   102 	    iWindowSizeCache->Close();
   102 	    iWindowSizeCache->Close();
   103 	    delete iWindowSizeCache;
   103 	    delete iWindowSizeCache;
   104 	    iWindowSizeCache = NULL;
   104 	    iWindowSizeCache = NULL;
   105 	    }
   105 	    }
   106 #ifdef SYMBIAN_GRAPHICS_FIXNATIVEORIENTATION
       
   107 	if (iWindowNativeSizeCache)
       
   108 	    {
       
   109 	    iWindowNativeSizeCache->Close();
       
   110 	    delete iWindowNativeSizeCache;
       
   111 	    iWindowNativeSizeCache = NULL;
       
   112 	    }
       
   113 #endif // SYMBIAN_GRAPHICS_FIXNATIVEORIENTATION
       
   114 	}
   106 	}
   115 
   107 
   116 void RWsBuffer::Destroy()
   108 void RWsBuffer::Destroy()
   117 	{
   109 	{
   118 	Flush();
   110 	Flush();
   279 TInt RWsBuffer::DoWrite(TInt aHandle, TUint aOpcode, TBool aFlush, const TIpcArgs* aIpcArgs, const TAny* aData, TInt aLength, const TAny* aData2, TInt aLength2)
   271 TInt RWsBuffer::DoWrite(TInt aHandle, TUint aOpcode, TBool aFlush, const TIpcArgs* aIpcArgs, const TAny* aData, TInt aLength, const TAny* aData2, TInt aLength2)
   280 	{
   272 	{
   281 	__ASSERT_DEBUG(((TUint32) aOpcode) < 0x8000, Assert(EW32AssertIllegalOpcode));
   273 	__ASSERT_DEBUG(((TUint32) aOpcode) < 0x8000, Assert(EW32AssertIllegalOpcode));
   282 	__ASSERT_DEBUG((aLength&0x3) == 0, Assert(EW32AssertOddLengthData));
   274 	__ASSERT_DEBUG((aLength&0x3) == 0, Assert(EW32AssertOddLengthData));
   283 	TInt xtra(0);
   275 	TInt xtra(0);
   284 	if (aLength2 > 0)
   276 	if (aLength2>0)
   285 		{
   277 		xtra = PadValue(aLength2);		// Round data upto a multiple of 4
   286 		xtra = 4 - (aLength2&0x3);		// Round data upto a multiple of 4
       
   287 		if (xtra==4)
       
   288 			{
       
   289 			xtra=0;
       
   290 			}
       
   291 		}
       
   292 
   278 
   293 	const TInt msgSize = aLength + aLength2 + xtra + static_cast<TInt>(sizeof(TWsCmdHeader));
   279 	const TInt msgSize = aLength + aLength2 + xtra + static_cast<TInt>(sizeof(TWsCmdHeader));
   294 	TInt available = iBuf.MaxLength() - iBuf.Length();
   280 	TInt available = iBuf.MaxLength() - iBuf.Length();
   295 	if (msgSize > available)
   281 	if (msgSize > available)
   296 		{
   282 		{
   334 
   320 
   335 	if (aLength)
   321 	if (aLength)
   336 		{
   322 		{
   337 		iBuf.Append((TUint8 *)aData, aLength);
   323 		iBuf.Append((TUint8 *)aData, aLength);
   338 		}
   324 		}
   339 	if (aLength2 > 0)
   325 	if (aLength2>0 && aData2!=NULL)
   340 		{
   326 		{
   341 		iBuf.Append((TUint8 *)aData2, aLength2);
   327 		iBuf.Append((TUint8 *)aData2, aLength2);
   342 		iBuf.AppendFill(0,xtra);
   328 		iBuf.AppendFill(0,xtra);
   343 		}
   329 		}
   344 
   330 #if defined(_DEBUG)
       
   331 	else if (aLength2>0 && aData2==NULL)
       
   332 		{
       
   333 		iAppendDataLength = aLength2;
       
   334 		}
       
   335 #endif
   345 	if (aFlush)
   336 	if (aFlush)
   346 		{
   337 		{
   347 		return Flush(aIpcArgs);
   338 		return Flush(aIpcArgs);
   348 		}
   339 		}
   349 	return KErrNone;
   340 	return KErrNone;
   352 void RWsBuffer::Write(TInt handle,TUint opcode)
   343 void RWsBuffer::Write(TInt handle,TUint opcode)
   353 	{
   344 	{
   354 	DoWrite(handle, opcode, iAutoFlush, NULL);
   345 	DoWrite(handle, opcode, iAutoFlush, NULL);
   355 	}
   346 	}
   356 
   347 
   357 void RWsBuffer::Write(TInt handle,TUint opcode,const TAny *pData, TInt length)
   348 /**
   358 	{
   349 Writes data sent in aData of length aLength1 for the specifed aOpcode
   359 	DoWrite(handle, opcode, iAutoFlush, NULL, pData, length);
   350 into wserv buffer. It also takes an TIpcArgs by which you can send additional 
   360 	}
   351 data. But one thing needs to be noted that if aIpcArgs has some content then 
   361 
   352 this function flushes the wserv buffer.
   362 void RWsBuffer::Write(TInt handle,TUint opcode,const TAny *pData, TInt length,const TAny *pData2, TInt length2)
   353 
   363 	{
   354 @param aHandle aHandle of class derived from MWsClientClass
   364 	DoWrite(handle, opcode, iAutoFlush, NULL, pData, length, pData2, length2);
   355 @param aOpcode Opcode for the current command
       
   356 @param aData Data to be added to the buffer
       
   357 @param aLength Length of the data to be added to buffer
       
   358 @param aIpcArgs Additional data sent from client to server. It has default argument NULL.
       
   359 				And if some data is sent in aIpcArgs, it flushes wserv buffer
       
   360 */
       
   361 void RWsBuffer::Write(TInt aHandle, TUint aOpcode, const TAny *aData, TInt aLength, const TIpcArgs* aIpcArgs/*=NULL*/)
       
   362 	{
       
   363 	TBool flush = (aIpcArgs != NULL ? ETrue : iAutoFlush);	// If aIpcArgs contains data then we do explicit flush
       
   364 	DoWrite(aHandle, aOpcode, flush, aIpcArgs, aData, aLength);
       
   365 	}
       
   366 
       
   367 /**
       
   368 Writes data sent in aData and aData2 of lengths aLength1 and aLength2 
       
   369 for the specifed aOpcode into wserv buffer. It also takes an TIpcArgs by which 
       
   370 you can send additional data. But one thing needs to be noted that if aIpcArgs 
       
   371 has some content then this function flushes the wserv buffer.
       
   372 
       
   373 @param aHandle Handle of class derived from MWsClientClass
       
   374 @param aOpcode Opcode for the current command
       
   375 @param aData Data to be added to the buffer
       
   376 @param aLength Length of the data to be added to buffer
       
   377 @param aData2 second Data to be added to the buffer
       
   378 @param aLength2 Length of the second data to be added to buffer
       
   379 @param aIpcArgs Additional data sent from client to server. It has default argument NULL.
       
   380 				And if some data is sent in aIpcArgs, it flushes wserv buffer
       
   381 */
       
   382 void RWsBuffer::Write(TInt aHandle, TUint aOpcode, const TAny *aData, TInt aLength, const TAny *aData2, TInt aLength2, const TIpcArgs* aIpcArgs/*=NULL*/)
       
   383 	{
       
   384 	__ASSERT_DEBUG(!((aIpcArgs != NULL) &&  (aLength2 > 0 && aData2 == NULL)), Assert(EW32AssertBufferLogic));
       
   385 	TBool flush = iAutoFlush;
       
   386 	if (aLength2 > 0 && aData2 == NULL)
       
   387 		{
       
   388 		flush = EFalse;		// if just length2 is sent then we should not flush
       
   389 		}
       
   390 	else if (aIpcArgs != NULL)
       
   391 		{
       
   392 		flush = ETrue;		// If aIpcArgs contains data then we do explicit flush
       
   393 		}
       
   394 	DoWrite(aHandle, aOpcode, flush, aIpcArgs, aData, aLength, aData2, aLength2);
       
   395 	}
       
   396 
       
   397 /**
       
   398 Appends data directly to wserv buffer for the current command. So this function 
       
   399 should be used after adding the current command. 
       
   400 
       
   401 @param aData Data to be added to the buffer
       
   402 @param aLength Length of the data to be added to buffer. Make sure that its length
       
   403 		is less than availabe buffer.
       
   404 @param aFinished EFalse, adds data to buffer and disables flushing even if auto flush is on, 
       
   405 				 basically this notfies that more data is pending to be added.
       
   406 				 ETrue, adds data to buffer and resume normal service for flushing
       
   407 				 ie. Signals that this is the last bit of data to be added
       
   408 
       
   409 Note: When data is added using this API, it pads out buffer to multiple of 4 bytes  
       
   410 */
       
   411 void RWsBuffer::AppendData(const TAny *aData,TInt aLength,TBool aFinished)
       
   412 	{
       
   413 	__ASSERT_ALWAYS(iBuf.MaxLength()-iBuf.Length()>=PaddedValue(aLength),Assert(EW32AssertBufferLogic));
       
   414 #if defined(_DEBUG)
       
   415 	// Check if this function is called only after setting iAppendDataLength
       
   416 	__ASSERT_DEBUG(iAppendDataLength > 0, Assert(EW32AssertBufferLogic));
       
   417 	// Check if length passed in is less then iAppendDataLength
       
   418 	__ASSERT_DEBUG(iAppendDataLength >= aLength, Assert(EW32AssertBufferLogic));
       
   419 	if (aFinished)
       
   420 		iAppendDataLength = 0; 
       
   421 	else
       
   422 		iAppendDataLength -= aLength;
       
   423 #endif
       
   424 	iBuf.Append((TUint8*)(aData),aLength);
       
   425 	iBuf.AppendFill(0,PadValue(iBuf.Length()));		// Padout out buffer to multiple of 4 bytes
       
   426 	if (aFinished && iAutoFlush)
       
   427 		Flush(NULL);
   365 	}
   428 	}
   366 
   429 
   367 TInt RWsBuffer::WriteReply(TInt handle,TUint opcode,const TIpcArgs* aIpcArgs)
   430 TInt RWsBuffer::WriteReply(TInt handle,TUint opcode,const TIpcArgs* aIpcArgs)
   368 	{
   431 	{
   369 	return DoWrite(handle, opcode, ETrue, aIpcArgs);
   432 	return DoWrite(handle, opcode, ETrue, aIpcArgs);
   472     if (iWindowSizeCache == NULL)
   535     if (iWindowSizeCache == NULL)
   473         {
   536         {
   474         iWindowSizeCache = new (ELeave) RHashMap<TInt, TWindowSizeCacheEntry>();        
   537         iWindowSizeCache = new (ELeave) RHashMap<TInt, TWindowSizeCacheEntry>();        
   475         }
   538         }
   476     }
   539     }
   477 
       
   478 #ifdef SYMBIAN_GRAPHICS_FIXNATIVEORIENTATION
       
   479 void RWsBuffer::EnableWindowNativeSizeCacheL()
       
   480     {
       
   481     if (iWindowNativeSizeCache == NULL)
       
   482         {
       
   483         iWindowNativeSizeCache = new (ELeave) RHashMap<TInt, TWindowSizeCacheEntry>();        
       
   484         }
       
   485     }
       
   486 #endif // SYMBIAN_GRAPHICS_FIXNATIVEORIENTATION
       
   487