os/boardsupport/emulator/emulatorbsp/inc/display_chan.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/boardsupport/emulator/emulatorbsp/inc/display_chan.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,242 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @publishedPartner
    1.22 + @prototype
    1.23 +*/
    1.24 +
    1.25 +#ifndef __DISPLAY_CHAN_H__
    1.26 +#define __DISPLAY_CHAN_H__
    1.27 +
    1.28 +#include "nk_priv.h"
    1.29 +#include <dispchannel.h>
    1.30 +#include <videodriver.h>
    1.31 +#include "displayhandler.h"
    1.32 +
    1.33 +struct TBufferAddressA;
    1.34 +class TScreenBuffer;
    1.35 +/**
    1.36 +Logical Channel kernel side class for Display
    1.37 +*/
    1.38 +
    1.39 +
    1.40 +class DDisplayChannel : public DLogicalChannel
    1.41 +	{
    1.42 +public:
    1.43 +	// constants
    1.44 +	enum { KDisplayChMajorVersionNumber = 1 };
    1.45 +	enum { KDisplayChMinorVersionNumber = 2 };
    1.46 +	enum { KDisplayChBuildVersionNumber = 1 };
    1.47 +public:
    1.48 +	// Duplicate of RDisplayChannel structure, as the header file cannot be used.
    1.49 +	class TCaps
    1.50 +    {
    1.51 +      public:
    1.52 +          TVersion iVersion;
    1.53 +    };
    1.54 +
    1.55 +	class TRequest
    1.56 +		{
    1.57 +	public:
    1.58 +		inline TRequest(void) : iThread(0), iStatus(0) {}
    1.59 +		TBool SetStatus(TThreadMessage& aMsg);
    1.60 +		void Complete(TInt aResult);
    1.61 +	public:
    1.62 +		DThread* iThread;
    1.63 +		TRequestStatus* iStatus;
    1.64 +		};
    1.65 +
    1.66 +	class TBufferInfo
    1.67 +		{
    1.68 +	public:
    1.69 +		TAny* iAddress;
    1.70 +		DChunk* iChunk;
    1.71 +		TRequest iRequest;
    1.72 +		};
    1.73 +
    1.74 +	enum TDisplayPanic
    1.75 +		{
    1.76 +		EDisplayPanicNullThreadOnSet = 1,
    1.77 +		EDisplayPanicInUse = 2,
    1.78 +		EDisplayPanicThreadAlreadySet = 3,
    1.79 +		EDisplayPanicNullThreadOnComplete = 4,
    1.80 +		EDisplayPanicThreadOpenFailed = 5,
    1.81 +		EDisplayPanicWaitForPostMissed = 6,
    1.82 +		EDisplayPanicNullArgument = 7,
    1.83 +		EDisplayPanicNotYetImplemented = 8,
    1.84 +		EDisplayPanicInvalidDimensions = 9,
    1.85 +		EDisplayPanicInvalidRotation = 10,
    1.86 +		EDisplayPanicInvalidBitDepth = 11,
    1.87 +		EDisplayPanicInvalidStride = 12,
    1.88 +		EDisplayPanicInvalidWindowHandle = 13,
    1.89 +		EDisplayPanicInvalidFrameBuffers = 14,
    1.90 +		EDisplayPanicInvalidRefreshRate = 15,
    1.91 +		EDisplayPanicInvalidOffset = 16,
    1.92 +		EDisplayPanicNoLegacyBuffer = 17
    1.93 +		};
    1.94 +
    1.95 +public:
    1.96 +	DDisplayChannel(void);
    1.97 +	~DDisplayChannel(void);
    1.98 +
    1.99 +	// DLogicalChannel implementation
   1.100 +	virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
   1.101 +	virtual void HandleMsg(TMessageBase* aMsg);
   1.102 +
   1.103 +	// Function used by the UI code to set up the buffers.
   1.104 +	virtual TInt Initialize(RDisplayChannel::TDisplayInfo& aInfo, 
   1.105 +							RDisplayChannel::TDisplayRotation aRotation,
   1.106 +							HWND aHwnd, RPointerArray<TAny>& aFrameBuffers, 
   1.107 +							RPointerArray<TBufferAddressA>& aChunks,
   1.108 +							TScreenBuffer& aDsaBuffer,
   1.109 +							TSize aResolution, 
   1.110 +							TSize aTwips,
   1.111 +							const RDisplayChannel::TPixelFormat aPixelFormatArray[],
   1.112 +							const TInt aPixelFormatArraySize,
   1.113 +							const RDisplayChannel::TBufferFormat& aBufferFormat);
   1.114 +	virtual void SetLegacyBuffer(void *aAddress);
   1.115 +
   1.116 +private:
   1.117 +	DDisplayChannel(const DDisplayChannel&);
   1.118 +
   1.119 +	// Handlers for the three classes of channel message sent
   1.120 +	TInt DoControl(TInt aFunction);
   1.121 +	void DoRequest(TInt aFunction);
   1.122 +	TInt DoCancel(TInt aRequestMask);
   1.123 +	TInt NumberOfResolutions();
   1.124 +	TInt SafePut(TAny* aDst, TAny* aSrc, TInt aBytes);
   1.125 +
   1.126 +	void ValidateSpecificInfo(TInt aBytesPerPixel, RDisplayChannel::TOrientationSpecificInfo& aInfo);
   1.127 +	static void Panic(TDisplayPanic aPanic);
   1.128 +	void ClientPanic(RDisplayChannel::TPanic aPanic);
   1.129 +
   1.130 +	inline TBool IsCompositionBuffer(RDisplayChannel::TBufferId aId);
   1.131 +	static inline TBool IsLegacyBuffer(RDisplayChannel::TBufferId aId);
   1.132 +	static inline TBool IsUserBuffer(RDisplayChannel::TBufferId aId);
   1.133 +	inline TBool IsValidBuffer(RDisplayChannel::TBufferId aId);
   1.134 +    inline RDisplayChannel::TBufferId NextCompositionBuffer(RDisplayChannel::TBufferId aId);
   1.135 +
   1.136 +	static inline TBool IsFlipped(RDisplayChannel::TDisplayRotation aRotation);
   1.137 +
   1.138 +	static void VSyncTimerFn(TAny* aDisplayChannel);
   1.139 +	void DoVSyncTimer(void);
   1.140 +	static void VSyncDfcFn(TAny* aDisplayChannel);
   1.141 +	void DoVSync(void);
   1.142 +
   1.143 +	TInt PostCompositionBuffer(TAny* aRegion, RDisplayChannel::TPostCount* aPostCount);
   1.144 +	TInt PostLegacyBuffer(TAny* aRegion, RDisplayChannel::TPostCount* aPostCount);
   1.145 +	TInt GetCompositionBuffer(TAny** aAddress);
   1.146 +	TInt PostUserBuffer(RDisplayChannel::TBufferId* aBufferId, TAny* aRegion, RDisplayChannel::TPostCount* aPostCount);
   1.147 +	TInt WaitForPost(RDisplayChannel::TPostCount* aPostCount);
   1.148 +	TInt WaitForDisplayConnect();
   1.149 +	TInt SetRotation(RDisplayChannel::TDisplayRotation* aNewRotation, TBool* aIsBufferPreserved);
   1.150 +	TInt RegisterUserBuffer(TInt aChunkHandle, TInt aOffset, RDisplayChannel::TBufferId* aBufferId);
   1.151 +	TInt DeregisterUserBuffer(RDisplayChannel::TBufferId* aBufferId);
   1.152 +	TInt GetResolutions();
   1.153 +	TInt SetResolution(TSize* aSize);
   1.154 +	TInt GetResolution(TSize* aSize);
   1.155 +	TInt GetTwips(TSize* aSize);
   1.156 +	TInt GetIndexForSize(const TSize& aSize,TInt& aSpinnerOut);
   1.157 +	TInt GetPixelFormats();
   1.158 +	TInt SetBufferFormat(RDisplayChannel::TBufferFormat* aBufferFormat);
   1.159 +	TInt NextPlaneOffset(RDisplayChannel::TBufferFormat* aBufferFormat, 
   1.160 +			            RDisplayChannel::TBufferFormatContext* aContext);
   1.161 +	TInt NextLineOffset(RDisplayChannel::TBufferFormat* aBufferFormat, 
   1.162 +			            RDisplayChannel::TBufferFormatContext* aContext);
   1.163 +	TInt ValidateBufferFormat(const RDisplayChannel::TBufferFormat& aBufferFormat,
   1.164 +						 	  const RDisplayChannel::TResolution& aResolution);
   1.165 +private:
   1.166 +	// Constants
   1.167 +	enum {KDfcPriority = 6};
   1.168 +
   1.169 +	enum {KBufferNotSet = -1};
   1.170 +
   1.171 +	// Buffer index points. The legacy buffer is first, followed by the user
   1.172 +	// buffers, followed by a variable number of composition buffers.
   1.173 +	enum { KLegacyBuffer = 0};
   1.174 +	enum { KFirstUserBuffer = KLegacyBuffer + 1};
   1.175 +	enum { KFirstCompositionBuffer = KFirstUserBuffer + RDisplayChannel::TDisplayInfo::KMaxUserBuffers};
   1.176 +	enum { KMaxBufferSizeHeightAndWidth = KMaxTInt16 };
   1.177 +
   1.178 +private:
   1.179 +	TInt iScreenNumber;
   1.180 +	TThreadMessage* iMsg;
   1.181 +	TInt iVSyncTicks;					// Number of nanokernel ticks between frames
   1.182 +	TUint iNumCompositionBuffers;		// Number of composition buffers
   1.183 +	TUint iTotalBuffers;				// KFirstCompositionBuffer + iNumCompositionBuffers
   1.184 +	RDisplayChannel::TDisplayInfo iChannelInfo;
   1.185 +	RDisplayChannel::TPostCount iPostCount;				// Count of Post... calls
   1.186 +	RDisplayChannel::TPostCount iLastPostCount;			// Value of iPostCount when last buffer was actually posted
   1.187 +	TBufferInfo* iBuffer;				// Allocated to contain iTotalBuffers
   1.188 +	TBufferAddressA* iChunks;
   1.189 +	DThread* iClient;
   1.190 +
   1.191 +	// Posting support
   1.192 +	NTimer iVSync;						// Emulated VSync signal using a timer
   1.193 +	TDfc iVSyncDfc;						// DFC queued on DfcQue0 when iVSync triggers
   1.194 +	RDisplayChannel::TBufferId iPostedBuffer;			// Index of buffer to be posted on next frame
   1.195 +	RDisplayChannel::TDisplayRotation iCurrentRotation;	// Rotation of buffer being posted
   1.196 +	RDisplayChannel::TDisplayRotation iNewRotation;	// Rotation of buffer being posted
   1.197 +	TSize iCurrentResolution;			// Display resolution (normal rotation) to be posted
   1.198 +	TSize iNewResolution;			    // Display resolution (normal rotation) for buffer being posted
   1.199 +	TSize iCurrentTwips;
   1.200 +	TInt iPostedRectCount;				// Number of rectangles defined in region
   1.201 +	RECT iPostedRect[RDisplayChannel::TDisplayInfo::KMaxRectangles];	//
   1.202 +
   1.203 +	// Paint support
   1.204 +	HWND iHwnd;							// Window to be painted
   1.205 +	RDisplayChannel::TBufferId iDisplayBuffer;			// Index of buffer to be painted
   1.206 +	RDisplayChannel::TDisplayRotation iDisplayRotation;	// Rotation of buffer to be painted
   1.207 +	TSize iDisplayResolution;			// Display resolution (normal rotation) on screen
   1.208 +
   1.209 +	// GetCompositionBuffer support
   1.210 +	TUint iGetBuffer;					// Index of next composition buffer
   1.211 +
   1.212 +	// WaitForPost support
   1.213 +	RDisplayChannel::TPostCount iWaitForPost;			// Post count being awaited
   1.214 +	TRequest iWaitForPostRequest;		// Request to complete when post count reached
   1.215 +	
   1.216 +	// WaitForDisplayConnect support 
   1.217 +	TRequest iWaitForDisplayConnect;		// Request to complete when display connection state changes
   1.218 +	
   1.219 +	TInt iDisplayStateSpinner;
   1.220 +	
   1.221 +	TVersion iVersion;
   1.222 +	const RDisplayChannel::TPixelFormat* iPixelFormatArray;
   1.223 +	TInt iPixelFormatArraySize;
   1.224 +	RDisplayChannel::TBufferFormat iInitialBufferFormat;
   1.225 +	RDisplayChannel::TBufferFormat iCurrentBufferFormat;
   1.226 +	RDisplayChannel::TBufferFormat iDisplayBufferFormat;
   1.227 +	RDisplayChannel::TBufferFormat iNewBufferFormat;
   1.228 +	};
   1.229 +
   1.230 +inline TBool DDisplayChannel::IsCompositionBuffer(RDisplayChannel::TBufferId aId)
   1.231 +	{ return (aId >= KFirstCompositionBuffer && aId < iTotalBuffers); }
   1.232 +inline TBool DDisplayChannel::IsLegacyBuffer(RDisplayChannel::TBufferId aId)
   1.233 +	{ return (aId == KLegacyBuffer); }
   1.234 +inline TBool DDisplayChannel::IsUserBuffer(RDisplayChannel::TBufferId aId)
   1.235 +	{ return (aId >= KFirstUserBuffer && aId < (KFirstUserBuffer + RDisplayChannel::TDisplayInfo::KMaxUserBuffers)); }
   1.236 +inline TBool DDisplayChannel::IsValidBuffer(RDisplayChannel::TBufferId aId)
   1.237 +	{ return (aId >= 0 && aId < iTotalBuffers); }
   1.238 +inline RDisplayChannel::TBufferId DDisplayChannel::NextCompositionBuffer(RDisplayChannel::TBufferId aId)
   1.239 +	{ TUint r = (aId + 1); return (r >= iTotalBuffers) ? KFirstCompositionBuffer : r; }
   1.240 +
   1.241 +inline TBool DDisplayChannel::IsFlipped(RDisplayChannel::TDisplayRotation aRotation)
   1.242 +	{ return !(aRotation & (RDisplayChannel::ERotationNormal | RDisplayChannel::ERotation180)); }
   1.243 +
   1.244 +#endif
   1.245 +