os/graphics/windowing/windowserver/nonnga/graphicdrawer/graphicmsgbuf.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "Graphics/WSGRAPHICMSGBUF.H"
sl@0
    17
#include "W32STDGRAPHIC.H"
sl@0
    18
sl@0
    19
#define KSizeOfTInt (TInt)sizeof(TInt)
sl@0
    20
sl@0
    21
// TWsGraphicMsgBufParser \\\\\\\\\\\\\\\\\\\\\\\\
sl@0
    22
sl@0
    23
EXPORT_C TWsGraphicMsgBufParser::TWsGraphicMsgBufParser(const TDesC8& aData): iData(aData)
sl@0
    24
/** Initialise a parser for the specified message buffer */
sl@0
    25
	{
sl@0
    26
	}
sl@0
    27
sl@0
    28
EXPORT_C TInt TWsGraphicMsgBufParser::Verify() const
sl@0
    29
/** Verifies that the message buffer is properly formed
sl@0
    30
	@return KErrNone if buffer is ok, else a system-wide error code */
sl@0
    31
	{
sl@0
    32
	const TInt length = iData.Length();
sl@0
    33
	TInt ofs = 0;
sl@0
    34
	const TInt tmp = (length - sizeof(TInt));
sl@0
    35
	while(ofs < tmp)
sl@0
    36
		{
sl@0
    37
		ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2);
sl@0
    38
		}
sl@0
    39
	if(ofs == length)
sl@0
    40
		{
sl@0
    41
		return KErrNone;
sl@0
    42
		}
sl@0
    43
	return KErrCorrupt;
sl@0
    44
	}
sl@0
    45
sl@0
    46
EXPORT_C TInt TWsGraphicMsgBufParser::Count() const
sl@0
    47
/** Returns the number of elements in the buffer.
sl@0
    48
@return the count of elements.
sl@0
    49
*/
sl@0
    50
	{
sl@0
    51
	const TInt length = iData.Length();
sl@0
    52
	TInt ofs = 0, count = 0;
sl@0
    53
	while(ofs < length)
sl@0
    54
		{
sl@0
    55
		count++;
sl@0
    56
		ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2);
sl@0
    57
		}
sl@0
    58
	return count;
sl@0
    59
	}
sl@0
    60
sl@0
    61
EXPORT_C TUid TWsGraphicMsgBufParser::Uid(TInt aIndex) const
sl@0
    62
/** Returns the UID if the message, or null UID if the buffer is empty.
sl@0
    63
@return KNullUid if the buffer is empty, otherwise the stored Uid
sl@0
    64
*/
sl@0
    65
	{
sl@0
    66
	const TInt length = iData.Length();
sl@0
    67
	TInt ofs = 0, count = 0;
sl@0
    68
	while(ofs < length)
sl@0
    69
		{
sl@0
    70
		if(count == aIndex)
sl@0
    71
			{
sl@0
    72
			return TUid::Uid(IntAt(ofs));
sl@0
    73
			}
sl@0
    74
		count++;
sl@0
    75
		ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2);
sl@0
    76
		}
sl@0
    77
	return KNullUid;
sl@0
    78
	}
sl@0
    79
sl@0
    80
EXPORT_C TPtrC8 TWsGraphicMsgBufParser::Data(TInt aIndex) const
sl@0
    81
/**Returns the buffer contents at a perticular offset (aIndex).
sl@0
    82
@param aIndex - the index into of the buffer element required.
sl@0
    83
@return KNullDesC8 if index is more than the element count, otherwise, the element at index aIndex.
sl@0
    84
*/
sl@0
    85
	{
sl@0
    86
	const TInt length = iData.Length();
sl@0
    87
	TInt ofs = 0, count = 0;
sl@0
    88
	while(ofs < length)
sl@0
    89
		{
sl@0
    90
		if(count == aIndex)
sl@0
    91
			{
sl@0
    92
			return iData.Mid(ofs+(KSizeOfTInt*2),IntAt(ofs+KSizeOfTInt));
sl@0
    93
			}
sl@0
    94
		count++;
sl@0
    95
		ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2);
sl@0
    96
		}
sl@0
    97
	return TPtrC8(KNullDesC8());
sl@0
    98
	}
sl@0
    99
sl@0
   100
EXPORT_C TInt TWsGraphicMsgBufParser::Find(TUid aUid,TInt aStartingFrom) const
sl@0
   101
