os/boardsupport/emulator/emulatorbsp/inc/display_chan.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-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
/**
sl@0
    17
 @file
sl@0
    18
 @publishedPartner
sl@0
    19
 @prototype
sl@0
    20
*/
sl@0
    21
sl@0
    22
#ifndef __DISPLAY_CHAN_H__
sl@0
    23
#define __DISPLAY_CHAN_H__
sl@0
    24
sl@0
    25
#include "nk_priv.h"
sl@0
    26
#include <dispchannel.h>
sl@0
    27
#include <videodriver.h>
sl@0
    28
#include "displayhandler.h"
sl@0
    29
sl@0
    30
struct TBufferAddressA;
sl@0
    31
class TScreenBuffer;
sl@0
    32
/**
sl@0
    33
Logical Channel kernel side class for Display
sl@0
    34
*/
sl@0
    35
sl@0
    36
sl@0
    37
class DDisplayChannel : public DLogicalChannel
sl@0
    38
	{
sl@0
    39
public:
sl@0
    40
	// constants
sl@0
    41
	enum { KDisplayChMajorVersionNumber = 1 };
sl@0
    42
	enum { KDisplayChMinorVersionNumber = 2 };
sl@0
    43
	enum { KDisplayChBuildVersionNumber = 1 };
sl@0
    44
public:
sl@0
    45
	// Duplicate of RDisplayChannel structure, as the header file cannot be used.
sl@0
    46
	class TCaps
sl@0
    47
    {
sl@0
    48
      public:
sl@0
    49
          TVersion iVersion;
sl@0
    50
    };
sl@0
    51
sl@0
    52
	class TRequest
sl@0
    53
		{
sl@0
    54
	public:
sl@0
    55
		inline TRequest(void) : iThread(0), iStatus(0) {}
sl@0
    56
		TBool SetStatus(TThreadMessage& aMsg);
sl@0
    57
		void Complete(TInt aResult);
sl@0
    58
	public:
sl@0
    59
		DThread* iThread;
sl@0
    60
		TRequestStatus* iStatus;
sl@0
    61
		};
sl@0
    62
sl@0
    63
	class TBufferInfo
sl@0
    64
		{
sl@0
    65
	public:
sl@0
    66
		TAny* iAddress;
sl@0
    67
		DChunk* iChunk;
sl@0
    68
		TRequest iRequest;
sl@0
    69
		};
sl@0
    70
sl@0
    71
	enum TDisplayPanic
sl@0
    72
		{
sl@0
    73
		EDisplayPanicNullThreadOnSet = 1,
sl@0
    74
		EDisplayPanicInUse = 2,
sl@0
    75
		EDisplayPanicThreadAlreadySet = 3,
sl@0
    76
		EDisplayPanicNullThreadOnComplete = 4,
sl@0
    77
		EDisplayPanicThreadOpenFailed = 5,
sl@0
    78
		EDisplayPanicWaitForPostMissed = 6,
sl@0
    79
		EDisplayPanicNullArgument = 7,
sl@0
    80
		EDisplayPanicNotYetImplemented = 8,
sl@0
    81
		EDisplayPanicInvalidDimensions = 9,
sl@0
    82
		EDisplayPanicInvalidRotation = 10,
sl@0
    83
		EDisplayPanicInvalidBitDepth = 11,
sl@0
    84
		EDisplayPanicInvalidStride = 12,
sl@0
    85
		EDisplayPanicInvalidWindowHandle = 13,
sl@0
    86
		EDisplayPanicInvalidFrameBuffers = 14,
sl@0
    87
		EDisplayPanicInvalidRefreshRate = 15,
sl@0
    88
		EDisplayPanicInvalidOffset = 16,
sl@0
    89
		EDisplayPanicNoLegacyBuffer = 17
sl@0
    90
		};
sl@0
    91
sl@0
    92
public:
sl@0
    93
	DDisplayChannel(void);
sl@0
    94
	~DDisplayChannel(void);
sl@0
    95
sl@0
    96
	// DLogicalChannel implementation
sl@0
    97
	virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
sl@0
    98
	virtual void HandleMsg(TMessageBase* aMsg);
sl@0
    99
sl@0
   100
	// Function used by the UI code to set up the buffers.
sl@0
   101
	virtual TInt Initialize(RDisplayChannel::TDisplayInfo& aInfo, 
sl@0
   102
							RDisplayChannel::TDisplayRotation aRotation,
sl@0
   103
							HWND aHwnd, RPointerArray<TAny>& aFrameBuffers, 
sl@0
   104
							RPointerArray<TBufferAddressA>& aChunks,
sl@0
   105
							TScreenBuffer& aDsaBuffer,
sl@0
   106
							TSize aResolution, 
sl@0
   107
							TSize aTwips,
sl@0
   108
							const RDisplayChannel::TPixelFormat aPixelFormatArray[],
sl@0
   109
							const TInt aPixelFormatArraySize,
sl@0
   110
							const RDisplayChannel::TBufferFormat& aBufferFormat);
sl@0
   111
	virtual void SetLegacyBuffer(void *aAddress);
sl@0
   112
sl@0
   113
private:
sl@0
   114
	DDisplayChannel(const DDisplayChannel&);
sl@0
   115
sl@0
   116
	// Handlers for the three classes of channel message sent
sl@0
   117
	TInt DoControl(TInt aFunction);
sl@0
   118
	void DoRequest(TInt aFunction);
sl@0
   119
	TInt DoCancel(TInt aRequestMask);
sl@0
   120
	TInt NumberOfResolutions();
sl@0
   121
	TInt SafePut(TAny* aDst, TAny* aSrc, TInt aBytes);
sl@0
   122
sl@0
   123
	void ValidateSpecificInfo(TInt aBytesPerPixel, RDisplayChannel::TOrientationSpecificInfo& aInfo);
sl@0
   124
	static void Panic(TDisplayPanic aPanic);
sl@0
   125
	void ClientPanic(RDisplayChannel::TPanic aPanic);
sl@0
   126
sl@0
   127
	inline TBool IsCompositionBuffer(RDisplayChannel::TBufferId aId);
sl@0
   128
	static inline TBool IsLegacyBuffer(RDisplayChannel::TBufferId aId);
sl@0
   129
	static inline TBool IsUserBuffer(RDisplayChannel::TBufferId aId);
sl@0
   130
	inline TBool IsValidBuffer(RDisplayChannel::TBufferId aId);
sl@0
   131
    inline RDisplayChannel::TBufferId NextCompositionBuffer(RDisplayChannel::TBufferId aId);
sl@0
   132
sl@0
   133
	static inline TBool IsFlipped(RDisplayChannel::TDisplayRotation aRotation);
sl@0
   134
sl@0
   135
	static void VSyncTimerFn(TAny* aDisplayChannel);
sl@0
   136
	void DoVSyncTimer(void);
sl@0
   137
	static void VSyncDfcFn(TAny* aDisplayChannel);
sl@0
   138
	void DoVSync(void);
sl@0
   139
sl@0
   140
	TInt PostCompositionBuffer(TAny* aRegion, RDisplayChannel::TPostCount* aPostCount);
sl@0
   141
	TInt PostLegacyBuffer(TAny* aRegion, RDisplayChannel::TPostCount* aPostCount);
sl@0
   142
	TInt GetCompositionBuffer(TAny** aAddress);
sl@0
   143
	TInt PostUserBuffer(RDisplayChannel::TBufferId* aBufferId, TAny* aRegion, RDisplayChannel::TPostCount* aPostCount);
sl@0
   144
	TInt WaitForPost(RDisplayChannel::TPostCount* aPostCount);
sl@0
   145
	TInt WaitForDisplayConnect();
sl@0
   146
	TInt SetRotation(RDisplayChannel::TDisplayRotation* aNewRotation, TBool* aIsBufferPreserved);
sl@0
   147
	TInt RegisterUserBuffer(TInt aChunkHandle, TInt aOffset, RDisplayChannel::TBufferId* aBufferId);
sl@0
   148
	TInt DeregisterUserBuffer(RDisplayChannel::TBufferId* aBufferId);
sl@0
   149
	TInt GetResolutions();
sl@0
   150
	TInt SetResolution(TSize* aSize);
sl@0
   151
	TInt GetResolution(TSize* aSize);
sl@0
   152
	TInt GetTwips(TSize* aSize);
sl@0
   153
	TInt GetIndexForSize(const TSize& aSize,TInt& aSpinnerOut);
sl@0
   154
	TInt GetPixelFormats();
sl@0
   155
	TInt SetBufferFormat(RDisplayChannel::TBufferFormat* aBufferFormat);
sl@0
   156
	TInt NextPlaneOffset(RDisplayChannel::TBufferFormat* aBufferFormat, 
sl@0
   157
			            RDisplayChannel::TBufferFormatContext* aContext);
sl@0
   158
	TInt NextLineOffset(RDisplayChannel::TBufferFormat* aBufferFormat, 
sl@0
   159
			            RDisplayChannel::TBufferFormatContext* aContext);
sl@0
   160
	TInt ValidateBufferFormat(const RDisplayChannel::TBufferFormat& aBufferFormat,
sl@0
   161
						 	  const RDisplayChannel::TResolution& aResolution);
sl@0
   162
private:
sl@0
   163
	// Constants
sl@0
   164
	enum {KDfcPriority = 6};
sl@0
   165
sl@0
   166
	enum {KBufferNotSet = -1};
sl@0
   167
sl@0
   168
	// Buffer index points. The legacy buffer is first, followed by the user
sl@0
   169
	// buffers, followed by a variable number of composition buffers.
sl@0
   170
	enum { KLegacyBuffer = 0};
sl@0
   171
	enum { KFirstUserBuffer = KLegacyBuffer + 1};
sl@0
   172
	enum { KFirstCompositionBuffer = KFirstUserBuffer + RDisplayChannel::TDisplayInfo::KMaxUserBuffers};
sl@0
   173
	enum { KMaxBufferSizeHeightAndWidth = KMaxTInt16 };
sl@0
   174
sl@0
   175
private:
sl@0
   176
	TInt iScreenNumber;
sl@0
   177
	TThreadMessage* iMsg;
sl@0
   178
	TInt iVSyncTicks;					// Number of nanokernel ticks between frames
sl@0
   179
	TUint iNumCompositionBuffers;		// Number of composition buffers
sl@0
   180
	TUint iTotalBuffers;				// KFirstCompositionBuffer + iNumCompositionBuffers
sl@0
   181
	RDisplayChannel::TDisplayInfo iChannelInfo;
sl@0
   182
	RDisplayChannel::TPostCount iPostCount;				// Count of Post... calls
sl@0
   183
	RDisplayChannel::TPostCount iLastPostCount;			// Value of iPostCount when last buffer was actually posted
sl@0
   184
	TBufferInfo* iBuffer;				// Allocated to contain iTotalBuffers
sl@0
   185
	TBufferAddressA* iChunks;
sl@0
   186
	DThread* iClient;
sl@0
   187
sl@0
   188
	// Posting support
sl@0
   189
	NTimer iVSync;						// Emulated VSync signal using a timer
sl@0
   190
	TDfc iVSyncDfc;						// DFC queued on DfcQue0 when iVSync triggers
sl@0
   191
	RDisplayChannel::TBufferId iPostedBuffer;			// Index of buffer to be posted on next frame
sl@0
   192
	RDisplayChannel::TDisplayRotation iCurrentRotation;	// Rotation of buffer being posted
sl@0
   193
	RDisplayChannel::TDisplayRotation iNewRotation;	// Rotation of buffer being posted
sl@0
   194
	TSize iCurrentResolution;			// Display resolution (normal rotation) to be posted
sl@0
   195
	TSize iNewResolution;			    // Display resolution (normal rotation) for buffer being posted
sl@0
   196
	TSize iCurrentTwips;
sl@0
   197
	TInt iPostedRectCount;				// Number of rectangles defined in region
sl@0
   198
	RECT iPostedRect[RDisplayChannel::TDisplayInfo::KMaxRectangles];	//
sl@0
   199
sl@0
   200
	// Paint support
sl@0
   201
	HWND iHwnd;							// Window to be painted
sl@0
   202
	RDisplayChannel::TBufferId iDisplayBuffer;			// Index of buffer to be painted
sl@0
   203
	RDisplayChannel::TDisplayRotation iDisplayRotation;	// Rotation of buffer to be painted
sl@0
   204
	TSize iDisplayResolution;			// Display resolution (normal rotation) on screen
sl@0
   205
sl@0
   206
	// GetCompositionBuffer support
sl@0
   207
	TUint iGetBuffer;					// Index of next composition buffer
sl@0
   208
sl@0
   209
	// WaitForPost support
sl@0
   210
	RDisplayChannel::TPostCount iWaitForPost;			// Post count being awaited
sl@0
   211
	TRequest iWaitForPostRequest;		// Request to complete when post count reached
sl@0
   212
	
sl@0
   213
	// WaitForDisplayConnect support 
sl@0
   214
	TRequest iWaitForDisplayConnect;		// Request to complete when display connection state changes
sl@0
   215
	
sl@0
   216
	TInt iDisplayStateSpinner;
sl@0
   217
	
sl@0
   218
	TVersion iVersion;
sl@0
   219
	const RDisplayChannel::TPixelFormat* iPixelFormatArray;
sl@0
   220
	TInt iPixelFormatArraySize;
sl@0
   221
	RDisplayChannel::TBufferFormat iInitialBufferFormat;
sl@0
   222
	RDisplayChannel::TBufferFormat iCurrentBufferFormat;
sl@0
   223
	RDisplayChannel::TBufferFormat iDisplayBufferFormat;
sl@0
   224
	RDisplayChannel::TBufferFormat iNewBufferFormat;
sl@0
   225
	};
