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