1 ///////////////////////////////////////////////////////////////////////////////
2 // $Source: x:/prj/tech/libsrc/dispdev/RCS/wdisp.h $
4 // $Date: 1998/01/12 15:44:26 $
17 ///////////////////////////////////////////////////////////////////////////////
19 F_DECLARE_INTERFACE(IWinApp
);
21 class cWinDisplayProvider
;
22 class cWinDisplayModeOperations
;
24 ///////////////////////////////////////////////////////////////////////////////
26 // STRUCT: sGdiBitmapInfo
28 // Initializes and stores information required to create a GDI bitmap
31 struct sGdiBitmapInfo
: public BITMAPINFO
33 sGdiBitmapInfo(int width
, int height
, int significantDepth
);
34 RGBQUAD bmiColors2
[255];
37 // Typedef Task Switch callback function
39 ///////////////////////////////////////////////////////////////////////////////
41 // CLASS: cWinDisplayDevice
43 // Implements IDisplayDevice. Acts primarily as an adaptor for instances
44 // of cWinDisplayProvider and cWinDisplayModeOperations
47 class cWinDisplayDevice
: public cDisplayDevice
50 cWinDisplayDevice(IUnknown
* pOuterUnknown
, eDisplayDeviceKind kind
, int flags
);
51 virtual ~cWinDisplayDevice();
53 ///////////////////////////////////
55 // Query functions for client Providers and Operations
59 // Query if the device has been opened
64 // Query if the device is useful (i.e., is in some mode, any mode)
66 BOOL
IsModeSet() const;
69 // Query the lock count
71 int GetLockCount() const;
76 STDMETHOD_(eDisplayDeviceKind
, GetKind
)();
79 // Query the creation flags
81 int GetCreateFlags() const;
84 // Temporarily break any lock on surfaces, returning lock count
86 STDMETHOD_(int, BreakLock
)();
89 // Restore broken lock
91 STDMETHOD_(void, RestoreLock
)(int iLockCount
);
94 // Try to gain exclusive use of display object, without locking video memory.
96 STDMETHOD_(BOOL
, IsLocked
)();
104 void RestoreMutex(int);
107 // Get the properties of the current mode
109 const sGrModeInfo
& GetCurrentModeInfo() const;
114 struct sPalette256
: public LOGPALETTE
121 PALETTEENTRY AddEntries
[255];
124 LOGPALETTE
& GetLogPalette();
125 PALETTEENTRY
* GetPaletteEntries();
127 // Set kind (must be outside Open/Close pair)
128 STDMETHOD_(void, SetKind
)(eDisplayDeviceKind
, int flags
);
130 // Get information about the device
131 STDMETHOD_(void, GetInfo
)(sGrDeviceInfo
*, sGrModeInfo
*);
133 // Open/Close the device
134 STDMETHOD (Open
)(sGrModeCap
*, int fFlags
);
138 STDMETHOD (SetMode
)(eGrDispMode
, int fFlags
);
139 STDMETHOD_(eGrDispMode
, GetMode
)(sGrModeInfoEx
* pOptionalModeInfo
);
141 // Return TRUE of retrace is in progress
142 STDMETHOD_(BOOL
, StatHTrace
)();
143 STDMETHOD_(BOOL
, StatVTrace
)();
145 // Set/Get the palette (if 8-bit palletized)
146 STDMETHOD_(BOOL
, SetPalette
)(unsigned uStart
, unsigned n
, const unsigned char * pRGBs
);
147 STDMETHOD_(BOOL
, GetPalette
)(unsigned uStart
, unsigned n
, unsigned char * pRGBs
);
149 // Flip the visible surface. No-op if no back buffer.
150 STDMETHOD (PageFlip
)();
152 // Try to lock video memory. Locked pointers will be placed in
153 // structure provided in SetMode(). Returns lock count.
154 STDMETHOD_(int, Lock
)();
156 // Release a lock on memory
157 STDMETHOD_(int, Unlock
)();
159 // Verify display reflects what is expected.
160 STDMETHOD_(void, Flush
)();
162 // Flush a specific region
163 STDMETHOD_(void, FlushRect
)(int x0
, int y0
, int x1
, int y1
);
165 // Add/Remove a pointer to the monitor set.
166 STDMETHOD_(BOOL
, SetMonitor
)(tGrDispBits
**, eDisplayDeviceMonitorFlag
);
168 // Create a device based bitmap
169 STDMETHOD (CreateBitmap
)(sGrDevBitmapDesc
*, int flags
, IDeviceBitmap
**);
171 // Locate an IDeviceBitmap for the given sGrBitmap, if any exists
172 STDMETHOD (FindBitmap
)(const sGrBitmap
*, IDeviceBitmap
**);
175 STDMETHOD (GetRenderTargets
)(sGrRenderTargets
*);
177 // Set kind (must be outside Open/Close pair)
178 STDMETHOD_(void, SetKind2
)(eDisplayDeviceKind
, int flags
, GUID
*pDDrawGuid
);
180 // Query kind, flags, and ddraw guid
181 STDMETHOD_(void, GetKind2
)(eDisplayDeviceKind
*, int *, GUID
**);
183 // Create a GDI bitmap
184 HBITMAP
CreateGDIBitmap(sGdiBitmapInfo
* pBitmapInfo
);
188 ///////////////////////////////////
190 // Fixes-up monitored pointers
191 void Sync2DPointers();
192 void InvalidateBasePointers();
194 // Manipulation of m_LogicalPalette
195 static void SetStoredPaletteEntries(unsigned uStart
, unsigned n
, const unsigned char * pRGBs
, int paletteFlags
);
196 static void GetStoredPaletteEntries(unsigned uStart
, unsigned n
, unsigned char * pRGBs
);
198 ///////////////////////////////////
200 void DoCursorBltFromGDIScreen(sGrBitmap
*, int x
, int y
);
201 void DoCursorBltToGDIScreen(sGrBitmap
*, int x
, int y
);
203 ///////////////////////////////////
205 // Enums and constants
210 kTotallyBogusBase
= 0xffeeffee,
211 kPrimaryBogusBase
= 0xfefefefe,
212 kSecondaryBogusBase
= 0xfdfdfdfd
217 // Start higher than base flags!
218 kStrictMonitors
= 0x10,
219 kSettingMode
= 0x20 // because setting the mode often
220 // requires breaking the display
221 // device mutex, an additional
222 // bit ensures the message thread
223 // doesn't do anything bad
226 ///////////////////////////////////
228 // CLASS: cIWinDisplayDeviceProxy
230 // Simply passes requests to outer object
233 class cIWinDisplayDeviceProxy
: public IWinDisplayDevice
236 cIWinDisplayDeviceProxy(cWinDisplayDevice
* pOuter
, IUnknown
* pOuterUnknown
)
237 : m_pOuter(pOuter
), m_pTaskSwitchCallback(NULL
)
239 INIT_DELEGATION(pOuterUnknown
);
243 DECLARE_DELEGATION();
245 STDMETHOD_(BOOL
, ProcessMessage
)(UINT msg
, WPARAM wParam
, LPARAM lParam
, long * pRetVal
);
246 STDMETHOD_(void, GetWidthHeight
)(unsigned * pWidth
, unsigned * pHeight
);
247 STDMETHOD_(void, OnTaskSwitch
) (BOOL
);
248 STDMETHOD_(BOOL
, GetDirectDraw
) (IDirectDraw
**);
249 STDMETHOD_(void, WaitForMutex
)();
250 STDMETHOD_(void, ReleaseMutex
)();
251 STDMETHOD_(void, CursorBltFromGDIScreen
)(sGrBitmap
*, int x
, int y
);
252 STDMETHOD_(void, CursorBltToGDIScreen
)(sGrBitmap
*, int x
, int y
);
253 STDMETHOD_(BOOL
, GetBitmapSurface
)(sGrBitmap
*, IDirectDrawSurface
**);
254 STDMETHOD_(void, AddTaskSwitchCallback
)(WinDispDevCallbackFunc
*callback
);
255 STDMETHOD_(void, RemoveTaskSwitchCallback
)(int id
);
257 cWinDisplayDevice
* m_pOuter
;
258 WinDispDevCallbackFunc
*m_pTaskSwitchCallback
;
261 friend class cIWinDisplayDeviceProxy
;
263 ///////////////////////////////////
273 cWinDisplayModeOperations
* m_pDisplayModeOperations
;
275 ///////////////////////////////////
277 sGrModeCap
* m_pModeInfo
;
278 eGrDispMode m_CurrentDispMode
;
280 ///////////////////////////////////
282 eDisplayDeviceKind m_DisplayDeviceKind
;
284 cWinDisplayProvider
* m_pDisplayProvider
;
285 cIWinDisplayDeviceProxy m_IWinDisplayDeviceProxy
;
287 ///////////////////////////////////
292 ///////////////////////////////////
294 cRelocationSet
<tGrDispBits
> m_PrimarySurfaceRelocationSet
;
295 cRelocationSet
<tGrDispBits
> m_SecondarySurfaceRelocationSet
;
297 ///////////////////////////////////
299 struct sCursorScratch
304 memset(&bitmap
, 0, sizeof(BITMAP
));
310 DeleteObject(hBitmap
);
317 sCursorScratch m_CursorScratch
;
319 ///////////////////////////////////
324 static sPalette256 gm_LogicalPalette
;
328 ///////////////////////////////////////////////////////////////////////////////
330 // Utility classes for display device mutex
333 class cAutoDisplayMutex
336 cAutoDisplayMutex(cWinDisplayDevice
* pWinDisplayDevice
)
338 m_pWinDisplayDevice
= pWinDisplayDevice
;
339 m_pWinDisplayDevice
->WaitForMutex();
344 m_pWinDisplayDevice
->ReleaseMutex();
348 cWinDisplayDevice
* m_pWinDisplayDevice
;
353 // Yield the display. Sorry, only 1 per scope
355 #define YieldDisplay(pDisplayDevice) \
356 int _YieldDisplay_iPreviousLock = pDisplayDevice->BreakLock(); \
357 int _YieldDisplay_iPreviousMutexLevel = pDisplayDevice->BreakMutex()
359 #define RegainDisplay(pDisplayDevice) \
360 m_pDisplayDevice->RestoreMutex(_YieldDisplay_iPreviousMutexLevel);\
361 m_pDisplayDevice->RestoreLock(_YieldDisplay_iPreviousLock)
364 ///////////////////////////////////////////////////////////////////////////////
366 // Inline members of cWinDisplayDevice
369 inline BOOL
cWinDisplayDevice::IsOpen() const
371 return !!m_pModeInfo
;
374 ///////////////////////////////////////
376 inline BOOL
cWinDisplayDevice::IsModeSet() const
378 return (m_pDisplayModeOperations
&& !(m_flags
& kSettingMode
));
381 ///////////////////////////////////////
383 inline int cWinDisplayDevice::GetLockCount() const
388 ///////////////////////////////////////
390 inline int cWinDisplayDevice::GetCreateFlags() const
395 ///////////////////////////////////////
397 inline void cWinDisplayDevice::WaitForMutex()
403 ///////////////////////////////////////
405 inline void cWinDisplayDevice::ReleaseMutex()
411 ///////////////////////////////////////
413 inline int cWinDisplayDevice::BreakMutex()
416 const int retVal
= m_MutexCount
;
426 ///////////////////////////////////////
428 inline void cWinDisplayDevice::RestoreMutex(int iMutexCount
)
431 m_MutexCount
+= iMutexCount
;
440 ///////////////////////////////////////
442 inline const sGrModeInfo
& cWinDisplayDevice::GetCurrentModeInfo() const
444 return EnumModeToModeInfo(m_CurrentDispMode
);
447 ///////////////////////////////////////
449 inline LOGPALETTE
& cWinDisplayDevice::GetLogPalette()
451 return gm_LogicalPalette
;
454 ///////////////////////////////////////
456 inline PALETTEENTRY
* cWinDisplayDevice::GetPaletteEntries()
458 return gm_LogicalPalette
.palPalEntry
;
461 ///////////////////////////////////////
463 inline HBITMAP
cWinDisplayDevice::CreateGDIBitmap(sGdiBitmapInfo
* pBitmapInfo
)
466 UINT fUsage
= (pBitmapInfo
->bmiHeader
.biCompression
== BI_RGB
) ? DIB_RGB_COLORS
: 0;
467 void * pDummy
; // @Note (toml 04-12-96): In winG, the bits argument could be NULL. We have to get it here, even though we retreive it again with the GetObject() below. This section should be cleaned-up
469 HDC hdcScreen
= GetDC(NULL
);
470 hBitmap
= CreateDIBSection(hdcScreen
, pBitmapInfo
, fUsage
, &pDummy
, NULL
, 0);
471 ReleaseDC(NULL
, hdcScreen
);
475 ///////////////////////////////////////////////////////////////////////////////
477 #endif /* !__WDISP_H */