sl@0
   226
sl@0
   227
inline TBool DDisplayChannel::IsCompositionBuffer(RDisplayChannel::TBufferId aId)
sl@0
   228
	{ return (aId >= KFirstCompositionBuffer && aId < iTotalBuffers); }
sl@0
   229
inline TBool DDisplayChannel::IsLegacyBuffer(RDisplayChannel::TBufferId aId)
sl@0
   230
	{ return (aId == KLegacyBuffer); }
sl@0
   231
inline TBool DDisplayChannel::IsUserBuffer(RDisplayChannel::TBufferId aId)
sl@0
   232
	{ return (aId >= KFirstUserBuffer && aId < (KFirstUserBuffer + RDisplayChannel::TDisplayInfo::KMaxUserBuffers)); }
sl@0
   233
inline TBool DDisplayChannel::IsValidBuffer(RDisplayChannel::TBufferId aId)
sl@0
   234
	{ return (aId >= 0 && aId < iTotalBuffers); }
sl@0
   235
inline RDisplayChannel::TBufferId DDisplayChannel::NextCompositionBuffer(RDisplayChannel::TBufferId aId)
sl@0
   236
	{ TUint r = (aId + 1); return (r >= iTotalBuffers) ? KFirstCompositionBuffer : r; }
sl@0
   237
sl@0
   238
inline TBool DDisplayChannel::IsFlipped(RDisplayChannel::TDisplayRotation aRotation)
sl@0
   239
	{ return !(aRotation & (RDisplayChannel::ERotationNormal | RDisplayChannel::ERotation180)); }
sl@0
   240
sl@0
   241
#endif
sl@0
   242