/** Finds the element equal to the aUid, and returns the index of the element in the buffer.
sl@0
   102
@param aUid - the search item to be found in the buffer.
sl@0
   103
@param aStartingFrom - the starting index.
sl@0
   104
@return the position (index) of the found element, or KErrNotFound
sl@0
   105
*/
sl@0
   106
	{
sl@0
   107
	const TInt length = iData.Length();
sl@0
   108
	TInt ofs = 0, count = 0;
sl@0
   109
	while(ofs < length)
sl@0
   110
		{
sl@0
   111
		if((count >= aStartingFrom) && (aUid == TUid::Uid(IntAt(ofs))))
sl@0
   112
			{
sl@0
   113
			return count;
sl@0
   114
			}
sl@0
   115
		count++;
sl@0
   116
		ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2);
sl@0
   117
		}
sl@0
   118
	return KErrNotFound;
sl@0
   119
	}
sl@0
   120
sl@0
   121
EXPORT_C TBool TWsGraphicMsgBufParser::LoadFixed(TUid aUid,TAny* aMsg,TInt aMsgSize,TInt aStartingFrom) const
sl@0
   122
/** Loads the buffer of aMsg with the contents of the buffer, based on the aUid and aMsgSize.
sl@0
   123
@param aUid - the Uid to match after which the loading is performed.
sl@0
   124
@param aMsg - the pointer to the output buffer.
sl@0
   125
@param aMsgSize - the size of the output buffer.
sl@0
   126
@param aStartingFrom - the starting position to be used in the search of the buffer.
sl@0
   127
@return ETrue if loaded, EFalse otherwise.
sl@0
   128
*/
sl@0
   129
	{
sl@0
   130
	const TInt length = iData.Length();
sl@0
   131
	TInt ofs = 0, count = 0;
sl@0
   132
	while(ofs < length)
sl@0
   133
		{
sl@0
   134
		if((count >= aStartingFrom) && (aUid == TUid::Uid(IntAt(ofs))))
sl@0
   135
			{
sl@0
   136
			// found it?  return it
sl@0
   137
			const TInt len = IntAt(ofs+KSizeOfTInt);
sl@0
   138
			if(len == aMsgSize)
sl@0
   139
				{
sl@0
   140
				TPtr8 msg(reinterpret_cast<TUint8*>(aMsg),aMsgSize);
sl@0
   141
				msg = iData.Mid(ofs+(KSizeOfTInt*2),len);
sl@0
   142
				return ETrue;
sl@0
   143
				}
sl@0
   144
			else // message was not the expected size!
sl@0
   145
				{
sl@0
   146
				return EFalse;
sl@0
   147
				}
sl@0
   148
			}
sl@0
   149
		count++;
sl@0
   150
		ofs += IntAt(ofs+KSizeOfTInt) + (KSizeOfTInt*2);
sl@0
   151
		}
sl@0
   152
	return EFalse;
sl@0
   153
	}
sl@0
   154
sl@0
   155
TInt TWsGraphicMsgBufParser::IntAt(TInt aOfs) const
sl@0
   156
/** @internalComponent @released */
sl@0
   157
	{
sl@0
   158
	if((aOfs < 0) || ((aOfs+KSizeOfTInt) > iData.Length()))
sl@0
   159
		{
sl@0
   160
		return 0;
sl@0
   161
		}
sl@0
   162
	TInt ret;
sl@0
   163
	memcpy(&ret,iData.Ptr()+aOfs,KSizeOfTInt);
sl@0
   164
	return ret;
sl@0
   165
	}
sl@0
   166
sl@0
   167
// TWsGraphicMsgAnimation \\\\\\\\\\\\\\\\\\\\\\\\
sl@0
   168
sl@0
   169
EXPORT_C TWsGraphicMsgAnimation::TWsGraphicMsgAnimation(): iFlags(EStopped)
sl@0
   170
	{
sl@0
   171
	}
sl@0
   172
sl@0
   173
EXPORT_C TInt TWsGraphicMsgAnimation::Load(const TWsGraphicMsgBufParser& aData)
sl@0
   174
	{
sl@0
   175
	const TInt index = aData.Find(TUid::Uid(TWsGraphicAnimation::ETypeId));
sl@0
   176
	if(index >= 0)
sl@0
   177
		{
sl@0
   178
		return Load(aData,index);
sl@0
   179
		}
sl@0
   180
	return index;
sl@0
   181
	}
sl@0
   182
