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.

273 lines
6.3 KiB

  1. /*********************************Class************************************\
  2. * class EDD_DEVLOCK
  3. *
  4. * Simple wrapper for the DEVLOCK that automatically unlocks when it
  5. * goes out of scope, so that we don't forget.
  6. *
  7. \**************************************************************************/
  8. class EDD_DEVLOCK
  9. {
  10. private:
  11. HDEV _hdev;
  12. public:
  13. EDD_DEVLOCK(EDD_DIRECTDRAW_GLOBAL* peDirectDrawGlobal)
  14. {
  15. _hdev = peDirectDrawGlobal->hdev;
  16. DxEngLockHdev(_hdev);
  17. }
  18. EDD_DEVLOCK(HDEV hdev)
  19. {
  20. _hdev = hdev;
  21. DxEngLockHdev(_hdev);
  22. }
  23. EDD_DEVLOCK(VOID)
  24. {
  25. _hdev = NULL;
  26. }
  27. ~EDD_DEVLOCK()
  28. {
  29. if (_hdev) DxEngUnlockHdev(_hdev);
  30. }
  31. VOID vLockDevice()
  32. {
  33. DxEngLockHdev(_hdev);
  34. }
  35. VOID vUnlockDevice()
  36. {
  37. DxEngUnlockHdev(_hdev);
  38. }
  39. VOID vUpdateDevice(EDD_DIRECTDRAW_GLOBAL* peDirectDrawGlobal)
  40. {
  41. ASSERTGDI(!DxEngIsHdevLockedByCurrentThread(_hdev),
  42. "vUpdateDdGlobal - Old Devlock is not released");
  43. _hdev = peDirectDrawGlobal->hdev;
  44. }
  45. };
  46. /*********************************Class************************************\
  47. * class EDD_SHAREDEVLOCK
  48. *
  49. * Simple wrapper for the DEVLOCK and SHAREDEVLOCK that automatically
  50. * unlocks them when it goes out of scope, so that we don't forget.
  51. *
  52. * This also ensures that we lock and unlock them in proper order.
  53. *
  54. \**************************************************************************/
  55. class EDD_SHAREDEVLOCK
  56. {
  57. private:
  58. HDEV _hdev;
  59. public:
  60. EDD_SHAREDEVLOCK(EDD_DIRECTDRAW_GLOBAL* peDirectDrawGlobal)
  61. {
  62. _hdev = peDirectDrawGlobal->hdev;
  63. DxEngLockShareSem();
  64. DxEngLockHdev(_hdev);
  65. }
  66. ~EDD_SHAREDEVLOCK()
  67. {
  68. DxEngUnlockHdev(_hdev);
  69. DxEngUnlockShareSem();
  70. }
  71. VOID vLockDevice()
  72. {
  73. DxEngLockHdev(_hdev);
  74. }
  75. VOID vUnlockDevice()
  76. {
  77. DxEngUnlockHdev(_hdev);
  78. }
  79. VOID vUpdateDevice(EDD_DIRECTDRAW_GLOBAL* peDirectDrawGlobal)
  80. {
  81. ASSERTGDI(!DxEngIsHdevLockedByCurrentThread(_hdev),
  82. "vUpdateDdGlobal - Old Devlock is not released");
  83. _hdev = peDirectDrawGlobal->hdev;
  84. }
  85. };
  86. class EDD_SHARELOCK
  87. {
  88. private:
  89. BOOL bLocked;
  90. public:
  91. VOID vLock()
  92. {
  93. DxEngLockShareSem();
  94. bLocked = TRUE;
  95. }
  96. EDD_SHARELOCK(BOOL b)
  97. {
  98. bLocked = FALSE;
  99. if (b)
  100. {
  101. vLock();
  102. }
  103. }
  104. ~EDD_SHARELOCK()
  105. {
  106. if (bLocked)
  107. {
  108. DxEngUnlockShareSem();
  109. }
  110. }
  111. };
  112. /*********************************Class************************************\
  113. * class EDD_LOCK_DIRECTDRAW
  114. *
  115. * Simple wrapper for DirectDraw surface objects that automatically unlocks
  116. * the object when it goes out of scope, so that we don't forget.
  117. *
  118. \**************************************************************************/
  119. class EDD_LOCK_DIRECTDRAW
  120. {
  121. private:
  122. EDD_DIRECTDRAW_LOCAL *m_peSurface;
  123. public:
  124. EDD_LOCK_DIRECTDRAW()
  125. {
  126. m_peSurface = NULL;
  127. }
  128. EDD_DIRECTDRAW_LOCAL* peLock(HANDLE h)
  129. {
  130. return(m_peSurface = (EDD_DIRECTDRAW_LOCAL*) DdHmgLock((HDD_OBJ) h, DD_DIRECTDRAW_TYPE, FALSE));
  131. }
  132. ~EDD_LOCK_DIRECTDRAW()
  133. {
  134. if (m_peSurface != NULL)
  135. {
  136. DEC_EXCLUSIVE_REF_CNT(m_peSurface); // Do an HmgUnlock
  137. }
  138. }
  139. };
  140. /*********************************Class************************************\
  141. * class EDD_LOCK_SURFACE
  142. *
  143. * Simple wrapper for DirectDraw surface objects that automatically unlocks
  144. * the object when it goes out of scope, so that we don't forget.
  145. *
  146. \**************************************************************************/
  147. class EDD_LOCK_SURFACE
  148. {
  149. private:
  150. EDD_SURFACE *m_peSurface;
  151. public:
  152. EDD_LOCK_SURFACE()
  153. {
  154. m_peSurface = NULL;
  155. }
  156. EDD_SURFACE* peLock(HANDLE h)
  157. {
  158. return(m_peSurface = (EDD_SURFACE*) DdHmgLock((HDD_OBJ) h, DD_SURFACE_TYPE, FALSE));
  159. }
  160. void vUnlockNoNullSet(void)
  161. {
  162. if (m_peSurface != NULL)
  163. {
  164. DEC_EXCLUSIVE_REF_CNT(m_peSurface); // Do an HmgUnlock
  165. }
  166. }
  167. void vUnlock(void)
  168. {
  169. vUnlockNoNullSet();
  170. m_peSurface = NULL;
  171. }
  172. ~EDD_LOCK_SURFACE()
  173. {
  174. vUnlockNoNullSet();
  175. }
  176. };
  177. /*********************************Class************************************\
  178. * class EDD_LOCK_VIDEOPORT
  179. *
  180. * Simple wrapper for DirectDraw videoport objects that automatically unlocks
  181. * the object when it goes out of scope, so that we don't forget.
  182. *
  183. \**************************************************************************/
  184. class EDD_LOCK_VIDEOPORT
  185. {
  186. private:
  187. EDD_VIDEOPORT *m_peSurface;
  188. public:
  189. EDD_LOCK_VIDEOPORT()
  190. {
  191. m_peSurface = NULL;
  192. }
  193. EDD_VIDEOPORT* peLock(HANDLE h)
  194. {
  195. return(m_peSurface = (EDD_VIDEOPORT*) DdHmgLock((HDD_OBJ) h, DD_VIDEOPORT_TYPE, FALSE));
  196. }
  197. void vUnlockNoNullSet(void)
  198. {
  199. if (m_peSurface != NULL)
  200. {
  201. DEC_EXCLUSIVE_REF_CNT(m_peSurface); // Do an HmgUnlock
  202. }
  203. }
  204. void vUnlock(void)
  205. {
  206. vUnlockNoNullSet();
  207. m_peSurface = NULL;
  208. }
  209. ~EDD_LOCK_VIDEOPORT()
  210. {
  211. vUnlockNoNullSet();
  212. }
  213. };
  214. /*********************************Class************************************\
  215. * class EDD_LOCK_MOTIONCOMP
  216. *
  217. * Simple wrapper for DirectDraw motion comp objects that automatically unlocks
  218. * the object when it goes out of scope, so that we don't forget.
  219. *
  220. \**************************************************************************/
  221. class EDD_LOCK_MOTIONCOMP
  222. {
  223. private:
  224. EDD_MOTIONCOMP *m_peSurface;
  225. public:
  226. EDD_LOCK_MOTIONCOMP()
  227. {
  228. m_peSurface = NULL;
  229. }
  230. EDD_MOTIONCOMP* peLock(HANDLE h)
  231. {
  232. return(m_peSurface = (EDD_MOTIONCOMP*) DdHmgLock((HDD_OBJ) h, DD_MOTIONCOMP_TYPE, FALSE));
  233. }
  234. void vUnlockNoNullSet(void)
  235. {
  236. if (m_peSurface != NULL)
  237. {
  238. DEC_EXCLUSIVE_REF_CNT(m_peSurface); // Do an HmgUnlock
  239. }
  240. }
  241. void vUnlock(void)
  242. {
  243. vUnlockNoNullSet();
  244. m_peSurface = NULL;
  245. }
  246. ~EDD_LOCK_MOTIONCOMP()
  247. {
  248. vUnlockNoNullSet();
  249. }
  250. };