os/graphics/windowing/windowserver/nga/SERVER/EVQUEUE.H
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1999-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
// Definition of classes related event queues
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#if !defined(__EVQUEUE_H__)
sl@0
    19
#define __EVQUEUE_H__
sl@0
    20
sl@0
    21
#include <e32std.h>
sl@0
    22
#include <e32base.h>
sl@0
    23
#include <graphics/WSGRAPHICDRAWERINTERFACE.H>
sl@0
    24
#include "W32STD.H"
sl@0
    25
sl@0
    26
class CWsClient;
sl@0
    27
class CWsWindowRedraw;
sl@0
    28
class CWsGraphicDrawer;
sl@0
    29
sl@0
    30
enum TEventQueueWalkRet
sl@0
    31
	{
sl@0
    32
	EEventQueueWalkOk,
sl@0
    33
	EEventQueueWalkDeleteEvent,
sl@0
    34
	EEventQueueWalkRestart,
sl@0
    35
	};
sl@0
    36
class TWsEvent;
sl@0
    37
sl@0
    38
typedef TEventQueueWalkRet (*EventQueueWalk)(TAny* aPtr, TWsEvent* aEvent);
sl@0
    39
sl@0
    40
enum TWservEventPriorities
sl@0
    41
	{
sl@0
    42
	EEventPriorityHigh,
sl@0
    43
	EEventPriorityLow,
sl@0
    44
	};
sl@0
    45
sl@0
    46
struct TRedraw
sl@0
    47
	{
sl@0
    48
	CWsWindowRedraw* iRedraw;
sl@0
    49
	TUint iPriority;
sl@0
    50
	};
sl@0
    51
sl@0
    52
class CEventBase : public CBase
sl@0
    53
	{
sl@0
    54
private:
sl@0
    55
	enum TEventSignalledState
sl@0
    56
		{
sl@0
    57
		EEventFlagSignalled=0x1,
sl@0
    58
		EEventFlagCancelled=0x2
sl@0
    59
		};
sl@0
    60
public:
sl@0
    61
	CEventBase(CWsClient* aOwner);
sl@0
    62
	~CEventBase();
sl@0
    63
	void CancelRead();
sl@0
    64
	void EventReadyCheck();
sl@0
    65
	virtual void EventReady(const RMessagePtr2& aEventMsg);
sl@0
    66
	void GetData(TAny* aData, TInt aLen);
sl@0
    67
protected:
sl@0
    68
	void SignalEvent(TInt aCode = KErrNone);
sl@0
    69
	inline TBool IsEventCancelled();
sl@0
    70
protected:
sl@0
    71
	TInt iEventSignalledState;
sl@0
    72
	CWsClient* iWsOwner;
sl@0
    73
	RMessagePtr2 iEventMsg;
sl@0
    74
	};
sl@0
    75
sl@0
    76