sl@0
   183
EXPORT_C TInt TWsGraphicMsgAnimation::Load(const TWsGraphicMsgBufParser& aData,TInt aIndex)
sl@0
   184
	{
sl@0
   185
	if(aData.Uid(aIndex).iUid != TWsGraphicAnimation::ETypeId)
sl@0
   186
		{
sl@0
   187
		return KErrArgument;
sl@0
   188
		}
sl@0
   189
	const TPtrC8 pckg = aData.Data(aIndex);
sl@0
   190
	if(pckg.Size() != sizeof(TWsGraphicMsgAnimation))
sl@0
   191
		{
sl@0
   192
		return KErrCorrupt;
sl@0
   193
		}
sl@0
   194
	memcpy(this,pckg.Ptr(),sizeof(TWsGraphicMsgAnimation));
sl@0
   195
	return KErrNone;
sl@0
   196
	}
sl@0
   197
sl@0
   198
EXPORT_C TTimeIntervalMicroSeconds TWsGraphicMsgAnimation::AnimationTime(const TTime& aNow,const TTimeIntervalMicroSeconds& aAnimationLength) const
sl@0
   199
	{
sl@0
   200
	// an animation to time?
sl@0
   201
	if(aAnimationLength <= 0LL)
sl@0
   202
		{
sl@0
   203
		return 0LL;
sl@0
   204
		}
sl@0
   205
	switch(iFlags & EStateMask)
sl@0
   206
		{
sl@0
   207
		case EPaused:
sl@0
   208
			return ((iPauseOrStopping.Int64() - iPlay.Int64()) % aAnimationLength.Int64());
sl@0
   209
		case EStopping:
sl@0
   210
			{
sl@0
   211
			const TInt64 elapsed = (aNow.Int64() - iPlay.Int64());
sl@0
   212
			if(elapsed <= aAnimationLength.Int64())
sl@0
   213
				{
sl@0
   214
				return (elapsed % aAnimationLength.Int64());
sl@0
   215
				}
sl@0
   216
			return 0LL;
sl@0
   217
			}
sl@0
   218
		case EStopped:
sl@0
   219
			return 0LL;
sl@0
   220
		case EPlaying:
sl@0
   221
			{
sl@0
   222
			const TInt64 elapsed = (aNow.Int64() - iPlay.Int64());
sl@0
   223
			if((iFlags & ELoop) || (elapsed <= aAnimationLength.Int64()))
sl@0
   224
				{
sl@0
   225
				return (elapsed % aAnimationLength.Int64());
sl@0
   226
				}
sl@0
   227
			return 0LL;
sl@0
   228
			}
sl@0
   229
		default:
sl@0
   230
			return 0LL;
sl@0
   231
		}
sl@0
   232
	}
sl@0
   233
sl@0
   234
EXPORT_C TBool TWsGraphicMsgAnimation::IsPlaying(const TTime& aNow,const TTimeIntervalMicroSeconds& aAnimationLength) const
sl@0
   235
	{
sl@0
   236
	// an animation to time?
sl@0
   237
	if(aAnimationLength <= 0LL)
sl@0
   238
		{
sl@0
   239
		return EFalse;
sl@0
   240
		}
sl@0
   241
	switch(iFlags & EStateMask)
sl@0
   242
		{
sl@0
   243
		case EPaused:
sl@0
   244
			return EFalse;
sl@0
   245
		case EStopping:
sl@0
   246
			{
sl@0
   247
			const TInt64 elapsed = (aNow.Int64() - iPlay.Int64());
sl@0
   248
			if(elapsed <= aAnimationLength.Int64())
sl@0
   249
				{
sl@0
   250
				return ETrue;
sl@0
   251
				}
sl@0
   252
			return EFalse;
sl@0
   253
			}
sl@0
   254
		case EStopped:
sl@0
   255
			return EFalse;
sl@0
   256
		case EPlaying:
sl@0
   257
			{
sl@0
   258
			const TInt64 elapsed = (aNow.Int64() - iPlay.Int64());
sl@0
   259
			if((iFlags & ELoop) || (elapsed <= aAnimationLength.Int64()))
sl@0
   260
				{
sl@0
   261
				return ETrue;
sl@0
   262
				}
sl@0
   263
			return EFalse;
sl@0
   264
			}
sl@0
   265
		default:
sl@0
   266
			return EFalse;
sl@0
   267
		}
sl@0
   268
	}
sl@0
   269