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.

309 lines
9.2 KiB

  1. #include "rgb_pch.h"
  2. #pragma hdrstop
  3. namespace RGB_RAST_LIB_NAMESPACE
  4. {
  5. void CR5G6B5Surface::Clear( const D3DHAL_DP2CLEAR& DP2Clear, const RECT& RC) throw()
  6. {
  7. // Check for empty RECT.
  8. if((RC.left>= RC.right) || (RC.top>= RC.bottom))
  9. return;
  10. if((DP2Clear.dwFlags& D3DCLEAR_TARGET)== 0)
  11. return;
  12. RECTL RectL;
  13. RectL.top= RC.top;
  14. RectL.left= RC.left;
  15. RectL.bottom= RC.bottom;
  16. RectL.right= RC.right;
  17. unsigned int iRow( RC.bottom- RC.top);
  18. const unsigned int iCols( RC.right- RC.left);
  19. // New scope for SurfaceLocker.
  20. {
  21. CSurfaceLocker< CR5G6B5Surface*> MySLocker( this, 0, &RectL);
  22. UINT8* pSData= reinterpret_cast<UINT8*>( MySLocker.GetData());
  23. UINT32 uiRColor( DP2Clear.dwFillColor& 0xF80000);
  24. UINT32 uiGColor( DP2Clear.dwFillColor& 0xFC00);
  25. UINT32 uiBColor( DP2Clear.dwFillColor& 0xF8);
  26. uiRColor>>= 8;
  27. uiGColor>>= 5;
  28. uiBColor>>= 3;
  29. UINT32 uiColor= uiRColor| uiGColor| uiBColor;
  30. uiColor|= (uiColor<< 16);
  31. if( RC.left== 0 && RC.right== m_wWidth)
  32. MemFill( uiColor, pSData, iRow* m_lPitch);
  33. else do
  34. {
  35. MemFill( uiColor, pSData, iCols* sizeof(UINT16));
  36. pSData+= m_lPitch;
  37. } while( --iRow);
  38. }
  39. }
  40. void CA8R8G8B8Surface::Clear( const D3DHAL_DP2CLEAR& DP2Clear, const RECT& RC) throw()
  41. {
  42. // Check for empty RECT.
  43. if((RC.left>= RC.right) || (RC.top>= RC.bottom))
  44. return;
  45. if((DP2Clear.dwFlags& D3DCLEAR_TARGET)== 0)
  46. return;
  47. RECTL RectL;
  48. RectL.top= RC.top;
  49. RectL.left= RC.left;
  50. RectL.bottom= RC.bottom;
  51. RectL.right= RC.right;
  52. unsigned int iRow( RC.bottom- RC.top);
  53. const unsigned int iCols( RC.right- RC.left);
  54. // New scope for SurfaceLocker.
  55. {
  56. CSurfaceLocker< CA8R8G8B8Surface*> MySLocker( this, 0, &RectL);
  57. UINT8* pSData= reinterpret_cast<UINT8*>( MySLocker.GetData());
  58. if( RC.left== 0 && RC.right== m_wWidth)
  59. MemFill( DP2Clear.dwFillColor, pSData, iRow* m_lPitch);
  60. else do
  61. {
  62. MemFill( DP2Clear.dwFillColor, pSData, iCols* sizeof(UINT32));
  63. pSData+= m_lPitch;
  64. } while( --iRow);
  65. }
  66. }
  67. void CX8R8G8B8Surface::Clear( const D3DHAL_DP2CLEAR& DP2Clear, const RECT& RC) throw()
  68. {
  69. // Check for empty RECT.
  70. if((RC.left>= RC.right) || (RC.top>= RC.bottom))
  71. return;
  72. if((DP2Clear.dwFlags& D3DCLEAR_TARGET)== 0)
  73. return;
  74. RECTL RectL;
  75. RectL.top= RC.top;
  76. RectL.left= RC.left;
  77. RectL.bottom= RC.bottom;
  78. RectL.right= RC.right;
  79. unsigned int iRow( RC.bottom- RC.top);
  80. const unsigned int iCols( RC.right- RC.left);
  81. // New scope for SurfaceLocker.
  82. {
  83. CSurfaceLocker< CX8R8G8B8Surface*> MySLocker( this, 0, &RectL);
  84. UINT8* pSData= reinterpret_cast<UINT8*>( MySLocker.GetData());
  85. if( RC.left== 0 && RC.right== m_wWidth)
  86. MemFill( DP2Clear.dwFillColor, pSData, iRow* m_lPitch);
  87. else do
  88. {
  89. MemFill( DP2Clear.dwFillColor, pSData, iCols* sizeof(UINT32));
  90. pSData+= m_lPitch;
  91. } while( --iRow);
  92. }
  93. }
  94. void CD16Surface::Clear( const D3DHAL_DP2CLEAR& DP2Clear, const RECT& RC) throw()
  95. {
  96. // Check for empty RECT.
  97. if((RC.left>= RC.right) || (RC.top>= RC.bottom))
  98. return;
  99. if((DP2Clear.dwFlags& D3DCLEAR_ZBUFFER)== 0)
  100. return;
  101. RECTL RectL;
  102. RectL.top= RC.top;
  103. RectL.left= RC.left;
  104. RectL.bottom= RC.bottom;
  105. RectL.right= RC.right;
  106. unsigned int iRow( RC.bottom- RC.top);
  107. const unsigned int iCols( RC.right- RC.left);
  108. // New scope for SurfaceLocker.
  109. {
  110. CSurfaceLocker< CD16Surface*> MySLocker( this, 0, &RectL);
  111. UINT8* pSData= reinterpret_cast<UINT8*>( MySLocker.GetData());
  112. // Warning, this operation is happening with the FPU mode set to
  113. // single precision, which is acceptable for 16 bit.
  114. D3DVALUE Z( DP2Clear.dvFillDepth);
  115. clamp( Z, 0.0f, 1.0f);
  116. Z= Z* 0xFFFF+ 0.5f;
  117. UINT32 uiZVal= static_cast<UINT32>( Z);
  118. uiZVal|= (uiZVal<< 16);
  119. if( RC.left== 0 && RC.right== m_wWidth)
  120. MemFill( uiZVal, pSData, iRow* m_lPitch);
  121. else do
  122. {
  123. MemFill( uiZVal, pSData, iCols* sizeof(UINT16));
  124. pSData+= m_lPitch;
  125. } while( --iRow);
  126. }
  127. }
  128. void CD24S8Surface::Clear( const D3DHAL_DP2CLEAR& DP2Clear, const RECT& RC) throw()
  129. {
  130. // Check for empty RECT.
  131. if((RC.left>= RC.right) || (RC.top>= RC.bottom))
  132. return;
  133. if((DP2Clear.dwFlags& (D3DCLEAR_ZBUFFER| D3DCLEAR_STENCIL))== 0)
  134. return;
  135. RECTL RectL;
  136. RectL.top= RC.top;
  137. RectL.left= RC.left;
  138. RectL.bottom= RC.bottom;
  139. RectL.right= RC.right;
  140. unsigned int iRow( RC.bottom- RC.top);
  141. const unsigned int iCols( RC.right- RC.left);
  142. // New scope for SurfaceLocker.
  143. {
  144. CSurfaceLocker< CD24S8Surface*> MySLocker( this, 0, &RectL);
  145. UINT8* pSData= reinterpret_cast<UINT8*>( MySLocker.GetData());
  146. UINT32 uiMask( 0);
  147. UINT32 uiVal( 0);
  148. if((DP2Clear.dwFlags& D3DCLEAR_ZBUFFER)!= 0)
  149. {
  150. // Need C compatable FPU Mode here.
  151. CEnsureFPUModeForC FPUMode;
  152. double Z( DP2Clear.dvFillDepth);
  153. clamp( Z, 0.0, 1.0);
  154. Z= Z* 0xFFFFFF+ 0.5;
  155. uiVal= static_cast<UINT32>( Z);
  156. uiVal<<= 8;
  157. uiMask= 0xFFFFFF00;
  158. }
  159. if((DP2Clear.dwFlags& D3DCLEAR_STENCIL)!= 0)
  160. {
  161. uiVal|= (DP2Clear.dwFillStencil& 0xFF);
  162. uiMask|= 0xFF;
  163. }
  164. if( 0xFFFFFFFF== uiMask)
  165. {
  166. if( RC.left== 0 && RC.right== m_wWidth)
  167. MemFill( uiVal, pSData, iRow* m_lPitch);
  168. else do
  169. {
  170. MemFill( uiVal, pSData, iCols* sizeof(UINT32));
  171. pSData+= m_lPitch;
  172. } while( --iRow);
  173. }
  174. else
  175. {
  176. if( RC.left== 0 && RC.right== m_wWidth)
  177. MemMask( uiVal, uiMask, pSData, iRow* m_lPitch);
  178. else do
  179. {
  180. MemMask( uiVal, uiMask, pSData, iCols* sizeof(UINT32));
  181. pSData+= m_lPitch;
  182. } while( --iRow);
  183. }
  184. }
  185. }
  186. void MemFill( UINT32 uiData, void* pData, UINT32 uiBytes) throw()
  187. {
  188. unsigned int uiBytesLeft( uiBytes);
  189. UINT32* p32Data= reinterpret_cast<UINT32*>(pData);
  190. // Unroll.
  191. unsigned int uiSpans( uiBytesLeft>> 6);
  192. uiBytesLeft= uiBytesLeft& 0x3F;
  193. if( uiSpans!= 0) do
  194. {
  195. p32Data[ 0]= uiData;
  196. p32Data[ 1]= uiData;
  197. p32Data[ 2]= uiData;
  198. p32Data[ 3]= uiData;
  199. p32Data[ 4]= uiData;
  200. p32Data[ 5]= uiData;
  201. p32Data[ 6]= uiData;
  202. p32Data[ 7]= uiData;
  203. p32Data[ 8]= uiData;
  204. p32Data[ 9]= uiData;
  205. p32Data[10]= uiData;
  206. p32Data[11]= uiData;
  207. p32Data[12]= uiData;
  208. p32Data[13]= uiData;
  209. p32Data[14]= uiData;
  210. p32Data[15]= uiData;
  211. p32Data+= 16;
  212. } while( --uiSpans!= 0);
  213. uiSpans= uiBytesLeft>> 2;
  214. uiBytesLeft= uiBytesLeft& 0x3;
  215. if( uiSpans!= 0) do
  216. {
  217. p32Data[0]= uiData;
  218. p32Data++;
  219. } while( --uiSpans!= 0);
  220. if( uiBytesLeft!= 0)
  221. {
  222. assert( 2== uiBytesLeft);
  223. UINT16* p16Data= reinterpret_cast<UINT16*>(p32Data);
  224. p16Data[0]= static_cast<UINT16>( uiData& 0xFFFF);
  225. }
  226. }
  227. void MemMask( UINT32 uiData, UINT32 uiMask, void* pData, UINT32 uiBytes) throw()
  228. {
  229. uiMask= ~uiMask;
  230. unsigned int uiBytesLeft( uiBytes);
  231. UINT32* p32Data= reinterpret_cast<UINT32*>(pData);
  232. // Unroll.
  233. unsigned int uiSpans( uiBytesLeft>> 6);
  234. uiBytesLeft= uiBytesLeft& 0x3F;
  235. if( uiSpans!= 0) do
  236. {
  237. p32Data[ 0]= (p32Data[ 0]& uiMask)| uiData;
  238. p32Data[ 1]= (p32Data[ 1]& uiMask)| uiData;
  239. p32Data[ 2]= (p32Data[ 2]& uiMask)| uiData;
  240. p32Data[ 3]= (p32Data[ 3]& uiMask)| uiData;
  241. p32Data[ 4]= (p32Data[ 4]& uiMask)| uiData;
  242. p32Data[ 5]= (p32Data[ 5]& uiMask)| uiData;
  243. p32Data[ 6]= (p32Data[ 6]& uiMask)| uiData;
  244. p32Data[ 7]= (p32Data[ 7]& uiMask)| uiData;
  245. p32Data[ 8]= (p32Data[ 8]& uiMask)| uiData;
  246. p32Data[ 9]= (p32Data[ 9]& uiMask)| uiData;
  247. p32Data[10]= (p32Data[10]& uiMask)| uiData;
  248. p32Data[11]= (p32Data[11]& uiMask)| uiData;
  249. p32Data[12]= (p32Data[12]& uiMask)| uiData;
  250. p32Data[13]= (p32Data[13]& uiMask)| uiData;
  251. p32Data[14]= (p32Data[14]& uiMask)| uiData;
  252. p32Data[15]= (p32Data[15]& uiMask)| uiData;
  253. p32Data+= 16;
  254. } while( --uiSpans!= 0);
  255. uiSpans= uiBytesLeft>> 2;
  256. uiBytesLeft= uiBytesLeft& 0x3;
  257. if( uiSpans!= 0) do
  258. {
  259. p32Data[0]= (p32Data[0]& uiMask)| uiData;
  260. p32Data++;
  261. } while( --uiSpans!= 0);
  262. if( uiBytesLeft!= 0)
  263. {
  264. assert( 2== uiBytesLeft);
  265. UINT16* p16Data= reinterpret_cast<UINT16*>(p32Data);
  266. p16Data[0]= (p16Data[0]& static_cast<UINT16>( uiMask& 0xFFFF))|
  267. static_cast<UINT16>( uiData& 0xFFFF);
  268. }
  269. }
  270. }