Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

322 lines
9.7 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: glgenwin.h
  3. *
  4. * Client side replacement for WNDOBJ. Tracks window state (size, location,
  5. * clip region, etc.).
  6. *
  7. * Created: 12-Jan-1995 00:31:42
  8. * Author: Gilman Wong [gilmanw]
  9. *
  10. * Copyright (c) 1994 Microsoft Corporation
  11. *
  12. \**************************************************************************/
  13. #ifndef _GLGENWIN_H_
  14. #define _GLGENWIN_H_
  15. // Tracks lock/unlock calls on windows if defined. This is always
  16. // on for checked builds.
  17. #define TRACK_WINCRIT
  18. #if DBG && !defined(TRACK_WINCRIT)
  19. #define TRACK_WINCRIT
  20. #endif
  21. // Not defined in NT 3.51!
  22. typedef ULONG FLONG;
  23. /*
  24. * GLGENscan structure
  25. *
  26. * Represents a single scan of a region. Consists of a top, a bottom
  27. * and an even number of walls.
  28. *
  29. * Part of the GLGENscanData structure.
  30. */
  31. typedef struct GLGENscanRec GLGENscan;
  32. typedef struct GLGENscanRec
  33. {
  34. // Accelerator points to next GLGENscan in the array (we could compute).
  35. GLGENscan *pNext;
  36. ULONG cWalls;
  37. LONG top;
  38. LONG bottom;
  39. #ifdef _IA64_
  40. LONG pad;
  41. #endif
  42. LONG alWalls[1]; // array of walls
  43. } GLGENscan;
  44. /*
  45. * GLGENscanData structure
  46. *
  47. * Scan line oriented version of the visible region info in the RGNDATA
  48. * structure.
  49. */
  50. typedef struct GLGENscanDataRec
  51. {
  52. ULONG cScans;
  53. GLGENscan aScans[1]; // array of scans
  54. } GLGENscanData;
  55. /*
  56. * GLGENlayerInfo structure
  57. *
  58. * Information about an overlay/underlay.
  59. */
  60. typedef struct GLGENlayerInfo
  61. {
  62. LONG cPalEntries;
  63. COLORREF pPalEntries[1];
  64. } GLGENlayerInfo;
  65. /*
  66. * GLGENlayers structure
  67. *
  68. *
  69. */
  70. typedef struct GLGENlayers
  71. {
  72. GLGENlayerInfo *overlayInfo[15];
  73. GLGENlayerInfo *underlayInfo[15];
  74. } GLGENlayers;
  75. /*
  76. * Identifying information for a window
  77. */
  78. #define GLWID_ERROR 0
  79. #define GLWID_HWND 1
  80. #define GLWID_HDC 2
  81. #define GLWID_DDRAW 3
  82. typedef struct IDirectDrawSurface *LPDIRECTDRAWSURFACE;
  83. typedef struct _GLWINDOWID
  84. {
  85. int iType;
  86. HWND hwnd;
  87. HDC hdc;
  88. LPDIRECTDRAWSURFACE pdds;
  89. } GLWINDOWID;
  90. #define CLC_TRIVIAL 0
  91. #define CLC_RECT 1
  92. #define CLC_COMPLEX 2
  93. /*
  94. * GLGENwindows structure
  95. *
  96. * Substitute for the NT DDI's WNDOBJ service. This structure is used to
  97. * track the current state of a window (size, location, clipping). A
  98. * semaphore protected linked list of these is kept globally per-process.
  99. */
  100. typedef struct GLGENwindowRec GLGENwindow;
  101. typedef struct GLGENwindowRec
  102. {
  103. struct __GLGENbuffersRec *buffers; // Buffer information
  104. int clipComplexity; // Clipping area complexity
  105. RECTL rclBounds; // Clip area bounds
  106. RECTL rclClient; // Window client rect
  107. GLGENwindow *pNext; // linked list
  108. GLWINDOWID gwid; // Identifying information
  109. int ipfd; // pixel format assigned to this window
  110. int ipfdDevMax; // max. device pixel format
  111. WNDPROC pfnOldWndProc; // original WndProc function
  112. ULONG ulPaletteUniq; // uniq palette id
  113. ULONG ulFlags;
  114. // These fields are used for direct screen access
  115. LPDIRECTDRAWCLIPPER pddClip;// DirectDraw clipper assocated with window
  116. UINT cjrgndat; // size of RGNDATA struct
  117. RGNDATA *prgndat; // pointer to RGNDATA struct
  118. // Scan version of RGNDATA.
  119. UINT cjscandat; // size of GLGENscanData struct
  120. GLGENscanData *pscandat; // pointer to GLGENscanData struct
  121. // Installable client drivers ONLY.
  122. PVOID pvDriver; // pointer to GLDRIVER for window
  123. // Layer palettes for MCD drivers ONLY.
  124. GLGENlayers *plyr; // pointer to GLGENlayers for window
  125. // non-NULL only if overlays for MCD are
  126. // actively in use
  127. // DirectDraw surface vtbl pointer for doing DDraw surface validation
  128. void *pvSurfaceVtbl;
  129. // DirectDraw surface locked if DIRECTSCREEN is set
  130. LPDIRECTDRAWSURFACE pddsDirectScreen;
  131. void *pvDirectScreen;
  132. void *pvDirectScreenLock;
  133. // MCD server-side handle for this window
  134. ULONG_PTR dwMcdWindow;
  135. //
  136. // Reference counting and serialization.
  137. //
  138. // Count of things holding a pointer to this window.
  139. LONG lUsers;
  140. // All accesses to this window's data must occur under this lock.
  141. CRITICAL_SECTION sem;
  142. // Context that is currently holding this window's lock.
  143. struct __GLGENcontextRec *gengc;
  144. // Thread that is currently holding this window's lock and
  145. // recursion count on this window's lock. This information may
  146. // be in the critical section but to be cross-platform we
  147. // maintain it ourselves.
  148. DWORD owningThread;
  149. DWORD lockRecursion;
  150. } GLGENwindow;
  151. /*
  152. * GLGENwindow::ulFlags
  153. *
  154. * GLGENWIN_DIRECTSCREEN Direct screen access locks are held
  155. * GLGENWIN_OTHERPROCESS The window handle is from another process
  156. * GLGENWIN_DRIVERSET pvDriver has been set
  157. */
  158. #define GLGENWIN_DIRECTSCREEN 0x00000001
  159. #define GLGENWIN_OTHERPROCESS 0x00000002
  160. #define GLGENWIN_DRIVERSET 0x00000004
  161. /*
  162. * Global header node for the linked list of GLGENwindow structures.
  163. * The semaphore in the header node is used as the list access semaphore.
  164. */
  165. extern GLGENwindow gwndHeader;
  166. /*
  167. * GLGENwindow list management functions.
  168. */
  169. // Retrieves the GLGENwindow that corresponds to the specified HWND.
  170. // NULL if failure.
  171. // Increments lUsers
  172. extern GLGENwindow * APIENTRY pwndGetFromHWND(HWND hwnd);
  173. // Retrieves the GLGENwindow that corresponds to the specified HDC.
  174. // NULL if failure.
  175. // Increments lUsers
  176. extern GLGENwindow * APIENTRY pwndGetFromMemDC(HDC hdc);
  177. // Retrieves the GLGENwindow that corresponds to the specified DDraw surface.
  178. // NULL if failure.
  179. // Increments lUsers
  180. GLGENwindow *pwndGetFromDdraw(LPDIRECTDRAWSURFACE pdds);
  181. // General retrieval
  182. // NULL if failure.
  183. // Increments lUsers
  184. extern GLGENwindow * APIENTRY pwndGetFromID(GLWINDOWID *pgwid);
  185. // Allocates a new GLGENwindow structure and puts it into the linked list.
  186. // NULL if failure.
  187. // Starts lUsers at 1
  188. extern GLGENwindow * APIENTRY pwndNew(GLGENwindow *pwndInit);
  189. // Creates a GLGENwindow for the given information
  190. extern GLGENwindow * APIENTRY CreatePwnd(GLWINDOWID *pgwid, int ipfd,
  191. int ipfdDevMax, DWORD dwObjectType,
  192. RECTL *prcl, BOOL *pbNew);
  193. // Cleans up resources for a GLGENwindow
  194. // NULL if success; pointer to GLGENwindow structure if failure.
  195. extern GLGENwindow * APIENTRY pwndFree(GLGENwindow *pwnd,
  196. BOOL bExitProcess);
  197. // Removes an active GLGENwindow from the window list and
  198. // waits for a safe time to clean it up, then pwndFrees it
  199. extern void APIENTRY pwndCleanup(GLGENwindow *pwnd);
  200. // Decrements lUsers
  201. #if DBG
  202. extern void APIENTRY pwndRelease(GLGENwindow *pwnd);
  203. #else
  204. #define pwndRelease(pwnd) \
  205. InterlockedDecrement(&(pwnd)->lUsers)
  206. #endif
  207. // Unlocks pwnd->sem and does pwndRelease
  208. extern void APIENTRY pwndUnlock(GLGENwindow *pwnd,
  209. struct __GLGENcontextRec *gengc);
  210. // Removes and deletes all GLGENwindow structures from the linked list.
  211. // Must *ONLY* be called from process detach (GLUnInitializeProcess).
  212. extern VOID APIENTRY vCleanupWnd(VOID);
  213. // Retrieves layer information for the specified layer of the pwnd.
  214. // Allocates if necessary.
  215. extern GLGENlayerInfo * APIENTRY plyriGet(GLGENwindow *pwnd, HDC hdc, int iLayer);
  216. void APIENTRY WindowIdFromHdc(HDC hdc, GLWINDOWID *pgwid);
  217. //
  218. // Begin/end direct screen access
  219. //
  220. extern BOOL BeginDirectScreenAccess(struct __GLGENcontextRec *gengc,
  221. GLGENwindow *pwnd,
  222. PIXELFORMATDESCRIPTOR *ppfd);
  223. extern VOID EndDirectScreenAccess(GLGENwindow *pwnd);
  224. //
  225. // Debugging support for tracking lock/unlock on a window.
  226. //
  227. #if DBG || defined(TRACK_WINCRIT)
  228. // Don't use ASSERTOPENGL so this can be used on free builds.
  229. #define ASSERT_WINCRIT(pwnd) \
  230. if ((pwnd)->owningThread != GetCurrentThreadId()) \
  231. { \
  232. DbgPrint("Window 0x%08lX owned by 0x%X, not 0x%X\n", \
  233. (pwnd), (pwnd)->owningThread, GetCurrentThreadId()); \
  234. DebugBreak(); \
  235. }
  236. #define ASSERT_NOT_WINCRIT(pwnd) \
  237. if ((pwnd)->owningThread == GetCurrentThreadId()) \
  238. { \
  239. DbgPrint("Window 0x%08lX already owned by 0x%X\n", \
  240. (pwnd), (pwnd)->owningThread); \
  241. DebugBreak(); \
  242. }
  243. // Asserts that the current thread can recursively take the given
  244. // wincrit. For this to be true it must be unowned or owned by
  245. // the same thread.
  246. #define ASSERT_COMPATIBLE_WINCRIT(pwnd) \
  247. if ((pwnd)->owningThread != 0 && \
  248. (pwnd)->owningThread != GetCurrentThreadId()) \
  249. { \
  250. DbgPrint("Window 0x%08lX owned by 0x%X, not 0x%X\n", \
  251. (pwnd), (pwnd)->owningThread, GetCurrentThreadId()); \
  252. DebugBreak(); \
  253. }
  254. #else
  255. #define ASSERT_WINCRIT(pwnd)
  256. #define ASSERT_NOT_WINCRIT(pwnd)
  257. #define ASSERT_COMPATIBLE_WINCRIT(pwnd)
  258. #endif
  259. // Use both GC and non-GC forms so it's possible to write macros
  260. // for both cases if we want to in the future.
  261. void ENTER_WINCRIT_GC(GLGENwindow *pwnd, struct __GLGENcontextRec *gengc);
  262. void LEAVE_WINCRIT_GC(GLGENwindow *pwnd, struct __GLGENcontextRec *gengc);
  263. #define ENTER_WINCRIT(pwnd) ENTER_WINCRIT_GC(pwnd, NULL)
  264. #define LEAVE_WINCRIT(pwnd) LEAVE_WINCRIT_GC(pwnd, NULL)
  265. #endif //_GLGENWIN_H_