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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #ifndef __DISPLAY_CHAN_H__
23 #define __DISPLAY_CHAN_H__
26 #include <dispchannel.h>
27 #include <videodriver.h>
28 #include "displayhandler.h"
30 struct TBufferAddressA;
33 Logical Channel kernel side class for Display
37 class DDisplayChannel : public DLogicalChannel
41 enum { KDisplayChMajorVersionNumber = 1 };
42 enum { KDisplayChMinorVersionNumber = 2 };
43 enum { KDisplayChBuildVersionNumber = 1 };
45 // Duplicate of RDisplayChannel structure, as the header file cannot be used.
55 inline TRequest(void) : iThread(0), iStatus(0) {}
56 TBool SetStatus(TThreadMessage& aMsg);
57 void Complete(TInt aResult);
60 TRequestStatus* iStatus;
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
93 DDisplayChannel(void);
94 ~DDisplayChannel(void);
96 // DLogicalChannel implementation
97 virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
98 virtual void HandleMsg(TMessageBase* aMsg);
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,
108 const RDisplayChannel::TPixelFormat aPixelFormatArray[],
109 const TInt aPixelFormatArraySize,
110 const RDisplayChannel::TBufferFormat& aBufferFormat);
111 virtual void SetLegacyBuffer(void *aAddress);
114 DDisplayChannel(const DDisplayChannel&);
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);
123 void ValidateSpecificInfo(TInt aBytesPerPixel, RDisplayChannel::TOrientationSpecificInfo& aInfo);
124 static void Panic(TDisplayPanic aPanic);
125 void ClientPanic(RDisplayChannel::TPanic aPanic);
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);
133 static inline TBool IsFlipped(RDisplayChannel::TDisplayRotation aRotation);
135 static void VSyncTimerFn(TAny* aDisplayChannel);
136 void DoVSyncTimer(void);
137 static void VSyncDfcFn(TAny* aDisplayChannel);
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);
164 enum {KDfcPriority = 6};
166 enum {KBufferNotSet = -1};
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 };
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;
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
197 TInt iPostedRectCount; // Number of rectangles defined in region
198 RECT iPostedRect[RDisplayChannel::TDisplayInfo::KMaxRectangles]; //
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
206 // GetCompositionBuffer support
207 TUint iGetBuffer; // Index of next composition buffer
209 // WaitForPost support
210 RDisplayChannel::TPostCount iWaitForPost; // Post count being awaited
211 TRequest iWaitForPostRequest; // Request to complete when post count reached
213 // WaitForDisplayConnect support
214 TRequest iWaitForDisplayConnect; // Request to complete when display connection state changes
216 TInt iDisplayStateSpinner;
219 const RDisplayChannel::TPixelFormat* iPixelFormatArray;
220 TInt iPixelFormatArraySize;
221 RDisplayChannel::TBufferFormat iInitialBufferFormat;
222 RDisplayChannel::TBufferFormat iCurrentBufferFormat;
223 RDisplayChannel::TBufferFormat iDisplayBufferFormat;
224 RDisplayChannel::TBufferFormat iNewBufferFormat;
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; }
238 inline TBool DDisplayChannel::IsFlipped(RDisplayChannel::TDisplayRotation aRotation)
239 { return !(aRotation & (RDisplayChannel::ERotationNormal | RDisplayChannel::ERotation180)); }