class CEventQueue : public CEventBase
sl@0
    77
	{
sl@0
    78
private:
sl@0
    79
	enum {EExtraQueueSize=16};
sl@0
    80
	enum {EMaxQueueSize=32};
sl@0
    81
	enum {EMinQueueSize=2};
sl@0
    82
	enum {EQueueGranularity=4};
sl@0
    83
	enum TCompressMode
sl@0
    84
		{
sl@0
    85
		ECompressNoPurge,	// Compress only free space
sl@0
    86
		ECompressPurge1,	// Purge from only non-foreground queues
sl@0
    87
		ECompressPurge2,	// Purge from all queues
sl@0
    88
		};
sl@0
    89
// Functions
sl@0
    90
public:
sl@0
    91
	CEventQueue(CWsClient* aOwner);
sl@0
    92
	~CEventQueue();
sl@0
    93
	void ConstructL();
sl@0
    94
	TBool QueueEvent(const TWsEvent &event);
sl@0
    95
	TBool QueueEvent(const TWsEvent &event, TWservEventPriorities aPriority);
sl@0
    96
	TBool QueueEvent(TUint32 aTarget, TInt aEvent, TInt aIntVal = 0);
sl@0
    97
	TBool CheckRoom();
sl@0
    98
	void GetData();
sl@0
    99
	void UpdateLastEvent(const TWsEvent &event);
sl@0
   100
	TBool UpdateLastPointerEvent(const TWsEvent &event);
sl@0
   101
	void RemoveEvent(TInt index);
sl@0
   102
	void PurgePointerEvents();
sl@0
   103
	const TWsEvent* PeekLastEvent();
sl@0
   104
	void WalkEventQueue(EventQueueWalk aFunc, TAny* aFuncParam);
sl@0
   105
	void MoveToFront();
sl@0
   106
	static void Wait();
sl@0
   107
	static void Signal();
sl@0
   108
	static void InitStaticsL();
sl@0
   109
	static void DeleteStaticsL();
sl@0
   110
	//void LogUpDownEvents(TChar aChar);
sl@0
   111
public:// from CEventBase
sl@0
   112
	void EventReady(const RMessagePtr2& aEventMsg);
sl@0
   113
private:
sl@0
   114
	static void EventCopy(TWsEvent* aStart, TWsEvent* aEnd, TInt aNumEvents);
sl@0
   115
	static TInt RequiredQueueSize(TInt aNumConnections);
sl@0
   116
	void AdjustQueueSizeL(TInt aNewSize);
sl@0
   117
	void IncreaseQueueSize(TInt aNumSpaces);
sl@0
   118
	TInt FollowingGap() const;
sl@0
   119
	void Purge();
sl@0
   120
	TInt PurgeInactiveEvents(const TInt& aSizeRequired);
sl@0
   121
	void Compress(TCompressMode aCompressMode);
sl@0
   122
	void AddQueueL();
sl@0
   123
	void RemoveQueue();
sl@0
   124
	TBool Expand(TWservEventPriorities aPriority);
sl@0
   125
	TBool doExpand(TCompressMode aCompressMode);
sl@0
   126
	TInt SqueezeUp();
sl@0
   127
	void SqueezeDown();
sl@0
   128
	void MoveUp(TInt aMove);
sl@0
   129
	void MoveDown(TInt aMove);
sl@0
   130
	TBool MoveDownAndExpand(TDblQueIter<CEventQueue> &aIter, TInt aExpand);
sl@0
   131
#if defined(_DEBUG)
sl@0
   132
	void CheckQueue();
sl@0
   133
	void ZapEvent(TWsEvent* aTarget);
sl@0
   134
	void ZapEvents(TWsEvent* aTarget, TInt aLen);
sl@0
   135
#endif
sl@0
   136
private:
sl@0
   137
	void QueueActive();
sl@0
   138
	TWsEvent* EventPtr(TInt index);
sl@0
   139
	void RemoveEvent(TWsEvent* aEvToRemove);
sl@0
   140
	inline void IncEventPointer(TWsEvent*& aEventPtr);	
sl@0
   141
	inline void DecEventPointer(TWsEvent*& aEventPtr);	
sl@0
   142
	void PurgeEventPairs(TWsEvent* aEventToPurge, TPointerEvent::TType aMatchingType, TPointerEvent::TType aSearchTerminator);
sl@0
   143
	TWsEvent* NextPointerEvent(TWsEvent* aBaseEvent);
sl@0
   144
	TBool CheckPurgePointerEvent(TWsEvent* aEventToPurge);
sl@0
   145
private:
sl@0
   146
    /** Position of head in local queue relative to iEventPtr. 
sl@0
   147
        First event to send to the Client. */ 
sl@0
   148
	TInt iHead;
sl@0
   149
	
sl@0
   150
	/** Number of events waiting in local queue */
sl@0
   151
    TInt iCount;
sl@0
   152
    
sl@0
   153
    /** Size of local queue = maximum number of events */
sl@0
   154
    TInt iQueueSize;
sl@0
   155
    
sl@0
   156
    /** Beginning of local queue */
sl@0
   157
    TWsEvent* iEventPtr;
sl@0
   158
    
sl@0
   159
    /** Used by iQueueList to link local queues */
sl@0
   160
	TDblQueLink iLink;
sl@0
   161
	
sl@0
   162
	/** Mutex for operations on global event queue */
sl@0
   163
	static RMutex iMutex;
sl@0
   164
	
sl@0
   165
	/** Always filled with zeros */
sl@0
   166
	static TWsEvent iNullEvent;
sl@0
   167
	
sl@0
   168
	/** List of event queues */
sl@0
   169
	static TDblQue<CEventQueue> iQueueList;
sl@0
   170
	
sl@0
   171
	/** Global queue that keeps all events queues */
sl@0
   172
	static TWsEvent* iGlobalEventQueue;
sl@0
   173
	
sl@0
   174
	/** Size of global queue */
sl@0
   175
	static TInt iGlobalEventQueueSize;
sl@0
   176
	
sl@0
   177
	/** Number of event queues */
sl@0
   178
	static TInt iNumConnections;
sl@0
   179
	};
sl@0
   180
sl@0
   181
class TWsRedrawEvent;
sl@0
   182
sl@0
   183
class CRedrawQueue : public CEventBase
sl@0
   184
	{
sl@0
   185
// Functions
sl@0
   186
public:
sl@0
   187
	CRedrawQueue(CWsClient *aOwner);
sl@0
   188
	~CRedrawQueue();
sl@0
   189
	void ConstructL();
sl@0
   190
	TBool TriggerRedraw();
sl@0
   191
	void ReCalcOrder();
sl@0
   192
	void AddInvalid(CWsWindowRedraw *redrawWin);
sl@0
   193
	void RemoveInvalid(CWsWindowRedraw *redrawWin);
sl@0
   194
	void GetData();
sl@0
   195
	TUint RedrawPriority(CWsWindowRedraw *aRedrawWin);
sl@0
   196
public:// from CEventBase
sl@0
   197
	void EventReady(const RMessagePtr2& aEventMsg);
sl@0
   198
private:
sl@0
   199
	void DeleteFromQueue(TInt aIndex);
sl@0
   200
	void QueueActive();
sl@0
   201
	TBool FindOutstandingRedrawEvent(CWsWindowRedraw& aRedraw, TWsRedrawEvent& aEvent);
sl@0
   202
	TBool FindWindowNeedingRedrawEvent(TWsRedrawEvent& aEvent);
sl@0
   203
private:
sl@0
   204
// Data
sl@0
   205
	CArrayFixSeg<TRedraw> *iRedraws;	// List of windows and their areas that require redraws
sl@0
   206
	TBool iAllocError;
sl@0
   207
	TBool iRedrawTrigger;
sl@0
   208
	TKeyArrayFix *iKeyPriority;
sl@0
   209
	TKeyArrayFix *iKeyWindow;
sl@0
   210
	static TWsRedrawEvent iNullRedrawEvent;
sl@0
   211
	};
sl@0
   212
sl@0
   213
class CWsGraphicMessageQueue: public CEventBase
sl@0
   214
	{
sl@0
   215
public:
sl@0
   216
	class CMessage: public CWsMessageData
sl@0
   217
		{
sl@0
   218
	public:
sl@0
   219
		static CMessage* New(const TDesC8& aData);
sl@0
   220
		~CMessage();
sl@0
   221
	public: // From CWsMessageData
sl@0
   222
		TPtrC8 Data() const;
sl@0
   223
		void Release();
sl@0
   224
	private:
sl@0
   225
		CMessage(const TDesC8& aData);
sl@0
   226
	private:
sl@0
   227
		TPtr8 iData;
sl@0
   228
		};
sl@0
   229
public:
sl@0
   230
	CWsGraphicMessageQueue(CWsClient *aOwner);
sl@0
   231
	~CWsGraphicMessageQueue();
sl@0
   232
	void GetGraphicMessage();
sl@0
   233
	void AbortMessage(TInt aError);
sl@0
   234
	void EventReady(const RMessagePtr2& aEventMsg);
sl@0
   235
	void Queue(CWsMessageData* aMessage);
sl@0
   236
	TInt TopClientHandle() const;
sl@0
   237
private:
sl@0
   238
	CWsMessageData* iHead;
sl@0
   239
	CWsMessageData* iTail;
sl@0
   240
	CWsMessageData* Pop();
sl@0
   241
	void GetDataWithHeader(TUint aHeader, const TDesC8& aData, TInt aDataLen);
sl@0
   242
	};
sl@0
   243
sl@0
   244
#endif